Implementing the possibility of loading the CDB as a snapshot in two ways:
authorrgrosso <rgrosso@f7af4fe6-9843-0410-8265-dc069ae4e863>
Mon, 3 Oct 2011 21:40:36 +0000 (21:40 +0000)
committerrgrosso <rgrosso@f7af4fe6-9843-0410-8265-dc069ae4e863>
Mon, 3 Oct 2011 21:40:36 +0000 (21:40 +0000)
1) you suppose you have it locally, in ./OCDB. That will be the case if you untar a CDB tarball.
2) you suppose you can find in some place in alien a root file containing both a map of the
   CDB entries and a list of the corresponding Ids (for the UserInfo)

1) is triggered by using:
cdb->SetDefaultStorage("snapshot://*) where one would put instead of "*" the original alien
location from where the tarball has been built.

2) is triggered by the call:
reco->SetFromCDBSnapshot(filename)
where filename is the name of the file containing the entries map and the ids
list.

1) is implemented in AliCDBLocal and AliCDBLocalParam changes
2) is implemented in AliReconstruction and AliCDBManager changes. For 2) also
the macro macros/MakeCDBSnapshot.C is added, as an example of how to produce
the snapshot file.

Additionally two coding conventions fixed in AliCDBManager (adding const to two parameters).

STEER/CDB/AliCDBLocal.cxx
STEER/CDB/AliCDBLocal.h
STEER/CDB/AliCDBManager.cxx
STEER/CDB/AliCDBManager.h
STEER/STEER/AliReconstruction.cxx
STEER/STEER/AliReconstruction.h
macros/MakeCDBSnapshot.C [new file with mode: 0644]

index 4a55eba..8de36a9 100644 (file)
@@ -942,9 +942,9 @@ ClassImp(AliCDBLocalFactory)
 Bool_t AliCDBLocalFactory::Validate(const char* dbString) {
 // check if the string is valid local URI
 
-        TRegexp dbPattern("^local://.+$");
+        TRegexp dbPatternLocal("^local://.+$");
 
-        return TString(dbString).Contains(dbPattern);
+        return (TString(dbString).Contains(dbPatternLocal) || TString(dbString).BeginsWith("snapshot://folder="));
 }
 
 //_____________________________________________________________________________
@@ -955,13 +955,25 @@ AliCDBParam* AliCDBLocalFactory::CreateParameter(const char* dbString) {
                return NULL;
        }
 
+       TString checkSS(dbString);
+       if(checkSS.BeginsWith("snapshot://"))
+       {
+           TString snapshotPath("OCDB");
+           snapshotPath.Prepend(TString(gSystem->WorkingDirectory()) + '/');
+           checkSS.Remove(0,checkSS.First(':')+3);
+           return new AliCDBLocalParam(snapshotPath,checkSS);
+       }
+               
+       // if the string argument is not a snapshot URI, than it is a plain local URI
        TString pathname(dbString + sizeof("local://") - 1);
        
-       gSystem->ExpandPathName(pathname);
+       if(gSystem->ExpandPathName(pathname))
+           return NULL;
 
        if (pathname[0] != '/') {
                pathname.Prepend(TString(gSystem->WorkingDirectory()) + '/');
        }
+       //pathname.Prepend("local://");
 
        return new AliCDBLocalParam(pathname);
 }
@@ -1020,6 +1032,17 @@ AliCDBLocalParam::AliCDBLocalParam(const char* dbPath):
 }
 
 //_____________________________________________________________________________
