]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - STEER/AliCDBStorage.cxx
No default selection on the ESD tracks
[u/mrichter/AliRoot.git] / STEER / AliCDBStorage.cxx
index 8e881d1b6b628f6f0439f038a8665f591d093bf6..351ba43eb827484392453119075c04165f7786f0 100644 (file)
@@ -13,6 +13,8 @@
  * provided "as is" without express or implied warranty.                  *
  **************************************************************************/
 
+#include <TKey.h>
+#include <TH1.h>
 #include "AliCDBManager.h"
 #include "AliCDBStorage.h"
 
@@ -35,7 +37,7 @@ AliCDBStorage::~AliCDBStorage() {
 }
 
 //_____________________________________________________________________________
-AliCDBId AliCDBStorage::GetSelection(const AliCDBId& id) {
+void AliCDBStorage::GetSelection(/*const*/ AliCDBId* id) {
 // return required version and subversion from the list of selection criteria 
        
        TIter iter(&fSelections);
@@ -44,19 +46,44 @@ AliCDBId AliCDBStorage::GetSelection(const AliCDBId& id) {
        // loop on the list of selection criteria
        while ((aSelection = (AliCDBId*) iter.Next())) {
                // check if selection element contains id's path and run (range) 
-               if (aSelection->Comprises(id)) {
-                       AliInfo(Form("Using selection criterion: %s ", aSelection->ToString().Data()));
+               if (aSelection->Comprises(*id)) {
+                       AliDebug(2,Form("Using selection criterion: %s ", aSelection->ToString().Data()));
                        // return required version and subversion
-                       return AliCDBId(id.GetAliCDBPath(), 
-                               id.GetAliCDBRunRange(),
-                               aSelection->GetVersion(), 
-                               aSelection->GetSubVersion());  
+                       
+                       id->SetVersion(aSelection->GetVersion());
+                       id->SetSubVersion(aSelection->GetSubVersion());
+                       return;  
                }
        }
        
        // no valid element is found in the list of selection criteria -> return
-       AliInfo("No matching selection criteria: highest version will be seeked!");
-       return AliCDBId(id.GetAliCDBPath(), id.GetAliCDBRunRange());
+       AliDebug(2,"Looking for objects with most recent version");
+       return;
+}
+
+//_____________________________________________________________________________
+void AliCDBStorage::ReadSelectionFromFile(const char *fileName){
+// read selection criteria list from file
+       
+       RemoveAllSelections();
+       
+       TList *list = GetIdListFromFile(fileName);
+       if(!list) return;
+       
+       list->SetOwner();       
+       Int_t nId = list->GetEntries();
+       AliCDBId *id;
+       TKey *key;
+       
+       for(int i=nId-1;i>=0;i--){
+               key = (TKey*) list->At(i);
+               id = (AliCDBId*) key->ReadObj();
+               if(id) AddSelection(*id);
+       }
+       delete list;
+       AliInfo(Form("Selection criteria list filled with %d entries",fSelections.GetEntries()));
+       PrintSelectionList();
+       
 }
 
 //_____________________________________________________________________________
@@ -172,13 +199,20 @@ AliCDBEntry* AliCDBStorage::Get(const AliCDBId& query) {
                                query.ToString().Data()));
                 return NULL;
        }
+       
+       // This is needed otherwise TH1  objects (histos, TTree's) are lost when file is closed!
+       Bool_t oldStatus = TH1::AddDirectoryStatus();
+       TH1::AddDirectory(kFALSE);
 
        AliCDBEntry* entry = GetEntry(query);
+
+       if (oldStatus != kFALSE)
+               TH1::AddDirectory(kTRUE);
                
        if (entry) {
-               AliInfo(Form("Valid AliCDBEntry object found! %s", entry->GetId().ToString().Data()));
+               AliInfo(Form("CDB object retrieved: %s", entry->GetId().ToString().Data()));
        } else {
-               AliInfo(Form("Sorry, found no object valid for: name = <%s>, run = %d", 
+               AliInfo(Form("No valid CDB object found! request was: name = <%s>, run = %d", 
                        (query.GetPath()).Data(), query.GetFirstRun()));
        }
        
@@ -222,19 +256,26 @@ TList* AliCDBStorage::GetAll(const AliCDBId& query) {
                return NULL;
        }       
         
+       // This is needed otherwise TH1  objects (histos, TTree's) are lost when file is closed!
+       Bool_t oldStatus = TH1::AddDirectoryStatus();
+       TH1::AddDirectory(kFALSE);
+
        TList *result = GetEntries(query);
 
+       if (oldStatus != kFALSE)
+               TH1::AddDirectory(kTRUE);
+
        Int_t nEntries = result->GetEntries();
        if (nEntries) {
-                AliInfo(Form("%d AliCDBEntry objects found!",nEntries));
+                AliInfo(Form("%d AliCDBEntry objects retrieved.",nEntries));
                 for(int i=0; i<nEntries;i++){
                        AliCDBEntry *entry = (AliCDBEntry*) result->At(i);
                        AliInfo(Form("%s",entry->GetId().ToString().Data()));
                 
                 }
        } else {
-                AliInfo(Form("Sorry, found no object valid for: name = <%s>, run = %d", 
-                       (query.GetPath()).Data(), query.GetFirstRun()));
+                AliInfo(Form("No valid CDB object found! request was: name = <%s>, run = %d, version = %d", 
+                       (query.GetPath()).Data(), query.GetFirstRun(), query.GetVersion()));
        }
 
        // if drain storage is set, drain entries into drain storage
@@ -269,7 +310,7 @@ TList* AliCDBStorage::GetAll(const AliCDBPath& path,
 
 //_____________________________________________________________________________
 Bool_t AliCDBStorage::Put(TObject* object, AliCDBId& id, AliCDBMetaData* metaData) {
-// put an AliCDBEntry object from the database
+// store an AliCDBEntry object into the database
        
        AliCDBEntry anEntry(object, id, metaData);
 
@@ -278,10 +319,15 @@ Bool_t AliCDBStorage::Put(TObject* object, AliCDBId& id, AliCDBMetaData* metaDat
 
 //_____________________________________________________________________________
 Bool_t AliCDBStorage::Put(AliCDBEntry* entry) {
-// put an AliCDBEntry object from the database
+// store an AliCDBEntry object into the database
 
+       if (!entry){
+               AliError("No entry!");
+               return kFALSE;
+       }
+       
        if (!entry->GetId().IsValid()) {
-               AliWarning(Form("Invalid entry ID: %s", 
+               AliError(Form("Invalid entry ID: %s", 
                        entry->GetId().ToString().Data()));
                return kFALSE;
        }       
@@ -292,6 +338,9 @@ Bool_t AliCDBStorage::Put(AliCDBEntry* entry) {
                return kFALSE;
        }
 
+       // set object's class name into metaData!
+       entry->GetMetaData()->SetObjectClassName(entry->GetObject()->ClassName());
+
        return PutEntry(entry);
 }