]> git.uio.no Git - u/mrichter/AliRoot.git/commitdiff
optimizing access to OCDB objects https://savannah.cern.ch/bugs/?80488, adding more...
authorrichterm <richterm@f7af4fe6-9843-0410-8265-dc069ae4e863>
Thu, 14 Apr 2011 09:11:26 +0000 (09:11 +0000)
committerrichterm <richterm@f7af4fe6-9843-0410-8265-dc069ae4e863>
Thu, 14 Apr 2011 09:11:26 +0000 (09:11 +0000)
HLT/rec/AliHLTMiscImplementation.cxx

index 7bacab9f770d9bcdf5a0a6d07c398191fe48141f..3bf4acbf863f3a498ec1472692f10a639fd0d8b1 100644 (file)
@@ -23,6 +23,7 @@
 
 #include "AliHLTMiscImplementation.h"
 #include "AliHLTLogging.h"
 
 #include "AliHLTMiscImplementation.h"
 #include "AliHLTLogging.h"
+#include "AliHLTErrorGuard.h"
 #include "AliLog.h"
 #include "AliCDBManager.h"
 #include "AliCDBStorage.h"
 #include "AliLog.h"
 #include "AliCDBManager.h"
 #include "AliCDBStorage.h"
@@ -111,22 +112,52 @@ int AliHLTMiscImplementation::GetCDBRunNo() const
 AliCDBEntry* AliHLTMiscImplementation::LoadOCDBEntry(const char* path, int runNo, int version, int subVersion) const
 {
   // see header file for function documentation
 AliCDBEntry* AliHLTMiscImplementation::LoadOCDBEntry(const char* path, int runNo, int version, int subVersion) const
 {
   // see header file for function documentation
+  if (!path) return NULL;
+  AliHLTLogging log;
+
   AliCDBManager* man = AliCDBManager::Instance();
   AliCDBManager* man = AliCDBManager::Instance();
-  if (!man) return NULL;
+  if (!man) {
+    ALIHLTERRORGUARD(1, "failed to access CDB manager");
+    return NULL;
+  }
   if (runNo<0) runNo=man->GetRun();
 
   if (runNo<0) runNo=man->GetRun();
 
+  // check the cache first if no specific version required
+  if (version<0) {
+    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);
   const char* uri=man->GetURI(path);
-  if (!uri) return NULL;
+  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) {
 
   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;
   }
 
   TString strUri=store->GetURI();
   bool bIsGrid=strUri.BeginsWith("alien://");
 
     return NULL;
   }
 
   TString strUri=store->GetURI();
   bool bIsGrid=strUri.BeginsWith("alien://");
 
-  if (version<0) version = store->GetLatestVersion(path, runNo);
+  int latest = store->GetLatestVersion(path, runNo);
+  if (latest<0) {
+    log.Logging(kHLTLogError, "AliHLTMiscImplementation::LoadOCDBEntry", "CDB handling", "Could not find an entry in the CDB for \"%s\".", path);
+    return NULL;
+  }
+  if (version<0) version=latest;
 
   // OCDB objects on GRID have no sub version
   if (subVersion<0 && !bIsGrid) subVersion = store->GetLatestSubVersion(path, runNo, version);
 
   // OCDB objects on GRID have no sub version
   if (subVersion<0 && !bIsGrid) subVersion = store->GetLatestSubVersion(path, runNo, version);
@@ -156,10 +187,20 @@ 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 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;
   int iResult=0;
   if (!pMap) return -EINVAL;
+  AliHLTLogging log;
+
+  AliCDBManager* man = AliCDBManager::Instance();
+  if (!man) {
+    ALIHLTERRORGUARD(1, "failed to access CDB manager");
+    return NULL;
+  }
+  const TMap* pCache=man->GetEntryCache();
 
 
-  const TMap* pStorages=AliCDBManager::Instance()->GetStorageMap();
   Int_t runNo = GetCDBRunNo();
 
   TIterator* next=pMap->MakeIterator();
   Int_t runNo = GetCDBRunNo();
 
   TIterator* next=pMap->MakeIterator();
@@ -167,24 +208,31 @@ int AliHLTMiscImplementation::CheckOCDBEntries(const TMap* const pMap) const
 
   TObject* pEntry=NULL;
   while ((pEntry=next->Next())) {
 
   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
     // 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 NULL;
+    }
+
+    AliCDBStorage* pStorage = AliCDBManager::Instance()->GetStorage(uri);
+    if (!pStorage) {
+      log.Logging(kHLTLogError, "AliHLTMiscImplementation::CheckOCDBEntries", "CDB handling", "can not find storage for URI \"%s\"", uri);
+      return NULL;
     }
 
     }
 
-    // FIXME: this will fail as soon as we have several specific storages
-    // access to the internal mapping information for specific storages is needed
+    // GetLatestVersion is the only method to check the existence without potential AliFatal
     if (pStorage->GetLatestVersion(pEntry->GetName(), runNo)<0) {
     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 {
       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;
     }
   }
   delete next;