1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
15 //-------------------------------------------------------------------------
16 // Implementation of AliCDBManager and AliCDBParam classe
17 // Author: Alberto Colla
18 // e-mail: Alberto.Colla@cern.ch
19 //-------------------------------------------------------------------------
21 #include "AliCDBManager.h"
22 #include "AliCDBStorage.h"
24 #include "AliCDBDump.h"
25 #include "AliCDBLocal.h"
26 #include "AliCDBGrid.h"
27 //#include "AliCDBEntry.h"
29 //#include <TObjString.h>
34 ClassImp(AliCDBManager)
36 AliCDBManager* AliCDBManager::fgInstance = 0x0;
38 //_____________________________________________________________________________
39 AliCDBManager* AliCDBManager::Instance() {
40 // returns AliCDBManager instance (singleton)
43 fgInstance = new AliCDBManager();
50 //_____________________________________________________________________________
51 void AliCDBManager::Init() {
52 // factory registering
54 RegisterFactory(new AliCDBDumpFactory());
55 RegisterFactory(new AliCDBLocalFactory());
56 // AliCDBGridFactory is registered only if AliEn libraries are enabled in Root
57 if(!gSystem->Exec("root-config --has-alien |grep yes 2>&1 > /dev/null")){ // returns 0 if yes
58 AliInfo("AliEn classes enabled in Root. AliCDBGrid factory registered.");
59 RegisterFactory(new AliCDBGridFactory());
62 //_____________________________________________________________________________
63 void AliCDBManager::Destroy() {
64 // delete ALCDBManager instance and active storages
72 //_____________________________________________________________________________
73 AliCDBManager::AliCDBManager():
74 fDefaultStorage(NULL),
78 fFactories.SetOwner();
81 //_____________________________________________________________________________
82 AliCDBManager::~AliCDBManager() {
84 DestroyActiveStorages();
86 fDefaultStorage = 0x0;
89 //_____________________________________________________________________________
90 AliCDBStorage* AliCDBManager::GetActiveStorage(const AliCDBParam* param) {
91 // get a storage object from the list of active storages
93 return (AliCDBStorage*) fActiveStorages.GetValue(param);
96 //_____________________________________________________________________________
97 void AliCDBManager::PutActiveStorage(AliCDBParam* param, AliCDBStorage* storage){
98 // put a storage object into the list of active storages
100 fActiveStorages.Add(param, storage);
101 AliDebug(1, Form("Active storages: %d", fActiveStorages.GetEntries()));
104 //_____________________________________________________________________________
105 void AliCDBManager::RegisterFactory(AliCDBStorageFactory* factory) {
106 // add a storage factory to the list of registerd factories
108 if (!fFactories.Contains(factory)) {
109 fFactories.Add(factory);
113 //_____________________________________________________________________________
114 Bool_t AliCDBManager::HasStorage(const char* dbString) const {
115 // check if dbString is a URI valid for one of the registered factories
117 TIter iter(&fFactories);
119 AliCDBStorageFactory* factory;
120 while ((factory = (AliCDBStorageFactory*) iter.Next())) {
122 if (factory->Validate(dbString)) {
130 //_____________________________________________________________________________
131 AliCDBParam* AliCDBManager::CreateParameter(const char* dbString) const {
132 // create AliCDBParam object from URI string
134 TIter iter(&fFactories);
136 AliCDBStorageFactory* factory;
137 while ((factory = (AliCDBStorageFactory*) iter.Next())) {
139 AliCDBParam* param = factory->CreateParameter(dbString);
148 //_____________________________________________________________________________
149 AliCDBStorage* AliCDBManager::GetStorage(const char* dbString) {
150 // get storage object from URI string
152 AliCDBParam* param = CreateParameter(dbString);
157 AliCDBStorage* aStorage = GetStorage(param);
164 //_____________________________________________________________________________
165 AliCDBStorage* AliCDBManager::GetStorage(const AliCDBParam* param) {
166 // get storage object from AliCDBParam object
168 // if the list of active storages already contains
169 // the requested storage, return it
170 AliCDBStorage* aStorage = GetActiveStorage(param);
175 TIter iter(&fFactories);
177 AliCDBStorageFactory* factory;
179 // loop on the list of registered factories
180 while ((factory = (AliCDBStorageFactory*) iter.Next())) {
182 // each factory tries to create its storage from the parameter
183 aStorage = factory->Create(param);
185 PutActiveStorage(param->CloneParam(), aStorage);
186 // if default storage is not set, set to this storage
187 if(!fDefaultStorage){
188 fDefaultStorage=aStorage;
189 AliInfo(Form("Default storage set to: %s",(param->GetURI()).Data()));
198 //_____________________________________________________________________________
199 TList* AliCDBManager::GetActiveStorages() {
200 // return list of active storages
202 TList* result = new TList();
204 TIter iter(fActiveStorages.GetTable());
206 while ((aPair = (TPair*) iter.Next())) {
207 result->Add(aPair->Value());
213 //_____________________________________________________________________________
214 void AliCDBManager::SetDrain(const char* dbString) {
215 // set drain storage from URI string
217 fDrainStorage = GetStorage(dbString);
220 //_____________________________________________________________________________
221 void AliCDBManager::SetDrain(const AliCDBParam* param) {
222 // set drain storage from AliCDBParam
224 fDrainStorage = GetStorage(param);
227 //_____________________________________________________________________________
228 void AliCDBManager::SetDrain(AliCDBStorage* storage) {
229 // set drain storage from another active storage
231 fDrainStorage = storage;
234 //_____________________________________________________________________________
235 Bool_t AliCDBManager::Drain(AliCDBEntry *entry) {
236 // drain retrieved object to drain storage
238 AliInfo("Draining into drain storage...");
239 return fDrainStorage->Put(entry);
242 //_____________________________________________________________________________
243 void AliCDBManager::SetDefaultStorage(const char* dbString) {
244 // sets default storage from URI string
246 fDefaultStorage = GetStorage(dbString);
249 //_____________________________________________________________________________
250 void AliCDBManager::SetDefaultStorage(const AliCDBParam* param) {
251 // set default storage from AliCDBParam object
253 fDrainStorage = GetStorage(param);
256 //_____________________________________________________________________________
257 void AliCDBManager::SetDefaultStorage(AliCDBStorage* storage) {
258 // set default storage from another active storage
260 fDefaultStorage = storage;
264 //_____________________________________________________________________________
265 void AliCDBManager::DestroyActiveStorages() {
266 // delete list of active storages
268 fActiveStorages.DeleteAll();
271 //_____________________________________________________________________________
272 void AliCDBManager::DestroyActiveStorage(AliCDBStorage* /*storage*/) {
273 // destroys active storage
276 TIter iter(fActiveStorages.GetTable());
278 while ((aPair = (TPair*) iter.Next())) {
279 if(storage == (AliCDBStorage*) aPair->Value())
280 delete fActiveStorages.Remove(aPair->Key());
281 storage->Delete(); storage=0x0;
287 ///////////////////////////////////////////////////////////
288 // AliCDBManager Parameter class //
289 // interface to specific AliCDBParameter class //
290 // (AliCDBGridParam, AliCDBLocalParam, AliCDBDumpParam) //
291 ///////////////////////////////////////////////////////////
293 AliCDBParam::AliCDBParam() {
298 //_____________________________________________________________________________
299 AliCDBParam::~AliCDBParam() {