]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - EVE/EveBase/AliEveEventManager.cxx
exit loop when in external control
[u/mrichter/AliRoot.git] / EVE / EveBase / AliEveEventManager.cxx
index 9d26760aee518e95ccf09d41f66597aac469cbac..d93f104524df296d40037bbac7a7e69d41e5a919 100644 (file)
 #include "AliEveEventManager.h"
 #include "AliEveEventSelector.h"
 #include "AliEveMacroExecutor.h"
+
+#include <THashList.h>
+#include <TEveElement.h>
 #include <TEveManager.h>
 #include <TEveViewer.h>
 
+#include <AliLog.h>
 #include <AliRunLoader.h>
 #include <AliRun.h>
 #include <AliESDRun.h>
 #include <AliESDfriend.h>
 #include <AliAODEvent.h>
 
+#include <AliRecoParam.h>
+#include <AliCentralTrigger.h>
+#include <AliCDBEntry.h>
+#include <AliTriggerClass.h>
+#include <AliTriggerConfiguration.h>
+#include <AliTriggerCluster.h>
+#include <AliDetectorRecoParam.h>
+
 #include <AliDAQ.h>
 #include <AliRawEventHeaderBase.h>
 #include <AliRawReaderRoot.h>
@@ -43,6 +55,8 @@
 #include <TPRegexp.h>
 #include <TError.h>
 #include <TEnv.h>
+#include <TString.h>
+#include <TMap.h>
 
 //==============================================================================
 //==============================================================================
@@ -88,9 +102,12 @@ TString  AliEveEventManager::fgCdbUri;
 
 TList*   AliEveEventManager::fgAODfriends = 0;
 
-Bool_t        AliEveEventManager::fgGRPLoaded    = kFALSE;
-AliMagF*      AliEveEventManager::fgMagField     = 0;
-Bool_t        AliEveEventManager::fgUniformField = kFALSE;
+Bool_t   AliEveEventManager::fgRawFromStandardLoc = kFALSE;
+
+Bool_t   AliEveEventManager::fgGRPLoaded    = kFALSE;
+AliMagF* AliEveEventManager::fgMagField     = 0;
+AliRecoParam* AliEveEventManager::fgRecoParam = 0;
+Bool_t   AliEveEventManager::fgUniformField = kFALSE;
 
 AliEveEventManager* AliEveEventManager::fgMaster  = 0;
 AliEveEventManager* AliEveEventManager::fgCurrent = 0;
@@ -115,6 +132,7 @@ void AliEveEventManager::InitInternals()
 
   fAutoLoadTimer = new TTimer;
   fAutoLoadTimer->Connect("Timeout()", "AliEveEventManager", this, "AutoLoadNextEvent()");
+  fAutoLoadTimer->Connect("Timeout()", "AliEveEventManager", this, "Timeout()");
 
   fExecutor = new AliEveMacroExecutor;
 
@@ -127,6 +145,8 @@ void AliEveEventManager::InitInternals()
   gEve->AddToListTree(fTransientLists, kFALSE);
 
   fPEventSelector = new AliEveEventSelector(this);
+
+  fGlobal = new TMap; fGlobal->SetOwnerKeyValue();
 }
 
 AliEveEventManager::AliEveEventManager(const TString& name) :
@@ -137,9 +157,10 @@ AliEveEventManager::AliEveEventManager(const TString& name) :
   fESDFile   (0), fESDTree (0), fESD (0),
   fESDfriend (0), fESDfriendExists(kFALSE),
   fAODFile   (0), fAODTree (0), fAOD (0),
-  fRawReader (0),
+  fRawReader (0), fEventInfo(),
   fAutoLoad  (kFALSE), fAutoLoadTime (5.),     fAutoLoadTimer(0),
   fIsOpen    (kFALSE), fHasEvent     (kFALSE), fExternalCtrl (kFALSE),
