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 **************************************************************************/
17 #include "AliCDBManager.h"
18 #include "AliCDBStorage.h"
20 #include "AliCDBEntry.h"
23 ClassImp(AliCDBStorage)
25 //_____________________________________________________________________________
26 AliCDBStorage::AliCDBStorage() {
29 fSelections.SetOwner(1);
32 //_____________________________________________________________________________
33 AliCDBStorage::~AliCDBStorage() {
38 //_____________________________________________________________________________
39 AliCDBId AliCDBStorage::GetSelection(const AliCDBId& id) {
40 // return required version and subversion from the list of selection criteria
42 TIter iter(&fSelections);
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());
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());
63 //_____________________________________________________________________________
64 void AliCDBStorage::ReadSelectionFromFile(const char *fileName){
65 // read selection criteria list from file
67 RemoveAllSelections();
69 TList *list = GetIdListFromFile(fileName);
73 Int_t nId = list->GetEntries();
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);
83 AliInfo(Form("Selection criteria list filled with %d entries",fSelections.GetEntries()));
88 //_____________________________________________________________________________
89 void AliCDBStorage::AddSelection(const AliCDBId& selection) {
90 // add a selection criterion
92 AliCDBPath path = selection.GetPath();
93 if(!path.IsValid()) return;
95 TIter iter(&fSelections);
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));
106 fSelections.AddFirst(new AliCDBId(selection));
109 //_____________________________________________________________________________
110 void AliCDBStorage::AddSelection(const AliCDBPath& path,
111 const AliCDBRunRange& runRange, Int_t version, Int_t subVersion){
112 // add a selection criterion
114 AddSelection(AliCDBId(path, runRange, version, subVersion));
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
122 AddSelection(AliCDBId(path, firstRun, lastRun, version, subVersion));
125 //_____________________________________________________________________________
126 void AliCDBStorage::RemoveSelection(const AliCDBId& selection) {
127 // remove a selection criterion
129 TIter iter(&fSelections);
130 AliCDBId* aSelection;
132 while ((aSelection = (AliCDBId*) iter.Next())) {
133 if (selection.Comprises(*aSelection)) {
134 fSelections.Remove(aSelection);
139 //_____________________________________________________________________________
140 void AliCDBStorage::RemoveSelection(const AliCDBPath& path,
141 const AliCDBRunRange& runRange){
142 // remove a selection criterion
144 RemoveSelection(AliCDBId(path, runRange, -1, -1));
147 //_____________________________________________________________________________
148 void AliCDBStorage::RemoveSelection(const AliCDBPath& path,
149 Int_t firstRun, Int_t lastRun){
150 // remove a selection criterion
152 RemoveSelection(AliCDBId(path, firstRun, lastRun, -1, -1));
155 //_____________________________________________________________________________
156 void AliCDBStorage::RemoveSelection(int position){
157 // remove a selection criterion from its position in the list
159 fSelections.RemoveAt(position);
162 //_____________________________________________________________________________
163 void AliCDBStorage::RemoveAllSelections(){
164 // remove all selection criteria
166 fSelections.RemoveAll();
169 //_____________________________________________________________________________
170 void AliCDBStorage::PrintSelectionList(){
171 // prints the list of selection criteria
173 TIter iter(&fSelections);
174 AliCDBId* aSelection;
176 // loop on the list of selection criteria
178 while ((aSelection = (AliCDBId*) iter.Next())) {
179 AliInfo(Form("index %d -> selection: %s",index++, aSelection->ToString().Data()));
184 //_____________________________________________________________________________
185 AliCDBEntry* AliCDBStorage::Get(const AliCDBId& query) {
186 // get an AliCDBEntry object from the database
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()));
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()));
202 AliCDBEntry* entry = GetEntry(query);
205 AliInfo(Form("CDB object retrieved: %s", entry->GetId().ToString().Data()));
207 AliInfo(Form("No valid CDB object found! request was: name = <%s>, run = %d",
208 (query.GetPath()).Data(), query.GetFirstRun()));
211 // if drain storage is set, drain entry into drain storage
212 if(entry && (AliCDBManager::Instance())->IsDrainSet())
213 AliCDBManager::Instance()->Drain(entry);
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
223 return Get(AliCDBId(path, runNumber, runNumber, version, subVersion));
226 //_____________________________________________________________________________
227 AliCDBEntry* AliCDBStorage::Get(const AliCDBPath& path,
228 const AliCDBRunRange& runRange, Int_t version,
230 // get an AliCDBEntry object from the database
232 return Get(AliCDBId(path, runRange, version, subVersion));
235 //_____________________________________________________________________________
236 TList* AliCDBStorage::GetAll(const AliCDBId& query) {
237 // get multiple AliCDBEntry objects from the database
240 if (!query.IsValid()) {
241 AliError(Form("Invalid query: %s", query.ToString().Data()));
245 if (query.IsAnyRange()) {
246 AliError(Form("Unspecified run or runrange: %s",
247 query.ToString().Data()));
251 TList *result = GetEntries(query);
253 Int_t nEntries = result->GetEntries();
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()));
262 AliInfo(Form("No valid CDB object found! request was: name = <%s>, run = %d, version = %d",
263 (query.GetPath()).Data(), query.GetFirstRun(), query.GetVersion()));
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);
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
283 return GetAll(AliCDBId(path, runNumber, runNumber, version,
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
292 return GetAll(AliCDBId(path, runRange, version, subVersion));
296 //_____________________________________________________________________________
297 Bool_t AliCDBStorage::Put(TObject* object, AliCDBId& id, AliCDBMetaData* metaData) {
298 // put an AliCDBEntry object from the database
300 AliCDBEntry anEntry(object, id, metaData);
302 return Put(&anEntry);
305 //_____________________________________________________________________________
306 Bool_t AliCDBStorage::Put(AliCDBEntry* entry) {
307 // put an AliCDBEntry object from the database
309 if (!entry->GetId().IsValid()) {
310 AliWarning(Form("Invalid entry ID: %s",
311 entry->GetId().ToString().Data()));
315 if (!entry->GetId().IsSpecified()) {
316 AliError(Form("Unspecified entry ID: %s",
317 entry->GetId().ToString().Data()));
321 return PutEntry(entry);