| 1 |
mocchiut |
1.1 |
// |
| 2 |
|
|
#include <iostream> |
| 3 |
|
|
#include <sstream> |
| 4 |
|
|
#include <errno.h> |
| 5 |
|
|
// |
| 6 |
|
|
#include <TSystem.h> |
| 7 |
|
|
// |
| 8 |
mocchiut |
1.17 |
#include <GLTables.h> |
| 9 |
mocchiut |
1.1 |
#include <PamelaDBOperations.h> |
| 10 |
|
|
#include <YodaProfilerVerl2.h> |
| 11 |
|
|
// |
| 12 |
|
|
using namespace std; |
| 13 |
|
|
// |
| 14 |
|
|
// Usage subroutine |
| 15 |
|
|
// |
| 16 |
|
|
void usage(){ |
| 17 |
|
|
printf("\nUsage:\n"); |
| 18 |
mocchiut |
1.2 |
printf("\n YodaProfiler [options] -rawFile raw_filename -yodaFile yoda_filename \n"); |
| 19 |
|
|
printf("\n -rawFile full path to the raw file\n"); |
| 20 |
mocchiut |
1.14 |
printf( " -yodaFile full path to the YODA file\n"); |
| 21 |
|
|
printf("\n Options are:\n\n"); |
| 22 |
|
|
printf(" --version print informations about compilation and exit\n"); |
| 23 |
|
|
printf(" -h | --help print this help and exit \n"); |
| 24 |
|
|
printf(" -v | --verbose be verbose [default]\n"); |
| 25 |
|
|
printf(" -s | --silent print nothing on STDOUT\n"); |
| 26 |
|
|
printf(" -g | --debug be very verbose [default: no]\n"); |
| 27 |
|
|
printf(" -boot number CPU boot number [default = taken from VarDump]\n"); |
| 28 |
|
|
printf(" -autoboot if no VarDump found try to determine the BOOT number\n"); |
| 29 |
|
|
printf(" looking at timesync [default]\n"); |
| 30 |
|
|
printf(" -no-autoboot disable previous check\n"); |
| 31 |
|
|
printf(" -tsync number timesync (s) [default = taken from data]\n"); |
| 32 |
|
|
printf(" -obt0 number obt at timesync (ms) [default = taken from data]\n"); |
| 33 |
mocchiut |
1.19 |
printf(" -dworbit number number is the downlink orbit number (to be used with non-standard names)\n"); |
| 34 |
mocchiut |
1.20 |
printf(" -static use static path inside the DB instead of symbolic names\n"); |
| 35 |
mocchiut |
1.25 |
// printf(" -gpamela shortcut to \"-clean 0 -obt0 1 -tsync 1 -no-autoboot -boot 1 -dworbit 1 -static\"\n"); |
| 36 |
|
|
printf(" -gpamela shortcut to \"-clean 0 -obt0 1 -no-autoboot -dworbit 1 -static\"\n"); |
| 37 |
mocchiut |
1.14 |
printf(" -clean number number in seconds after which the fragment table\n"); |
| 38 |
|
|
printf(" can be cleaned and runs validated [default = -1 do not clean],\n"); |
| 39 |
|
|
printf(" if 0 force cleaning immediatly, if negative do not clean\n"); |
| 40 |
|
|
printf(" -remove file remove file and all related runs and calibrations from DB\n"); |
| 41 |
|
|
printf(" file must be the YODA filename (full path is not needed)\n"); |
| 42 |
|
|
printf(" 'same' can be used if in conjuction with -yodaFile\n"); |
| 43 |
|
|
printf(" -validate file validates runs between the two closest calibration to file \n"); |
| 44 |
|
|
printf(" not belonging to file itself. File must be the YODA filename\n"); |
| 45 |
|
|
printf(" 'same' can be used if in conjuction with -yodaFile\n"); |
| 46 |
|
|
printf(" -cleanfrag file clean run fragments for file only\n"); |
| 47 |
|
|
printf(" File must be the YODA filename\n"); |
| 48 |
|
|
printf(" 'same' can be used if in conjuction with -yodaFile\n"); |
| 49 |
|
|
printf(" -nofrag do not leave runs in the fragment table and look for fragments\n"); |
| 50 |
|
|
printf(" in the GL_RUN table.\n"); |
| 51 |
|
|
printf(" -force to be used to reprocess a file or to process a file\n"); |
| 52 |
|
|
printf(" when already validated the surroundings, it is equivalent to:\n"); |
| 53 |
|
|
printf(" -remove same -validate same -cleanfrag same -nofrag\n"); |
| 54 |
mocchiut |
1.15 |
printf(" -check performs some test on the GL_RUN table to check its consistency\n"); |
| 55 |
mocchiut |
1.14 |
printf(" -host name of the DB host [default = $PAM_DBHOST or mysql://localhost/pamelaprod]\n"); |
| 56 |
|
|
printf(" -user username for the DB connection [default = $PAM_DBUSER or \"anonymous\"] \n"); |
| 57 |
|
|
printf(" -psw password for the DB connection [default = $PAM_DBPSW or \"\"]\n"); |
| 58 |
|
|
printf(" -tle <file> ascii file containing TLE obtained from celestrak.org or space-track.org [default = no]\n"); |
| 59 |
mocchiut |
1.2 |
printf("\n The order of input files and options does not matter. \n"); |
| 60 |
mocchiut |
1.14 |
printf("\n Example: \n"); |
| 61 |
mocchiut |
1.16 |
printf(" YodaProfiler -yodaFile /path/to/raw/files/000_000_00000_cln2.root -rawFile /path/to/filesfromyoda/000_000_00000_cln2.pam -v \n\n"); |
| 62 |
mocchiut |
1.1 |
}; |
| 63 |
|
|
// |
| 64 |
|
|
int main(int numinp, char *inps[]){ |
| 65 |
|
|
// |
| 66 |
|
|
// Variables booking |
| 67 |
|
|
// |
| 68 |
|
|
Int_t signal = 0; |
| 69 |
|
|
Int_t nul = 0; |
| 70 |
|
|
UInt_t boot = 0; |
| 71 |
|
|
UInt_t tsync = 0; |
| 72 |
|
|
UInt_t obt0 = 0; |
| 73 |
mocchiut |
1.18 |
UInt_t dwinput = 0; |
| 74 |
mocchiut |
1.12 |
Long64_t olderthan = -1LL; |
| 75 |
mocchiut |
1.1 |
// |
| 76 |
|
|
// |
| 77 |
pam-fi |
1.5 |
TString filerawname = ""; |
| 78 |
|
|
TString filerootname = ""; |
| 79 |
mocchiut |
1.1 |
// |
| 80 |
mocchiut |
1.3 |
TString host = "mysql://localhost/pamelaprod"; |
| 81 |
|
|
TString user = "anonymous"; |
| 82 |
|
|
TString password = ""; |
| 83 |
|
|
// |
| 84 |
mocchiut |
1.10 |
TString tlefilename = ""; |
| 85 |
mocchiut |
1.12 |
// |
| 86 |
mocchiut |
1.9 |
const char *pamdbhost = gSystem->Getenv("PAM_DBHOST"); |
| 87 |
|
|
const char *pamdbuser = gSystem->Getenv("PAM_DBUSER"); |
| 88 |
|
|
const char *pamdbpsw = gSystem->Getenv("PAM_DBPSW"); |
| 89 |
|
|
if ( !pamdbhost ) pamdbhost = ""; |
| 90 |
|
|
if ( !pamdbuser ) pamdbuser = ""; |
| 91 |
|
|
if ( !pamdbpsw ) pamdbpsw = ""; |
| 92 |
mocchiut |
1.3 |
if ( strcmp(pamdbhost,"") ) host = pamdbhost; |
| 93 |
|
|
if ( strcmp(pamdbuser,"") ) user = pamdbuser; |
| 94 |
mocchiut |
1.6 |
if ( strcmp(pamdbpsw,"") ) password = pamdbpsw; |
| 95 |
mocchiut |
1.1 |
// |
| 96 |
|
|
// |
| 97 |
mocchiut |
1.20 |
Bool_t staticp = false; |
| 98 |
mocchiut |
1.3 |
Bool_t beverbose = true; |
| 99 |
mocchiut |
1.1 |
Bool_t debug = false; |
| 100 |
mocchiut |
1.13 |
Bool_t autoboot = true; |
| 101 |
mocchiut |
1.19 |
Bool_t gpamela = false; |
| 102 |
mocchiut |
1.12 |
// |
| 103 |
|
|
Bool_t remove = false; |
| 104 |
|
|
TString remfile = ""; |
| 105 |
|
|
// |
| 106 |
|
|
Bool_t forceclean = false; |
| 107 |
|
|
TString fcleanfile = ""; |
| 108 |
|
|
// |
| 109 |
|
|
Bool_t validate = false; |
| 110 |
|
|
TString validfile = ""; |
| 111 |
|
|
// |
| 112 |
|
|
Bool_t nofrag = false; |
| 113 |
|
|
// |
| 114 |
|
|
Bool_t force = false; |
| 115 |
mocchiut |
1.10 |
// |
| 116 |
mocchiut |
1.15 |
Bool_t check = false; |
| 117 |
|
|
// |
| 118 |
mocchiut |
1.1 |
Int_t i = 0; |
| 119 |
|
|
// |
| 120 |
|
|
if ( numinp > 1 ){ |
| 121 |
|
|
while ( i < numinp ){ |
| 122 |
|
|
if ( !strcmp(inps[i],"--version") ){ |
| 123 |
|
|
YodaProfilerInfo(true); |
| 124 |
|
|
exit(0); |
| 125 |
|
|
}; |
| 126 |
|
|
if ( !strcmp(inps[i],"-h") || !strcmp(inps[i],"--help") ){ |
| 127 |
pam-fi |
1.5 |
|
| 128 |
mocchiut |
1.1 |
usage(); |
| 129 |
|
|
exit(0); |
| 130 |
|
|
}; |
| 131 |
|
|
if ( !strcmp(inps[i],"-rawFile") ) { |
| 132 |
|
|
if ( numinp-1 < i+1 ){ |
| 133 |
|
|
usage(); |
| 134 |
|
|
exit(1); |
| 135 |
|
|
}; |
| 136 |
|
|
filerawname = (TString)inps[i+1]; |
| 137 |
|
|
}; |
| 138 |
|
|
if ( !strcmp(inps[i],"-yodaFile") ) { |
| 139 |
|
|
if ( numinp-1 < i+1 ){ |
| 140 |
|
|
usage(); |
| 141 |
|
|
exit(1); |
| 142 |
|
|
}; |
| 143 |
|
|
filerootname = (TString)inps[i+1]; |
| 144 |
|
|
}; |
| 145 |
mocchiut |
1.12 |
if ( !strcmp(inps[i],"-remove") ) { |
| 146 |
|
|
if ( numinp-1 < i+1 ){ |
| 147 |
|
|
usage(); |
| 148 |
|
|
exit(1); |
| 149 |
|
|
}; |
| 150 |
|
|
remfile = (TString)inps[i+1]; |
| 151 |
|
|
remove = true; |
| 152 |
|
|
}; |
| 153 |
|
|
if ( !strcmp(inps[i],"-cleanfrag") ) { |
| 154 |
|
|
if ( numinp-1 < i+1 ){ |
| 155 |
|
|
usage(); |
| 156 |
|
|
exit(1); |
| 157 |
|
|
}; |
| 158 |
|
|
fcleanfile = (TString)inps[i+1]; |
| 159 |
|
|
forceclean = true; |
| 160 |
|
|
}; |
| 161 |
|
|
if ( !strcmp(inps[i],"-validate") ) { |
| 162 |
|
|
if ( numinp-1 < i+1 ){ |
| 163 |
|
|
usage(); |
| 164 |
|
|
exit(1); |
| 165 |
|
|
}; |
| 166 |
|
|
validfile = (TString)inps[i+1]; |
| 167 |
|
|
validate = true; |
| 168 |
|
|
}; |
| 169 |
mocchiut |
1.19 |
if ( !strcmp(inps[i],"-gpamela") ) { |
| 170 |
|
|
gpamela = true; |
| 171 |
|
|
}; |
| 172 |
mocchiut |
1.20 |
if ( !strcmp(inps[i],"-static") ) { |
| 173 |
|
|
staticp = true; |
| 174 |
|
|
}; |
| 175 |
mocchiut |
1.13 |
if ( !strcmp(inps[i],"-autoboot") ) { |
| 176 |
|
|
autoboot = true; |
| 177 |
|
|
}; |
| 178 |
|
|
if ( !strcmp(inps[i],"-no-autoboot") ) { |
| 179 |
|
|
autoboot = false; |
| 180 |
|
|
}; |
| 181 |
mocchiut |
1.1 |
if ( !strcmp(inps[i],"-boot") ) { |
| 182 |
|
|
if ( numinp-1 < i+1 ){ |
| 183 |
|
|
usage(); |
| 184 |
|
|
exit(1); |
| 185 |
|
|
}; |
| 186 |
|
|
boot = atoi(inps[i+1]); |
| 187 |
|
|
}; |
| 188 |
|
|
if ( !strcmp(inps[i],"-tsync") ) { |
| 189 |
|
|
if ( numinp-1 < i+1 ){ |
| 190 |
|
|
usage(); |
| 191 |
|
|
exit(1); |
| 192 |
|
|
}; |
| 193 |
mocchiut |
1.2 |
tsync = (UInt_t)atoll(inps[i+1]); |
| 194 |
mocchiut |
1.1 |
}; |
| 195 |
|
|
if ( !strcmp(inps[i],"-obt0") ) { |
| 196 |
|
|
if ( numinp-1 < i+1 ){ |
| 197 |
|
|
usage(); |
| 198 |
|
|
exit(1); |
| 199 |
|
|
}; |
| 200 |
mocchiut |
1.2 |
obt0 = (UInt_t)atoll(inps[i+1]); |
| 201 |
|
|
}; |
| 202 |
mocchiut |
1.18 |
if ( !strcmp(inps[i],"-dworbit") ) { |
| 203 |
|
|
if ( numinp-1 < i+1 ){ |
| 204 |
|
|
usage(); |
| 205 |
|
|
exit(1); |
| 206 |
|
|
}; |
| 207 |
|
|
dwinput = (UInt_t)atoll(inps[i+1]); |
| 208 |
|
|
}; |
| 209 |
mocchiut |
1.2 |
if ( !strcmp(inps[i],"-clean") ) { |
| 210 |
|
|
if ( numinp-1 < i+1 ){ |
| 211 |
|
|
usage(); |
| 212 |
|
|
exit(1); |
| 213 |
|
|
}; |
| 214 |
|
|
olderthan = (Long64_t)atoll(inps[i+1]); |
| 215 |
mocchiut |
1.1 |
}; |
| 216 |
|
|
if ( !strcmp(inps[i],"-host") ) { |
| 217 |
|
|
if ( numinp-1 < i+1 ){ |
| 218 |
|
|
usage(); |
| 219 |
|
|
exit(1); |
| 220 |
|
|
}; |
| 221 |
|
|
host = (TString)inps[i+1]; |
| 222 |
|
|
}; |
| 223 |
|
|
if ( !strcmp(inps[i],"-user") ) { |
| 224 |
|
|
if ( numinp-1 < i+1 ){ |
| 225 |
|
|
usage(); |
| 226 |
|
|
exit(1); |
| 227 |
|
|
}; |
| 228 |
|
|
user = (TString)inps[i+1]; |
| 229 |
|
|
}; |
| 230 |
|
|
if ( !strcmp(inps[i],"-psw") ) { |
| 231 |
|
|
if ( numinp-1 < i+1 ){ |
| 232 |
|
|
usage(); |
| 233 |
|
|
exit(1); |
| 234 |
|
|
}; |
| 235 |
|
|
password = (TString)inps[i+1]; |
| 236 |
|
|
}; |
| 237 |
mocchiut |
1.10 |
if ( !strcmp(inps[i],"-tle") ) { |
| 238 |
|
|
if ( numinp-1 < i+1 ){ |
| 239 |
|
|
usage(); |
| 240 |
|
|
exit(1); |
| 241 |
|
|
}; |
| 242 |
|
|
tlefilename = (TString)inps[i+1]; |
| 243 |
|
|
}; |
| 244 |
mocchiut |
1.1 |
// |
| 245 |
|
|
if ( !strcmp(inps[i],"-v") || !strcmp(inps[i],"--verbose") ) beverbose = true; |
| 246 |
|
|
// |
| 247 |
mocchiut |
1.3 |
if ( !strcmp(inps[i],"-s") || !strcmp(inps[i],"--silent") ) beverbose = false; |
| 248 |
|
|
// |
| 249 |
mocchiut |
1.1 |
if ( !strcmp(inps[i],"-g") || !strcmp(inps[i],"--debug") ) debug = true; |
| 250 |
|
|
// |
| 251 |
mocchiut |
1.12 |
if ( !strcmp(inps[i],"-f") || !strcmp(inps[i],"-force") ) force = true; |
| 252 |
|
|
// |
| 253 |
|
|
if ( !strcmp(inps[i],"-nofrag") ) nofrag = true; |
| 254 |
|
|
// |
| 255 |
mocchiut |
1.15 |
if ( !strcmp(inps[i],"-check") ) check = true; |
| 256 |
|
|
// |
| 257 |
mocchiut |
1.1 |
i++; |
| 258 |
|
|
}; |
| 259 |
|
|
} else { |
| 260 |
|
|
// |
| 261 |
|
|
// no input parameters exit with error, we need at least the run id. |
| 262 |
|
|
// |
| 263 |
|
|
cout << "\n ERROR: NO INPUT PARAMETERS \n"; |
| 264 |
|
|
usage(); |
| 265 |
|
|
exit(1); |
| 266 |
|
|
}; |
| 267 |
|
|
|
| 268 |
|
|
// |
| 269 |
|
|
// If not in verbose mode redirect to /dev/null the stdout and stderr |
| 270 |
|
|
// |
| 271 |
|
|
if ( !beverbose ){ |
| 272 |
|
|
nul = open("/dev/null", O_CREAT | O_RDWR,S_IREAD | S_IWRITE); |
| 273 |
|
|
dup2(nul,1); |
| 274 |
|
|
dup2(nul,2); |
| 275 |
|
|
}; |
| 276 |
|
|
// |
| 277 |
mocchiut |
1.12 |
if ( !strcmp(filerootname.Data(),"") ){ |
| 278 |
|
|
if ( (validate && !strcmp(validfile.Data(),"same")) || |
| 279 |
|
|
(remove && !strcmp(remfile.Data(),"same")) || |
| 280 |
|
|
(forceclean && !strcmp(fcleanfile.Data(),"same")) || force ){ |
| 281 |
|
|
printf("\n ERROR IN INPUT PARAMETERS \n"); |
| 282 |
|
|
usage(); |
| 283 |
|
|
exit(1); |
| 284 |
|
|
}; |
| 285 |
|
|
} else { |
| 286 |
|
|
if ( validate && !strcmp(validfile.Data(),"same") ) validfile = (TString)gSystem->BaseName(filerootname.Data()); |
| 287 |
|
|
if ( remove && !strcmp(remfile.Data(),"same") ) remfile = (TString)gSystem->BaseName(filerootname.Data()); |
| 288 |
|
|
if ( forceclean && !strcmp(fcleanfile.Data(),"same") ) fcleanfile = (TString)gSystem->BaseName(filerootname.Data()); |
| 289 |
|
|
}; |
| 290 |
|
|
// |
| 291 |
|
|
if ( force ){ |
| 292 |
|
|
nofrag = true; |
| 293 |
|
|
forceclean = true; |
| 294 |
|
|
remove = true; |
| 295 |
|
|
validate = true; |
| 296 |
|
|
fcleanfile = (TString)gSystem->BaseName(filerootname.Data()); |
| 297 |
|
|
remfile = fcleanfile; |
| 298 |
|
|
validfile = fcleanfile; |
| 299 |
|
|
}; |
| 300 |
mocchiut |
1.25 |
// |
| 301 |
mocchiut |
1.20 |
const char *paml0 = gSystem->Getenv("PAM_L0"); |
| 302 |
|
|
const char *paml2 = gSystem->Getenv("PAM_L2"); |
| 303 |
|
|
const char *pamraw = gSystem->Getenv("PAM_RAW"); |
| 304 |
|
|
if ( !paml0 || !paml2 || !pamraw ){ |
| 305 |
|
|
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"); |
| 306 |
|
|
staticp = true; |
| 307 |
|
|
}; |
| 308 |
mocchiut |
1.25 |
// |
| 309 |
|
|
// |
| 310 |
|
|
GL_TABLES *glt = new GL_TABLES(host,user,password); |
| 311 |
|
|
// |
| 312 |
mocchiut |
1.19 |
if ( gpamela ){ |
| 313 |
mocchiut |
1.25 |
// // -clean 0 -obt0 1 -tsync 1 -boot 1 -dworbit 1 |
| 314 |
|
|
// -clean 0 -obt0 1 -dworbit 1 |
| 315 |
mocchiut |
1.19 |
if ( olderthan < 0LL ) olderthan = 0LL; |
| 316 |
|
|
if ( !obt0 ) obt0 = 1; |
| 317 |
mocchiut |
1.25 |
// if ( !tsync ) tsync = 1; |
| 318 |
|
|
// if ( !boot ) boot = 1; |
| 319 |
mocchiut |
1.19 |
if ( !dwinput ) dwinput = 1; |
| 320 |
mocchiut |
1.20 |
staticp = true; |
| 321 |
mocchiut |
1.19 |
autoboot = false; |
| 322 |
|
|
}; |
| 323 |
mocchiut |
1.12 |
// |
| 324 |
mocchiut |
1.20 |
if ( filerawname == "" && filerootname != "" ){ |
| 325 |
|
|
filerawname = "/not_given/"+(TString)gSystem->BaseName(filerootname.Data()); |
| 326 |
|
|
filerawname = filerawname.ReplaceAll(".root",5,".pam",4); |
| 327 |
|
|
// printf("filerawname %s \n",filerawname.Data()); |
| 328 |
|
|
}; |
| 329 |
|
|
// |
| 330 |
mocchiut |
1.1 |
// Start: |
| 331 |
|
|
TString message; |
| 332 |
|
|
char *version = YodaProfilerInfo(false); |
| 333 |
|
|
PamelaDBOperations *pamDB = 0; |
| 334 |
mocchiut |
1.12 |
UInt_t sizeofwar = 12; |
| 335 |
|
|
UInt_t WAR[12]; |
| 336 |
|
|
memset(WAR, 0, sizeofwar*sizeof(UInt_t)); |
| 337 |
mocchiut |
1.1 |
// |
| 338 |
mocchiut |
1.2 |
printf("\n Welcome to the PAMELA YodaProfiler, version %s \n\n",version); |
| 339 |
mocchiut |
1.1 |
try{ |
| 340 |
|
|
// |
| 341 |
|
|
//------------------------------------------------------------------------------------------- |
| 342 |
|
|
// Create pamDB object and open SQL connection |
| 343 |
|
|
//------------------------------------------------------------------------------------------- |
| 344 |
mocchiut |
1.2 |
if ( beverbose ) printf(" 1 => Initialize and open SQL connection \n"); |
| 345 |
mocchiut |
1.25 |
pamDB = new PamelaDBOperations(host,user,password,filerawname,filerootname,boot,tsync,obt0,debug,tlefilename,dwinput,staticp,gpamela); |
| 346 |
mocchiut |
1.7 |
pamDB->CheckConnection(); |
| 347 |
|
|
//------------------------------------------------------------------------------------------- |
| 348 |
mocchiut |
1.1 |
// |
| 349 |
mocchiut |
1.12 |
pamDB->SetNoFrag(nofrag); |
| 350 |
mocchiut |
1.13 |
pamDB->SetAutoBoot(autoboot); |
| 351 |
mocchiut |
1.12 |
// |
| 352 |
|
|
if ( remove ){ |
| 353 |
|
|
//------------------------------------------------------------------------------------------- |
| 354 |
|
|
// Remove a file and, on cascade, all that follows from the DB |
| 355 |
|
|
//------------------------------------------------------------------------------------------- |
| 356 |
|
|
if ( beverbose ) printf(" X => Remove file %s from DB \n",((TString)gSystem->BaseName(remfile)).Data()); |
| 357 |
|
|
WAR[11] = pamDB->removeFile((TString)gSystem->BaseName(remfile.Data())); |
| 358 |
|
|
//------------------------------------------------------------------------------------------- |
| 359 |
|
|
}; |
| 360 |
|
|
// |
| 361 |
|
|
if( pamDB->InsertRaw() ){ |
| 362 |
mocchiut |
1.7 |
//------------------------------------------------------------------------------------------- |
| 363 |
|
|
//Insert a Raw file in GL_RAW |
| 364 |
|
|
//------------------------------------------------------------------------------------------- |
| 365 |
|
|
if ( beverbose ) printf(" 2 => Insert a RAW file in GL_RAW \n"); |
| 366 |
|
|
WAR[0] = pamDB->insertPamelaRawFile(); |
| 367 |
|
|
//------------------------------------------------------------------------------------------- |
| 368 |
|
|
}; |
| 369 |
mocchiut |
1.12 |
// |
| 370 |
|
|
if( pamDB->InsertRoot() ){ |
| 371 |
|
|
// |
| 372 |
|
|
if( !pamDB->InsertRaw() )printf("=> RAW file not inserted --- the DB might not ( yet ) be filled correctly \n"); |
| 373 |
mocchiut |
1.7 |
pamDB->CheckFile(); |
| 374 |
|
|
// |
| 375 |
|
|
//------------------------------------------------------------------------------------------- |
| 376 |
|
|
//Insert an entry in GL_TIMESYNC |
| 377 |
|
|
//------------------------------------------------------------------------------------------- |
| 378 |
mocchiut |
1.13 |
if ( beverbose ) printf(" 3 => Insert an entry in GL_TIMESYNC \n"); |
| 379 |
mocchiut |
1.7 |
WAR[1] = pamDB->insertPamelaGL_TIMESYNC(); |
| 380 |
|
|
//------------------------------------------------------------------------------------------- |
| 381 |
|
|
// |
| 382 |
mocchiut |
1.13 |
//------------------------------------------------------------------------------------------- |
| 383 |
|
|
//Update a single GL_RAW record with its BOOT_NUMBER |
| 384 |
|
|
//------------------------------------------------------------------------------------------- |
| 385 |
|
|
if ( beverbose ) printf(" 4 => Update a single GL_RAW record with its BOOT_NUMBER \n"); |
| 386 |
|
|
WAR[3] = pamDB->assignBOOT_NUMBER(); |
| 387 |
|
|
if ( WAR[3] && WAR[3] != 1 && WAR[3] != 8 ) throw -9; |
| 388 |
|
|
//------------------------------------------------------------------------------------------- |
| 389 |
|
|
// |
| 390 |
mocchiut |
1.7 |
//------------------------------------------------------------------------------------------- |
| 391 |
|
|
//Insert unpack ROOT file in GL_ROOT |
| 392 |
|
|
//------------------------------------------------------------------------------------------- |
| 393 |
|
|
if ( beverbose ) printf(" 5 => Insert unpack ROOT file in GL_ROOT \n"); |
| 394 |
|
|
WAR[2] = pamDB->insertPamelaRootFile(); |
| 395 |
|
|
//------------------------------------------------------------------------------------------- |
| 396 |
|
|
// |
| 397 |
|
|
//------------------------------------------------------------------------------------------- |
| 398 |
|
|
//Insert in GL_RUN runs information records relative to a single unpack |
| 399 |
|
|
//------------------------------------------------------------------------------------------- |
| 400 |
|
|
if ( beverbose ) printf(" 6 => Scan physics and store runs in the GL_RUN table\n"); |
| 401 |
|
|
WAR[4] = pamDB->insertPamelaRUN(); |
| 402 |
|
|
//------------------------------------------------------------------------------------------- |
| 403 |
pam-fi |
1.5 |
|
| 404 |
mocchiut |
1.7 |
//------------------------------------------------------------------------------------------- |
| 405 |
|
|
//Insert in GL_CALO_CALIB calibration information records relative to a single unpack |
| 406 |
|
|
//------------------------------------------------------------------------------------------- |
| 407 |
|
|
if ( beverbose ) printf(" 7 => Insert calorimeter calibrations in the GL_CALO_CALIB table\n"); |
| 408 |
|
|
WAR[5] = pamDB->insertCALO_CALIB(); |
| 409 |
|
|
//------------------------------------------------------------------------------------------- |
| 410 |
pam-fi |
1.5 |
|
| 411 |
mocchiut |
1.7 |
//------------------------------------------------------------------------------------------- |
| 412 |
|
|
//Insert in GL_TRK_CALIB calibration information records relative to a single unpack |
| 413 |
|
|
//------------------------------------------------------------------------------------------- |
| 414 |
|
|
if ( beverbose ) printf(" 8 => Insert tracker calibrations in the GL_TRK_CALIB table\n"); |
| 415 |
|
|
WAR[6] = pamDB->insertTRK_CALIB(); |
| 416 |
|
|
//------------------------------------------------------------------------------------------- |
| 417 |
pam-fi |
1.5 |
|
| 418 |
mocchiut |
1.7 |
//------------------------------------------------------------------------------------------- |
| 419 |
|
|
//Insert in GL_S4_CALIB calibration information records relative to a single unpack |
| 420 |
|
|
//------------------------------------------------------------------------------------------- |
| 421 |
|
|
if ( beverbose ) printf(" 9 => Insert S4 calibrations in the GL_S4_CALIB table\n"); |
| 422 |
|
|
WAR[7] = pamDB->insertS4_CALIB(); |
| 423 |
|
|
//------------------------------------------------------------------------------------------- |
| 424 |
|
|
}; |
| 425 |
|
|
// |
| 426 |
mocchiut |
1.12 |
if ( forceclean ){ |
| 427 |
|
|
//------------------------------------------------------------------------------------------- |
| 428 |
|
|
//Clean the GL_RUN_FRAGMENTS for the given file |
| 429 |
|
|
//------------------------------------------------------------------------------------------- |
| 430 |
|
|
if ( beverbose ) printf(" 10 => Clean the GL_RUN_FRAGMENTS table for file %s \n",fcleanfile.Data()); |
| 431 |
|
|
WAR[8] = pamDB->CleanGL_RUN_FRAGMENTS((TString)gSystem->BaseName(fcleanfile.Data())); |
| 432 |
|
|
}; |
| 433 |
|
|
// |
| 434 |
|
|
// |
| 435 |
|
|
if ( validate ){ |
| 436 |
|
|
//------------------------------------------------------------------------------------------- |
| 437 |
|
|
//Validate runs |
| 438 |
|
|
//------------------------------------------------------------------------------------------- |
| 439 |
|
|
if ( beverbose ) printf(" 11 => Validate runs table for file %s \n",validfile.Data()); |
| 440 |
|
|
WAR[9] = pamDB->ValidateRuns((TString)gSystem->BaseName(validfile.Data())); |
| 441 |
|
|
//------------------------------------------------------------------------------------------- |
| 442 |
|
|
}; |
| 443 |
|
|
// |
| 444 |
mocchiut |
1.7 |
pamDB->CheckValidate(olderthan); |
| 445 |
|
|
// |
| 446 |
mocchiut |
1.12 |
if( pamDB->Validate() ){ |
| 447 |
mocchiut |
1.7 |
//------------------------------------------------------------------------------------------- |
| 448 |
|
|
//Clean the GL_RUN_FRAGMENTS |
| 449 |
|
|
//------------------------------------------------------------------------------------------- |
| 450 |
mocchiut |
1.8 |
if ( beverbose ) printf(" 10 => Clean the GL_RUN_FRAGMENTS table (earlier than %s) \n",pamDB->GetCleanTime() ); |
| 451 |
mocchiut |
1.7 |
WAR[8] = pamDB->CleanGL_RUN_FRAGMENTS(); |
| 452 |
mocchiut |
1.12 |
//------------------------------------------------------------------------------------------- |
| 453 |
mocchiut |
1.7 |
//------------------------------------------------------------------------------------------- |
| 454 |
|
|
//Validate runs |
| 455 |
|
|
//------------------------------------------------------------------------------------------- |
| 456 |
mocchiut |
1.8 |
if ( beverbose ) printf(" 11 => Validate runs (earlier than %s)\n",pamDB->GetCleanTime()); |
| 457 |
mocchiut |
1.7 |
WAR[9] = pamDB->ValidateRuns(); |
| 458 |
|
|
//------------------------------------------------------------------------------------------- |
| 459 |
|
|
}; |
| 460 |
mocchiut |
1.10 |
|
| 461 |
|
|
if(! tlefilename.IsNull() ) { |
| 462 |
|
|
//---------------------------------------------- |
| 463 |
|
|
//Populate GL_TLE table using the file provided |
| 464 |
|
|
//---------------------------------------------- |
| 465 |
|
|
if ( beverbose ) printf(" 12 => Insert TLE elements in the GL_TLE table from file %s \n",tlefilename.Data()); |
| 466 |
|
|
WAR[10] = pamDB->populateTLE(); |
| 467 |
|
|
} |
| 468 |
mocchiut |
1.15 |
|
| 469 |
|
|
if ( check ){ |
| 470 |
|
|
//---------------------------------------------- |
| 471 |
|
|
//Check GL_RUN table consistency |
| 472 |
|
|
//---------------------------------------------- |
| 473 |
|
|
if ( beverbose ) printf(" 13 => Check GL_RUN table consistency\n"); |
| 474 |
|
|
UInt_t ch = pamDB->Check(); |
| 475 |
|
|
if ( !ch ){ |
| 476 |
|
|
printf(" GL_RUN table seems ok!\n"); |
| 477 |
|
|
} else { |
| 478 |
|
|
printf(" Problems found in the GL_RUN table!\n"); |
| 479 |
|
|
}; |
| 480 |
|
|
}; |
| 481 |
pam-fi |
1.5 |
|
| 482 |
mocchiut |
1.1 |
} catch (Int_t exc) { |
| 483 |
|
|
signal = exc; |
| 484 |
|
|
switch(exc){ |
| 485 |
|
|
case -1: message += " DB connection failure"; break; |
| 486 |
|
|
case -2: message += " Connection failure"; break; |
| 487 |
|
|
case -3: message += " Cannot determine the timesync, use the -tsync and -obt0 options to override"; break; |
| 488 |
|
|
case -4: message += " Error querying DB"; break; |
| 489 |
|
|
case -5: message += " Inconsistent OBT/pkt_num"; break; |
| 490 |
|
|
case -6: message += " The file is not in the database"; break; |
| 491 |
mocchiut |
1.10 |
case -7: message += " Cannot open TLE file"; break; |
| 492 |
mocchiut |
1.1 |
case -8: message += " Event file is empty"; break; |
| 493 |
|
|
case -9: message += " No VarDump no BOOT number, use the -boot option to override"; break; |
| 494 |
|
|
case -10: message += " No results from DB"; break; |
| 495 |
|
|
case -11: message += " Raw file not found"; break; |
| 496 |
|
|
case -12: message += " Cannot open Level0 file"; break; |
| 497 |
|
|
case -13: message += " No consistent OBT/PKT_NUM information"; break; |
| 498 |
|
|
case -14: message += " Not supported yet: run with no events, no runtrailer, no runheader"; break; |
| 499 |
|
|
case -15: message += " Not supported yet: run with no runheader at the beginning/end of file not recognized as run fragment"; break; |
| 500 |
|
|
case -16: message += " No Physics tree in Level0 file"; break; |
| 501 |
|
|
case -17: message += " No RunHeader tree in Level0 file"; break; |
| 502 |
|
|
case -18: message += " No RunTrailer tree in Level0 file"; break; |
| 503 |
|
|
case -19: message += " No Mcmd tree in Level0 file"; break; |
| 504 |
|
|
case -20: message += " No VarDump tree in Level0 file"; break; |
| 505 |
|
|
case -21: message += " No CalibCalPed tree in Level0 file"; break; |
| 506 |
|
|
case -22: message += " No CalibTrk1 tree in Level0 file"; break; |
| 507 |
|
|
case -23: message += " No CalibTrk2 tree in Level0 file"; break; |
| 508 |
|
|
case -24: message += " No CalibS4 tree in Level0 file"; break; |
| 509 |
mocchiut |
1.2 |
case -25: message += " Cannot find the run just inserted"; break; |
| 510 |
|
|
case -26: message += " Raw file not found looking for VarDump"; break; |
| 511 |
mocchiut |
1.11 |
case -27: message += " Cannot determine downlink orbit, wrong filename format?"; break; |
| 512 |
|
|
case -28: message += " Cannot assign a RUN ID unique number!"; break; |
| 513 |
mocchiut |
1.13 |
case -29: message += " No VarDump and impossible to find a consistent BOOT number, use the -boot option to override"; break; |
| 514 |
mocchiut |
1.1 |
default: message += " Unidentified error"; break; |
| 515 |
|
|
}; |
| 516 |
|
|
printf("\n"); |
| 517 |
|
|
printf(" ERROR (%i) %s \n",exc,message.Data()); |
| 518 |
|
|
printf("\n"); |
| 519 |
|
|
} |
| 520 |
|
|
// |
| 521 |
|
|
// warnings handlers |
| 522 |
|
|
// |
| 523 |
|
|
Bool_t printwarning = false; |
| 524 |
|
|
message=""; |
| 525 |
|
|
for (UInt_t j=0; j<sizeofwar; j++){ |
| 526 |
|
|
if ( WAR[j] ){ |
| 527 |
|
|
printwarning = true; |
| 528 |
|
|
// |
| 529 |
|
|
if ( j == 0 ){ // insertPamelaRaw warnings |
| 530 |
|
|
for (UInt_t bit=0; bit<32; bit++){ |
| 531 |
|
|
if ( WAR[j] & (1 << bit) ){ |
| 532 |
|
|
if ( bit == 0 ) message += "=> RAW file already inserted\n"; |
| 533 |
mocchiut |
1.2 |
else message += "=> Unidentified insertPamelaRaw warning\n"; |
| 534 |
mocchiut |
1.1 |
}; |
| 535 |
|
|
}; |
| 536 |
|
|
}; |
| 537 |
|
|
// |
| 538 |
|
|
if ( j == 1 ){ // insertTimeSync warnings |
| 539 |
|
|
for (UInt_t bit=0; bit<32; bit++){ |
| 540 |
|
|
if ( WAR[j] & (1 << bit) ){ |
| 541 |
|
|
if ( bit == 0 ) message += "=> TIMESYNC already inserted\n"; |
| 542 |
mocchiut |
1.2 |
else if ( bit == 1 ) message += "=> No mcmd timesync in the file\n"; |
| 543 |
|
|
else if ( bit == 2 ) message += "=> No runheaders in the file\n"; |
| 544 |
|
|
else if ( bit == 3 ) message += "=> No runtrailers in the file\n"; |
| 545 |
|
|
else if ( bit == 4 ) message += "=> No mcmd inclination in the file\n"; |
| 546 |
mocchiut |
1.21 |
else if ( bit == 5 ) message += "=> Inconsistent PKT/OBT sequence\n"; |
| 547 |
|
|
else if ( bit == 6 ) message += "=> No physics events in the file\n"; |
| 548 |
|
|
else if ( bit == 7 ) message += "=> Less than 2 physics events in the file\n"; |
| 549 |
mocchiut |
1.2 |
else message += "=> Unidentified insertTimeSync warning\n"; |
| 550 |
mocchiut |
1.1 |
}; |
| 551 |
|
|
}; |
| 552 |
|
|
}; |
| 553 |
|
|
// |
| 554 |
|
|
if ( j == 2 ){ // insertPamelaRoot warnings |
| 555 |
|
|
for (UInt_t bit=0; bit<32; bit++){ |
| 556 |
|
|
if ( WAR[j] & (1 << bit) ){ |
| 557 |
|
|
if ( bit == 0 ) message += "=> ROOT file already inserted\n"; |
| 558 |
mocchiut |
1.2 |
else message += "=> Unidentified insertPamelaRoot warning\n"; |
| 559 |
mocchiut |
1.1 |
}; |
| 560 |
|
|
}; |
| 561 |
|
|
}; |
| 562 |
|
|
// |
| 563 |
|
|
if ( j == 3 ){ // assignBOOTnumber warnings |
| 564 |
|
|
for (UInt_t bit=0; bit<32; bit++){ |
| 565 |
|
|
if ( WAR[j] & (1 << bit) ){ |
| 566 |
mocchiut |
1.2 |
if ( bit == 0 ) message += "=> BOOT number already inserted\n";// |
| 567 |
|
|
else if ( bit == 1 ) message += "=> VarDump event tree is empty, use the -boot option to override\n";// |
| 568 |
|
|
else if ( bit == 2 ) message += "=> No BOOT number in VarDump(!), use the -boot option to override\n";// |
| 569 |
mocchiut |
1.13 |
else if ( bit == 3 ) message += "=> No VarDump! autoboot option used\n";// |
| 570 |
mocchiut |
1.2 |
else if ( bit == 4 ) message += "=> The file is not in the database looking for VarDump, use the -boot option to override\n";// |
| 571 |
|
|
else message += "=> Unidentified assignBOOTnumber warning\n"; |
| 572 |
mocchiut |
1.1 |
}; |
| 573 |
|
|
}; |
| 574 |
|
|
}; |
| 575 |
|
|
// |
| 576 |
|
|
if ( j == 4 ){ // insertPamelaRUN |
| 577 |
|
|
for (UInt_t bit=0; bit<32; bit++){ |
| 578 |
|
|
if ( WAR[j] & (1 << bit) ){ |
| 579 |
mocchiut |
1.2 |
if ( bit == 0 ) message += "=> Inconsistent PKT/OBT sequence\n"; |
| 580 |
|
|
else if ( bit == 1 ) message += "=> No physics events in the file\n"; |
| 581 |
|
|
else if ( bit == 2 ) message += "=> Less than 2 physics events in the file\n"; |
| 582 |
mocchiut |
1.23 |
else if ( bit == 3 ) message += "=> Not supported yet: run with no events, no runtrailer, no runheader\n"; |
| 583 |
mocchiut |
1.24 |
else if ( bit == 4 ) message += "=> File with no events, no runtrailers, no runheaders\n"; |
| 584 |
mocchiut |
1.2 |
else message += "=> Unidentified insertPamelaRun warning\n"; |
| 585 |
mocchiut |
1.1 |
}; |
| 586 |
|
|
}; |
| 587 |
|
|
}; |
| 588 |
|
|
// |
| 589 |
|
|
if ( j == 5 ){ // insertCALO_CALIB |
| 590 |
|
|
for (UInt_t bit=0; bit<32; bit++){ |
| 591 |
|
|
if ( WAR[j] & (1 << bit) ){ |
| 592 |
mocchiut |
1.2 |
if ( bit == 0 ) message += "=> No calorimeter calibrations in the file\n"; |
| 593 |
|
|
else message += "=> Unidentified insertCaloCalib warning\n"; |
| 594 |
mocchiut |
1.1 |
}; |
| 595 |
|
|
}; |
| 596 |
|
|
}; |
| 597 |
|
|
// |
| 598 |
|
|
// |
| 599 |
|
|
if ( j == 6 ){ // insertTRACKER_CALIB |
| 600 |
|
|
for (UInt_t bit=0; bit<32; bit++){ |
| 601 |
|
|
if ( WAR[j] & (1 << bit) ){ |
| 602 |
mocchiut |
1.2 |
if ( bit == 0 ) message += "=> No tracker calibrations in the file\n"; |
| 603 |
|
|
else message += "=> Unidentified insertTrkCalib warning\n"; |
| 604 |
mocchiut |
1.1 |
}; |
| 605 |
|
|
}; |
| 606 |
|
|
}; |
| 607 |
|
|
// |
| 608 |
|
|
// |
| 609 |
|
|
if ( j == 7 ){ // insertS4_CALIB |
| 610 |
|
|
for (UInt_t bit=0; bit<32; bit++){ |
| 611 |
|
|
if ( WAR[j] & (1 << bit) ){ |
| 612 |
mocchiut |
1.2 |
if ( bit == 0 ) message += "=> No s4 calibrations in the file\n"; |
| 613 |
|
|
else message += "=> Unidentified insertS4calib warning\n"; |
| 614 |
|
|
}; |
| 615 |
|
|
}; |
| 616 |
|
|
}; |
| 617 |
|
|
// |
| 618 |
|
|
// |
| 619 |
|
|
if ( j == 8 ){ // CleanGL_RUN_FRAGMENTS |
| 620 |
|
|
for (UInt_t bit=0; bit<32; bit++){ |
| 621 |
|
|
if ( WAR[j] & (1 << bit) ){ |
| 622 |
|
|
if ( bit == 0 ) message += "=> Skip the GL_RUN_FRAGMENTS table cleaning\n"; |
| 623 |
mocchiut |
1.12 |
if ( bit == 1 ) message += "=> Problems retrieving ROOT ID from DB\n"; |
| 624 |
mocchiut |
1.2 |
else message += "=> Unidentified CleanGL_RUN_FRAGMENTS warning\n"; |
| 625 |
mocchiut |
1.1 |
}; |
| 626 |
|
|
}; |
| 627 |
|
|
}; |
| 628 |
|
|
// |
| 629 |
mocchiut |
1.2 |
if ( j == 9 ){ // ValidateRuns |
| 630 |
|
|
for (UInt_t bit=0; bit<32; bit++){ |
| 631 |
|
|
if ( WAR[j] & (1 << bit) ){ |
| 632 |
|
|
if ( bit == 0 ) message += "=> Skip the run validation \n"; |
| 633 |
mocchiut |
1.12 |
if ( bit == 1 ) message += "=> Problems retrieving ROOT ID from DB\n"; |
| 634 |
mocchiut |
1.2 |
else message += "=> Unidentified ValidateRuns warning\n"; |
| 635 |
|
|
}; |
| 636 |
|
|
}; |
| 637 |
|
|
}; |
| 638 |
mocchiut |
1.10 |
// |
| 639 |
|
|
if ( j == 10 ){ // populateTLE |
| 640 |
|
|
for (UInt_t bit=0; bit<32; bit++){ |
| 641 |
|
|
if ( WAR[j] & (1 << bit) ){ |
| 642 |
|
|
if ( bit == 0 ) message += "=> TLE insertion failed\n"; |
| 643 |
|
|
if ( bit == 1 ) message += "=> No new TLE available\n"; |
| 644 |
|
|
else message += "=> Unidentified populateTle warning\n"; |
| 645 |
|
|
}; |
| 646 |
|
|
}; |
| 647 |
|
|
}; |
| 648 |
mocchiut |
1.12 |
// |
| 649 |
|
|
if ( j == 11 ){ // removeFile |
| 650 |
|
|
for (UInt_t bit=0; bit<32; bit++){ |
| 651 |
|
|
if ( WAR[j] & (1 << bit) ){ |
| 652 |
|
|
if ( bit == 0 ) message += "=> No file to delete from DB \n"; |
| 653 |
|
|
else message += "=> Unidentified populateTle warning\n"; |
| 654 |
|
|
}; |
| 655 |
|
|
}; |
| 656 |
|
|
}; |
| 657 |
mocchiut |
1.1 |
}; |
| 658 |
|
|
}; |
| 659 |
|
|
// |
| 660 |
|
|
if ( printwarning ){ |
| 661 |
|
|
printf("\n"); |
| 662 |
|
|
printf(" WARNING(s):\n%s\n",message.Data()); |
| 663 |
|
|
printf("\n"); |
| 664 |
|
|
if ( !signal ) signal = 1; |
| 665 |
|
|
}; |
| 666 |
|
|
// |
| 667 |
|
|
//--------------------------------------------------------------------------------------- |
| 668 |
|
|
// Close and exit |
| 669 |
|
|
//--------------------------------------------------------------------------------------- |
| 670 |
mocchiut |
1.10 |
if ( beverbose ) printf(" 13 => Free objects and close SQL connection \n"); |
| 671 |
mocchiut |
1.1 |
pamDB->Close(); |
| 672 |
|
|
// |
| 673 |
mocchiut |
1.17 |
if ( debug ) printf(" Total number of queries through GLTABLES: %u \n",glt->GetNqueries()); |
| 674 |
|
|
delete glt; |
| 675 |
|
|
// |
| 676 |
mocchiut |
1.1 |
printf("\n"); |
| 677 |
|
|
printf(" Finished, exiting...\n"); |
| 678 |
|
|
printf("\n"); |
| 679 |
|
|
// |
| 680 |
|
|
// Close redirection if the case. |
| 681 |
|
|
// |
| 682 |
|
|
if ( !beverbose ) close(nul); |
| 683 |
|
|
// |
| 684 |
|
|
exit(signal); |
| 685 |
|
|
// |
| 686 |
|
|
} |