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