70 #include "TEntryList.h"
76 #include "AliRawReaderRoot.h"
77 #include "AliXRDPROOFtoolkit.h"
78 #include "AliRawVEvent.h"
79 #include "AliRawEventHeaderBase.h"
81 #include "AliSysInfo.h"
82 #include "TTimeStamp.h"
83 #include "TAlienCollection.h"
92 TNamed(triggerName,triggerName),
97 fCounterEventInput(0),
98 fCounterFileOutput(0),
99 fCounterEventOutput(0),
106 fDefaultTimeOut(timeOut),
107 fDefaultTreeCache(cacheSize),
108 fESDTriggerList(NULL)
111 gSystem->Setenv(
"XRDCLIENTMAXWAIT",Form(
"%d",timeOut));
112 gEnv->SetValue(
"XNet.RequestTimeout", timeOut);
113 gEnv->SetValue(
"XNet.ConnectTimeout", timeOut);
114 gEnv->SetValue(
"XNet.TransactionTimeout", timeOut);
115 gEnv->SetValue(
"XNet.FirstConnectMaxCnt", 2);
116 gEnv->SetValue(
"TFile.AsyncPrefetching", 1);
129 for (
Int_t i=0; i<entries; i++){
132 tree->SetAlias(
"trigger",trigger);
147 if (rawFile==NULL)
return;
148 if (TPRegexp(
"^alien").Match(rawFile) && gGrid==0) TGrid::Connect(
"alien");
150 TPRegexp reg0(
".*/");
151 reg0.Substitute(chunkName,
"");
152 TPRegexp reg1(
".root$");
153 reg1.Substitute(chunkName,
"");
155 std::ofstream file_out(
"gidrawReader.list");
157 file_out<<
"fname/C:eventCounter/i:gid/l:timeStamp/i:period/i:orbit/i:bcid/i:eventID/i"<<endl;
159 AliRawReaderRoot *preader =
new AliRawReaderRoot(rawFile);
161 ::Error(
"dumpRAWGIDTree",
"rawFile %s not accessible",rawFile);
165 while (preader->NextEvent()){
169 "\t"<<preader->GetEventIdAsLong()<<
170 "\t"<<preader->GetTimestamp()<<
171 "\t"<<preader->GetPeriod()<<
172 "\t"<<preader->GetOrbitID()<<
173 "\t"<<preader->GetBCID()<<
176 if (counter%100==0) printf(
"EventNumber\t%d\t%llu\n",counter,preader->GetEventIdAsLong());
199 if (rawFile==NULL)
return;
200 if (TPRegexp(
"^alien").Match(rawFile) && gGrid==0) TGrid::Connect(
"alien");
203 TPRegexp expRoot(
".root$");
204 TPRegexp expList(
".list$");
207 if (
TString(rawFile).Contains(expRoot)){
209 fileList->AddLast(
new TObjString(rawFile));
211 if (
TString(rawFile).Contains(expList)){
212 fileList =
gSystem->GetFromPipe(TString::Format(
"cat %s", rawFile)).Tokenize(
"\n");
215 ::Error(
"dumpRAWGIDTree",
"Invalid input r %s",rawFile);
217 std::ofstream file_out(
"gidrawTree.list");
220 file_out<<
"fname/C:eventCounter/i:gid/l:timeStamp/i:period/i:orbit/i:bcid/i:eventID/i"<<endl;
222 Int_t nFiles= fileList->GetEntries();
223 for (
Int_t iFile=0; iFile<nFiles; iFile++){
224 if (TPRegexp(
"^alien").Match(fileList->At(iFile)->GetName()) && gGrid==0) TGrid::Connect(
"alien");
225 finput =TFile::Open(fileList->At(iFile)->GetName());
227 ::Error(
"dumpRAWGIDTree",
"rawFile %s not accessible", fileList->At(iFile)->GetName());
230 tree = (
TTree*)finput->Get(
"RAW");
232 ::Error(
"dumpRAWGIDTree",
"rawFile %s does not contained requested tree",rawFile);
236 TString chunkName=fileList->At(iFile)->GetName();
237 TPRegexp yearExp(
"./20.*/");
238 Int_t indexShort=chunkName.Index(yearExp);
239 TString chunkShort(&(chunkName[indexShort+7]));
241 TPRegexp reg0(
".*/");
242 reg0.Substitute(chunkName,
"");
243 TPRegexp reg1(
".root$");
244 reg1.Substitute(chunkName,
"");
246 AliRawVEvent* fEvent=0;
247 tree->SetBranchStatus(
"TPC*",kFALSE);
248 tree->SetBranchStatus(
"TRD*",kFALSE);
249 tree->SetBranchStatus(
"rawevent",kTRUE);
250 TBranch *fBranch = tree->GetBranch(
"rawevent");
260 fBranch->SetAddress(&fEvent);
261 fBranch->GetEntry(ievent);
262 AliRawEventHeaderBase *header = fEvent->GetHeader();
263 Int_t run = header->Get(
"RunNb");
265 const UInt_t *
id = header->GetP(
"Id");
266 ULong64_t period =
id ? (((id)[0]>>4)&0x0fffffff): 0;
267 ULong64_t orbit =
id ? ((((id)[0]<<20)&0xf00000)|(((
id)[1]>>12)&0xfffff)) : 0;
268 ULong64_t bcID =
id ? ((id)[1]&0x00000fff) : 0;
269 ULong64_t gid = (((ULong64_t)period << 36) | ((ULong64_t)orbit << 12) |(ULong64_t)bcID);
270 UInt_t timeStamp=header->Get(
"Timestamp");
274 AliSysInfo::AddStamp(TString::Format(
"%s",chunkShort.Data()).
Data(), 2, iFile, ievent);
285 if (ievent%100==0) printf(
"EventNumber\t%d\t%llu\n",ievent,gid);
312 if (TPRegexp(
"^alien").Match(chinput) && gGrid==0) TGrid::Connect(
"alien");
313 TFile * finput = TFile::Open(chinput);
315 ::Error(
"dumpRAWGIDTree",
"rawFile %s not accessible",chinput);
318 TTree * esdTree= (
TTree*)finput->Get(
"esdTree");
320 ::Error(
"dumpRAWGIDTree",
"rawFile %s does not contained requested tree",chinput);
324 TPRegexp regE(
"/AliESDs.root$");
325 regE.Substitute(chunkName,
"");
326 TPRegexp reg0(
".*/");
327 reg0.Substitute(chunkName,
"");
336 Int_t entries=esdTree->GetEntries();
337 ::Info(
"dumpAndCompareGID::DumpGIDESD",
"Entries=%llu",esdTree->GetEntries());
338 esdTree->SetAlias(
"gid",
"((fPeriodNumber << 36) | (fOrbitNumber << 12) | fBunchCrossNumber)");
340 entries=esdTree->Draw(
"gid:Entry$:fPeriodNumber:fOrbitNumber:fBunchCrossNumber:fEventNumberInFile:fTimeStamp",trigger,
"goffpara");
342 std::ofstream file_out(choutput);
344 file_out<<
"fname/C:eventCounter/i:gid/l:timeStamp/i:period/i:orbit/i:bcid/i:eventID/i"<<endl;
346 if (entries>0)
for (
Int_t i=0;i<entries; i++){
349 "\t"<<
Long64_t(esdTree->GetVal(1)[i])<<
350 "\t"<<
Long64_t(esdTree->GetVal(0)[i])<<
351 "\t"<<
Long64_t(esdTree->GetVal(6)[i])<<
352 "\t"<<
Long64_t(esdTree->GetVal(2)[i])<<
353 "\t"<<
Long64_t(esdTree->GetVal(3)[i])<<
354 "\t"<<
Long64_t(esdTree->GetVal(4)[i])<<
355 "\t"<<
Long64_t(esdTree->GetVal(5)[i])<<
374 treeGIDRAWReader->ReadFile(
"gidrawReeader.list",
"",
'\t');
375 treeGIDRAWTree->ReadFile(
"gidrawTree.list",
"",
'\t');
376 treeGIDESD->ReadFile(
"gidesd.list",
"",
'\t');
378 treeGIDESD->BuildIndex(
"gid");
379 treeGIDRAWTree->BuildIndex(
"gid");
380 treeGIDRAWReader->BuildIndex(
"gid");
381 treeGIDESD->AddFriend(treeGIDRAWReader,
"RAW");
382 treeGIDESD->AddFriend(treeGIDRAWTree,
"RAWTree");
384 if ( treeGIDRAWReader->GetEntries()!= treeGIDESD->GetEntries()){
385 ::Error(
"dumpAndCompareGID::diffList",
"TestFailed. Mismatch in number of events RAW=%llu\tESD=%llu", treeGIDRAWReader->GetEntries(), treeGIDESD->GetEntries());
387 ::Info(
"dumpAndCompareGID::diffList",
"TestOK. Match in number of events RAW=%llu\tESD=%llu", treeGIDRAWReader->GetEntries(), treeGIDESD->GetEntries());
389 if ( treeGIDRAWTree->GetEntries()!= treeGIDESD->GetEntries()){
390 ::Error(
"dumpAndCompareGID::diffList",
"TestFailed. Mismatch in number of events RAWTree=%llu\tESD=%llu", treeGIDRAWTree->GetEntries(), treeGIDESD->GetEntries());
392 ::Info(
"dumpAndCompareGID::diffList",
"TestOK. Match in number of events RAWTree=%llu\tESD=%llu", treeGIDRAWTree->GetEntries(), treeGIDESD->GetEntries());
394 Int_t entriesMatch=treeGIDESD->Draw(
"event-RAW.event",
"1");
396 if (entriesMatch>0) diff= TMath::Mean(entriesMatch, treeGIDESD->GetV1());
397 if (entriesMatch!= treeGIDRAWReader->GetEntries() || diff!=0){
398 ::Error(
"dumpAndCompareGID::diffList",
"TestFailed. Mismatch in GID");
400 ::Info(
"dumpAndCompareGID::diffList",
"TestOK. Match in GID");
413 if (!friendTrees)
return NULL;
415 Int_t ntrees=array->GetEntries();
417 tree->ReadFile(refTree,
"",
'\t');
418 tree->BuildIndex(
"gid");
419 for (
Int_t jf=0; jf<ntrees; jf++){
421 ftree->ReadFile(array->At(jf)->GetName(),
"",
'\t');
422 ftree->BuildIndex(
"gid");
423 tree->AddFriend(ftree,TString::Format(
"T%d",jf));
441 tree->ReadFile(triggerList,
"",
'\t');
442 Int_t entries=tree->GetEntries();
444 ::Error(
"AliOfflineTrigger::LoadTriggerList",
"Invalid input trigger list\t%s", triggerList);
447 TBranch *chBranch=tree->GetBranch(
"fname");
448 TBranch *gidBranch=tree->GetBranch(
"gid");
449 TBranch *eventBranch=tree->GetBranch(
"eventID");
450 TBranch *timeBranch=tree->GetBranch(
"timeStamp");
451 TBranch *triggerBranch=tree->GetBranch(
"trigger");
452 Bool_t isOK=(chBranch!=NULL && gidBranch!=NULL &&eventBranch && timeBranch!=NULL);
454 ::Error(
"AliOfflineTrigger::LoadTriggerList",
"Missing information - in trigger list\t%s", triggerList);
459 char * chbuffer=
new char[10000];
460 char * chtrigger=
new char[10000];
461 chBranch->SetAddress(chbuffer);
462 gidBranch->SetAddress(&gid);
463 timeBranch->SetAddress(&timeStamp);
464 eventBranch->SetAddress(&eventNr);
465 if (triggerBranch) triggerBranch->SetAddress(chtrigger);
466 for (
Int_t i=0; i<entries; i++){
485 if (rawFile==NULL)
return 0;
486 if (TPRegexp(
"^alien").Match(rawFile) && gGrid==0) TGrid::Connect(
"alien");
487 TFile * finput =TFile::Open(rawFile);
489 ::Error(
"dumpRAWGIDTree",
"rawFile %s not accessible",rawFile);
494 ::Error(
"dumpRAWGIDTree",
"rawFile %s does not contained requested tree",rawFile);
498 TPRegexp reg0(
".*/");
499 reg0.Substitute(chunkName,
"");
500 TPRegexp reg1(
".root$");
501 reg1.Substitute(chunkName,
"");
503 AliRawVEvent* fEvent=0;
504 tree->SetBranchStatus(
"TPC*",kFALSE);
505 tree->SetBranchStatus(
"TRD*",kFALSE);
506 tree->SetBranchStatus(
"rawevent",kTRUE);
507 TBranch *fBranch = tree->GetBranch(
"rawevent");
508 fBranch->SetAddress(&fEvent);
517 fBranch->GetEntry(ievent);
518 Int_t run = fEvent->GetHeader()->Get(
"RunNb");
519 const UInt_t *
id = fEvent->GetHeader()->GetP(
"Id");
520 ULong64_t period =
id ? (((id)[0]>>4)&0x0fffffff): 0;
521 ULong64_t orbit =
id ? ((((id)[0]<<20)&0xf00000)|(((
id)[1]>>12)&0xfffff)) : 0;
522 ULong64_t bcID =
id ? ((id)[1]&0x00000fff) : 0;
523 ULong64_t gid = (((ULong64_t)period << 36) | ((ULong64_t)orbit << 12) |(ULong64_t)bcID);
524 UInt_t timeStamp=fEvent->GetHeader()->Get(
"Timestamp");
525 if (gid==gidOld && verbose>0){
526 ::Error(
"AliOfflineTrigger::LoadMapFromRawData)",
"Event %d not unique GID. GID %llu can not be used as unique ID. Time %d", ievent, gid, timeStamp);
533 if (verbose==1&&ievent%100==0) ::Info(
"AliOfflineTrigger::LoadMapFromRawData",
"Event # \t%d\t%llu",ievent,gid);
534 if ((verbose&2)>0) ::Info(
"AliOfflineTrigger::LoadMapFromRawData",
"Event # \t%d\t%llu",ievent,gid);
539 ::Info(
"AliOfflineTrigger::LoadMapFromRawData()",
"Trig.event=%d. GID=%llu\tTime=%d", ievent, gid, timeStamp);
540 if (trgTimeStamp!=timeStamp){
541 ::Error(
"AliOfflineTrigger::LoadMapFromRawData()",
"Inconsistent timestamp");
548 tree->SetCacheSize(0);
561 AliRawVEvent* fEvent=0;
562 TBranch *fEventBranch = 0;
565 ::Error(
"AliOfflineTrigger::ExtractSelected",
"Output file not intitialized");
570 ::Info(
"AliOfflineTrigger::LoadMapFromRawData",
"Trigger list is empty. Nothing to filter for file %s", rawFile);
574 ::Info(
" AliOfflineTrigger::ExtractSelected",
"%s:\t N_{trig}=%d", rawFile,nTriggered);
578 TFile * finput = TFile::Open(rawFile);
580 ::Info(
" AliOfflineTrigger::ExtractSelected",
"File %s not exist or not accessible within TimeOut %d", rawFile,
fDefaultTimeOut);
583 if (finput->IsOpen()==kFALSE || finput->IsZombie()){
584 ::Info(
" AliOfflineTrigger::ExtractSelected",
"File %s not accessible within TimeOut %d", rawFile,
fDefaultTimeOut);
587 TTree *itree=
dynamic_cast<TTree*
>(finput->Get(
"RAW"));
589 ::Info(
" AliOfflineTrigger::ExtractSelected",
"Tree in file %s not exist or not accessible within TimeOut %d", rawFile,
fDefaultTimeOut);
592 fEventBranch = itree->GetBranch(
"rawevent");
593 fEventBranch->SetAddress(&fEvent);
601 Int_t size= itree->GetEntry(0);
605 Bool_t isSelected = kFALSE;
608 if (!isSelected)
continue;
613 size= itree->GetEntry(iEvent);
615 Int_t readEntry=itree->GetReadEntry();
622 itree->ResetBranchAddresses();
641 if (TPRegexp(
".xml$").Match(rawList)){
642 TAlienCollection *coll = (TAlienCollection *)TAlienCollection::Open(rawList);
643 Int_t nFiles = coll->GetNofGroups();
645 while( coll->Next()){
646 rawArray->AddLast(
new TObjString(coll->GetTURL()));
649 rawArray =
gSystem->GetFromPipe(TString::Format(
"cat %s", rawList)).Tokenize(
"\n");
651 Int_t nFiles=rawArray->GetEntries();
653 ::Error(
"AliOfflineTrigger::ExtractSelected",
"Empty input list");
656 for (
Int_t iFile=0; iFile<nFiles; iFile++){
void SetTriggerAlias(TTree *tree, const char *trigger)
std::map< ULong64_t, TString > fTrgGIDTrigger
GID -> ChunkName.
void DumpGIDESD(const char *chinput="AliESDs.root", const char *trigger="1", const char *choutput="gidesd.list")
TObjArray * fESDTriggerList
std::map< ULong64_t, UInt_t > fRAWGIDTimeStamp
EventNumber -> GID.
void LoadTriggerList(const char *triggerList)
TFile * fRawTriggerFile
name of the output file
TTree * fRawTriggerTree
! pointer to ouput raw trigger files
Int_t LoadMapFromRawData(const char *rawFile="raw.root", Int_t verbose=1)
void AddESDAlias(const char *aliasName, const char *aliasValue)
std::map< ULong64_t, TString > fTrgGIDChunkName
std::map< UInt_t, ULong64_t > fRAWEventNrGID
GID -> EventNumber.
Int_t fCounterFileInput
input event counter
Int_t fDefaultTimeOut
triger map GID -> TimeStamp map
std::map< ULong64_t, UInt_t > fRAWGIDEventNr
GID -> ChunkName.
Double_t nEvents
plot quality messages
static TTree * MakeDiffTree(const char *refTree, const char *friendTrees)
Bool_t Data(TH1F *h, Double_t *rangefit, Bool_t writefit, Double_t &sgn, Double_t &errsgn, Double_t &bkg, Double_t &errbkg, Double_t &sgnf, Double_t &errsgnf, Double_t &sigmafit, Int_t &status)
Int_t fCounterFileOutput
triger map GID -> TimeStamp map
std::map< ULong64_t, TString > fRAWGIDChunkName
! pointer to output raw trigger tree
void DumpGIDRAWTree(const char *rawFile="raw.root")
void DumpGIDRAWReader(const char *rawFile="raw.root")
std::map< ULong64_t, UInt_t > fTrgGIDEventNr
GID -> Trigger type.
std::map< ULong64_t, UInt_t > fTrgGIDTimeStamp
GID -> EventNumber.
void ExtractSelected(const char *rawList, const char *triggerList, const char *outputName, Long_t maxCounter, Int_t verbose=1)
This class provides fucntionality for OFFLINE Trigger raw data selection and consistency checks...