Add missing include
[u/mrichter/AliRoot.git] / STEER / CDB / AliCDBManager.h
CommitLineData
9e1ceb13 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>
27cac7e3 16#include <TSystem.h>
c022b397 17#include <TFile.h>
9e1ceb13 18
fdf65bb5 19class AliCDBEntry;
02c4845e 20class AliCDBId;
21class AliCDBPath;
22class AliCDBRunRange;
23class AliCDBMetaData;
9e1ceb13 24class AliCDBStorage;
25class AliCDBStorageFactory;
26class AliCDBParam;
27
28class AliCDBManager: public TObject {
29
5078a13f 30 public:
31 enum DataType {kCondition=0, kReference, kPrivate};
9e1ceb13 32
5078a13f 33 void RegisterFactory(AliCDBStorageFactory* factory);
9e1ceb13 34
5078a13f 35 Bool_t HasStorage(const char* dbString) const;
9e1ceb13 36
5078a13f 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);
9e1ceb13 41
5078a13f 42 AliCDBStorage* GetStorage(const char* dbString);
b8ec52f6 43
5078a13f 44 TList* GetActiveStorages();
9e1ceb13 45
5078a13f 46 const TMap* GetStorageMap() const {return fStorageMap;}
47 const TList* GetRetrievedIds() const {return fIds;}
b21e3194 48
5078a13f 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);
4667c116 54
5078a13f 55 Bool_t IsDefaultStorageSet() const {return fDefaultStorage != 0;}
56 AliCDBStorage* GetDefaultStorage() const {return fDefaultStorage;}
57 void UnsetDefaultStorage();
4667c116 58
5078a13f 59 void SetSpecificStorage(const char* calibType, const char* dbString);
02c4845e 60
5078a13f 61 AliCDBStorage* GetSpecificStorage(const char* calibType);
9e1ceb13 62
5078a13f 63 void SetDrain(const char* dbString);
64 void SetDrain(const AliCDBParam* param);
65 void SetDrain(AliCDBStorage *storage);
67522875 66 void UnsetDrain(){fDrainStorage = 0x0;}
5078a13f 67 Bool_t IsDrainSet() const {return fDrainStorage != 0;}
5078a13f 68 Bool_t Drain(AliCDBEntry* entry);
9e1ceb13 69
67522875 70 Bool_t SetOCDBUploadMode();
71 void UnsetOCDBUploadMode() { fOCDBUploadMode=kFALSE; }
72 Bool_t IsOCDBUploadMode() const { return fOCDBUploadMode; }
9e1ceb13 73
e973a743 74 AliCDBEntry* Get(const AliCDBId& query, Bool_t forceCaching=kFALSE);
5078a13f 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);
02c4845e 80
5078a13f 81 const char* GetURI(const char* path);
4667c116 82
5078a13f 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);
02c4845e 88
5078a13f 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);
b8ec52f6 92
5078a13f 93 void SetCacheFlag(Bool_t cacheFlag) {fCache=cacheFlag;}
94 Bool_t GetCacheFlag() const {return fCache;}
4b5e0dce 95
5078a13f 96 ULong64_t SetLock(Bool_t lockFlag=kTRUE, ULong64_t key=0);
97 Bool_t GetLock() const {return fLock;}
7de84b33 98
5078a13f 99 void SetRaw(Bool_t rawFlag){fRaw=rawFlag;}
100 Bool_t GetRaw() const {return fRaw;}
4b5e0dce 101
5078a13f 102 void SetRun(Int_t run);
103 Int_t GetRun() const {return fRun;}
3d152e8d 104
5078a13f 105 void SetMirrorSEs(const char* mirrors);
106 const char* GetMirrorSEs() const;
917a098b 107
5078a13f 108 void DestroyActiveStorages();
109 void DestroyActiveStorage(AliCDBStorage* storage);
62032124 110
5078a13f 111 void QueryCDB();
917a098b 112
5078a13f 113 void Print(Option_t* option="") const;
9e1ceb13 114
5078a13f 115 static void Destroy();
116 ~AliCDBManager();
8e245d15 117
5078a13f 118 void ClearCache();
119 void UnloadFromCache(const char* path);
120 const TMap* GetEntryCache() const {return &fEntryCache;}
4667c116 121
5078a13f 122 Bool_t IsShortLived(const char* path);
9e1ceb13 123
5078a13f 124 static AliCDBManager* Instance(TMap *entryCache = NULL, Int_t run = -1);
b7df0cc5 125
5078a13f 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;}
18d58637 131 void DumpToSnapshotFile(const char* snapshotFileName, Bool_t singleKeys) const;
132 void DumpToLightSnapshotFile(const char* lightSnapshotFileName) const;
a37a1dfc 133
5078a13f 134 Int_t GetStartRunLHCPeriod();
135 Int_t GetEndRunLHCPeriod();
136 TString GetLHCPeriod();
003e9909 137 TString GetCvmfsOcdbTag() const {return fCvmfsOcdb;}
b8ec52f6 138
5078a13f 139 Bool_t DiffObjects(const char *cdbFile1, const char *cdbFile2) const;
c612d6cd 140 void ExtractBaseFolder(TString& url); // remove everything but the url from OCDB path
141
5078a13f 142 protected:
fe12e09c 143
5078a13f 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
917a098b 150
5078a13f 151 AliCDBManager() ;
152 AliCDBManager(const AliCDBManager & source);
153 AliCDBManager & operator=(const AliCDBManager & source);
8e245d15 154
5078a13f 155 static AliCDBManager* fgInstance; // AliCDBManager instance
9e1ceb13 156
5078a13f 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;
4667c116 163
5078a13f 164 void CacheEntry(const char* path, AliCDBEntry* entry);
4667c116 165
5078a13f 166 AliCDBParam* SelectSpecificStorage(const TString& path);
b21e3194 167
5078a13f 168 AliCDBId* GetId(const AliCDBId& query);
169 AliCDBId* GetId(const AliCDBPath& path, Int_t runNumber=-1,
170 Int_t version = -1, Int_t subVersion = -1);
171 AliCDBId* GetId(const AliCDBPath& path, const AliCDBRunRange& runRange,
172 Int_t version = -1, Int_t subVersion = -1);
4b5e0dce 173
9e1ceb13 174
5078a13f 175 // void Init();
176 void InitShortLived();
177 // void InitFromCache(TMap *entryCache, Int_t run);
4b5e0dce 178
4b5e0dce 179
5078a13f 180 TList fFactories; //! list of registered storage factories
181 TMap fActiveStorages; //! list of active storages
182 TMap fSpecificStorages; //! list of detector-specific storages
183 TMap fEntryCache; //! cache of the retrieved objects
c022b397 184
5078a13f 185 TList* fIds; //! List of the retrieved object Id's (to be streamed to file)
186 TMap* fStorageMap; //! list of storages (to be streamed to file)
187 TList* fShortLived; //! List of short lived objects
7de84b33 188
5078a13f 189 AliCDBStorage *fDefaultStorage; //! pointer to default storage
190 AliCDBStorage *fDrainStorage; //! pointer to drain storage
a6f59240 191
5078a13f 192 AliCDBParam* fCondParam; // Conditions data storage parameters
193 AliCDBParam* fRefParam; // Reference data storage parameters
4667c116 194
5078a13f 195 Int_t fRun; //! The run number
196 Bool_t fCache; //! The cache flag
197 Bool_t fLock; //! Lock flag, if ON default storage and run number cannot be reset
198
199 Bool_t fSnapshotMode; //! flag saying if we are in snapshot mode
200 TFile *fSnapshotFile;
67522875 201 Bool_t fOCDBUploadMode; //! flag for uploads to Official CDBs (upload to cvmfs must follow upload to AliEn)
5078a13f 202
203 Bool_t fRaw; // flag to say whether we are in the raw case
204 TString fCvmfsOcdb; // set from $OCDB_PATH, points to a cvmfs AliRoot package
205 Int_t fStartRunLHCPeriod; // 1st run of the LHC period set
206 Int_t fEndRunLHCPeriod; // last run of the LHC period set
207 TString fLHCPeriod; // LHC period alien folder
208
209 private:
210 ULong64_t fKey; //! Key for locking/unlocking
211
212
213 ClassDef(AliCDBManager, 0);
9e1ceb13 214};
215
216
217/////////////////////////////////////////////////////////////////////
218// //
219// class AliCDBStorageFactory //
220// //
221/////////////////////////////////////////////////////////////////////
222
223class AliCDBParam;
224class AliCDBStorageFactory: public TObject {
5078a13f 225 friend class AliCDBManager;
226
227 public:
228 virtual ~AliCDBStorageFactory(){}
229 virtual Bool_t Validate(const char* dbString) = 0;
230 virtual AliCDBParam* CreateParameter(const char* dbString) = 0;
9e1ceb13 231
5078a13f 232 protected:
233 virtual AliCDBStorage* Create(const AliCDBParam* param) = 0;
9e1ceb13 234
5078a13f 235 ClassDef(AliCDBStorageFactory, 0);
9e1ceb13 236};
237
238/////////////////////////////////////////////////////////////////////
239// //
240// class AliCDBParam //
241// //
242/////////////////////////////////////////////////////////////////////
243
244class AliCDBParam: public TObject {
245
5078a13f 246 public:
9e1ceb13 247
5078a13f 248 AliCDBParam();
249 virtual ~AliCDBParam();
9e1ceb13 250
5078a13f 251 const TString& GetType() const {return fType;};
252 const TString& GetURI() const {return fURI;};
9e1ceb13 253
5078a13f 254 virtual AliCDBParam* CloneParam() const = 0;
9e1ceb13 255
5078a13f 256 protected:
9e1ceb13 257
5078a13f 258 void SetType(const char* type) {fType = type;};
259 void SetURI(const char* uri) {fURI = uri;};
9e1ceb13 260
5078a13f 261 private:
9e1ceb13 262
5078a13f 263 TString fType; //! CDB type
264 TString fURI; //! CDB URI
9e1ceb13 265
5078a13f 266 ClassDef(AliCDBParam, 0);
9e1ceb13 267};
268
269#endif