]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - HLT/rec/AliHLTMiscImplementation.cxx
Fix for deleting array of AliMixInputHandlerInfo objects, causes crash at the end...
[u/mrichter/AliRoot.git] / HLT / rec / AliHLTMiscImplementation.cxx
index 86f03c60654c5197987beb8d08e7020b577a8534..b102f1e70083f525a67a9b61c59cf7c264f6c51a 100644 (file)
 
 #include "AliHLTMiscImplementation.h"
 #include "AliHLTLogging.h"
+#include "AliHLTErrorGuard.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 "AliESDtrack.h"
 #include "AliESDHLTDecision.h"
-#endif //HAVE_NOT_ALIESDHLTDECISION
 #include "TGeoGlobalMagField.h"
 #include "AliHLTGlobalTriggerDecision.h"
 #include "TClass.h"
@@ -107,16 +108,54 @@ int AliHLTMiscImplementation::GetCDBRunNo() const
   return -1;
 }
 
-AliCDBEntry* AliHLTMiscImplementation::LoadOCDBEntry(const char* path, int runNo, int version, int subVersion) const
+AliCDBEntry* AliHLTMiscImplementation::LoadOCDBEntry(const char* path, int runNo) const
 {
   // see header file for function documentation
-  AliCDBStorage* store = AliCDBManager::Instance()->GetDefaultStorage();
+  if (!path) return NULL;
+  AliHLTLogging log;
+
+  AliCDBManager* man = AliCDBManager::Instance();
+  if (!man) {
+    ALIHLTERRORGUARD(1, "failed to access CDB manager");
+    return NULL;
+  }
+  if (runNo<0) runNo=man->GetRun();
+
+  // check the cache first if no specific version required
+  { //condition was deprecated, but keep for formatting
+    const TMap* pCache=man->GetEntryCache();
+    TObject* pEntryObj=NULL;
+    if (pCache && (pEntryObj=pCache->GetValue(path))!=NULL) {
+      AliCDBEntry* pEntry=dynamic_cast<AliCDBEntry*>(pEntryObj);
+      if (pEntry) {
+       log.Logging(kHLTLogDebug, "AliHLTMiscImplementation::LoadOCDBEntry", "CDB handling", "using OCDB object %s from cache", path);
+       return pEntry;
+      } else {
+       log.Logging(kHLTLogError, "AliHLTMiscImplementation::LoadOCDBEntry", "CDB handling", "invalid OCDB object %s found in cache, not of type AliCDBEntry", path);
+      }
+    }
+  }
+
+  const char* uri=man->GetURI(path);
+  if (!uri) {
+    log.Logging(kHLTLogError, "AliHLTMiscImplementation::LoadOCDBEntry", "CDB handling", "can not find URI for CDB object \"%s\"", path);
+    return NULL;
+  }
+
+  AliCDBStorage* store = AliCDBManager::Instance()->GetStorage(uri);
   if (!store) {
+    log.Logging(kHLTLogError, "AliHLTMiscImplementation::LoadOCDBEntry", "CDB handling", "can not find storage for URI \"%s\"", uri);
     return NULL;
   }
-  if (version<0) version = store->GetLatestVersion(path, runNo);
-  if (subVersion<0) subVersion = store->GetLatestSubVersion(path, runNo, version);
-  return store->Get(path, runNo, version, subVersion);
+
+  int latest = store->GetLatestVersion(path, runNo);
+  if (latest<0) {
+    log.Logging(kHLTLogError, "AliHLTMiscImplementation::LoadOCDBEntry", "CDB handling", "Could not find an entry for \"%s\" in storage \"%s\", run %d.", path, uri, runNo>=0?runNo:man->GetRun());
+    return NULL;
+  }
+
+  AliCDBEntry* entry=man->Get(path, runNo);
+  return entry;
 }
 
 TObject* AliHLTMiscImplementation::ExtractObject(AliCDBEntry* entry) const
@@ -131,33 +170,56 @@ 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
+  // check uses AliCDBStorage::GetLatestVersion, which is the only method
+  // to check the existence without risking AliFatal
+
   int iResult=0;
   if (!pMap) return -EINVAL;
