]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliCDBStorage.cxx
Alignment framework (C.Cheshkov). More information is available in http://agenda...
[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 "AliCDBManager.h"
17 #include "AliCDBStorage.h"
18
19 #include "AliCDBEntry.h"
20 #include "AliLog.h"
21
22 ClassImp(AliCDBStorage)
23
24 //_____________________________________________________________________________
25 AliCDBStorage::AliCDBStorage() {
26 // constructor
27
28         fSelections.SetOwner(1);
29 }
30
31 //_____________________________________________________________________________
32 AliCDBStorage::~AliCDBStorage() {
33 // destructor
34
35 }
36
37 //_____________________________________________________________________________
38 AliCDBId 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());
60 }
61
62 //_____________________________________________________________________________
63 void 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 }
82
83 //_____________________________________________________________________________
84 void AliCDBStorage::AddSelection(const AliCDBPath& path, 
85         const AliCDBRunRange& runRange, Int_t version, Int_t subVersion){
86 // add a selection criterion
87
88         AddSelection(AliCDBId(path, runRange, version, subVersion));
89 }
90
91 //_____________________________________________________________________________
92 void 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 }
98
99 //_____________________________________________________________________________
100 void AliCDBStorage::RemoveSelection(const AliCDBId& selection) {
101 // remove a selection criterion
102
103         TIter iter(&fSelections);
104         AliCDBId* aSelection;
105
106         while ((aSelection = (AliCDBId*) iter.Next())) {
107                 if (selection.Comprises(*aSelection)) {
108                         fSelections.Remove(aSelection);
109                 }
110         }
111 }
112
113 //_____________________________________________________________________________
114 void AliCDBStorage::RemoveSelection(const AliCDBPath& path, 
115         const AliCDBRunRange& runRange){
116 // remove a selection criterion
117
118         RemoveSelection(AliCDBId(path, runRange, -1, -1));
119 }
120
121 //_____________________________________________________________________________
122 void AliCDBStorage::RemoveSelection(const AliCDBPath& path,
123         Int_t firstRun, Int_t lastRun){
124 // remove a selection criterion
125
126         RemoveSelection(AliCDBId(path, firstRun, lastRun, -1, -1));
127 }
128
129 //_____________________________________________________________________________
130 void AliCDBStorage::RemoveSelection(int position){
131 // remove a selection criterion from its position in the list
132
133         fSelections.RemoveAt(position);
134 }
135
136 //_____________________________________________________________________________
137 void AliCDBStorage::RemoveAllSelections(){
138 // remove all selection criteria
139
140         fSelections.RemoveAll();
141 }
142
143 //_____________________________________________________________________________
144 void 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         }
155
156 }
157
158 //_____________________________________________________________________________
159 AliCDBEntry* 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;
190 }
191
192 //_____________________________________________________________________________
193 AliCDBEntry* AliCDBStorage::Get(const AliCDBPath& path, Int_t runNumber, 
194         Int_t version, Int_t subVersion) {
195 // get an AliCDBEntry object from the database
196
197         return Get(AliCDBId(path, runNumber, runNumber, version, subVersion));
198 }
199
200 //_____________________________________________________________________________
201 AliCDBEntry* AliCDBStorage::Get(const AliCDBPath& path, 
202         const AliCDBRunRange& runRange, Int_t version,
203         Int_t subVersion) {
204 // get an AliCDBEntry object from the database
205
206         return Get(AliCDBId(path, runRange, version, subVersion));
207 }
208
209 //_____________________________________________________________________________
210 TList* 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 }
251
252 //_____________________________________________________________________________
253 TList* AliCDBStorage::GetAll(const AliCDBPath& path, Int_t runNumber, 
254         Int_t version, Int_t subVersion) {
255 // get multiple AliCDBEntry objects from the database
256
257         return GetAll(AliCDBId(path, runNumber, runNumber, version,     
258                         subVersion));
259 }
260
261 //_____________________________________________________________________________
262 TList* AliCDBStorage::GetAll(const AliCDBPath& path, 
263         const AliCDBRunRange& runRange, Int_t version, Int_t subVersion) {
264 // get multiple AliCDBEntry objects from the database
265
266         return GetAll(AliCDBId(path, runRange, version, subVersion));
267 }
268
269
270 //_____________________________________________________________________________
271 Bool_t AliCDBStorage::Put(TObject* object, AliCDBId& id, AliCDBMetaData* metaData) {
272 // put an AliCDBEntry object from the database
273         
274         AliCDBEntry anEntry(object, id, metaData);
275
276         return Put(&anEntry);
277
278
279 //_____________________________________________________________________________
280 Bool_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);
296 }
297