| 1 |
// |
| 2 |
// C/C++ headers |
| 3 |
// |
| 4 |
#include <iostream> |
| 5 |
#include <sstream> |
| 6 |
#include <TSystem.h> |
| 7 |
// |
| 8 |
// ROOT headers |
| 9 |
// |
| 10 |
#include <TString.h> |
| 11 |
#include <TSQLServer.h> |
| 12 |
// |
| 13 |
// This package headers |
| 14 |
// |
| 15 |
#include <TrigCore.h> |
| 16 |
#include <TrigVerl2.h> |
| 17 |
// |
| 18 |
using namespace std; |
| 19 |
// |
| 20 |
// Usage subroutine |
| 21 |
// |
| 22 |
void usage(){ |
| 23 |
printf("\nUsage:\n"); |
| 24 |
printf("\n TriggerLevel2 [-v] [-h] [--version] -idRun ID_RUN [-processFile filename] [-processFolder folder]\n"); |
| 25 |
printf("\n [-host host] [-user username] [-psw password]\n"); |
| 26 |
printf("\n --version print informations about compilation and exit\n"); |
| 27 |
printf("\n -h | --help print this help and exit \n"); |
| 28 |
printf("\n -v | --verbose be verbose [default: print nothing on STDOUT]\n"); |
| 29 |
printf("\n -idRun ID_RUN: ID number of the run to be processed \n"); |
| 30 |
printf("\n -processFile filename : output filename [default ID_RUN.Level2.root]\n"); |
| 31 |
printf("\n -processFolder default \"triggerFolder\"\n"); |
| 32 |
printf("\n -host name for the host [default = mysql://localhost/pamelaprod]\n"); |
| 33 |
printf("\n -user username for the DB [default = anonymous] \n"); |
| 34 |
printf("\n -psw password for the DB [default = \"\"]\n"); |
| 35 |
printf("\n Notice that parameter order does not matter. \n"); |
| 36 |
printf("\nExample: \n\nTriggerLevel2 -idRun 1085 -processFile nomefile.root\n\n"); |
| 37 |
}; |
| 38 |
// |
| 39 |
bool debug = false; |
| 40 |
// |
| 41 |
// Here the main |
| 42 |
// |
| 43 |
int main(int numinp, char *inps[]){ |
| 44 |
// |
| 45 |
// Variables booking |
| 46 |
// |
| 47 |
TFile *processFile =0; |
| 48 |
int nul = 0; |
| 49 |
Int_t error = 0; |
| 50 |
Bool_t beverbose = false; |
| 51 |
ULong64_t run = 0; |
| 52 |
TString filename=""; |
| 53 |
TString processFolder; |
| 54 |
TString outdir = "./"; |
| 55 |
TSQLServer *dbc = 0; |
| 56 |
Bool_t givenid = false; |
| 57 |
processFolder = "triggerFolder"; |
| 58 |
// |
| 59 |
TString host = "mysql://localhost/pamelaprod"; |
| 60 |
TString user = "anonymous"; |
| 61 |
TString psw = ""; |
| 62 |
// |
| 63 |
// Checking input parameters |
| 64 |
// |
| 65 |
if ( numinp > 1 ){ |
| 66 |
for ( int i = 0; i < numinp; i++ ){ |
| 67 |
if ( !strcmp(inps[i],"--version") ){ |
| 68 |
TrigInfo(true); |
| 69 |
exit(0); |
| 70 |
}; |
| 71 |
if ( !strcmp(inps[i],"-h") || !strcmp(inps[i],"--help") ){ |
| 72 |
usage(); |
| 73 |
exit(0); |
| 74 |
}; |
| 75 |
if ( !strcmp(inps[i],"-idRun") ) { |
| 76 |
if ( numinp-1 < i+1 ){ |
| 77 |
usage(); |
| 78 |
exit(-3); |
| 79 |
}; |
| 80 |
givenid = true; |
| 81 |
char *pEnd; |
| 82 |
run = strtoull(inps[i+1],&pEnd,0); |
| 83 |
}; |
| 84 |
if ( !strcmp(inps[i],"-outDir") ) { |
| 85 |
if ( numinp-1 < i+1 ){ |
| 86 |
usage(); |
| 87 |
exit(-3); |
| 88 |
}; |
| 89 |
outdir = (TString)inps[i+1]; |
| 90 |
}; |
| 91 |
if ( !strcmp(inps[i],"-processFile") ) { |
| 92 |
if ( numinp-1 < i+1 ){ |
| 93 |
usage(); |
| 94 |
exit(-3); |
| 95 |
}; |
| 96 |
filename = (TString)inps[i+1]; |
| 97 |
}; |
| 98 |
if ( !strcmp(inps[i],"-processFolder") ) { |
| 99 |
if ( numinp-1 < i+1 ){ |
| 100 |
usage(); |
| 101 |
exit(-3); |
| 102 |
}; |
| 103 |
processFolder = (TString)inps[i+1]; |
| 104 |
}; |
| 105 |
if ( !strcmp(inps[i],"-host") ) { |
| 106 |
if ( numinp-1 < i+1 ){ |
| 107 |
usage(); |
| 108 |
exit(-3); |
| 109 |
}; |
| 110 |
host = (TString)inps[i+1]; |
| 111 |
}; |
| 112 |
if ( !strcmp(inps[i],"-user") ) { |
| 113 |
if ( numinp-1 < i+1 ){ |
| 114 |
usage(); |
| 115 |
exit(-3); |
| 116 |
}; |
| 117 |
user = (TString)inps[i+1]; |
| 118 |
}; |
| 119 |
if ( !strcmp(inps[i],"-psw") ) { |
| 120 |
if ( numinp-1 < i+1 ){ |
| 121 |
usage(); |
| 122 |
exit(-3); |
| 123 |
}; |
| 124 |
psw = (TString)inps[i+1]; |
| 125 |
}; |
| 126 |
if ( !strcmp(inps[i],"-v") || !strcmp(inps[i],"--verbose") ) beverbose = true; |
| 127 |
}; |
| 128 |
} else { |
| 129 |
// |
| 130 |
// no input parameters exit with error, we need at least the run id. |
| 131 |
// |
| 132 |
printf(" TRIGGER - ERROR: you must provide a run number (at least -1)\n"); |
| 133 |
exit(-1); |
| 134 |
}; |
| 135 |
// |
| 136 |
// If not in verbose mode redirect to /dev/null the stdout and stderr |
| 137 |
// |
| 138 |
if ( !beverbose ){ |
| 139 |
nul = open("/dev/null", O_CREAT | O_RDWR,S_IREAD | S_IWRITE); |
| 140 |
dup2(nul,1); |
| 141 |
dup2(nul,2); |
| 142 |
}; |
| 143 |
// |
| 144 |
// Check that an input run number has been given |
| 145 |
// |
| 146 |
if ( !givenid ) { |
| 147 |
printf(" TRIGGER - ERROR: you must provide a run number (at least -1)\n"); |
| 148 |
exit(-1); |
| 149 |
}; |
| 150 |
// |
| 151 |
char *version = TrigInfo(false); |
| 152 |
// |
| 153 |
// Start: |
| 154 |
// |
| 155 |
printf("\n Welcome to the Trigger LEVEL2 flight software, version %s \n",version); |
| 156 |
// |
| 157 |
// Connect to the DB |
| 158 |
// |
| 159 |
printf("\nConnecting to database... \n"); |
| 160 |
// |
| 161 |
dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data()); |
| 162 |
if( !dbc ) { |
| 163 |
printf(" TRIGGER - ERROR: problems connecting to the DB (check username and passwd), exiting...\n\n"); |
| 164 |
exit(-2); |
| 165 |
}; |
| 166 |
bool connect = dbc->IsConnected(); |
| 167 |
// |
| 168 |
if( !connect ) { |
| 169 |
printf(" TRIGGER - ERROR: problems connecting to the DB (check username and passwd), exiting...\n\n"); |
| 170 |
exit(-2); |
| 171 |
}; |
| 172 |
printf("...connected! \n\n"); |
| 173 |
// |
| 174 |
if ( filename.IsNull() ){ |
| 175 |
stringstream strun; |
| 176 |
strun.str(""); |
| 177 |
strun << run; |
| 178 |
filename += strun.str(); |
| 179 |
filename += ".Level2.root"; |
| 180 |
}; |
| 181 |
filename = outdir + "/" + filename; |
| 182 |
processFile = new TFile(filename.Data(),"UPDATE"); |
| 183 |
// |
| 184 |
// Run the core program, put any output error in the "error" variable |
| 185 |
// |
| 186 |
error = TrigCore(run, processFile ,dbc, numinp, inps); |
| 187 |
if( processFile ) processFile->Close(); |
| 188 |
// |
| 189 |
// Close the DB connection |
| 190 |
// |
| 191 |
printf("\nClose the connection to the database... \n"); |
| 192 |
dbc->Close(); |
| 193 |
printf("...connection terminated!\n\n"); |
| 194 |
// |
| 195 |
// Close redirection if the case. |
| 196 |
// |
| 197 |
if ( !beverbose ) close(nul); |
| 198 |
// |
| 199 |
// Return "error" |
| 200 |
// |
| 201 |
if ( error > 0 ) printf(" TRIGGER - WARNING: exiting with signal %i \n\n",error); |
| 202 |
if ( error < 0 ) printf(" TRIGGER - ERROR: exiting with signal %i \n\n",error); |
| 203 |
exit(error); |
| 204 |
} |