Skip to content

Commit c9d7a60

Browse files
committed
Extend CCDB functions with optional headers
1 parent 9c91409 commit c9d7a60

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

CCDB/include/CCDB/BasicCCDBManager.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,9 @@ class CCDBManagerInstance
9898
/// query timestamp
9999
long getTimestamp() const { return mTimestamp; }
100100

101-
/// retrieve an object of type T from CCDB as stored under path and timestamp
101+
/// retrieve an object of type T from CCDB as stored under path and timestamp. Optional to get the headers
102102
template <typename T>
103-
T* getForTimeStamp(std::string const& path, long timestamp);
103+
T* getForTimeStamp(std::string const& path, long timestamp, std::map<std::string, std::string>* headers = nullptr);
104104

105105
/// retrieve an object of type T from CCDB as stored under path and using the timestamp in the middle of the run
106106
template <typename T>
@@ -235,7 +235,7 @@ class CCDBManagerInstance
235235
};
236236

237237
template <typename T>
238-
T* CCDBManagerInstance::getForTimeStamp(std::string const& path, long timestamp)
238+
T* CCDBManagerInstance::getForTimeStamp(std::string const& path, long timestamp, std::map<std::string, std::string>* headers)
239239
{
240240
mHeaders.clear(); // we clear at the beginning; to allow to retrieve the header information in a subsequent call
241241
T* ptr = nullptr;
@@ -262,6 +262,9 @@ T* CCDBManagerInstance::getForTimeStamp(std::string const& path, long timestamp)
262262
auto& cached = mCache[path];
263263
cached.queries++;
264264
if ((!isOnline() && cached.isCacheValid(timestamp)) || (mCheckObjValidityEnabled && cached.isValid(timestamp))) {
265+
if (headers) {
266+
*headers = mHeaders;
267+
}
265268
return reinterpret_cast<T*>(cached.noCleanupPtr ? cached.noCleanupPtr : cached.objPtr.get());
266269
}
267270
ptr = mCCDBAccessor.retrieveFromTFileAny<T>(path, mMetaData, timestamp, &mHeaders, cached.uuid,
@@ -321,6 +324,9 @@ T* CCDBManagerInstance::getForTimeStamp(std::string const& path, long timestamp)
321324
mFailures++;
322325
}
323326
}
327+
if (headers) {
328+
*headers = mHeaders; // Do a deep copy of the headers
329+
}
324330
auto end = std::chrono::system_clock::now();
325331
mTimerMS += std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count();
326332
return ptr;

CCDB/include/CCDB/CcdbApi.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ class CcdbApi //: public DatabaseInterface
281281
* @return: True in case operation successful or false if there was a failure/problem.
282282
*/
283283
bool retrieveBlob(std::string const& path, std::string const& targetdir, std::map<std::string, std::string> const& metadata, long timestamp,
284-
bool preservePathStructure = true, std::string const& localFileName = "snapshot.root", std::string const& createdNotAfter = "", std::string const& createdNotBefore = "") const;
284+
bool preservePathStructure = true, std::string const& localFileName = "snapshot.root", std::string const& createdNotAfter = "", std::string const& createdNotBefore = "", std::map<std::string, std::string>* headers = nullptr) const;
285285

286286
/**
287287
* Retrieve the headers of a CCDB entry, if it exists.

CCDB/src/CcdbApi.cxx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -831,7 +831,7 @@ TObject* CcdbApi::retrieveFromTFile(std::string const& path, std::map<std::strin
831831
}
832832

833833
bool CcdbApi::retrieveBlob(std::string const& path, std::string const& targetdir, std::map<std::string, std::string> const& metadata,
834-
long timestamp, bool preservePath, std::string const& localFileName, std::string const& createdNotAfter, std::string const& createdNotBefore) const
834+
long timestamp, bool preservePath, std::string const& localFileName, std::string const& createdNotAfter, std::string const& createdNotBefore, std::map<std::string, std::string>* outHeaders) const
835835
{
836836

837837
// we setup the target path for this blob
@@ -879,6 +879,9 @@ bool CcdbApi::retrieveBlob(std::string const& path, std::string const& targetdir
879879
CCDBQuery querysummary(path, metadata, timestamp);
880880

881881
updateMetaInformationInLocalFile(targetpath.c_str(), &headers, &querysummary);
882+
if (outHeaders) {
883+
*outHeaders = std::move(headers); // Re-use the same headers to give back to the callee
884+
}
882885
return true;
883886
}
884887

0 commit comments

Comments
 (0)