]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliCDBStorage.cxx
Replaced with new AliMUONSegFactory and AliMpSegFactory classes
[u/mrichter/AliRoot.git] / STEER / AliCDBStorage.cxx
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 <TKey.h>
17 #include "AliCDBManager.h"
18 #include "AliCDBStorage.h"
19
20 #include "AliCDBEntry.h"
21 #include "AliLog.h"
22
23 ClassImp(AliCDBStorage)
24
25 //_____________________________________________________________________________
26 AliCDBStorage::AliCDBStorage() {
27 // constructor
28
29         fSelections.SetOwner(1);
30 }
31
32 //_____________________________________________________________________________
33 AliCDBStorage::~AliCDBStorage() {
34 // destructor
35
36 }
37
38 //_____________________________________________________________________________
39 AliCDBId 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)) {
49                         AliDebug(2,Form("Using selection criterion: %s ", aSelection->ToString().Data()));
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
59         AliDebug(2,"Looking for objects with most recent version");
60         return AliCDBId(id.GetAliCDBPath(), id.GetAliCDBRunRange());
61 }
62
63 //_____________________________________________________________________________
64 void 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
88 //_____________________________________________________________________________
89 void 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 }
108
109 //_____________________________________________________________________________
110 void AliCDBStorage::AddSelection(const AliCDBPath& path, 
111         const AliCDBRunRange& runRange, Int_t version, Int_t subVersion){
112 // add a selection criterion
113
114         AddSelection(AliCDBId(path, runRange, version, subVersion));
115 }
116
117 //_____________________________________________________________________________
118 void 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 }
124
125 //_____________________________________________________________________________
126 void AliCDBStorage::RemoveSelection(const AliCDBId& selection) {
127 // remove a selection criterion
128
129         TIter iter(&fSelections);
130         AliCDBId* aSelection;
131
132         while ((aSelection = (AliCDBId*) iter.Next())) {
133                 if (selection.Comprises(*aSelection)) {
134                         fSelections.Remove(aSelection);
135                 }
136         }
137 }
138
139 //_____________________________________________________________________________
140 void AliCDBStorage::RemoveSelection(const AliCDBPath& path, 
141         const AliCDBRunRange& runRange){
142 // remove a selection criterion
143
144         RemoveSelection(AliCDBId(path, runRange, -1, -1));
145 }
146
147 //_____________________________________________________________________________
148 void AliCDBStorage::RemoveSelection(const AliCDBPath& path,
149         Int_t firstRun, Int_t lastRun){
150 // remove a selection criterion
151
152         RemoveSelection(AliCDBId(path, firstRun, lastRun, -1, -1));
153 }
154
155 //_____________________________________________________________________________
156 void AliCDBStorage::RemoveSelection(int position){
157 // remove a selection criterion from its position in the list
158
159         fSelections.RemoveAt(position);
160 }
161
162 //_____________________________________________________________________________
163 void AliCDBStorage::RemoveAllSelections(){
164 // remove all selection criteria
165
166         fSelections.RemoveAll();
167 }
168
169 //_____________________________________________________________________________
170 void 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         }
181
182 }
183
184 //_____________________________________________________________________________
185 AliCDBEntry* 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) {
205                 AliInfo(Form("CDB object retrieved: %s", entry->GetId().ToString().Data()));
206         } else {
207                 AliInfo(Form("No valid CDB object found! request was: name = <%s>, run = %d", 
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;
216 }
217
218 //_____________________________________________________________________________
219 AliCDBEntry* AliCDBStorage::Get(const AliCDBPath& path, Int_t runNumber, 
220         Int_t version, Int_t subVersion) {
221 // get an AliCDBEntry object from the database
222
223         return Get(AliCDBId(path, runNumber, runNumber, version, subVersion));
224 }
225
226 //_____________________________________________________________________________
227 AliCDBEntry* AliCDBStorage::Get(const AliCDBPath& path, 
228         const AliCDBRunRange& runRange, Int_t version,
229         Int_t subVersion) {
230 // get an AliCDBEntry object from the database
231
232         return Get(AliCDBId(path, runRange, version, subVersion));
233 }
234
235 //_____________________________________________________________________________
236 TList* 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) {
255                  AliInfo(Form("%d AliCDBEntry objects retrieved.",nEntries));
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 {
262                  AliInfo(Form("No valid CDB object found! request was: name = <%s>, run = %d, version = %d", 
263                         (query.GetPath()).Data(), query.GetFirstRun(), query.GetVersion()));
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 }
277
278 //_____________________________________________________________________________
279 TList* AliCDBStorage::GetAll(const AliCDBPath& path, Int_t runNumber, 
280         Int_t version, Int_t subVersion) {
281 // get multiple AliCDBEntry objects from the database
282
283         return GetAll(AliCDBId(path, runNumber, runNumber, version,     
284                         subVersion));
285 }
286
287 //_____________________________________________________________________________
288 TList* AliCDBStorage::GetAll(const AliCDBPath& path, 
289         const AliCDBRunRange& runRange, Int_t version, Int_t subVersion) {
290 // get multiple AliCDBEntry objects from the database
291
292         return GetAll(AliCDBId(path, runRange, version, subVersion));
293 }
294
295
296 //_____________________________________________________________________________
297 Bool_t AliCDBStorage::Put(TObject* object, AliCDBId& id, AliCDBMetaData* metaData) {
298 // put an AliCDBEntry object from the database
299         
300         AliCDBEntry anEntry(object, id, metaData);
301
302         return Put(&anEntry);
303
304
305 //_____________________________________________________________________________
306 Bool_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);
322 }
323