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();
87 //_____________________________________________________________________________
88 AliCDBStorage* AliCDBManager::GetActiveStorage(const AliCDBParam* param) {
89 // get a storage object from the list of active storages
91 return (AliCDBStorage*) fActiveStorages.GetValue(param);
94 //_____________________________________________________________________________
95 void AliCDBManager::PutActiveStorage(AliCDBParam* param, AliCDBStorage* storage){
96 // put a storage object into the list of active storages
98 fActiveStorages.Add(param, storage);
99 AliDebug(1, Form("Active storages: %d", fActiveStorages.GetEntries()));
102 //_____________________________________________________________________________
103 void AliCDBManager::RegisterFactory(AliCDBStorageFactory* factory) {
104 // add a storage factory to the list of registerd factories
106 if (!fFactories.Contains(factory)) {
107 fFactories.Add(factory);
111 //_____________________________________________________________________________
112 Bool_t AliCDBManager::HasStorage(const char* dbString) const {
113 // check if dbString is a URI valid for one of the registered factories
115 TIter iter(&fFactories);
117 AliCDBStorageFactory* factory;
118 while ((factory = (AliCDBStorageFactory*) iter.Next())) {
120 if (factory->Validate(dbString)) {
128 //_____________________________________________________________________________
129 AliCDBParam* AliCDBManager::CreateParameter(const char* dbString) const {
130 // create AliCDBParam object from URI string
132 TIter iter(&fFactories);
134 AliCDBStorageFactory* factory;
135 while ((factory = (AliCDBStorageFactory*) iter.Next())) {
137 AliCDBParam* param = factory->CreateParameter(dbString);
146 //_____________________________________________________________________________
147 AliCDBStorage* AliCDBManager::GetStorage(const char* dbString) {
148 // get storage object from URI string
150 AliCDBParam* param = CreateParameter(dbString);
155 AliCDBStorage* aStorage = GetStorage(param);
162 //_____________________________________________________________________________
163 AliCDBStorage* AliCDBManager::GetStorage(const AliCDBParam* param) {
164 // get storage object from AliCDBParam object
166 // if the list of active storages already contains
167 // the requested storage, return it
168 AliCDBStorage* aStorage = GetActiveStorage(param);
173 TIter iter(&fFactories);
175 AliCDBStorageFactory* factory;
177 // loop on the list of registered factories
178 while ((factory = (AliCDBStorageFactory*) iter.Next())) {
180 // each factory tries to create its storage from the parameter
181 aStorage = factory->Create(param);
183 PutActiveStorage(param->CloneParam(), aStorage);
184 // if default storage is not set, set to this storage
185 if(!fDefaultStorage){
186 fDefaultStorage=aStorage;
187 AliInfo(Form("Default storage set to: %s",(param->GetURI()).Data()));
196 //_____________________________________________________________________________
197 TList* AliCDBManager::GetActiveStorages() {
198 // return list of active storages
200 TList* result = new TList();
202 TIter iter(fActiveStorages.GetTable());
204 while ((aPair = (TPair*) iter.Next())) {
205 result->Add(aPair->Value());
211 //_____________________________________________________________________________
212 void AliCDBManager::SetDrain(const char* dbString) {
213 // set drain storage from URI string
215 fDrainStorage = GetStorage(dbString);
218 //_____________________________________________________________________________
219 void AliCDBManager::SetDrain(const AliCDBParam* param) {
220 // set drain storage from AliCDBParam
222 fDrainStorage = GetStorage(param);
225 //_____________________________________________________________________________
226 void AliCDBManager::SetDrain(AliCDBStorage* storage) {
227 // set drain storage from another active storage
229 fDrainStorage = storage;
232 //_____________________________________________________________________________
233 Bool_t AliCDBManager::Drain(AliCDBEntry *entry) {
234 // drain retrieved object to drain storage
236 AliInfo("Draining into drain storage...");
237 return fDrainStorage->Put(entry);
240 //_____________________________________________________________________________
241 void AliCDBManager::RemoveDrain() {
242 // remove drain storage
247 //_____________________________________________________________________________
248 void AliCDBManager::SetDefaultStorage(const char* dbString) {
249 // sets default storage from URI string
251 if(fDefaultStorage) fDefaultStorage = 0;
252 fDefaultStorage = GetStorage(dbString);
255 //_____________________________________________________________________________
256 void AliCDBManager::SetDefaultStorage(const AliCDBParam* param) {
257 // set default storage from AliCDBParam object
259 if(fDefaultStorage) fDefaultStorage = 0;
260 fDrainStorage = GetStorage(param);
263 //_____________________________________________________________________________
264 void AliCDBManager::SetDefaultStorage(AliCDBStorage* storage) {
265 // set default storage from another active storage
267 if(fDefaultStorage) fDefaultStorage = 0;
268 fDefaultStorage = storage;
271 //_____________________________________________________________________________
272 void AliCDBManager::RemoveDefaultStorage() {
273 // remove default storage
278 //_____________________________________________________________________________
279 void AliCDBManager::DestroyActiveStorages() {
280 // delete list of active storages
282 fActiveStorages.DeleteAll();
285 //_____________________________________________________________________________
286 void AliCDBManager::DestroyActiveStorage(AliCDBStorage* /*storage*/) {
287 // destroys active storage (not implemented)
291 ///////////////////////////////////////////////////////////
292 // AliCDBManager Parameter class //
293 // interface to specific AliCDBParameter class //
294 // (AliCDBGridParam, AliCDBLocalParam, AliCDBDumpParam) //
295 ///////////////////////////////////////////////////////////
297 AliCDBParam::AliCDBParam() {
302 //_____________________________________________________________________________
303 AliCDBParam::~AliCDBParam() {