]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/CDB/AliCDBManager.h
adding getters for the LHC period (OCDB folder) and its first/last run
[u/mrichter/AliRoot.git] / STEER / CDB / AliCDBManager.h
1 #ifndef ALI_CDB_MANAGER_H
2 #define ALI_CDB_MANAGER_H
3
4 /* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
5  * See cxx source for full Copyright notice                               */
6
7 /////////////////////////////////////////////////////////////////////
8 //                                                                 //
9 //  class AliCDBManager                                            //
10 //                                                                 //
11 /////////////////////////////////////////////////////////////////////
12
13 #include <TObject.h>
14 #include <TList.h>
15 #include <TMap.h>
16 #include <TSystem.h>
17 #include <TFile.h>
18
19 class AliCDBEntry;
20 class AliCDBId;
21 class AliCDBPath;
22 class AliCDBRunRange;
23 class AliCDBMetaData;
24 class AliCDBStorage;
25 class AliCDBStorageFactory;
26 class AliCDBParam;
27
28 class AliCDBManager: public TObject {
29
30  public:
31         enum DataType {kCondition=0, kReference, kPrivate};
32
33         void RegisterFactory(AliCDBStorageFactory* factory);
34
35         Bool_t HasStorage(const char* dbString) const;
36
37         AliCDBParam* CreateParameter(const char* dbString) const;
38         AliCDBParam* GetCondParam() const {return fCondParam;}
39         AliCDBParam* GetRefParam() const {return fRefParam;}
40         static const char* GetDataTypeName(DataType type);
41
42         AliCDBStorage* GetStorage(const char* dbString);
43         AliCDBStorage* GetStorage(const AliCDBParam* param);
44
45         TList* GetActiveStorages();
46
47         const TMap* GetStorageMap() const {return fStorageMap;}
48         const TList* GetRetrievedIds() const {return fIds;}
49
50         void SetDefaultStorage(const char* dbString);
51         void SetDefaultStorage(const AliCDBParam* param);
52         void SetDefaultStorage(AliCDBStorage *storage);
53         void SetDefaultStorage(const char* runType, const char* simType);
54         void SetDefaultStorageFromRun(Int_t run);
55
56         Bool_t IsDefaultStorageSet() const {return fDefaultStorage != 0;}
57         AliCDBStorage* GetDefaultStorage() const {return fDefaultStorage;}
58         void UnsetDefaultStorage();
59
60         void SetSpecificStorage(const char* calibType, const char* dbString);
61         void SetSpecificStorage(const char* calibType, const AliCDBParam* param);
62
63         AliCDBStorage* GetSpecificStorage(const char* calibType);
64
65         void SetDrain(const char* dbString);
66         void SetDrain(const AliCDBParam* param);
67         void SetDrain(AliCDBStorage *storage);
68
69         Bool_t IsDrainSet() const {return fDrainStorage != 0;}
70
71         Bool_t Drain(AliCDBEntry* entry);
72
73         void UnsetDrain(){fDrainStorage = 0x0;}
74
75         AliCDBEntry* Get(const AliCDBId& query, Bool_t forceCaching=kFALSE);
76         AliCDBEntry* Get(const AliCDBPath& path, Int_t runNumber=-1,
77                                 Int_t version = -1, Int_t subVersion = -1);
78         AliCDBEntry* Get(const AliCDBPath& path, const AliCDBRunRange& runRange,
79                                  Int_t version = -1, Int_t subVersion = -1);
80         AliCDBEntry* GetEntryFromSnapshot(const char* path);
81
82         const char* GetURI(const char* path);                            
83                                  
84         AliCDBId* GetId(const AliCDBId& query);
85         AliCDBId* GetId(const AliCDBPath& path, Int_t runNumber=-1,
86                                 Int_t version = -1, Int_t subVersion = -1);
87         AliCDBId* GetId(const AliCDBPath& path, const AliCDBRunRange& runRange,
88                                  Int_t version = -1, Int_t subVersion = -1);
89
90         TList* GetAll(const AliCDBId& query);
91         TList* GetAll(const AliCDBPath& path, Int_t runNumber=-1,
92                                 Int_t version = -1, Int_t subVersion = -1);
93         TList* GetAll(const AliCDBPath& path, const AliCDBRunRange& runRange,
94                                  Int_t version = -1, Int_t subVersion = -1); 
95
96         Bool_t Put(TObject* object, const AliCDBId& id,
97                         AliCDBMetaData* metaData, const DataType type=kPrivate);
98         Bool_t Put(AliCDBEntry* entry, DataType type=kPrivate);
99
100         void SetCacheFlag(Bool_t cacheFlag) {fCache=cacheFlag;}
101         Bool_t GetCacheFlag() const {return fCache;}
102         
103         ULong_t SetLock(Bool_t lockFlag=kTRUE, ULong_t key=0);
104         Bool_t GetLock() const {return fLock;}
105
106         void SetRaw(Bool_t rawFlag){fRaw=rawFlag;}
107         Bool_t GetRaw() const {return fRaw;}
108
109         void SetRun(Int_t run);
110         Int_t GetRun() const {return fRun;}
111
112         void DestroyActiveStorages();
113         void DestroyActiveStorage(AliCDBStorage* storage);
114
115         void QueryCDB();
116
117         void Print(Option_t* option="") const;
118
119         static void Destroy();
120         ~AliCDBManager();
121
122         void ClearCache();
123         void UnloadFromCache(const char* path);
124         const TMap* GetEntryCache() const {return &fEntryCache;}
125
126         Bool_t IsShortLived(const char* path);
127
128         static AliCDBManager* Instance(TMap *entryCache = NULL, Int_t run = -1);
129
130         void Init();
131         void InitFromCache(TMap *entryCache, Int_t run);
132         Bool_t InitFromSnapshot(const char* snapshotFileName, Bool_t overwrite=kTRUE);
133         Bool_t SetSnapshotMode(const char* snapshotFileName="OCDB.root");
134         void UnsetSnapshotMode() {fSnapshotMode=kFALSE;}
135         void DumpToSnapshotFile(const char* snapshotFileName, Bool_t singleKeys);
136   
137         Int_t GetStartRunLHCPeriod();
138         Int_t GetEndRunLHCPeriod();
139         TString GetLHCPeriod();
140
141 protected:
142
143         static TString fgkCondUri;      // URI of the Conditions data base folder
144         static TString fgkRefUri;       // URI of the Reference data base folder
145         static TString fgkMCIdealStorage;       // URI of the MC-Ideal Conditions data base folder form MC data
146         static TString fgkMCFullStorage;        // URI of the MC-Full Conditions data base folder form MC data
147         static TString fgkMCResidualStorage;    // URI of the MC-Residual Conditions data base folder form MC data
148         static TString fgkOCDBFolderXMLfile;    // alien path of the XML file for OCDB folder <--> Run range correspondance
149
150         AliCDBManager() ; 
151         AliCDBManager(const AliCDBManager & source);
152         AliCDBManager & operator=(const AliCDBManager & source);
153
154         static AliCDBManager* fgInstance; // AliCDBManager instance
155         
156         AliCDBStorage* GetActiveStorage(const AliCDBParam* param);
157         void PutActiveStorage(AliCDBParam* param, AliCDBStorage* storage);
158
159         void CacheEntry(const char* path, AliCDBEntry* entry);
160
161         AliCDBParam* SelectSpecificStorage(const TString& path);
162         
163
164 //      void Init();
165         void InitShortLived();
166 //      void InitFromCache(TMap *entryCache, Int_t run);
167
168
169         TList fFactories;               //! list of registered storage factories
170         TMap fActiveStorages;           //! list of active storages
171         TMap fSpecificStorages;         //! list of detector-specific storages
172         TMap fEntryCache;               //! cache of the retrieved objects
173
174         TList* fIds;            //! List of the retrieved object Id's (to be streamed to file)
175         TMap* fStorageMap;      //! list of storages (to be streamed to file)
176         TList* fShortLived;     //! List of short lived objects
177
178         AliCDBStorage *fDefaultStorage; //! pointer to default storage
179         AliCDBStorage *fDrainStorage;   //! pointer to drain storage
180
181         AliCDBParam* fCondParam;        // Conditions data storage parameters
182         AliCDBParam* fRefParam;         // Reference data storage parameters
183
184         Int_t fRun;                     //! The run number
185         Bool_t fCache;                  //! The cache flag
186         Bool_t fLock;   //! Lock flag, if ON default storage and run number cannot be reset
187
188         Bool_t fSnapshotMode;           //! flag saying if we are in snapshot mode
189         TFile *fSnapshotFile;
190
191         Bool_t fRaw;   // flag to say whether we are in the raw case
192         Int_t fStartRunLHCPeriod; // 1st run of the LHC period set
193         Int_t fEndRunLHCPeriod;   // last run of the LHC period set
194         TString fLHCPeriod;       // LHC period alien folder
195
196 private:
197    ULong_t fKey;  //! Key for locking/unlocking
198
199
200         ClassDef(AliCDBManager, 0);
201 };
202
203
204 /////////////////////////////////////////////////////////////////////
205 //                                                                 //
206 //  class AliCDBStorageFactory                                     //
207 //                                                                 //
208 /////////////////////////////////////////////////////////////////////
209
210 class AliCDBParam;
211 class AliCDBStorageFactory: public TObject {
212         friend class AliCDBManager;
213         
214 public:
215         virtual ~AliCDBStorageFactory(){}
216         virtual Bool_t Validate(const char* dbString) = 0;
217         virtual AliCDBParam* CreateParameter(const char* dbString) = 0; 
218
219 protected:
220         virtual AliCDBStorage* Create(const AliCDBParam* param) = 0;
221
222         ClassDef(AliCDBStorageFactory, 0);
223 };
224
225 /////////////////////////////////////////////////////////////////////
226 //                                                                 //
227 //  class AliCDBParam                                              //
228 //                                                                 //
229 /////////////////////////////////////////////////////////////////////
230
231 class AliCDBParam: public TObject {
232
233 public:
234
235         AliCDBParam();
236         virtual ~AliCDBParam();
237
238         const TString& GetType() const {return fType;};
239         const TString& GetURI() const {return fURI;};
240
241         virtual AliCDBParam* CloneParam() const = 0;
242
243 protected:
244
245         void SetType(const char* type) {fType = type;};
246         void SetURI(const char* uri) {fURI = uri;};
247
248 private:
249
250         TString fType; //! CDB type
251         TString fURI;  //! CDB URI
252
253         ClassDef(AliCDBParam, 0);
254 };
255
256 #endif