1 |
|
|
2 |
#include "log4cpp/Category.hh" |
#include <log4cxx/logger.h> |
3 |
#include "log4cpp/PropertyConfigurator.hh" |
#include <log4cxx/propertyconfigurator.h> |
|
#include "log4cpp/RollingFileAppender.hh" |
|
|
#include "log4cpp/PatternLayout.hh" |
|
|
|
|
|
#include "TROOT.h" |
|
|
|
|
|
#include "TechmodelPamelaRun.h" |
|
4 |
#include "EventReader.h" |
#include "EventReader.h" |
|
#include <fstream> |
|
|
#include <cstdlib> |
|
|
#include <stream.h> |
|
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; |
15 |
|
using namespace std; |
16 |
using namespace pamela::techmodel; |
using namespace pamela::techmodel; |
17 |
|
|
18 |
static log4cpp::Category& cat = log4cpp::Category::getInstance("pamela.techmodel.TechmodelReader"); |
static LoggerPtr logger = Logger::getLogger(_T("pamela.techmodel.TechmodelReader")); |
19 |
|
|
20 |
int main(int argc, char* argv[]) { |
int main(int argc, char* argv[]) { |
21 |
|
|
22 |
|
stringstream oss; |
23 |
|
int maxPackets = 0; |
24 |
|
bool multiFile = 0; |
25 |
|
short compression = 3; |
26 |
|
char nomeFileLog[L_tmpnam]; |
27 |
|
mkstemp(nomeFileLog); |
28 |
|
DIR *dirp; |
29 |
|
char *outDir = ""; |
30 |
|
|
31 |
|
//---------------- Log4cxx configuration----------------------------------------------- |
32 |
|
//BasicConfigurator::configure(); |
33 |
|
//Retrieve the rootLogger and append to it a default FileAppender. |
34 |
|
//Note that the priority level of the rootLogger (defined in log4cxx.conf) is unmodified |
35 |
|
//LoggerPtr rootLogger = Logger::getRootLogger(); |
36 |
|
|
37 |
|
//FileAppender *fileAppender = new FileAppender(); |
38 |
|
//fileAppender->setFile(pathLog); |
39 |
|
//fileAppender->setAppend(false); |
40 |
|
//fileAppender->setBufferedIO(true); //the default size is 8k |
41 |
|
//fileAppender->setBufferSize(1000000); |
42 |
|
//fileAppender->activateOptions(); |
43 |
|
//fileAppender->setLayout(new PatternLayout()); |
44 |
|
|
45 |
|
//FileAppender *fileAppender = new FileAppender(new PatternLayout(), pathLog, false, true, 10000); |
46 |
|
//rootLogger->addAppender(fileAppender); |
47 |
|
//rootLogger->removeAppender('A1'); |
48 |
|
//---------------- Log4cxx configuration----------------------------------------------- |
49 |
|
|
50 |
// Check file name |
// Check file name |
51 |
if (argc != 2){ |
|
52 |
cat.info("You have forgotten the file name"); |
if (argc < 2){ |
53 |
|
//logger->info(_T("You have forgotten the file name.")); |
54 |
|
cout << "You have forgotten the file name. \n"; |
55 |
|
cout << "Try '-help' for more information. \n"; |
56 |
|
exit(1); |
57 |
|
} |
58 |
|
|
59 |
|
if (!strcmp(argv[1], "-help")){ |
60 |
|
cout << "Usage: yoda FILE [OPTION] \n"; |
61 |
|
cout << "\t -help print this help and exit \n"; |
62 |
|
cout << "\t -version print version number \n"; |
63 |
|
cout << "\t -p maximum number of packets to process [default all] \n"; |
64 |
|
cout << "\t -multi generate multiple root files \n"; |
65 |
|
cout << "\t -c set the compression level for the generated root file(s). Values: [0,9] [default = 3]\n"; |
66 |
|
cout << "\t -o set the output directory for the generated root file(s). [default = $YODA_DATA]. Notice that in the same directory have to be prensent a log4cxx configuration file called \"log4cxx.conf\" \n"; |
67 |
|
exit(1); |
68 |
|
} |
69 |
|
|
70 |
|
if (!strcmp(argv[1], "-version")){ |
71 |
|
cout << "$Name: $ $Revision: 6.2 $" << "\n"; |
72 |
|
exit(1); |
73 |
|
} |
74 |
|
|
75 |
|
ifstream from (argv[1]); |
76 |
|
if (!from) { |
77 |
|
//logger->info(_T("The file does not exist.")); |
78 |
|
cout << "The file does not exist. \n"; |
79 |
exit(1); |
exit(1); |
80 |
} |
} |
81 |
|
|
82 |
std::ifstream from (argv[1]); |
for (int i = 2; i < argc; i++){ |
83 |
if (!from) cat.info("The file does not exist"); |
if (!strcmp(argv[i], "-p")){ |
84 |
|
if (++i >= argc){ |
85 |
|
cerr << "-p needs arguments. \n"; |
86 |
|
cout << "Try '-help' for more information. \n"; |
87 |
|
exit(1); |
88 |
|
} |
89 |
|
if (isdigit(*argv[i]) && (atoi(argv[i]) > 0)) { |
90 |
|
maxPackets = atoi(argv[i]); |
91 |
|
} else { |
92 |
|
//logger->info(_T("The file does not exist.")); |
93 |
|
cerr << "-p needs a integer value. \n"; |
94 |
|
cout << "Try '-help' for more information. \n"; |
95 |
|
exit(1); |
96 |
|
} |
97 |
|
continue; |
98 |
|
} |
99 |
|
|
100 |
|
if (!strcmp(argv[i], "-multi")) multiFile = 1; |
101 |
|
|
102 |
|
if (!strcmp(argv[i], "-c")){ |
103 |
|
if (++i >= argc){ |
104 |
|
cerr << "-c needs arguments. \n"; |
105 |
|
cout << "Try '-help' for more information. \n"; |
106 |
|
exit(1); |
107 |
|
} |
108 |
|
if ((isdigit(*argv[i])) && ( (atoi(argv[i]) >= 0) && (atoi(argv[i]) <= 9))) { |
109 |
|
compression = atoi(argv[i]); |
110 |
|
} else { |
111 |
|
//logger->info(_T("The file does not exist.")); |
112 |
|
cerr << "-c needs a integer value beetween 0 and 9. \n"; |
113 |
|
cout << "Try '-help' for more information. \n"; |
114 |
|
exit(1); |
115 |
|
} |
116 |
|
continue; |
117 |
|
} |
118 |
|
|
119 |
|
if (!strcmp(argv[i], "-o")){ |
120 |
|
if (++i >= argc){ |
121 |
|
cerr << "-o needs arguments. \n"; |
122 |
|
cout << "Try '-help' for more information. \n"; |
123 |
|
exit(1); |
124 |
|
} |
125 |
|
DIR* tempdir; |
126 |
|
if ((tempdir = opendir(argv[i])) != 0) { |
127 |
|
outDir = argv[i]; |
128 |
|
closedir(tempdir); |
129 |
|
} else { |
130 |
|
//logger->info(_T("The file does not exist.")); |
131 |
|
cerr << "-o needs an existing/accessable directory. \n"; |
132 |
|
cout << "Try '-help' for more information. \n"; |
133 |
|
exit(1); |
134 |
|
} |
135 |
|
continue; |
136 |
|
} |
137 |
|
|
138 |
|
} |
139 |
|
|
140 |
|
if (outDir == ""){ |
141 |
|
try { |
142 |
|
outDir = getenv("YODA_DATA"); |
143 |
|
if (getenv("YODA_DATA") == NULL) throw NotFoundEnvironmentVarException("The variable YODA_DATA has not been found."); |
144 |
|
} catch (NotFoundEnvironmentVarException exc) { |
145 |
|
cout << "The variable YODA_DATA has not been found. \n"; |
146 |
|
cout << "Please check your environment variables \n"; |
147 |
|
oss.str(""); |
148 |
|
oss << exc.print(); |
149 |
|
logger->fatal(oss.str().c_str()); |
150 |
|
exit(1); |
151 |
|
} |
152 |
|
} |
153 |
|
|
154 |
|
string pathDir(outDir); |
155 |
|
string pathLog = nomeFileLog; |
156 |
|
//Define the configuration file to be used on log4cxx |
157 |
|
PropertyConfigurator::configure(pathDir + "/log4cxx.conf"); |
158 |
|
|
|
/*try { |
|
|
log4cpp::PropertyConfigurator::configure("/home/kusanagi/yoda/techmodel/YodaLog.conf"); |
|
|
} catch (log4cpp::ConfigureFailure& f) { |
|
|
std::cerr << "Logging Configure Problem " << f.what() << std::endl; |
|
|
}*/ |
|
|
|
|
|
|
|
|
//-------------------------------------------------- |
|
|
//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 |
|
|
std::string nomeFileLog = "YodaLog.txt"; |
|
|
log4cpp::Appender* appender; |
|
|
log4cpp::Category& cat = log4cpp::Category::getRoot(); |
|
|
DIR *dirp; |
|
|
//std::string pathDir((char*)getenv("YODA_LOGS")); |
|
|
std::string pathDir((char*)getenv("YODA_DATA")); |
|
|
|
|
|
std::string pathLog = pathDir + "/" + nomeFileLog; |
|
|
appender = new log4cpp::FileAppender("default", pathLog.c_str(), false); |
|
|
log4cpp::PatternLayout * pl = new log4cpp::PatternLayout(); |
|
|
pl->setConversionPattern("%d{%Y/%m/%d %H:%M:%S.%l} %p %c - %m"); |
|
|
appender->setLayout(pl); |
|
|
cat.setAppender(appender); |
|
|
cat.setPriority(log4cpp::Priority::DEBUG); |
|
159 |
time_t rawtime; |
time_t rawtime; |
160 |
struct tm * timeinfo; |
struct tm * timeinfo; |
|
|
|
161 |
time ( &rawtime ); |
time ( &rawtime ); |
162 |
timeinfo = localtime ( &rawtime ); |
timeinfo = localtime ( &rawtime ); |
163 |
//-------------------------------------------------- |
|
164 |
cat << log4cpp::Priority::INFO |
oss.str(""); |
165 |
<< "<-------------------------------START UNPACKING------------------------------->\n" |
oss << "<-------------------------------START UNPACKING------------------------------->\n" |
166 |
<< " Starting the program at: " << asctime (timeinfo) << " Opening file: " << argv[1] |
<< " Starting the program at: " << asctime (timeinfo) << " Opening file: " << argv[1]; |
167 |
<< "\n \n" << log4cpp::CategoryStream::ENDLINE; |
logger->info(oss.str().c_str()); |
168 |
|
|
169 |
|
|
170 |
gROOT->SetBatch(kTRUE); |
gROOT->SetBatch(kTRUE); |
171 |
|
EventReader *reader = new EventReader(maxPackets); |
|
EventReader Reader; |
|
172 |
|
|
173 |
int num = 0; |
int num = 0; |
174 |
TechmodelPamelaRun Run(argv[1]); |
TechmodelPamelaRun Run(argv[1], outDir, multiFile, compression); |
175 |
Reader.Init(&Run); |
reader->Init(&Run); |
176 |
cat << log4cpp::Priority::INFO |
|
177 |
<< "Init successul ok" << asctime (timeinfo) << log4cpp::CategoryStream::ENDLINE; |
oss.str(""); |
178 |
Reader.RunEvent(num); //TBD --- eliminate the runNumber |
oss << "Init successul ok" << asctime (timeinfo); |
179 |
Reader.Finish(); |
logger->debug(oss.str().c_str()); |
180 |
|
|
181 |
|
reader->RunEvent(num); //TBD --- eliminate the runNumber |
182 |
|
reader->Finish(); |
183 |
Run.WriteFiles(); |
Run.WriteFiles(); |
184 |
cat << log4cpp::Priority::INFO |
|
185 |
<< "<-------------------------------END UNPACKING------------------------------->" |
logger->info("<-------------------------------END UNPACKING------------------------------->\n"); |
186 |
<< "\n " << log4cpp::CategoryStream::ENDLINE; |
|
187 |
log4cpp::Category::shutdown(); |
//Momentarly suspended the save |
188 |
std::string command; |
//system(command.c_str()); |
|
command = "mv " + pathLog + " " + pathDir + "/" + Run.GetRun() + "/."; |
|
|
cat.info(command); |
|
|
system(command.c_str()); |
|
189 |
} |
} |
190 |
|
|