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" |
20 |
} |
} |
21 |
|
|
22 |
|
|
23 |
|
|
24 |
using namespace pamela; |
using namespace pamela; |
25 |
|
using namespace log4cxx; |
26 |
|
using namespace std; |
27 |
using namespace pamela::techmodel; |
using namespace pamela::techmodel; |
28 |
|
|
29 |
static log4cpp::Category& cat = log4cpp::Category::getInstance("pamela.techmodel.TechmodelReader"); |
static LoggerPtr logger = Logger::getLogger(_T("pamela.techmodel.TechmodelReader")); |
30 |
|
|
31 |
int main(int argc, char* argv[]) { |
int main(int argc, char* argv[]) { |
32 |
|
|
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 |
|
bool ANALIZE = false; |
41 |
|
//---------------- 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 |
// Check file name |
// Check file name |
63 |
if (argc != 2){ |
|
64 |
cat.info("You have forgotten the file name"); |
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); |
exit(1); |
69 |
} |
} |
|
|
|
|
std::ifstream from (argv[1]); |
|
|
if (!from) cat.info("The file does not exist"); |
|
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 |
|
cout << "\t -analize generate pre-defined analisys files (gif/text) inside the unpacking directory\n"; |
76 |
|
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 |
|
exit(1); |
84 |
|
} |
85 |
|
|
86 |
/*try { |
for (int i = 2; i < argc; i++){ |
87 |
log4cpp::PropertyConfigurator::configure("/home/kusanagi/yoda/techmodel/YodaLog.conf"); |
if (!strcmp(argv[i], "-p")){ |
88 |
} catch (log4cpp::ConfigureFailure& f) { |
if (++i >= argc){ |
89 |
std::cerr << "Logging Configure Problem " << f.what() << std::endl; |
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 |
|
|
108 |
|
if (!strcmp(argv[i], "-analize")) ANALIZE = true; |
109 |
|
|
110 |
|
} |
111 |
|
|
112 |
|
|
113 |
//-------------------------------------------------- |
//-------------------------------------------------- |
114 |
//This is the configuration for the Yoda Logger |
//This is the configuration for the Yoda Logger |
115 |
//The parameters in the RollingFileAppender means |
//The parameters in the RollingFileAppender means |
117 |
// YodaLog.txt ------------>the LogFile name |
// YodaLog.txt ------------>the LogFile name |
118 |
// 1000 ------------>The max size (in Kb) of the LogFile |
// 1000 ------------>The max size (in Kb) of the LogFile |
119 |
// 5 ------------>How many times the file will be backup |
// 5 ------------>How many times the file will be backup |
120 |
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); |
|
121 |
time_t rawtime; |
time_t rawtime; |
122 |
struct tm * timeinfo; |
struct tm * timeinfo; |
|
|
|
123 |
time ( &rawtime ); |
time ( &rawtime ); |
124 |
timeinfo = localtime ( &rawtime ); |
timeinfo = localtime ( &rawtime ); |
125 |
//-------------------------------------------------- |
|
126 |
cat << log4cpp::Priority::INFO |
oss.str(""); |
127 |
<< "<-------------------------------START UNPACKING------------------------------->\n" |
oss << "<-------------------------------START UNPACKING------------------------------->\n" |
128 |
<< " Starting the program at: " << asctime (timeinfo) << " Opening file: " << argv[1] |
<< " Starting the program at: " << asctime (timeinfo) << " Opening file: " << argv[1]; |
129 |
<< "\n \n" << log4cpp::CategoryStream::ENDLINE; |
logger->info(oss.str().c_str()); |
130 |
|
|
131 |
|
|
132 |
gROOT->SetBatch(kTRUE); |
gROOT->SetBatch(kTRUE); |
133 |
|
EventReader *reader = new EventReader(maxPackets); |
|
EventReader Reader; |
|
134 |
|
|
135 |
int num = 0; |
int num = 0; |
136 |
TechmodelPamelaRun Run(argv[1]); |
TechmodelPamelaRun Run(argv[1]); |
137 |
Reader.Init(&Run); |
reader->Init(&Run); |
138 |
cat << log4cpp::Priority::INFO |
|
139 |
<< "Init successul ok" << asctime (timeinfo) << log4cpp::CategoryStream::ENDLINE; |
oss.str(""); |
140 |
Reader.RunEvent(num); //TBD --- eliminate the runNumber |
oss << "Init successul ok" << asctime (timeinfo); |
141 |
Reader.Finish(); |
logger->debug(oss.str().c_str()); |
142 |
|
|
143 |
|
reader->RunEvent(num); //TBD --- eliminate the runNumber |
144 |
|
reader->Finish(); |
145 |
Run.WriteFiles(); |
Run.WriteFiles(); |
146 |
cat << log4cpp::Priority::INFO |
|
147 |
<< "<-------------------------------END UNPACKING------------------------------->" |
logger->info("<-------------------------------END UNPACKING------------------------------->\n"); |
148 |
<< "\n " << log4cpp::CategoryStream::ENDLINE; |
|
149 |
log4cpp::Category::shutdown(); |
//Momentarly suspended the save |
150 |
std::string command; |
//system(command.c_str()); |
|
command = "mv " + pathLog + " " + pathDir + "/" + Run.GetRun() + "/."; |
|
|
cat.info(command); |
|
|
system(command.c_str()); |
|
151 |
} |
} |