+
+Bool_t AliReconstruction::HasNextEventAfter(Int_t eventId)
+{
+ return ( (eventId < fRunLoader->GetNumberOfEvents()) ||
+ (fRawReader && fRawReader->NextEvent()) );
+}
+
+//_________________________________________________________________
+void AliReconstruction::CheckRecoCDBvsSimuCDB()
+{
+ // if some CDB entries must be the same in the simulation
+ // and reconstruction, check here
+ int nent = fCheckRecoCDBvsSimuCDB.GetEntriesFast();
+ AliInfo(Form("Check %d entries for matching between sim and rec",nent));
+ //
+ // get simulation CDB
+ fRunLoader->CdGAFile();
+ TMap* cdbMapSim = (TMap*)gDirectory->Get("cdbMap");
+ TList* cdbListSim = (TList*)gDirectory->Get("cdbList");
+ if (!(cdbMapSim && cdbListSim)) {
+ AliInfo(Form("No CDBMap/List found in %s, nothing to check",fGAliceFileName.Data()));
+ return;
+ }
+ // read the requested objects to make sure they will appear in the reco list
+ for (Int_t i=0;i<nent;i++) {
+ TNamed* cdbent = (TNamed*) fCheckRecoCDBvsSimuCDB[i];
+ if (!cdbent) continue;
+ AliCDBManager::Instance()->Get(cdbent->GetName());
+ }
+ // get default path for simulation
+ TPair* pair;
+ TObjString* stro;
+ pair = (TPair*)cdbMapSim->FindObject("default");
+ if (!pair) {AliFatal("Did not find default storage used for simulations"); return;}
+ TString defSimStore = ((TObjString*)pair->Value())->GetString();
+ RectifyCDBurl(defSimStore);
+ //
+ // get reconstruction CDB
+ const TMap *cdbMapRec = AliCDBManager::Instance()->GetStorageMap();
+ const TList *cdbListRec = AliCDBManager::Instance()->GetRetrievedIds();
+ //
+ // get default path for reconstruction
+ pair = (TPair*)cdbMapRec->FindObject("default");
+ if (!pair) {AliFatal("Did not find default storage used for reconstruction"); return;}
+ TString defRecStore = ((TObjString*)pair->Value())->GetString();
+ RectifyCDBurl(defRecStore);
+ //
+ for (Int_t i=0;i<nent;i++) {
+ TNamed* cdbent = (TNamed*) fCheckRecoCDBvsSimuCDB[i];
+ if (!cdbent) continue;
+ //
+ AliInfo(Form("#%d Checking %s",i,cdbent->GetName()));
+ //
+ // find cdbID used for sim
+ TString idSim="",storSim="";
+ TIter nextSim(cdbListSim);
+ while ((stro=(TObjString*)nextSim())) {
+ if (stro->GetString().Contains(cdbent->GetName())) {
+ idSim = stro->GetString();
+ break;
+ }
+ }
+ // find the storage used for sim
+ // check in the simuCDB special paths
+ pair = (TPair*)cdbMapSim->FindObject(cdbent->GetName());
+ if (pair) { // specific path is used
+ storSim = ((TObjString*)pair->Value())->GetString();
+ RectifyCDBurl(storSim);
+ }
+ else storSim = defSimStore; // default storage list is used
+ //
+ if (!idSim.IsNull()) AliInfo(Form("Sim. used %s from %s",idSim.Data(), storSim.Data()));
+ else AliInfo("Sim. did not use this object");
+ //
+ // find cdbID used for rec
+ TString idRec="",storRec="";
+ TIter nextRec(cdbListRec);
+ AliCDBId* id=0;
+ while ((id=(AliCDBId*)nextRec())) {
+ idRec = id->ToString();
+ if (idRec.Contains(cdbent->GetName())) break;
+ idRec="";
+ }
+ //
+ // find storage used for the rec
+ pair = (TPair*)cdbMapRec->FindObject(cdbent->GetName());
+ if (pair) { // specific path is used
+ storRec = ((TObjString*)pair->Value())->GetString();
+ RectifyCDBurl(storRec);
+ }
+ else storRec = defRecStore; // default storage list is used
+ //
+ if (!idRec.IsNull()) AliInfo(Form("Rec. used %s from %s",idRec.Data(), storRec.Data()));
+ else AliInfo("Rec. did not use this object");
+ //
+ if (!idSim.IsNull() && !idRec.IsNull() && ((idSim!=idRec) || (storSim!=storRec)) )
+ AliFatal("Different objects were used in sim and rec");
+ }
+
+}
+
+//_________________________________________________________
+void AliReconstruction::RectifyCDBurl(TString& url)
+{
+ // TBD RS
+ // remove everything but the url
+ TString sbs;
+ if (!(sbs=url("\\?User=[^?]*")).IsNull()) url.ReplaceAll(sbs,"");
+ if (!(sbs=url("\\?DBFolder=[^?]*")).IsNull()) url.ReplaceAll("?DB","");
+ if (!(sbs=url("\\?SE=[^?]*")).IsNull()) url.ReplaceAll(sbs,"");
+ if (!(sbs=url("\\?CacheFolder=[^?]*")).IsNull()) url.ReplaceAll(sbs,"");
+ if (!(sbs=url("\\?OperateDisconnected=[^?]*")).IsNull()) url.ReplaceAll(sbs,"");
+ if (!(sbs=url("\\?CacheSize=[^?]*")).IsNull()) url.ReplaceAll(sbs,"");
+ if (!(sbs=url("\\?CleanupInterval=[^?]*")).IsNull()) url.ReplaceAll(sbs,"");
+ Bool_t slash=kFALSE,space=kFALSE;
+ while ( (slash=url.EndsWith("/")) || (space=url.EndsWith(" ")) ) {
+ if (slash) url = url.Strip(TString::kTrailing,'/');
+ if (space) url = url.Strip(TString::kTrailing,' ');
+ }
+ //url.ToLower();
+ //
+}
+
+//_________________________________________________________
+void AliReconstruction::ProcessTriggerAliases()
+{
+ // load trigger aliases, attach them to the reader
+ //
+ fDeclTriggerClasses.Clear();
+ AliCentralTrigger *aCTP = NULL;
+ if (fRawReader) {
+ aCTP = new AliCentralTrigger();
+ TString configstr("");
+ if (!aCTP->LoadConfiguration(configstr)) { // Load CTP config from OCDB
+ AliError("No trigger configuration found in OCDB! The trigger configuration information will not be used!");
+ delete aCTP;
+ return;
+ }
+ }
+ else if (fRunLoader && (!fRunLoader->LoadTrigger())) {
+ aCTP = fRunLoader->GetTrigger();
+ }
+ else {
+ if (fStopOnMissingTriggerFile) AliFatal("No trigger can be loaded! Stopping reconstruction!");
+ AliWarning("No trigger can be loaded! The trigger information will not be used!");
+ return;
+ }
+ //
+ AliTriggerConfiguration *config = aCTP->GetConfiguration();
+ if (!config) {
+ AliError("No trigger configuration has been found! The trigger configuration information will not be used!");
+ if (fRawReader) delete aCTP;
+ return;
+ }
+ //
+ // here we have list of active triggers
+ const TObjArray& classesArray = config->GetClasses();
+ Int_t nclasses = classesArray.GetEntriesFast();
+ //
+ fAlias2Trigger = new THashList();
+ //
+ AliCDBEntry * entry = AliCDBManager::Instance()->Get("GRP/CTP/Aliases");
+ if (entry) {
+ THashList * lst = dynamic_cast<THashList*>(entry->GetObject());
+ if (lst) {
+ lst->Sort(kSortDescending); // to avoid problems with substrungs
+ if (fRawReader) fRawReader->LoadTriggerAlias(lst);
+ // Now declare all the triggers present in the aliases
+ TIter iter(lst);
+ TNamed *nmd = 0;
+ while((nmd = dynamic_cast<TNamed*>(iter.Next()))) { // account aliases of this trigger >>
+ fDeclTriggerClasses += " ";
+ fDeclTriggerClasses += nmd->GetName();
+ //
+ if (!classesArray.FindObject(nmd->GetName())) continue;
+ TString aliasList(nmd->GetTitle());
+ TObjArray* arrAliases = aliasList.Tokenize(',');
+ Int_t nAliases = arrAliases->GetEntries();
+ // Loop on aliases for the current trigger
+ for(Int_t i=0; i<nAliases; i++){
+ TObjString *alias = (TObjString*) arrAliases->At(i);
+ // Find the current alias in the hash list. If it is not there, add TNamed entry
+ TNamed * inlist = (TNamed*)fAlias2Trigger->FindObject((alias->GetString()).Data());
+ if (!inlist) {
+ inlist = new TNamed((alias->GetString()).Data(),Form(" %s ",nmd->GetName()));
+ fAlias2Trigger->Add(inlist);
+ }
+ else {
+ TString tt(inlist->GetTitle());
+ tt += "||";
+ tt += Form(" %s ",nmd->GetName());
+ inlist->SetTitle(tt.Data());
+ }
+ }
+ delete arrAliases;
+ } // account aliases of this trigger <<
+ }
+ else AliError("Cannot cast the object with trigger aliases to THashList!");
+ }
+ else AliError("No OCDB ebtry for the trigger aliases!");
+ //
+ AliInfo("Aliases defined:");
+ fAlias2Trigger->Print();
+ //
+ if (fRawReader) {
+ // active classes mentioned in the alias will be converted to their masks
+ for( Int_t iclass=0; iclass < nclasses; iclass++ ) {
+ AliTriggerClass* trclass = (AliTriggerClass*)classesArray.At(iclass);
+ if (trclass && trclass->GetMask()>0) {
+ Int_t trindex = TMath::Nint(TMath::Log2(trclass->GetMask()));
+ fRawReader->LoadTriggerClass(trclass->GetName(),trindex);
+ }
+ if (trclass && trclass->GetMaskNext50()>0) {
+ Int_t trindex = TMath::Nint(TMath::Log2(trclass->GetMaskNext50()))+50;
+ fRawReader->LoadTriggerClass(trclass->GetName(),trindex);
+ }
+ }
+ //
+ // nullify all remaining triggers mentioned in the alias
+ if (!fDeclTriggerClasses.IsNull()) {
+ TObjArray *tokens = fDeclTriggerClasses.Tokenize(" ");
+ Int_t ntokens = tokens->GetEntriesFast();
+ for (Int_t itoken = 0; itoken < ntokens; ++itoken) {
+ fRawReader->LoadTriggerClass((((TObjString*)tokens->At(itoken))->String()).Data(),-1);
+ }
+ delete tokens;
+ }
+ }
+ //
+}
+
+//___________________________________________________
+Bool_t AliReconstruction::TriggerMatches2Alias(const char* trigName, const char* alias)
+{
+ // check if trigger matches to alias
+ TString trName = trigName;
+ if (!fAlias2Trigger) return kFALSE;
+ TNamed* al = (TNamed*)fAlias2Trigger->FindObject(alias);
+ if (!al) return kFALSE;
+ TString altrig = al->GetTitle();
+ return altrig.Contains(Form(" %s ",trigName));
+ //
+}