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 **************************************************************************/
16 #include "AliCDBManager.h"
17 #include "AliCDBStorage.h"
19 #include "AliCDBEntry.h"
22 ClassImp(AliCDBStorage)
24 //_____________________________________________________________________________
25 AliCDBStorage::AliCDBStorage() {
28 fSelections.SetOwner(1);
31 //_____________________________________________________________________________
32 AliCDBStorage::~AliCDBStorage() {
37 //_____________________________________________________________________________
38 AliCDBId AliCDBStorage::GetSelection(const AliCDBId& id) {
39 // return required version and subversion from the list of selection criteria
41 TIter iter(&fSelections);
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());
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());
62 //_____________________________________________________________________________
63 void AliCDBStorage::AddSelection(const AliCDBId& selection) {
64 // add a selection criterion
66 AliCDBPath path = selection.GetPath();
67 if(!path.IsValid()) return;
69 TIter iter(&fSelections);
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));
80 fSelections.AddFirst(new AliCDBId(selection));
83 //_____________________________________________________________________________
84 void AliCDBStorage::AddSelection(const AliCDBPath& path,
85 const AliCDBRunRange& runRange, Int_t version, Int_t subVersion){
86 // add a selection criterion
88 AddSelection(AliCDBId(path, runRange, version, subVersion));
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
96 AddSelection(AliCDBId(path, firstRun, lastRun, version, subVersion));
99 //_____________________________________________________________________________
100 void AliCDBStorage::RemoveSelection(const AliCDBId& selection) {
101 // remove a selection criterion
103 TIter iter(&fSelections);
104 AliCDBId* aSelection;
106 while ((aSelection = (AliCDBId*) iter.Next())) {
107 if (selection.Comprises(*aSelection)) {
108 fSelections.Remove(aSelection);
113 //_____________________________________________________________________________
114 void AliCDBStorage::RemoveSelection(const AliCDBPath& path,
115 const AliCDBRunRange& runRange){
116 // remove a selection criterion
118 RemoveSelection(AliCDBId(path, runRange, -1, -1));
121 //_____________________________________________________________________________
122 void AliCDBStorage::RemoveSelection(const AliCDBPath& path,
123 Int_t firstRun, Int_t lastRun){
124 // remove a selection criterion
126 RemoveSelection(AliCDBId(path, firstRun, lastRun, -1, -1));
129 //_____________________________________________________________________________
130 void AliCDBStorage::RemoveSelection(int position){
131 // remove a selection criterion from its position in the list
133 fSelections.RemoveAt(position);
136 //_____________________________________________________________________________
137 void AliCDBStorage::RemoveAllSelections(){
138 // remove all selection criteria
140 fSelections.RemoveAll();
143 //_____________________________________________________________________________
144 void AliCDBStorage::PrintSelectionList(){
145 // prints the list of selection criteria
147 TIter iter(&fSelections);
148 AliCDBId* aSelection;
150 // loop on the list of selection criteria
152 while ((aSelection = (AliCDBId*) iter.Next())) {
153 AliInfo(Form("index %d -> selection: %s",index++, aSelection->ToString().Data()));
158 //_____________________________________________________________________________
159 AliCDBEntry* AliCDBStorage::Get(const AliCDBId& query) {
160 // get an AliCDBEntry object from the database
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()));
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()));
176 AliCDBEntry* entry = GetEntry(query);
179 AliInfo(Form("Valid AliCDBEntry object found! %s", entry->GetId().ToString().Data()));
181 AliInfo(Form("Sorry, found no object valid for: name = <%s>, run = %d",
182 (query.GetPath()).Data(), query.GetFirstRun()));
185 // if drain storage is set, drain entry into drain storage
186 if(entry && (AliCDBManager::Instance())->IsDrainSet())
187 AliCDBManager::Instance()->Drain(entry);
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
197 return Get(AliCDBId(path, runNumber, runNumber, version, subVersion));
200 //_____________________________________________________________________________
201 AliCDBEntry* AliCDBStorage::Get(const AliCDBPath& path,
202 const AliCDBRunRange& runRange, Int_t version,
204 // get an AliCDBEntry object from the database
206 return Get(AliCDBId(path, runRange, version, subVersion));
209 //_____________________________________________________________________________
210 TList* AliCDBStorage::GetAll(const AliCDBId& query) {
211 // get multiple AliCDBEntry objects from the database
214 if (!query.IsValid()) {
215 AliError(Form("Invalid query: %s", query.ToString().Data()));
219 if (query.IsAnyRange()) {
220 AliError(Form("Unspecified run or runrange: %s",
221 query.ToString().Data()));
225 TList *result = GetEntries(query);
227 Int_t nEntries = result->GetEntries();
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()));
236 AliInfo(Form("Sorry, found no object valid for: name = <%s>, run = %d",
237 (query.GetPath()).Data(), query.GetFirstRun()));
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);
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
257 return GetAll(AliCDBId(path, runNumber, runNumber, version,
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
266 return GetAll(AliCDBId(path, runRange, version, subVersion));
270 //_____________________________________________________________________________
271 Bool_t AliCDBStorage::Put(TObject* object, AliCDBId& id, AliCDBMetaData* metaData) {
272 // put an AliCDBEntry object from the database
274 AliCDBEntry anEntry(object, id, metaData);
276 return Put(&anEntry);
279 //_____________________________________________________________________________
280 Bool_t AliCDBStorage::Put(AliCDBEntry* entry) {
281 // put an AliCDBEntry object from the database
283 if (!entry->GetId().IsValid()) {
284 AliWarning(Form("Invalid entry ID: %s",
285 entry->GetId().ToString().Data()));
289 if (!entry->GetId().IsSpecified()) {
290 AliError(Form("Unspecified entry ID: %s",
291 entry->GetId().ToString().Data()));
295 return PutEntry(entry);