]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - HLT/rec/AliHLTMiscImplementation.cxx
bugfix: CDBManager caching was overrun for objects on the GRID due to missing subversion
[u/mrichter/AliRoot.git] / HLT / rec / AliHLTMiscImplementation.cxx
index 7774f5377b599bcc3daefb474a607c3f52473f9e..7bacab9f770d9bcdf5a0a6d07c398191fe48141f 100644 (file)
 /// @date   
 /// @brief  Miscellaneous methods for the HLT AliRoot integration
 
-// define will be set set from configure.ac, but for now it needs
-// to be set until the changes in STEER have been committed
-#define HAVE_NOT_ALIESDHLTDECISION
-
 #include "AliHLTMiscImplementation.h"
 #include "AliHLTLogging.h"
+#include "AliLog.h"
 #include "AliCDBManager.h"
 #include "AliCDBStorage.h"
 #include "AliCDBEntry.h"
 #include "AliGRPManager.h"
 #include "AliRawReader.h"
+#include "AliRawEventHeaderBase.h"
 #include "AliTracker.h"
 #ifndef HAVE_NOT_ALIESDHLTDECISION
 #include "AliESDHLTDecision.h"
 #endif //HAVE_NOT_ALIESDHLTDECISION
 #include "TGeoGlobalMagField.h"
 #include "AliHLTGlobalTriggerDecision.h"
+#include "TClass.h"
+#include "TStreamerInfo.h"
+#include "TObjArray.h"
 
 /** ROOT macro for the implementation of ROOT specific class methods */
 ClassImp(AliHLTMiscImplementation);
@@ -94,25 +95,104 @@ int AliHLTMiscImplementation::SetCDBRunNo(int runNo)
   return iResult;
 }
 
-AliCDBEntry* AliHLTMiscImplementation::LoadOCDBEntry(const char* path, int runNo, int version, int subVersion)
+int AliHLTMiscImplementation::GetCDBRunNo() const
+{
+  // see header file for function documentation
+  AliCDBManager* pCDB = AliCDBManager::Instance();
+  AliHLTLogging log;
+  if (!pCDB) {
+    log.Logging(kHLTLogError, "SetCDBRunNo", "CDB handling", "Could not get CDB instance");
+  } else {
+    return pCDB->GetRun();
+  }
+  return -1;
+}
+
+AliCDBEntry* AliHLTMiscImplementation::LoadOCDBEntry(const char* path, int runNo, int version, int subVersion) const
 {
   // see header file for function documentation
-  AliCDBStorage* store = AliCDBManager::Instance()->GetDefaultStorage();
+  AliCDBManager* man = AliCDBManager::Instance();
+  if (!man) return NULL;
+  if (runNo<0) runNo=man->GetRun();
+
+  const char* uri=man->GetURI(path);
+  if (!uri) return NULL;
+
+  AliCDBStorage* store = AliCDBManager::Instance()->GetStorage(uri);
   if (!store) {
     return NULL;
   }
+
+  TString strUri=store->GetURI();
+  bool bIsGrid=strUri.BeginsWith("alien://");
+
   if (version<0) version = store->GetLatestVersion(path, runNo);
-  if (subVersion<0) subVersion = store->GetLatestSubVersion(path, runNo, version);
-  return AliCDBManager::Instance()->Get(path, runNo, version, subVersion);
+
+  // OCDB objects on GRID have no sub version
+  if (subVersion<0 && !bIsGrid) subVersion = store->GetLatestSubVersion(path, runNo, version);
+  AliCDBEntry* entry=man->Get(path, runNo, version, subVersion);
+  if (entry) {
+    // there seems to be a problem with the caching of objects in the CDBManager
+    // regardless what version is specified it returns the object from the cache
+    AliCDBId id=entry->GetId();
+    if ((version<0 || id.GetVersion()==version) &&
+       (subVersion<0 || id.GetSubVersion()==subVersion)) {
+      // entry in the cache has the correct version
+      return entry;
+    }
+  }
+  return store->Get(path, runNo, version, subVersion);
 }
 
