/[PAMELA software]/YodaProfiler/src/YodaProfiler.cpp
ViewVC logotype

Annotation of /YodaProfiler/src/YodaProfiler.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (hide annotations) (download)
Fri Sep 1 12:47:13 2006 UTC (18 years, 3 months ago) by mocchiut
Branch: MAIN
CVS Tags: v1r02
Changes since 1.1: +80 -34 lines
First release of the new profiler

1 mocchiut 1.1 //
2     #include <iostream>
3     #include <sstream>
4     #include <errno.h>
5     //
6     #include <TSystem.h>
7     //
8     #include <PamelaDBOperations.h>
9     #include <YodaProfilerVerl2.h>
10     //
11     using namespace std;
12     //
13     // Usage subroutine
14     //
15     void usage(){
16     printf("\nUsage:\n");
17 mocchiut 1.2 printf("\n YodaProfiler [options] -rawFile raw_filename -yodaFile yoda_filename \n");
18     printf("\n -rawFile full path to the raw file\n");
19     printf("\n -yodaFile full path to the YODA file\n");
20     printf("\n Options can be: \n");
21 mocchiut 1.1 printf("\n --version print informations about compilation and exit\n");
22     printf("\n -h | --help print this help and exit \n");
23     printf("\n -v | --verbose be verbose [default: print nothing on STDOUT]\n");
24     printf("\n -g | --debug be very verbose [default: no]\n");
25     printf("\n -boot number CPU boot number [default = taken from VarDump]\n");
26     printf("\n -tsync number timesync (s) [default = taken from data]\n");
27     printf("\n -obt0 number obt at timesync (ms) [default = taken from data]\n");
28 mocchiut 1.2 printf("\n -clean number number in seconds after which the fragment table\n");
29     printf("\n can be cleaned and runs validated [default = 864000 (10 days)],\n");
30     printf("\n if 0 force cleaning immediatly, if negative do not clean\n");
31 mocchiut 1.1 printf("\n -host name for the host [default = mysql://localhost/pamelaprod]\n");
32     printf("\n -user username for the DB [default = anonymous] \n");
33     printf("\n -psw password for the DB [default = \"\"]\n");
34 mocchiut 1.2 printf("\n The order of input files and options does not matter. \n");
35     printf("\nExample: \n");
36     printf("\n YodaProfiler -yodaFile /path/to/raw/files/000_000_00000_cln2.pam -rawFile /path/to/filesfromyoda/000_000_00000_cln2.root -v \n\n");
37 mocchiut 1.1 };
38     //
39     int main(int numinp, char *inps[]){
40     //
41     // Variables booking
42     //
43     Int_t signal = 0;
44     Int_t nul = 0;
45     UInt_t boot = 0;
46     UInt_t tsync = 0;
47     UInt_t obt0 = 0;
48 mocchiut 1.2 Long64_t olderthan = 864000LL;
49 mocchiut 1.1 //
50     //
51     TString filerawname;
52     //
53     TString host;
54     TString user;
55     TString password;
56     //
57     TString filerootname;
58     //
59     Bool_t beverbose = false;
60     Bool_t debug = false;
61     Int_t i = 0;
62     //
63     if ( numinp > 1 ){
64     while ( i < numinp ){
65     if ( !strcmp(inps[i],"--version") ){
66     YodaProfilerInfo(true);
67     exit(0);
68     };
69     if ( !strcmp(inps[i],"-h") || !strcmp(inps[i],"--help") ){
70     usage();
71     exit(0);
72     };
73     if ( !strcmp(inps[i],"-rawFile") ) {
74     if ( numinp-1 < i+1 ){
75     usage();
76     exit(1);
77     };
78     filerawname = (TString)inps[i+1];
79     };
80     if ( !strcmp(inps[i],"-yodaFile") ) {
81     if ( numinp-1 < i+1 ){
82     usage();
83     exit(1);
84     };
85     filerootname = (TString)inps[i+1];
86     };
87     if ( !strcmp(inps[i],"-boot") ) {
88     if ( numinp-1 < i+1 ){
89     usage();
90     exit(1);
91     };
92     boot = atoi(inps[i+1]);
93     };
94     if ( !strcmp(inps[i],"-tsync") ) {
95     if ( numinp-1 < i+1 ){
96     usage();
97     exit(1);
98     };
99 mocchiut 1.2 tsync = (UInt_t)atoll(inps[i+1]);
100 mocchiut 1.1 };
101     if ( !strcmp(inps[i],"-obt0") ) {
102     if ( numinp-1 < i+1 ){
103     usage();
104     exit(1);
105     };
106 mocchiut 1.2 obt0 = (UInt_t)atoll(inps[i+1]);
107     };
108     if ( !strcmp(inps[i],"-clean") ) {
109     if ( numinp-1 < i+1 ){
110     usage();
111     exit(1);
112     };
113     olderthan = (Long64_t)atoll(inps[i+1]);
114 mocchiut 1.1 };
115     if ( !strcmp(inps[i],"-host") ) {
116     if ( numinp-1 < i+1 ){
117     usage();
118     exit(1);
119     };
120     host = (TString)inps[i+1];
121     };
122     if ( !strcmp(inps[i],"-user") ) {
123     if ( numinp-1 < i+1 ){
124     usage();
125     exit(1);
126     };
127     user = (TString)inps[i+1];
128     };
129     if ( !strcmp(inps[i],"-psw") ) {
130     if ( numinp-1 < i+1 ){
131     usage();
132     exit(1);
133     };
134     password = (TString)inps[i+1];
135     };
136     //
137     if ( !strcmp(inps[i],"-v") || !strcmp(inps[i],"--verbose") ) beverbose = true;
138     //
139     if ( !strcmp(inps[i],"-g") || !strcmp(inps[i],"--debug") ) debug = true;
140     //
141     i++;
142     };
143     } else {
144     //
145     // no input parameters exit with error, we need at least the run id.
146     //
147     cout << "\n ERROR: NO INPUT PARAMETERS \n";
148     usage();
149     exit(1);
150     };
151    
152     //
153     // If not in verbose mode redirect to /dev/null the stdout and stderr
154     //
155     if ( !beverbose ){
156     nul = open("/dev/null", O_CREAT | O_RDWR,S_IREAD | S_IWRITE);
157     dup2(nul,1);
158     dup2(nul,2);
159     };
160     //
161     // Start:
162     //
163     TString message;
164     char *version = YodaProfilerInfo(false);
165     PamelaDBOperations *pamDB = 0;
166     UInt_t sizeofwar = 10;
167     UInt_t WAR[10];
168     memset(WAR, 0, 10*sizeof(UInt_t));
169     //
170 mocchiut 1.2 printf("\n Welcome to the PAMELA YodaProfiler, version %s \n\n",version);
171 mocchiut 1.1 try{
172     //
173     //-------------------------------------------------------------------------------------------
174     // Create pamDB object and open SQL connection
175     //-------------------------------------------------------------------------------------------
176 mocchiut 1.2 if ( beverbose ) printf(" 1 => Initialize and open SQL connection \n");
177 mocchiut 1.1 pamDB = new PamelaDBOperations(host,user,password,filerawname,filerootname,boot,tsync,obt0,debug);
178     pamDB->CheckFile();
179 mocchiut 1.2 pamDB->SetOlderThan(olderthan);
180 mocchiut 1.1 //-------------------------------------------------------------------------------------------
181     //
182     //-------------------------------------------------------------------------------------------
183     //Insert a Raw file in GL_RAW
184     //-------------------------------------------------------------------------------------------
185     if ( beverbose ) printf(" 2 => Insert a RAW file in GL_RAW \n");
186     WAR[0] = pamDB->insertPamelaRawFile();
187     //-------------------------------------------------------------------------------------------
188     //-------------------------------------------------------------------------------------------
189     //Update a single GL_RAW record with its BOOT_NUMBER
190     //-------------------------------------------------------------------------------------------
191     if ( beverbose ) printf(" 3 => Update a single GL_RAW record with its BOOT_NUMBER \n");
192     WAR[3] = pamDB->assignBOOT_NUMBER();
193     // if ( WAR[3] ) pamDB->SetNOBOOT(true);
194     if ( WAR[3] && WAR[3] != 1 ) throw -9;
195     //-------------------------------------------------------------------------------------------
196     //
197     //-------------------------------------------------------------------------------------------
198     //Insert an entry in GL_TIMESYNC
199     //-------------------------------------------------------------------------------------------
200     if ( beverbose ) printf(" 4 => Insert an entry in GL_TIMESYNC \n");
201     WAR[1] = pamDB->insertPamelaGL_TIMESYNC();
202     //-------------------------------------------------------------------------------------------
203     //
204     //-------------------------------------------------------------------------------------------
205     //Insert unpack ROOT file in GL_ROOT
206     //-------------------------------------------------------------------------------------------
207     if ( beverbose ) printf(" 5 => Insert unpack ROOT file in GL_ROOT \n");
208     WAR[2] = pamDB->insertPamelaRootFile();
209     //-------------------------------------------------------------------------------------------
210     //
211    
212     //-------------------------------------------------------------------------------------------
213     //Insert in GL_RUN runs information records relative to a single unpack
214     //-------------------------------------------------------------------------------------------
215     if ( beverbose ) printf(" 6 => Scan physics and store runs in the GL_RUN table\n");
216     WAR[4] = pamDB->insertPamelaRUN();
217     //-------------------------------------------------------------------------------------------
218    
219     //-------------------------------------------------------------------------------------------
220     //Insert in GL_CALO_CALIB calibration information records relative to a single unpack
221     //-------------------------------------------------------------------------------------------
222     if ( beverbose ) printf(" 7 => Insert calorimeter calibrations in the GL_CALO_CALIB table\n");
223     WAR[5] = pamDB->insertCALO_CALIB();
224     //-------------------------------------------------------------------------------------------
225    
226     //-------------------------------------------------------------------------------------------
227     //Insert in GL_TRK_CALIB calibration information records relative to a single unpack
228     //-------------------------------------------------------------------------------------------
229     if ( beverbose ) printf(" 8 => Insert tracker calibrations in the GL_TRK_CALIB table\n");
230     WAR[6] = pamDB->insertTRK_CALIB();
231     //-------------------------------------------------------------------------------------------
232    
233     //-------------------------------------------------------------------------------------------
234     //Insert in GL_S4_CALIB calibration information records relative to a single unpack
235     //-------------------------------------------------------------------------------------------
236     if ( beverbose ) printf(" 9 => Insert S4 calibrations in the GL_S4_CALIB table\n");
237     WAR[7] = pamDB->insertS4_CALIB();
238     //-------------------------------------------------------------------------------------------
239    
240 mocchiut 1.2 //-------------------------------------------------------------------------------------------
241     //Clean the GL_RUN_FRAGMENTS
242     //-------------------------------------------------------------------------------------------
243     if ( beverbose ) printf(" 10 => Clean the GL_RUN_FRAGMENTS table\n");
244     WAR[8] = pamDB->CleanGL_RUN_FRAGMENTS();
245     //-------------------------------------------------------------------------------------------
246    
247     //-------------------------------------------------------------------------------------------
248     //Validate runs
249     //-------------------------------------------------------------------------------------------
250     if ( beverbose ) printf(" 11 => Validate runs\n");
251     WAR[9] = pamDB->ValidateRuns();
252     //-------------------------------------------------------------------------------------------
253    
254 mocchiut 1.1 } catch (Int_t exc) {
255     signal = exc;
256     switch(exc){
257     case -1: message += " DB connection failure"; break;
258     case -2: message += " Connection failure"; break;
259     case -3: message += " Cannot determine the timesync, use the -tsync and -obt0 options to override"; break;
260     case -4: message += " Error querying DB"; break;
261     case -5: message += " Inconsistent OBT/pkt_num"; break;
262     case -6: message += " The file is not in the database"; break;
263     case -8: message += " Event file is empty"; break;
264     case -9: message += " No VarDump no BOOT number, use the -boot option to override"; break;
265     case -10: message += " No results from DB"; break;
266     case -11: message += " Raw file not found"; break;
267     case -12: message += " Cannot open Level0 file"; break;
268     case -13: message += " No consistent OBT/PKT_NUM information"; break;
269     case -14: message += " Not supported yet: run with no events, no runtrailer, no runheader"; break;
270     case -15: message += " Not supported yet: run with no runheader at the beginning/end of file not recognized as run fragment"; break;
271     case -16: message += " No Physics tree in Level0 file"; break;
272     case -17: message += " No RunHeader tree in Level0 file"; break;
273     case -18: message += " No RunTrailer tree in Level0 file"; break;
274     case -19: message += " No Mcmd tree in Level0 file"; break;
275     case -20: message += " No VarDump tree in Level0 file"; break;
276     case -21: message += " No CalibCalPed tree in Level0 file"; break;
277     case -22: message += " No CalibTrk1 tree in Level0 file"; break;
278     case -23: message += " No CalibTrk2 tree in Level0 file"; break;
279     case -24: message += " No CalibS4 tree in Level0 file"; break;
280 mocchiut 1.2 case -25: message += " Cannot find the run just inserted"; break;
281     case -26: message += " Raw file not found looking for VarDump"; break;
282 mocchiut 1.1 default: message += " Unidentified error"; break;
283     };
284     printf("\n");
285     printf(" ERROR (%i) %s \n",exc,message.Data());
286     printf("\n");
287     }
288     //
289     // warnings handlers
290     //
291     Bool_t printwarning = false;
292     message="";
293     for (UInt_t j=0; j<sizeofwar; j++){
294     if ( WAR[j] ){
295     printwarning = true;
296     //
297     if ( j == 0 ){ // insertPamelaRaw warnings
298     for (UInt_t bit=0; bit<32; bit++){
299     if ( WAR[j] & (1 << bit) ){
300     if ( bit == 0 ) message += "=> RAW file already inserted\n";
301 mocchiut 1.2 else message += "=> Unidentified insertPamelaRaw warning\n";
302 mocchiut 1.1 };
303     };
304     };
305     //
306     if ( j == 1 ){ // insertTimeSync warnings
307     for (UInt_t bit=0; bit<32; bit++){
308     if ( WAR[j] & (1 << bit) ){
309     if ( bit == 0 ) message += "=> TIMESYNC already inserted\n";
310 mocchiut 1.2 else if ( bit == 1 ) message += "=> No mcmd timesync in the file\n";
311     else if ( bit == 2 ) message += "=> No runheaders in the file\n";
312     else if ( bit == 3 ) message += "=> No runtrailers in the file\n";
313     else if ( bit == 4 ) message += "=> No mcmd inclination in the file\n";
314     else message += "=> Unidentified insertTimeSync warning\n";
315 mocchiut 1.1 };
316     };
317     };
318     //
319     if ( j == 2 ){ // insertPamelaRoot warnings
320     for (UInt_t bit=0; bit<32; bit++){
321     if ( WAR[j] & (1 << bit) ){
322     if ( bit == 0 ) message += "=> ROOT file already inserted\n";
323 mocchiut 1.2 else message += "=> Unidentified insertPamelaRoot warning\n";
324 mocchiut 1.1 };
325     };
326     };
327     //
328     if ( j == 3 ){ // assignBOOTnumber warnings
329     for (UInt_t bit=0; bit<32; bit++){
330     if ( WAR[j] & (1 << bit) ){
331 mocchiut 1.2 if ( bit == 0 ) message += "=> BOOT number already inserted\n";//
332     else if ( bit == 1 ) message += "=> VarDump event tree is empty, use the -boot option to override\n";//
333     else if ( bit == 2 ) message += "=> No BOOT number in VarDump(!), use the -boot option to override\n";//
334     else if ( bit == 4 ) message += "=> The file is not in the database looking for VarDump, use the -boot option to override\n";//
335     else message += "=> Unidentified assignBOOTnumber warning\n";
336 mocchiut 1.1 };
337     };
338     };
339     //
340     if ( j == 4 ){ // insertPamelaRUN
341     for (UInt_t bit=0; bit<32; bit++){
342     if ( WAR[j] & (1 << bit) ){
343 mocchiut 1.2 if ( bit == 0 ) message += "=> Inconsistent PKT/OBT sequence\n";
344     else if ( bit == 1 ) message += "=> No physics events in the file\n";
345     else if ( bit == 2 ) message += "=> Less than 2 physics events in the file\n";
346     else message += "=> Unidentified insertPamelaRun warning\n";
347 mocchiut 1.1 };
348     };
349     };
350     //
351     if ( j == 5 ){ // insertCALO_CALIB
352     for (UInt_t bit=0; bit<32; bit++){
353     if ( WAR[j] & (1 << bit) ){
354 mocchiut 1.2 if ( bit == 0 ) message += "=> No calorimeter calibrations in the file\n";
355     else message += "=> Unidentified insertCaloCalib warning\n";
356 mocchiut 1.1 };
357     };
358     };
359     //
360     //
361     if ( j == 6 ){ // insertTRACKER_CALIB
362     for (UInt_t bit=0; bit<32; bit++){
363     if ( WAR[j] & (1 << bit) ){
364 mocchiut 1.2 if ( bit == 0 ) message += "=> No tracker calibrations in the file\n";
365     else message += "=> Unidentified insertTrkCalib warning\n";
366 mocchiut 1.1 };
367     };
368     };
369     //
370     //
371     if ( j == 7 ){ // insertS4_CALIB
372     for (UInt_t bit=0; bit<32; bit++){
373     if ( WAR[j] & (1 << bit) ){
374 mocchiut 1.2 if ( bit == 0 ) message += "=> No s4 calibrations in the file\n";
375     else message += "=> Unidentified insertS4calib warning\n";
376     };
377     };
378     };
379     //
380     //
381     if ( j == 8 ){ // CleanGL_RUN_FRAGMENTS
382     for (UInt_t bit=0; bit<32; bit++){
383     if ( WAR[j] & (1 << bit) ){
384     if ( bit == 0 ) message += "=> Skip the GL_RUN_FRAGMENTS table cleaning\n";
385     else message += "=> Unidentified CleanGL_RUN_FRAGMENTS warning\n";
386 mocchiut 1.1 };
387     };
388     };
389     //
390 mocchiut 1.2 if ( j == 9 ){ // ValidateRuns
391     for (UInt_t bit=0; bit<32; bit++){
392     if ( WAR[j] & (1 << bit) ){
393     if ( bit == 0 ) message += "=> Skip the run validation \n";
394     else message += "=> Unidentified ValidateRuns warning\n";
395     };
396     };
397     };
398 mocchiut 1.1 };
399     };
400     //
401     if ( printwarning ){
402     printf("\n");
403     printf(" WARNING(s):\n%s\n",message.Data());
404     printf("\n");
405     if ( !signal ) signal = 1;
406     };
407     //
408     //---------------------------------------------------------------------------------------
409     // Close and exit
410     //---------------------------------------------------------------------------------------
411 mocchiut 1.2 if ( beverbose ) printf(" 12 => Free objects and close SQL connection \n");
412 mocchiut 1.1 pamDB->Close();
413     //
414     printf("\n");
415     printf(" Finished, exiting...\n");
416     printf("\n");
417     //
418     // Close redirection if the case.
419     //
420     if ( !beverbose ) close(nul);
421     //
422     exit(signal);
423     //
424     }

  ViewVC Help
Powered by ViewVC 1.1.23