Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions CCDB/include/CCDB/BasicCCDBManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,16 +108,20 @@ class CCDBManagerInstance

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

/// 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)
template <typename T>
T* getSpecificForRun(std::string const& path, int runNumber, MD metaData = MD());
T* getSpecificForRun(std::string const& path, int runNumber, MD const& metaData = MD());

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

// gain access to underlaying CCDB layer (to allow for more complex queries without need to reinit another API)
CcdbApi& getCCDBAccessor() { return mCCDBAccessor; }

bool isHostReachable() const { return mCCDBAccessor.isHostReachable(); }

/// clear all entries in the cache
Expand Down Expand Up @@ -230,11 +237,12 @@ class CCDBManagerInstance
template <typename T>
T* CCDBManagerInstance::getForTimeStamp(std::string const& path, long timestamp)
{
mHeaders.clear(); // we clear at the beginning; to allow to retrieve the header information in a subsequent call
T* ptr = nullptr;
mQueries++;
auto start = std::chrono::system_clock::now();
if (!isCachingEnabled()) {
ptr = mCCDBAccessor.retrieveFromTFileAny<T>(path, mMetaData, timestamp, nullptr, "",
ptr = mCCDBAccessor.retrieveFromTFileAny<T>(path, mMetaData, timestamp, &mHeaders, "",
mCreatedNotAfter ? std::to_string(mCreatedNotAfter) : "",
mCreatedNotBefore ? std::to_string(mCreatedNotBefore) : "");
if (!ptr) {
Expand Down Expand Up @@ -305,7 +313,6 @@ T* CCDBManagerInstance::getForTimeStamp(std::string const& path, long timestamp)
} else {
cached.cacheValidUntil = -1;
}
mHeaders.clear();
mMetaData.clear();
if (!ptr) {
if (mFatalWhenNull) {
Expand All @@ -328,7 +335,7 @@ T* CCDBManagerInstance::getForRun(std::string const& path, int runNumber, bool s
}

template <typename T>
T* CCDBManagerInstance::getSpecificForRun(std::string const& path, int runNumber, MD metaData)
T* CCDBManagerInstance::getSpecificForRun(std::string const& path, int runNumber, MD const& metaData)
{
auto [start, stop] = getRunDuration(runNumber, mFatalWhenNull);
if (start < 0 || stop < 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ struct AggregatedRunInfo {
int runNumber = 0; // run number
int64_t sor = 0; // best known timestamp for the start of run
int64_t eor = 0; // best known timestamp for end of run
int64_t orbitsPerTF = 0; // number of orbits per TF
int64_t orbitsPerTF = 0; // number of orbits per TF (takes precedence over that in GRPECS)
int64_t orbitReset = 0; // timestamp of orbit reset before run
int64_t orbitSOR = 0; // orbit when run starts after orbit reset
int64_t orbitEOR = 0; // orbit when run ends after orbit reset
Expand All @@ -43,6 +43,13 @@ struct AggregatedRunInfo {
// fills and returns AggregatedRunInfo for a given run number.
static AggregatedRunInfo buildAggregatedRunInfo(o2::ccdb::CCDBManagerInstance& ccdb, int runnumber);
static AggregatedRunInfo buildAggregatedRunInfo(int runnumber, long sorMS, long eorMS, long orbitResetMUS, const o2::parameters::GRPECSObject* grpecs, const std::vector<Long64_t>* ctfFirstRunOrbitVec);

// Special method for MC because MC may use extra settings or different values.
// Will construct AggregatedRunInfo as in data but override certain values (OrbitsPerTF) if appropriate.
// Needs to be given an lpm production tag as identifier and optionally the username who performed MC.
static AggregatedRunInfo buildAggregatedRunInfo_MC(o2::ccdb::CCDBManagerInstance& ccdb, int run_number, std::string const& lpm_prod_tag, std::string const& username = "aliprod");

ClassDefNV(AggregatedRunInfo, 1);
};

} // namespace o2::parameters
Expand Down
45 changes: 45 additions & 0 deletions DataFormats/Parameters/src/AggregatedRunInfo.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,48 @@ o2::parameters::AggregatedRunInfo AggregatedRunInfo::buildAggregatedRunInfo(int
}
return AggregatedRunInfo{runnumber, sorMS, eorMS, nOrbitsPerTF, orbitResetMUS, orbitSOR, orbitEOR, grpecs};
}

namespace
{

// get path where to find MC production info
std::string getFullPath_MC(std::string const& username, std::string const& lpm_prod_tag)
{
// construct the path where to lookup
std::string path = "/Users/" + std::string(1, username[0]) + "/" + username;
std::string fullpath = path + "/" + "MCProdInfo/" + lpm_prod_tag;
return fullpath;
}

} // namespace

AggregatedRunInfo AggregatedRunInfo::buildAggregatedRunInfo_MC(o2::ccdb::CCDBManagerInstance& ccdb, int run_number, std::string const& lpm_prod_tag, std::string const& username)
{
// (a) lookup the AggregatedRunInfo for the run
// (b) modify/overwrite the info object with MC specific settings (if available)

// For now just the timeframe length is overwritten. We can consider
// to return the full MCProdInfo meta-data to the caller as well.

auto original_info = buildAggregatedRunInfo(ccdb, run_number);

std::map<std::string, std::string> metaDataFilter;
metaDataFilter["lpm_prod_tag"] = lpm_prod_tag;

// fetch the meta information for MC productions
auto header_data = ccdb.getCCDBAccessor().retrieveHeaders(getFullPath_MC(username, lpm_prod_tag), metaDataFilter, run_number);

// adjust timeframe length if we find entry for MC production
auto iter = header_data.find("OrbitsPerTF");
if (iter != header_data.end()) {
auto mc_orbitsPerTF = std::stoi(iter->second);
if (mc_orbitsPerTF != original_info.orbitsPerTF) {
LOG(info) << "Adjusting OrbitsPerTF from " << original_info.orbitsPerTF << " to " << mc_orbitsPerTF << " based on differing MC info";
original_info.orbitsPerTF = mc_orbitsPerTF;
}
} else {
LOG(warn) << "No OrbitsPerTF information found for MC production " << lpm_prod_tag << " and run number " << run_number;
}

return original_info;
}