/[PAMELA software]/yoda/techmodel/techmodelreader.cpp
ViewVC logotype

Contents of /yoda/techmodel/techmodelreader.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 6.7 - (show annotations) (download)
Mon Oct 16 16:02:21 2006 UTC (18 years, 2 months ago) by mocchiut
Branch: MAIN
CVS Tags: YODA6_3/19, YODA6_3/18, YODA6_3/13, YODA6_3/17, YODA6_3/16, YODA6_3/15, YODA6_3/14
Changes since 6.6: +1 -5 lines
libyoda.so linking bug fixed, do not print on screen tracker errors

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

  ViewVC Help
Powered by ViewVC 1.1.23