Skip to content

Commit f4a8aad

Browse files
committed
Devs to Publish/Query AggregatedRunInfo for MC
This commit is * slightly changing BasicCCDBManager to be able to - retrieve meta information headers - retrieve the underlying CCDB api for reuse * offering an API to publish AggregatedRunInfo on CCDB with MC production tags as meta-data. This allows to keep information about how MC was done for certain runs ... in particular timeframe length * offering an API to query AggregatedRunInfo used in MC from CCDB - this could be used from the analysis side
1 parent 108aeca commit f4a8aad

File tree

3 files changed

+77
-7
lines changed

3 files changed

+77
-7
lines changed

CCDB/include/CCDB/BasicCCDBManager.h

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,16 +108,20 @@ class CCDBManagerInstance
108108

109109
/// retrieve an object of type T from CCDB as stored under path, timestamp and metaData
110110
template <typename T>
111-
T* getSpecific(std::string const& path, long timestamp = -1, MD metaData = MD())
111+
T* getSpecific(std::string const& path, long timestamp = -1, MD metaData = MD(), std::map<std::string, std::string>* headers = nullptr)
112112
{
113113
// TODO: add some error info/handling when failing
114114
mMetaData = metaData;
115-
return getForTimeStamp<T>(path, timestamp);
115+
auto obj = getForTimeStamp<T>(path, timestamp);
116+
if (headers) {
117+
*headers = mHeaders;
118+
}
119+
return obj;
116120
}
117121

118122
/// retrieve an object of type T from CCDB as stored under path and using the timestamp in the middle of the run + metadata. The run number is provided separately to conform to typical analysis use (in which case metadata does not include runNumber)
119123
template <typename T>
120-
T* getSpecificForRun(std::string const& path, int runNumber, MD metaData = MD());
124+
T* getSpecificForRun(std::string const& path, int runNumber, MD const& metaData = MD());
121125

122126
/// detect online processing modes (i.e. CCDB objects may be updated in the lifetime of the manager)
123127
bool isOnline() const { return mDeplMode == o2::framework::DeploymentMode::OnlineAUX || mDeplMode == o2::framework::DeploymentMode::OnlineDDS || mDeplMode == o2::framework::DeploymentMode::OnlineECS; }
@@ -129,6 +133,9 @@ class CCDBManagerInstance
129133
return getForTimeStamp<T>(path, mTimestamp);
130134
}
131135

136+
// gain access to underlaying CCDB layer (to allow for more complex queries without need to reinit another API)
137+
CcdbApi& getCCDBAccessor() { return mCCDBAccessor; }
138+
132139
bool isHostReachable() const { return mCCDBAccessor.isHostReachable(); }
133140

