| 1 |  | 
| 2 | #include "log4cpp/Category.hh" | 
| 3 | #include "log4cpp/PropertyConfigurator.hh" | 
| 4 | #include "log4cpp/RollingFileAppender.hh" | 
| 5 | #include "log4cpp/PatternLayout.hh" | 
| 6 |  | 
| 7 | #include "TROOT.h" | 
| 8 |  | 
| 9 | #include "TechmodelPamelaRun.h" | 
| 10 | #include "EventReader.h" | 
| 11 | #include <fstream> | 
| 12 | #include <cstdlib> | 
| 13 | #include <stream.h> | 
| 14 | #include <time.h> | 
| 15 | extern "C" { | 
| 16 | //#include "DirectoryStructure.h" | 
| 17 | #include <dirent.h> | 
| 18 | } | 
| 19 |  | 
| 20 |  | 
| 21 | using namespace pamela; | 
| 22 | using namespace pamela::techmodel; | 
| 23 |  | 
| 24 | static log4cpp::Category& cat = log4cpp::Category::getInstance("pamela.techmodel.TechmodelReader"); | 
| 25 |  | 
| 26 | int main(int argc, char* argv[]) { | 
| 27 |  | 
| 28 | // Check file name | 
| 29 | if (argc != 2){ | 
| 30 | cat.info("You have forgotten the file name"); | 
| 31 | exit(1); | 
| 32 | } | 
| 33 |  | 
| 34 | std::ifstream from (argv[1]); | 
| 35 | if (!from) cat.info("The file does not exist"); | 
| 36 |  | 
| 37 |  | 
| 38 | /*try { | 
| 39 | log4cpp::PropertyConfigurator::configure("/home/kusanagi/yoda/techmodel/YodaLog.conf"); | 
| 40 | } catch (log4cpp::ConfigureFailure& f) { | 
| 41 | std::cerr << "Logging Configure Problem " << f.what() << std::endl; | 
| 42 | }*/ | 
| 43 |  | 
| 44 |  | 
| 45 | //-------------------------------------------------- | 
| 46 | //This is the configuration for the Yoda Logger | 
| 47 | //The parameters in the RollingFileAppender means | 
| 48 | // default           ------------>the selected category | 
| 49 | // YodaLog.txt  ------------>the LogFile name | 
| 50 | // 1000              ------------>The max size (in Kb) of the LogFile | 
| 51 | // 5                     ------------>How many times the file will be backup | 
| 52 | char nomeFileLog[L_tmpnam]; | 
| 53 | tmpnam(nomeFileLog); | 
| 54 | //std::string nomeFileLog = "YodaLog.txt"; | 
| 55 | log4cpp::Appender* appender; | 
| 56 | log4cpp::Category& cat = log4cpp::Category::getRoot(); | 
| 57 | DIR *dirp; | 
| 58 | std::string pathDir((char*)getenv("YODA_DATA")); | 
| 59 |  | 
| 60 | //std::string pathLog = pathDir + "/" + nomeFileLog; | 
| 61 | std::string pathLog = nomeFileLog; | 
| 62 | appender = new log4cpp::FileAppender("default", pathLog.c_str(), false); | 
| 63 | log4cpp::PatternLayout * pl = new log4cpp::PatternLayout(); | 
| 64 | pl->setConversionPattern("%d{%Y/%m/%d %H:%M:%S.%l} %p %c - %m"); | 
| 65 | appender->setLayout(pl); | 
| 66 | cat.setAppender(appender); | 
| 67 | //cat.setPriority(log4cpp::Priority::DEBUG); | 
| 68 | //cat.setPriority(log4cpp::Priority::WARN); | 
| 69 | cat.setPriority(log4cpp::Priority::INFO); | 
| 70 | time_t rawtime; | 
| 71 | struct tm * timeinfo; | 
| 72 |  | 
| 73 | time ( &rawtime ); | 
| 74 | timeinfo = localtime ( &rawtime ); | 
| 75 | //-------------------------------------------------- | 
| 76 | cat << log4cpp::Priority::INFO | 
| 77 | << "<-------------------------------START UNPACKING------------------------------->\n" | 
| 78 | << " Starting the program at: " << asctime (timeinfo) << " Opening file: " << argv[1] | 
| 79 | << "\n \n" << log4cpp::CategoryStream::ENDLINE; | 
| 80 | gROOT->SetBatch(kTRUE); | 
| 81 |  | 
| 82 | EventReader Reader; | 
| 83 |  | 
| 84 | int num = 0; | 
| 85 | TechmodelPamelaRun Run(argv[1]); | 
| 86 | Reader.Init(&Run); | 
| 87 | cat << log4cpp::Priority::INFO | 
| 88 | << "Init successul ok" << asctime (timeinfo) << log4cpp::CategoryStream::ENDLINE; | 
| 89 | Reader.RunEvent(num); //TBD --- eliminate the runNumber | 
| 90 | Reader.Finish(); | 
| 91 | Run.WriteFiles(); | 
| 92 | cat << log4cpp::Priority::INFO | 
| 93 | << "<-------------------------------END UNPACKING------------------------------->" | 
| 94 | << "\n " << log4cpp::CategoryStream::ENDLINE; | 
| 95 | log4cpp::Category::shutdown(); | 
| 96 | std::string command; | 
| 97 | //command = "mv " + pathLog + "  " + pathDir + "/" + Run.GetRun() + "/YodaLog.txt"; | 
| 98 | command = "mv " + pathLog + "  " + pathDir + "/" + Run.GetRun() + "/YodaLog.txt"; | 
| 99 | cat.info(command); | 
| 100 | system(command.c_str()); | 
| 101 | } |