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

Annotation of /yoda/techmodel/techmodelreader.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 6.8 - (hide annotations) (download)
Fri Oct 19 08:14:52 2007 UTC (17 years, 1 month ago) by mocchiut
Branch: MAIN
CVS Tags: YODA6_3/20, HEAD
Changes since 6.7: +2 -1 lines
Added headers to compile with ROOT v5.16/x

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.8 #include <TROOT.h>
7 mocchiut 6.7 #include "../event/yodaversion.h"
8 kusanagi 1.1 extern "C" {
9 kusanagi 5.1 #include <dirent.h>
10 kusanagi 1.1 }
11    
12     using namespace pamela;
13 kusanagi 1.7 using namespace log4cxx;
14     using namespace std;
15 kusanagi 1.1 using namespace pamela::techmodel;
16    
17 kusanagi 1.7 static LoggerPtr logger = Logger::getLogger(_T("pamela.techmodel.TechmodelReader"));
18 mocchiut 6.6
19 kusanagi 1.1 int main(int argc, char* argv[]) {
20 kusanagi 1.7
21     stringstream oss;
22     int maxPackets = 0;
23 kusanagi 5.1 bool multiFile = 0;
24     short compression = 3;
25 kusanagi 1.7 char nomeFileLog[L_tmpnam];
26 kusanagi 6.3 mkstemp(nomeFileLog);
27 kusanagi 1.7 DIR *dirp;
28 kusanagi 6.1 char *outDir = "";
29    
30 kusanagi 1.7 //---------------- Log4cxx configuration-----------------------------------------------
31     //BasicConfigurator::configure();
32     //Retrieve the rootLogger and append to it a default FileAppender.
33     //Note that the priority level of the rootLogger (defined in log4cxx.conf) is unmodified
34     //LoggerPtr rootLogger = Logger::getRootLogger();
35    
36     //FileAppender *fileAppender = new FileAppender();
37     //fileAppender->setFile(pathLog);
38     //fileAppender->setAppend(false);
39     //fileAppender->setBufferedIO(true); //the default size is 8k
40     //fileAppender->setBufferSize(1000000);
41     //fileAppender->activateOptions();
42     //fileAppender->setLayout(new PatternLayout());
43    
44     //FileAppender *fileAppender = new FileAppender(new PatternLayout(), pathLog, false, true, 10000);
45     //rootLogger->addAppender(fileAppender);
46     //rootLogger->removeAppender('A1');
47     //---------------- Log4cxx configuration-----------------------------------------------
48 kusanagi 6.1
49 kusanagi 1.1 // Check file name
50 kusanagi 1.7
51     if (argc < 2){
52     //logger->info(_T("You have forgotten the file name."));
53     cout << "You have forgotten the file name. \n";
54 kusanagi 6.2 cout << "Try '-help' for more information. \n";
55 kusanagi 1.7 exit(1);
56     }
57    
58 kusanagi 6.2 if (!strcmp(argv[1], "-help")){
59 kusanagi 1.7 cout << "Usage: yoda FILE [OPTION] \n";
60 kusanagi 6.2 cout << "\t -help print this help and exit \n";
61     cout << "\t -version print version number \n";
62 kusanagi 1.7 cout << "\t -p maximum number of packets to process [default all] \n";
63 kusanagi 6.1 cout << "\t -multi generate multiple root files \n";
64     cout << "\t -c set the compression level for the generated root file(s). Values: [0,9] [default = 3]\n";
65     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";
66 kusanagi 1.7 exit(1);
67     }
68    
69 kusanagi 6.2 if (!strcmp(argv[1], "-version")){
70 mocchiut 6.6 printf(" Version %i \n",GetYODAver());
71 mocchiut 6.8 // cout << "$Name: $ $Revision: 6.7 $" << "\n";
72 kusanagi 6.2 exit(1);
73     }
74    
75 kusanagi 1.7 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 kusanagi 1.1 exit(1);
80     }
81    
82 kusanagi 1.7 for (int i = 2; i < argc; i++){
83     if (!strcmp(argv[i], "-p")){
84     if (++i >= argc){
85     cerr << "-p needs arguments. \n";
86 kusanagi 6.2 cout << "Try '-help' for more information. \n";
87 kusanagi 1.7 exit(1);
88     }
89 kusanagi 5.1 if (isdigit(*argv[i]) && (atoi(argv[i]) > 0)) {
90 kusanagi 1.7 maxPackets = atoi(argv[i]);
91     } else {
92     //logger->info(_T("The file does not exist."));
93     cerr << "-p needs a integer value. \n";
94 kusanagi 6.2 cout << "Try '-help' for more information. \n";
95 kusanagi 1.7 exit(1);
96     }
97 kusanagi 5.1 continue;
98 kusanagi 1.7 }
99    
100 kusanagi 6.1 if (!strcmp(argv[i], "-multi")) multiFile = 1;
101 kusanagi 5.1
102     if (!strcmp(argv[i], "-c")){
103     if (++i >= argc){
104     cerr << "-c needs arguments. \n";
105 kusanagi 6.2 cout << "Try '-help' for more information. \n";
106 kusanagi 5.1 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 kusanagi 6.2 cout << "Try '-help' for more information. \n";
114 kusanagi 5.1 exit(1);
115     }
116     continue;
117 kusanagi 1.7 }
118 kusanagi 6.1
119     if (!strcmp(argv[i], "-o")){
120     if (++i >= argc){
121     cerr << "-o needs arguments. \n";
122 kusanagi 6.2 cout << "Try '-help' for more information. \n";
123 kusanagi 6.1 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 kusanagi 6.2 cout << "Try '-help' for more information. \n";
133 kusanagi 6.1 exit(1);
134     }
135     continue;
136     }
137    
138 kusanagi 1.7 }
139 kusanagi 1.6
140 kusanagi 6.1 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    
159 kusanagi 1.1 time_t rawtime;
160     struct tm * timeinfo;
161     time ( &rawtime );
162     timeinfo = localtime ( &rawtime );
163 kusanagi 1.7
164 kusanagi 2.1 oss.str("");
165 kusanagi 1.7 oss << "<-------------------------------START UNPACKING------------------------------->\n"
166     << " Starting the program at: " << asctime (timeinfo) << " Opening file: " << argv[1];
167     logger->info(oss.str().c_str());
168    
169    
170 kusanagi 1.1 gROOT->SetBatch(kTRUE);
171 kusanagi 1.7 EventReader *reader = new EventReader(maxPackets);
172 kusanagi 1.1
173     int num = 0;
174 kusanagi 5.1 TechmodelPamelaRun Run(argv[1], outDir, multiFile, compression);
175 kusanagi 1.7 reader->Init(&Run);
176    
177 kusanagi 2.1 oss.str("");
178 kusanagi 1.7 oss << "Init successul ok" << asctime (timeinfo);
179     logger->debug(oss.str().c_str());
180    
181     reader->RunEvent(num); //TBD --- eliminate the runNumber
182     reader->Finish();
183 kusanagi 1.1 Run.WriteFiles();
184 kusanagi 1.7
185     logger->info("<-------------------------------END UNPACKING------------------------------->\n");
186 mocchiut 6.6 printf("Finished, exiting...\n");
187 pam-rm2 6.5
188 kusanagi 1.7 //Momentarly suspended the save
189     //system(command.c_str());
190 kusanagi 1.1 }
191 kusanagi 6.2

  ViewVC Help
Powered by ViewVC 1.1.23