]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/CDB/AliCDBManager.h
Introduce GetStorage("raw://")
[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
44     TList* GetActiveStorages();
45
46     const TMap* GetStorageMap() const {return fStorageMap;}
47     const TList* GetRetrievedIds() const {return fIds;}
48
49     void SetDefaultStorage(const char* dbString);
50     void SetDefaultStorage(const AliCDBParam* param);
51     void SetDefaultStorage(AliCDBStorage *storage);
52     void SetDefaultStorage(const char* runType, const char* simType);
53     void SetDefaultStorageFromRun(Int_t run);
54
55     Bool_t IsDefaultStorageSet() const {return fDefaultStorage != 0;}
56     AliCDBStorage* GetDefaultStorage() const {return fDefaultStorage;}
57     void UnsetDefaultStorage();
58
59     void SetSpecificStorage(const char* calibType, const char* dbString);
60
61     AliCDBStorage* GetSpecificStorage(const char* calibType);
62
63     void SetDrain(const char* dbString);
64     void SetDrain(const AliCDBParam* param);
65     void SetDrain(AliCDBStorage *storage);
66     void UnsetDrain(){fDrainStorage = 0x0;}
67     Bool_t IsDrainSet() const {return fDrainStorage != 0;}
68     Bool_t Drain(AliCDBEntry* entry);
69
70     Bool_t SetOCDBUploadMode();
71     void UnsetOCDBUploadMode() { fOCDBUploadMode=kFALSE; }
72     Bool_t IsOCDBUploadMode() const { return fOCDBUploadMode; }
73
74     AliCDBEntry* Get(const AliCDBId& query, Bool_t forceCaching=kFALSE);
75     AliCDBEntry* Get(const AliCDBPath& path, Int_t runNumber=-1,
76         Int_t version = -1, Int_t subVersion = -1);
77     AliCDBEntry* Get(const AliCDBPath& path, const AliCDBRunRange& runRange,
78         Int_t version = -1, Int_t subVersion = -1);
79     AliCDBEntry* GetEntryFromSnapshot(const char* path);
80
81     const char* GetURI(const char* path);                                
82
83     TList* GetAll(const AliCDBId& query);
84     TList* GetAll(const AliCDBPath& path, Int_t runNumber=-1,
85         Int_t version = -1, Int_t subVersion = -1);
86     TList* GetAll(const AliCDBPath& path, const AliCDBRunRange& runRange,
87         Int_t version = -1, Int_t subVersion = -1); 
88
89     Bool_t Put(TObject* object, const AliCDBId& id, AliCDBMetaData* metaData,
90         const char* mirrors="", DataType type=kPrivate);
91     Bool_t Put(AliCDBEntry* entry, const char* mirrors="", DataType type=kPrivate);
92
93     void SetCacheFlag(Bool_t cacheFlag) {fCache=cacheFlag;}
94     Bool_t GetCacheFlag() const {return fCache;}
95
96     ULong64_t SetLock(Bool_t lockFlag=kTRUE, ULong64_t key=0);
97     Bool_t GetLock() const {return fLock;}
98
99     void SetRaw(Bool_t rawFlag){fRaw=rawFlag;}
100     Bool_t GetRaw() const {return fRaw;}
101
102     void SetRun(Int_t run);
103     Int_t GetRun() const {return fRun;}
104
105     void SetMirrorSEs(const char* mirrors);
106     const char* GetMirrorSEs() const;
107
108     void DestroyActiveStorages();
109     void DestroyActiveStorage(AliCDBStorage* storage);
110
111     void QueryCDB();
112
113     void Print(Option_t* option="") const;
114
115     static void Destroy();
116     ~AliCDBManager();
117
118     void ClearCache();
119     void UnloadFromCache(const char* path);
120     const TMap* GetEntryCache() const {return &fEntryCache;}
121
122     Bool_t IsShortLived(const char* path);
123
124     static AliCDBManager* Instance(TMap *entryCache = NULL, Int_t run = -1);
125
126     void Init();
127     void InitFromCache(TMap *entryCache, Int_t run);
128     Bool_t InitFromSnapshot(const char* snapshotFileName, Bool_t overwrite=kTRUE);
129     Bool_t SetSnapshotMode(const char* snapshotFileName="OCDB.root");
130     void UnsetSnapshotMode() {fSnapshotMode=kFALSE;}
131     void DumpToSnapshotFile(const char* snapshotFileName, Bool_t singleKeys) const;
132     void DumpToLightSnapshotFile(const char* lightSnapshotFileName) const;
133
134     Int_t GetStartRunLHCPeriod();
135     Int_t GetEndRunLHCPeriod();
136     TString GetLHCPeriod();
137     TString GetCvmfsOcdbTag() const {return fCvmfsOcdb;}
138
139     Bool_t DiffObjects(const char *cdbFile1, const char *cdbFile2) const;
140     void ExtractBaseFolder(TString& url); // remove everything but the url from OCDB path
141
142   protected:
143
144     static TString fgkCondUri;  // URI of the Conditions data base folder
145     static TString fgkRefUri;   // URI of the Reference data base folder
146     static TString fgkMCIdealStorage;   // URI of the MC-Ideal Conditions data base folder form MC data
147     static TString fgkMCFullStorage;    // URI of the MC-Full Conditions data base folder form MC data
148     static TString fgkMCResidualStorage;        // URI of the MC-Residual Conditions data base folder form MC data
149     static TString fgkOCDBFolderXMLfile;        // alien path of the XML file for OCDB folder <--> Run range correspondance
150
151     AliCDBManager() ; 
152     AliCDBManager(const AliCDBManager & source);
153     AliCDBManager & operator=(const AliCDBManager & source);
154
155     static AliCDBManager* fgInstance; // AliCDBManager instance
156
157     AliCDBStorage* GetStorage(const AliCDBParam* param);
158     AliCDBStorage* GetActiveStorage(const AliCDBParam* param);
159     void PutActiveStorage(AliCDBParam* param, AliCDBStorage* storage);
160     void SetSpecificStorage(const char* calibType, const AliCDBParam* param);
161     void AlienToCvmfsUri(TString& uriString) const;
162     void ValidateCvmfsCase() const;
163     void GetLHCPeriodAgainstAlienFile(Int_t run, TString& lhcPeriod, Int_t& startRun, Int_t& endRun);
164     void GetLHCPeriodAgainstCvmfsFile(Int_t run, TString& lhcPeriod, Int_t& startRun, Int_t& endRun);
165
166     void CacheEntry(const char* path, AliCDBEntry* entry);
167
168     AliCDBParam* SelectSpecificStorage(const TString& path);
169
170     AliCDBId* GetId(const AliCDBId& query);
171     AliCDBId* GetId(const AliCDBPath& path, Int_t runNumber=-1,
172         Int_t version = -1, Int_t subVersion = -1);
173     AliCDBId* GetId(const AliCDBPath& path, const AliCDBRunRange& runRange,
174         Int_t version = -1, Int_t subVersion = -1);
175
176
177     //  void Init();
178     void InitShortLived();
179     //  void InitFromCache(TMap *entryCache, Int_t run);
180
181
182     TList fFactories;           //! list of registered storage factories
183     TMap fActiveStorages;               //! list of active storages
184     TMap fSpecificStorages;         //! list of detector-specific storages
185     TMap fEntryCache;                   //! cache of the retrieved objects
186
187     TList* fIds;                //! List of the retrieved object Id's (to be streamed to file)
188     TMap* fStorageMap;      //! list of storages (to be streamed to file)
189     TList* fShortLived;         //! List of short lived objects
190
191     AliCDBStorage *fDefaultStorage;     //! pointer to default storage
192     AliCDBStorage *fDrainStorage;       //! pointer to drain storage
193
194     AliCDBParam* fCondParam;    // Conditions data storage parameters
195     AliCDBParam* fRefParam;             // Reference data storage parameters
196
197     Int_t fRun;                 //! The run number
198     Bool_t fCache;                      //! The cache flag
199     Bool_t fLock;       //! Lock flag, if ON default storage and run number cannot be reset
200
201     Bool_t fSnapshotMode;           //! flag saying if we are in snapshot mode
202     TFile *fSnapshotFile;
203     Bool_t fOCDBUploadMode;         //! flag for uploads to Official CDBs (upload to cvmfs must follow upload to AliEn)
204
205     Bool_t fRaw;   // flag to say whether we are in the raw case
206     TString fCvmfsOcdb;       // set from $OCDB_PATH, points to a cvmfs AliRoot package
207     Int_t fStartRunLHCPeriod; // 1st run of the LHC period set
208     Int_t fEndRunLHCPeriod;   // last run of the LHC period set
209     TString fLHCPeriod;       // LHC period alien folder
210
211   private:
212     ULong64_t fKey;  //! Key for locking/unlocking
213
214
215     ClassDef(AliCDBManager, 0);
216 };
217
218
219 /////////////////////////////////////////////////////////////////////
220 //                                                                 //
221 //  class AliCDBStorageFactory                                     //
222 //                                                                 //
223 /////////////////////////////////////////////////////////////////////
224
225 class AliCDBParam;
226 class AliCDBStorageFactory: public TObject {
227   friend class AliCDBManager;
228
229   public:
230   virtual ~AliCDBStorageFactory(){}
231   virtual Bool_t Validate(const char* dbString) = 0;
232   virtual AliCDBParam* CreateParameter(const char* dbString) = 0;       
233
234   protected:
235   virtual AliCDBStorage* Create(const AliCDBParam* param) = 0;
236
237   ClassDef(AliCDBStorageFactory, 0);
238 };
239
240 /////////////////////////////////////////////////////////////////////
241 //                                                                 //
242 //  class AliCDBParam                                              //
243 //                                                                 //
244 /////////////////////////////////////////////////////////////////////
245
246 class AliCDBParam: public TObject {
247
248   public:
249
250     AliCDBParam();
251     virtual ~AliCDBParam();
252
253     const TString& GetType() const {return fType;};
254     const TString& GetURI() const {return fURI;};
255
256     virtual AliCDBParam* CloneParam() const = 0;
257
258   protected:
259
260     void SetType(const char* type) {fType = type;};
261     void SetURI(const char* uri) {fURI = uri;};
262
263   private:
264
265     TString fType; //! CDB type
266     TString fURI;  //! CDB URI
267
268     ClassDef(AliCDBParam, 0);
269 };
270
271 #endif