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

Annotation of /YodaProfiler/src/YodaProfiler.cpp

Parent Directory Parent Directory | Revision Log Revision Log


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

  ViewVC Help
Powered by ViewVC 1.1.23