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