AliRoot Core  3dc7879 (3dc7879)
AliCDBManager.h
Go to the documentation of this file.
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 
8 // //
9 // class AliCDBManager //
10 // //
12 
13 #include <TObject.h>
14 #include <TList.h>
15 #include <TMap.h>
16 #include <TSystem.h>
17 #include <TFile.h>
18 #include <TTimeStamp.h>
19 
20 class AliCDBEntry;
21 class AliCDBId;
22 class AliCDBPath;
23 class AliCDBRunRange;
24 class AliCDBMetaData;
25 class AliCDBStorage;
27 class AliCDBParam;
28 
29 class AliCDBManager: public TObject {
30 
31  public:
33 
35 
36  Bool_t HasStorage(const char* dbString) const;
37 
38  AliCDBParam* CreateParameter(const char* dbString) const;
39  AliCDBParam* GetCondParam() const {return fCondParam;}
40  AliCDBParam* GetRefParam() const {return fRefParam;}
41  static const char* GetDataTypeName(DataType type);
42 
43  AliCDBStorage* GetStorage(const char* dbString);
44 
45  TList* GetActiveStorages();
46 
47  const TMap* GetStorageMap() const {return fStorageMap;}
48  const TList* GetRetrievedIds() const {return fIds;}
49 
50  const TMap* GetSnapshotMap() const;
51  const TList* GetSnapshotRetrievedIds() const;
52  void CreateMapListCopy(TMap& mapCopy, TList& listCopy) const;
53 
54  void SetDefaultStorage(const char* dbString);
55  void SetDefaultStorage(const AliCDBParam* param);
56  void SetDefaultStorage(AliCDBStorage *storage);
57  void SetDefaultStorage(const char* runType, const char* simType);
58  void SetDefaultStorageFromRun(Int_t run);
59 
60  Bool_t IsDefaultStorageSet() const {return fDefaultStorage != 0;}
62  void UnsetDefaultStorage();
63 
64  void SetSpecificStorage(const char* calibType, const char* dbString, Int_t version = -1, Int_t subVersion = -1);
65 
66  //this puts an object in the fPromptEntryCache to override some storage with
67  //in-memory object (to be used online)
68  void PromptCacheEntry(const char* calibType, AliCDBEntry* entry);
69  void SetPromptCacheFlag(Bool_t f) {fPromptCache = f;}
70  Bool_t GetPromptCacheFlag() const {return fPromptCache;}
71 
72  AliCDBStorage* GetSpecificStorage(const char* calibType);
73 
74  void SetDrain(const char* dbString);
75  void SetDrain(const AliCDBParam* param);
76  void SetDrain(AliCDBStorage *storage);
77  void UnsetDrain(){fDrainStorage = 0x0;}
78  Bool_t IsDrainSet() const {return fDrainStorage != 0;}
79  Bool_t Drain(AliCDBEntry* entry);
80 
81  Bool_t SetOCDBUploadMode();
83  Bool_t IsOCDBUploadMode() const { return fOCDBUploadMode; }
84 
85  AliCDBEntry* Get(const AliCDBId& query, Bool_t forceCaching=kFALSE);
86  AliCDBEntry* Get(const AliCDBPath& path, Int_t runNumber=-1,
87  Int_t version = -1, Int_t subVersion = -1);
88  AliCDBEntry* Get(const AliCDBPath& path, const AliCDBRunRange& runRange,
89  Int_t version = -1, Int_t subVersion = -1);
90  AliCDBEntry* GetEntryFromSnapshot(const char* path);
91 
92  const char* GetURI(const char* path);
93 
94  TList* GetAll(const AliCDBId& query);
95  TList* GetAll(const AliCDBPath& path, Int_t runNumber=-1,
96  Int_t version = -1, Int_t subVersion = -1);
97  TList* GetAll(const AliCDBPath& path, const AliCDBRunRange& runRange,
98  Int_t version = -1, Int_t subVersion = -1);
99 
100  Bool_t Put(TObject* object, const AliCDBId& id, AliCDBMetaData* metaData,
101  const char* mirrors="", DataType type=kPrivate);
102  Bool_t Put(AliCDBEntry* entry, const char* mirrors="", DataType type=kPrivate);
103 
104  void SetCacheFlag(Bool_t cacheFlag) {fCache=cacheFlag;}
105  Bool_t GetCacheFlag() const {return fCache;}
106 
107  ULong64_t SetLock(Bool_t lockFlag=kTRUE, ULong64_t key=0);
108  Bool_t GetLock() const {return fLock;}
109 
110  void SetRaw(Bool_t rawFlag){fRaw=rawFlag;}
111  Bool_t GetRaw() const {return fRaw;}
112 
113  void SetRun(Int_t run);
114  Int_t GetRun() const {return fRun;}
115 
116  void SetMaxDate(time_t maxDate);
117  void SetMaxDate(TTimeStamp &maxDate) { SetMaxDate(maxDate.GetSec()); }
118  time_t GetMaxDate() const { return fMaxDate; }
119 
120  void SetMirrorSEs(const char* mirrors);
121  const char* GetMirrorSEs() const;
122 
123  void DestroyActiveStorages();
124  void DestroyActiveStorage(AliCDBStorage* storage);
125 
126  void QueryCDB();
127 
128  void Print(Option_t* option="") const;
129 
130  static void Destroy();
131  ~AliCDBManager();
132 
133  void ClearCache();
134  void ClearPromptCache();
135  void UnloadFromCache(const char* path);
136  const TMap* GetEntryCache() const {return &fEntryCache;}
137 
138  Bool_t IsShortLived(const char* path);
139 
140  static AliCDBManager* Instance(TMap *entryCache = NULL, Int_t run = -1);
141 
142  void Init();
143  void InitFromCache(TMap *entryCache, Int_t run);
144  Bool_t InitFromSnapshot(const char* snapshotFileName, Bool_t overwrite=kTRUE);
145  Bool_t SetSnapshotMode(const char* snapshotFileName="OCDB.root");
147  void DumpToSnapshotFile(const char* snapshotFileName, Bool_t singleKeys) const;
148  void DumpToLightSnapshotFile(const char* lightSnapshotFileName) const;
149 
150  Int_t GetStartRunLHCPeriod();
151  Int_t GetEndRunLHCPeriod();
152  TString GetLHCPeriod();
153  TString GetCvmfsOcdbTag() const {return fCvmfsOcdb;}
154 
155  Bool_t DiffObjects(const char *cdbFile1, const char *cdbFile2) const;
156  void ExtractBaseFolder(TString& url); // remove everything but the url from OCDB path
157 
158 
159  protected:
160 
161  static TString fgkCondUri; // URI of the Conditions data base folder
162  static TString fgkRefUri; // URI of the Reference data base folder
163  static TString fgkMCIdealStorage; // URI of the MC-Ideal Conditions data base folder form MC data
164  static TString fgkMCFullStorage; // URI of the MC-Full Conditions data base folder form MC data
165  static TString fgkMCResidualStorage; // URI of the MC-Residual Conditions data base folder form MC data
166  static TString fgkOCDBFolderXMLfile; // alien path of the XML file for OCDB folder <--> Run range correspondance
167 
168  AliCDBManager() ;
169  AliCDBManager(const AliCDBManager & source);
170  AliCDBManager & operator=(const AliCDBManager & source);
171 
172  static AliCDBManager* fgInstance; // AliCDBManager instance
173 
174  AliCDBStorage* GetStorage(const AliCDBParam* param);
176  void PutActiveStorage(AliCDBParam* param, AliCDBStorage* storage);
177  void SetSpecificStorage(const char* calibType, const AliCDBParam* param, Int_t version = -1, Int_t subVersion = -1);
178  void AlienToCvmfsUri(TString& uriString) const;
179  void ValidateCvmfsCase() const;
180  void GetLHCPeriodAgainstAlienFile(Int_t run, TString& lhcPeriod, Int_t& startRun, Int_t& endRun);
181  void GetLHCPeriodAgainstCvmfsFile(Int_t run, TString& lhcPeriod, Int_t& startRun, Int_t& endRun);
182 
183  void CacheEntry(const char* path, AliCDBEntry* entry);
184 
185  AliCDBParam* SelectSpecificStorage(const TString& path);
186 
187  AliCDBId* GetId(const AliCDBId& query);
188  AliCDBId* GetId(const AliCDBPath& path, Int_t runNumber=-1,
189  Int_t version = -1, Int_t subVersion = -1);
190  AliCDBId* GetId(const AliCDBPath& path, const AliCDBRunRange& runRange,
191  Int_t version = -1, Int_t subVersion = -1);
192 
193 
194  // void Init();
195  void InitShortLived();
196  // void InitFromCache(TMap *entryCache, Int_t run);
197 
198 
199  TList fFactories;
202  TMap fEntryCache;
204 
205  TList* fIds;
206  TMap* fStorageMap;
207  TList* fShortLived;
208 
211 
212  AliCDBParam* fCondParam; // Conditions data storage parameters
213  AliCDBParam* fRefParam; // Reference data storage parameters
214 
215  Int_t fRun;
216  Bool_t fCache;
217  Bool_t fPromptCache;
218  Bool_t fLock;
219 
220  Bool_t fSnapshotMode;
223 
224  Bool_t fRaw; // flag to say whether we are in the raw case
225  TString fCvmfsOcdb; // set from $OCDB_PATH, points to a cvmfs AliRoot package
226  Int_t fStartRunLHCPeriod; // 1st run of the LHC period set
227  Int_t fEndRunLHCPeriod; // last run of the LHC period set
228  TString fLHCPeriod; // LHC period alien folder
229 
230  time_t fMaxDate;
231 
232  private:
233  ULong64_t fKey;
234 
235 
236  ClassDef(AliCDBManager, 0);
237 };
238 
239 
241 // //
242 // class AliCDBStorageFactory //
243 // //
245 
246 class AliCDBParam;
247 class AliCDBStorageFactory: public TObject {
248  friend class AliCDBManager;
249 
250  public:
252  virtual Bool_t Validate(const char* dbString) = 0;
253  virtual AliCDBParam* CreateParameter(const char* dbString) = 0;
254 
255  protected:
256  virtual AliCDBStorage* Create(const AliCDBParam* param) = 0;
257 
258  ClassDef(AliCDBStorageFactory, 0);
259 };
260 
262 // //
263 // class AliCDBParam //
264 // //
266 
267 class AliCDBParam: public TObject {
268 
269  public:
270 
271  AliCDBParam();
272  virtual ~AliCDBParam();
273 
274  const TString& GetType() const {return fType;};
275  const TString& GetURI() const {return fURI;};
276 
277  virtual AliCDBParam* CloneParam() const = 0;
278 
279  protected:
280 
281  void SetType(const char* type) {fType = type;};
282  void SetURI(const char* uri) {fURI = uri;};
283 
284  private:
285 
286  TString fType;
287  TString fURI;
288 
289  ClassDef(AliCDBParam, 0);
290 };
291 
292 #endif
void SetURI(const char *uri)
void SetPromptCacheFlag(Bool_t f)
Definition: AliCDBManager.h:69
AliCDBEntry * GetEntryFromSnapshot(const char *path)
void SetDefaultStorageFromRun(Int_t run)
static TString fgkCondUri
void UnsetSnapshotMode()
Int_t GetRun() const
void RegisterFactory(AliCDBStorageFactory *factory)
AliCDBStorage * GetSpecificStorage(const char *calibType)
ULong64_t fKey
max UNIX timestamp for OCDB objects
AliCDBManager & operator=(const AliCDBManager &source)
void CreateMapListCopy(TMap &mapCopy, TList &listCopy) const
static AliCDBManager * fgInstance
void UnsetOCDBUploadMode()
Definition: AliCDBManager.h:82
virtual ~AliCDBStorageFactory()
void ExtractBaseFolder(TString &url)
Bool_t fCache
The run number.
Bool_t fPromptCache
The cache flag.
const char * path
AliCDBParam * GetCondParam() const
Definition: AliCDBManager.h:39
Bool_t fSnapshotMode
Lock flag, if ON default storage and run number cannot be reset.
const char * GetMirrorSEs() const
Bool_t GetLock() const
AliCDBParam * CreateParameter(const char *dbString) const
void DumpToSnapshotFile(const char *snapshotFileName, Bool_t singleKeys) const
void PutActiveStorage(AliCDBParam *param, AliCDBStorage *storage)
Bool_t fOCDBUploadMode
AliCDBParam * fCondParam
pointer to drain storage
static TString fgkMCFullStorage
AliCDBStorage * fDrainStorage
pointer to default storage
static void Destroy()
void SetCacheFlag(Bool_t cacheFlag)
const TString & GetType() const
Bool_t IsDrainSet() const
Definition: AliCDBManager.h:78
Int_t GetEndRunLHCPeriod()
const TString & GetURI() const
const TList * GetRetrievedIds() const
Definition: AliCDBManager.h:48
AliCDBId * GetId(const AliCDBId &query)
void InitFromCache(TMap *entryCache, Int_t run)
TList * fShortLived
list of storages (to be streamed to file)
void PromptCacheEntry(const char *calibType, AliCDBEntry *entry)
void DestroyActiveStorages()
TString GetCvmfsOcdbTag() const
Bool_t Drain(AliCDBEntry *entry)
Bool_t IsShortLived(const char *path)
void CacheEntry(const char *path, AliCDBEntry *entry)
AliCDBEntry * Get(const AliCDBId &query, Bool_t forceCaching=kFALSE)
static TString fgkMCResidualStorage
Int_t fStartRunLHCPeriod
static const char * GetDataTypeName(DataType type)
static TString fgkRefUri
TString fURI
CDB type.
TMap fActiveStorages
list of registered storage factories
TList * GetActiveStorages()
void SetMaxDate(time_t maxDate)
AliCDBStorage * GetStorage(const char *dbString)
void SetSpecificStorage(const char *calibType, const char *dbString, Int_t version=-1, Int_t subVersion=-1)
TMap * fStorageMap
List of the retrieved object Id&#39;s (to be streamed to file)
const TMap * GetEntryCache() const
TFile * fSnapshotFile
flag saying if we are in snapshot mode
Bool_t GetCacheFlag() const
void UnsetDefaultStorage()
Bool_t GetRaw() const
TList * GetAll(const AliCDBId &query)
Bool_t IsOCDBUploadMode() const
Definition: AliCDBManager.h:83
Bool_t HasStorage(const char *dbString) const
TString fCvmfsOcdb
const TMap * GetStorageMap() const
Definition: AliCDBManager.h:47
TList * fIds
cache for in-memory objects to override objects on storage (to be used online)
TMap fSpecificStorages
list of active storages
AliCDBParam * GetRefParam() const
Definition: AliCDBManager.h:40
Bool_t SetOCDBUploadMode()
Bool_t fRaw
flag for uploads to Official CDBs (upload to cvmfs must follow upload to AliEn)
Bool_t Put(TObject *object, const AliCDBId &id, AliCDBMetaData *metaData, const char *mirrors="", DataType type=kPrivate)
void GetLHCPeriodAgainstAlienFile(Int_t run, TString &lhcPeriod, Int_t &startRun, Int_t &endRun)
void SetRun(Int_t run)
Definition: AliCDBEntry.h:18
void SetDrain(const char *dbString)
TString fLHCPeriod
TF1 * f
Definition: interpolTest.C:21
void UnloadFromCache(const char *path)
void SetDefaultStorage(const char *dbString)
void Print(Option_t *option="") const
void UnsetDrain()
Definition: AliCDBManager.h:77
Bool_t DiffObjects(const char *cdbFile1, const char *cdbFile2) const
Int_t GetStartRunLHCPeriod()
void SetType(const char *type)
void DumpToLightSnapshotFile(const char *lightSnapshotFileName) const
void AlienToCvmfsUri(TString &uriString) const
void DestroyActiveStorage(AliCDBStorage *storage)
const TMap * GetSnapshotMap() const
AliCDBStorage * GetDefaultStorage() const
Definition: AliCDBManager.h:61
static Int_t runNumber
Definition: pdc06_config.C:126
static TString fgkMCIdealStorage
Bool_t InitFromSnapshot(const char *snapshotFileName, Bool_t overwrite=kTRUE)
ULong64_t SetLock(Bool_t lockFlag=kTRUE, ULong64_t key=0)
void SetMaxDate(TTimeStamp &maxDate)
time_t GetMaxDate() const
const char * GetURI(const char *path)
static AliCDBManager * Instance(TMap *entryCache=NULL, Int_t run=-1)
Bool_t IsDefaultStorageSet() const
Definition: AliCDBManager.h:60
void SetMirrorSEs(const char *mirrors)
AliCDBStorage * GetActiveStorage(const AliCDBParam *param)
AliCDBParam * fRefParam
Int_t fEndRunLHCPeriod
TMap fEntryCache
list of detector-specific storages
TString GetLHCPeriod()
TMap fPromptEntryCache
cache of the retrieved objects
Bool_t SetSnapshotMode(const char *snapshotFileName="OCDB.root")
void SetRaw(Bool_t rawFlag)
AliCDBParam * SelectSpecificStorage(const TString &path)
void GetLHCPeriodAgainstCvmfsFile(Int_t run, TString &lhcPeriod, Int_t &startRun, Int_t &endRun)
void ValidateCvmfsCase() const
Bool_t fLock
The prompt cache flag.
static TString fgkOCDBFolderXMLfile
AliCDBStorage * fDefaultStorage
List of short lived objects.
Bool_t GetPromptCacheFlag() const
Definition: AliCDBManager.h:70
const TList * GetSnapshotRetrievedIds() const