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

Annotation of /YodaProfiler/src/YodaProfiler.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1.1.1 - (hide annotations) (download) (vendor branch)
Wed Aug 30 11:18:13 2006 UTC (18 years, 3 months ago) by mocchiut
Branch: YodaProfiler
CVS Tags: v0r00, start
Changes since 1.1: +0 -0 lines
Imported sources

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

  ViewVC Help
Powered by ViewVC 1.1.23