| 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 |
std::string nomeFileLog = "YodaLog.txt"; |
| 53 |
log4cpp::Appender* appender; |
| 54 |
log4cpp::Category& cat = log4cpp::Category::getRoot(); |
| 55 |
DIR *dirp; |
| 56 |
//std::string pathDir((char*)getenv("YODA_LOGS")); |
| 57 |
std::string pathDir((char*)getenv("YODA_DATA")); |
| 58 |
|
| 59 |
std::string pathLog = pathDir + "/" + nomeFileLog; |
| 60 |
appender = new log4cpp::FileAppender("default", pathLog.c_str(), false); |
| 61 |
log4cpp::PatternLayout * pl = new log4cpp::PatternLayout(); |
| 62 |
pl->setConversionPattern("%d{%Y/%m/%d %H:%M:%S.%l} %p %c - %m"); |
| 63 |
appender->setLayout(pl); |
| 64 |
cat.setAppender(appender); |
| 65 |
cat.setPriority(log4cpp::Priority::DEBUG); |
| 66 |
time_t rawtime; |
| 67 |
struct tm * timeinfo; |
| 68 |
|
| 69 |
time ( &rawtime ); |
| 70 |
timeinfo = localtime ( &rawtime ); |
| 71 |
//-------------------------------------------------- |
| 72 |
cat << log4cpp::Priority::INFO |
| 73 |
<< "<-------------------------------START UNPACKING------------------------------->\n" |
| 74 |
<< " Starting the program at: " << asctime (timeinfo) << " Opening file: " << argv[1] |
| 75 |
<< "\n \n" << log4cpp::CategoryStream::ENDLINE; |
| 76 |
gROOT->SetBatch(kTRUE); |
| 77 |
|
| 78 |
EventReader Reader; |
| 79 |
|
| 80 |
int num = 0; |
| 81 |
TechmodelPamelaRun Run(argv[1]); |
| 82 |
Reader.Init(&Run); |
| 83 |
cat << log4cpp::Priority::INFO |
| 84 |
<< "Init successul ok" << asctime (timeinfo) << log4cpp::CategoryStream::ENDLINE; |
| 85 |
Reader.RunEvent(num); //TBD --- eliminate the runNumber |
| 86 |
Reader.Finish(); |
| 87 |
Run.WriteFiles(); |
| 88 |
cat << log4cpp::Priority::INFO |
| 89 |
<< "<-------------------------------END UNPACKING------------------------------->" |
| 90 |
<< "\n " << log4cpp::CategoryStream::ENDLINE; |
| 91 |
log4cpp::Category::shutdown(); |
| 92 |
std::string command; |
| 93 |
command = "mv " + pathLog + " " + pathDir + "/" + Run.GetRun() + "/."; |
| 94 |
cat.info(command); |
| 95 |
system(command.c_str()); |
| 96 |
} |