@@ -45,11 +45,23 @@ class CCDBManagerInstance
4545 void * noCleanupPtr = nullptr ; // if assigned instead of objPtr, no cleanup will be done on exit (for global objects cleaned up by the root, e.g. gGeoManager)
4646 std::string uuid;
4747 long startvalidity = 0 ;
48- long endvalidity = 0 ;
48+ long endvalidity = -1 ;
49+ bool isBlob = false ; // is this raw blob or parsed object?
4950 bool isValid (long ts) { return ts < endvalidity && ts > startvalidity; }
51+ void clear ()
52+ {
53+ objPtr.reset ();
54+ uuid = " " ;
55+ startvalidity = 0 ;
56+ endvalidity = -1 ;
57+ isBlob = false ;
58+ }
5059 };
5160
5261 public:
62+ using BLOB = std::vector<char >;
63+ using MD = std::map<std::string, std::string>;
64+
5365 CCDBManagerInstance (std::string const & path) : mCCDBAccessor {}
5466 {
5567 mCCDBAccessor .init (path);
@@ -77,7 +89,7 @@ class CCDBManagerInstance
7789
7890 // / retrieve an object of type T from CCDB as stored under path, timestamp and metaData
7991 template <typename T>
80- T* getSpecific (std::string const & path, long timestamp = -1 , std::map<std::string, std::string> metaData = std::map<std::string, std::string> ())
92+ T* getSpecific (std::string const & path, long timestamp = -1 , MD metaData = MD ())
8193 {
8294 // TODO: add some error info/handling when failing
8395 mMetaData = metaData;
@@ -91,6 +103,11 @@ class CCDBManagerInstance
91103 return getForTimeStamp<T>(path, mTimestamp );
92104 }
93105
106+ // / aliases for BLOB retrieval
107+ BLOB * getBlobForTimeStamp (std::string const & path, long timestamp) { return getForTimeStamp<BLOB >(path, timestamp); }
108+ BLOB * getSpecificBlob (std::string const & path, long timestamp = -1 , MD metaData = MD ()) { return getSpecific<BLOB >(path, timestamp, metaData); }
109+ BLOB * getBlob (std::string const & path) { return get<BLOB >(path); }
110+
94111 bool isHostReachable () const { return mCCDBAccessor .isHostReachable (); }
95112
96113 // / clear all entries in the cache
@@ -143,47 +160,78 @@ class CCDBManagerInstance
143160 private:
144161 // method to print (fatal) error
145162 void reportFatal (std::string_view s);
146-
163+ BLOB * createBlob (std::string const & path,
164+ MD const & metadata, long timestamp,
165+ MD * headers, std::string const & etag,
166+ const std::string& createdNotAfter, const std::string& createdNotBefore);
147167 // we access the CCDB via the CURL based C++ API
148168 o2::ccdb::CcdbApi mCCDBAccessor ;
149169 std::unordered_map<std::string, CachedObject> mCache ; // ! map for {path, CachedObject} associations
150- std::map<std::string, std::string> mMetaData ; // some dummy object needed to talk to CCDB API
151- std::map<std::string, std::string> mHeaders ; // headers to retrieve tags
170+ MD mMetaData ; // some dummy object needed to talk to CCDB API
171+ MD mHeaders ; // headers to retrieve tags
152172 long mTimestamp {o2::ccdb::getCurrentTimestamp ()}; // timestamp to be used for query (by default "now")
153173 bool mCanDefault = false ; // whether default is ok --> useful for testing purposes done standalone/isolation
154174 bool mCachingEnabled = true ; // whether caching is enabled
155175 bool mCheckObjValidityEnabled = false ; // wether the validity of cached object is checked before proceeding to a CCDB API query
156176 long mCreatedNotAfter = 0 ; // upper limit for object creation timestamp (TimeMachine mode) - If-Not-After HTTP header
157177 long mCreatedNotBefore = 0 ; // lower limit for object creation timestamp (TimeMachine mode) - If-Not-Before HTTP header
158178 bool mFatalWhenNull = true ; // if nullptr blob replies should be treated as fatal (can be set by user)
179+
180+ ClassDefNV (CCDBManagerInstance, 1 );
159181};
160182
161183template <typename T>
162184T* CCDBManagerInstance::getForTimeStamp (std::string const & path, long timestamp)
163185{
186+ T* ptr = nullptr ;
164187 if (!isCachingEnabled ()) {
165- auto ptr = mCCDBAccessor .retrieveFromTFileAny <T>(path, mMetaData , timestamp, nullptr , " " ,
166- mCreatedNotAfter ? std::to_string (mCreatedNotAfter ) : " " ,
167- mCreatedNotBefore ? std::to_string (mCreatedNotBefore ) : " " );
188+ if constexpr (std::is_same<T, BLOB >::value) {
189+ ptr = createBlob (path, mMetaData , timestamp, nullptr , " " ,
190+ mCreatedNotAfter ? std::to_string (mCreatedNotAfter ) : " " ,
191+ mCreatedNotBefore ? std::to_string (mCreatedNotBefore ) : " " );
192+ } else {
193+ ptr = mCCDBAccessor .retrieveFromTFileAny <T>(path, mMetaData , timestamp, nullptr , " " ,
194+ mCreatedNotAfter ? std::to_string (mCreatedNotAfter ) : " " ,
195+ mCreatedNotBefore ? std::to_string (mCreatedNotBefore ) : " " );
196+ }
168197 if (!ptr && mFatalWhenNull ) {
169198 reportFatal (std::string (" Got nullptr from CCDB for path " ) + path + std::string (" and timestamp " ) + std::to_string (timestamp));
170199 }
171200 return ptr;
172201 }
173202 auto & cached = mCache [path];
203+ if constexpr (std::is_same<T, BLOB >::value) { // check if cached object type is consistent with requested one
204+ if (!cached.isBlob ) {
205+ cached.clear ();
206+ }
207+ } else {
208+ if (cached.isBlob ) {
209+ cached.clear ();
210+ }
211+ }
174212 if (mCheckObjValidityEnabled && cached.isValid (timestamp)) {
175213 return reinterpret_cast <T*>(cached.noCleanupPtr ? cached.noCleanupPtr : cached.objPtr .get ());
176214 }
177-
178- T* ptr = mCCDBAccessor .retrieveFromTFileAny <T>(path, mMetaData , timestamp, &mHeaders , cached.uuid ,
179- mCreatedNotAfter ? std::to_string (mCreatedNotAfter ) : " " ,
180- mCreatedNotBefore ? std::to_string (mCreatedNotBefore ) : " " );
215+ if constexpr (std::is_same<T, BLOB >::value) {
216+ ptr = createBlob (path, mMetaData , timestamp, &mHeaders , cached.uuid ,
217+ mCreatedNotAfter ? std::to_string (mCreatedNotAfter ) : " " ,
218+ mCreatedNotBefore ? std::to_string (mCreatedNotBefore ) : " " );
219+ } else {
220+ ptr = mCCDBAccessor .retrieveFromTFileAny <T>(path, mMetaData , timestamp, &mHeaders , cached.uuid ,
221+ mCreatedNotAfter ? std::to_string (mCreatedNotAfter ) : " " ,
222+ mCreatedNotBefore ? std::to_string (mCreatedNotBefore ) : " " );
223+ }
181224 if (ptr) { // new object was shipped, old one (if any) is not valid anymore
182225 if constexpr (std::is_same<TGeoManager, T>::value) { // some special objects cannot be cached to shared_ptr since root may delete their raw global pointer
183226 cached.noCleanupPtr = ptr;
184227 } else {
185228 cached.objPtr .reset (ptr);
186229 }
230+ if constexpr (std::is_same<T, BLOB >::value) {
231+ cached.isBlob = true ;
232+ } else {
233+ cached.isBlob = false ;
234+ }
187235 cached.uuid = mHeaders [" ETag" ];
188236 cached.startvalidity = std::stol (mHeaders [" Valid-From" ]);
189237 cached.endvalidity = std::stol (mHeaders [" Valid-Until" ]);
0 commit comments