+  fGlobal    (0), fGlobalReplace (kTRUE), fGlobalUpdate (kTRUE),
   fExecutor    (0), fTransients(0), fTransientLists(0),
   fPEventSelector(0),
   fSubManagers (0),
@@ -158,9 +179,10 @@ AliEveEventManager::AliEveEventManager(const TString& name, const TString& path,
   fESDFile   (0), fESDTree (0), fESD (0),
   fESDfriend (0), fESDfriendExists(kFALSE),
   fAODFile   (0), fAODTree (0), fAOD (0),
-  fRawReader (0),
+  fRawReader (0), fEventInfo(), 
   fAutoLoad  (kFALSE), fAutoLoadTime (5),      fAutoLoadTimer(0),
   fIsOpen    (kFALSE), fHasEvent     (kFALSE), fExternalCtrl (kFALSE),
+  fGlobal    (0), fGlobalReplace (kTRUE), fGlobalUpdate (kTRUE),
   fExecutor    (0), fTransients(0), fTransientLists(0),
   fPEventSelector(0),
   fSubManagers (0),
@@ -180,6 +202,8 @@ AliEveEventManager::AliEveEventManager(const TString& name, const TString& path,
 AliEveEventManager::~AliEveEventManager()
 {
   // Destructor.
+  fAutoLoadTimer->Stop();
+       fAutoLoadTimer->Disconnect("Timeout");
 
   delete fSubManagers;
 
@@ -193,6 +217,8 @@ AliEveEventManager::~AliEveEventManager()
 
   fTransientLists->DecDenyDestroy();
   fTransientLists->Destroy();
+  
+  //delete fExecutor;
 }
 
 /******************************************************************************/
@@ -252,6 +278,15 @@ void AliEveEventManager::SetAssertElements(Bool_t assertRunloader, Bool_t assert
   fgAssertRaw = assertRaw;
 }
 
+void AliEveEventManager::SearchRawForCentralReconstruction()
+{
+  // Enable searching of raw data in standard location. The path passed to
+  // Open() is expected to point to a centrally reconstructed run, e.g.:
+  // "alien:///alice/data/2009/LHC09c/000101134/ESDs/pass1/09000101134018.10".
+
+  fgRawFromStandardLoc = kTRUE;
+}
+
 /******************************************************************************/
 
 void AliEveEventManager::Open()
@@ -293,6 +328,7 @@ void AliEveEventManager::Open()
   // Open ESD and ESDfriends
 
   TString esdPath(Form("%s/%s", fPath.Data(), fgESDFileName.Data()));
+  if (fPath.EndsWith(".zip")) esdPath.Form("%s#%s",fPath.Data(),fgESDFileName.Data());
   if ((fESDFile = TFile::Open(esdPath)))
   {
     fESD = new AliESDEvent();
@@ -304,6 +340,7 @@ void AliEveEventManager::Open()
       // as it seems to work better when attachine alieve to a
       // running reconstruction process with auto-save on.
       TString p(Form("%s/AliESDfriends.root", fPath.Data()));
+      if (fPath.EndsWith(".zip")) p.Form("%s#AliESDfriends.root",fPath.Data());
       TFile *esdFriendFile = TFile::Open(p);
       if (esdFriendFile)
       {
@@ -363,6 +400,7 @@ void AliEveEventManager::Open()
   // Open AOD and registered friends
 
   TString aodPath(Form("%s/%s", fPath.Data(), fgAODFileName.Data()));
+  if (fPath.EndsWith(".zip")) aodPath.Form("%s#%s",fPath.Data(),fgAODFileName.Data());
   if ((fAODFile = TFile::Open(aodPath)))
   {
     fAOD = new AliAODEvent();
@@ -375,6 +413,7 @@ void AliEveEventManager::Open()
       while ((name = (TObjString*) friends()) != 0)
       {
        TString p(Form("%s/%s", fPath.Data(), name->GetName()));
+        if (fPath.EndsWith(".zip")) p.Form("%s#%s",fPath.Data(),name->GetName());
        if (gSystem->AccessPathName(p, kReadPermission) == kFALSE)
        {
          fAODTree->AddFriend("aodTree", name->GetName());
@@ -419,6 +458,7 @@ void AliEveEventManager::Open()
   // Open RunLoader from galice.root
 
   TString gaPath(Form("%s/galice.root", fPath.Data()));
+  if (fPath.EndsWith(".zip")) gaPath.Form("%s#%s",fPath.Data(),"galice.root");
   // If i use open directly, we get fatal.
   // Is AccessPathName check ok for xrootd / alien? Yes, not for http.
   // Seems not to work for alien anymore.
@@ -471,7 +511,31 @@ void AliEveEventManager::Open()
 
   // Open raw-data file
 
-  TString rawPath(Form("%s/%s", fPath.Data(), fgRawFileName.Data()));
+  TString rawPath;
+  if (fgRawFromStandardLoc)
+  {
+    if (!fPath.BeginsWith("alien:"))
+      throw kEH + "Standard raw search requested, but the directory is not in AliEn.";
+    if (!fPath.Contains("/ESDs/"))
+      throw kEH + "Standard raw search requested, but does not contain 'ESDs' directory.";
+
+    TPMERegexp chunk("/([\\d\\.])+/?$");
+    Int_t nm = chunk.Match(fPath);
+    if (nm != 2)
+      throw kEH + "Standard raw search requested, but the path does not end with chunk-id directory.";
+
+    TPMERegexp esdstrip("/ESDs/.*");
+    rawPath = fPath;
+    esdstrip.Substitute(rawPath, "/raw/");
+    rawPath += chunk[0];
+    rawPath += ".root";
+
+    Info(kEH, "Standard raw search requested, using the following path:\n  %s\n", rawPath.Data());
+  }
+  else
+  {
+    rawPath.Form("%s/%s", fPath.Data(), fgRawFileName.Data());
+  }
   // If i use open directly, raw-reader reports an error but i have
   // no way to detect it.
   // Is this (AccessPathName check) ok for xrootd / alien? Yes, not for http.
@@ -498,7 +562,9 @@ void AliEveEventManager::Open()
     if (fgAssertRaw)
     {
       throw (kEH + "raw-data not initialized. Its precence was requested.");
-    } else {
+    }
+    else
+    {
       Warning(kEH, "raw-data not initialized.");
     }
   }
@@ -507,11 +573,16 @@ void AliEveEventManager::Open()
   {
     if (fRawReader)
     {
-      fRawReader->NextEvent();
+      if ( ! fRawReader->NextEvent())
+      {
+       throw (kEH + "can not go to first event in raw-reader to determine run-id.");
+      }
       runNo = fRawReader->GetRunNumber();
       Info(kEH, "Determining run-no from raw ... run=%d.", runNo);
       fRawReader->RewindEvents();
-    } else {
+    }
+    else 
+    {
       throw (kEH + "unknown run number.");
     }
   }
@@ -684,6 +755,8 @@ void AliEveEventManager::GotoEvent(Int_t event)
     throw (kEH + "Event-files not opened.");
   }
 
+ fEventInfo.Reset();
   fHasEvent = kFALSE;
 
   Int_t maxEvent = 0;
@@ -816,6 +889,11 @@ void AliEveEventManager::GotoEvent(Int_t event)
   AliSysInfo::AddStamp(sysInfoHeader + "PostUserActions");
 }
 
+void AliEveEventManager::Timeout()
+{
+               Emit("Timeout()");
+}
+
 void AliEveEventManager::NextEvent()
 {
   // Loads next event.
@@ -833,8 +911,8 @@ void AliEveEventManager::NextEvent()
     // !!! This should really go somewhere else. It is done in GotoEvent(),
     // so here we should do it in SetEvent().
     DestroyElements();
+               gSystem->ExitLoop();
 
-    gSystem->ExitLoop();
   }
   else if (fESDTree)
   {
@@ -843,7 +921,7 @@ void AliEveEventManager::NextEvent()
     {
       GotoEvent(nextevent);
     }
-  }
+  } 
   else if (fEventId < GetMaxEventId(kTRUE))
   {
     GotoEvent(fEventId + 1);
@@ -853,7 +931,7 @@ void AliEveEventManager::NextEvent()
 void AliEveEventManager::PrevEvent()
 {
   // Loads previous event.
-
+       
   static const TEveException kEH("AliEveEventManager::PrevEvent ");
 
   if (fAutoLoadTimerRunning)
@@ -1123,6 +1201,111 @@ TGeoManager* AliEveEventManager::AssertGeometry()
   return gGeoManager;
 }
 
+AliRecoParam* AliEveEventManager::AssertRecoParams()
+{
+  if(!fgRecoParam) 
+    InitRecoParam();
+               
+  return fgRecoParam;
+}
+
+Bool_t AliEveEventManager::InitRecoParam()
+{
+// This is mostly a reap-off from reconstruction
+// The method accesses OCDB and retrieves all
+// the available reco-param objects from there.
+
+  fgRecoParam = new AliRecoParam;
+  const Int_t  kNDetectors = 14;
+       
+  static const TEveException kEH("AliEveEventManager::InitRecoParam ");
+  
+  Bool_t isOK = kTRUE;
+
+  if (fgRecoParam->GetDetRecoParamArray(kNDetectors)) {
+    ::Info(kEH, "Using custom GRP reconstruction parameters");
+  }
+  else {
+    ::Info(kEH, "Loading GRP reconstruction parameter objects");
+
+    AliCDBPath path("GRP","Calib","RecoParam");
+    AliCDBEntry *entry=AliCDBManager::Instance()->Get(path.GetPath());
+    if(!entry){ 
+      ::Warning(kEH, "Couldn't find GRP RecoParam entry in OCDB");
+      isOK = kFALSE;
+    }
+    else {
+      TObject *recoParamObj = entry->GetObject();
+      if (dynamic_cast<TObjArray*>(recoParamObj)) {
+       // GRP has a normal TobjArray of AliDetectorRecoParam objects
+       // Registering them in AliRecoParam
+       fgRecoParam->AddDetRecoParamArray(kNDetectors,dynamic_cast<TObjArray*>(recoParamObj));
+      }
+      else if (dynamic_cast<AliDetectorRecoParam*>(recoParamObj)) {
+       // GRP has only onse set of reco parameters
+       // Registering it in AliRecoParam
+       ::Info(kEH, "Single set of GRP reconstruction parameters found");
+       dynamic_cast<AliDetectorRecoParam*>(recoParamObj)->SetAsDefault();
+       fgRecoParam->AddDetRecoParam(kNDetectors,dynamic_cast<AliDetectorRecoParam*>(recoParamObj));
+      }
+      else {
+       ::Error(kEH, "No valid GRP RecoParam object found in the OCDB");
+       isOK = kFALSE;
+      }
+      entry->SetOwner(0);
+    }
+  }
+
+  const char* fgkDetectorName[kNDetectors] = {"ITS", "TPC", "TRD", "TOF", "PHOS", "HMPID", "EMCAL", "MUON", "FMD", "ZDC", "PMD", "T0", "VZERO", "ACORDE" };
+
+  
+  for (Int_t iDet = 0; iDet < kNDetectors; iDet++) {
+
+    if (fgRecoParam->GetDetRecoParamArray(iDet)) {
+      ::Info(kEH, Form("Using custom reconstruction parameters for detector %s",fgkDetectorName[iDet]));
+      continue;
+    }
+
+    ::Info(kEH, Form("Loading reconstruction parameter objects for detector %s",fgkDetectorName[iDet]));
+  
+    AliCDBPath path(fgkDetectorName[iDet],"Calib","RecoParam");
+    AliCDBEntry *entry=AliCDBManager::Instance()->Get(path.GetPath());
+    if(!entry){ 
+      ::Warning(kEH, Form("Couldn't find RecoParam entry in OCDB for detector %s",fgkDetectorName[iDet]));
+      isOK = kFALSE;
+    }
+    else {
+      TObject *recoParamObj = entry->GetObject();
+      if (dynamic_cast<TObjArray*>(recoParamObj)) {
+       // The detector has a normal TobjArray of AliDetectorRecoParam objects
+       // Registering them in AliRecoParam
+       fgRecoParam->AddDetRecoParamArray(iDet,dynamic_cast<TObjArray*>(recoParamObj));
+      }
+      else if (dynamic_cast<AliDetectorRecoParam*>(recoParamObj)) {
+       // The detector has only onse set of reco parameters
+       // Registering it in AliRecoParam
+       ::Info(kEH, Form("Single set of reconstruction parameters found for detector %s",fgkDetectorName[iDet]));
+       dynamic_cast<AliDetectorRecoParam*>(recoParamObj)->SetAsDefault();
+       fgRecoParam->AddDetRecoParam(iDet,dynamic_cast<AliDetectorRecoParam*>(recoParamObj));
+      }
+      else {
+       ::Error(kEH, Form("No valid RecoParam object found in the OCDB for detector %s",fgkDetectorName[iDet]));
+       isOK = kFALSE;
+      }
+      entry->SetOwner(0);
+    
+    }
+  }
+  
+  if(!isOK) {
+    delete fgRecoParam;
+    fgRecoParam = 0;
+  }
+
+  return isOK;
+}
+
+
 //------------------------------------------------------------------------------
 
 AliEveEventManager* AliEveEventManager::AddDependentManager(const TString& name, const TString& path)
@@ -1350,6 +1533,122 @@ void AliEveEventManager::NewEventLoaded()
 // Event info dumpers
 //------------------------------------------------------------------------------
 
+const AliEventInfo* AliEveEventManager::GetEventInfo() 
+{
+  // Fill the event info object
+
+  AliCentralTrigger *aCTP = NULL;
+  if (fRawReader) {
+    fEventInfo.SetEventType(fRawReader->GetType());
+
+    ULong64_t mask = fRawReader->GetClassMask();
+    fEventInfo.SetTriggerMask(mask);
+    UInt_t clmask = fRawReader->GetDetectorPattern()[0];
+    fEventInfo.SetTriggerCluster(AliDAQ::ListOfTriggeredDetectors(clmask));
+
+    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 0;
+    }
+    aCTP->SetClassMask(mask);
+    aCTP->SetClusterMask(clmask);
+
+    if (fRunLoader) {
+      AliCentralTrigger* rlCTP = fRunLoader->GetTrigger();
+      if (rlCTP) {
+       rlCTP->SetClassMask(mask);
+       rlCTP->SetClusterMask(clmask);
+      }
+    }
+  }
+  else {
+    fEventInfo.SetEventType(AliRawEventHeaderBase::kPhysicsEvent);
+
+    if (fRunLoader && (!fRunLoader->LoadTrigger())) {
+      aCTP = fRunLoader->GetTrigger();
+      fEventInfo.SetTriggerMask(aCTP->GetClassMask());
+      // get inputs from actp - just get
+      AliESDHeader* esdheader = fESD->GetHeader();
+      esdheader->SetL0TriggerInputs(aCTP->GetL0TriggerInputs());
+      esdheader->SetL1TriggerInputs(aCTP->GetL1TriggerInputs());
+      esdheader->SetL2TriggerInputs(aCTP->GetL2TriggerInputs());
+      fEventInfo.SetTriggerCluster(AliDAQ::ListOfTriggeredDetectors(aCTP->GetClusterMask()));
+    }
+    else {
+      AliWarning("No trigger can be loaded! The trigger information will not be used!");
+      return 0;
+    }
+  }
+
+  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 0;
+  }
+
+  TString declTriggerClasses;
+       
+  // Load trigger aliases and declare the trigger classes included in aliases
+  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 substrings
+      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()))){
+       declTriggerClasses += " ";
+       declTriggerClasses += nmd->GetName();
+      }
+    }
+    else {
+      AliError("Cannot cast the object with trigger aliases to THashList!");
+    }
+  }
+  else {
+    AliError("No OCDB entry for the trigger aliases!");
+  }
+  
+  // Load trigger classes for this run
+  UChar_t clustmask = 0;
+  TString trclasses;
+  ULong64_t trmask = fEventInfo.GetTriggerMask();
+  const TObjArray& classesArray = config->GetClasses();
+  Int_t nclasses = classesArray.GetEntriesFast();
+  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()));
+      if (fESD) fESD->SetTriggerClass(trclass->GetName(),trindex);
+      if (fRawReader) fRawReader->LoadTriggerClass(trclass->GetName(),trindex);
+      if (trmask & (1ull << trindex)) {
+       trclasses += " ";
+       trclasses += trclass->GetName();
+       trclasses += " ";
+       clustmask |= trclass->GetCluster()->GetClusterMask();
+      }
+    }
+  }
+  fEventInfo.SetTriggerClasses(trclasses);
+
+  if (!aCTP->CheckTriggeredDetectors()) {
+    if (fRawReader) delete aCTP;
+    return 0;
+  }
+
+  if (fRawReader) delete aCTP;
+
+// everything went ok, return pointer
+  return (&fEventInfo);
+}
+
+
 TString AliEveEventManager::GetEventInfoHorizontal() const
 {
   // Dumps the event-header contents in vertical formatting.
@@ -1490,3 +1789,60 @@ Bool_t AliEveEventManager::InitGRP()
 
   return kTRUE;
 } 