+  AliHLTLogging log;
+
+  AliCDBManager* man = AliCDBManager::Instance();
+  if (!man) {
+    ALIHLTERRORGUARD(1, "failed to access CDB manager");
+    return -ENOSYS;
+  }
+  const TMap* pCache=man->GetEntryCache();
 
-  const TMap* pStorages=AliCDBManager::Instance()->GetStorageMap();
   Int_t runNo = GetCDBRunNo();
 
   TIterator* next=pMap->MakeIterator();
+  if (!next) return -EFAULT;
+
   TObject* pEntry=NULL;
   while ((pEntry=next->Next())) {
+    // check if already on cache
+    if (pCache && pCache->GetValue(pEntry->GetName())!=NULL) {
+      log.Logging(kHLTLogDebug, "AliHLTMiscImplementation::CheckOCDBEntries", "CDB handling", "found OCDB object %s on cache", pEntry->GetName());      
+      continue;
+    }
+
     // 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();
+    const char* uri=man->GetURI(pEntry->GetName());
+    if (!uri) {
+      log.Logging(kHLTLogError, "AliHLTMiscImplementation::CheckOCDBEntries", "CDB handling", "can not find URI for CDB object \"%s\"", pEntry->GetName());
+      return -ENODEV;
+    }
+
+    AliCDBStorage* pStorage = AliCDBManager::Instance()->GetStorage(uri);
+    if (!pStorage) {
+      log.Logging(kHLTLogError, "AliHLTMiscImplementation::CheckOCDBEntries", "CDB handling", "can not find storage for URI \"%s\"", uri);
+      return -EBADF;
     }
 
+    // GetLatestVersion is the only method to check the existence without potential AliFatal
     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());
+      log.Logging(kHLTLogError, "AliHLTMiscImplementation::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());
+      log.Logging(kHLTLogDebug, "AliHLTMiscImplementation::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;
 }
@@ -203,6 +265,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.
@@ -224,18 +310,13 @@ void AliHLTMiscImplementation::GetBxByBz(const Double_t r[3], Double_t b[3])
 const TClass* AliHLTMiscImplementation::IsAliESDHLTDecision() const
 {
   // Return the IsA of the AliESDHLTDecision class
-#ifndef HAVE_NOT_ALIESDHLTDECISION
   return AliESDHLTDecision::Class();
-#else // HAVE_NOT_ALIESDHLTDECISION
-  return NULL;
-#endif // HAVE_NOT_ALIESDHLTDECISION
 }
 
 int AliHLTMiscImplementation::Copy(const AliHLTGlobalTriggerDecision* pDecision, TObject* object) const
 {
   // Copy HLT global trigger decision to AliESDHLTDecision container
   if (!pDecision || !object) return -EINVAL;
-#ifndef HAVE_NOT_ALIESDHLTDECISION
   AliESDHLTDecision* pESDHLTDecision=NULL;
   if (object->IsA()==NULL ||
       object->IsA() != AliESDHLTDecision::Class() ||
@@ -248,7 +329,6 @@ int AliHLTMiscImplementation::Copy(const AliHLTGlobalTriggerDecision* pDecision,
   pESDHLTDecision->~AliESDHLTDecision();
   new (pESDHLTDecision) AliESDHLTDecision(pDecision->Result(), pDecision->GetTitle());
 
-#endif // HAVE_NOT_ALIESDHLTDECISION
   return 0;
 }
 
@@ -325,3 +405,15 @@ int AliHLTMiscImplementation::InitStreamerInfos(TObjArray* pSchemas) const
 
   return 0;
 }
+
+void AliHLTMiscImplementation::SetAliESDtrackOnlineModeFlag(bool mode) const
+{
+  /// set the online mode flag of AliESDtrack
+  AliESDtrack::OnlineMode(mode);
+}
+
+bool AliHLTMiscImplementation::GetAliESDtrackOnlineModeFlag() const
+{
+  /// get status of the online mode flag of AliESDtrack
+  return AliESDtrack::OnlineMode();
+}