Skip to content

Commit 3b4c9cf

Browse files
mpucciosawenzel
authored andcommitted
feat(CCDB): add getForRunMiddleTimeStamp method
Adds a new method `getForRunMiddleTimeStamp` to the `CCDBManagerInstance` class. This method retrieves an object of type `T` from the CCDB using the path and the middle timestamp of the given run number. This is a useful utility method for cases where the exact timestamp does not matter and the run number is available. Optionally use metadata in the query Rename the function Fix setting of the metadata
1 parent dbfe3c6 commit 3b4c9cf

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

CCDB/include/CCDB/BasicCCDBManager.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,10 @@ class CCDBManagerInstance
102102
template <typename T>
103103
T* getForTimeStamp(std::string const& path, long timestamp);
104104

105+
/// retrieve an object of type T from CCDB as stored under path and using the timestamp in the middle of the run
106+
template <typename T>
107+
T* getForRun(std::string const& path, int runNumber, bool setRunMetadata = false);
108+
105109
/// retrieve an object of type T from CCDB as stored under path, timestamp and metaData
106110
template <typename T>
107111
T* getSpecific(std::string const& path, long timestamp = -1, MD metaData = MD())
@@ -311,6 +315,20 @@ T* CCDBManagerInstance::getForTimeStamp(std::string const& path, long timestamp)
311315
return ptr;
312316
}
313317

318+
template <typename T>
319+
T* CCDBManagerInstance::getForRun(std::string const& path, int runNumber, bool setRunMetadata)
320+
{
321+
auto [start, stop] = getRunDuration(runNumber);
322+
if (start < 0 || stop < 0) {
323+
if (mFatalWhenNull) {
324+
reportFatal(std::string("Failed to get run duration for run ") + std::to_string(runNumber));
325+
}
326+
return nullptr;
327+
}
328+
mMetaData = setRunMetadata ? MD{{"runNumber", std::to_string(runNumber)}} : MD{};
329+
return getForTimeStamp<T>(path, start / 2 + stop / 2);
330+
}
331+
314332
class BasicCCDBManager : public CCDBManagerInstance
315333
{
316334
public:

0 commit comments

Comments
 (0)