1 #ifndef ALI_CDB_MANAGER_H
2 #define ALI_CDB_MANAGER_H
4 /* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
5 * See cxx source for full Copyright notice */
7 /////////////////////////////////////////////////////////////////////
9 // class AliCDBManager //
11 /////////////////////////////////////////////////////////////////////
25 class AliCDBStorageFactory;
28 class AliCDBManager: public TObject {
31 enum DataType {kCondition=0, kReference, kPrivate};
33 void RegisterFactory(AliCDBStorageFactory* factory);
35 Bool_t HasStorage(const char* dbString) const;
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);
42 AliCDBStorage* GetStorage(const char* dbString);
44 TList* GetActiveStorages();
46 const TMap* GetStorageMap() const {return fStorageMap;}
47 const TList* GetRetrievedIds() const {return fIds;}
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);
55 Bool_t IsDefaultStorageSet() const {return fDefaultStorage != 0;}
56 AliCDBStorage* GetDefaultStorage() const {return fDefaultStorage;}
57 void UnsetDefaultStorage();
59 void SetSpecificStorage(const char* calibType, const char* dbString);
61 AliCDBStorage* GetSpecificStorage(const char* calibType);
63 void SetDrain(const char* dbString);
64 void SetDrain(const AliCDBParam* param);
65 void SetDrain(AliCDBStorage *storage);
67 Bool_t IsDrainSet() const {return fDrainStorage != 0;}
69 Bool_t Drain(AliCDBEntry* entry);
71 void UnsetDrain(){fDrainStorage = 0x0;}
73 AliCDBEntry* Get(const AliCDBId& query, Bool_t forceCaching=kFALSE, Bool_t doCatch=kFALSE);
74 AliCDBEntry* Get(const AliCDBPath& path, Int_t runNumber=-1,
75 Int_t version = -1, Int_t subVersion = -1);
76 AliCDBEntry* Get(const AliCDBPath& path, const AliCDBRunRange& runRange,
77 Int_t version = -1, Int_t subVersion = -1);
78 AliCDBEntry* GetEntryFromSnapshot(const char* path);
80 const char* GetURI(const char* path);
82 TList* GetAll(const AliCDBId& query);
83 TList* GetAll(const AliCDBPath& path, Int_t runNumber=-1,
84 Int_t version = -1, Int_t subVersion = -1);
85 TList* GetAll(const AliCDBPath& path, const AliCDBRunRange& runRange,
86 Int_t version = -1, Int_t subVersion = -1);
88 Bool_t Put(TObject* object, const AliCDBId& id, AliCDBMetaData* metaData,
89 const char* mirrors="", DataType type=kPrivate);
90 Bool_t Put(AliCDBEntry* entry, const char* mirrors="", DataType type=kPrivate);
92 void SetCacheFlag(Bool_t cacheFlag) {fCache=cacheFlag;}
93 Bool_t GetCacheFlag() const {return fCache;}
95 ULong64_t SetLock(Bool_t lockFlag=kTRUE, ULong64_t key=0);
96 Bool_t GetLock() const {return fLock;}
98 void SetRaw(Bool_t rawFlag){fRaw=rawFlag;}
99 Bool_t GetRaw() const {return fRaw;}
101 void SetRun(Int_t run);
102 Int_t GetRun() const {return fRun;}
104 void SetMirrorSEs(const char* mirrors);
105 const char* GetMirrorSEs() const;
107 void DestroyActiveStorages();
108 void DestroyActiveStorage(AliCDBStorage* storage);
112 void Print(Option_t* option="") const;
114 static void Destroy();
118 void UnloadFromCache(const char* path);
119 const TMap* GetEntryCache() const {return &fEntryCache;}
121 Bool_t IsShortLived(const char* path);
123 static AliCDBManager* Instance(TMap *entryCache = NULL, Int_t run = -1);
126 void InitFromCache(TMap *entryCache, Int_t run);
127 Bool_t InitFromSnapshot(const char* snapshotFileName, Bool_t overwrite=kTRUE);
128 Bool_t SetSnapshotMode(const char* snapshotFileName="OCDB.root");
129 void UnsetSnapshotMode() {fSnapshotMode=kFALSE;}
130 void DumpToSnapshotFile(const char* snapshotFileName, Bool_t singleKeys);
132 Int_t GetStartRunLHCPeriod();
133 Int_t GetEndRunLHCPeriod();
134 TString GetLHCPeriod();
135 TString GetCvmfsOcdbTag() const {return fCvmfsOcdb;}
137 Bool_t DiffObjects(const char *cdbFile1, const char *cdbFile2) const;
141 static TString fgkCondUri; // URI of the Conditions data base folder
142 static TString fgkRefUri; // URI of the Reference data base folder
143 static TString fgkMCIdealStorage; // URI of the MC-Ideal Conditions data base folder form MC data
144 static TString fgkMCFullStorage; // URI of the MC-Full Conditions data base folder form MC data
145 static TString fgkMCResidualStorage; // URI of the MC-Residual Conditions data base folder form MC data
146 static TString fgkOCDBFolderXMLfile; // alien path of the XML file for OCDB folder <--> Run range correspondance
149 AliCDBManager(const AliCDBManager & source);
150 AliCDBManager & operator=(const AliCDBManager & source);
152 static AliCDBManager* fgInstance; // AliCDBManager instance
154 AliCDBStorage* GetStorage(const AliCDBParam* param);
155 AliCDBStorage* GetActiveStorage(const AliCDBParam* param);
156 void PutActiveStorage(AliCDBParam* param, AliCDBStorage* storage);
157 void SetSpecificStorage(const char* calibType, const AliCDBParam* param);
158 void AlienToCvmfsUri(TString& uriString) const;
159 void ValidateCvmfsCase() const;
161 void CacheEntry(const char* path, AliCDBEntry* entry);
163 AliCDBParam* SelectSpecificStorage(const TString& path);
165 AliCDBId* GetId(const AliCDBId& query);
166 AliCDBId* GetId(const AliCDBPath& path, Int_t runNumber=-1,
167 Int_t version = -1, Int_t subVersion = -1);
168 AliCDBId* GetId(const AliCDBPath& path, const AliCDBRunRange& runRange,
169 Int_t version = -1, Int_t subVersion = -1);
173 void InitShortLived();
174 // void InitFromCache(TMap *entryCache, Int_t run);
177 TList fFactories; //! list of registered storage factories
178 TMap fActiveStorages; //! list of active storages
179 TMap fSpecificStorages; //! list of detector-specific storages
180 TMap fEntryCache; //! cache of the retrieved objects
182 TList* fIds; //! List of the retrieved object Id's (to be streamed to file)
183 TMap* fStorageMap; //! list of storages (to be streamed to file)
184 TList* fShortLived; //! List of short lived objects
186 AliCDBStorage *fDefaultStorage; //! pointer to default storage
187 AliCDBStorage *fDrainStorage; //! pointer to drain storage
189 AliCDBParam* fCondParam; // Conditions data storage parameters
190 AliCDBParam* fRefParam; // Reference data storage parameters
192 Int_t fRun; //! The run number
193 Bool_t fCache; //! The cache flag
194 Bool_t fLock; //! Lock flag, if ON default storage and run number cannot be reset
196 Bool_t fSnapshotMode; //! flag saying if we are in snapshot mode
197 TFile *fSnapshotFile;
199 Bool_t fRaw; // flag to say whether we are in the raw case
200 TString fCvmfsOcdb; // set from $OCDB_PATH, points to a cvmfs AliRoot package
201 Int_t fStartRunLHCPeriod; // 1st run of the LHC period set
202 Int_t fEndRunLHCPeriod; // last run of the LHC period set
203 TString fLHCPeriod; // LHC period alien folder
206 ULong64_t fKey; //! Key for locking/unlocking
209 ClassDef(AliCDBManager, 0);
213 /////////////////////////////////////////////////////////////////////
215 // class AliCDBStorageFactory //
217 /////////////////////////////////////////////////////////////////////
220 class AliCDBStorageFactory: public TObject {
221 friend class AliCDBManager;
224 virtual ~AliCDBStorageFactory(){}
225 virtual Bool_t Validate(const char* dbString) = 0;
226 virtual AliCDBParam* CreateParameter(const char* dbString) = 0;
229 virtual AliCDBStorage* Create(const AliCDBParam* param) = 0;
231 ClassDef(AliCDBStorageFactory, 0);
234 /////////////////////////////////////////////////////////////////////
236 // class AliCDBParam //
238 /////////////////////////////////////////////////////////////////////
240 class AliCDBParam: public TObject {
245 virtual ~AliCDBParam();
247 const TString& GetType() const {return fType;};
248 const TString& GetURI() const {return fURI;};
250 virtual AliCDBParam* CloneParam() const = 0;
254 void SetType(const char* type) {fType = type;};
255 void SetURI(const char* uri) {fURI = uri;};
259 TString fType; //! CDB type
260 TString fURI; //! CDB URI
262 ClassDef(AliCDBParam, 0);