From 024cf675196bebb0ff74599c31999078a77f033d Mon Sep 17 00:00:00 2001 From: cvetan Date: Fri, 24 Mar 2006 15:59:00 +0000 Subject: [PATCH] New version of CDB framework. Proper initialization of CDB inside AliSimulation and AliReconstruction. Centralized application of alignment data for all sub-detectors inside AliSimulation and AliReconstruction (R.Grosso and A.Colla) --- STEER/AliCDBDump.cxx | 12 +- STEER/AliCDBEntry.cxx | 7 ++ STEER/AliCDBEntry.h | 2 + STEER/AliCDBGrid.cxx | 29 +++-- STEER/AliCDBLocal.cxx | 28 ++--- STEER/AliCDBManager.cxx | 138 +++++++++++++--------- STEER/AliCDBManager.h | 14 ++- STEER/AliReconstruction.cxx | 55 ++++++--- STEER/AliReconstruction.h | 8 ++ STEER/AliRun.cxx | 2 +- STEER/AliRun.h | 2 +- STEER/AliSimulation.cxx | 226 ++++++++++++++++++++++++++++++++---- STEER/AliSimulation.h | 25 +++- 13 files changed, 414 insertions(+), 134 deletions(-) diff --git a/STEER/AliCDBDump.cxx b/STEER/AliCDBDump.cxx index 18a5ba21614..c90dffe53ac 100644 --- a/STEER/AliCDBDump.cxx +++ b/STEER/AliCDBDump.cxx @@ -291,7 +291,7 @@ Bool_t AliCDBDump::GetId(const AliCDBId& query, AliCDBId& result) { aRunRange.GetLastRun()); } else if (result.GetVersion() == aVersion && result.GetSubVersion() == aSubVersion){ - AliError(Form("More than one object valid for run %d, version %d_%d!", + AliDebug(2,Form("More than one object valid for run %d, version %d_%d!", query.GetFirstRun(), aVersion, aSubVersion)); result.SetRunRange(-1,-1); result.SetVersion(-1); result.SetSubVersion(-1); return kFALSE; @@ -314,7 +314,7 @@ Bool_t AliCDBDump::GetId(const AliCDBId& query, AliCDBId& result) { // aVersion is requested version! if(result.GetSubVersion() == aSubVersion){ - AliError(Form("More than one object valid for run %d, version %d_%d!", + AliDebug(2,Form("More than one object valid for run %d, version %d_%d!", query.GetFirstRun(), aVersion, aSubVersion)); result.SetRunRange(-1,-1); result.SetVersion(-1); result.SetSubVersion(-1); return kFALSE; @@ -344,7 +344,7 @@ Bool_t AliCDBDump::GetId(const AliCDBId& query, AliCDBId& result) { // aVersion and aSubVersion are requested version and subVersion! if(result.GetVersion() == aVersion && result.GetSubVersion() == aSubVersion){ - AliError(Form("More than one object valid for run %d, version %d_%d!", + AliDebug(2,Form("More than one object valid for run %d, version %d_%d!", query.GetFirstRun(), aVersion, aSubVersion)); result.SetRunRange(-1,-1); result.SetVersion(-1); result.SetSubVersion(-1); return kFALSE; @@ -395,7 +395,7 @@ AliCDBEntry* AliCDBDump::GetEntry(const AliCDBId& queryId) { TString keyname; if (!IdToKeyName(dataId.GetAliCDBRunRange(), dataId.GetVersion(), dataId.GetSubVersion(), keyname)) { - AliError("Bad ID encountered! Subnormal error!"); + AliDebug(2,Form("Bad ID encountered! Subnormal error!")); return NULL; } @@ -405,12 +405,12 @@ AliCDBEntry* AliCDBDump::GetEntry(const AliCDBId& queryId) { TObject* anObject = gDirectory->Get(keyname); if (!anObject) { - AliError("Bad storage data: NULL entry object!"); + AliDebug(2,Form("Bad storage data: NULL entry object!")); return NULL; } if (AliCDBEntry::Class() != anObject->IsA()) { - AliError("Bad storage data: Invalid entry object!"); + AliDebug(2,Form("Bad storage data: Invalid entry object!")); return NULL; } diff --git a/STEER/AliCDBEntry.cxx b/STEER/AliCDBEntry.cxx index 29dce5c2e55..e305983170c 100644 --- a/STEER/AliCDBEntry.cxx +++ b/STEER/AliCDBEntry.cxx @@ -22,6 +22,7 @@ ///////////////////////////////////////////////////////////////////// #include "AliCDBEntry.h" +#include "AliLog.h" ClassImp(AliCDBEntry) @@ -135,3 +136,9 @@ AliCDBEntry::~AliCDBEntry() { } } +//_____________________________________________________________________________ +void AliCDBEntry::PrintId() const { + + AliInfo(Form("%s",fId.ToString().Data())); + +} diff --git a/STEER/AliCDBEntry.h b/STEER/AliCDBEntry.h index 7f9e723d098..fb608d3b518 100644 --- a/STEER/AliCDBEntry.h +++ b/STEER/AliCDBEntry.h @@ -49,6 +49,7 @@ public: void SetId(const AliCDBId& id) {fId = id;}; AliCDBId& GetId() {return fId;}; const AliCDBId& GetId() const {return fId;}; + void PrintId() const; void SetObject(TObject* object) {fObject = object;}; TObject* GetObject() {return fObject;}; @@ -57,6 +58,7 @@ public: void SetMetaData(AliCDBMetaData* metaData) {fMetaData = metaData;}; AliCDBMetaData* GetMetaData() {return fMetaData;}; const AliCDBMetaData* GetMetaData() const {return fMetaData;}; + void PrintMetaData() const {fMetaData->PrintMetaData();} void SetOwner(Bool_t owner) {fIsOwner = owner;}; Bool_t IsOwner() const {return fIsOwner;}; diff --git a/STEER/AliCDBGrid.cxx b/STEER/AliCDBGrid.cxx index 2086fd4dc55..640a558c88c 100644 --- a/STEER/AliCDBGrid.cxx +++ b/STEER/AliCDBGrid.cxx @@ -50,8 +50,13 @@ fSE(se) // if the same Grid is alreay active, skip connection if (!gGrid || fGridUrl != gGrid->GridUrl() - || fUser != gGrid->GetUser()) { + || (( fUser != "" ) && ( fUser != gGrid->GetUser() )) ) { // connection to the Grid + AliInfo("Connection to the Grid!!!!"); + if(gGrid){ + AliInfo(Form("gGrid = %x; fGridUrl = %s; gGrid->GridUrl() = %s",gGrid,fGridUrl.Data(), gGrid->GridUrl())); + AliInfo(Form("fUser = %s; gGrid->GetUser() = %s",fUser.Data(), gGrid->GetUser())); + } TGrid::Connect(fGridUrl.Data(),fUser.Data()); } @@ -225,8 +230,8 @@ Bool_t AliCDBGrid::GetId(const AliCDBId& query, AliCDBId& result) { dirName += query.GetPath(); // dirName = fDBFolder/idPath if (!gGrid->Cd(dirName,0)) { - AliError(Form("Directory <%s> not found", (query.GetPath()).Data())); - AliError(Form("in DB folder %s", fDBFolder.Data())); + AliDebug(2,Form("Directory <%s> not found", (query.GetPath()).Data())); + AliDebug(2,Form("in DB folder %s", fDBFolder.Data())); return kFALSE; } @@ -247,7 +252,7 @@ Bool_t AliCDBGrid::GetId(const AliCDBId& query, AliCDBId& result) { if (!query.HasVersion()){ // look for highest version if(result.GetVersion() > aVersion) continue; if(result.GetVersion() == aVersion) { - AliError(Form("More than one object valid for run %d, version %d!", + AliDebug(2,Form("More than one object valid for run %d, version %d!", query.GetFirstRun(), aVersion)); return kFALSE; } @@ -258,7 +263,7 @@ Bool_t AliCDBGrid::GetId(const AliCDBId& query, AliCDBId& result) { } else { // look for specified version if(query.GetVersion() != aVersion) continue; if(result.GetVersion() == aVersion){ - AliError(Form("More than one object valid for run %d, version %d!", + AliDebug(2,Form("More than one object valid for run %d, version %d!", query.GetFirstRun(), aVersion)); return kFALSE; } @@ -295,17 +300,17 @@ AliCDBEntry* AliCDBGrid::GetEntry(const AliCDBId& queryId) { TString filename; if (!IdToFilename(dataId.GetAliCDBRunRange(), dataId.GetVersion(),filename)) { - AliError("Bad data ID encountered! Subnormal error!"); + AliDebug(2,Form("Bad data ID encountered! Subnormal error!")); return NULL; } filename.Prepend("/alien" + fDBFolder + queryId.GetPath() + '/'); filename += "?se="; filename += fSE.Data(); - AliInfo(Form("Opening file: %s",filename.Data())); + AliDebug(2,Form("Opening file: %s",filename.Data())); TFile *file = TFile::Open(filename); if (!file) { - AliError(Form("Can't open file <%s>!", filename.Data())); + AliDebug(2,Form("Can't open file <%s>!", filename.Data())); return NULL; } @@ -315,12 +320,12 @@ AliCDBEntry* AliCDBGrid::GetEntry(const AliCDBId& queryId) { TObject* anObject = file->Get("AliCDBEntry"); if (!anObject) { - AliError("Bad storage data: NULL entry object!"); + AliDebug(2,Form("Bad storage data: NULL entry object!")); return NULL; } if (AliCDBEntry::Class() != anObject->IsA()) { - AliError("Bad storage data: Invalid entry object!"); + AliDebug(2,Form("Bad storage data: Invalid entry object!")); return NULL; } @@ -352,7 +357,7 @@ void AliCDBGrid::GetEntriesForLevel0(const char* level0, level0Dir += level0; if (!gGrid->Cd(level0Dir,0)) { - AliError(Form("Level0 directory <%s> not found", level0Dir.Data())); + AliDebug(2,Form("Level0 directory <%s> not found", level0Dir.Data())); return; } @@ -377,7 +382,7 @@ void AliCDBGrid::GetEntriesForLevel1(const char* level0, const char* level1, level1Dir += level1; if (!gGrid->Cd(level1Dir,0)) { - AliError(Form("Level1 directory <%s> not found", level1Dir.Data())); + AliDebug(2,Form("Level1 directory <%s> not found", level1Dir.Data())); return; } diff --git a/STEER/AliCDBLocal.cxx b/STEER/AliCDBLocal.cxx index 5f0fa08f6da..e6e4a3d6fc5 100644 --- a/STEER/AliCDBLocal.cxx +++ b/STEER/AliCDBLocal.cxx @@ -250,8 +250,8 @@ Bool_t AliCDBLocal::GetId(const AliCDBId& query, AliCDBId& result) { void* dirPtr = gSystem->OpenDirectory(dirName); if (!dirPtr) { - AliError(Form("Directory <%s> not found", (query.GetPath()).Data())); - AliError(Form("in DB folder %s", fBaseDirectory.Data())); + AliDebug(2,Form("Directory <%s> not found", (query.GetPath()).Data())); + AliDebug(2,Form("in DB folder %s", fBaseDirectory.Data())); return kFALSE; } @@ -294,7 +294,7 @@ Bool_t AliCDBLocal::GetId(const AliCDBId& query, AliCDBId& result) { aRunRange.GetLastRun()); } else if (result.GetVersion() == aVersion && result.GetSubVersion() == aSubVersion){ - AliError(Form("More than one object valid for run %d, version %d_%d!", + AliDebug(2,Form("More than one object valid for run %d, version %d_%d!", query.GetFirstRun(), aVersion, aSubVersion)); gSystem->FreeDirectory(dirPtr); return kFALSE; @@ -320,7 +320,7 @@ Bool_t AliCDBLocal::GetId(const AliCDBId& query, AliCDBId& result) { // aVersion is requested version! if(result.GetSubVersion() == aSubVersion){ - AliError(Form("More than one object valid for run %d, version %d_%d!", + AliDebug(2,Form("More than one object valid for run %d, version %d_%d!", query.GetFirstRun(), aVersion, aSubVersion)); gSystem->FreeDirectory(dirPtr); return kFALSE; @@ -353,7 +353,7 @@ Bool_t AliCDBLocal::GetId(const AliCDBId& query, AliCDBId& result) { // aVersion and aSubVersion are requested version and subVersion! if(result.GetVersion() == aVersion && result.GetSubVersion() == aSubVersion){ - AliError(Form("More than one object valid for run %d, version %d_%d!", + AliDebug(2,Form("More than one object valid for run %d, version %d_%d!", query.GetFirstRun(), aVersion, aSubVersion)); gSystem->FreeDirectory(dirPtr); return kFALSE; @@ -394,7 +394,7 @@ AliCDBEntry* AliCDBLocal::GetEntry(const AliCDBId& queryId) { if (!IdToFilename(dataId.GetAliCDBRunRange(), dataId.GetVersion(), dataId.GetSubVersion(), filename)) { - AliError("Bad data ID encountered! Subnormal error!"); + AliDebug(2,Form("Bad data ID encountered! Subnormal error!")); return NULL; } @@ -402,7 +402,7 @@ AliCDBEntry* AliCDBLocal::GetEntry(const AliCDBId& queryId) { TFile file(filename, "READ"); // open file if (!file.IsOpen()) { - AliError(Form("Can't open file <%s>!", filename.Data())); + AliDebug(2,Form("Can't open file <%s>!", filename.Data())); return NULL; } @@ -411,12 +411,12 @@ AliCDBEntry* AliCDBLocal::GetEntry(const AliCDBId& queryId) { TObject* anObject = file.Get("AliCDBEntry"); if (!anObject) { - AliError("Bad storage data: NULL entry object!"); + AliDebug(2,Form("Bad storage data: NULL entry object!")); return NULL; } if (AliCDBEntry::Class() != anObject->IsA()) { - AliError("Bad storage data: Invalid entry object!"); + AliDebug(2,Form("Bad storage data: Invalid entry object!")); return NULL; } @@ -451,7 +451,7 @@ void AliCDBLocal::GetEntriesForLevel0(const char* level0, void* level0DirPtr = gSystem->OpenDirectory(level0Dir); if (!level0DirPtr) { - AliError(Form("Can't open level0 directory <%s>!", + AliDebug(2,Form("Can't open level0 directory <%s>!", level0Dir.Data())); return; } @@ -486,7 +486,7 @@ void AliCDBLocal::GetEntriesForLevel1(const char* level0, const char* level1, void* level1DirPtr = gSystem->OpenDirectory(level1Dir); if (!level1DirPtr) { - AliError(Form("Can't open level1 directory <%s>!", + AliDebug(2,Form("Can't open level1 directory <%s>!", level1Dir.Data())); return; } @@ -521,7 +521,7 @@ TList* AliCDBLocal::GetEntries(const AliCDBId& queryId) { void* storageDirPtr = gSystem->OpenDirectory(fBaseDirectory); if (!storageDirPtr) { - AliError(Form("Can't open storage directory <%s>", + AliDebug(2,Form("Can't open storage directory <%s>", fBaseDirectory.Data())); return NULL; } @@ -562,7 +562,7 @@ Bool_t AliCDBLocal::PutEntry(AliCDBEntry* entry) { if (!IdToFilename(id.GetAliCDBRunRange(), id.GetVersion(), id.GetSubVersion(), filename)) { - AliError("Bad ID encountered! Subnormal error!"); + AliDebug(2,Form("Bad ID encountered! Subnormal error!")); return kFALSE; } @@ -580,7 +580,7 @@ Bool_t AliCDBLocal::PutEntry(AliCDBEntry* entry) { // write object (key name: "AliCDBEntry") Bool_t result = file.WriteTObject(entry, "AliCDBEntry"); - if (!result) AliError(Form("Can't write entry to file: %s", filename.Data())); + if (!result) AliDebug(2,Form("Can't write entry to file: %s", filename.Data())); file.Close(); if(result) AliInfo(Form("CDB object stored into file %s",filename.Data())); diff --git a/STEER/AliCDBManager.cxx b/STEER/AliCDBManager.cxx index f469c7f5551..8bb84542fa4 100644 --- a/STEER/AliCDBManager.cxx +++ b/STEER/AliCDBManager.cxx @@ -267,42 +267,45 @@ void AliCDBManager::SetDefaultStorage(AliCDBStorage* storage) { } //_____________________________________________________________________________ -void AliCDBManager::SetSpecificStorage(const char* detName, const char* dbString) { -// sets storage specific for detector (works with AliCDBManager::Get(...)) +void AliCDBManager::SetSpecificStorage(const char* calibType, const char* dbString) { +// sets storage specific for detector or calibration type (works with AliCDBManager::Get(...)) AliCDBParam *aPar = CreateParameter(dbString); if(!aPar) return; - SetSpecificStorage(detName, aPar); + SetSpecificStorage(calibType, aPar); delete aPar; } //_____________________________________________________________________________ -void AliCDBManager::SetSpecificStorage(const char* detName, AliCDBParam* param) { -// sets storage specific for detector (works with AliCDBManager::Get(...)) +void AliCDBManager::SetSpecificStorage(const char* calibType, 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://"); +// AliCDBManager::instance()->SetSpecificStorage("TPC","local://DB_TPC"); +// AliCDBManager::instance()->SetSpecificStorage("RICH/Align","local://DB_TPCAlign"); if(!fDefaultStorage) { AliError("Please activate a default storage first!"); return; } - TObjString *objDetName = new TObjString(detName); - AliCDBParam *checkPar = (AliCDBParam*) fSpecificStorages.GetValue(objDetName); - if(checkPar){ - AliWarning(Form("%s storage already activated! It will be replaced by the new one",objDetName->String().Data())); - fSpecificStorages.Remove(objDetName); - delete checkPar; + TObjString *objCalibType = new TObjString(calibType); + if(fSpecificStorages.Contains(objCalibType)){ + AliWarning(Form("%s storage already activated! It will be replaced by the new one", + calibType)); + fSpecificStorages.Remove(objCalibType); } GetStorage(param); - fSpecificStorages.Add(objDetName, param->CloneParam()); + fSpecificStorages.Add(objCalibType, param->CloneParam()); } //_____________________________________________________________________________ -AliCDBStorage* AliCDBManager::GetSpecificStorage(const char* detName) { -// get storage specific for detector +AliCDBStorage* AliCDBManager::GetSpecificStorage(const char* calibType) { +// get storage specific for detector or calibration type - AliCDBParam *checkPar = (AliCDBParam*) fSpecificStorages.GetValue(detName); + AliCDBParam *checkPar = (AliCDBParam*) fSpecificStorages.GetValue(calibType); if(!checkPar){ - AliError(Form("%s storage not found!",detName)); + AliError(Form("%s storage not found!",calibType)); return NULL; } else { return GetStorage(checkPar); @@ -310,11 +313,36 @@ AliCDBStorage* AliCDBManager::GetSpecificStorage(const char* detName) { } +//_____________________________________________________________________________ +AliCDBParam* AliCDBManager::SelectSpecificStorage(const TString& path) { +// select storage valid for path from the list of specific storages + + TIter iter(&fSpecificStorages); + TObjString *aCalibType; + AliCDBParam* aPar=0; + while((aCalibType = (TObjString*) iter.Next())){ + if(path.Contains(aCalibType->String(), TString::kIgnoreCase)) { + aPar = (AliCDBParam*) fSpecificStorages.GetValue(aCalibType); + break; + } + } + return aPar; +} + //_____________________________________________________________________________ AliCDBEntry* AliCDBManager::Get(const AliCDBPath& path, Int_t runNumber, Int_t version, Int_t subVersion) { // get an AliCDBEntry object from the database + if(runNumber < 0){ + // RunNumber is not specified. Try with fRun + if (fRun < 0){ + AliError("Run number neither specified in query nor set in AliCDBManager! Use AliCDBManager::SetRun."); + return NULL; + } + runNumber = fRun; + } + return Get(AliCDBId(path, runNumber, runNumber, version, subVersion)); } @@ -342,17 +370,33 @@ AliCDBEntry* AliCDBManager::Get(const AliCDBId& query) { AliError(Form("Invalid query: %s", query.ToString().Data())); return NULL; } - - // query is not specified if path contains wildcard or runrange = [-1,-1] - if (!query.IsSpecified()) { + + // query is not specified if path contains wildcard or run range= [-1,-1] + if (!query.IsSpecified()) { AliError(Form("Unspecified query: %s", query.ToString().Data())); return NULL; } - TObjString objStrLev0(query.GetLevel0()); - AliCDBParam *aPar = (AliCDBParam*) fSpecificStorages.GetValue(&objStrLev0); - AliCDBStorage *aStorage; + if(fCache && query.GetFirstRun() != fRun) + AliWarning("Run number explicitly set in query: CDB cache temporarily disabled!"); + + + AliCDBEntry *entry=0; + + + // first look into map of cached objects + if(query.GetFirstRun() == fRun) + entry = (AliCDBEntry*) fEntryCache.GetValue(query.GetPath()); + + if(entry) { + AliInfo(Form("Object %s retrieved from cache !!",query.GetPath().Data())); + return entry; + } + + // Entry is not in cache -> retrieve it from CDB and cache it!! + AliCDBStorage *aStorage=0; + AliCDBParam *aPar=SelectSpecificStorage(query.GetPath()); if(aPar) { aStorage=GetStorage(aPar); @@ -364,7 +408,16 @@ AliCDBEntry* AliCDBManager::Get(const AliCDBId& query) { AliDebug(2,"Looking into default storage"); } - return aStorage->Get(query); + entry = aStorage->Get(query); + if (!entry) return NULL; + + if(fCache && (query.GetFirstRun() == fRun)){ + AliInfo(Form("Caching entry %s !",query.GetPath().Data())); + CacheEntry(query.GetPath(), entry); + } + + return entry; + } //_____________________________________________________________________________ @@ -387,6 +440,8 @@ TList* AliCDBManager::GetAll(const AliCDBPath& path, //_____________________________________________________________________________ TList* AliCDBManager::GetAll(const AliCDBId& query) { // get multiple AliCDBEntry objects from the database +// Warning: this method works correctly only for queries of the type "Detector/*" +// and not for more specific queries e.g. "Detector/Calib/*" ! if(!fDefaultStorage) { AliError("No storage set!"); @@ -411,8 +466,8 @@ TList* AliCDBManager::GetAll(const AliCDBId& query) { TObjString objStrLev0(query.GetLevel0()); AliCDBParam *aPar = (AliCDBParam*) fSpecificStorages.GetValue(&objStrLev0); - AliCDBStorage *aStorage; - + + AliCDBStorage *aStorage; if(aPar) { aStorage=GetStorage(aPar); TString str = aPar->GetURI(); @@ -465,8 +520,8 @@ Bool_t AliCDBManager::Put(AliCDBEntry* entry){ } AliCDBId id = entry->GetId(); - TObjString objStrLev0(id.GetLevel0()); - AliCDBParam *aPar = (AliCDBParam*) fSpecificStorages.GetValue(&objStrLev0); + AliCDBParam *aPar = SelectSpecificStorage(id.GetPath()); + AliCDBStorage *aStorage; if(aPar) { @@ -484,33 +539,6 @@ Bool_t AliCDBManager::Put(AliCDBEntry* entry){ } -//_____________________________________________________________________________ -AliCDBEntry* AliCDBManager::Get(const char* path) -{ -// get an AliCDBEntry object from the database, using fRun as run number - - if (fRun < 0) - { - AliError("Run number not set! Use AliCDBManager::SetRun."); - return 0; - } - - AliCDBEntry *entry; - - // first look into map of cached objects - entry = (AliCDBEntry*) fEntryCache.GetValue(path); - if(entry) return entry; - - // Entry is not in cache -> retrieve it from CDB and cache it!! - entry = Get(path, fRun); - if (!entry) return 0; - - if(fCache) CacheEntry(path, entry); - - return entry; - -} - //_____________________________________________________________________________ void AliCDBManager::CacheEntry(const char* path, AliCDBEntry* entry) { @@ -525,10 +553,8 @@ void AliCDBManager::CacheEntry(const char* path, AliCDBEntry* entry) //_____________________________________________________________________________ void AliCDBManager::SetRun(Long64_t run) { -// // Sets current run number. // When the run number changes the caching is cleared. -// if (fRun == run) return; diff --git a/STEER/AliCDBManager.h b/STEER/AliCDBManager.h index 3d341efeabc..4c9d208a189 100644 --- a/STEER/AliCDBManager.h +++ b/STEER/AliCDBManager.h @@ -46,10 +46,10 @@ class AliCDBManager: public TObject { AliCDBStorage* GetDefaultStorage() const {return fDefaultStorage;} void UnsetDefaultStorage() {fDefaultStorage = 0x0;} - void SetSpecificStorage(const char* detName, const char* dbString); - void SetSpecificStorage(const char* detName, AliCDBParam* param); + void SetSpecificStorage(const char* calibType, const char* dbString); + void SetSpecificStorage(const char* calibType, AliCDBParam* param); - AliCDBStorage* GetSpecificStorage(const char* detName); + AliCDBStorage* GetSpecificStorage(const char* calibType); void SetDrain(const char* dbString); void SetDrain(const AliCDBParam* param); @@ -62,13 +62,13 @@ class AliCDBManager: public TObject { void UnsetDrain(){fDrainStorage = 0x0;} AliCDBEntry* Get(const AliCDBId& query); - AliCDBEntry* Get(const AliCDBPath& path, Int_t runNumber, + AliCDBEntry* Get(const AliCDBPath& path, Int_t runNumber=-1, Int_t version = -1, Int_t subVersion = -1); AliCDBEntry* Get(const AliCDBPath& path, const AliCDBRunRange& runRange, Int_t version = -1, Int_t subVersion = -1); TList* GetAll(const AliCDBId& query); - TList* GetAll(const AliCDBPath& path, Int_t runNumber, + TList* GetAll(const AliCDBPath& path, Int_t runNumber=-1, Int_t version = -1, Int_t subVersion = -1); TList* GetAll(const AliCDBPath& path, const AliCDBRunRange& runRange, Int_t version = -1, Int_t subVersion = -1); @@ -82,7 +82,7 @@ class AliCDBManager: public TObject { void SetRun(Long64_t run); Long64_t GetRun() {return fRun;} - AliCDBEntry* Get(const char* path); + // AliCDBEntry* Get(const char* path); void DestroyActiveStorages(); void DestroyActiveStorage(AliCDBStorage* storage); @@ -103,6 +103,8 @@ class AliCDBManager: public TObject { void ClearCache(); void CacheEntry(const char* path, AliCDBEntry* entry); + AliCDBParam* SelectSpecificStorage(const TString& path); + void Init(); diff --git a/STEER/AliReconstruction.cxx b/STEER/AliReconstruction.cxx index 60c1b04c2f0..0595d5b9fca 100644 --- a/STEER/AliReconstruction.cxx +++ b/STEER/AliReconstruction.cxx @@ -147,7 +147,7 @@ ClassImp(AliReconstruction) const char* AliReconstruction::fgkDetectorName[AliReconstruction::fgkNDetectors] = {"ITS", "TPC", "TRD", "TOF", "PHOS", "RICH", "EMCAL", "MUON", "FMD", "ZDC", "PMD", "START", "VZERO", "CRT", "HLT"}; //_____________________________________________________________________________ -AliReconstruction::AliReconstruction(const char* gAliceFilename, +AliReconstruction::AliReconstruction(const char* gAliceFilename, const char* cdbUri, const char* name, const char* title) : TNamed(name, title), @@ -170,7 +170,8 @@ AliReconstruction::AliReconstruction(const char* gAliceFilename, fVertexer(NULL), - fWriteAlignmentData(kFALSE) + fWriteAlignmentData(kFALSE), + fCDBUri(cdbUri) { // create reconstruction object with default parameters @@ -209,7 +210,8 @@ AliReconstruction::AliReconstruction(const AliReconstruction& rec) : fVertexer(NULL), - fWriteAlignmentData(rec.fWriteAlignmentData) + fWriteAlignmentData(rec.fWriteAlignmentData), + fCDBUri(rec.fCDBUri) { // copy constructor @@ -242,6 +244,41 @@ AliReconstruction::~AliReconstruction() fOptions.Delete(); } +//_____________________________________________________________________________ +void AliReconstruction::InitCDBStorage() +{ +// activate a default CDB storage +// First check if we have any CDB storage set, because it is used +// to retrieve the calibration and alignment constants + + AliCDBManager* man = AliCDBManager::Instance(); + if (!man->IsDefaultStorageSet()) + { + AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); + AliWarning("Default CDB storage not yet set"); + AliWarning(Form("Using default storage declared in AliSimulation: %s",fCDBUri.Data())); + AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); + SetDefaultStorage(fCDBUri); + } + +} + +//_____________________________________________________________________________ +void AliReconstruction::SetDefaultStorage(const char* uri) { +// activate a default CDB storage + + AliCDBManager::Instance()->SetDefaultStorage(uri); + +} + +//_____________________________________________________________________________ +void AliReconstruction::SetSpecificStorage(const char* detName, const char* uri) { +// activate a detector-specific CDB storage + + AliCDBManager::Instance()->SetSpecificStorage(detName, uri); + +} + //_____________________________________________________________________________ void AliReconstruction::SetGAliceFile(const char* fileName) @@ -268,17 +305,7 @@ Bool_t AliReconstruction::Run(const char* input, { // run the reconstruction - // First check if we have any CDB storage set, because it is used - // to retrieve the calibration and alignment constants - - AliCDBManager* man = AliCDBManager::Instance(); - if (!man->IsDefaultStorageSet()) - { - AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); - AliWarning("No default CDB storage set, so I will use $ALICE_ROOT"); - AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); - man->SetDefaultStorage("local://$ALICE_ROOT"); - } + InitCDBStorage(); // set the input if (!input) input = fInput.Data(); diff --git a/STEER/AliReconstruction.h b/STEER/AliReconstruction.h index 157b1b83efc..8f39c79901b 100644 --- a/STEER/AliReconstruction.h +++ b/STEER/AliReconstruction.h @@ -39,6 +39,7 @@ class AliEventTag; class AliReconstruction: public TNamed { public: AliReconstruction(const char* gAliceFilename = "galice.root", + const char* cdbUri = "local://$ALICE_ROOT", const char* name = "AliReconstruction", const char* title = "reconstruction"); AliReconstruction(const AliReconstruction& rec); @@ -69,6 +70,11 @@ public: {fStopOnError = stopOnError;} void SetCheckPointLevel(Int_t checkPointLevel) {fCheckPointLevel = checkPointLevel;} + + // CDB storage activation + void InitCDBStorage(); + void SetDefaultStorage(const char* uri); + void SetSpecificStorage(const char* detName, const char* uri); virtual Bool_t Run(const char* input, Int_t firstEvent, Int_t lastEvent = -1); @@ -132,6 +138,8 @@ private: Bool_t fWriteAlignmentData; // write track space-points flag + TString fCDBUri; // Uri of the default CDB storage + ClassDef(AliReconstruction, 6) // class for running the reconstruction }; diff --git a/STEER/AliRun.cxx b/STEER/AliRun.cxx index ddd0042009a..3aec60032c0 100644 --- a/STEER/AliRun.cxx +++ b/STEER/AliRun.cxx @@ -960,7 +960,7 @@ void AliRun::AddModule(AliModule* mod) } //_____________________________________________________________________________ -Bool_t AliRun::ApplyAlignObjsToGeom(TClonesArray* AlObjArray) +Bool_t AliRun::ApplyAlignObjsToGeom(TObjArray* AlObjArray) { // Read collection of alignment objects (AliAlignObj derived) saved // in the TClonesArray ClArrayName and apply them to the geometry diff --git a/STEER/AliRun.h b/STEER/AliRun.h index b62c249375b..7989bba0757 100644 --- a/STEER/AliRun.h +++ b/STEER/AliRun.h @@ -141,7 +141,7 @@ public: // Method to introduce the detector misliagnment // It is called by AliSimulation - static Bool_t ApplyAlignObjsToGeom(TClonesArray* AlObjArray); + static Bool_t ApplyAlignObjsToGeom(TObjArray* AlObjArray); protected: virtual void Tree2Tree(Option_t *option, const char *detector=0); diff --git a/STEER/AliSimulation.cxx b/STEER/AliSimulation.cxx index eb4e0f7b858..7dd5f646b35 100644 --- a/STEER/AliSimulation.cxx +++ b/STEER/AliSimulation.cxx @@ -132,12 +132,14 @@ ClassImp(AliSimulation) //_____________________________________________________________________________ -AliSimulation::AliSimulation(const char* configFileName, +AliSimulation::AliSimulation(const char* configFileName, const char* cdbUri, const char* name, const char* title) : TNamed(name, title), fRunGeneration(kTRUE), fRunSimulation(kTRUE), + fLoadAlignFromCDB(kTRUE), + fLoadAlignData("ALL"), fMakeSDigits("ALL"), fMakeDigits("ALL"), fMakeTrigger(""), @@ -154,7 +156,8 @@ AliSimulation::AliSimulation(const char* configFileName, fBkgrdFileNames(NULL), fAlignObjArray(NULL), fUseBkgrdVertex(kTRUE), - fRegionOfInterest(kFALSE) + fRegionOfInterest(kFALSE), + fCDBUri(cdbUri) { // create simulation object with default parameters @@ -167,6 +170,8 @@ AliSimulation::AliSimulation(const AliSimulation& sim) : fRunGeneration(sim.fRunGeneration), fRunSimulation(sim.fRunSimulation), + fLoadAlignFromCDB(sim.fLoadAlignFromCDB), + fLoadAlignData(sim.fLoadAlignData), fMakeSDigits(sim.fMakeSDigits), fMakeDigits(sim.fMakeDigits), fMakeTrigger(sim.fMakeTrigger), @@ -183,7 +188,8 @@ AliSimulation::AliSimulation(const AliSimulation& sim) : fBkgrdFileNames(NULL), fAlignObjArray(NULL), fUseBkgrdVertex(sim.fUseBkgrdVertex), - fRegionOfInterest(sim.fRegionOfInterest) + fRegionOfInterest(sim.fRegionOfInterest), + fCDBUri(sim.fCDBUri) { // copy constructor @@ -215,6 +221,8 @@ AliSimulation::~AliSimulation() // clean up fEventsPerFile.Delete(); +// if(fAlignObjArray) fAlignObjArray->Delete(); // fAlignObjArray->RemoveAll() ??? +// delete fAlignObjArray; fAlignObjArray=0; if (fBkgrdFileNames) { fBkgrdFileNames->Delete(); @@ -231,6 +239,41 @@ void AliSimulation::SetNumberOfEvents(Int_t nEvents) fNEvents = nEvents; } +//_____________________________________________________________________________ +void AliSimulation::InitCDBStorage(const char* uri) +{ +// activate a default CDB storage +// First check if we have any CDB storage set, because it is used +// to retrieve the calibration and alignment constants + + AliCDBManager* man = AliCDBManager::Instance(); + if (!man->IsDefaultStorageSet()) + { + AliWarningClass("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); + AliWarningClass("Default CDB storage not yet set"); + AliWarningClass(Form("Using default storage declared in AliSimulation: %s",uri)); + AliWarningClass("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); + SetDefaultStorage(uri); + } + +} + +//_____________________________________________________________________________ +void AliSimulation::SetDefaultStorage(const char* uri) { +// activate a default CDB storage + + AliCDBManager::Instance()->SetDefaultStorage(uri); + +} + +//_____________________________________________________________________________ +void AliSimulation::SetSpecificStorage(const char* detName, const char* uri) { +// activate a detector-specific CDB storage + + AliCDBManager::Instance()->SetSpecificStorage(detName, uri); + +} + //_____________________________________________________________________________ void AliSimulation::SetConfigFile(const char* fileName) { @@ -326,6 +369,109 @@ Bool_t AliSimulation::ApplyAlignObjsToGeom(const char* uri, const char* path, In } +//_____________________________________________________________________________ +Bool_t AliSimulation::ApplyAlignObjsToGeom(const char* detName, Int_t runnum, Int_t version, Int_t sversion) +{ + // read collection of alignment objects (AliAlignObj derived) saved + // in the TClonesArray ClArrayName in the AliCDBEntry identified by + // param (to get the AliCDBStorage) and Id; apply the alignment objects + // to the TGeo geometry passed as argument + // + + InitCDBStorage("local://$ALICE_ROOT"); + AliCDBPath path(detName,"Align","Data"); + AliCDBEntry* entry = AliCDBManager::Instance()->Get(path.GetPath(),runnum,version,sversion); + + if(!entry) return kFALSE; + TClonesArray* AlObjArray = ((TClonesArray*) entry->GetObject()); + + return gAlice->ApplyAlignObjsToGeom(AlObjArray); +} + + +//_____________________________________________________________________________ +void AliSimulation::SetAlignObjArray(const char* detectors) +{ + // Fills array of detectors' alignable objects from CDB + // detectors can be "ALL" or "ITS TPC ..." + + AliRunLoader* runLoader = LoadRun(); + if (!runLoader) return; + + InitCDBStorage(fCDBUri); + + if(!fAlignObjArray) fAlignObjArray = new TObjArray(); + fAlignObjArray->SetOwner(0); // AliCDBEntry is owner of the align objects! + fAlignObjArray->Clear(); + + TString detStr = detectors; + TObjArray* detArray = runLoader->GetAliRun()->Detectors(); + TString dataNotLoaded=""; + TString dataLoaded=""; + + for (Int_t iDet = 0; iDet < detArray->GetEntriesFast(); iDet++) { + AliModule* det = (AliModule*) detArray->At(iDet); + if (!det || !det->IsActive()) continue; + if (IsSelected(det->GetName(), detStr)) { + + if(!SetAlignObjArraySingleDet(det->GetName())){ + dataNotLoaded += det->GetName(); + dataNotLoaded += " "; + } else { + dataLoaded += det->GetName(); + dataLoaded += " "; + } + } + } // end loop over all detectors + + if ((detStr.CompareTo("ALL") == 0)) detStr = ""; + dataNotLoaded += detStr; + AliInfo(Form("Alignment data loaded for: %s", + dataLoaded.Data())); + AliInfo(Form("Didn't/couldn't load alignment data for: %s", + dataNotLoaded.Data())); + + AliDebug(2, Form("fAlignObjArray entries: %d",fAlignObjArray->GetEntries() )); + delete detArray; + +} + +//_____________________________________________________________________________ +Bool_t AliSimulation::SetAlignObjArraySingleDet(const char* detName) +{ + // Fills array of single detector's alignable objects from CDB + + AliDebug(2, Form("Loading alignment data for detector: %s",detName)); + + AliCDBEntry *entry; + + AliCDBPath path(detName,"Align","Data"); + + entry=AliCDBManager::Instance()->Get(path.GetPath()); + if(!entry){ + AliDebug(2,Form("Couldn't load alignment data for detector %s",detName)); + return kFALSE; + } + entry->SetOwner(1); + TClonesArray *alignArray = (TClonesArray*) entry->GetObject(); + alignArray->SetOwner(0); + AliDebug(2,Form("Found %d alignment objects for %s", + alignArray->GetEntries(),detName)); + + AliAlignObj *alignObj=0; + TIter iter(alignArray); + + // loop over align objects in detector + while( ( alignObj=(AliAlignObj *) iter.Next() ) ){ + fAlignObjArray->Add(alignObj); + } + // delete entry --- Don't delete, it is cached! + + AliDebug(2, Form("fAlignObjArray entries: %d",fAlignObjArray->GetEntries() )); + return kTRUE; + +} + //_____________________________________________________________________________ void AliSimulation::MergeWith(const char* fileName, Int_t nSignalPerBkgrd) { @@ -343,17 +489,7 @@ Bool_t AliSimulation::Run(Int_t nEvents) { // run the generation, simulation and digitization - // First check if we have any CDB storage set, because it is used - // to retrieve the calibration and alignment constants - - AliCDBManager* man = AliCDBManager::Instance(); - if (!man->IsDefaultStorageSet()) - { - AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); - AliWarning("No default CDB storage set, so I will use $ALICE_ROOT"); - AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); - man->SetDefaultStorage("local://$ALICE_ROOT"); - } + InitCDBStorage(fCDBUri); if (nEvents > 0) fNEvents = nEvents; @@ -506,6 +642,54 @@ Bool_t AliSimulation::RunSimulation(Int_t nEvents) gAlice->Init(fConfigFileName.Data()); );); + // Set run number in CDBManager (here????) + AliCDBManager::Instance()->SetRun(gAlice->GetRunNumber()); + AliInfo(Form("Run number: %d",AliCDBManager::Instance()->GetRun())); + + AliRunLoader* runLoader = gAlice->GetRunLoader(); + if (!runLoader) { + AliError(Form("gAlice has no run loader object. " + "Check your config file: %s", fConfigFileName.Data())); + return kFALSE; + } + SetGAliceFile(runLoader->GetFileName()); + + // Load alignment data from CDB and fill fAlignObjArray + + if(fLoadAlignFromCDB){ + if(!fAlignObjArray) fAlignObjArray = new TObjArray(); + + //fAlignObjArray->RemoveAll(); + fAlignObjArray->Clear(); + fAlignObjArray->SetOwner(0); + + TString detStr = fLoadAlignData; + TString dataNotLoaded=""; + TString dataLoaded=""; + + TObjArray* detArray = runLoader->GetAliRun()->Detectors(); + for (Int_t iDet = 0; iDet < detArray->GetEntriesFast(); iDet++) { + AliModule* det = (AliModule*) detArray->At(iDet); + if (!det || !det->IsActive()) continue; + if (IsSelected(det->GetName(), detStr)) { + if(!SetAlignObjArraySingleDet(det->GetName())){ + dataNotLoaded += det->GetName(); + dataNotLoaded += " "; + } else { + dataLoaded += det->GetName(); + dataLoaded += " "; + } + } + } // end loop over detectors + + if ((detStr.CompareTo("ALL") == 0)) detStr = ""; + dataNotLoaded += detStr; + AliInfo(Form("Alignment data loaded for: %s", + dataLoaded.Data())); + AliInfo(Form("Didn't/couldn't load alignment data for: %s", + dataNotLoaded.Data())); + } // fLoadAlignFromCDB flag + // Check if the array with alignment objects was // provided by the user. If yes, apply the objects // to the present TGeo geometry @@ -525,13 +709,13 @@ Bool_t AliSimulation::RunSimulation(Int_t nEvents) // Export TGeo geometry if (gGeoManager) gGeoManager->Export("geometry.root"); - AliRunLoader* runLoader = gAlice->GetRunLoader(); - if (!runLoader) { - AliError(Form("gAlice has no run loader object. " - "Check your config file: %s", fConfigFileName.Data())); - return kFALSE; - } - SetGAliceFile(runLoader->GetFileName()); +// AliRunLoader* runLoader = gAlice->GetRunLoader(); +// if (!runLoader) { +// AliError(Form("gAlice has no run loader object. " +// "Check your config file: %s", fConfigFileName.Data())); +// return kFALSE; +// } +// SetGAliceFile(runLoader->GetFileName()); if (!gAlice->Generator()) { AliError(Form("gAlice has no generator object. " diff --git a/STEER/AliSimulation.h b/STEER/AliSimulation.h index 0a0f303242e..7804f4573ae 100644 --- a/STEER/AliSimulation.h +++ b/STEER/AliSimulation.h @@ -24,6 +24,7 @@ class AliRunLoader; class AliSimulation: public TNamed { public: AliSimulation(const char* configFileName = "Config.C", + const char* cdbUri = "local://$ALICE_ROOT", const char* name = "AliSimulation", const char* title = "generation, simulation and digitization"); AliSimulation(const AliSimulation& sim); @@ -38,6 +39,9 @@ public: void SetRunGeneration(Bool_t run) {fRunGeneration = run;}; void SetRunSimulation(Bool_t run) {fRunSimulation = run;}; + void SetLoadAlignFromCDB(Bool_t load) {fLoadAlignFromCDB = load;}; + void SetLoadAlignData(const char* detectors) + {fLoadAlignData = detectors;}; void SetMakeSDigits(const char* detectors) {fMakeSDigits = detectors;}; void MergeWith(const char* fileName, Int_t nSignalPerBkgrd = 0); @@ -63,8 +67,19 @@ public: static Bool_t ApplyAlignObjsToGeom(const char* uri, const char* path, Int_t runnum, Int_t version, Int_t sversion); - void SetAlignObjArray(TClonesArray *array) - {fAlignObjArray = array;} + static Bool_t ApplyAlignObjsToGeom(const char* detName, Int_t runnum, Int_t version, + Int_t sversion); + void SetAlignObjArray(TObjArray *array) + {fAlignObjArray = array; + fLoadAlignFromCDB = kFALSE;} + + void SetAlignObjArray(const char* detectors="ALL"); + Bool_t SetAlignObjArraySingleDet(const char* detName); + + // CDB storage activation + static void InitCDBStorage(const char *uri); + static void SetDefaultStorage(const char* uri); + static void SetSpecificStorage(const char* detName, const char* uri); virtual Bool_t Run(Int_t nEvents = 0); @@ -89,6 +104,8 @@ private: Bool_t fRunGeneration; // generate prim. particles or not Bool_t fRunSimulation; // simulate detectors (hits) or not + Bool_t fLoadAlignFromCDB; // Load alignment data from CDB and apply it to geometry or not + TString fLoadAlignData; // Load alignment data from CDB for these detectors TString fMakeSDigits; // create sdigits for these detectors TString fMakeDigits; // create digits for these detectors TString fMakeTrigger; // run trigger for these descriptors @@ -104,10 +121,12 @@ private: TObjArray fEventsPerFile; // number of events per file for given detectors and data types TObjArray* fBkgrdFileNames; // names of background files for merging - TClonesArray* fAlignObjArray; // array with the alignment objects to be applied to the geometry + TObjArray* fAlignObjArray; // array with the alignment objects to be applied to the geometry Bool_t fUseBkgrdVertex; // use vertex from background in case of merging Bool_t fRegionOfInterest; // digitization in region of interest + TString fCDBUri; // Uri of the default CDB storage + ClassDef(AliSimulation, 2) // class for running generation, simulation and digitization }; -- 2.39.3