1 |
|
2 |
#include <log4cxx/logger.h> |
3 |
#include <log4cxx/basicconfigurator.h> |
4 |
#include <log4cxx/fileappender.h> |
5 |
#include <log4cxx/patternlayout.h> |
6 |
#include <log4cxx/propertyconfigurator.h> |
7 |
#include <log4cxx/helpers/exception.h> |
8 |
|
9 |
#include "TROOT.h" |
10 |
|
11 |
#include "TechmodelPamelaRun.h" |
12 |
#include "EventReader.h" |
13 |
|
14 |
#include <cstdlib> |
15 |
#include <iostream> |
16 |
#include <time.h> |
17 |
extern "C" { |
18 |
//#include "DirectoryStructure.h" |
19 |
#include <dirent.h> |
20 |
} |
21 |
|
22 |
|
23 |
using namespace pamela; |
24 |
using namespace log4cxx; |
25 |
using namespace std; |
26 |
using namespace pamela::techmodel; |
27 |
|
28 |
static LoggerPtr logger = Logger::getLogger(_T("pamela.techmodel.TechmodelReader")); |
29 |
|
30 |
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 |
62 |
|
63 |
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); |
68 |
} |
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 |
for (int i = 2; i < argc; i++){ |
85 |
if (!strcmp(argv[i], "-p")){ |
86 |
if (++i >= argc){ |
87 |
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 |
110 |
//The parameters in the RollingFileAppender means |
111 |
// default ------------>the selected category |
112 |
// YodaLog.txt ------------>the LogFile name |
113 |
// 1000 ------------>The max size (in Kb) of the LogFile |
114 |
// 5 ------------>How many times the file will be backup |
115 |
|
116 |
time_t rawtime; |
117 |
struct tm * timeinfo; |
118 |
time ( &rawtime ); |
119 |
timeinfo = localtime ( &rawtime ); |
120 |
|
121 |
oss.flush(); |
122 |
oss << "<-------------------------------START UNPACKING------------------------------->\n" |
123 |
<< " Starting the program at: " << asctime (timeinfo) << " Opening file: " << argv[1]; |
124 |
logger->info(oss.str().c_str()); |
125 |
|
126 |
|
127 |
gROOT->SetBatch(kTRUE); |
128 |
EventReader *reader = new EventReader(maxPackets); |
129 |
|
130 |
int num = 0; |
131 |
TechmodelPamelaRun Run(argv[1]); |
132 |
reader->Init(&Run); |
133 |
|
134 |
oss.flush(); |
135 |
oss << "Init successul ok" << asctime (timeinfo); |
136 |
logger->debug(oss.str().c_str()); |
137 |
|
138 |
reader->RunEvent(num); //TBD --- eliminate the runNumber |
139 |
reader->Finish(); |
140 |
Run.WriteFiles(); |
141 |
|
142 |
logger->info("<-------------------------------END UNPACKING------------------------------->\n"); |
143 |
|
144 |
std::string command; |
145 |
command = "mv " + pathLog + " " + pathDir + "/" + Run.GetRun() + "/YodaLog.txt"; |
146 |
//Momentarly suspended the save |
147 |
//system(command.c_str()); |
148 |
} |