Skip to content

Commit

Permalink
[EMCAL-1037] Use DPL CCDB fetcher and finalizeCCDD for loading of the…
Browse files Browse the repository at this point in the history
… CTP configuration
  • Loading branch information
mfasDa committed Nov 22, 2023
1 parent 29555cc commit e221117
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 48 deletions.
11 changes: 8 additions & 3 deletions Modules/EMCAL/include/EMCAL/BCTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@

class TH1F;

namespace o2::ctp
{
class CTPConfiguration;
}

using namespace o2::quality_control::core;

namespace o2::quality_control_modules::emcal
Expand Down Expand Up @@ -61,12 +66,12 @@ class BCTask final : public TaskInterface
void endOfCycle() override;
void endOfActivity(const Activity& activity) override;
void reset() override;
void finaliseCCDB(o2::framework::ConcreteDataMatcher& matcher, void* obj) override;

protected:
/// \brief Load trigger configuration for current run and timestamp
/// \param timestamp Timestamp from ProcessingContext
/// \return True if classes were successfully loaded, false otherwise
bool loadTriggerClasses(uint64_t timestamp);
/// \param ctpconfig CTP configuration
void loadTriggerClasses(const o2::ctp::CTPConfiguration* ctpconfig);

/// \brief Check if the class masks are initialized
/// \return True if the class masks are initialized, false otherwise
Expand Down
85 changes: 40 additions & 45 deletions Modules/EMCAL/src/BCTask.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -75,21 +75,15 @@ void BCTask::startOfCycle()