+AliCDBLocalParam::AliCDBLocalParam(const char* dbPath, const char* uri):
+ AliCDBParam(),
+ fDBPath(dbPath)
+{
+// constructor
+
+       SetType("local");
+       SetURI(TString("alien://") + uri);
+}
+
+//_____________________________________________________________________________
 AliCDBLocalParam::~AliCDBLocalParam() {
 // destructor
 
index f0f73d6..193eb3f 100644 (file)
@@ -90,6 +90,7 @@ class AliCDBLocalParam: public AliCDBParam {
 public:
        AliCDBLocalParam();
        AliCDBLocalParam(const char* dbPath);
+       AliCDBLocalParam(const char* dbPath, const char* uri);
        
        virtual ~AliCDBLocalParam();
 
index b80765d..53ea6b0 100644 (file)
@@ -30,6 +30,7 @@
 #include <TObjString.h>
 #include <TSAXParser.h>
 #include <TFile.h>
+#include <TKey.h>
 #include <TUUID.h>
 #include <TGrid.h>
 
@@ -98,6 +99,84 @@ void AliCDBManager::InitFromCache(TMap *entryCache, Int_t run) {
 }
 
 //_____________________________________________________________________________
+Bool_t AliCDBManager::InitFromSnapshot(const char* snapshotFileName){
+// initialize manager from a CDB snapshot, that is add the entries
+// to the entries map and the ids to the ids list taking them from
+// the map and the list found in the input file
+
+    // open the file
+    TString snapshotFile(snapshotFileName);
+    if(snapshotFile.BeginsWith("alien://")){
+       if(!gGrid) {
+           TGrid::Connect("alien://","");
+           if(!gGrid) {
+               AliError("Connection to alien failed!");
+               return kFALSE;
+           }
+       }
+    }
+
+    TFile *f = TFile::Open(snapshotFileName);
+    if (!f || f->IsZombie()){
+       AliError(Form("Cannot open file %s",snapshotFileName));
+       return kFALSE;
+    }
+
+    // retrieve entries map
+    TMap *entriesMap = 0;
+    TIter next(f->GetListOfKeys());
+    TKey *key;
+    while ((key = (TKey*)next())) {
+       if (strcmp(key->GetClassName(),"TMap") != 0) continue;
+       entriesMap = (TMap*)key->ReadObj();
+       break;
+    }
+    if (!entriesMap || entriesMap->GetEntries()==0){
+       AliError("Cannot get valid map of CDB entries from snapshot file");
+       return kFALSE;
+    }
+
+    // retrieve ids list
+    TList *idsList = 0;
+    TIter nextKey(f->GetListOfKeys());
+    TKey *keyN;
+    while ((keyN = (TKey*)nextKey())) {
+       if (strcmp(keyN->GetClassName(),"TList") != 0) continue;
+       idsList = (TList*)keyN->ReadObj();
+       break;
+    }
+    if (!idsList || idsList->GetEntries()==0){
+       AliError("Cannot get valid list of CDB entries from snapshot file");
+       return kFALSE;
+    }
+
+    TIter iterObj(entriesMap->GetTable());
+    TPair* pair = 0;
+
+    while((pair = dynamic_cast<TPair*> (iterObj.Next()))){
+       fEntryCache.Add(pair->Key(),pair->Value());
+    }
+    // fEntry is the new owner of the cache
+    fEntryCache.SetOwnerKeyValue(kTRUE,kTRUE);
+    entriesMap->SetOwnerKeyValue(kFALSE,kFALSE);
+    AliInfo(Form("%d cache entries have been loaded",fEntryCache.GetEntries()));
+
+    TIter iterId(idsList);      
+
+    AliCDBId* id=0;
+    while((id = dynamic_cast<AliCDBId*> (iterId.Next()))){      
+       fIds->Add(id);   
+    }   
+    fIds->SetOwner(kTRUE);
+    idsList->SetOwner(kFALSE);
+    f->Close();
+    delete f;
+    AliInfo(Form("%d cache ids loaded. Total number of ids is %d",idsList->GetEntries(),fIds->GetEntries()));
+
+    return kTRUE;
+}
+
+//_____________________________________________________________________________
 void AliCDBManager::Destroy() {
 // delete ALCDBManager instance and active storages
 
@@ -523,7 +602,7 @@ void AliCDBManager::SetSpecificStorage(const char* calibType, const char* dbStri
 }
 
 //_____________________________________________________________________________
-void AliCDBManager::SetSpecificStorage(const char* calibType, AliCDBParam* param) {
+void AliCDBManager::SetSpecificStorage(const char* calibType, const AliCDBParam* param) {
 // sets storage specific for detector or calibration type (works with AliCDBManager::Get(...))
 // Default storage should be defined prior to any specific storages, e.g.:
 // AliCDBManager::instance()->SetDefaultStorage("alien://");
@@ -931,7 +1010,7 @@ TList* AliCDBManager::GetAll(const AliCDBId& query) {
 }
 
 //_____________________________________________________________________________
-Bool_t AliCDBManager::Put(TObject* object, AliCDBId& id, AliCDBMetaData* metaData, const DataType type){
+Bool_t AliCDBManager::Put(TObject* object, const AliCDBId& id, AliCDBMetaData* metaData, const DataType type){
 // store an AliCDBEntry object into the database
 
        if (object==0x0) {
index 22bd2b8..822145a 100644 (file)
@@ -57,7 +57,7 @@ class AliCDBManager: public TObject {
        void UnsetDefaultStorage();
 
        void SetSpecificStorage(const char* calibType, const char* dbString);
-       void SetSpecificStorage(const char* calibType, AliCDBParam* param);
+       void SetSpecificStorage(const char* calibType, const AliCDBParam* param);
 
        AliCDBStorage* GetSpecificStorage(const char* calibType);
 
@@ -91,7 +91,7 @@ class AliCDBManager: public TObject {
        TList* GetAll(const AliCDBPath& path, const AliCDBRunRange& runRange,
                                 Int_t version = -1, Int_t subVersion = -1); 
 
-       Bool_t Put(TObject* object, AliCDBId& id,
+       Bool_t Put(TObject* object, const AliCDBId& id,
                        AliCDBMetaData* metaData, const DataType type=kPrivate);
        Bool_t Put(AliCDBEntry* entry, DataType type=kPrivate);
 
@@ -127,6 +127,7 @@ class AliCDBManager: public TObject {
 
        void Init();
        void InitFromCache(TMap *entryCache, Int_t run);
+       Bool_t InitFromSnapshot(const char* snapshotFileName);
   
 protected:
 
index 9b3533f..3638cb3 100644 (file)
@@ -275,6 +275,7 @@ AliReconstruction::AliReconstruction(const char* gAliceFilename) :
   fQARefUri(),
   fSpecCDBUri(), 
   fInitCDBCalled(kFALSE),
+  fFromCDBSnapshot(kFALSE),
   fSetRunNumberFromDataCalled(kFALSE),
   fQADetectors("ALL"), 
   fQATasks("ALL"), 
@@ -393,6 +394,7 @@ AliReconstruction::AliReconstruction(const AliReconstruction& rec) :
   fQARefUri(rec.fQARefUri),
   fSpecCDBUri(), 
   fInitCDBCalled(rec.fInitCDBCalled),
+  fFromCDBSnapshot(rec.fFromCDBSnapshot),
   fSetRunNumberFromDataCalled(rec.fSetRunNumberFromDataCalled),
   fQADetectors(rec.fQADetectors), 
   fQATasks(rec.fQATasks), 
@@ -559,6 +561,7 @@ AliReconstruction& AliReconstruction::operator = (const AliReconstruction& rec)
   fQARefUri      = rec.fQARefUri;
   fSpecCDBUri.Delete();
   fInitCDBCalled               = rec.fInitCDBCalled;
+  fFromCDBSnapshot             = rec.fFromCDBSnapshot;
   fSetRunNumberFromDataCalled  = rec.fSetRunNumberFromDataCalled;
   fQADetectors                 = rec.fQADetectors;
   fQATasks                     = rec.fQATasks; 
@@ -1496,6 +1499,14 @@ void AliReconstruction::Begin(TTree *)
     AliSysInfo::AddStamp("CheckGeom");
   }
 
+  if(fFromCDBSnapshot){
+      AliDebug(2,"Initializing from a CDB snapshot");
+      if(!AliCDBManager::Instance()->InitFromSnapshot(fSnapshotFileName.Data())){
+         Abort("InitFromSnapshot", TSelector::kAbortProcess);
+         return;
+      }
+  }
+
   if (!MisalignGeometry(fLoadAlignData)) {
     Abort("MisalignGeometry", TSelector::kAbortProcess);
     return;
@@ -1509,11 +1520,13 @@ void AliReconstruction::Begin(TTree *)
   }
   AliSysInfo::AddStamp("InitGRP");
 
-  if (!LoadCDB()) {
-    Abort("LoadCDB", TSelector::kAbortProcess);
-    return;
+  if(!fFromCDBSnapshot){
+      if (!LoadCDB()) {
+         Abort("LoadCDB", TSelector::kAbortProcess);
+         return;
+      }
+      AliSysInfo::AddStamp("LoadCDB");
   }
-  AliSysInfo::AddStamp("LoadCDB");
 
   if (!LoadTriggerScalersCDB()) {
     Abort("LoadTriggerScalersCDB", TSelector::kAbortProcess);
index 92a910d..eabb816 100644 (file)
@@ -118,6 +118,8 @@ public:
   // CDB storage activation
   void SetDefaultStorage(const char* uri);
   void SetSpecificStorage(const char* calibType, const char* uri);
+  void SetFromCDBSnapshot(const char* snapshotFileName) {fFromCDBSnapshot = kTRUE; fSnapshotFileName=snapshotFileName;}
+  void UnSetFromCDBSnapshot() {fFromCDBSnapshot = kFALSE;}
 
   Bool_t MisalignGeometry(const TString& detectors);
 
@@ -310,6 +312,8 @@ private:
   TString       fQARefUri;         //! Uri of the default QA reference storage
   TObjArray      fSpecCDBUri;         //! Array with detector specific CDB storages
   Bool_t        fInitCDBCalled;               //! flag to check if CDB storages are already initialized
+  Bool_t        fFromCDBSnapshot;             //! flag to check if we are loading the CDB from a snapshot
+  TString        fSnapshotFileName;           //! string for the file containing the CDB snapshot
   Bool_t        fSetRunNumberFromDataCalled;  //! flag to check if run number is already loaded from run loader
 
   //Quality Assurance
@@ -357,7 +361,7 @@ private:
   TString              fAnalysisMacro; // Full path to a macro creating an analysis manager train
   AliAnalysisManager  *fAnalysis;      //! Analysis manager
   AliRecoInputHandler *fRecoHandler;   //! Input handler adapted for reconstruction
-  ClassDef(AliReconstruction, 40)      // class for running the reconstruction
+  ClassDef(AliReconstruction, 41)      // class for running the reconstruction
 };
 
 #endif
diff --git a/macros/MakeCDBSnapshot.C b/macros/MakeCDBSnapshot.C
new file mode 100644 (file)
index 0000000..ddfb7d8
--- /dev/null
@@ -0,0 +1,128 @@
+#include "AliCDBManager.h"
+#include "AliCDBId.h"
+#include "TCollection.h"
+#include "TMap.h"
+#include "TKey.h"
+#include "TString.h"
+#include "TObjString.h"
+#include "TFile.h"
+#include "TSystem.h"
+
+void MakeSnapshot(Int_t run, const char* defStorage, TMap* specStorages, const char* snapshotFileName)
+{
+    AliCDBManager *cdb = AliCDBManager::Instance();
+    cdb->SetDefaultStorage(defStorage);
+    cdb->SetRun(run);
+
+    TIter iter(specStorages->GetTable());
+    TPair *pair = 0;
+    while((pair = dynamic_cast<TPair*> (iter.Next()))){
+       TObjString* caltype = dynamic_cast<TObjString*> (pair->Key());
+       TObjString* specstor= dynamic_cast<TObjString*> (pair->Value());
+       if (caltype && specstor)
+           //TString calType = caltype->GetString();
+           //TString specStor = specstor->GetString();
+           //cdb->SetSpecificStorage(calType.Data(),specStor.Data());
+           cdb->SetSpecificStorage(caltype->GetString().Data(),specstor->GetString().Data());
+       else
+           //AliFatal("Error reading info for specific storage")
+           Printf("Error reading info for specific storage");
+    }
+
+    // ********************************** GRP ******************************************
+    cdb->Get("GRP/CTP/Config");
+    cdb->Get("GRP/Calib/LHCClockPhase");
+    cdb->Get("GRP/GRP/Data");
+    cdb->Get("GRP/Align/Data");
+    cdb->Get("GRP/Calib/MeanVertexSPD");
+    cdb->Get("GRP/Calib/MeanVertex");
+    cdb->Get("GRP/Calib/MeanVertexTPC");
+    cdb->Get("GRP/Calib/CosmicTriggers");
+    cdb->Get("GRP/CTP/Scalers");
+    cdb->Get("GRP/CTP/CTPtiming");
+    cdb->Get("GRP/CTP/TimeAlign");
+    cdb->Get("GRP/GRP/LHCData");
+    cdb->Get("GRP/Calib/RecoParam");
+
+    // ********************************** ALL ******************************************
+    TString detStr = ("ITS TPC TRD TOF PHOS HMPID EMCAL MUON ZDC PMD T0 VZERO");
+    //TString detStr = ("ITS MUON TPC");
+    TObjArray *arr = detStr.Tokenize(' ');
+    for (Int_t iDet=0; iDet<arr->GetEntries(); iDet++) {
+       TObjString *detOStr = dynamic_cast<TObjString*>(arr->At(iDet));
+       AliCDBManager::Instance()->GetAll(Form("%s/Calib/*",detOStr->GetString().Data()));
+       AliCDBManager::Instance()->Get(Form("%s/Align/Data",detOStr->GetString().Data()));
+    }
+
+    // ******************************** TRIGGER ****************************************
+    // Temporary fix - one has to define the correct policy in order
+    // to load the trigger OCDB entries only for the detectors that
+    // in the trigger or that are needed in order to put correct
+    // information in ESD
+    AliCDBManager::Instance()->GetAll("TRIGGER/*/*");
+
+    // ********************************** HLT ******************************************
+    // cdb->Get("HLT/ConfigHLT/esdLayout");
+    // cdb->Get("HLT/Calib/StreamerInfo");
+
+    TMap* entriesMap = const_cast<TMap*>(cdb->GetEntryCache());
+    Printf("\nentriesMap has %d entries!\n", entriesMap->GetEntries());
+
+    TList* entriesList = const_cast<TList*>(cdb->GetRetrievedIds());
+    Printf("\nentriesList has %d entries!\n", entriesList->GetEntries());
+
+    //TString filename(TString::Format("CDBsnapshot_Run%d.root",run));
+    TString filename(snapshotFileName);
+    TFile *f = new TFile(filename.Data(),"recreate");
+    f->cd();
+    f->WriteObject(entriesMap,"entriesMap");
+    f->WriteObject(entriesList,"entriesList");
+    f->Close();
+    entriesMap->SetOwnerKeyValue(kFALSE,kFALSE);
+    entriesList->SetOwner(kFALSE);
+}
+
+void MakeCDBSnapshot()
+{
+    //TMap *specMap = new TMap(10);
+    TMap *specMap = new TMap(30);
+    specMap->SetName("mapOfSpecificStorages");
+    specMap->SetOwner(1);
+    specMap->Add(new TObjString("ITS/Align/Data"), new TObjString("alien://folder=/alice/simulation/2008/v4-15-Release/Residual"));
+
+    specMap->Add(new TObjString("MUON/Align/Data"), new TObjString("alien://Folder=/alice/simulation/2008/v4-15-Release/Ideal/"));
+    specMap->Add(new TObjString("MUON/Calib/Gains"), new TObjString("alien://Folder=/alice/simulation/2008/v4-15-Release/Ideal/"));
+    //      MTR
+    specMap->Add(new TObjString("MUON/Calib/GlobalTriggerCrateConfig"), new TObjString("alien://Folder=/alice/simulation/2008/v4-15-Release/Full"));
+    specMap->Add(new TObjString("MUON/Calib/LocalTriggerBoardMasks"), new TObjString("alien://Folder=/alice/simulation/2008/v4-15-Release/Full"));
+    specMap->Add(new TObjString("MUON/Calib/RegionalTriggerConfig"), new TObjString("alien://Folder=/alice/simulation/2008/v4-15-Release/Full"));
+    specMap->Add(new TObjString("MUON/Calib/TriggerEfficiency"), new TObjString("alien://Folder=/alice/simulation/2008/v4-15-Release/Full"));
+    // TPC (23 total) 
+    specMap->Add(new TObjString("TPC/Calib/PadGainFactor"), new TObjString("alien://Folder=/alice/simulation/2008/v4-15-Release/Ideal/"));
+    specMap->Add(new TObjString("TPC/Calib/TimeGain"), new TObjString("alien://Folder=/alice/simulation/2008/v4-15-Release/Ideal/"));
+    specMap->Add(new TObjString("TPC/Calib/GainFactorDedx"), new TObjString("alien://Folder=/alice/simulation/2008/v4-15-Release/Ideal/"));
+    specMap->Add(new TObjString("TPC/Calib/PadTime0"), new TObjString("alien://Folder=/alice/simulation/2008/v4-15-Release/Ideal/"));
+    specMap->Add(new TObjString("TPC/Calib/Distortion"), new TObjString("alien://Folder=/alice/simulation/2008/v4-15-Release/Ideal/"));
+    specMap->Add(new TObjString("TPC/Calib/PadNoise"), new TObjString("alien://Folder=/alice/simulation/2008/v4-15-Release/Ideal/"));
+    specMap->Add(new TObjString("TPC/Calib/PadNoise"), new TObjString("alien://Folder=/alice/simulation/2008/v4-15-Release/Ideal/"));
+    specMap->Add(new TObjString("TPC/Calib/Pedestals"), new TObjString("alien://Folder=/alice/simulation/2008/v4-15-Release/Ideal/"));
+    specMap->Add(new TObjString("TPC/Calib/Temperature"), new TObjString("alien://Folder=/alice/simulation/2008/v4-15-Release/Ideal/"));
+    specMap->Add(new TObjString("TPC/Calib/Parameters"), new TObjString("alien://Folder=/alice/simulation/2008/v4-15-Release/Ideal/"));
+    specMap->Add(new TObjString("TPC/Calib/ClusterParam"), new TObjString("alien://Folder=/alice/simulation/2008/v4-15-Release/Ideal/"));
+    specMap->Add(new TObjString("TPC/Calib/AltroConfig"), new TObjString("alien://Folder=/alice/simulation/2008/v4-15-Release/Ideal/"));
+    specMap->Add(new TObjString("TPC/Calib/Pulser"), new TObjString("alien://Folder=/alice/simulation/2008/v4-15-Release/Ideal/"));
+    specMap->Add(new TObjString("TPC/Calib/Pulser"), new TObjString("alien://Folder=/alice/simulation/2008/v4-15-Release/Ideal/"));
+    specMap->Add(new TObjString("TPC/Calib/CE"), new TObjString("alien://Folder=/alice/simulation/2008/v4-15-Release/Ideal/"));
+    specMap->Add(new TObjString("TPC/Calib/Mapping"), new TObjString("alien://Folder=/alice/simulation/2008/v4-15-Release/Ideal/"));
+    specMap->Add(new TObjString("TPC/Calib/Correction"), new TObjString("alien://Folder=/alice/simulation/2008/v4-15-Release/Ideal/"));
+    specMap->Add(new TObjString("TPC/Align/Data"), new TObjString("alien://Folder=/alice/simulation/2008/v4-15-Release/Ideal/"));
+    specMap->Add(new TObjString("TPC/Calib/Goofie"), new TObjString("alien://Folder=/alice/simulation/2008/v4-15-Release/Ideal/"));
+    specMap->Add(new TObjString("TPC/Calib/TimeDrift"), new TObjString("alien://Folder=/alice/simulation/2008/v4-15-Release/Ideal/"));
+    specMap->Add(new TObjString("TPC/Calib/Raw"), new TObjString("alien://Folder=/alice/simulation/2008/v4-15-Release/Ideal/"));
+    specMap->Add(new TObjString("TPC/Calib/QA"), new TObjString("alien://Folder=/alice/simulation/2008/v4-15-Release/Ideal/"));
+    specMap->Add(new TObjString("TPC/Calib/HighVoltage"), new TObjString("alien://Folder=/alice/simulation/2008/v4-15-Release/Ideal/")); 
+
+
+    MakeSnapshot(139517,"alien://folder=/alice/data/2010/OCDB",specMap,"cdbSnapshot.root");
+
+}