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

Annotation of /yoda/techmodel/techmodelreader.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 6.7 - (hide annotations) (download)
Mon Oct 16 16:02:21 2006 UTC (18 years, 1 month 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 kusanagi 1.1
2 kusanagi 1.7 #include <log4cxx/logger.h>
3     #include <log4cxx/propertyconfigurator.h>
4 kusanagi 1.1 #include "EventReader.h"
5     #include <time.h>
6 mocchiut 6.7 #include "../event/yodaversion.h"
7 kusanagi 1.1 extern "C" {
8 kusanagi 5.1 #include <dirent.h>
9 kusanagi 1.1 }
10    
11     using namespace pamela;
12 kusanagi 1.7 using namespace log4cxx;
13     using namespace std;
14 kusanagi 1.1 using namespace pamela::techmodel;
15    
16 kusanagi 1.7 static LoggerPtr logger = Logger::getLogger(_T("pamela.techmodel.TechmodelReader"));
17 mocchiut 6.6
18 kusanagi 1.1 int main(int argc, char* argv[]) {
19 kusanagi 1.7
20     stringstream oss;
21     int maxPackets = 0;
22 kusanagi 5.1 bool multiFile = 0;
23     short compression = 3;
24 kusanagi 1.7 char nomeFileLog[L_tmpnam];
25 kusanagi 6.3 mkstemp(nomeFileLog);
26 kusanagi 1.7 DIR *dirp;
27 kusanagi 6.1 char *outDir = "";
28    
29 kusanagi 1.7 //---------------- 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 kusanagi 6.1
48 kusanagi 1.1 // Check file name
49 kusanagi 1.7
50     if (argc < 2){
51     //logger->info(_T("You have forgotten the file name."));
52     cout << "You have forgotten the file name. \n";
53 kusanagi 6.2 cout << "Try '-help' for more information. \n";
54 kusanagi 1.7 exit(1);
55     }
56    
57 kusanagi 6.2 if (!strcmp(argv[1], "-help")){
58 kusanagi 1.7 cout << "Usage: yoda FILE [OPTION] \n";
59 kusanagi 6.2 cout << "\t -help print this help and exit \n";
60     cout << "\t -version print version number \n";
61 kusanagi 1.7 cout << "\t -p maximum number of packets to process [default all] \n";
62 kusanagi 6.1 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 kusanagi 1.7 exit(1);
66     }
67    
68 kusanagi 6.2 if (!strcmp(argv[1], "-version")){
69 mocchiut 6.6 printf(" Version %i \n",GetYODAver());
70     // cout << "$Name: $ $Revision: 6.5 $" << "\n";
71 kusanagi 6.2 exit(1);
72     }
73    
74 kusanagi 1.7 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 kusanagi 1.1 exit(1);
79     }
80    
81 kusanagi 1.7 for (int i = 2; i < argc; i++){
82     if (!strcmp(argv[i], "-p")){
83     if (++i >= argc){
84     cerr << "-p needs arguments. \n";
85 kusanagi 6.2 cout << "Try '-help' for more information. \n";
86 kusanagi 1.7 exit(1);
87     }
88 kusanagi 5.1 if (isdigit(*argv[i]) && (atoi(argv[i]) > 0)) {
89 kusanagi 1.7 maxPackets = atoi(argv[i]);
90     } else {
91     //logger->info(_T("The file does not exist."));
92     cerr << "-p needs a integer value. \n";
93 kusanagi 6.2 cout << "Try '-help' for more information. \n";
94 kusanagi 1.7 exit(1);
95     }
96 kusanagi 5.1 continue;
97 kusanagi 1.7 }
98    
99 kusanagi 6.1 if (!strcmp(argv[i], "-multi")) multiFile = 1;
100 kusanagi 5.1
101     if (!strcmp(argv[i], "-c")){
102     if (++i >= argc){
103     cerr << "-c needs arguments. \n";
104 kusanagi 6.2 cout << "Try '-help' for more information. \n";
105 kusanagi 5.1 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 kusanagi 6.2 cout << "Try '-help' for more information. \n";
113 kusanagi 5.1 exit(1);
114     }
115     continue;
116 kusanagi 1.7 }
117 kusanagi 6.1
118     if (!strcmp(argv[i], "-o")){
119     if (++i >= argc){
120     cerr << "-o needs arguments. \n";
121 kusanagi 6.2 cout << "Try '-help' for more information. \n";
122 kusanagi 6.1 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 kusanagi 6.2 cout << "Try '-help' for more information. \n";
132 kusanagi 6.1 exit(1);
133     }
134     continue;
135     }
136    
137 kusanagi 1.7 }
138 kusanagi 1.6
139 kusanagi 6.1 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 kusanagi 1.1 time_t rawtime;
159     struct tm * timeinfo;
160     time ( &rawtime );
161     timeinfo = localtime ( &rawtime );
162 kusanagi 1.7
163 kusanagi 2.1 oss.str("");
164 kusanagi 1.7 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 kusanagi 1.1 gROOT->SetBatch(kTRUE);
170 kusanagi 1.7 EventReader *reader = new EventReader(maxPackets);
171 kusanagi 1.1
172     int num = 0;
173 kusanagi 5.1 TechmodelPamelaRun Run(argv[1], outDir, multiFile, compression);
174 kusanagi 1.7 reader->Init(&Run);
175    
176 kusanagi 2.1 oss.str("");
177 kusanagi 1.7 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 kusanagi 1.1 Run.WriteFiles();
183 kusanagi 1.7
184     logger->info("<-------------------------------END UNPACKING------------------------------->\n");
185 mocchiut 6.6 printf("Finished, exiting...\n");
186 pam-rm2 6.5
187 kusanagi 1.7 //Momentarly suspended the save
188     //system(command.c_str());
189 kusanagi 1.1 }
190 kusanagi 6.2

  ViewVC Help
Powered by ViewVC 1.1.23