#include "log4cpp/Category.hh" #include "log4cpp/PropertyConfigurator.hh" #include "log4cpp/RollingFileAppender.hh" #include "log4cpp/PatternLayout.hh" #include "TROOT.h" #include "TechmodelPamelaRun.h" #include "EventReader.h" #include #include #include #include extern "C" { //#include "DirectoryStructure.h" #include } using namespace pamela; using namespace pamela::techmodel; static log4cpp::Category& cat = log4cpp::Category::getInstance("pamela.techmodel.TechmodelReader"); int main(int argc, char* argv[]) { // Check file name if (argc != 2){ cat.info("You have forgotten the file name"); exit(1); } std::ifstream from (argv[1]); if (!from) cat.info("The file does not exist"); /*try { log4cpp::PropertyConfigurator::configure("/home/kusanagi/yoda/techmodel/YodaLog.conf"); } catch (log4cpp::ConfigureFailure& f) { std::cerr << "Logging Configure Problem " << f.what() << std::endl; }*/ //-------------------------------------------------- //This is the configuration for the Yoda Logger //The parameters in the RollingFileAppender means // default ------------>the selected category // YodaLog.txt ------------>the LogFile name // 1000 ------------>The max size (in Kb) of the LogFile // 5 ------------>How many times the file will be backup char nomeFileLog[L_tmpnam]; tmpnam(nomeFileLog); DIR *dirp; std::string pathDir((char*)getenv("YODA_DATA")); std::string pathLog = nomeFileLog; log4cpp::Category& root = log4cpp::Category::getRoot(); try{ std::string initFileName = pathDir + "/log4cpp.conf"; log4cpp::PropertyConfigurator::configure(initFileName); } catch (log4cpp::ConfigureFailure& f) { std::cerr << "Could not load log configuration from file: " << f.what() << std::endl << "Using default setup (all msgs to stdout)" << std::endl; log4cpp::Appender* appender; appender = new log4cpp::FileAppender("default", pathLog.c_str(), false); // set a nice layout log4cpp::PatternLayout * pl = new log4cpp::PatternLayout(); pl->setConversionPattern("%d{%Y/%m/%d %H:%M:%S.%l} %p %c - %m"); appender->setLayout(pl); //log4cpp::Category& cat = log4cpp::Category::getInstance("cat"); // remove default appender cat.removeAllAppenders(); // use this appender for all categories cat.addAppender(appender); // log messages from all levels. //cat.setPriority(log4cpp::Priority::DEBUG); //cat.setPriority(log4cpp::Priority::WARN); cat.setPriority(log4cpp::Priority::INFO); } time_t rawtime; struct tm * timeinfo; time ( &rawtime ); timeinfo = localtime ( &rawtime ); //-------------------------------------------------- cat.log(log4cpp::Priority::INFO,"Importance depends on context"); cat << log4cpp::Priority::INFO << "<-------------------------------START UNPACKING------------------------------->\n" << " Starting the program at: " << asctime (timeinfo) << " Opening file: " << argv[1] << "\n \n" << log4cpp::CategoryStream::ENDLINE; gROOT->SetBatch(kTRUE); EventReader Reader; int num = 0; TechmodelPamelaRun Run(argv[1]); Reader.Init(&Run); cat << log4cpp::Priority::INFO << "Init successul ok" << asctime (timeinfo) << log4cpp::CategoryStream::ENDLINE; Reader.RunEvent(num); //TBD --- eliminate the runNumber Reader.Finish(); Run.WriteFiles(); cat << log4cpp::Priority::INFO << "<-------------------------------END UNPACKING------------------------------->" << "\n " << log4cpp::CategoryStream::ENDLINE; log4cpp::Category::shutdown(); std::string command; //command = "mv " + pathLog + " " + pathDir + "/" + Run.GetRun() + "/YodaLog.txt"; command = "mv " + pathLog + " " + pathDir + "/" + Run.GetRun() + "/YodaLog.txt"; cat.info(command); system(command.c_str()); }