| 1 |
// |
| 2 |
// C/C++ headers |
| 3 |
// |
| 4 |
#include <iostream> |
| 5 |
// |
| 6 |
// ROOT headers |
| 7 |
// |
| 8 |
#include <TString.h> |
| 9 |
#include <TSQLServer.h> |
| 10 |
// |
| 11 |
// This package headers |
| 12 |
// |
| 13 |
#include <MyDect1Core.h> |
| 14 |
#include <MyDect1Verl2.h> |
| 15 |
// |
| 16 |
using namespace std; |
| 17 |
// |
| 18 |
// Usage subroutine |
| 19 |
// |
| 20 |
void usage(){ |
| 21 |
printf("\nUsage:\n"); |
| 22 |
printf("\n MyDetector1Level2 [-v] [-h] [--version] -idRun ID_RUN [-processFile filename] [-processFolder folder]\n"); |
| 23 |
printf("\n --version print informations about compilation and exit\n"); |
| 24 |
printf("\n -h | --help print this help and exit \n"); |
| 25 |
printf("\n -v | --verbose be verbose [default: print nothing on STDOUT]\n"); |
| 26 |
printf("\n -idRun ID_RUN: ID number of the run to be processed \n"); |
| 27 |
printf("\n -processFile filename : output filename [default ID_RUN.Level2.root]\n"); |
| 28 |
printf("\n -processFolder not used [default \"\"]\n"); |
| 29 |
printf("\n Notice that parameter order does not matter. \n"); |
| 30 |
printf("\nExample: \n\nMyDetector1Level2 -idRun 1085 -processFile nomefile.root\n\n"); |
| 31 |
}; |
| 32 |
// |
| 33 |
// Here the main |
| 34 |
// |
| 35 |
int main(int numinp, char *inps[]){ |
| 36 |
// |
| 37 |
// Variables booking |
| 38 |
// |
| 39 |
int nul = 0; |
| 40 |
Int_t error = 0; |
| 41 |
Bool_t beverbose = false; |
| 42 |
ULong64_t run = 0; |
| 43 |
TString filename; |
| 44 |
TSQLServer *dbc = 0; |
| 45 |
Bool_t givenid = false; |
| 46 |
// |
| 47 |
// Checking input parameters |
| 48 |
// |
| 49 |
if ( numinp > 1 ){ |
| 50 |
for ( int i = 0; i < numinp; i++ ){ |
| 51 |
if ( !strcmp(inps[i],"--version") ){ |
| 52 |
MyDect1Info(true); |
| 53 |
exit(0); |
| 54 |
}; |
| 55 |
if ( !strcmp(inps[i],"-h") || !strcmp(inps[i],"--help") ){ |
| 56 |
usage(); |
| 57 |
exit(0); |
| 58 |
}; |
| 59 |
if ( !strcmp(inps[i],"-idRun") ) { |
| 60 |
if ( numinp-1 < i+1 ) exit(-3); |
| 61 |
givenid = true; |
| 62 |
char *pEnd; |
| 63 |
run = strtoull(inps[i+1],&pEnd,0); |
| 64 |
}; |
| 65 |
if ( !strcmp(inps[i],"-processFile") ) { |
| 66 |
if ( numinp-1 < i+1 ) exit(-3); |
| 67 |
filename = (TString)inps[i+1]; |
| 68 |
}; |
| 69 |
if ( !strcmp(inps[i],"-v") || !strcmp(inps[i],"--verbose") ) beverbose = true; |
| 70 |
}; |
| 71 |
} else { |
| 72 |
// |
| 73 |
// no input parameters exit with error, we need at least the run id. |
| 74 |
// |
| 75 |
printf(" MYDETECTOR1 - ERROR: you must provide a run number (at least -1)\n"); |
| 76 |
exit(-1); |
| 77 |
}; |
| 78 |
// |
| 79 |
// If not in verbose mode redirect to /dev/null the stdout and stderr |
| 80 |
// |
| 81 |
if ( !beverbose ){ |
| 82 |
nul = open("/dev/null", O_CREAT | O_RDWR,S_IREAD | S_IWRITE); |
| 83 |
dup2(nul,1); |
| 84 |
dup2(nul,2); |
| 85 |
}; |
| 86 |
// |
| 87 |
// Check that an input run number has been given |
| 88 |
// |
| 89 |
if ( !givenid ) { |
| 90 |
printf(" MYDETECTOR1 - ERROR: you must provide a run number (at least -1)\n"); |
| 91 |
exit(-1); |
| 92 |
}; |
| 93 |
// |
| 94 |
char *version = MyDect1Info(false); |
| 95 |
// |
| 96 |
// Start: |
| 97 |
// |
| 98 |
printf("\n Welcome to the MyDetector1 LEVEL2 flight software, version %s \n",version); |
| 99 |
// |
| 100 |
// Connect to the DB |
| 101 |
// |
| 102 |
printf("\nConnecting to database... \n"); |
| 103 |
// |
| 104 |
dbc = TSQLServer::Connect("mysql://localhost/pamelaprod","anonymous",""); |
| 105 |
if( !dbc ) { |
| 106 |
printf(" MYDETECTOR1 - ERROR: problems connecting to the DB (check username and passwd), exiting...\n\n"); |
| 107 |
exit(-2); |
| 108 |
}; |
| 109 |
bool connect = dbc->IsConnected(); |
| 110 |
// |
| 111 |
if( !connect ) { |
| 112 |
printf(" MYDETECTOR1 - ERROR: problems connecting to the DB (check username and passwd), exiting...\n\n"); |
| 113 |
exit(-2); |
| 114 |
}; |
| 115 |
printf("...connected! \n\n"); |
| 116 |
// |
| 117 |
// Run the core program, put any output error in the "error" variable |
| 118 |
// |
| 119 |
error = MyDect1Core(run,filename,dbc); |
| 120 |
// |
| 121 |
// Close the DB connection |
| 122 |
// |
| 123 |
printf("\nClose the connection to the database... \n"); |
| 124 |
dbc->Close(); |
| 125 |
printf("...connection terminated!\n\n"); |
| 126 |
// |
| 127 |
// Close redirection if the case. |
| 128 |
// |
| 129 |
if ( !beverbose ) close(nul); |
| 130 |
// |
| 131 |
// Return "error" |
| 132 |
// |
| 133 |
if ( error > 0 ) printf(" MYDETECTOR1 - WARNING: exiting with signal %i \n\n",error); |
| 134 |
if ( error < 0 ) printf(" MYDETECTOR1 - ERROR: exiting with signal %i \n\n",error); |
| 135 |
exit(error); |
| 136 |
} |