1 |
|
|
2 |
#include "log4cpp/Category.hh" |
#include <log4cxx/logger.h> |
3 |
#include "log4cpp/PropertyConfigurator.hh" |
#include <log4cxx/basicconfigurator.h> |
4 |
#include "log4cpp/RollingFileAppender.hh" |
#include <log4cxx/fileappender.h> |
5 |
#include "log4cpp/PatternLayout.hh" |
#include <log4cxx/patternlayout.h> |
6 |
|
#include <log4cxx/propertyconfigurator.h> |
7 |
|
#include <log4cxx/helpers/exception.h> |
8 |
|
|
9 |
#include "TROOT.h" |
#include "TROOT.h" |
10 |
|
|
11 |
#include "TechmodelPamelaRun.h" |
#include "TechmodelPamelaRun.h" |
12 |
#include "EventReader.h" |
#include "EventReader.h" |
13 |
#include <fstream> |
|
14 |
#include <cstdlib> |
#include <cstdlib> |
15 |
#include <stream.h> |
#include <iostream> |
16 |
#include <time.h> |
#include <time.h> |
17 |
extern "C" { |
extern "C" { |
18 |
//#include "DirectoryStructure.h" |
//#include "DirectoryStructure.h" |
21 |
|
|
22 |
|
|
23 |
using namespace pamela; |
using namespace pamela; |
24 |
|
using namespace log4cxx; |
25 |
|
using namespace std; |
26 |
using namespace pamela::techmodel; |
using namespace pamela::techmodel; |
27 |
|
|
28 |
static log4cpp::Category& cat = log4cpp::Category::getInstance("pamela.techmodel.TechmodelReader"); |
static LoggerPtr logger = Logger::getLogger(_T("pamela.techmodel.TechmodelReader")); |
29 |
|
|
30 |
int main(int argc, char* argv[]) { |
int main(int argc, char* argv[]) { |
31 |
|
|
32 |
|
stringstream oss; |
33 |
|
int maxPackets = 0; |
34 |
|
char nomeFileLog[L_tmpnam]; |
35 |
|
tmpnam(nomeFileLog); |
36 |
|
DIR *dirp; |
37 |
|
string pathDir((char*)getenv("YODA_DATA")); |
38 |
|
string pathLog = nomeFileLog; |
39 |
|
|
40 |
|
//---------------- Log4cxx configuration----------------------------------------------- |
41 |
|
//Define the configuration file to be used on log4cxx |
42 |
|
PropertyConfigurator::configure(pathDir + "/log4cxx.conf"); |
43 |
|
//BasicConfigurator::configure(); |
44 |
|
//Retrieve the rootLogger and append to it a default FileAppender. |
45 |
|
//Note that the priority level of the rootLogger (defined in log4cxx.conf) is unmodified |
46 |
|
//LoggerPtr rootLogger = Logger::getRootLogger(); |
47 |
|
|
48 |
|
//FileAppender *fileAppender = new FileAppender(); |
49 |
|
//fileAppender->setFile(pathLog); |
50 |
|
//fileAppender->setAppend(false); |
51 |
|
//fileAppender->setBufferedIO(true); //the default size is 8k |
52 |
|
//fileAppender->setBufferSize(1000000); |
53 |
|
//fileAppender->activateOptions(); |
54 |
|
//fileAppender->setLayout(new PatternLayout()); |
55 |
|
|
56 |
|
//FileAppender *fileAppender = new FileAppender(new PatternLayout(), pathLog, false, true, 10000); |
57 |
|
//rootLogger->addAppender(fileAppender); |
58 |
|
//rootLogger->removeAppender('A1'); |
59 |
|
//---------------- Log4cxx configuration----------------------------------------------- |
60 |
|
|
61 |
// Check file name |
// Check file name |
62 |
if (argc != 2){ |
|
63 |
cat.info("You have forgotten the file name"); |
if (argc < 2){ |
64 |
|
//logger->info(_T("You have forgotten the file name.")); |
65 |
|
cout << "You have forgotten the file name. \n"; |
66 |
|
cout << "Try '--help' for more information. \n"; |
67 |
exit(1); |
exit(1); |
68 |
} |
} |
|
|
|
|
std::ifstream from (argv[1]); |
|
|
if (!from) cat.info("The file does not exist"); |
|
69 |
|
|
70 |
|
if (!strcmp(argv[1], "--help")){ |
71 |
|
cout << "Usage: yoda FILE [OPTION] \n"; |
72 |
|
cout << "\t --help print this help and exit \n"; |
73 |
|
cout << "\t -p maximum number of packets to process [default all] \n"; |
74 |
|
exit(1); |
75 |
|
} |
76 |
|
|
77 |
|
ifstream from (argv[1]); |
78 |
|
if (!from) { |
79 |
|
//logger->info(_T("The file does not exist.")); |
80 |
|
cout << "The file does not exist. \n"; |
81 |
|
exit(1); |
82 |
|
} |
83 |
|
|
84 |
/*try { |
for (int i = 2; i < argc; i++){ |
85 |
log4cpp::PropertyConfigurator::configure("/home/kusanagi/yoda/techmodel/YodaLog.conf"); |
if (!strcmp(argv[i], "-p")){ |
86 |
} catch (log4cpp::ConfigureFailure& f) { |
if (++i >= argc){ |
87 |
std::cerr << "Logging Configure Problem " << f.what() << std::endl; |
cerr << "-p needs arguments. \n"; |
88 |
}*/ |
cout << "Try '--help' for more information. \n"; |
89 |
|
exit(1); |
90 |
|
} |
91 |
|
if (isdigit(*argv[i])) { |
92 |
|
maxPackets = atoi(argv[i]); |
93 |
|
} else { |
94 |
|
//logger->info(_T("The file does not exist.")); |
95 |
|
cerr << "-p needs a integer value. \n"; |
96 |
|
cout << "Try '--help' for more information. \n"; |
97 |
|
exit(1); |
98 |
|
} |
99 |
|
} |
100 |
|
|
101 |
|
if (!maxPackets){ |
102 |
|
cout << "Try '--help' for more information. \n"; |
103 |
|
exit(1); |
104 |
|
} |
105 |
|
} |
106 |
|
|
107 |
|
|
108 |
//-------------------------------------------------- |
//-------------------------------------------------- |
109 |
//This is the configuration for the Yoda Logger |
//This is the configuration for the Yoda Logger |
110 |
//The parameters in the RollingFileAppender means |
//The parameters in the RollingFileAppender means |
112 |
// YodaLog.txt ------------>the LogFile name |
// YodaLog.txt ------------>the LogFile name |
113 |
// 1000 ------------>The max size (in Kb) of the LogFile |
// 1000 ------------>The max size (in Kb) of the LogFile |
114 |
// 5 ------------>How many times the file will be backup |
// 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); |
|
|
} |
|
115 |
|
|
116 |
time_t rawtime; |
time_t rawtime; |
117 |
struct tm * timeinfo; |
struct tm * timeinfo; |
|
|
|
118 |
time ( &rawtime ); |
time ( &rawtime ); |
119 |
timeinfo = localtime ( &rawtime ); |
timeinfo = localtime ( &rawtime ); |
120 |
//-------------------------------------------------- |
|
121 |
cat.log(log4cpp::Priority::INFO,"Importance depends on context"); |
oss.flush(); |
122 |
cat << log4cpp::Priority::INFO |
oss << "<-------------------------------START UNPACKING------------------------------->\n" |
123 |
<< "<-------------------------------START UNPACKING------------------------------->\n" |
<< " Starting the program at: " << asctime (timeinfo) << " Opening file: " << argv[1]; |
124 |
<< " Starting the program at: " << asctime (timeinfo) << " Opening file: " << argv[1] |
logger->info(oss.str().c_str()); |
125 |
<< "\n \n" << log4cpp::CategoryStream::ENDLINE; |
|
126 |
|
|
127 |
gROOT->SetBatch(kTRUE); |
gROOT->SetBatch(kTRUE); |
128 |
|
EventReader *reader = new EventReader(maxPackets); |
|
EventReader Reader; |
|
129 |
|
|
130 |
int num = 0; |
int num = 0; |
131 |
TechmodelPamelaRun Run(argv[1]); |
TechmodelPamelaRun Run(argv[1]); |
132 |
Reader.Init(&Run); |
reader->Init(&Run); |
133 |
cat << log4cpp::Priority::INFO |
|
134 |
<< "Init successul ok" << asctime (timeinfo) << log4cpp::CategoryStream::ENDLINE; |
oss.flush(); |
135 |
Reader.RunEvent(num); //TBD --- eliminate the runNumber |
oss << "Init successul ok" << asctime (timeinfo); |
136 |
Reader.Finish(); |
logger->debug(oss.str().c_str()); |
137 |
|
|
138 |
|
reader->RunEvent(num); //TBD --- eliminate the runNumber |
139 |
|
reader->Finish(); |
140 |
Run.WriteFiles(); |
Run.WriteFiles(); |
141 |
cat << log4cpp::Priority::INFO |
|
142 |
<< "<-------------------------------END UNPACKING------------------------------->" |
logger->info("<-------------------------------END UNPACKING------------------------------->\n"); |
143 |
<< "\n " << log4cpp::CategoryStream::ENDLINE; |
|
|
log4cpp::Category::shutdown(); |
|
144 |
std::string command; |
std::string command; |
|
//command = "mv " + pathLog + " " + pathDir + "/" + Run.GetRun() + "/YodaLog.txt"; |
|
145 |
command = "mv " + pathLog + " " + pathDir + "/" + Run.GetRun() + "/YodaLog.txt"; |
command = "mv " + pathLog + " " + pathDir + "/" + Run.GetRun() + "/YodaLog.txt"; |
146 |
cat.info(command); |
//Momentarly suspended the save |
147 |
system(command.c_str()); |
//system(command.c_str()); |
148 |
} |
} |