]> git.uio.no Git - u/mrichter/AliRoot.git/blame - STEER/AliCDBStorage.cxx
fix in Gain
[u/mrichter/AliRoot.git] / STEER / AliCDBStorage.cxx
CommitLineData
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>
9e1ceb13 18#include "AliCDBManager.h"
fe913d8f 19#include "AliCDBStorage.h"
2c8628dd 20
9e1ceb13 21#include "AliCDBEntry.h"
22#include "AliLog.h"
2c8628dd 23
fe913d8f 24ClassImp(AliCDBStorage)
2c8628dd 25
9e1ceb13 26//_____________________________________________________________________________
27AliCDBStorage::AliCDBStorage() {
28// constructor
29
30 fSelections.SetOwner(1);
31}
2c8628dd 32
9e1ceb13 33//_____________________________________________________________________________
34AliCDBStorage::~AliCDBStorage() {
35// destructor
2c8628dd 36
9e1ceb13 37}
2c8628dd 38
39//_____________________________________________________________________________
4b5e0dce 40void AliCDBStorage::GetSelection(/*const*/ AliCDBId* id) {
9e1ceb13 41// return required version and subversion from the list of selection criteria
42
43 TIter iter(&fSelections);
44 AliCDBId* aSelection;
45
46 // loop on the list of selection criteria
47 while ((aSelection = (AliCDBId*) iter.Next())) {
48 // check if selection element contains id's path and run (range)
4b5e0dce 49 if (aSelection->Comprises(*id)) {
b05400be 50 AliDebug(2,Form("Using selection criterion: %s ", aSelection->ToString().Data()));
9e1ceb13 51 // return required version and subversion
4b5e0dce 52
53 id->SetVersion(aSelection->GetVersion());
54 id->SetSubVersion(aSelection->GetSubVersion());
55 return;
9e1ceb13 56 }
57 }
58
59 // no valid element is found in the list of selection criteria -> return
b05400be 60 AliDebug(2,"Looking for objects with most recent version");
4b5e0dce 61 return;
2c8628dd 62}
63
b05400be 64//_____________________________________________________________________________
65void AliCDBStorage::ReadSelectionFromFile(const char *fileName){
66// read selection criteria list from file
67
68 RemoveAllSelections();
69
70 TList *list = GetIdListFromFile(fileName);
71 if(!list) return;
72
73 list->SetOwner();
74 Int_t nId = list->GetEntries();
75 AliCDBId *id;
76 TKey *key;
77
78 for(int i=nId-1;i>=0;i--){
79 key = (TKey*) list->At(i);
80 id = (AliCDBId*) key->ReadObj();
81 if(id) AddSelection(*id);
82 }
83 delete list;
84 AliInfo(Form("Selection criteria list filled with %d entries",fSelections.GetEntries()));
85 PrintSelectionList();
86
87}
88
2c8628dd 89//_____________________________________________________________________________
9e1ceb13 90void AliCDBStorage::AddSelection(const AliCDBId& selection) {
91// add a selection criterion
92
93 AliCDBPath path = selection.GetPath();
94 if(!path.IsValid()) return;
95
96 TIter iter(&fSelections);
97 const AliCDBId *anId;
98 while((anId = (AliCDBId*) iter.Next())){
99 if(selection.Comprises(*anId)){
100 AliWarning("This selection is more general than a previous one and will hide it!");
101 AliWarning(Form("%s", (anId->ToString()).Data()));
102 fSelections.AddBefore(anId, new AliCDBId(selection));
103 return;
104 }
105
106 }
107 fSelections.AddFirst(new AliCDBId(selection));
108}
2c8628dd 109
110//_____________________________________________________________________________
9e1ceb13 111void AliCDBStorage::AddSelection(const AliCDBPath& path,
112 const AliCDBRunRange& runRange, Int_t version, Int_t subVersion){
113// add a selection criterion
2c8628dd 114
9e1ceb13 115 AddSelection(AliCDBId(path, runRange, version, subVersion));
2c8628dd 116}
117
9e1ceb13 118//_____________________________________________________________________________
119void AliCDBStorage::AddSelection(const AliCDBPath& path,
120 Int_t firstRun, Int_t lastRun, Int_t version, Int_t subVersion){
121// add a selection criterion
122
123 AddSelection(AliCDBId(path, firstRun, lastRun, version, subVersion));
124}
2c8628dd 125
9e1ceb13 126//_____________________________________________________________________________
127void AliCDBStorage::RemoveSelection(const AliCDBId& selection) {
128// remove a selection criterion
2c8628dd 129
9e1ceb13 130 TIter iter(&fSelections);
131 AliCDBId* aSelection;
2c8628dd 132
9e1ceb13 133 while ((aSelection = (AliCDBId*) iter.Next())) {
134 if (selection.Comprises(*aSelection)) {
135 fSelections.Remove(aSelection);
136 }
137 }
138}
2c8628dd 139
9e1ceb13 140//_____________________________________________________________________________
141void AliCDBStorage::RemoveSelection(const AliCDBPath& path,
142 const AliCDBRunRange& runRange){
143// remove a selection criterion
2c8628dd 144
9e1ceb13 145 RemoveSelection(AliCDBId(path, runRange, -1, -1));
146}
f05209ee 147
9e1ceb13 148//_____________________________________________________________________________
149void AliCDBStorage::RemoveSelection(const AliCDBPath& path,
150 Int_t firstRun, Int_t lastRun){
151// remove a selection criterion
f05209ee 152
9e1ceb13 153 RemoveSelection(AliCDBId(path, firstRun, lastRun, -1, -1));
154}
f05209ee 155
9e1ceb13 156//_____________________________________________________________________________
eb0b1051 157void AliCDBStorage::RemoveSelection(int position){
9e1ceb13 158// remove a selection criterion from its position in the list
2c8628dd 159
9e1ceb13 160 fSelections.RemoveAt(position);
2c8628dd 161}
162
2c8628dd 163//_____________________________________________________________________________
9e1ceb13 164void AliCDBStorage::RemoveAllSelections(){
165// remove all selection criteria
2c8628dd 166
9e1ceb13 167 fSelections.RemoveAll();
168}
fe913d8f 169
9e1ceb13 170//_____________________________________________________________________________
171void AliCDBStorage::PrintSelectionList(){
172// prints the list of selection criteria
173
174 TIter iter(&fSelections);
175 AliCDBId* aSelection;
176
177 // loop on the list of selection criteria
178 int index=0;
179 while ((aSelection = (AliCDBId*) iter.Next())) {
180 AliInfo(Form("index %d -> selection: %s",index++, aSelection->ToString().Data()));
181 }
fe913d8f 182
9e1ceb13 183}
fe913d8f 184
9e1ceb13 185//_____________________________________________________________________________
186AliCDBEntry* AliCDBStorage::Get(const AliCDBId& query) {
187// get an AliCDBEntry object from the database
188
189 // check if query's path and runRange are valid
190 // query is invalid also if version is not specified and subversion is!
191 if (!query.IsValid()) {
192 AliError(Form("Invalid query: %s", query.ToString().Data()));
193 return NULL;
194 }
195
196 // query is not specified if path contains wildcard or runrange = [-1,-1]
197 if (!query.IsSpecified()) {
198 AliError(Form("Unspecified query: %s",
199 query.ToString().Data()));
200 return NULL;
201 }
02c4845e 202
203 // This is needed otherwise TH1 objects (histos, TTree's) are lost when file is closed!
204 Bool_t oldStatus = TH1::AddDirectoryStatus();
205 TH1::AddDirectory(kFALSE);
9e1ceb13 206
207 AliCDBEntry* entry = GetEntry(query);
02c4845e 208
209 if (oldStatus != kFALSE)
210 TH1::AddDirectory(kTRUE);
9e1ceb13 211
212 if (entry) {
b05400be 213 AliInfo(Form("CDB object retrieved: %s", entry->GetId().ToString().Data()));
9e1ceb13 214 } else {
b05400be 215 AliInfo(Form("No valid CDB object found! request was: name = <%s>, run = %d",
9e1ceb13 216 (query.GetPath()).Data(), query.GetFirstRun()));
217 }
218
219 // if drain storage is set, drain entry into drain storage
220 if(entry && (AliCDBManager::Instance())->IsDrainSet())
221 AliCDBManager::Instance()->Drain(entry);
222
223 return entry;
2c8628dd 224}
225
226//_____________________________________________________________________________
9e1ceb13 227AliCDBEntry* AliCDBStorage::Get(const AliCDBPath& path, Int_t runNumber,
228 Int_t version, Int_t subVersion) {
229// get an AliCDBEntry object from the database
2c8628dd 230
9e1ceb13 231 return Get(AliCDBId(path, runNumber, runNumber, version, subVersion));
2c8628dd 232}
233
2c8628dd 234//_____________________________________________________________________________
9e1ceb13 235AliCDBEntry* AliCDBStorage::Get(const AliCDBPath& path,
236 const AliCDBRunRange& runRange, Int_t version,
237 Int_t subVersion) {
238// get an AliCDBEntry object from the database
2c8628dd 239
9e1ceb13 240 return Get(AliCDBId(path, runRange, version, subVersion));
2c8628dd 241}
242
2c8628dd 243//_____________________________________________________________________________
9e1ceb13 244TList* AliCDBStorage::GetAll(const AliCDBId& query) {
245// get multiple AliCDBEntry objects from the database
246
247
248 if (!query.IsValid()) {
249 AliError(Form("Invalid query: %s", query.ToString().Data()));
250 return NULL;
251 }
252
253 if (query.IsAnyRange()) {
254 AliError(Form("Unspecified run or runrange: %s",
255 query.ToString().Data()));
256 return NULL;
257 }
258
02c4845e 259 // This is needed otherwise TH1 objects (histos, TTree's) are lost when file is closed!
260 Bool_t oldStatus = TH1::AddDirectoryStatus();
261 TH1::AddDirectory(kFALSE);
262
9e1ceb13 263 TList *result = GetEntries(query);
264
02c4845e 265 if (oldStatus != kFALSE)
266 TH1::AddDirectory(kTRUE);
267
9e1ceb13 268 Int_t nEntries = result->GetEntries();
269 if (nEntries) {
b05400be 270 AliInfo(Form("%d AliCDBEntry objects retrieved.",nEntries));
9e1ceb13 271 for(int i=0; i<nEntries;i++){
272 AliCDBEntry *entry = (AliCDBEntry*) result->At(i);
273 AliInfo(Form("%s",entry->GetId().ToString().Data()));
274
275 }
276 } else {
b05400be 277 AliInfo(Form("No valid CDB object found! request was: name = <%s>, run = %d, version = %d",
278 (query.GetPath()).Data(), query.GetFirstRun(), query.GetVersion()));
9e1ceb13 279 }
280
281 // if drain storage is set, drain entries into drain storage
282 if((AliCDBManager::Instance())->IsDrainSet()){
283 for(int i = 0; i<result->GetEntries(); i++){
284 AliCDBEntry* entry = (AliCDBEntry*) result->At(i);
285 AliCDBManager::Instance()->Drain(entry);
286 }
287 }
288
289
290 return result;
291}
2c8628dd 292
9e1ceb13 293//_____________________________________________________________________________
294TList* AliCDBStorage::GetAll(const AliCDBPath& path, Int_t runNumber,
295 Int_t version, Int_t subVersion) {
296// get multiple AliCDBEntry objects from the database
2c8628dd 297
9e1ceb13 298 return GetAll(AliCDBId(path, runNumber, runNumber, version,
299 subVersion));
2c8628dd 300}
301
2c8628dd 302//_____________________________________________________________________________
9e1ceb13 303TList* AliCDBStorage::GetAll(const AliCDBPath& path,
304 const AliCDBRunRange& runRange, Int_t version, Int_t subVersion) {
305// get multiple AliCDBEntry objects from the database
2c8628dd 306
9e1ceb13 307 return GetAll(AliCDBId(path, runRange, version, subVersion));
2c8628dd 308}
f05209ee 309
310
311//_____________________________________________________________________________
9e1ceb13 312Bool_t AliCDBStorage::Put(TObject* object, AliCDBId& id, AliCDBMetaData* metaData) {
02c4845e 313// store an AliCDBEntry object into the database
9e1ceb13 314
315 AliCDBEntry anEntry(object, id, metaData);
f05209ee 316
9e1ceb13 317 return Put(&anEntry);
318}
f05209ee 319
9e1ceb13 320//_____________________________________________________________________________
321Bool_t AliCDBStorage::Put(AliCDBEntry* entry) {
02c4845e 322// store an AliCDBEntry object into the database
9e1ceb13 323
02c4845e 324 if (!entry){
325 AliError("No entry!");
326 return kFALSE;
327 }
328
9e1ceb13 329 if (!entry->GetId().IsValid()) {
02c4845e 330 AliError(Form("Invalid entry ID: %s",
9e1ceb13 331 entry->GetId().ToString().Data()));
332 return kFALSE;
333 }
334
335 if (!entry->GetId().IsSpecified()) {
336 AliError(Form("Unspecified entry ID: %s",
337 entry->GetId().ToString().Data()));
338 return kFALSE;
339 }
340
02c4845e 341 // set object's class name into metaData!
342 entry->GetMetaData()->SetObjectClassName(entry->GetObject()->ClassName());
343
9e1ceb13 344 return PutEntry(entry);
f05209ee 345}
fe913d8f 346