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