// #include #include #include // #include // #include #include #include // using namespace std; // // Usage subroutine // void usage(){ printf("\nUsage:\n"); printf("\n YodaProfiler [options] -rawFile raw_filename -yodaFile yoda_filename \n"); printf("\n -rawFile full path to the raw file\n"); printf( " -yodaFile full path to the YODA file OR ID of the file to be processed\n"); printf("\n Options are:\n\n"); printf(" --version print informations about compilation and exit\n"); printf(" -h | --help print this help and exit \n"); printf(" -v | --verbose be verbose [default]\n"); printf(" -s | --silent print nothing on STDOUT\n"); printf(" -g | --debug be very verbose [default: no]\n"); printf(" -p | --pedantic be strict in checks, exit with error if any problem is found [default: no]\n"); printf(" -boot number CPU boot number [default = taken from VarDump]\n"); printf(" -autoboot if no VarDump found try to determine the BOOT number\n"); printf(" looking at timesync [default]\n"); printf(" -no-autoboot disable previous check\n"); printf(" -tsync number timesync (s) [default = taken from data]\n"); printf(" -obt0 number obt at timesync (ms) [default = taken from data]\n"); printf(" -dworbit number number is the downlink orbit number (to be used with non-standard names)\n"); printf(" -static use static path inside the DB instead of symbolic names\n"); // printf(" -gpamela shortcut to \"-clean 0 -obt0 1 -tsync 1 -no-autoboot -boot 1 -dworbit 1 -static\"\n"); printf(" -gpamela shortcut to \"-clean 0 -obt0 1 -no-autoboot -dworbit 1 -static\"\n"); printf(" -clean number number in seconds after which the fragment table\n"); printf(" can be cleaned and runs validated [default = -1 do not clean],\n"); printf(" if 0 force cleaning immediatly, if negative do not clean\n"); printf(" -remove file remove file and all related runs and calibrations from DB\n"); printf(" file must be the YODA filename (full path is not needed)\n"); printf(" 'same' can be used if in conjuction with -yodaFile\n"); printf(" -validate file validates runs between the two closest calibration to file \n"); printf(" not belonging to file itself. File must be the YODA filename\n"); printf(" 'same' can be used if in conjuction with -yodaFile\n"); printf(" -cleanfrag file clean run fragments for file only\n"); printf(" File must be the YODA filename\n"); printf(" 'same' can be used if in conjuction with -yodaFile\n"); printf(" -runpieces when cleaning fragments check if run are divided in more pieces [default: false in standard case, true for chewbacca files]\n"); printf(" -nofrag do not leave runs in the fragment table and look for fragments\n"); printf(" in the GL_RUN table.\n"); printf(" -f | -force to be used to reprocess a file or to process a file\n"); printf(" when already validated the surroundings, it is equivalent to:\n"); printf(" -remove same -validate same -cleanfrag same -nofrag\n"); printf(" -check performs some test on the GL_RUN table to check its consistency\n"); printf(" -checkfrom idrun performs some test on the GL_RUN table to check its consistency starting from run number idrun\n"); printf(" -checkto idrun performs some test on the GL_RUN table to check its consistency arriving till run number idrun\n"); printf(" -host name of the DB host [default = $PAM_DBHOST or mysql://localhost/pamelaprod]\n"); printf(" -user username for the DB connection [default = $PAM_DBUSER or \"anonymous\"] \n"); printf(" -psw password for the DB connection [default = $PAM_DBPSW or \"\"]\n"); printf(" -tle ascii file containing TLE obtained from celestrak.org or space-track.org [default = no]\n"); printf("\n The order of input files and options does not matter. \n"); printf("\n Example: \n"); printf(" YodaProfiler -yodaFile /path/to/raw/files/000_000_00000_cln2.root -rawFile /path/to/filesfromyoda/000_000_00000_cln2.pam -v \n\n"); }; // int main(int numinp, char *inps[]){ // // Variables booking // Int_t signal = 0; Int_t nul = 0; UInt_t boot = 0; UInt_t tsync = 0; UInt_t obt0 = 0; UInt_t dwinput = 0; UInt_t chfrom = 0; UInt_t chto = 0; Long64_t olderthan = -1LL; Bool_t runpieces = false; // // TString filerawname = ""; TString filerootname = ""; // TString host = "mysql://localhost/pamelaprod"; TString user = "anonymous"; TString password = ""; // TString tlefilename = ""; // const char *pamdbhost = gSystem->Getenv("PAM_DBHOST"); const char *pamdbuser = gSystem->Getenv("PAM_DBUSER"); const char *pamdbpsw = gSystem->Getenv("PAM_DBPSW"); if ( !pamdbhost ) pamdbhost = ""; if ( !pamdbuser ) pamdbuser = ""; if ( !pamdbpsw ) pamdbpsw = ""; if ( strcmp(pamdbhost,"") ) host = pamdbhost; if ( strcmp(pamdbuser,"") ) user = pamdbuser; if ( strcmp(pamdbpsw,"") ) password = pamdbpsw; // // Bool_t chewbacca = false; Bool_t staticp = false; Bool_t beverbose = true; Bool_t debug = false; Bool_t autoboot = true; Bool_t gpamela = false; // Bool_t remove = false; TString remfile = ""; // Bool_t forceclean = false; TString fcleanfile = ""; // Bool_t validate = false; TString validfile = ""; // Bool_t nofrag = false; // Bool_t force = false; // Bool_t check = false; // Bool_t pedantic = false; // Int_t i = 0; // if ( numinp > 1 ){ while ( i < numinp ){ if ( !strcmp(inps[i],"--version") ){ YodaProfilerInfo(true); exit(0); }; if ( !strcmp(inps[i],"-h") || !strcmp(inps[i],"--help") ){ usage(); exit(0); }; if ( !strcmp(inps[i],"-rawFile") ) { if ( numinp-1 < i+1 ){ usage(); exit(1); }; filerawname = (TString)inps[i+1]; }; if ( !strcmp(inps[i],"-yodaFile") ) { if ( numinp-1 < i+1 ){ usage(); exit(1); }; filerootname = (TString)inps[i+1]; if ( filerootname.IsDigit() ){ chewbacca = true; runpieces = true; }; }; if ( !strcmp(inps[i],"-remove") ) { if ( numinp-1 < i+1 ){ usage(); exit(1); }; remfile = (TString)inps[i+1]; remove = true; }; if ( !strcmp(inps[i],"-cleanfrag") ) { if ( numinp-1 < i+1 ){ usage(); exit(1); }; fcleanfile = (TString)inps[i+1]; forceclean = true; }; if ( !strcmp(inps[i],"-validate") ) { if ( numinp-1 < i+1 ){ usage(); exit(1); }; validfile = (TString)inps[i+1]; validate = true; }; if ( !strcmp(inps[i],"-gpamela") ) { gpamela = true; }; if ( !strcmp(inps[i],"-runpieces") ) { runpieces = true; }; if ( !strcmp(inps[i],"-static") ) { staticp = true; }; if ( !strcmp(inps[i],"-autoboot") ) { autoboot = true; }; if ( !strcmp(inps[i],"-no-autoboot") ) { autoboot = false; }; if ( !strcmp(inps[i],"-boot") ) { if ( numinp-1 < i+1 ){ usage(); exit(1); }; boot = atoi(inps[i+1]); }; if ( !strcmp(inps[i],"-checkfrom") ) { if ( numinp-1 < i+1 ){ usage(); exit(1); }; chfrom = atoi(inps[i+1]); check = true; }; if ( !strcmp(inps[i],"-checkto") ) { if ( numinp-1 < i+1 ){ usage(); exit(1); }; chto = atoi(inps[i+1]); check = true; }; if ( !strcmp(inps[i],"-tsync") ) { if ( numinp-1 < i+1 ){ usage(); exit(1); }; tsync = (UInt_t)atoll(inps[i+1]); }; if ( !strcmp(inps[i],"-obt0") ) { if ( numinp-1 < i+1 ){ usage(); exit(1); }; obt0 = (UInt_t)atoll(inps[i+1]); }; if ( !strcmp(inps[i],"-dworbit") ) { if ( numinp-1 < i+1 ){ usage(); exit(1); }; dwinput = (UInt_t)atoll(inps[i+1]); }; if ( !strcmp(inps[i],"-clean") ) { if ( numinp-1 < i+1 ){ usage(); exit(1); }; olderthan = (Long64_t)atoll(inps[i+1]); }; if ( !strcmp(inps[i],"-host") ) { if ( numinp-1 < i+1 ){ usage(); exit(1); }; host = (TString)inps[i+1]; }; if ( !strcmp(inps[i],"-user") ) { if ( numinp-1 < i+1 ){ usage(); exit(1); }; user = (TString)inps[i+1]; }; if ( !strcmp(inps[i],"-psw") ) { if ( numinp-1 < i+1 ){ usage(); exit(1); }; password = (TString)inps[i+1]; }; if ( !strcmp(inps[i],"-tle") ) { if ( numinp-1 < i+1 ){ usage(); exit(1); }; tlefilename = (TString)inps[i+1]; }; // if ( !strcmp(inps[i],"-v") || !strcmp(inps[i],"--verbose") ) beverbose = true; // if ( !strcmp(inps[i],"-s") || !strcmp(inps[i],"--silent") ) beverbose = false; // if ( !strcmp(inps[i],"-g") || !strcmp(inps[i],"--debug") ) debug = true; // if ( !strcmp(inps[i],"-f") || !strcmp(inps[i],"-force") ) force = true; // if ( !strcmp(inps[i],"-p") || !strcmp(inps[i],"--pedantic") ) pedantic = true; // if ( !strcmp(inps[i],"-nofrag") ) nofrag = true; // if ( !strcmp(inps[i],"-check") ) check = true; // i++; }; } else { // // no input parameters exit with error, we need at least the run id. // cout << "\n ERROR: NO INPUT PARAMETERS \n"; usage(); exit(1); }; // // If not in verbose mode redirect to /dev/null the stdout and stderr // if ( !beverbose ){ nul = open("/dev/null", O_CREAT | O_RDWR,S_IREAD | S_IWRITE); dup2(nul,1); dup2(nul,2); }; // if ( !strcmp(filerootname.Data(),"") ){ if ( (validate && !strcmp(validfile.Data(),"same")) || (remove && !strcmp(remfile.Data(),"same")) || (forceclean && !strcmp(fcleanfile.Data(),"same")) || force ){ printf("\n ERROR IN INPUT PARAMETERS \n"); usage(); exit(1); }; } else { if ( validate && !strcmp(validfile.Data(),"same") ) validfile = (TString)gSystem->BaseName(filerootname.Data()); if ( remove && !strcmp(remfile.Data(),"same") ) remfile = (TString)gSystem->BaseName(filerootname.Data()); if ( forceclean && !strcmp(fcleanfile.Data(),"same") ) fcleanfile = (TString)gSystem->BaseName(filerootname.Data()); }; // if ( force ){ nofrag = true; forceclean = true; remove = true; validate = true; fcleanfile = (TString)gSystem->BaseName(filerootname.Data()); remfile = fcleanfile; validfile = fcleanfile; }; // if ( chewbacca ){ // // temporary settings // // pedantic = true; // debug = true; // end temporary settings if ( debug ) printf("\n\n WOW! using the new software features \n\n"); }; // const char *paml0 = gSystem->Getenv("PAM_L0"); const char *paml2 = gSystem->Getenv("PAM_L2"); const char *pamraw = gSystem->Getenv("PAM_RAW"); if ( !paml0 || !paml2 || !pamraw ){ printf(" WARNING: to use symbolic paths in DB you must set up PAM_L0, PAM_L2 and PAM_RAW env var!\n Using static paths\n"); staticp = true; }; // // GL_TABLES *glt = new GL_TABLES(host,user,password); // if ( gpamela ){ // // -clean 0 -obt0 1 -tsync 1 -boot 1 -dworbit 1 // -clean 0 -obt0 1 -dworbit 1 if ( olderthan < 0LL ) olderthan = 0LL; if ( !obt0 ) obt0 = 1; // if ( !tsync ) tsync = 1; // if ( !boot ) boot = 1; if ( !dwinput ) dwinput = 1; staticp = true; autoboot = false; }; // if ( filerawname == "" && filerootname != "" ){ filerawname = "/not_given/"+(TString)gSystem->BaseName(filerootname.Data()); filerawname = filerawname.ReplaceAll(".root",5,".pam",4); // printf("filerawname %s \n",filerawname.Data()); }; // // Start: TString message; char *version = YodaProfilerInfo(false); PamelaDBOperations *pamDB = 0; UInt_t sizeofwar = 12; UInt_t WAR[12]; memset(WAR, 0, sizeofwar*sizeof(UInt_t)); // printf("\n Welcome to the PAMELA YodaProfiler, version %s \n\n",version); try{ // //------------------------------------------------------------------------------------------- // Create pamDB object and open SQL connection //------------------------------------------------------------------------------------------- if ( beverbose ) printf(" 1 => Initialize and open SQL connection \n"); pamDB = new PamelaDBOperations(host,user,password,filerawname,filerootname,boot,tsync,obt0,debug,tlefilename,dwinput,staticp,gpamela); pamDB->CheckConnection(); pamDB->LockTables(); pamDB->OpenL0File(filerootname); //------------------------------------------------------------------------------------------- // // pamDB->SetNoFrag(nofrag); pamDB->SetAutoBoot(autoboot); pamDB->SetPedantic(pedantic); // if ( remove ){ //------------------------------------------------------------------------------------------- // Remove a file and, on cascade, all that follows from the DB //------------------------------------------------------------------------------------------- if ( beverbose ) printf(" X => Remove file %s from DB \n",((TString)gSystem->BaseName(remfile)).Data()); WAR[11] = pamDB->removeFile((TString)gSystem->BaseName(remfile.Data())); //------------------------------------------------------------------------------------------- }; // if( pamDB->InsertRaw() ){ //------------------------------------------------------------------------------------------- //Insert a Raw file in GL_RAW //------------------------------------------------------------------------------------------- if ( beverbose ) printf(" 2 => Insert a RAW file in GL_RAW \n"); WAR[0] = pamDB->insertPamelaRawFile(); //------------------------------------------------------------------------------------------- }; // if( pamDB->InsertRoot() ){ // if( !pamDB->InsertRaw() && !chewbacca ) printf("=> RAW file not inserted --- the DB might not ( yet ) be filled correctly \n"); pamDB->CheckFile(); // // Set upper and lower limits (taken out from insertPamelaGL_TIMESYNC()) // WAR[1] = pamDB->SetUpperLimits(); //------------------------------------------------------------------------------------------- //Insert an entry in GL_TIMESYNC //------------------------------------------------------------------------------------------- if ( beverbose ) printf(" 3 => Insert an entry in GL_TIMESYNC \n"); WAR[1] += pamDB->insertPamelaGL_TIMESYNC(); //------------------------------------------------------------------------------------------- // //------------------------------------------------------------------------------------------- //Update a single GL_RAW record with its BOOT_NUMBER //------------------------------------------------------------------------------------------- if ( beverbose ) printf(" 4 => Update a single GL_RAW record with its BOOT_NUMBER \n"); WAR[3] = pamDB->assignBOOT_NUMBER(); if ( WAR[3] && WAR[3] != 1 && WAR[3] != 8 ) throw -9; //------------------------------------------------------------------------------------------- // //------------------------------------------------------------------------------------------- //Insert unpack ROOT file in GL_ROOT //------------------------------------------------------------------------------------------- if ( beverbose ) printf(" 5 => Insert unpacked ROOT file in GL_ROOT \n"); WAR[2] = pamDB->insertPamelaRootFile(); //------------------------------------------------------------------------------------------- // //------------------------------------------------------------------------------------------- //Insert in GL_RUN runs information records relative to a single unpack //------------------------------------------------------------------------------------------- if ( beverbose ) printf(" 6 => Scan physics and store runs in the GL_RUN table\n"); WAR[4] = pamDB->insertPamelaRUN(); //------------------------------------------------------------------------------------------- //------------------------------------------------------------------------------------------- //Insert in GL_CALO_CALIB calibration information records relative to a single unpack //------------------------------------------------------------------------------------------- if ( beverbose ) printf(" 7 => Insert calorimeter calibrations in the GL_CALO_CALIB table\n"); WAR[5] = pamDB->insertCALO_CALIB(); //------------------------------------------------------------------------------------------- if ( !gpamela ){ //--------------------------------------------------------------------------------------------------------------------- //Insert in GL_CALOPULSE_CALIB calibration PULSE information records relative to a single unpack (only for real data!) //--------------------------------------------------------------------------------------------------------------------- if ( beverbose ) printf(" 7b => Insert calorimeter pulse calibrations in the GL_CALOPULSE_CALIB table\n"); WAR[5] += pamDB->insertCALOPULSE_CALIB(); //------------------------------------------------------------------------------------------- }; //------------------------------------------------------------------------------------------- //Insert in GL_TRK_CALIB calibration information records relative to a single unpack //------------------------------------------------------------------------------------------- if ( beverbose ) printf(" 8 => Insert tracker calibrations in the GL_TRK_CALIB table\n"); WAR[6] = pamDB->insertTRK_CALIB(); //------------------------------------------------------------------------------------------- //------------------------------------------------------------------------------------------- //Insert in GL_S4_CALIB calibration information records relative to a single unpack //------------------------------------------------------------------------------------------- if ( beverbose ) printf(" 9 => Insert S4 calibrations in the GL_S4_CALIB table\n"); WAR[7] = pamDB->insertS4_CALIB(); //------------------------------------------------------------------------------------------- }; // if ( forceclean ){ //------------------------------------------------------------------------------------------- //Clean the GL_RUN_FRAGMENTS for the given file //------------------------------------------------------------------------------------------- if ( beverbose ) printf(" 10 => Clean the GL_RUN_FRAGMENTS table for file %s \n",fcleanfile.Data()); WAR[8] = pamDB->CleanGL_RUN_FRAGMENTS((TString)gSystem->BaseName(fcleanfile.Data()),runpieces); }; // // if ( validate ){ //------------------------------------------------------------------------------------------- //Validate runs //------------------------------------------------------------------------------------------- if ( beverbose ) printf(" 11 => Validate runs table for file %s \n",validfile.Data()); WAR[9] = pamDB->ValidateRuns((TString)gSystem->BaseName(validfile.Data())); //------------------------------------------------------------------------------------------- }; // pamDB->CheckValidate(olderthan); // if( pamDB->Validate() ){ //------------------------------------------------------------------------------------------- //Clean the GL_RUN_FRAGMENTS //------------------------------------------------------------------------------------------- if ( beverbose ) printf(" 10 => Clean the GL_RUN_FRAGMENTS table (earlier than %s) \n",pamDB->GetCleanTime() ); WAR[8] = pamDB->CleanGL_RUN_FRAGMENTS(runpieces); //------------------------------------------------------------------------------------------- //------------------------------------------------------------------------------------------- //Validate runs //------------------------------------------------------------------------------------------- if ( beverbose ) printf(" 11 => Validate runs (earlier than %s)\n",pamDB->GetCleanTime()); WAR[9] = pamDB->ValidateRuns(); //------------------------------------------------------------------------------------------- }; if(! tlefilename.IsNull() ) { //---------------------------------------------- //Populate GL_TLE table using the file provided //---------------------------------------------- if ( beverbose ) printf(" 12 => Insert TLE elements in the GL_TLE table from file %s \n",tlefilename.Data()); WAR[10] = pamDB->populateTLE(); } if ( check ){ //---------------------------------------------- //Check GL_RUN table consistency //---------------------------------------------- if ( beverbose ) printf(" 13 => Check GL_RUN table consistency\n"); UInt_t ch = pamDB->Check(chfrom,chto); if ( !ch ){ printf(" GL_RUN table seems ok!\n"); } else { printf(" Problems found in the GL_RUN table!\n"); }; }; } catch (Int_t exc) { signal = exc; switch(exc){ case -1: message += " DB connection failure"; break; case -2: message += " Connection failure"; break; case -3: message += " Cannot determine the timesync, use the -tsync and -obt0 options to override"; break; case -4: message += " Error querying DB"; break; case -5: message += " Inconsistent OBT/pkt_num"; break; case -6: message += " The file is not in the database"; break; case -7: message += " Cannot open TLE file"; break; case -8: message += " Event file is empty"; break; case -9: message += " No VarDump no BOOT number, use the -boot option to override"; break; case -10: message += " No results from DB"; break; case -11: message += " Raw file not found"; break; case -12: message += " Cannot open Level0 file"; break; case -13: message += " No consistent OBT/PKT_NUM information"; break; case -14: message += " Not supported yet: run with no events, no runtrailer, no runheader"; break; case -15: message += " Not supported yet: run with no runheader at the beginning/end of file not recognized as run fragment"; break; case -16: message += " No Physics tree in Level0 file"; break; case -17: message += " No RunHeader tree in Level0 file"; break; case -18: message += " No RunTrailer tree in Level0 file"; break; case -19: message += " No Mcmd tree in Level0 file"; break; case -20: message += " No VarDump tree in Level0 file"; break; case -21: message += " No CalibCalPed tree in Level0 file"; break; case -22: message += " No CalibTrk1 tree in Level0 file"; break; case -23: message += " No CalibTrk2 tree in Level0 file"; break; case -24: message += " No CalibS4 tree in Level0 file"; break; case -25: message += " Cannot find the run just inserted"; break; case -26: message += " Raw file not found looking for VarDump"; break; case -27: message += " Cannot determine downlink orbit, wrong filename format?"; break; case -28: message += " Cannot assign a RUN ID unique number!"; break; case -29: message += " No VarDump and impossible to find a consistent BOOT number, use the -boot option to override"; break; case -30: message += " Old database selected, no GL_CALOPULSE_CALIB table in the DB!"; break; case -31: message += " No CalibCalPulse1 tree in Level0 file"; break; case -32: message += " No CalibCalPulse2 tree in Level0 file"; break; case -66: message += " PEDANTIC: REPETITION"; break; case -67: message += " PEDANTIC: TIMESYNC ALREADY INSERTED"; break; case -68: message += " PEDANTIC: NO TIMESYNC IN THE FILE"; break; case -69: message += " PEDANTIC: RUN FRAGMENT ALREADY INSERTED"; break; case -70: message += " PEDANTIC: RUN ALREADY INSERTED"; break; case -71: message += " PEDANTIC: OVERLAPPING RUNS (FIRST)"; break; case -72: message += " PEDANTIC: OVERLAPPING RUNS (LAST)"; break; case -73: message += " PEDANTIC: CALO CALIB ALREADY INSERTED"; break; case -74: message += " PEDANTIC: CALO CALIB REPEATED"; break; case -75: message += " PEDANTIC: CALOPULSE1 CALIB ALREADY INSERTED"; break; case -76: message += " PEDANTIC: CALOPULSE1 CALIB REPEATED"; break; case -77: message += " PEDANTIC: CALOPULSE2 CALIB ALREADY INSERTED"; break; case -78: message += " PEDANTIC: CALOPULSE2 CALIB REPEATED"; break; case -79: message += " PEDANTIC: TRK1 CALIB REPEATED"; break; case -80: message += " PEDANTIC: TRK CALIB ALREADY INSERTED"; break; case -81: message += " PEDANTIC: S4 CALIB ALREADY INSERTED"; break; case -82: message += " PEDANTIC: S4 CALIB REPEATED"; break; case -83: message += " PEDANTIC: CLEANING ERROR, RUN ALREADY INSERTED IN THE GL_RUN TABLE"; break; case -84: message += " CHEWBACCA: problems querying the ROOT_TABLE_MERGING table"; break; case -85: message += " CHEWBACCA: problems querying the ROOT_TABLE table"; break; case -86: message += " PEDANTIC: RUN ALREADY INSERTED IN THE GL_RUN TABLE"; break; case -87: message += " PEDANTIC: THE RUN SHOULD HAVE ALREADY BEEN TREATED BY HANDLERUN()!"; break; case -88: message += " PEDANTIC: INCONSISTENT PKT/OBT SEQUENCE"; break; case -89: message += " PEDANTIC: CANNOT FIND PKT/OBT SEQUENCE IN THE POINTED FILE"; break; case -90: message += " No PhysEndRun tree in the file"; break; case -91: message += " PEDANTIC: Repetition of PhysEndRun data"; break; default: message += " Unidentified error"; break; }; printf("\n"); printf(" ERROR (%i) %s \n",exc,message.Data()); printf("\n"); } // // warnings handlers // Bool_t printwarning = false; message=""; for (UInt_t j=0; j Free objects and close SQL connection \n"); pamDB->UnLockTables(); pamDB->Close(); // if ( debug ) printf(" Total number of queries through GLTABLES: %u \n",glt->GetNqueries()); delete glt; // printf("\n"); printf(" Finished, exiting...\n"); printf("\n"); // // Close redirection if the case. // if ( !beverbose ) close(nul); // exit(signal); // }