| 13 |
#include <TClassEdit.h> |
#include <TClassEdit.h> |
| 14 |
#include <TObject.h> |
#include <TObject.h> |
| 15 |
#include <TList.h> |
#include <TList.h> |
| 16 |
#include <TArrayL.h> |
#include <TArrayI.h> |
| 17 |
#include <TSystem.h> |
#include <TSystem.h> |
| 18 |
#include <TSystemDirectory.h> |
#include <TSystemDirectory.h> |
| 19 |
#include <TString.h> |
#include <TString.h> |
| 26 |
// YODA headers |
// YODA headers |
| 27 |
// |
// |
| 28 |
#include <PamelaRun.h> |
#include <PamelaRun.h> |
|
#include <RegistryEvent.h> |
|
| 29 |
#include <PscuHeader.h> |
#include <PscuHeader.h> |
| 30 |
#include <PscuEvent.h> |
#include <PscuEvent.h> |
| 31 |
#include <EventHeader.h> |
#include <EventHeader.h> |
|
#include <RegistryEvent.h> |
|
| 32 |
// |
// |
| 33 |
// RunInfo header |
// RunInfo header |
| 34 |
// |
// |
| 47 |
// CORE ROUTINE |
// CORE ROUTINE |
| 48 |
// |
// |
| 49 |
// |
// |
| 50 |
|
int OrbitalInfoCore(UInt_t run, TFile *file, TSQLServer *dbc, Int_t OrbitalInfoargc, char *OrbitalInfoargv[]){ |
|
int OrbitalInfoCore(ULong64_t run, TFile *file, TSQLServer *dbc, Int_t OrbitalInfoargc, char *OrbitalInfoargv[]){ |
|
| 51 |
Int_t i = 0; |
Int_t i = 0; |
| 52 |
// |
// |
| 53 |
TString processFolder = "OrbitalInfoFolder"; |
TString processFolder = "OrbitalInfoFolder"; |
| 81 |
const char* outDir = gSystem->DirName(gSystem->DirName(file->GetPath())); |
const char* outDir = gSystem->DirName(gSystem->DirName(file->GetPath())); |
| 82 |
// |
// |
| 83 |
TTree *OrbitalInfotr = 0; |
TTree *OrbitalInfotr = 0; |
| 84 |
Long64_t nevents = 0LL; |
UInt_t nevents = 0; |
| 85 |
// |
// |
| 86 |
// variables needed to reprocess data |
// variables needed to reprocess data |
| 87 |
// |
// |
| 88 |
TString OrbitalInfoversion; |
TString OrbitalInfoversion; |
| 89 |
ItoRunInfo *runinfo = 0; |
ItoRunInfo *runinfo = 0; |
| 90 |
TArrayL *runlist = 0; |
TArrayI *runlist = 0; |
| 91 |
TTree *OrbitalInfotrclone = 0; |
TTree *OrbitalInfotrclone = 0; |
| 92 |
Bool_t reproc = false; |
Bool_t reproc = false; |
| 93 |
Bool_t reprocall = false; |
Bool_t reprocall = false; |
| 96 |
UInt_t numbofrun = 0; |
UInt_t numbofrun = 0; |
| 97 |
stringstream ftmpname; |
stringstream ftmpname; |
| 98 |
TString fname; |
TString fname; |
| 99 |
Long64_t totfileentries = 0ULL; |
UInt_t totfileentries = 0; |
| 100 |
Long64_t idRun = 0LL; |
UInt_t idRun = 0; |
| 101 |
// |
// |
| 102 |
// variables needed to handle error signals |
// variables needed to handle error signals |
| 103 |
// |
// |
| 113 |
// |
// |
| 114 |
TFile *l0File = 0; |
TFile *l0File = 0; |
| 115 |
TTree *l0tr = 0; |
TTree *l0tr = 0; |
|
TBranch *l0registry = 0; |
|
|
pamela::RegistryEvent *l0reg=0; |
|
| 116 |
// EM: open also header branch |
// EM: open also header branch |
| 117 |
TBranch *l0head = 0; |
TBranch *l0head = 0; |
| 118 |
pamela::EventHeader *eh = 0; |
pamela::EventHeader *eh = 0; |
| 126 |
stringstream file3; |
stringstream file3; |
| 127 |
stringstream qy; |
stringstream qy; |
| 128 |
Int_t totevent = 0; |
Int_t totevent = 0; |
| 129 |
ULong64_t atime = 0ULL; |
UInt_t atime = 0; |
| 130 |
Int_t ei = 0; |
UInt_t re = 0; |
|
Int_t re = 0; |
|
| 131 |
// |
// |
| 132 |
// Working filename |
// Working filename |
| 133 |
// |
// |
| 154 |
// DB classes |
// DB classes |
| 155 |
// |
// |
| 156 |
GL_ROOT *glroot = new GL_ROOT(); |
GL_ROOT *glroot = new GL_ROOT(); |
| 157 |
|
GL_TIMESYNC *dbtime = 0; |
| 158 |
// |
// |
| 159 |
// Let's start! |
// Let's start! |
| 160 |
// |
// |
| 162 |
// if run != 0 we must process only that run but first we have to check if the tree MyDetector2 already exist in the file |
// if run != 0 we must process only that run but first we have to check if the tree MyDetector2 already exist in the file |
| 163 |
// if it exists we are reprocessing data and we must delete that entries, if not we must create it. |
// if it exists we are reprocessing data and we must delete that entries, if not we must create it. |
| 164 |
// |
// |
| 165 |
if ( run == 0ULL ) reproc = true; |
if ( run == 0 ) reproc = true; |
| 166 |
// |
// |
| 167 |
// |
// |
| 168 |
// Output file is "outputfile" |
// Output file is "outputfile" |
| 219 |
// tree does not exist, we are not reprocessing |
// tree does not exist, we are not reprocessing |
| 220 |
// |
// |
| 221 |
reproc = false; |
reproc = false; |
| 222 |
if ( run == 0ULL ){ |
if ( run == 0 ){ |
| 223 |
if (verbose) printf(" OrbitalInfo - WARNING: you are reprocessing data but OrbitalInfo tree does not exist!\n"); |
if (verbose) printf(" OrbitalInfo - WARNING: you are reprocessing data but OrbitalInfo tree does not exist!\n"); |
| 224 |
} |
} |
| 225 |
if ( runinfo->IsReprocessing() && run != 0ULL ) { |
if ( runinfo->IsReprocessing() && run != 0 ) { |
| 226 |
if (verbose) printf(" OrbitalInfo - WARNING: it seems you are not reprocessing data but OrbitalInfo\n versioning information already exists in RunInfo.\n"); |
if (verbose) printf(" OrbitalInfo - WARNING: it seems you are not reprocessing data but OrbitalInfo\n versioning information already exists in RunInfo.\n"); |
| 227 |
} |
} |
| 228 |
} else { |
} else { |
| 234 |
// |
// |
| 235 |
if (verbose) printf("\n Preparing the pre-processing...\n"); |
if (verbose) printf("\n Preparing the pre-processing...\n"); |
| 236 |
// |
// |
| 237 |
if ( run == 0ULL ){ |
if ( run == 0 ){ |
| 238 |
// |
// |
| 239 |
// we are reprocessing all the file |
// we are reprocessing all the file |
| 240 |
// if we are reprocessing everything we don't need to copy any old event and we can just work with the new tree and delete the old one immediately |
// if we are reprocessing everything we don't need to copy any old event and we can just work with the new tree and delete the old one immediately |
| 249 |
// |
// |
| 250 |
reprocall = false; |
reprocall = false; |
| 251 |
// |
// |
| 252 |
if (verbose) printf("\n OrbitalInfo - WARNING: Reprocessing run number %llu \n",run); |
if (verbose) printf("\n OrbitalInfo - WARNING: Reprocessing run number %u \n",run); |
| 253 |
// |
// |
| 254 |
// copying old tree to a new file |
// copying old tree to a new file |
| 255 |
// |
// |
| 285 |
if ( nobefrun > 0 ){ |
if ( nobefrun > 0 ){ |
| 286 |
if (verbose){ |
if (verbose){ |
| 287 |
printf("\n Pre-processing: copying events from the old tree before the processed run\n"); |
printf("\n Pre-processing: copying events from the old tree before the processed run\n"); |
| 288 |
printf(" Copying %u events in the file which are before the beginning of the run %llu \n",nobefrun,run); |
printf(" Copying %u events in the file which are before the beginning of the run %u \n",nobefrun,run); |
| 289 |
printf(" Start copying at event number 0, end copying at event number %u \n",nobefrun); |
printf(" Start copying at event number 0, end copying at event number %u \n",nobefrun); |
| 290 |
} |
} |
| 291 |
for (UInt_t j = 0; j < nobefrun; j++){ |
for (UInt_t j = 0; j < nobefrun; j++){ |
| 294 |
// |
// |
| 295 |
// copy orbitalinfoclone to mydec |
// copy orbitalinfoclone to mydec |
| 296 |
// |
// |
|
// orbitalinfo = new OrbitalInfo(); |
|
| 297 |
orbitalinfo->Clear(); |
orbitalinfo->Clear(); |
| 298 |
|
// |
| 299 |
memcpy(&orbitalinfo,&orbitalinfoclone,sizeof(orbitalinfoclone)); |
memcpy(&orbitalinfo,&orbitalinfoclone,sizeof(orbitalinfoclone)); |
| 300 |
// |
// |
| 301 |
// Fill entry in the new tree |
// Fill entry in the new tree |
| 324 |
printf(" ####################################################################### \n\n\n"); |
printf(" ####################################################################### \n\n\n"); |
| 325 |
} |
} |
| 326 |
// |
// |
| 327 |
runinfo->ID_REG_RUN = 0ULL; |
runinfo->ID_ROOT_L0 = 0; |
| 328 |
// |
// |
| 329 |
// store in the runinfo class the GL_RUN variables for our run |
// store in the runinfo class the GL_RUN variables for our run |
| 330 |
// |
// |
| 331 |
sgnl = 0; |
sgnl = 0; |
| 332 |
sgnl = runinfo->GetRunInfo(idRun); |
sgnl = runinfo->GetRunInfo(idRun); |
| 333 |
if ( sgnl ){ |
if ( sgnl ){ |
| 334 |
//printf("\n OrbitalInfo - ERROR: RunInfo exited with non-zero status\n"); |
if ( debug ) printf("\n OrbitalInfo - ERROR: RunInfo exited with non-zero status\n"); |
| 335 |
code = sgnl; |
code = sgnl; |
| 336 |
goto closeandexit; |
goto closeandexit; |
| 337 |
} else { |
} else { |
| 340 |
// |
// |
| 341 |
// now you can access that variables using the RunInfo class this way runinfo->ID_REG_RUN |
// now you can access that variables using the RunInfo class this way runinfo->ID_REG_RUN |
| 342 |
// |
// |
| 343 |
if ( runinfo->ID_REG_RUN == 0 ){ |
if ( runinfo->ID_ROOT_L0 == 0 ){ |
| 344 |
//printf("\n OrbitalInfo - ERROR: no run with ID_RUN = %i \n\n Exiting... \n\n",(int)idRun); |
if ( debug ) printf("\n OrbitalInfo - ERROR: no run with ID_RUN = %u \n\n Exiting... \n\n",idRun); |
| 345 |
code = -5; |
code = -5; |
| 346 |
goto closeandexit; |
goto closeandexit; |
| 347 |
}; |
}; |
| 348 |
// |
// |
| 349 |
|
// prepare the timesync for the db |
| 350 |
|
// |
| 351 |
|
dbtime = new GL_TIMESYNC(runinfo->ID_ROOT_L0,"ID",dbc); |
| 352 |
|
// |
| 353 |
// Search in the DB the path and name of the LEVEL0 file to be processed. |
// Search in the DB the path and name of the LEVEL0 file to be processed. |
| 354 |
// |
// |
| 355 |
glroot->Query_GL_ROOT(runinfo->ID_REG_RUN,dbc); |
glroot->Query_GL_ROOT(runinfo->ID_ROOT_L0,dbc); |
| 356 |
// |
// |
| 357 |
ftmpname.str(""); |
ftmpname.str(""); |
| 358 |
ftmpname << glroot->PATH.Data() << "/"; |
ftmpname << glroot->PATH.Data() << "/"; |
| 361 |
// |
// |
| 362 |
// print out informations |
// print out informations |
| 363 |
// |
// |
| 364 |
totevent = runinfo->EV_REG_PHYS_TO - runinfo->EV_REG_PHYS_FROM + 1; |
totevent = runinfo->NEVENTS; |
| 365 |
if (verbose){ |
if (verbose){ |
| 366 |
printf("\n LEVEL0 data file: %s \n",fname.Data()); |
printf("\n LEVEL0 data file: %s \n",fname.Data()); |
| 367 |
printf(" RUN HEADER absolute time is: %llu \n",runinfo->RUNHEADER_TIME); |
printf(" RUN HEADER absolute time is: %u \n",runinfo->RUNHEADER_TIME); |
| 368 |
printf(" RUN TRAILER absolute time is: %llu \n",runinfo->RUNTRAILER_TIME); |
printf(" RUN TRAILER absolute time is: %u \n",runinfo->RUNTRAILER_TIME); |
| 369 |
printf(" %i events to be processed for run %llu: from %i to %i (reg entries)\n\n",totevent,idRun,runinfo->EV_REG_PHYS_FROM,runinfo->EV_REG_PHYS_TO); |
printf(" %i events to be processed for run %u: from %i to %i \n\n",totevent,idRun,runinfo->EV_FROM,runinfo->EV_FROM+totevent); |
| 370 |
}// |
}// |
| 371 |
// Open Level0 file |
// Open Level0 file |
| 372 |
l0File = new TFile(fname.Data()); |
l0File = new TFile(fname.Data()); |
| 373 |
if ( !l0File ) { |
if ( !l0File ) { |
| 374 |
//printf(" OrbitalInfo - ERROR: problems opening Level0 file\n"); |
if ( debug ) printf(" OrbitalInfo - ERROR: problems opening Level0 file\n"); |
| 375 |
code = -6; |
code = -6; |
| 376 |
goto closeandexit; |
goto closeandexit; |
| 377 |
}; |
}; |
| 378 |
l0tr = (TTree*)l0File->Get("Physics"); |
l0tr = (TTree*)l0File->Get("Physics"); |
| 379 |
if ( !l0tr ) { |
if ( !l0tr ) { |
| 380 |
//printf(" OrbitalInfo - ERROR: no Physics tree in Level0 file\n"); |
if ( debug ) printf(" OrbitalInfo - ERROR: no Physics tree in Level0 file\n"); |
| 381 |
l0File->Close(); |
l0File->Close(); |
| 382 |
code = -7; |
code = -7; |
| 383 |
goto closeandexit; |
goto closeandexit; |
| 385 |
// EM: open header branch as well |
// EM: open header branch as well |
| 386 |
l0head = l0tr->GetBranch("Header"); |
l0head = l0tr->GetBranch("Header"); |
| 387 |
if ( !l0head ) { |
if ( !l0head ) { |
| 388 |
//if ( verbose ) printf(" CALORIMETER - ERROR: no Header branch in Level0 tree\n"); |
if ( debug ) printf(" OrbitalInfo - ERROR: no Header branch in Level0 tree\n"); |
| 389 |
l0File->Close(); |
l0File->Close(); |
| 390 |
code = -8; |
code = -8; |
| 391 |
goto closeandexit; |
goto closeandexit; |
| 392 |
}; |
}; |
| 393 |
l0tr->SetBranchAddress("Header", &eh); |
l0tr->SetBranchAddress("Header", &eh); |
| 394 |
// end EM |
// end EM |
| 395 |
l0registry = l0tr->GetBranch("Registry"); |
nevents = l0head->GetEntries(); |
|
if ( !l0registry ) { |
|
|
//printf(" OrbitalInfo - ERROR: no Registry branch in Level0 tree\n"); |
|
|
l0File->Close(); |
|
|
code = -9; |
|
|
goto closeandexit; |
|
|
}; |
|
|
// |
|
|
l0tr->SetBranchAddress("Registry", &l0reg); |
|
|
// |
|
|
nevents = l0registry->GetEntries(); |
|
| 396 |
// |
// |
| 397 |
if ( nevents < 1 ) { |
if ( nevents < 1 ) { |
| 398 |
//printf(" OrbitalInfo - ERROR: Level0 file is empty\n\n"); |
if ( debug ) printf(" OrbitalInfo - ERROR: Level0 file is empty\n\n"); |
| 399 |
l0File->Close(); |
l0File->Close(); |
| 400 |
code = -11; |
code = -11; |
| 401 |
goto closeandexit; |
goto closeandexit; |
| 402 |
}; |
}; |
| 403 |
// |
// |
| 404 |
if ( runinfo->EV_REG_PHYS_TO > nevents-1 ) { |
if ( runinfo->EV_TO > nevents-1 ) { |
| 405 |
//printf(" OrbitalInfo - ERROR: too few entries in the registry tree\n"); |
if ( debug ) printf(" OrbitalInfo - ERROR: too few entries in the registry tree\n"); |
| 406 |
l0File->Close(); |
l0File->Close(); |
| 407 |
code = -12; |
code = -12; |
| 408 |
goto closeandexit; |
goto closeandexit; |
| 412 |
// |
// |
| 413 |
if (verbose) printf("\n Ready to start! \n\n Processed events: \n\n"); |
if (verbose) printf("\n Ready to start! \n\n Processed events: \n\n"); |
| 414 |
// |
// |
| 415 |
for ( re = runinfo->EV_REG_PHYS_FROM; re <= runinfo->EV_REG_PHYS_TO; re++){ |
for ( re = runinfo->EV_FROM; re < (runinfo->EV_FROM+runinfo->NEVENTS); re++){ |
| 416 |
// |
// |
| 417 |
if ( procev%1000 == 0 && procev > 0 && verbose) printf(" %iK \n",procev/1000); |
if ( procev%1000 == 0 && procev > 0 && verbose ) printf(" %iK \n",procev/1000); |
| 418 |
// |
// |
| 419 |
l0registry->GetEntry(re); |
l0head->GetEntry(re); |
| 420 |
// |
// |
| 421 |
// absolute time of this event |
// absolute time of this event |
| 422 |
// |
// |
| 423 |
atime = l0reg->absTime; |
ph = eh->GetPscuHeader(); |
| 424 |
// |
atime = dbtime->DBabsTime(ph->GetOrbitalTime()); |
|
// physics events is at entry number ei where |
|
|
// |
|
|
ei = l0reg->event; |
|
| 425 |
// |
// |
| 426 |
// paranoid check |
// paranoid check |
| 427 |
// |
// |
| 435 |
// start processing |
// start processing |
| 436 |
// |
// |
| 437 |
orbitalinfo->Clear(); |
orbitalinfo->Clear(); |
| 438 |
//orbitalinfo = new OrbitalInfo(); |
// |
| 439 |
orbitalinfo->absTime = l0reg->absTime; |
// CHANGE HERE!!!! |
| 440 |
|
// |
| 441 |
|
orbitalinfo->absTime = atime; |
| 442 |
// EM: add OBT and plt_num infos from the header |
// EM: add OBT and plt_num infos from the header |
|
l0head->GetEntry(ei); |
|
| 443 |
ph = eh->GetPscuHeader(); |
ph = eh->GetPscuHeader(); |
| 444 |
orbitalinfo->pkt_num = ph->GetCounter(); |
orbitalinfo->pkt_num = ph->GetCounter(); |
| 445 |
orbitalinfo->OBT = ph->GetOrbitalTime(); |
orbitalinfo->OBT = ph->GetOrbitalTime(); |
| 454 |
// |
// |
| 455 |
// Here you may want to clear some variables before processing another run |
// Here you may want to clear some variables before processing another run |
| 456 |
// |
// |
| 457 |
ei = 0; |
delete dbtime; |
| 458 |
}; // process all the runs |
}; // process all the runs |
| 459 |
// |
// |
| 460 |
if (verbose) printf("\n Finished processing data \n"); |
if (verbose) printf("\n Finished processing data \n"); |
| 479 |
// copy orbitalinfoclone to OrbitalInfo |
// copy orbitalinfoclone to OrbitalInfo |
| 480 |
// |
// |
| 481 |
orbitalinfo->Clear(); |
orbitalinfo->Clear(); |
| 482 |
// orbitalinfo = new OrbitalInfo(); |
// |
| 483 |
memcpy(&orbitalinfo,&orbitalinfoclone,sizeof(orbitalinfoclone)); |
memcpy(&orbitalinfo,&orbitalinfoclone,sizeof(orbitalinfoclone)); |
| 484 |
// |
// |
| 485 |
// Fill entry in the new tree |
// Fill entry in the new tree |
| 495 |
if ( l0File ) l0File->Close(); |
if ( l0File ) l0File->Close(); |
| 496 |
if ( tempfile ) tempfile->Close(); |
if ( tempfile ) tempfile->Close(); |
| 497 |
gSystem->Unlink(tempname.str().c_str()); |
gSystem->Unlink(tempname.str().c_str()); |
| 498 |
|
// |
|
//if ( code < 0 ) printf("\n OrbitalInfo - ERROR: an error occurred, try to save anyway...\n"); |
|
|
//printf("\n Writing and closing rootple\n"); |
|
| 499 |
if ( runinfo ) runinfo->Close(); |
if ( runinfo ) runinfo->Close(); |
| 500 |
if ( OrbitalInfotr ) OrbitalInfotr->SetName("OrbitalInfo"); |
if ( OrbitalInfotr ) OrbitalInfotr->SetName("OrbitalInfo"); |
| 501 |
if ( file ){ |
if ( file ){ |