-TObject* AliHLTMiscImplementation::ExtractObject(AliCDBEntry* entry)
+TObject* AliHLTMiscImplementation::ExtractObject(AliCDBEntry* entry) const
 {
   // see header file for function documentation
   if (!entry) return NULL;
   return entry->GetObject();
 }
 
+int AliHLTMiscImplementation::CheckOCDBEntries(const TMap* const pMap) const
+{
+  // check the availability of the OCDB entry descriptions in the TMap
+  //  key : complete OCDB path of the entry
+  //  value : auxiliary object - short description
+  int iResult=0;
+  if (!pMap) return -EINVAL;
+
+  const TMap* pStorages=AliCDBManager::Instance()->GetStorageMap();
+  Int_t runNo = GetCDBRunNo();
+
+  TIterator* next=pMap->MakeIterator();
+  if (!next) return -ENOENT;
+
+  TObject* pEntry=NULL;
+  while ((pEntry=next->Next())) {
+    // check if the entry has specific storage
+    AliCDBStorage* pStorage=NULL;
+    TObject* pStorageId=pStorages->GetValue(pEntry->GetName());
+    if (pStorageId) {
+      pStorage=AliCDBManager::Instance()->GetStorage(pStorageId->GetName());
+    } else {
+      pStorage=AliCDBManager::Instance()->GetDefaultStorage();
+    }
+
+    // FIXME: this will fail as soon as we have several specific storages
+    // access to the internal mapping information for specific storages is needed
+    if (pStorage->GetLatestVersion(pEntry->GetName(), runNo)<0) {
+      AliHLTLogging log;
+      log.Logging(kHLTLogError, "CheckOCDBEntries", "CDB handling", "can not find required OCDB object %s for run number %d in storage %s", pEntry->GetName(), runNo, pStorage->GetURI().Data());
+      iResult=-ENOENT;
+    } else {
+      AliHLTLogging log;
+      log.Logging(kHLTLogDebug, "CheckOCDBEntries", "CDB handling", "found required OCDB object %s for run number %d in storage %s", pEntry->GetName(), runNo, pStorage->GetURI().Data());
+    }
+  }
+  delete next;
+  next=NULL;
+
+  return iResult;
+}
+
 int AliHLTMiscImplementation::InitMagneticField() const
 {
   // see header file for function documentation
@@ -154,6 +234,30 @@ AliHLTUInt64_t AliHLTMiscImplementation::GetTriggerMask(AliRawReader* rawReader)
   return trgMask;
 }
 
+AliHLTUInt32_t AliHLTMiscImplementation::GetTimeStamp(AliRawReader* rawReader) const
+{
+  // extract time stamp of the event from the event header
+  if (!rawReader) return 0;
+  const AliRawEventHeaderBase* eventHeader = rawReader->GetEventHeader();
+  if (!eventHeader) return 0;
+  return eventHeader->Get("Timestamp");
+}
+
+AliHLTUInt32_t AliHLTMiscImplementation::GetEventType(AliRawReader* rawReader) const
+{
+  // extract event type from the event header
+  if (!rawReader) return 0;
+  const AliRawEventHeaderBase* eventHeader = rawReader->GetEventHeader();
+  if (!eventHeader) return 0;
+  return eventHeader->Get("Type");
+}
+
+const char* AliHLTMiscImplementation::GetBeamTypeFromGRP() const
+{
+  // get beam type from GRP
+  return NULL;
+}
+
 Double_t AliHLTMiscImplementation::GetBz()
 {
   // Returns Bz.
@@ -197,8 +301,82 @@ int AliHLTMiscImplementation::Copy(const AliHLTGlobalTriggerDecision* pDecision,
   }
 
   pESDHLTDecision->~AliESDHLTDecision();
-  new (pESDHLTDecision) AliESDHLTDecision(pDecision->GetTitle());
+  new (pESDHLTDecision) AliESDHLTDecision(pDecision->Result(), pDecision->GetTitle());
 
 #endif // HAVE_NOT_ALIESDHLTDECISION
   return 0;
 }
