1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 #include "AliCDBManager.h"
19 #include "AliCDBStorage.h"
21 #include "AliCDBEntry.h"
24 ClassImp(AliCDBStorage)
26 //_____________________________________________________________________________
27 AliCDBStorage::AliCDBStorage():
40 fValidFileIds.SetOwner(1);
41 fSelections.SetOwner(1);
44 //_____________________________________________________________________________
45 AliCDBStorage::~AliCDBStorage() {
48 RemoveAllSelections();
49 fValidFileIds.Clear();
50 delete fMetaDataFilter;
54 //_____________________________________________________________________________
55 void AliCDBStorage::GetSelection(/*const*/ AliCDBId* id) {
56 // return required version and subversion from the list of selection criteria
58 TIter iter(&fSelections);
61 // loop on the list of selection criteria
62 while ((aSelection = (AliCDBId*) iter.Next())) {
63 // check if selection element contains id's path and run (range)
64 if (aSelection->Comprises(*id)) {
65 AliDebug(2,Form("Using selection criterion: %s ", aSelection->ToString().Data()));
66 // return required version and subversion
68 id->SetVersion(aSelection->GetVersion());
69 id->SetSubVersion(aSelection->GetSubVersion());
74 // no valid element is found in the list of selection criteria -> return
75 AliDebug(2,"Looking for objects with most recent version");
79 //_____________________________________________________________________________
80 void AliCDBStorage::ReadSelectionFromFile(const char *fileName){
81 // read selection criteria list from file
83 RemoveAllSelections();
85 TList *list = GetIdListFromFile(fileName);
89 Int_t nId = list->GetEntries();
93 for(int i=nId-1;i>=0;i--){
94 key = (TKey*) list->At(i);
95 id = (AliCDBId*) key->ReadObj();
96 if(id) AddSelection(*id);
99 AliInfo(Form("Selection criteria list filled with %d entries",fSelections.GetEntries()));
100 PrintSelectionList();
104 //_____________________________________________________________________________
105 void AliCDBStorage::AddSelection(const AliCDBId& selection) {
106 // add a selection criterion
108 AliCDBPath path = selection.GetPath();
109 if(!path.IsValid()) return;
111 TIter iter(&fSelections);
112 const AliCDBId *anId;
113 while((anId = (AliCDBId*) iter.Next())){
114 if(selection.Comprises(*anId)){
115 AliWarning("This selection is more general than a previous one and will hide it!");
116 AliWarning(Form("%s", (anId->ToString()).Data()));
117 fSelections.AddBefore(anId, new AliCDBId(selection));
122 fSelections.AddFirst(new AliCDBId(selection));
125 //_____________________________________________________________________________
126 void AliCDBStorage::AddSelection(const AliCDBPath& path,
127 const AliCDBRunRange& runRange, Int_t version, Int_t subVersion){
128 // add a selection criterion
130 AddSelection(AliCDBId(path, runRange, version, subVersion));
133 //_____________________________________________________________________________
134 void AliCDBStorage::AddSelection(const AliCDBPath& path,
135 Int_t firstRun, Int_t lastRun, Int_t version, Int_t subVersion){
136 // add a selection criterion
138 AddSelection(AliCDBId(path, firstRun, lastRun, version, subVersion));
141 //_____________________________________________________________________________
142 void AliCDBStorage::RemoveSelection(const AliCDBId& selection) {
143 // remove a selection criterion
145 TIter iter(&fSelections);
146 AliCDBId* aSelection;
148 while ((aSelection = (AliCDBId*) iter.Next())) {
149 if (selection.Comprises(*aSelection)) {
150 fSelections.Remove(aSelection);
155 //_____________________________________________________________________________
156 void AliCDBStorage::RemoveSelection(const AliCDBPath& path,
157 const AliCDBRunRange& runRange){
158 // remove a selection criterion
160 RemoveSelection(AliCDBId(path, runRange, -1, -1));
163 //_____________________________________________________________________________
164 void AliCDBStorage::RemoveSelection(const AliCDBPath& path,
165 Int_t firstRun, Int_t lastRun){
166 // remove a selection criterion
168 RemoveSelection(AliCDBId(path, firstRun, lastRun, -1, -1));
171 //_____________________________________________________________________________
172 void AliCDBStorage::RemoveSelection(int position){
173 // remove a selection criterion from its position in the list
175 delete fSelections.RemoveAt(position);
178 //_____________________________________________________________________________
179 void AliCDBStorage::RemoveAllSelections(){
180 // remove all selection criteria
185 //_____________________________________________________________________________
186 void AliCDBStorage::PrintSelectionList(){
187 // prints the list of selection criteria
189 TIter iter(&fSelections);
190 AliCDBId* aSelection;
192 // loop on the list of selection criteria
194 while ((aSelection = (AliCDBId*) iter.Next())) {
195 AliInfo(Form("index %d -> selection: %s",index++, aSelection->ToString().Data()));
200 //_____________________________________________________________________________
201 AliCDBEntry* AliCDBStorage::Get(const AliCDBId& query) {
202 // get an AliCDBEntry object from the database
204 // check if query's path and runRange are valid
205 // query is invalid also if version is not specified and subversion is!
206 if (!query.IsValid()) {
207 AliError(Form("Invalid query: %s", query.ToString().Data()));
211 // query is not specified if path contains wildcard or runrange = [-1,-1]
212 if (!query.IsSpecified()) {
213 AliError(Form("Unspecified query: %s",
214 query.ToString().Data()));
218 // This is needed otherwise TH1 objects (histos, TTree's) are lost when file is closed!
219 Bool_t oldStatus = TH1::AddDirectoryStatus();
220 TH1::AddDirectory(kFALSE);
222 AliCDBEntry* entry = GetEntry(query);
224 if (oldStatus != kFALSE)
225 TH1::AddDirectory(kTRUE);
228 // this is to make the SHUTTLE output lighter
229 if(!(query.GetPath().Contains("SHUTTLE/STATUS")))
230 AliInfo(Form("CDB object retrieved: %s", entry->GetId().ToString().Data()));
232 // this is to make the SHUTTLE output lighter
233 if(!(query.GetPath().Contains("SHUTTLE/STATUS")))
234 AliInfo(Form("No valid CDB object found! request was: name = <%s>, run = %d",
235 (query.GetPath()).Data(), query.GetFirstRun()));
238 // if drain storage is set, drain entry into drain storage
239 if(entry && (AliCDBManager::Instance())->IsDrainSet())
240 AliCDBManager::Instance()->Drain(entry);
245 //_____________________________________________________________________________
246 AliCDBEntry* AliCDBStorage::Get(const AliCDBPath& path, Int_t runNumber,
247 Int_t version, Int_t subVersion) {
248 // get an AliCDBEntry object from the database
250 return Get(AliCDBId(path, runNumber, runNumber, version, subVersion));
253 //_____________________________________________________________________________
254 AliCDBEntry* AliCDBStorage::Get(const AliCDBPath& path,
255 const AliCDBRunRange& runRange, Int_t version,
257 // get an AliCDBEntry object from the database
259 return Get(AliCDBId(path, runRange, version, subVersion));
262 //_____________________________________________________________________________
263 TList* AliCDBStorage::GetAll(const AliCDBId& query) {
264 // get multiple AliCDBEntry objects from the database
267 if (!query.IsValid()) {
268 AliError(Form("Invalid query: %s", query.ToString().Data()));
272 if (query.IsAnyRange()) {
273 AliError(Form("Unspecified run or runrange: %s",
274 query.ToString().Data()));
278 // This is needed otherwise TH1 objects (histos, TTree's) are lost when file is closed!
279 Bool_t oldStatus = TH1::AddDirectoryStatus();
280 TH1::AddDirectory(kFALSE);
282 TList *result = GetEntries(query);
284 if (oldStatus != kFALSE)
285 TH1::AddDirectory(kTRUE);
287 Int_t nEntries = result->GetEntries();
289 AliInfo(Form("%d objects retrieved.",nEntries));
290 for(int i=0; i<nEntries;i++){
291 AliCDBEntry *entry = (AliCDBEntry*) result->At(i);
292 AliInfo(Form("%s",entry->GetId().ToString().Data()));
296 AliInfo(Form("No valid CDB object found! request was: name = <%s>, run = %d, version = %d",
297 (query.GetPath()).Data(), query.GetFirstRun(), query.GetVersion()));
300 // if drain storage is set, drain entries into drain storage
301 if((AliCDBManager::Instance())->IsDrainSet()){
302 for(int i = 0; i<result->GetEntries(); i++){
303 AliCDBEntry* entry = (AliCDBEntry*) result->At(i);
304 AliCDBManager::Instance()->Drain(entry);
312 //_____________________________________________________________________________
313 TList* AliCDBStorage::GetAll(const AliCDBPath& path, Int_t runNumber,
314 Int_t version, Int_t subVersion) {
315 // get multiple AliCDBEntry objects from the database
317 return GetAll(AliCDBId(path, runNumber, runNumber, version,
321 //_____________________________________________________________________________
322 TList* AliCDBStorage::GetAll(const AliCDBPath& path,
323 const AliCDBRunRange& runRange, Int_t version, Int_t subVersion) {
324 // get multiple AliCDBEntry objects from the database
326 return GetAll(AliCDBId(path, runRange, version, subVersion));
330 //_____________________________________________________________________________
331 Bool_t AliCDBStorage::Put(TObject* object, AliCDBId& id, AliCDBMetaData* metaData) {
332 // store an AliCDBEntry object into the database
334 AliCDBEntry anEntry(object, id, metaData);
336 return Put(&anEntry);
339 //_____________________________________________________________________________
340 Bool_t AliCDBStorage::Put(AliCDBEntry* entry) {
341 // store an AliCDBEntry object into the database
344 AliError("No entry!");
348 if (!entry->GetId().IsValid()) {
349 AliError(Form("Invalid entry ID: %s",
350 entry->GetId().ToString().Data()));
354 if (!entry->GetId().IsSpecified()) {
355 AliError(Form("Unspecified entry ID: %s",
356 entry->GetId().ToString().Data()));
360 // set object's class name into metaData!
361 entry->GetMetaData()->SetObjectClassName(entry->GetObject()->ClassName());
363 return PutEntry(entry);
366 //_____________________________________________________________________________
367 void AliCDBStorage::QueryCDB(Long64_t run, const char* pathFilter,
368 Int_t version, AliCDBMetaData* md){
369 // query CDB for files valid for given run, and fill list fValidFileIds
370 // Actual query is done in virtual function QueryValidFiles()
374 fPathFilter = pathFilter;
375 if(!fPathFilter.IsValid()) {
376 AliError(Form("Filter not valid: %s", pathFilter));
383 // Clear fValidFileIds list (it cannot be filled twice!
384 AliDebug(2, "Clearing list of CDB Id's previously loaded");
385 fValidFileIds.Clear();
387 if(fMetaDataFilter) {delete fMetaDataFilter; fMetaDataFilter=0;}
388 if(md) fMetaDataFilter = dynamic_cast<AliCDBMetaData*> (md->Clone());
392 AliInfo(Form("%d files valid for run %ld, path %s and version %d found in CDB storage: \n %s://%s",
393 fValidFileIds.GetEntries(), (long) fRun, pathFilter, version,
394 fType.Data(), fBaseFolder.Data()));
398 //_____________________________________________________________________________
399 void AliCDBStorage::PrintQueryCDB(){
400 // print parameters used to load list of CDB Id's (fRun, fPathFilter, fVersion)
402 AliInfo(Form("QueryCDB Parameters: \n\tRun = %ld \n\tPath filter = %s \n\tVersion = %d",
403 (long) fRun, fPathFilter.GetPath().Data(), fVersion));
405 if(fMetaDataFilter) {
406 AliInfo("CDBMetaData Parameters: ");
408 fMetaDataFilter->PrintMetaData();
410 AliInfo("Id's of valid objects found:");
411 TIter iter(&fValidFileIds);
414 // loop on the list of selection criteria
415 while ((anId = dynamic_cast<AliCDBId*>(iter.Next()))) {
416 AliInfo(Form("%s", anId->ToString().Data()));