// // L2CAL.cc -- standalone program to call the l2calcore subroutine. // Written by Emiliano Mocchiutti (2005). // // Version 2.00 (2006/03/23) // // Changelog: // // 1.00 - 2.00 (2006/03/23): Input parameters must be now introduced by an identifier (-id run_id -file filename). Order does not matter. // Added verbose/not verbose option. // // 0.00 - 1.00 : working. // // // C/C++ headers // #include #include // // ROOT headers // #include #include #include // // This package headers // #include #include // using namespace std; // // Usage subroutine // void usage(){ printf("\nUsage:\n"); printf("\n CalorimeterLevel2 [-v] [-h] [--version] -idRun ID_RUN [-processFile filename] [-processFolder folder]\n"); printf("\n [-host host] [-user username] [-psw password]\n"); printf("\n --version print informations about compilation and exit\n"); printf("\n -h | --help print this help and exit \n"); printf("\n -v | --verbose be verbose [default: print nothing on STDOUT]\n"); printf("\n -idRun ID_RUN: ID number of the run to be processed \n"); printf("\n -processFile output filename [default ID_RUN.Level2.root]\n"); printf("\n -processFolder folder for output data but the processFile [default \"calorimeterFolder\"]\n"); printf("\n -host name for the host [default = mysql://localhost/pamelaprod]\n"); printf("\n -user username for the DB [default = anonymous] \n"); printf("\n -psw password for the DB [default = \"\"]\n"); printf("\n Notice that parameter order does not matter. \n"); printf("\nExample: \n\nCalorimeterLevel2 -idRun 1085 -processFile nomefile.root\n\n"); }; // Bool_t debug = false; // // Here the main // int main(int numinp, char *inps[]){ // // Variables booking // int nul = 0; Int_t error = 0; TFile *processFile =0; Bool_t beverbose = false; UInt_t run = 0; TString filename; TString processFolder; TString outDir="./"; TSQLServer *dbc = 0; Bool_t givenid = false; processFolder = "calorimeterFolder"; // TString host = "mysql://localhost/pamelaprod"; TString user = "anonymous"; TString psw = ""; // // Checking input parameters // if ( numinp > 1 ){ for ( int i = 0; i < numinp; i++ ){ if ( !strcmp(inps[i],"--version") ){ CaloInfo(true); exit(0); }; if ( !strcmp(inps[i],"-h") || !strcmp(inps[i],"--help") ){ usage(); exit(0); }; if ( !strcmp(inps[i],"-idRun") ) { if ( numinp-1 < i+1 ) { usage(); exit(-3); }; givenid = true; run = (UInt_t)atoll(inps[i+1]); }; if ( !strcmp(inps[i],"-processFile") ) { if ( numinp-1 < i+1 ){ usage(); exit(-3); }; filename = (TString)inps[i+1]; }; if ( !strcmp(inps[i],"-processFolder") ) { if ( numinp-1 < i+1 ){ usage(); exit(-3); }; processFolder = (TString)inps[i+1]; }; if ( !strcmp(inps[i],"-host") ) { if ( numinp-1 < i+1 ){ usage(); exit(-3); }; host = (TString)inps[i+1]; }; if ( !strcmp(inps[i],"-user") ) { if ( numinp-1 < i+1 ){ usage(); exit(-3); }; user = (TString)inps[i+1]; }; if ( !strcmp(inps[i],"-psw") ) { if ( numinp-1 < i+1 ){ usage(); exit(-3); }; psw = (TString)inps[i+1]; }; if ( !strcmp(inps[i],"-v") || !strcmp(inps[i],"--verbose") ) beverbose = true; }; } else { // // no input parameters exit with error, we need at least the run id. // printf("\n CALORIMETER - ERROR: you must provide a run number (at least 0)\n\n"); 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); }; // // Check that an input run number has been given // if ( !givenid ) { printf("\n CALORIMETER - ERROR: you must provide a run number (at least 0)\n\n"); exit(-1); }; // char *version = CaloInfo(false); // // Start: // printf("\n Welcome to the Calorimeter LEVEL2 flight software, version %s \n",version); // // Connect to the DB // printf("\nConnecting to database... \n"); // dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data()); if( !dbc ) { printf(" CALORIMETER - ERROR: problems connecting to the DB (check username and passwd), exiting...\n\n"); exit(-2); }; bool connect = dbc->IsConnected(); // if( !connect ) { printf(" CALORIMETER - ERROR: problems connecting to the DB (check username and passwd), exiting...\n\n"); exit(-2); }; printf("...connected! \n\n"); // if ( filename.IsNull() ){ stringstream strun; strun.str(""); strun << run; filename += strun.str(); filename += ".Level2.root"; }; filename = outDir + "/" + filename; processFile = new TFile(filename.Data(),"UPDATE"); // // Run the core program, put any output error in the "error" variable // error = CaloCore(run, processFile, dbc, numinp, inps); // // Close the DB connection // printf("\nClose the connection to the database... \n"); dbc->Close(); delete dbc; dbc = 0; printf("...connection terminated!\n\n"); // // Close redirection if the case. // if ( !beverbose ) close(nul); // // Return "error" // if ( error > 0 ) printf(" CALORIMETER - WARNING: exiting with signal %i \n\n",error); if ( error < 0 ) printf(" CALORIMETER - ERROR: exiting with signal %i \n\n",error); processFile->Close(); exit(error); }