134141
/// clear all entries in the cache
@@ -230,11 +237,12 @@ class CCDBManagerInstance
230237
template <typename T>
231238
T* CCDBManagerInstance::getForTimeStamp(std::string const& path, long timestamp)
232239
{
240+
mHeaders.clear(); // we clear at the beginning; to allow to retrieve the header information in a subsequent call
233241
T* ptr = nullptr;
234242
mQueries++;
235243
auto start = std::chrono::system_clock::now();
236244
if (!isCachingEnabled()) {
237-
ptr = mCCDBAccessor.retrieveFromTFileAny<T>(path, mMetaData, timestamp, nullptr, "",
245+
ptr = mCCDBAccessor.retrieveFromTFileAny<T>(path, mMetaData, timestamp, &mHeaders, "",
238246
mCreatedNotAfter ? std::to_string(mCreatedNotAfter) : "",
239247
mCreatedNotBefore ? std::to_string(mCreatedNotBefore) : "");
240248
if (!ptr) {
@@ -305,7 +313,6 @@ T* CCDBManagerInstance::getForTimeStamp(std::string const& path, long timestamp)
305313
} else {
306314
cached.cacheValidUntil = -1;
307315
}
308-
mHeaders.clear();
309316
mMetaData.clear();
310317
if (!ptr) {
311318
if (mFatalWhenNull) {
@@ -328,7 +335,7 @@ T* CCDBManagerInstance::getForRun(std::string const& path, int runNumber, bool s
328335
}
329336

330337
template <typename T>
331-
T* CCDBManagerInstance::getSpecificForRun(std::string const& path, int runNumber, MD metaData)
338+
T* CCDBManagerInstance::getSpecificForRun(std::string const& path, int runNumber, MD const& metaData)
332339
{
333340
auto [start, stop] = getRunDuration(runNumber, mFatalWhenNull);
334341
if (start < 0 || stop < 0) {

DataFormats/Parameters/include/DataFormatsParameters/AggregatedRunInfo.h

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ struct AggregatedRunInfo {
3232
int runNumber = 0; // run number
3333
int64_t sor = 0; // best known timestamp for the start of run
3434
int64_t eor = 0; // best known timestamp for end of run
35-
int64_t orbitsPerTF = 0; // number of orbits per TF
35+
int64_t orbitsPerTF = 0; // number of orbits per TF (takes precedence over that in GRPECS)
3636
int64_t orbitReset = 0; // timestamp of orbit reset before run
3737
int64_t orbitSOR = 0; // orbit when run starts after orbit reset
3838
int64_t orbitEOR = 0; // orbit when run ends after orbit reset
@@ -43,6 +43,19 @@ struct AggregatedRunInfo {
4343
// fills and returns AggregatedRunInfo for a given run number.
4444
static AggregatedRunInfo buildAggregatedRunInfo(o2::ccdb::CCDBManagerInstance& ccdb, int runnumber);
4545
static AggregatedRunInfo buildAggregatedRunInfo(int runnumber, long sorMS, long eorMS, long orbitResetMUS, const o2::parameters::GRPECSObject* grpecs, const std::vector<Long64_t>* ctfFirstRunOrbitVec);
46+
47+
// Special method for MC becayse MC may use extra settings or different values.
48+
// The idea is to rely on a composite RunInfo object that a MC production uploaded to CCDB.
49+
// This may depend:
50+
// - on the runnumber
51+
// - the lpm_prod_tag as a unique specifier of a MC GRID campaign
52+
// - maybe username -> to allow for analysis of user-generated AO2D. The username determines the base-path where to look for CCDB objects
53+
// The return value is a pointer to AggregatedRunInfo if such object exists or nullptr otherwise
54+
static AggregatedRunInfo const* lookupAggregatedRunInfo_MC(o2::ccdb::CCDBManagerInstance& ccdb, int run_number, std::string const& lpm_prod_tag, std::string const& username = "aliprod");
55+
56+
static void publishToCCDB_MC(AggregatedRunInfo const& info, o2::ccdb::CCDBManagerInstance& ccdb, int run_number, std::string const& lpm_prod_tag, std::string const& username);
57+
58+
ClassDefNV(AggregatedRunInfo, 1);
4659
};
4760

4861
} // namespace o2::parameters

DataFormats/Parameters/src/AggregatedRunInfo.cxx

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,53 @@ o2::parameters::AggregatedRunInfo AggregatedRunInfo::buildAggregatedRunInfo(int
8383
}
8484
return AggregatedRunInfo{runnumber, sorMS, eorMS, nOrbitsPerTF, orbitResetMUS, orbitSOR, orbitEOR, grpecs};
8585
}
86+
87+
namespace
88+
{
89+
90+
std::string getFullPath_MC(std::string username)
91+
{
92+
// construct the path where to lookup
93+
std::string path = "/Users/" + std::string(1, username[0]) + "/" + username;
94+
std::string fullpath = path + "/" + "MCAggregatedRunInfo";
95+
return fullpath;
96+
}
97+
98+
} // namespace
99+
100+
o2::parameters::AggregatedRunInfo const* AggregatedRunInfo::lookupAggregatedRunInfo_MC(o2::ccdb::CCDBManagerInstance& ccdb, int run_number, std::string const& lpm_prod_tag, std::string const& username)
101+
{
102+
// we simply look if we find a prebuild AggregatedRunInfo, stored from an MC production, under the expected location
103+
104+
std::map<std::string, std::string> headers;
105+
std::map<std::string, std::string> metaDataFilter;
106+
metaDataFilter["lpm_prod_tag"] = lpm_prod_tag;
107+
108+
bool oldFatalState = ccdb.getFatalWhenNull();
109+
ccdb.setFatalWhenNull(false);
110+
auto obj = ccdb.getSpecific<o2::parameters::AggregatedRunInfo>(getFullPath_MC(username), run_number, metaDataFilter, &headers);
111+
ccdb.setFatalWhenNull(oldFatalState);
112+
return obj;
113+
}
114+
115+
void o2::parameters::AggregatedRunInfo::publishToCCDB_MC(AggregatedRunInfo const& info, o2::ccdb::CCDBManagerInstance& ccdb, int run_number, std::string const& lpm_prod_tag, std::string const& username)
116+
{
117+
// we upload the info to the MC path on CCDB - but we check first of all of this is already there
118+
auto path = getFullPath_MC(username);
119+
std::map<std::string, std::string> meta;
120+
meta["lpm_prod_tag"] = lpm_prod_tag;
121+
122+
auto cl = TClass::GetClass(typeid(AggregatedRunInfo));
123+
auto ti = cl->GetTypeInfo();
124+
125+
auto& api = ccdb.getCCDBAccessor();
126+
127+
auto headers = api.retrieveHeaders(path, meta, run_number);
128+
if (headers.find("lpm_prod_tag") != headers.end()) {
129+
LOG(info) << "AggregatedRunInfo Object already present on CCDB for this production tag and user. Not doing anything";
130+
// already uploaded
131+
return;
132+
}
133+
134+
api.storeAsTFile_impl(&info, *ti, path, meta, run_number, run_number + 1);
135+
}

0 commit comments

Comments
 (0)