+
+//------------------------------------
+// Global variables management
+//------------------------------------
+
+Bool_t AliEveEventManager::InsertGlobal(const TString& tag, TEveElement* model)
+{
+   // Insert a new visualization-parameter database entry with the default
+   return InsertGlobal(tag, model, fGlobalReplace, fGlobalUpdate);
+}
+
+Bool_t AliEveEventManager::InsertGlobal(const TString& tag, TEveElement* model,
+                    Bool_t replace, Bool_t update)
+{
+   TPair* pair = (TPair*) fGlobal->FindObject(tag);
+   if (pair)
+   {
+      if (replace)
+      {
+         model->IncDenyDestroy();
+         model->SetRnrChildren(kFALSE);
+
+         TEveElement* old_model = dynamic_cast<TEveElement*>(pair->Value());
+                if(!old_model) AliFatal("old_model == 0, dynamic cast failed\n");
+         while (old_model->HasChildren())
+         {
+            TEveElement *el = old_model->FirstChild();
+            el->SetVizModel(model);
+            if (update)
+            {
+               el->CopyVizParams(model);
+               el->PropagateVizParamsToProjecteds();
+            }
+         }
+         old_model->DecDenyDestroy();
+
+         pair->SetValue(dynamic_cast<TObject*>(model));
+         return kTRUE;
+      }
+      else
+      {
+         return kFALSE;
+      }
+   }
+   else
+   {
+      model->IncDenyDestroy();
+      model->SetRnrChildren(kFALSE);
+      fGlobal->Add(new TObjString(tag), dynamic_cast<TObject*>(model));
+      return kTRUE;
+   }
+}
+
+TEveElement* AliEveEventManager::FindGlobal(const TString& tag)
+{
+   return dynamic_cast<TEveElement*>(fGlobal->GetValue(tag));
+}