]>
Commit | Line | Data |
---|---|---|
2c8628dd | 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 | ||
b05400be | 16 | #include <TKey.h> |
02c4845e | 17 | #include <TH1.h> |
145f45a2 | 18 | #include <TTree.h> |
19 | #include <TFile.h> | |
fe913d8f | 20 | #include "AliCDBStorage.h" |
b8ec52f6 | 21 | #include "AliCDBGrid.h" |
2c8628dd | 22 | |
9e1ceb13 | 23 | #include "AliCDBEntry.h" |
24 | #include "AliLog.h" | |
2c8628dd | 25 | |
fe913d8f | 26 | ClassImp(AliCDBStorage) |
2c8628dd | 27 | |
9e1ceb13 | 28 | //_____________________________________________________________________________ |
62032124 | 29 | AliCDBStorage::AliCDBStorage(): |
30 | fValidFileIds(), | |
31 | fRun(-1), | |
32 | fPathFilter(), | |
33 | fVersion(-1), | |
34 | fMetaDataFilter(0), | |
35 | fSelections(), | |
36 | fURI(), | |
37 | fType(), | |
38 | fBaseFolder() | |
39 | { | |
9e1ceb13 | 40 | // constructor |
41 | ||
62032124 | 42 | fValidFileIds.SetOwner(1); |
9e1ceb13 | 43 | fSelections.SetOwner(1); |
44 | } | |
2c8628dd | 45 | |
9e1ceb13 | 46 | //_____________________________________________________________________________ |
47 | AliCDBStorage::~AliCDBStorage() { | |
48 | // destructor | |
2c8628dd | 49 | |
62032124 | 50 | RemoveAllSelections(); |
51 | fValidFileIds.Clear(); | |
52 | delete fMetaDataFilter; | |
53 | ||
9e1ceb13 | 54 | } |
2c8628dd | 55 | |
56 | //_____________________________________________________________________________ | |
4b5e0dce | 57 | void AliCDBStorage::GetSelection(/*const*/ AliCDBId* id) { |
0f678e35 | 58 | // return required version and subversion from the list of selection criteria |
9e1ceb13 | 59 | |
60 | TIter iter(&fSelections); | |
61 | AliCDBId* aSelection; | |
62 | ||
63 | // loop on the list of selection criteria | |
64 | while ((aSelection = (AliCDBId*) iter.Next())) { | |
65 | // check if selection element contains id's path and run (range) | |
4b5e0dce | 66 | if (aSelection->Comprises(*id)) { |
b05400be | 67 | AliDebug(2,Form("Using selection criterion: %s ", aSelection->ToString().Data())); |
9e1ceb13 | 68 | // return required version and subversion |
4b5e0dce | 69 | |
70 | id->SetVersion(aSelection->GetVersion()); | |
71 | id->SetSubVersion(aSelection->GetSubVersion()); | |
72 | return; | |
9e1ceb13 | 73 | } |
74 | } | |
75 | ||
76 | // no valid element is found in the list of selection criteria -> return | |
b05400be | 77 | AliDebug(2,"Looking for objects with most recent version"); |
4b5e0dce | 78 | return; |
2c8628dd | 79 | } |
80 | ||
b05400be | 81 | //_____________________________________________________________________________ |
82 | void AliCDBStorage::ReadSelectionFromFile(const char *fileName){ | |
83 | // read selection criteria list from file | |
84 | ||
85 | RemoveAllSelections(); | |
86 | ||
87 | TList *list = GetIdListFromFile(fileName); | |
88 | if(!list) return; | |
89 | ||
90 | list->SetOwner(); | |
91 | Int_t nId = list->GetEntries(); | |
92 | AliCDBId *id; | |
93 | TKey *key; | |
94 | ||
95 | for(int i=nId-1;i>=0;i--){ | |
96 | key = (TKey*) list->At(i); | |
97 | id = (AliCDBId*) key->ReadObj(); | |
98 | if(id) AddSelection(*id); | |
99 | } | |
100 | delete list; | |
101 | AliInfo(Form("Selection criteria list filled with %d entries",fSelections.GetEntries())); | |
102 | PrintSelectionList(); | |
103 | ||
104 | } | |
105 | ||
2c8628dd | 106 | //_____________________________________________________________________________ |
9e1ceb13 | 107 | void AliCDBStorage::AddSelection(const AliCDBId& selection) { |
108 | // add a selection criterion | |
109 | ||
110 | AliCDBPath path = selection.GetPath(); | |
111 | if(!path.IsValid()) return; | |
112 | ||
113 | TIter iter(&fSelections); | |
114 | const AliCDBId *anId; | |
115 | while((anId = (AliCDBId*) iter.Next())){ | |
116 | if(selection.Comprises(*anId)){ | |
117 | AliWarning("This selection is more general than a previous one and will hide it!"); | |
118 | AliWarning(Form("%s", (anId->ToString()).Data())); | |
119 | fSelections.AddBefore(anId, new AliCDBId(selection)); | |
120 | return; | |
121 | } | |
122 | ||
123 | } | |
124 | fSelections.AddFirst(new AliCDBId(selection)); | |
125 | } | |
2c8628dd | 126 | |
127 | //_____________________________________________________________________________ | |
62032124 | 128 | void AliCDBStorage::AddSelection(const AliCDBPath& path, |
9e1ceb13 | 129 | const AliCDBRunRange& runRange, Int_t version, Int_t subVersion){ |
130 | // add a selection criterion | |
2c8628dd | 131 | |
9e1ceb13 | 132 | AddSelection(AliCDBId(path, runRange, version, subVersion)); |
2c8628dd | 133 | } |
134 | ||
9e1ceb13 | 135 | //_____________________________________________________________________________ |
136 | void AliCDBStorage::AddSelection(const AliCDBPath& path, | |
137 | Int_t firstRun, Int_t lastRun, Int_t version, Int_t subVersion){ | |
138 | // add a selection criterion | |
139 | ||
140 | AddSelection(AliCDBId(path, firstRun, lastRun, version, subVersion)); | |
141 | } | |
2c8628dd | 142 | |
9e1ceb13 | 143 | //_____________________________________________________________________________ |
144 | void AliCDBStorage::RemoveSelection(const AliCDBId& selection) { | |
145 | // remove a selection criterion | |
2c8628dd | 146 | |
9e1ceb13 | 147 | TIter iter(&fSelections); |
148 | AliCDBId* aSelection; | |
2c8628dd | 149 | |
9e1ceb13 | 150 | while ((aSelection = (AliCDBId*) iter.Next())) { |
151 | if (selection.Comprises(*aSelection)) { | |
152 | fSelections.Remove(aSelection); | |
153 | } | |
154 | } | |
155 | } | |
2c8628dd | 156 | |
9e1ceb13 | 157 | //_____________________________________________________________________________ |
158 | void AliCDBStorage::RemoveSelection(const AliCDBPath& path, | |
159 | const AliCDBRunRange& runRange){ | |
160 | // remove a selection criterion | |
2c8628dd | 161 | |
9e1ceb13 | 162 | RemoveSelection(AliCDBId(path, runRange, -1, -1)); |
163 | } | |
f05209ee | 164 | |
9e1ceb13 | 165 | //_____________________________________________________________________________ |
166 | void AliCDBStorage::RemoveSelection(const AliCDBPath& path, | |
167 | Int_t firstRun, Int_t lastRun){ | |
168 | // remove a selection criterion | |
f05209ee | 169 | |
9e1ceb13 | 170 | RemoveSelection(AliCDBId(path, firstRun, lastRun, -1, -1)); |
171 | } | |
f05209ee | 172 | |
9e1ceb13 | 173 | //_____________________________________________________________________________ |
eb0b1051 | 174 | void AliCDBStorage::RemoveSelection(int position){ |
9e1ceb13 | 175 | // remove a selection criterion from its position in the list |
2c8628dd | 176 | |
62032124 | 177 | delete fSelections.RemoveAt(position); |
2c8628dd | 178 | } |
179 | ||
2c8628dd | 180 | //_____________________________________________________________________________ |
9e1ceb13 | 181 | void AliCDBStorage::RemoveAllSelections(){ |
182 | // remove all selection criteria | |
2c8628dd | 183 | |
62032124 | 184 | fSelections.Clear(); |
9e1ceb13 | 185 | } |
fe913d8f | 186 | |
9e1ceb13 | 187 | //_____________________________________________________________________________ |
188 | void AliCDBStorage::PrintSelectionList(){ | |
189 | // prints the list of selection criteria | |
190 | ||
191 | TIter iter(&fSelections); | |
192 | AliCDBId* aSelection; | |
62032124 | 193 | |
9e1ceb13 | 194 | // loop on the list of selection criteria |
195 | int index=0; | |
196 | while ((aSelection = (AliCDBId*) iter.Next())) { | |
197 | AliInfo(Form("index %d -> selection: %s",index++, aSelection->ToString().Data())); | |
198 | } | |
fe913d8f | 199 | |
9e1ceb13 | 200 | } |
fe913d8f | 201 | |
9e1ceb13 | 202 | //_____________________________________________________________________________ |
0f678e35 | 203 | AliCDBEntry* AliCDBStorage::Get(const AliCDBId& query) { |
9e1ceb13 | 204 | // get an AliCDBEntry object from the database |
205 | ||
206 | // check if query's path and runRange are valid | |
207 | // query is invalid also if version is not specified and subversion is! | |
208 | if (!query.IsValid()) { | |
209 | AliError(Form("Invalid query: %s", query.ToString().Data())); | |
210 | return NULL; | |
211 | } | |
212 | ||
213 | // query is not specified if path contains wildcard or runrange = [-1,-1] | |
214 | if (!query.IsSpecified()) { | |
215 | AliError(Form("Unspecified query: %s", | |
216 | query.ToString().Data())); | |
217 | return NULL; | |
218 | } | |
62032124 | 219 | |
02c4845e | 220 | // This is needed otherwise TH1 objects (histos, TTree's) are lost when file is closed! |
221 | Bool_t oldStatus = TH1::AddDirectoryStatus(); | |
222 | TH1::AddDirectory(kFALSE); | |
9e1ceb13 | 223 | |
224 | AliCDBEntry* entry = GetEntry(query); | |
02c4845e | 225 | |
226 | if (oldStatus != kFALSE) | |
227 | TH1::AddDirectory(kTRUE); | |
0f678e35 | 228 | |
9e1ceb13 | 229 | if (entry) { |
62032124 | 230 | // this is to make the SHUTTLE output lighter |
231 | if(!(query.GetPath().Contains("SHUTTLE/STATUS"))) | |
b8ec52f6 | 232 | AliDebug(2, Form("CDB object retrieved: %s", entry->GetId().ToString().Data())); |
9e1ceb13 | 233 | } else { |
62032124 | 234 | // this is to make the SHUTTLE output lighter |
0f678e35 | 235 | if(!(query.GetPath().Contains("SHUTTLE/STATUS"))) |
c3a7b59a | 236 | AliInfo(Form("No valid CDB object found! request was: %s", query.ToString().Data())); |
9e1ceb13 | 237 | } |
0f678e35 | 238 | |
9e1ceb13 | 239 | // if drain storage is set, drain entry into drain storage |
240 | if(entry && (AliCDBManager::Instance())->IsDrainSet()) | |
241 | AliCDBManager::Instance()->Drain(entry); | |
0f678e35 | 242 | |
9e1ceb13 | 243 | return entry; |
2c8628dd | 244 | } |
245 | ||
246 | //_____________________________________________________________________________ | |
9e1ceb13 | 247 | AliCDBEntry* AliCDBStorage::Get(const AliCDBPath& path, Int_t runNumber, |
248 | Int_t version, Int_t subVersion) { | |
249 | // get an AliCDBEntry object from the database | |
2c8628dd | 250 | |
9e1ceb13 | 251 | return Get(AliCDBId(path, runNumber, runNumber, version, subVersion)); |
2c8628dd | 252 | } |
253 | ||
2c8628dd | 254 | //_____________________________________________________________________________ |
9e1ceb13 | 255 | AliCDBEntry* AliCDBStorage::Get(const AliCDBPath& path, |
256 | const AliCDBRunRange& runRange, Int_t version, | |
257 | Int_t subVersion) { | |
258 | // get an AliCDBEntry object from the database | |
2c8628dd | 259 | |
9e1ceb13 | 260 | return Get(AliCDBId(path, runRange, version, subVersion)); |
2c8628dd | 261 | } |
262 | ||
2c8628dd | 263 | //_____________________________________________________________________________ |
9e1ceb13 | 264 | TList* AliCDBStorage::GetAll(const AliCDBId& query) { |
265 | // get multiple AliCDBEntry objects from the database | |
266 | ||
267 | ||
268 | if (!query.IsValid()) { | |
269 | AliError(Form("Invalid query: %s", query.ToString().Data())); | |
270 | return NULL; | |
271 | } | |
272 | ||
273 | if (query.IsAnyRange()) { | |
274 | AliError(Form("Unspecified run or runrange: %s", | |
275 | query.ToString().Data())); | |
276 | return NULL; | |
277 | } | |
278 | ||
02c4845e | 279 | // This is needed otherwise TH1 objects (histos, TTree's) are lost when file is closed! |
280 | Bool_t oldStatus = TH1::AddDirectoryStatus(); | |
281 | TH1::AddDirectory(kFALSE); | |
282 | ||
9e1ceb13 | 283 | TList *result = GetEntries(query); |
284 | ||
02c4845e | 285 | if (oldStatus != kFALSE) |
286 | TH1::AddDirectory(kTRUE); | |
287 | ||
9e1ceb13 | 288 | Int_t nEntries = result->GetEntries(); |
b8ec52f6 | 289 | |
290 | AliInfo(Form("%d objects retrieved. Request was: %s", | |
291 | nEntries, query.ToString().Data())); | |
292 | for(int i=0; i<nEntries;i++){ | |
293 | AliCDBEntry *entry = (AliCDBEntry*) result->At(i); | |
294 | AliInfo(Form("%s",entry->GetId().ToString().Data())); | |
9e1ceb13 | 295 | } |
296 | ||
b8ec52f6 | 297 | |
9e1ceb13 | 298 | // if drain storage is set, drain entries into drain storage |
299 | if((AliCDBManager::Instance())->IsDrainSet()){ | |
300 | for(int i = 0; i<result->GetEntries(); i++){ | |
301 | AliCDBEntry* entry = (AliCDBEntry*) result->At(i); | |
302 | AliCDBManager::Instance()->Drain(entry); | |
303 | } | |
304 | } | |
305 | ||
306 | ||
307 | return result; | |
308 | } | |
2c8628dd | 309 | |
9e1ceb13 | 310 | //_____________________________________________________________________________ |
311 | TList* AliCDBStorage::GetAll(const AliCDBPath& path, Int_t runNumber, | |
312 | Int_t version, Int_t subVersion) { | |
313 | // get multiple AliCDBEntry objects from the database | |
2c8628dd | 314 | |
9e1ceb13 | 315 | return GetAll(AliCDBId(path, runNumber, runNumber, version, |
316 | subVersion)); | |
2c8628dd | 317 | } |
318 | ||
2c8628dd | 319 | //_____________________________________________________________________________ |
9e1ceb13 | 320 | TList* AliCDBStorage::GetAll(const AliCDBPath& path, |
321 | const AliCDBRunRange& runRange, Int_t version, Int_t subVersion) { | |
322 | // get multiple AliCDBEntry objects from the database | |
2c8628dd | 323 | |
9e1ceb13 | 324 | return GetAll(AliCDBId(path, runRange, version, subVersion)); |
2c8628dd | 325 | } |
f05209ee | 326 | |
327 | ||
328 | //_____________________________________________________________________________ | |
b8ec52f6 | 329 | Bool_t AliCDBStorage::Put(TObject* object, AliCDBId& id, AliCDBMetaData* metaData, AliCDBManager::DataType type) { |
02c4845e | 330 | // store an AliCDBEntry object into the database |
9e1ceb13 | 331 | |
332 | AliCDBEntry anEntry(object, id, metaData); | |
f05209ee | 333 | |
b8ec52f6 | 334 | return Put(&anEntry, type); |
335 | } | |
f05209ee | 336 | |
9e1ceb13 | 337 | //_____________________________________________________________________________ |
b8ec52f6 | 338 | Bool_t AliCDBStorage::Put(AliCDBEntry* entry, AliCDBManager::DataType type) { |
02c4845e | 339 | // store an AliCDBEntry object into the database |
9e1ceb13 | 340 | |
02c4845e | 341 | if (!entry){ |
342 | AliError("No entry!"); | |
343 | return kFALSE; | |
344 | } | |
345 | ||
9e1ceb13 | 346 | if (!entry->GetId().IsValid()) { |
62032124 | 347 | AliError(Form("Invalid entry ID: %s", |
9e1ceb13 | 348 | entry->GetId().ToString().Data())); |
349 | return kFALSE; | |
350 | } | |
351 | ||
352 | if (!entry->GetId().IsSpecified()) { | |
62032124 | 353 | AliError(Form("Unspecified entry ID: %s", |
9e1ceb13 | 354 | entry->GetId().ToString().Data())); |
355 | return kFALSE; | |
356 | } | |
357 | ||
b8ec52f6 | 358 | AliCDBManager::DataType expectedType = GetDataType(); |
359 | ||
360 | if(expectedType != AliCDBManager::kPrivate && type != expectedType) { | |
361 | AliError(Form("It is forbidden to store %s data into a folder of type %s!", | |
362 | AliCDBManager::GetDataTypeName(type), | |
363 | AliCDBManager::GetDataTypeName(expectedType))); | |
364 | return 0; | |
365 | } | |
366 | ||
02c4845e | 367 | // set object's class name into metaData! |
368 | entry->GetMetaData()->SetObjectClassName(entry->GetObject()->ClassName()); | |
369 | ||
9e1ceb13 | 370 | return PutEntry(entry); |
f05209ee | 371 | } |
fe913d8f | 372 | |
62032124 | 373 | //_____________________________________________________________________________ |
c3a7b59a | 374 | void AliCDBStorage::QueryCDB(Int_t run, const char* pathFilter, |
62032124 | 375 | Int_t version, AliCDBMetaData* md){ |
376 | // query CDB for files valid for given run, and fill list fValidFileIds | |
377 | // Actual query is done in virtual function QueryValidFiles() | |
378 | ||
379 | fRun = run; | |
380 | ||
381 | fPathFilter = pathFilter; | |
382 | if(!fPathFilter.IsValid()) { | |
383 | AliError(Form("Filter not valid: %s", pathFilter)); | |
384 | fPathFilter = "*"; | |
385 | return; | |
386 | } | |
387 | ||
388 | fVersion = version; | |
389 | ||
6dc56e97 | 390 | AliInfo(Form("Querying files valid for run %d and path \"%s\" into CDB storage \"%s://%s\"", |
391 | fRun, pathFilter, fType.Data(), fBaseFolder.Data())); | |
392 | ||
62032124 | 393 | // Clear fValidFileIds list (it cannot be filled twice! |
394 | AliDebug(2, "Clearing list of CDB Id's previously loaded"); | |
395 | fValidFileIds.Clear(); | |
396 | ||
397 | if(fMetaDataFilter) {delete fMetaDataFilter; fMetaDataFilter=0;} | |
398 | if(md) fMetaDataFilter = dynamic_cast<AliCDBMetaData*> (md->Clone()); | |
399 | ||
400 | QueryValidFiles(); | |
c3a7b59a | 401 | AliCDBId queryId(pathFilter,run,run,version); |
62032124 | 402 | |
6dc56e97 | 403 | AliInfo(Form("%d valid files found!", fValidFileIds.GetEntriesFast())); |
62032124 | 404 | |
405 | } | |
406 | ||
407 | //_____________________________________________________________________________ | |
408 | void AliCDBStorage::PrintQueryCDB(){ | |
409 | // print parameters used to load list of CDB Id's (fRun, fPathFilter, fVersion) | |
410 | ||
c3a7b59a | 411 | AliCDBId paramId(fPathFilter, fRun, fRun, fVersion); |
412 | AliInfo(Form("**** QueryCDB Parameters **** \n\t<%s>\n", | |
413 | paramId.ToString().Data())); | |
414 | ||
415 | if(fMetaDataFilter) fMetaDataFilter->PrintMetaData(); | |
62032124 | 416 | |
62032124 | 417 | |
c3a7b59a | 418 | TString message = "**** Id's of valid objects found *****\n"; |
62032124 | 419 | TIter iter(&fValidFileIds); |
420 | AliCDBId* anId=0; | |
421 | ||
422 | // loop on the list of selection criteria | |
423 | while ((anId = dynamic_cast<AliCDBId*>(iter.Next()))) { | |
c3a7b59a | 424 | message += Form("\t%s\n", anId->ToString().Data()); |
62032124 | 425 | } |
6dc56e97 | 426 | message += Form("\n\tTotal: %d objects found\n", fValidFileIds.GetEntriesFast()); |
c3a7b59a | 427 | AliInfo(Form("%s", message.Data())); |
62032124 | 428 | } |
429 | ||
b8ec52f6 | 430 | //_____________________________________________________________________________ |
431 | AliCDBManager::DataType AliCDBStorage::GetDataType() const { | |
432 | // returns the type of the data that should be stored into this storage: | |
433 | // kConditions: conditions data; kReference: reference data; kPrivate: private (user-defined) data type | |
434 | ||
435 | if(GetType() != "alien") return AliCDBManager::kPrivate; | |
436 | ||
437 | TString condFolder = ((AliCDBGridParam*) AliCDBManager::Instance()->GetCondParam())->GetDBFolder(); | |
438 | TString refFolder = ((AliCDBGridParam*) AliCDBManager::Instance()->GetRefParam())->GetDBFolder(); | |
439 | ||
440 | if(GetBaseFolder().Contains(condFolder)) return AliCDBManager::kCondition; | |
441 | if(GetBaseFolder().Contains(refFolder)) return AliCDBManager::kReference; | |
442 | ||
443 | return AliCDBManager::kPrivate; | |
444 | } | |
145f45a2 | 445 | |
446 | //_____________________________________________________________________________ | |
447 | void AliCDBStorage::LoadTreeFromFile(AliCDBEntry *entry) const { | |
448 | // Checks whether entry contains a TTree and in case loads it into memory | |
449 | ||
450 | AliCDBMetaData *md = dynamic_cast<AliCDBMetaData*> (entry->GetMetaData()); | |
451 | if(!md) return; | |
452 | TString objStr = md->GetObjectClassName(); | |
453 | if(objStr != "TTree") return; | |
454 | AliWarning("Entry contains a TTree! Loading baskets..."); | |
455 | ||
456 | TTree* tree = dynamic_cast<TTree*> (entry->GetObject()); | |
457 | ||
458 | if(!tree) return; | |
459 | ||
460 | tree->LoadBaskets(); | |
461 | tree->SetDirectory(0); | |
462 | ||
463 | return; | |
464 | } | |
465 | ||
466 | //_____________________________________________________________________________ | |
467 | void AliCDBStorage::SetTreeToFile(AliCDBEntry *entry, TFile* file) const { | |
468 | // Checks whether entry contains a TTree and in case assigns it to memory | |
469 | ||
470 | AliCDBMetaData *md = dynamic_cast<AliCDBMetaData*> (entry->GetMetaData()); | |
471 | if(!md) return; | |
472 | TString objStr = md->GetObjectClassName(); | |
473 | if(objStr != "TTree") return; | |
474 | AliWarning("Entry contains a TTree! Setting file..."); | |
475 | ||
476 | TTree* tree = dynamic_cast<TTree*> (entry->GetObject()); | |
477 | ||
478 | if(!tree) return; | |
479 | ||
480 | tree->SetDirectory(file); | |
481 | ||
482 | return; | |
483 | } |