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 **************************************************************************/
16 #include "AliCDBManager.h"
17 #include "AliCDBStorage.h"
19 #include "AliCDBDump.h"
20 #include "AliCDBLocal.h"
21 #include "AliCDBGrid.h"
23 #include <TObjString.h>
28 ClassImp(AliCDBManager)
30 AliCDBManager* AliCDBManager::fgInstance = 0x0;
32 //_____________________________________________________________________________
33 AliCDBManager* AliCDBManager::Instance() {
34 // returns AliCDBManager instance (singleton)
37 fgInstance = new AliCDBManager();
44 //_____________________________________________________________________________
45 void AliCDBManager::Init() {
46 // factory registering
48 RegisterFactory(new AliCDBDumpFactory());
49 RegisterFactory(new AliCDBLocalFactory());
50 // AliCDBGridFactory is registered only if AliEn libraries are enabled in Root
51 if(!gSystem->Exec("root-config --has-alien |grep yes 2>&1 > /dev/null")){ // returns 0 if yes
52 AliInfo("AliEn classes enabled in Root. AliCDBGrid factory registered.");
53 RegisterFactory(new AliCDBGridFactory());
56 //_____________________________________________________________________________
57 void AliCDBManager::Destroy() {
58 // delete ALCDBManager instance and active storages
66 //_____________________________________________________________________________
67 AliCDBManager::AliCDBManager():
68 fDefaultStorage(NULL),
72 fFactories.SetOwner();
75 //_____________________________________________________________________________
76 AliCDBManager::~AliCDBManager() {
78 DestroyActiveStorages();
81 //_____________________________________________________________________________
82 AliCDBStorage* AliCDBManager::GetActiveStorage(const AliCDBParam* param) {
83 // get a storage object from the list of active storages
85 return (AliCDBStorage*) fActiveStorages.GetValue(param);
88 //_____________________________________________________________________________
89 void AliCDBManager::PutActiveStorage(AliCDBParam* param, AliCDBStorage* storage){
90 // put a storage object into the list of active storages
92 fActiveStorages.Add(param, storage);
93 AliDebug(1, Form("Active storages: %d", fActiveStorages.GetEntries()));
96 //_____________________________________________________________________________
97 void AliCDBManager::RegisterFactory(AliCDBStorageFactory* factory) {
98 // add a storage factory to the list of registerd factories
100 if (!fFactories.Contains(factory)) {
101 fFactories.Add(factory);
105 //_____________________________________________________________________________
106 Bool_t AliCDBManager::HasStorage(const char* dbString) {
107 // check if dbString is a URI valid for one of the registered factories
109 TIter iter(&fFactories);
111 AliCDBStorageFactory* factory;
112 while ((factory = (AliCDBStorageFactory*) iter.Next())) {
114 if (factory->Validate(dbString)) {
122 //_____________________________________________________________________________
123 AliCDBParam* AliCDBManager::CreateParameter(const char* dbString) {
124 // create AliCDBParam object from URI string
126 TIter iter(&fFactories);
128 AliCDBStorageFactory* factory;
129 while ((factory = (AliCDBStorageFactory*) iter.Next())) {
131 AliCDBParam* param = factory->CreateParameter(dbString);
140 //_____________________________________________________________________________
141 AliCDBStorage* AliCDBManager::GetStorage(const char* dbString) {
142 // get storage object from URI string
144 AliCDBParam* param = CreateParameter(dbString);
149 AliCDBStorage* aStorage = GetStorage(param);
156 //_____________________________________________________________________________
157 AliCDBStorage* AliCDBManager::GetStorage(const AliCDBParam* param) {
158 // get storage object from AliCDBParam object
160 // if the list of active storages already contains
161 // the requested storage, return it
162 AliCDBStorage* aStorage = GetActiveStorage(param);
167 TIter iter(&fFactories);
169 AliCDBStorageFactory* factory;
171 // loop on the list of registered factories
172 while ((factory = (AliCDBStorageFactory*) iter.Next())) {
174 // each factory tries to create its storage from the parameter
175 aStorage = factory->Create(param);
177 PutActiveStorage(param->CloneParam(), aStorage);
178 // if default storage is not set, set to this storage
179 if(!fDefaultStorage){
180 fDefaultStorage=aStorage;
181 AliInfo(Form("Default storage set to: %s",(param->GetURI()).Data()));
190 //_____________________________________________________________________________
191 TList* AliCDBManager::GetActiveStorages() {
192 // return list of active storages
194 TList* result = new TList();
196 TIter iter(fActiveStorages.GetTable());
198 while ((aPair = (TPair*) iter.Next())) {
199 result->Add(aPair->Value());
205 //_____________________________________________________________________________
206 void AliCDBManager::SetDrain(const char* dbString) {
207 // set drain storage from URI string
209 fDrainStorage = GetStorage(dbString);
212 //_____________________________________________________________________________
213 void AliCDBManager::SetDrain(const AliCDBParam* param) {
214 // set drain storage from AliCDBParam
216 fDrainStorage = GetStorage(param);
219 //_____________________________________________________________________________
220 void AliCDBManager::SetDrain(AliCDBStorage* storage) {
221 // set drain storage from another active storage
223 fDrainStorage = storage;
226 //_____________________________________________________________________________
227 Bool_t AliCDBManager::Drain(AliCDBEntry *entry) {
228 // drain retrieved object to drain storage
230 AliInfo("Draining into drain storage...");
231 return fDrainStorage->Put(entry);
234 //_____________________________________________________________________________
235 void AliCDBManager::RemoveDrain() {
236 // remove drain storage
241 //_____________________________________________________________________________
242 void AliCDBManager::SetDefaultStorage(const char* dbString) {
243 // sets default storage from URI string
245 if(fDefaultStorage) fDefaultStorage = 0;
246 fDefaultStorage = GetStorage(dbString);
249 //_____________________________________________________________________________
250 void AliCDBManager::SetDefaultStorage(const AliCDBParam* param) {
251 // set default storage from AliCDBParam object
253 if(fDefaultStorage) fDefaultStorage = 0;
254 fDrainStorage = GetStorage(param);
257 //_____________________________________________________________________________
258 void AliCDBManager::SetDefaultStorage(AliCDBStorage* storage) {
259 // set default storage from another active storage
261 if(fDefaultStorage) fDefaultStorage = 0;
262 fDefaultStorage = storage;
265 //_____________________________________________________________________________
266 void AliCDBManager::RemoveDefaultStorage() {
267 // remove default storage
272 //_____________________________________________________________________________
273 void AliCDBManager::DestroyActiveStorages() {
274 // delete list of active storages
276 fActiveStorages.DeleteAll();
279 //_____________________________________________________________________________
280 void AliCDBManager::DestroyActiveStorage(AliCDBStorage* /*storage*/) {
281 // destroys active storage (not implemented)
285 ///////////////////////////////////////////////////////////
286 // AliCDBManager Parameter class //
287 // interface to specific AliCDBParameter class //
288 // (AliCDBGridParam, AliCDBLocalParam, AliCDBDumpParam) //
289 ///////////////////////////////////////////////////////////
291 AliCDBParam::AliCDBParam() {
296 //_____________________________________________________________________________
297 AliCDBParam::~AliCDBParam() {