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