1 |
|
|
2 |
#include <log4cxx/logger.h> |
#include <log4cxx/logger.h> |
|
#include <log4cxx/basicconfigurator.h> |
|
|
#include <log4cxx/fileappender.h> |
|
|
#include <log4cxx/patternlayout.h> |
|
3 |
#include <log4cxx/propertyconfigurator.h> |
#include <log4cxx/propertyconfigurator.h> |
|
#include <log4cxx/helpers/exception.h> |
|
|
|
|
|
#include "TROOT.h" |
|
|
|
|
|
#include "TechmodelPamelaRun.h" |
|
4 |
#include "EventReader.h" |
#include "EventReader.h" |
|
|
|
|
#include <cstdlib> |
|
|
#include <iostream> |
|
5 |
#include <time.h> |
#include <time.h> |
6 |
|
|
7 |
extern "C" { |
extern "C" { |
8 |
//#include "DirectoryStructure.h" |
#include <dirent.h> |
|
#include <dirent.h> |
|
9 |
} |
} |
10 |
|
|
11 |
|
|
12 |
|
|
13 |
using namespace pamela; |
using namespace pamela; |
14 |
using namespace log4cxx; |
using namespace log4cxx; |
15 |
using namespace std; |
using namespace std; |
21 |
|
|
22 |
stringstream oss; |
stringstream oss; |
23 |
int maxPackets = 0; |
int maxPackets = 0; |
24 |
|
bool multiFile = 0; |
25 |
|
short compression = 3; |
26 |
char nomeFileLog[L_tmpnam]; |
char nomeFileLog[L_tmpnam]; |
27 |
tmpnam(nomeFileLog); |
tmpnam(nomeFileLog); |
28 |
DIR *dirp; |
DIR *dirp; |
|
string pathDir((char*)getenv("YODA_DATA")); |
|
|
string pathLog = nomeFileLog; |
|
29 |
|
|
30 |
|
// check if yoda_DATA exist!!!! |
31 |
|
char *outDir; |
32 |
|
try { |
33 |
|
outDir = getenv("YODA_DATA"); |
34 |
|
if (getenv("YODA_DATA") == NULL) throw NotFoundEnvironmentVarException("The variable YODA_DATA has not been found."); |
35 |
|
} catch (NotFoundEnvironmentVarException exc) { |
36 |
|
cout << "The variable YODA_DATA has not been found. \n"; |
37 |
|
cout << "Please check your environment variables \n"; |
38 |
|
oss.str(""); |
39 |
|
oss << exc.print(); |
40 |
|
logger->fatal(oss.str().c_str()); |
41 |
|
exit(1); |
42 |
|
} |
43 |
|
|
44 |
|
string pathDir(outDir); |
45 |
|
|
46 |
|
string pathLog = nomeFileLog; |
47 |
|
bool ANALIZE = false; |
48 |
//---------------- Log4cxx configuration----------------------------------------------- |
//---------------- Log4cxx configuration----------------------------------------------- |
49 |
//Define the configuration file to be used on log4cxx |
//Define the configuration file to be used on log4cxx |
50 |
PropertyConfigurator::configure(pathDir + "/log4cxx.conf"); |
PropertyConfigurator::configure(pathDir + "/log4cxx.conf"); |
79 |
cout << "Usage: yoda FILE [OPTION] \n"; |
cout << "Usage: yoda FILE [OPTION] \n"; |
80 |
cout << "\t --help print this help and exit \n"; |
cout << "\t --help print this help and exit \n"; |
81 |
cout << "\t -p maximum number of packets to process [default all] \n"; |
cout << "\t -p maximum number of packets to process [default all] \n"; |
82 |
|
cout << "\t -m generate multiple root files. Values: {'true', 'false'} [default = 'false']\n"; |
83 |
|
cout << "\t -c set the compression level for the generated root files. Values: [0,9] [default = 3]\n"; |
84 |
exit(1); |
exit(1); |
85 |
} |
} |
86 |
|
|
98 |
cout << "Try '--help' for more information. \n"; |
cout << "Try '--help' for more information. \n"; |
99 |
exit(1); |
exit(1); |
100 |
} |
} |
101 |
if (isdigit(*argv[i])) { |
if (isdigit(*argv[i]) && (atoi(argv[i]) > 0)) { |
102 |
maxPackets = atoi(argv[i]); |
maxPackets = atoi(argv[i]); |
103 |
} else { |
} else { |
104 |
//logger->info(_T("The file does not exist.")); |
//logger->info(_T("The file does not exist.")); |
106 |
cout << "Try '--help' for more information. \n"; |
cout << "Try '--help' for more information. \n"; |
107 |
exit(1); |
exit(1); |
108 |
} |
} |
109 |
|
continue; |
110 |
} |
} |
111 |
|
|
112 |
if (!maxPackets){ |
if (!strcmp(argv[i], "-multifile")) multiFile = 1; |
113 |
cout << "Try '--help' for more information. \n"; |
|
114 |
exit(1); |
if (!strcmp(argv[i], "-c")){ |
115 |
|
if (++i >= argc){ |
116 |
|
cerr << "-c needs arguments. \n"; |
117 |
|
cout << "Try '--help' for more information. \n"; |
118 |
|
exit(1); |
119 |
|
} |
120 |
|
if ((isdigit(*argv[i])) && ( (atoi(argv[i]) >= 0) && (atoi(argv[i]) <= 9))) { |
121 |
|
compression = atoi(argv[i]); |
122 |
|
} else { |
123 |
|
//logger->info(_T("The file does not exist.")); |
124 |
|
cerr << "-c needs a integer value beetween 0 and 9. \n"; |
125 |
|
cout << "Try '--help' for more information. \n"; |
126 |
|
exit(1); |
127 |
|
} |
128 |
|
continue; |
129 |
} |
} |
130 |
} |
} |
|
|
|
|
|
|
|
//-------------------------------------------------- |
|
|
//This is the configuration for the Yoda Logger |
|
|
//The parameters in the RollingFileAppender means |
|
|
// default ------------>the selected category |
|
|
// YodaLog.txt ------------>the LogFile name |
|
|
// 1000 ------------>The max size (in Kb) of the LogFile |
|
|
// 5 ------------>How many times the file will be backup |
|
131 |
|
|
132 |
time_t rawtime; |
time_t rawtime; |
133 |
struct tm * timeinfo; |
struct tm * timeinfo; |
134 |
time ( &rawtime ); |
time ( &rawtime ); |
135 |
timeinfo = localtime ( &rawtime ); |
timeinfo = localtime ( &rawtime ); |
136 |
|
|
137 |
oss.flush(); |
oss.str(""); |
138 |
oss << "<-------------------------------START UNPACKING------------------------------->\n" |
oss << "<-------------------------------START UNPACKING------------------------------->\n" |
139 |
<< " Starting the program at: " << asctime (timeinfo) << " Opening file: " << argv[1]; |
<< " Starting the program at: " << asctime (timeinfo) << " Opening file: " << argv[1]; |
140 |
logger->info(oss.str().c_str()); |
logger->info(oss.str().c_str()); |
144 |
EventReader *reader = new EventReader(maxPackets); |
EventReader *reader = new EventReader(maxPackets); |
145 |
|
|
146 |
int num = 0; |
int num = 0; |
147 |
TechmodelPamelaRun Run(argv[1]); |
TechmodelPamelaRun Run(argv[1], outDir, multiFile, compression); |
148 |
reader->Init(&Run); |
reader->Init(&Run); |
149 |
|
|
150 |
oss.flush(); |
oss.str(""); |
151 |
oss << "Init successul ok" << asctime (timeinfo); |
oss << "Init successul ok" << asctime (timeinfo); |
152 |
logger->debug(oss.str().c_str()); |
logger->debug(oss.str().c_str()); |
153 |
|
|
157 |
|
|
158 |
logger->info("<-------------------------------END UNPACKING------------------------------->\n"); |
logger->info("<-------------------------------END UNPACKING------------------------------->\n"); |
159 |
|
|
|
std::string command; |
|
|
command = "mv " + pathLog + " " + pathDir + "/" + Run.GetRun() + "/YodaLog.txt"; |
|
160 |
//Momentarly suspended the save |
//Momentarly suspended the save |
161 |
//system(command.c_str()); |
//system(command.c_str()); |
162 |
} |
} |