]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliCDBManager.h
New version of CDB framework. Proper initialization of CDB inside AliSimulation and...
[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
30         void RegisterFactory(AliCDBStorageFactory* factory);
31
32         Bool_t HasStorage(const char* dbString) const;
33
34         AliCDBParam* CreateParameter(const char* dbString) const;
35
36         AliCDBStorage* GetStorage(const char* dbString);
37         AliCDBStorage* GetStorage(const AliCDBParam* param);
38         
39         TList* GetActiveStorages();
40
41         void SetDefaultStorage(const char* dbString);
42         void SetDefaultStorage(const AliCDBParam* param);
43         void SetDefaultStorage(AliCDBStorage *storage);
44         
45         Bool_t IsDefaultStorageSet() const {return fDefaultStorage != 0;}
46         AliCDBStorage* GetDefaultStorage() const {return fDefaultStorage;}
47         void UnsetDefaultStorage() {fDefaultStorage = 0x0;}
48         
49         void SetSpecificStorage(const char* calibType, const char* dbString);
50         void SetSpecificStorage(const char* calibType, AliCDBParam* param);
51
52         AliCDBStorage* GetSpecificStorage(const char* calibType);
53
54         void SetDrain(const char* dbString);
55         void SetDrain(const AliCDBParam* param);
56         void SetDrain(AliCDBStorage *storage);
57
58         Bool_t IsDrainSet() const {return fDrainStorage != 0;}
59
60         Bool_t Drain(AliCDBEntry* entry);
61
62         void UnsetDrain(){fDrainStorage = 0x0;}
63
64         AliCDBEntry* Get(const AliCDBId& query);
65         AliCDBEntry* Get(const AliCDBPath& path, Int_t runNumber=-1, 
66                                 Int_t version = -1, Int_t subVersion = -1);
67         AliCDBEntry* Get(const AliCDBPath& path, const AliCDBRunRange& runRange,
68                                  Int_t version = -1, Int_t subVersion = -1);
69
70         TList* GetAll(const AliCDBId& query);
71         TList* GetAll(const AliCDBPath& path, Int_t runNumber=-1, 
72                                 Int_t version = -1, Int_t subVersion = -1);
73         TList* GetAll(const AliCDBPath& path, const AliCDBRunRange& runRange,
74                                  Int_t version = -1, Int_t subVersion = -1); 
75
76         Bool_t Put(TObject* object, AliCDBId& id,  AliCDBMetaData* metaData);
77         Bool_t Put(AliCDBEntry* entry);
78                 
79         void SetCacheFlag(Bool_t cacheFlag) {fCache=cacheFlag;}
80         Bool_t GetCacheFlag() {return fCache;}
81
82         void SetRun(Long64_t run);
83         Long64_t GetRun() {return fRun;}
84
85         // AliCDBEntry* Get(const char* path);
86
87         void DestroyActiveStorages();
88         void DestroyActiveStorage(AliCDBStorage* storage);
89         
90         static void Destroy();
91         ~AliCDBManager();
92
93         static AliCDBManager* Instance(); 
94
95  private:
96                 
97         AliCDBManager();
98         static AliCDBManager* fgInstance; // AliCDBManager instance
99         
100         AliCDBStorage* GetActiveStorage(const AliCDBParam* param);
101         void PutActiveStorage(AliCDBParam* param, AliCDBStorage* storage);
102         
103         void ClearCache();
104         void CacheEntry(const char* path, AliCDBEntry* entry);
105         
106         AliCDBParam* SelectSpecificStorage(const TString& path);
107         
108
109         void Init();
110         
111         TList fFactories;               //! list of registered storage factories
112         TMap fActiveStorages;           //! list of active storages
113         TMap fSpecificStorages;         //! list of detector-specific storages
114
115         AliCDBStorage *fDefaultStorage; //! pointer to default storage
116         AliCDBStorage *fDrainStorage;   //! pointer to drain storage
117
118         TMap fEntryCache;       //! cache of the retrieved objects
119
120         Bool_t fCache;                  //! The cache flag
121         Long64_t fRun;                  //! The run number
122
123         ClassDef(AliCDBManager, 0);
124 };
125
126
127 /////////////////////////////////////////////////////////////////////
128 //                                                                 //
129 //  class AliCDBStorageFactory                                     //
130 //                                                                 //
131 /////////////////////////////////////////////////////////////////////
132
133 class AliCDBParam;
134 class AliCDBStorageFactory: public TObject {
135         friend class AliCDBManager;
136         
137 public:
138         virtual Bool_t Validate(const char* dbString) = 0;
139         virtual AliCDBParam* CreateParameter(const char* dbString) = 0; 
140
141 protected:
142         virtual AliCDBStorage* Create(const AliCDBParam* param) = 0;
143
144         ClassDef(AliCDBStorageFactory, 0);
145 };
146
147 /////////////////////////////////////////////////////////////////////
148 //                                                                 //
149 //  class AliCDBParam                                              //
150 //                                                                 //
151 /////////////////////////////////////////////////////////////////////
152
153 class AliCDBParam: public TObject {
154
155 public:
156
157         AliCDBParam();
158         virtual ~AliCDBParam();
159
160         const TString& GetType() const {return fType;};
161         const TString& GetURI() const {return fURI;};
162
163         virtual AliCDBParam* CloneParam() const = 0;
164
165 protected:
166
167         void SetType(const char* type) {fType = type;};
168         void SetURI(const char* uri) {fURI = uri;};
169
170 private:
171
172         TString fType; // CDB type
173         TString fURI;  // CDB URI
174
175         ClassDef(AliCDBParam, 0);
176 };
177
178 #endif