void BCTask::monitorData(o2::framework::ProcessingContext& ctx)
{
bool hasCTPConfig = true;
if (!hasClassMasksLoaded()) {
if (!loadTriggerClasses(ctx.services().get<o2::framework::TimingInfo>().creation)) {
ILOG(Error, Support) << "No trigger classes loaded, processing CTP digits not possible" << ENDM;
hasCTPConfig = false;
}
}
auto ctpconfig = ctx.inputs().get<o2::ctp::CTPConfiguration*>("ctp-config");
auto emctriggers = ctx.inputs().get<gsl::span<o2::emcal::TriggerRecord>>("emcal-triggers");
for (const auto& emctrg : emctriggers) {
if (emctrg.getTriggerBits() & o2::trigger::PhT) {
mBCReadout->Fill(emctrg.getBCData().bc);
}
}

if (hasCTPConfig) {
if (hasClassMasksLoaded()) {
auto ctpdigits = ctx.inputs().get<gsl::span<o2::ctp::CTPDigit>>("ctp-digits");
for (const auto& ctpdigit : ctpdigits) {
auto bc = ctpdigit.intRecord.bc;
Expand Down Expand Up @@ -128,6 +122,17 @@ void BCTask::endOfActivity(const Activity& /*activity*/)
ILOG(Debug, Devel) << "endOfActivity" << ENDM;
}

void BCTask::finaliseCCDB(o2::framework::ConcreteDataMatcher& matcher, void* obj)
{
if (matcher == o2::framework::ConcreteDataMatcher("CTP", "CTPCONFIG", 0)) {
auto triggerconfig = reinterpret_cast<const o2::ctp::CTPConfiguration*>(obj);
if (triggerconfig) {
ILOG(Info, Support) << "Loading EMCAL trigger classes for new trigger configuration: " << ENDM;
loadTriggerClasses(triggerconfig);
}
}
}

void BCTask::reset()
{
// clean all the monitor objects here
Expand Down Expand Up @@ -221,7 +226,7 @@ BCTask::BeamPresenceMode_t BCTask::getBeamPresenceMode(const std::string_view be
return BeamPresenceMode_t::ANY;
}

bool BCTask::loadTriggerClasses(uint64_t timestamp)
void BCTask::loadTriggerClasses(const o2::ctp::CTPConfiguration* ctpconfig)
{
auto tokenize = [](const std::string_view trgclass, char delimiter) -> std::vector<std::string> {
std::vector<std::string> tokens;
Expand All @@ -234,45 +239,35 @@ bool BCTask::loadTriggerClasses(uint64_t timestamp)
return tokens;
};
mAllEMCALClasses.clear();
std::map<std::string, std::string> metadata;
metadata["runNumber"] = std::to_string(mCurrentRun);
// temproary fix to make the task not crashing if the trigger configuration for the given run is not found (O2-4122)
o2::ccdb::BasicCCDBManager::instance().setFatalWhenNull(false);
auto ctpconfig = this->retrieveConditionAny<o2::ctp::CTPConfiguration>("CTP/Config/Config", metadata, timestamp);
if (ctpconfig) {
for (auto& cls : ctpconfig->getCTPClasses()) {
auto trgclsname = boost::algorithm::to_upper_copy(cls.name);
auto tokens = tokenize(trgclsname, '-');
auto triggercluster = tokens[3];
if (triggercluster.find("EMC") == std::string::npos) {
// Not an EMCAL trigger class

for (auto& cls : ctpconfig->getCTPClasses()) {
auto trgclsname = boost::algorithm::to_upper_copy(cls.name);
auto tokens = tokenize(trgclsname, '-');
auto triggercluster = tokens[3];
if (triggercluster.find("EMC") == std::string::npos) {
// Not an EMCAL trigger class
continue;
}
if (mBeamMode != BeamPresenceMode_t::ANY) {
if (tokens[1] != getBeamPresenceModeToken(mBeamMode)) {
// beam mode not matching
continue;
}
if (mBeamMode != BeamPresenceMode_t::ANY) {
if (tokens[1] != getBeamPresenceModeToken(mBeamMode)) {
// beam mode not matching
continue;
}
}
ILOG(Info, Support) << "EMCAL trigger cluster: Found trigger class: " << trgclsname << ENDM;
mAllEMCALClasses.insert(cls.classMask);
if (tokens[0] == mTriggerAliases.find("MB")->second) {
mTriggerClassIndices[EMCMinBias] = cls.classMask;
ILOG(Info, Support) << "Trigger class index EMC min bias: " << mTriggerClassIndices[EMCMinBias] << " (Class name: " << cls.name << ")" << ENDM;
}
if (tokens[0] == mTriggerAliases.find("0EMC")->second) {
mTriggerClassIndices[EMCL0] = cls.classMask;
ILOG(Info, Support) << "Trigger class index EMC L0: " << mTriggerClassIndices[EMCL0] << " (Class name: " << cls.name << ")" << ENDM;
}
if (tokens[0] == mTriggerAliases.find("0DMC")->second) {
mTriggerClassIndices[DMCL0] = cls.classMask;
ILOG(Info, Support) << "Trigger class index DMC L0: " << mTriggerClassIndices[DMCL0] << " (Class name: " << cls.name << ")" << ENDM;
}
}
return true;
} else {
ILOG(Error, Support) << "Failed loading CTP configuration for run " << mCurrentRun << ", timestamp " << timestamp << ENDM;
return false;
ILOG(Info, Support) << "EMCAL trigger cluster: Found trigger class: " << trgclsname << ENDM;
mAllEMCALClasses.insert(cls.classMask);
if (tokens[0] == mTriggerAliases.find("MB")->second) {
mTriggerClassIndices[EMCMinBias] = cls.classMask;
ILOG(Info, Support) << "Trigger class index EMC min bias: " << mTriggerClassIndices[EMCMinBias] << " (Class name: " << cls.name << ")" << ENDM;
}
if (tokens[0] == mTriggerAliases.find("0EMC")->second) {
mTriggerClassIndices[EMCL0] = cls.classMask;
ILOG(Info, Support) << "Trigger class index EMC L0: " << mTriggerClassIndices[EMCL0] << " (Class name: " << cls.name << ")" << ENDM;
}
if (tokens[0] == mTriggerAliases.find("0DMC")->second) {
mTriggerClassIndices[DMCL0] = cls.classMask;
ILOG(Info, Support) << "Trigger class index DMC L0: " << mTriggerClassIndices[DMCL0] << " (Class name: " << cls.name << ")" << ENDM;
}
}
}

Expand Down

0 comments on commit e221117

Please sign in to comment.