]>
Commit | Line | Data |
---|---|---|
9e1ceb13 | 1 | /************************************************************************** |
2 | * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * | |
3 | * * | |
4 | * Author: The ALICE Off-line Project. * | |
5 | * Contributors are mentioned in the code where appropriate. * | |
6 | * * | |
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 | **************************************************************************/ | |
fdf65bb5 | 15 | //------------------------------------------------------------------------- |
16 | // Implementation of AliCDBManager and AliCDBParam classe | |
17 | // Author: Alberto Colla | |
18 | // e-mail: Alberto.Colla@cern.ch | |
19 | //------------------------------------------------------------------------- | |
9e1ceb13 | 20 | |
21 | #include "AliCDBManager.h" | |
22 | #include "AliCDBStorage.h" | |
23 | #include "AliLog.h" | |
24 | #include "AliCDBDump.h" | |
25 | #include "AliCDBLocal.h" | |
26 | #include "AliCDBGrid.h" | |
fdf65bb5 | 27 | //#include "AliCDBEntry.h" |
9e1ceb13 | 28 | |
fdf65bb5 | 29 | //#include <TObjString.h> |
9e1ceb13 | 30 | #include <TSystem.h> |
31 | ||
32 | ClassImp(AliCDBParam) | |
33 | ||
34 | ClassImp(AliCDBManager) | |
35 | ||
36 | AliCDBManager* AliCDBManager::fgInstance = 0x0; | |
37 | ||
38 | //_____________________________________________________________________________ | |
39 | AliCDBManager* AliCDBManager::Instance() { | |
40 | // returns AliCDBManager instance (singleton) | |
41 | ||
42 | if (!fgInstance) { | |
43 | fgInstance = new AliCDBManager(); | |
44 | fgInstance->Init(); | |
45 | } | |
46 | ||
47 | return fgInstance; | |
48 | } | |
49 | ||
50 | //_____________________________________________________________________________ | |
51 | void AliCDBManager::Init() { | |
52 | // factory registering | |
53 | ||
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()); | |
60 | } | |
61 | } | |
62 | //_____________________________________________________________________________ | |
63 | void AliCDBManager::Destroy() { | |
64 | // delete ALCDBManager instance and active storages | |
65 | ||
66 | if (fgInstance) { | |
67 | delete fgInstance; | |
68 | fgInstance = 0x0; | |
69 | } | |
70 | } | |
71 | ||
72 | //_____________________________________________________________________________ | |
73 | AliCDBManager::AliCDBManager(): | |
74 | fDefaultStorage(NULL), | |
75 | fDrainStorage(NULL) | |
76 | { | |
77 | // default constuctor | |
78 | fFactories.SetOwner(); | |
79 | } | |
80 | ||
81 | //_____________________________________________________________________________ | |
82 | AliCDBManager::~AliCDBManager() { | |
83 | // destructor | |
84 | DestroyActiveStorages(); | |
85 | } | |
86 | ||
87 | //_____________________________________________________________________________ | |
88 | AliCDBStorage* AliCDBManager::GetActiveStorage(const AliCDBParam* param) { | |
89 | // get a storage object from the list of active storages | |
90 | ||
91 | return (AliCDBStorage*) fActiveStorages.GetValue(param); | |
92 | } | |
93 | ||
94 | //_____________________________________________________________________________ | |
95 | void AliCDBManager::PutActiveStorage(AliCDBParam* param, AliCDBStorage* storage){ | |
96 | // put a storage object into the list of active storages | |
97 | ||
98 | fActiveStorages.Add(param, storage); | |
99 | AliDebug(1, Form("Active storages: %d", fActiveStorages.GetEntries())); | |
100 | } | |
101 | ||
102 | //_____________________________________________________________________________ | |
103 | void AliCDBManager::RegisterFactory(AliCDBStorageFactory* factory) { | |
104 | // add a storage factory to the list of registerd factories | |
105 | ||
106 | if (!fFactories.Contains(factory)) { | |
107 | fFactories.Add(factory); | |
108 | } | |
109 | } | |
110 | ||
111 | //_____________________________________________________________________________ | |
fdf65bb5 | 112 | Bool_t AliCDBManager::HasStorage(const char* dbString) const { |
9e1ceb13 | 113 | // check if dbString is a URI valid for one of the registered factories |
114 | ||
115 | TIter iter(&fFactories); | |
116 | ||
117 | AliCDBStorageFactory* factory; | |
118 | while ((factory = (AliCDBStorageFactory*) iter.Next())) { | |
119 | ||
120 | if (factory->Validate(dbString)) { | |
121 | return kTRUE; | |
122 | } | |
123 | } | |
124 | ||
125 | return kFALSE; | |
126 | } | |
127 | ||
128 | //_____________________________________________________________________________ | |
fdf65bb5 | 129 | AliCDBParam* AliCDBManager::CreateParameter(const char* dbString) const { |
9e1ceb13 | 130 | // create AliCDBParam object from URI string |
131 | ||
132 | TIter iter(&fFactories); | |
133 | ||
134 | AliCDBStorageFactory* factory; | |
135 | while ((factory = (AliCDBStorageFactory*) iter.Next())) { | |
136 | ||
137 | AliCDBParam* param = factory->CreateParameter(dbString); | |
138 | if (param) { | |
139 | return param; | |
140 | } | |
141 | } | |
142 | ||
143 | return NULL; | |
144 | } | |
145 | ||
146 | //_____________________________________________________________________________ | |
147 | AliCDBStorage* AliCDBManager::GetStorage(const char* dbString) { | |
148 | // get storage object from URI string | |
149 | ||
150 | AliCDBParam* param = CreateParameter(dbString); | |
151 | if (!param) { | |
152 | return NULL; | |
153 | } | |
154 | ||
155 | AliCDBStorage* aStorage = GetStorage(param); | |
156 | ||
157 | delete param; | |
158 | ||
159 | return aStorage; | |
160 | } | |
161 | ||
162 | //_____________________________________________________________________________ | |
163 | AliCDBStorage* AliCDBManager::GetStorage(const AliCDBParam* param) { | |
164 | // get storage object from AliCDBParam object | |
165 | ||
166 | // if the list of active storages already contains | |
167 | // the requested storage, return it | |
168 | AliCDBStorage* aStorage = GetActiveStorage(param); | |
169 | if (aStorage) { | |
170 | return aStorage; | |
171 | } | |
172 | ||
173 | TIter iter(&fFactories); | |
174 | ||
175 | AliCDBStorageFactory* factory; | |
176 | ||
177 | // loop on the list of registered factories | |
178 | while ((factory = (AliCDBStorageFactory*) iter.Next())) { | |
179 | ||
180 | // each factory tries to create its storage from the parameter | |
181 | aStorage = factory->Create(param); | |
182 | if (aStorage) { | |
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())); | |
188 | } | |
189 | return aStorage; | |
190 | } | |
191 | } | |
192 | ||
193 | return NULL; | |
194 | } | |
195 | ||
196 | //_____________________________________________________________________________ | |
197 | TList* AliCDBManager::GetActiveStorages() { | |
198 | // return list of active storages | |
199 | ||
200 | TList* result = new TList(); | |
201 | ||
202 | TIter iter(fActiveStorages.GetTable()); | |
203 | TPair* aPair; | |
204 | while ((aPair = (TPair*) iter.Next())) { | |
205 | result->Add(aPair->Value()); | |
206 | } | |
207 | ||
208 | return result; | |
209 | } | |
210 | ||
211 | //_____________________________________________________________________________ | |
212 | void AliCDBManager::SetDrain(const char* dbString) { | |
213 | // set drain storage from URI string | |
214 | ||
215 | fDrainStorage = GetStorage(dbString); | |
216 | } | |
217 | ||
218 | //_____________________________________________________________________________ | |
219 | void AliCDBManager::SetDrain(const AliCDBParam* param) { | |
220 | // set drain storage from AliCDBParam | |
221 | ||
222 | fDrainStorage = GetStorage(param); | |
223 | } | |
224 | ||
225 | //_____________________________________________________________________________ | |
226 | void AliCDBManager::SetDrain(AliCDBStorage* storage) { | |
227 | // set drain storage from another active storage | |
228 | ||
229 | fDrainStorage = storage; | |
230 | } | |
231 | ||
232 | //_____________________________________________________________________________ | |
233 | Bool_t AliCDBManager::Drain(AliCDBEntry *entry) { | |
234 | // drain retrieved object to drain storage | |
235 | ||
236 | AliInfo("Draining into drain storage..."); | |
237 | return fDrainStorage->Put(entry); | |
238 | } | |
239 | ||
240 | //_____________________________________________________________________________ | |
241 | void AliCDBManager::RemoveDrain() { | |
242 | // remove drain storage | |
243 | ||
244 | fDrainStorage=0; | |
245 | } | |
246 | ||
247 | //_____________________________________________________________________________ | |
248 | void AliCDBManager::SetDefaultStorage(const char* dbString) { | |
249 | // sets default storage from URI string | |
250 | ||
251 | if(fDefaultStorage) fDefaultStorage = 0; | |
252 | fDefaultStorage = GetStorage(dbString); | |
253 | } | |
254 | ||
255 | //_____________________________________________________________________________ | |
256 | void AliCDBManager::SetDefaultStorage(const AliCDBParam* param) { | |
257 | // set default storage from AliCDBParam object | |
258 | ||
259 | if(fDefaultStorage) fDefaultStorage = 0; | |
260 | fDrainStorage = GetStorage(param); | |
261 | } | |
262 | ||
263 | //_____________________________________________________________________________ | |
264 | void AliCDBManager::SetDefaultStorage(AliCDBStorage* storage) { | |
265 | // set default storage from another active storage | |
266 | ||
267 | if(fDefaultStorage) fDefaultStorage = 0; | |
268 | fDefaultStorage = storage; | |
269 | } | |
270 | ||
271 | //_____________________________________________________________________________ | |
272 | void AliCDBManager::RemoveDefaultStorage() { | |
273 | // remove default storage | |
274 | ||
275 | fDefaultStorage = 0; | |
276 | } | |
277 | ||
278 | //_____________________________________________________________________________ | |
279 | void AliCDBManager::DestroyActiveStorages() { | |
280 | // delete list of active storages | |
281 | ||
282 | fActiveStorages.DeleteAll(); | |
283 | } | |
284 | ||
285 | //_____________________________________________________________________________ | |
286 | void AliCDBManager::DestroyActiveStorage(AliCDBStorage* /*storage*/) { | |
287 | // destroys active storage (not implemented) | |
288 | ||
289 | } | |
290 | ||
291 | /////////////////////////////////////////////////////////// | |
292 | // AliCDBManager Parameter class // | |
293 | // interface to specific AliCDBParameter class // | |
294 | // (AliCDBGridParam, AliCDBLocalParam, AliCDBDumpParam) // | |
295 | /////////////////////////////////////////////////////////// | |
296 | ||
297 | AliCDBParam::AliCDBParam() { | |
298 | // constructor | |
299 | ||
300 | } | |
301 | ||
302 | //_____________________________________________________________________________ | |
303 | AliCDBParam::~AliCDBParam() { | |
304 | // destructor | |
305 | ||
306 | } | |
307 |