]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliCDBManager.h
Implementation of the local caching of the OCDB set required some upgrade of the...
[u/mrichter/AliRoot.git] / STEER / 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
17 class AliCDBEntry;
18 class AliCDBId;
19 class AliCDBPath;
20 class AliCDBRunRange;
21 class AliCDBMetaData;
22 class AliCDBStorage;
23 class AliCDBStorageFactory;
24 class AliCDBParam;
25
26 class AliCDBManager: public TObject {
27
28  public:
29         enum DataType {kCondition=0, kReference, kPrivate};
30
31         void RegisterFactory(AliCDBStorageFactory* factory);
32
33         Bool_t HasStorage(const char* dbString) const;
34
35         AliCDBParam* CreateParameter(const char* dbString) const;
36         AliCDBParam* GetCondParam() const {return fCondParam;}
37         AliCDBParam* GetRefParam() const {return fRefParam;}
38         static const char* GetDataTypeName(DataType type);
39
40         AliCDBStorage* GetStorage(const char* dbString);
41         AliCDBStorage* GetStorage(const AliCDBParam* param);
42
43         TList* GetActiveStorages();
44
45         void SetDefaultStorage(const char* dbString);
46         void SetDefaultStorage(const AliCDBParam* param);
47         void SetDefaultStorage(AliCDBStorage *storage);
48
49         Bool_t IsDefaultStorageSet() const {return fDefaultStorage != 0;}
50         AliCDBStorage* GetDefaultStorage() const {return fDefaultStorage;}
51         void UnsetDefaultStorage() {fDefaultStorage = 0x0;}
52
53         void SetRemoteStorage(const char* dbString);
54         void SetRemoteStorage(const AliCDBParam* param);
55         void SetRemoteStorage(AliCDBStorage *storage);
56
57         Bool_t IsRemoteStorageSet() const {return fRemoteStorage != 0;}
58         AliCDBStorage* GetRemoteStorage() const {return fRemoteStorage;}
59         void UnsetRemoteStorage() {fRemoteStorage = 0x0;}
60
61         void SetSpecificStorage(const char* calibType, const char* dbString);
62         void SetSpecificStorage(const char* calibType, AliCDBParam* param);
63
64         AliCDBStorage* GetSpecificStorage(const char* calibType);
65
66         void SetDrain(const char* dbString);
67         void SetDrain(const AliCDBParam* param);
68         void SetDrain(AliCDBStorage *storage);
69
70         Bool_t IsDrainSet() const {return fDrainStorage != 0;}
71
72         Bool_t Drain(AliCDBEntry* entry);
73
74         void UnsetDrain(){fDrainStorage = 0x0;}
75
76         AliCDBEntry* Get(const AliCDBId& query);
77         AliCDBEntry* Get(const AliCDBPath& path, Int_t runNumber=-1,
78                                 Int_t version = -1, Int_t subVersion = -1);
79         AliCDBEntry* Get(const AliCDBPath& path, const AliCDBRunRange& runRange,
80                                  Int_t version = -1, Int_t subVersion = -1);
81
82         AliCDBId* GetId(const AliCDBId& query);
83         AliCDBId* GetId(const AliCDBPath& path, Int_t runNumber=-1,
84                                 Int_t version = -1, Int_t subVersion = -1);
85         AliCDBId* GetId(const AliCDBPath& path, const AliCDBRunRange& runRange,
86                                  Int_t version = -1, Int_t subVersion = -1);
87
88         TList* GetAll(const AliCDBId& query);
89         TList* GetAll(const AliCDBPath& path, Int_t runNumber=-1,
90                                 Int_t version = -1, Int_t subVersion = -1);
91         TList* GetAll(const AliCDBPath& path, const AliCDBRunRange& runRange,
92                                  Int_t version = -1, Int_t subVersion = -1); 
93
94         Bool_t Put(TObject* object, AliCDBId& id,
95                         AliCDBMetaData* metaData, DataType type=kPrivate);
96         Bool_t Put(AliCDBEntry* entry, DataType type=kPrivate);
97
98         void SetCacheFlag(Bool_t cacheFlag) {fCache=cacheFlag;}
99         Bool_t GetCacheFlag() const {return fCache;}
100
101         void SetRun(Int_t run);
102         Int_t GetRun() const {return fRun;}
103
104         void DestroyActiveStorages();
105         void DestroyActiveStorage(AliCDBStorage* storage);
106
107         void QueryCDB();
108
109         void Print(Option_t* option="") const;
110
111         static void Destroy();
112         ~AliCDBManager();
113
114         void ClearCache();
115         void UnloadFromCache(const char* path);
116
117         Bool_t IsShortLived(const char* path);
118
119         static AliCDBManager* Instance();
120
121  private:
122
123         static TString fgkCondUri;      // URI of the Conditions data base folder
124         static TString fgkRefUri;       // URI of the Reference data base folder
125         AliCDBParam* fCondParam;        // Conditions data storage parameters
126         AliCDBParam* fRefParam;         // Reference data storage parameters
127
128         AliCDBManager();
129         AliCDBManager(const AliCDBManager & source);
130         AliCDBManager & operator=(const AliCDBManager & source);
131
132         static AliCDBManager* fgInstance; // AliCDBManager instance
133         
134         AliCDBStorage* GetActiveStorage(const AliCDBParam* param);
135         void PutActiveStorage(AliCDBParam* param, AliCDBStorage* storage);
136
137         void CacheEntry(const char* path, AliCDBEntry* entry);
138
139         AliCDBParam* SelectSpecificStorage(const TString& path);
140         
141
142         void Init();
143         void InitShortLived();
144
145
146         TList fFactories;               //! list of registered storage factories
147         TMap fActiveStorages;           //! list of active storages
148         TMap fSpecificStorages;         //! list of detector-specific storages
149
150         AliCDBStorage *fDefaultStorage; //! pointer to default storage
151         AliCDBStorage *fRemoteStorage;  //! pointer to remote storage
152         AliCDBStorage *fDrainStorage;   //! pointer to drain storage
153
154         TMap fEntryCache;       //! cache of the retrieved objects
155
156         Bool_t fCache;                  //! The cache flag
157         Int_t fRun;                     //! The run number
158
159         TList* fShortLived;     //! List of short lived objects
160
161         ClassDef(AliCDBManager, 0);
162 };
163
164
165 /////////////////////////////////////////////////////////////////////
166 //                                                                 //
167 //  class AliCDBStorageFactory                                     //
168 //                                                                 //
169 /////////////////////////////////////////////////////////////////////
170
171 class AliCDBParam;
172 class AliCDBStorageFactory: public TObject {
173         friend class AliCDBManager;
174         
175 public:
176         virtual ~AliCDBStorageFactory(){}
177         virtual Bool_t Validate(const char* dbString) = 0;
178         virtual AliCDBParam* CreateParameter(const char* dbString) = 0; 
179
180 protected:
181         virtual AliCDBStorage* Create(const AliCDBParam* param) = 0;
182
183         ClassDef(AliCDBStorageFactory, 0);
184 };
185
186 /////////////////////////////////////////////////////////////////////
187 //                                                                 //
188 //  class AliCDBParam                                              //
189 //                                                                 //
190 /////////////////////////////////////////////////////////////////////
191
192 class AliCDBParam: public TObject {
193
194 public:
195
196         AliCDBParam();
197         virtual ~AliCDBParam();
198
199         const TString& GetType() const {return fType;};
200         const TString& GetURI() const {return fURI;};
201
202         virtual AliCDBParam* CloneParam() const = 0;
203
204 protected:
205
206         void SetType(const char* type) {fType = type;};
207         void SetURI(const char* uri) {fURI = uri;};
208
209 private:
210
211         TString fType; //! CDB type
212         TString fURI;  //! CDB URI
213
214         ClassDef(AliCDBParam, 0);
215 };
216
217 #endif