| 1 |
/** |
| 2 |
* \file TrackerLevel2.cpp |
| 3 |
* \author Elena Vannuccini |
| 4 |
*/ |
| 5 |
#include <stdlib.h> |
| 6 |
#include <iostream> |
| 7 |
#include <TSQLServer.h> |
| 8 |
#include <TSystem.h> |
| 9 |
#include <TSystemDirectory.h> |
| 10 |
#include <TString.h> |
| 11 |
// |
| 12 |
#include <TrkCore.h> |
| 13 |
#include <TrkVerl2.h> |
| 14 |
// |
| 15 |
using namespace std; |
| 16 |
bool DEBUG; |
| 17 |
|
| 18 |
/** |
| 19 |
* The program handles input parameters, open the connection to the DB and call the TrkCore() routine. |
| 20 |
*/ |
| 21 |
int main(int argc, char *argv[]){ |
| 22 |
|
| 23 |
try{ |
| 24 |
|
| 25 |
TSQLServer *dbc = 0; |
| 26 |
TFile *f2 = 0; |
| 27 |
// ----------------------- |
| 28 |
// Default input parameters |
| 29 |
// ----------------------- |
| 30 |
DEBUG = 0; |
| 31 |
UInt_t run = 0; |
| 32 |
int get1 = 0; |
| 33 |
int get2 = 1; |
| 34 |
bool standalone = false; |
| 35 |
TString frame2 = "root"; |
| 36 |
TString frame1 = "hbook"; |
| 37 |
TString file1 ; |
| 38 |
TString file2 ; |
| 39 |
TString outdir = gSystem->WorkingDirectory(); // "./"; |
| 40 |
TString pfolder = "/TrackerFolder"; |
| 41 |
TString host = "mysql://localhost/pamelaprod"; |
| 42 |
TString user = "anonymous"; |
| 43 |
TString psw = ""; |
| 44 |
|
| 45 |
if(argc<2)throw -1; |
| 46 |
// ----------------------------- |
| 47 |
// program help and version info |
| 48 |
// ----------------------------- |
| 49 |
if ( !strcmp(argv[1],"--version") ){ |
| 50 |
TrkInfo(true); |
| 51 |
return(0); |
| 52 |
// ---------------------------------------------------------------- |
| 53 |
} else if ( !strcmp(argv[1],"-h") || !strcmp(argv[1],"--help") ){ |
| 54 |
printf( "\n\n USAGE\n\n TrackerLevel2 -idRun xxxxx [options] \n \n"); |
| 55 |
printf( "\n --version : Print tracker software version and exit "); |
| 56 |
printf( "\n --help, -h : Print this help and exit \n"); |
| 57 |
printf( "\n -idRun RUN : ID number of the run to be processed (for reprocessing RUN=0) \n"); |
| 58 |
printf( "\n -outDir OUTDIR : Path where to put the LEVEL2 output [default ./ ] "); |
| 59 |
printf( "\n -processFolder DIR : Directory (relative to OUTDIR) for other output files [default TrackerFolder/ ] "); |
| 60 |
printf( "\n -processFile FILE : Name of the LEVEL2 output file [default RUN.Level2.root]"); |
| 61 |
printf( "\n -processFile1 FILE : Name of the LEVEL1 output file [default RUN.Level1.rz]"); |
| 62 |
printf( "\n -frame1 FRAME : type of output for LEVEL1, root/hbook [default hbook ] "); |
| 63 |
printf( "\n -frame2 FRAME : type of output for LEVEL2, root/hbook [default root ] "); |
| 64 |
printf( "\n --get1 : flag to get LEVEL1 output [default (no LEVEL1 output) ] "); |
| 65 |
printf( "\n --dontget2 : flag to do not get LEVEL2 output [default (get LEVEL2 output)]"); |
| 66 |
printf( "\n --verbose, -v : Run the program in debug mode "); |
| 67 |
printf( "\n --standalone, -s : Run the program in standalone mode (without RunInfo) \n"); |
| 68 |
printf( "\n -host HOST : Name for the host [default mysql://localhost/pamelaprod ]"); |
| 69 |
printf( "\n -user USER : Username for the DB [default anonymous] "); |
| 70 |
printf( "\n -psw PSW : Password for the DB [default (none)]\n \n \n"); |
| 71 |
exit(-12); |
| 72 |
// ---------------------------------------------------------------- |
| 73 |
} |
| 74 |
|
| 75 |
// cout << "bbb "<< gDirectory->pwd()<< endl; |
| 76 |
|
| 77 |
// ----------------------- |
| 78 |
// Read input parameters |
| 79 |
// ----------------------- |
| 80 |
TString input_parameters=0; |
| 81 |
int ncustom =0; |
| 82 |
char* vcustom[30]; |
| 83 |
for (int i = 1; i < argc; i++){ |
| 84 |
// cout << i << " "<< argv[i] << endl; |
| 85 |
vcustom[ncustom] = argv[i]; |
| 86 |
ncustom++; |
| 87 |
// -----------------------------------------------------// |
| 88 |
if (!strcmp(argv[i], "-idRun")){ |
| 89 |
if (++i >= argc) throw -1; |
| 90 |
run = atoi(argv[i]); |
| 91 |
continue; |
| 92 |
} |
| 93 |
// -----------------------------------------------------// |
| 94 |
else if (!strcmp(argv[i], "-outDir")){ |
| 95 |
if (++i >= argc)throw -3; |
| 96 |
outdir = argv[i]; |
| 97 |
continue; |
| 98 |
} |
| 99 |
// -----------------------------------------------------// |
| 100 |
else if (!strcmp(argv[i], "-processFolder")){ |
| 101 |
if (++i >= argc) throw -3; |
| 102 |
pfolder = argv[i]; |
| 103 |
continue; |
| 104 |
} |
| 105 |
// -----------------------------------------------------// |
| 106 |
else if (!strcmp(argv[i], "-processFile")){ |
| 107 |
if (++i >= argc) throw -3; |
| 108 |
get2 = 1; |
| 109 |
file2 = argv[i]; |
| 110 |
continue; |
| 111 |
} |
| 112 |
// -----------------------------------------------------// |
| 113 |
else if (!strcmp(argv[i], "--get1")){ |
| 114 |
get1 = 1; |
| 115 |
continue; |
| 116 |
} |
| 117 |
//-----------------------------------------------------// |
| 118 |
else if (!strcmp(argv[i], "--dontget2")){ |
| 119 |
get2 = 0; |
| 120 |
continue; |
| 121 |
} |
| 122 |
//-----------------------------------------------------// |
| 123 |
else if (!strcmp(argv[i], "--standalone") || !strcmp(argv[i], "-s")){ |
| 124 |
standalone = true; |
| 125 |
continue; |
| 126 |
} |
| 127 |
//-----------------------------------------------------// |
| 128 |
else if (!strcmp(argv[i], "-processFile1")){ |
| 129 |
if (++i >= argc) throw -3; |
| 130 |
get1 = 1; |
| 131 |
file1 = argv[i]; |
| 132 |
continue; |
| 133 |
} |
| 134 |
//-----------------------------------------------------// |
| 135 |
else if (!strcmp(argv[i], "-frame1")){ |
| 136 |
if (++i >= argc)throw -3; |
| 137 |
get1 = 1; |
| 138 |
frame1 = argv[i]; |
| 139 |
continue; |
| 140 |
} |
| 141 |
//-----------------------------------------------------// |
| 142 |
else if (!strcmp(argv[i], "-frame2")){ |
| 143 |
if (++i >= argc)throw -3; |
| 144 |
get2 = 1; |
| 145 |
frame2 = argv[i]; |
| 146 |
continue; |
| 147 |
} |
| 148 |
// -----------------------------------------------------// |
| 149 |
else if (!strcmp(argv[i], "-host")){ |
| 150 |
if (++i >= argc)throw -3; |
| 151 |
host = argv[i]; |
| 152 |
continue; |
| 153 |
} |
| 154 |
// -----------------------------------------------------// |
| 155 |
else if (!strcmp(argv[i], "-user")){ |
| 156 |
if (++i >= argc)throw -3; |
| 157 |
user = argv[i]; |
| 158 |
continue; |
| 159 |
} |
| 160 |
// -----------------------------------------------------// |
| 161 |
else if (!strcmp(argv[i], "-psw")){ |
| 162 |
if (++i >= argc)throw -3; |
| 163 |
psw = argv[i]; |
| 164 |
continue; |
| 165 |
} |
| 166 |
//-----------------------------------------------------// |
| 167 |
else if (!strcmp(argv[i], "--verbose") || !strcmp(argv[i], "-v")){ |
| 168 |
DEBUG = 1; |
| 169 |
continue; |
| 170 |
}else{ |
| 171 |
}; |
| 172 |
} |
| 173 |
|
| 174 |
|
| 175 |
// ----------------------- |
| 176 |
// Handle input parameters |
| 177 |
// ----------------------- |
| 178 |
// check patameter consistency |
| 179 |
// if(run == -1 || (run < 0 && run != 0)) throw -1; |
| 180 |
if( get1 == 0 && get2 == 0) throw -202; |
| 181 |
if( get1 == 1 && get2 == 0 && run == 0) throw -204; |
| 182 |
if( standalone && run == 0) throw -298; |
| 183 |
// compose outputfile names |
| 184 |
/* if(get1){ |
| 185 |
TString filety; |
| 186 |
if (!frame1.CompareTo("root", TString::kIgnoreCase)) filety=".root"; |
| 187 |
else if (!frame1.CompareTo("hbook", TString::kIgnoreCase)) filety=".rz"; |
| 188 |
else throw -200; |
| 189 |
if(file1.IsNull()){ |
| 190 |
file1 += run; |
| 191 |
file1 += ".Level1"; |
| 192 |
file1 += filety; |
| 193 |
}else if (!file1.Contains(filety.Data())) file1 += filety; |
| 194 |
file1 = outdir + "/"+ pfolder + "/" + file1; |
| 195 |
};*/ |
| 196 |
if(get2){ |
| 197 |
if(run == 0 && file2.IsNull()) throw -4; |
| 198 |
TString filety; |
| 199 |
if (!frame2.CompareTo("root", TString::kIgnoreCase)) filety=".root"; |
| 200 |
else if (!frame2.CompareTo("hbook", TString::kIgnoreCase)) filety=".rz"; |
| 201 |
else throw -201; |
| 202 |
if(file2.IsNull()){ |
| 203 |
file2 += (Int_t)run; |
| 204 |
file2 += ".Level2"; |
| 205 |
file2 += filety; |
| 206 |
}else if (!file2.Contains(filety.Data())) file2 += filety; |
| 207 |
file2 = outdir + "/" + file2; |
| 208 |
f2= new TFile(file2,"UPDATE"); |
| 209 |
if ( !f2->IsOpen() ) throw -204; |
| 210 |
|
| 211 |
}; |
| 212 |
|
| 213 |
if(DEBUG){ |
| 214 |
cout << endl << "Input parameters: " << endl; |
| 215 |
cout << "idRun "<< run << endl; |
| 216 |
cout << "get1 "<< get1 << endl; |
| 217 |
cout << "get2 "<< get2 << endl; |
| 218 |
cout << "LEVEL1 output "<< file1 << endl; |
| 219 |
cout << "LEVEL2 output "<< file2 << endl; |
| 220 |
cout << "host "<< host << endl; |
| 221 |
cout << "user "<< user << endl; |
| 222 |
cout << "password "<< psw << endl; |
| 223 |
} |
| 224 |
// ----------------------- |
| 225 |
// connect to the database |
| 226 |
// ----------------------- |
| 227 |
if(DEBUG) printf("\nConnecting to database... \n"); |
| 228 |
// dbc = TSQLServer::Connect("mysql://localhost/pamelaprod","anonymous",""); |
| 229 |
dbc = TSQLServer::Connect(host,user,psw); |
| 230 |
Bool_t connect = dbc->IsConnected(); |
| 231 |
if( !connect ) throw -2; |
| 232 |
if(DEBUG) printf("...connected! \n\n"); |
| 233 |
// ------------------------- |
| 234 |
// CALL REDUCTION ROUTINE |
| 235 |
// ------------------------- |
| 236 |
// TrkCore(run,dbc,file1,file2,standalone); |
| 237 |
TrkCore(run,f2,dbc,ncustom,vcustom); |
| 238 |
// ----------------------- |
| 239 |
// close connection to db |
| 240 |
// ----------------------- |
| 241 |
if(DEBUG) printf("\nClose the connection to the database... \n"); |
| 242 |
dbc->Close(); |
| 243 |
if(DEBUG) printf("...connection terminated!\n\n"); |
| 244 |
|
| 245 |
if(get2)f2->Close(); |
| 246 |
|
| 247 |
return 0; |
| 248 |
} |
| 249 |
catch(int e){ |
| 250 |
|
| 251 |
TString message; |
| 252 |
switch(e){ |
| 253 |
case -1: message += "Missing/wrong run ID input parameter"; break; |
| 254 |
case -2: message += "DB connection failure"; break; |
| 255 |
case -3: message += "Error in input parameters (check format)"; break; |
| 256 |
case -4: message += "Request reprocessing of all runs (idRun = 0) but processFile is missing"; break; |
| 257 |
case -6: message += "No LEVEL0 file "; break; |
| 258 |
case -7: message += "No \"Physics\" tree in LEVEL0 file"; break; |
| 259 |
case -8: message += "No \"Header\" branch in LEVEL0 \"Physics\" tree"; break; |
| 260 |
case -9: message += "No \"Registry\" branch in LEVEL0 \"Physics\" tree"; break; |
| 261 |
case -11: message += "LEVEL0 \"Physics\" tree is empty"; break; |
| 262 |
case -12: message += "LEVEL2 output directory does not exists"; break; |
| 263 |
case -13: message += "Cannot create processFolder directory"; break; |
| 264 |
|
| 265 |
case -50: message += "No entries matching GL_RUN query"; break; |
| 266 |
case -51: message += "No entries matching GL_ROOT query"; break; |
| 267 |
case -52: message += "No entries matching GL_PARAM query"; break; |
| 268 |
case -53: message += "No entries matching GL_TRK_CALIB query"; break; |
| 269 |
case -54: message += "No entries matching GL_CALO_CALIB query"; break; |
| 270 |
|
| 271 |
|
| 272 |
case -200: message += "LEVEL1 framework unknown (HBOOK/ROOT)"; break; |
| 273 |
case -201: message += "LEVEL2 framework unknown (HBOOK/ROOT)"; break; |
| 274 |
case -202: message += "Neither LEVEL1 nor LEVEL2 output requested"; break; |
| 275 |
case -203: message += "No \"Tracker\" branch in LEVEL0 \"Physics\" tree"; break; |
| 276 |
case -204: message += "No reprocessing implemented for LEVEL1 output"; break; |
| 277 |
case -205: message += "Error accessing \"RunInfo\" "; break; |
| 278 |
|
| 279 |
case -210: message += "Error opening/reading \"trk mask\" GL_PARAM parameters "; break; |
| 280 |
case -211: message += "Error opening/reading \"trk alignment\" GL_PARAM parameters"; break; |
| 281 |
case -212: message += "Error opening/reading \"trk mip\" GL_PARAM parameters"; break; |
| 282 |
case -213: message += "Error opening/reading \"trk charge\" GL_PARAM parameters"; break; |
| 283 |
case -214: message += "Error opening/reading \"trk pfa\" GL_PARAM parameters"; break; |
| 284 |
case -215: message += "Error opening/reading \"field\" GL_PARAM parameters"; break; |
| 285 |
case -216: message += "Error opening/reading \"default calibration\" GL_PARAM parameters"; break; |
| 286 |
|
| 287 |
case -298: message += "Reprocessing not implemented in standalone mode"; break; |
| 288 |
case -299: message += "Not yet implemented"; break; |
| 289 |
|
| 290 |
default: message += "Unidentified"; break; |
| 291 |
} |
| 292 |
cout << "TrackerLevel2 - ERROR ("<< e << ") "<< message <<endl; |
| 293 |
exit(e); |
| 294 |
} |
| 295 |
} |
| 296 |
|
| 297 |
|