+
+int AliHLTMiscImplementation::InitStreamerInfos(const char* ocdbEntry) const
+{
+  // init streamer infos for HLT reconstruction
+  // Root schema evolution is not enabled for AliHLTMessage and all streamed objects.
+  // Objects in the raw data payload rely on the availability of the correct stream info.
+  // The relevant streamer info for a specific run is stored in the OCDB.
+  int iResult=0;
+
+  AliCDBEntry* pEntry=LoadOCDBEntry(ocdbEntry);
+  TObject* pObject=NULL;
+  if (pEntry && (pObject=ExtractObject(pEntry))!=NULL)
+    {
+    TObjArray* pSchemas=dynamic_cast<TObjArray*>(pObject);
+    if (pSchemas) {
+      iResult=InitStreamerInfos(pSchemas);
+    } else {
+      AliError(Form("internal mismatch in OCDB entry %s: wrong class type", ocdbEntry));
+    }
+  } else {
+    AliWarning(Form("missing HLT reco data (%s), skipping initialization of streamer info for TObjects in HLT raw data payload", ocdbEntry));
+  }
+  return iResult;
+}
+
+int AliHLTMiscImplementation::InitStreamerInfos(TObjArray* pSchemas) const
+{
+  // init streamer infos for HLT reconstruction from an array of TStreamerInfo objects
+
+  for (int i=0; i<pSchemas->GetEntriesFast(); i++) {
+    if (pSchemas->At(i)) {
+      TStreamerInfo* pSchema=dynamic_cast<TStreamerInfo*>(pSchemas->At(i));
+      if (pSchema) {
+       int version=pSchema->GetClassVersion();
+       TClass* pClass=TClass::GetClass(pSchema->GetName());
+       if (pClass) {
+         if (pClass->GetClassVersion()==version) {
+           AliDebug(0,Form("skipping schema definition %d version %d to class %s as this is the native version", i, version, pSchema->GetName()));
+           continue;
+         }
+         TObjArray* pInfos=pClass->GetStreamerInfos();
+         if (pInfos /*&& version<pInfos->GetEntriesFast()*/) {
+           if (pInfos->At(version)==NULL) {
+             TStreamerInfo* pClone=(TStreamerInfo*)pSchema->Clone();
+             if (pClone) {
+               pClone->SetClass(pClass);
+               pClone->BuildOld();
+               pInfos->AddAtAndExpand(pClone, version);
+               AliDebug(0,Form("adding schema definition %d version %d to class %s", i, version, pSchema->GetName()));
+             } else {
+               AliError(Form("skipping schema definition %d (%s), unable to create clone object", i, pSchema->GetName()));
+             }
+           } else {
+             TStreamerInfo* pInfo=dynamic_cast<TStreamerInfo*>(pInfos->At(version));
+             if (pInfo && pInfo->GetClassVersion()==version) {
+               AliDebug(0,Form("schema definition %d version %d already available in class %s, skipping ...", i, version, pSchema->GetName()));
+             } else {
+               AliError(Form("can not verify version for already existing schema definition %d (%s) version %d: version of existing definition is %d", i, pSchema->GetName(), version, pInfo?pInfo->GetClassVersion():-1));
+             }
+           }
+         } else {
+           AliError(Form("skipping schema definition %d (%s), unable to set version %d in info array of size %d", i, pSchema->GetName(), version, pInfos?pInfos->GetEntriesFast():-1));
+         }
+       } else {
+         AliError(Form("skipping schema definition %d (%s), unable to find class", i, pSchema->GetName()));
+       }
+      } else {
+       AliError(Form("skipping schema definition %d, not of TStreamerInfo", i));
+      }
+    }
+  }
+
+  return 0;
+}