Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,11 @@ class DCSProcessor
bool updateVoltagesDPsCCDB();
bool updateCurrentsDPsCCDB();
bool updateEnvDPsCCDB();
bool updateRunDPsCCDB();
// LB: new DPs for Fed
bool updateFedChamberStatusDPsCCDB();
bool updateFedCFGtagDPsCCDB();

// signal that the CCDB object for the voltages should be updated due to change exceeding threshold
bool shouldUpdateVoltages() const { return mShouldUpdateVoltages; }
bool shouldUpdateRun() const { return mShouldUpdateRun; }
// LB: Only update ChamberStatus/CFGtag if both conditions are met (complete DPs and new run)
bool shouldUpdateFedChamberStatus() const { return mFedChamberStatusCompleteDPs && mFirstRunEntryForFedChamberStatusUpdate; }
bool shouldUpdateFedCFGtag() const { return mFedCFGtagCompleteDPs && mFirstRunEntryForFedCFGtagUpdate; }
Expand All @@ -91,14 +88,13 @@ class DCSProcessor
CcdbObjectInfo& getccdbVoltagesDPsInfo() { return mCcdbVoltagesDPsInfo; }
CcdbObjectInfo& getccdbCurrentsDPsInfo() { return mCcdbCurrentsDPsInfo; }
CcdbObjectInfo& getccdbEnvDPsInfo() { return mCcdbEnvDPsInfo; }
CcdbObjectInfo& getccdbRunDPsInfo() { return mCcdbRunDPsInfo; }
CcdbObjectInfo& getccdbFedChamberStatusDPsInfo() { return mCcdbFedChamberStatusDPsInfo; }
CcdbObjectInfo& getccdbFedCFGtagDPsInfo() { return mCcdbFedCFGtagDPsInfo; }

const std::unordered_map<DPID, TRDDCSMinMaxMeanInfo>& getTRDGasDPsInfo() const { return mTRDDCSGas; }
const std::unordered_map<DPID, float>& getTRDVoltagesDPsInfo() const { return mTRDDCSVoltages; }
const std::unordered_map<DPID, TRDDCSMinMaxMeanInfo>& getTRDCurrentsDPsInfo() const { return mTRDDCSCurrents; }
const std::unordered_map<DPID, TRDDCSMinMaxMeanInfo>& getTRDEnvDPsInfo() const { return mTRDDCSEnv; }
const std::unordered_map<DPID, int>& getTRDRunDPsInfo() const { return mTRDDCSRun; }
const std::array<int, constants::MAXCHAMBER>& getTRDFedChamberStatusDPsInfo() const { return mTRDDCSFedChamberStatus; }
const std::array<string, constants::MAXCHAMBER>& getTRDFedCFGtagDPsInfo() const { return mTRDDCSFedCFGtag; }

Expand All @@ -115,7 +111,6 @@ class DCSProcessor
void clearCurrentsDPsInfo();
void clearEnvDPsInfo();
void clearRunDPsInfo();
// LB: new DPs for Fed
void clearFedChamberStatusDPsInfo();
void clearFedCFGtagDPsInfo();

Expand All @@ -128,8 +123,6 @@ class DCSProcessor
std::unordered_map<DPID, TRDDCSMinMaxMeanInfo> mTRDDCSCurrents; ///< anode and drift currents
std::unordered_map<DPID, float> mTRDDCSVoltages; ///< anode and drift voltages
std::unordered_map<DPID, TRDDCSMinMaxMeanInfo> mTRDDCSEnv; ///< environment parameters (temperatures, pressures, humidity)
std::unordered_map<DPID, int> mTRDDCSRun; ///< run number (run type ignored)
// LB: new DPs for Fed
std::array<int, constants::MAXCHAMBER> mTRDDCSFedChamberStatus; ///< fed chamber status
std::array<string, constants::MAXCHAMBER> mTRDDCSFedCFGtag; ///< fed config tag

Expand All @@ -140,32 +133,24 @@ class DCSProcessor
CcdbObjectInfo mCcdbVoltagesDPsInfo;
CcdbObjectInfo mCcdbCurrentsDPsInfo;
CcdbObjectInfo mCcdbEnvDPsInfo;
CcdbObjectInfo mCcdbRunDPsInfo;
// LB: new DPs for Fed
CcdbObjectInfo mCcdbFedChamberStatusDPsInfo;
CcdbObjectInfo mCcdbFedCFGtagDPsInfo;

TFType mGasStartTS; ///< the time stamp of the first TF which was processesd for the current GAS CCDB object
TFType mVoltagesStartTS; ///< the time stamp of the first TF which was processesd for the current voltages CCDB object
TFType mCurrentsStartTS; ///< the time stamp of the first TF which was processesd for the current voltages CCDB object
TFType mEnvStartTS;
TFType mRunStartTS;
TFType mRunEndTS;
// LB: new DPs for Fed
TFType mFedChamberStatusStartTS;
TFType mFedCFGtagStartTS;
TFType mCurrentTS{0}; ///< the time stamp of the TF currently being processed
bool mGasStartTSset{false};
bool mVoltagesStartTSSet{false};
bool mCurrentsStartTSSet{false};
bool mEnvStartTSSet{false};
bool mRunStartTSSet{false};
// LB: new DPs for Fed
bool mFedChamberStatusStartTSSet{false};
bool mFedCFGtagStartTSSet{false};
std::bitset<constants::MAXCHAMBER> mVoltageSet{};
bool mShouldUpdateVoltages{false};
bool mShouldUpdateRun{false};
// LB: FedChamberStatus and FedCFGtag logic
bool mFedChamberStatusCompleteDPs{false};
bool mFedCFGtagCompleteDPs{false};
Expand All @@ -174,8 +159,6 @@ class DCSProcessor
int mCurrentRunNumber{-1};
int mFedChamberStatusAlarmCounter{0};
int mFedCFGtagAlarmCounter{0};
// LB: for testing runNo object, turned off for now
// int mFinishedRunNumber;

// settings
int mVerbosity{0};
Expand Down
80 changes: 13 additions & 67 deletions Detectors/TRD/calibration/src/DCSProcessor.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -197,46 +197,38 @@ int DCSProcessor::processDP(const DPCOM& dpcom)
}

if (type == DPVAL_INT) {
if (std::strstr(dpid.get_alias(), "trd_fed_runNo") != nullptr) { // DP is trd_fed_runNo
if (!mRunStartTSSet) {
mRunStartTS = mCurrentTS;
mRunStartTSSet = true;
}

auto& runNumber = mTRDDCSRun[dpid];

// LB: Check if new value is a valid run number (0 = cleared variable)
// check if DP is run number, only used for Chamber Status/CFGtag metadata
if (std::strstr(dpid.get_alias(), "trd_fed_runNo") != nullptr) { // DP is trd_fed_runNo
// LB: Check if new value is a valid run number (0 = cleared variable, -1 = start variable)
if (o2::dcs::getValue<int32_t>(dpcom) > 0) {
// If value has changed from previous one, new run has begun and update
if (o2::dcs::getValue<int32_t>(dpcom) != mCurrentRunNumber) {
LOG(info) << "New run number " << o2::dcs::getValue<int32_t>(dpcom) << " differs from the old one " << mCurrentRunNumber;
mShouldUpdateRun = true;
// LB: two different flags as they reset separately, after upload of CCDB, for each object
mFirstRunEntryForFedChamberStatusUpdate = true;
mFirstRunEntryForFedCFGtagUpdate = true;
// LB: reset alarm counters
mFedChamberStatusAlarmCounter = 0;
mFedCFGtagAlarmCounter = 0;
mRunEndTS = mCurrentTS;
}

// LB: Save current run number
mCurrentRunNumber = o2::dcs::getValue<int32_t>(dpcom);
// Save to mTRDDCSRun
runNumber = mCurrentRunNumber;
}

if (mVerbosity > 2) {
LOG(info) << "Current Run Number: " << mCurrentRunNumber;
}

} else if (std::strstr(dpid.get_alias(), "trd_chamberStatus") != nullptr) { // DP is trd_chamberStatus
// check if DP is Chamber Status
} else if (std::strstr(dpid.get_alias(), "trd_chamberStatus") != nullptr) {
if (!mFedChamberStatusStartTSSet) {
mFedChamberStatusStartTS = mCurrentTS;
mFedChamberStatusStartTSSet = true;
}

// LB: for ChamberStatus, grab the chamber number from alias
// LB: grab the chamber number from alias
int chamberId = getChamberIdFromAlias(dpid.get_alias());
auto& dpInfoFedChamberStatus = mTRDDCSFedChamberStatus[chamberId];
if (etime != mLastDPTimeStamps[dpid]) {
Expand All @@ -261,7 +253,9 @@ int DCSProcessor::processDP(const DPCOM& dpcom)
}

if (type == DPVAL_STRING) {
if (std::strstr(dpid.get_alias(), "trd_CFGtag") != nullptr) { // DP is trd_CFGtag

// check if DP is chamber configuration tag
if (std::strstr(dpid.get_alias(), "trd_CFGtag") != nullptr) {
if (!mFedCFGtagStartTSSet) {
mFedCFGtagStartTS = mCurrentTS;
mFedCFGtagStartTSSet = true;
Expand Down Expand Up @@ -476,38 +470,6 @@ bool DCSProcessor::updateEnvDPsCCDB()
return retVal;
}

bool DCSProcessor::updateRunDPsCCDB()
{
// here we create the object containing the run data points to then be sent to CCDB
LOG(info) << "Preparing CCDB object for TRD run DPs";

bool retVal = false; // set to 'true' in case at least one DP for run has been processed

for (const auto& it : mPids) {
const auto& type = it.first.get_type();
if (type == o2::dcs::DPVAL_INT) {
if (std::strstr(it.first.get_alias(), "trd_fed_run") != nullptr) {
if (it.second == true) { // we processed the DP at least 1x
retVal = true;
}
if (mVerbosity > 0) {
LOG(info) << "PID = " << it.first.get_alias() << ". Value = " << mTRDDCSRun[it.first];
}
}
}
}
std::map<std::string, std::string> md;
md["responsible"] = "Leonardo Barreto";
// Redundancy for testing, this object is updated after run ended, so need to write old run number, not current
// md["runNumber"] = std::to_string(mFinishedRunNumber);
o2::calibration::Utils::prepareCCDBobjectInfo(mTRDDCSRun, mCcdbRunDPsInfo, "TRD/Calib/DCSDPsRun", md, mRunStartTS, mRunEndTS);

// LB: Deactivated upload of Run DPs to CCDB even if processed
// To turn it back on just comment the next line
retVal = false;
return retVal;
}

bool DCSProcessor::updateFedChamberStatusDPsCCDB()
{
// here we create the object containing the fedChamberStatus data points to then be sent to CCDB
Expand All @@ -533,9 +495,9 @@ bool DCSProcessor::updateFedChamberStatusDPsCCDB()
std::map<std::string, std::string> md;
md["responsible"] = "Leonardo Barreto";
md["runNumber"] = std::to_string(mCurrentRunNumber);
// LB: set start timestamp 30 seconds before DPs are received
// LB: set start timestamp 30000 miliseconds before DPs are received
o2::calibration::Utils::prepareCCDBobjectInfo(mTRDDCSFedChamberStatus, mCcdbFedChamberStatusDPsInfo,
"TRD/Calib/DCSDPsFedChamberStatus", md, mFedChamberStatusStartTS - 30,
"TRD/Calib/DCSDPsFedChamberStatus", md, mFedChamberStatusStartTS - 30000,
mFedChamberStatusStartTS + 3 * o2::ccdb::CcdbObjectInfo::DAY);

return retVal;
Expand Down Expand Up @@ -566,9 +528,9 @@ bool DCSProcessor::updateFedCFGtagDPsCCDB()
std::map<std::string, std::string> md;
md["responsible"] = "Leonardo Barreto";
md["runNumber"] = std::to_string(mCurrentRunNumber);
// LB: set start timestamp 30 seconds before DPs are received
// LB: set start timestamp 30000 seconds before DPs are received
o2::calibration::Utils::prepareCCDBobjectInfo(mTRDDCSFedCFGtag, mCcdbFedCFGtagDPsInfo,
"TRD/Calib/DCSDPsFedCFGtag", md, mFedCFGtagStartTS - 30,
"TRD/Calib/DCSDPsFedCFGtag", md, mFedCFGtagStartTS - 30000,
mFedCFGtagStartTS + 3 * o2::ccdb::CcdbObjectInfo::DAY);

return retVal;
Expand Down Expand Up @@ -637,22 +599,6 @@ void DCSProcessor::clearEnvDPsInfo()
}
}

void DCSProcessor::clearRunDPsInfo()
{
mTRDDCSRun.clear();
mRunStartTSSet = false;
mShouldUpdateRun = false;
// reset the 'processed' flags for the run DPs
for (auto& it : mPids) {
const auto& type = it.first.get_type();
if (type == o2::dcs::DPVAL_INT) {
if (std::strstr(it.first.get_alias(), "trd_fed_run") != nullptr) {
it.second = false;
}
}
}
}

void DCSProcessor::clearFedChamberStatusDPsInfo()
{
// mTRDDCSFedChamberStatus should not be cleared after upload giving alarm/warn logic
Expand Down
59 changes: 17 additions & 42 deletions Detectors/TRD/calibration/workflow/TRDDCSDataProcessorSpec.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,14 @@ class TRDDCSDataProcessor : public o2::framework::Task
LOG(info) << "Invalid voltage variation trigger of DPs to update Anode/DriftUMon to " << utrigger << ", using default value of 1 V";
}

mUploadAtEoS = ic.options().get<bool>("enable-uploadAtEoS");
LOG(info) << "Setting upload of CCDB objects at end of stream to " << mUploadAtEoS;

mProcessor->init(vect);
mTimerGas = std::chrono::high_resolution_clock::now();
mTimerVoltages = mTimerGas;
mTimerCurrents = mTimerGas;
mTimerEnv = mTimerGas;
// LB: new DPs for Fed
mTimerFedChamberStatus = mTimerGas;
mTimerFedCFGtag = mTimerGas;

Expand Down Expand Up @@ -201,7 +203,6 @@ class TRDDCSDataProcessor : public o2::framework::Task
mTimerEnv = timeNow;
}

// LB: processing logic for FedChamberStatus and FedCFGtag
if (mProcessor->shouldUpdateFedChamberStatus()) {
sendDPsoutputFedChamberStatus(pc.outputs());
}
Expand All @@ -210,35 +211,35 @@ class TRDDCSDataProcessor : public o2::framework::Task
sendDPsoutputFedCFGtag(pc.outputs());
}

if (mProcessor->shouldUpdateRun()) {
sendDPsoutputRun(pc.outputs());
}
sw.Stop();

if (mReportTiming) {
LOGP(info, "Timing CPU:{:.3e} Real:{:.3e} at slice {}", sw.CpuTime(), sw.RealTime(), pc.services().get<o2::framework::TimingInfo>().timeslice);
}
}

void endOfStream(o2::framework::EndOfStreamContext& ec) final
{
sendDPsoutputGas(ec.outputs());
sendDPsoutputVoltages(ec.outputs());
sendDPsoutputCurrents(ec.outputs());
sendDPsoutputEnv(ec.outputs());
sendDPsoutputRun(ec.outputs());
// LB: new DPs for Fed
sendDPsoutputFedChamberStatus(ec.outputs());
sendDPsoutputFedCFGtag(ec.outputs());
// LB: no objects should be uploaded at end of stream, unless stated otherwise
if (mUploadAtEoS) {
LOG(info) << "End of stream upload of CCDB objects";
sendDPsoutputGas(ec.outputs());
sendDPsoutputVoltages(ec.outputs());
sendDPsoutputCurrents(ec.outputs());
sendDPsoutputEnv(ec.outputs());
} else {
LOG(info) << "No CCDB object upload done at the end of stream";
}
}

private:
bool mUploadAtEoS = false;
bool mReportTiming = false;
std::unique_ptr<DCSProcessor> mProcessor;
std::chrono::high_resolution_clock::time_point mTimerGas;
std::chrono::high_resolution_clock::time_point mTimerVoltages;
std::chrono::high_resolution_clock::time_point mTimerCurrents;
std::chrono::high_resolution_clock::time_point mTimerEnv;
// LB: new DPs for Fed
std::chrono::high_resolution_clock::time_point mTimerFedChamberStatus;
std::chrono::high_resolution_clock::time_point mTimerFedCFGtag;

Expand All @@ -247,7 +248,6 @@ class TRDDCSDataProcessor : public o2::framework::Task
int64_t mCurrentsDPsUpdateInterval;
int64_t mMinUpdateIntervalU;
int64_t mEnvDPsUpdateInterval;
// LB: new DPs for Fed
int64_t mFedChamberStatusDPsUpdateInterval;
int64_t mFedCFGtagDPsUpdateInterval;

Expand Down Expand Up @@ -325,27 +325,6 @@ class TRDDCSDataProcessor : public o2::framework::Task
}
}

//________________________________________________________________
void sendDPsoutputRun(DataAllocator& output)
{
// extract CCDB infos and calibration object for DPs
if (mProcessor->updateRunDPsCCDB()) {
const auto& payload = mProcessor->getTRDRunDPsInfo();
auto& info = mProcessor->getccdbRunDPsInfo();
auto image = o2::ccdb::CcdbApi::createObjectImage(&payload, &info);
LOG(info) << "Sending object " << info.getPath() << "/" << info.getFileName() << " of size " << image->size()
<< " bytes, valid for " << info.getStartValidityTimestamp() << " : " << info.getEndValidityTimestamp();
output.snapshot(Output{o2::calibration::Utils::gDataOriginCDBPayload, "TRD_DCSRunDPs", 0}, *image.get());
output.snapshot(Output{o2::calibration::Utils::gDataOriginCDBWrapper, "TRD_DCSRunDPs", 0}, info);
mProcessor->clearRunDPsInfo();
} else {
auto& info = mProcessor->getccdbRunDPsInfo();
// LOG(info) << "Not sending object " << info.getPath() << "/" << info.getFileName() << " since no DPs were processed for it";
LOG(info) << "Not sending object " << info.getPath() << "/" << info.getFileName() << " as upload of Run DPs was deactivated";
}
}

// LB: new DP for FedChamberStatus
//________________________________________________________________
void sendDPsoutputFedChamberStatus(DataAllocator& output)
{
Expand All @@ -365,7 +344,6 @@ class TRDDCSDataProcessor : public o2::framework::Task
}
}

// LB: new DP for FedCFGtag
//________________________________________________________________
void sendDPsoutputFedCFGtag(DataAllocator& output)
{
Expand Down Expand Up @@ -395,18 +373,14 @@ DataProcessorSpec getTRDDCSDataProcessorSpec()
{

std::vector<OutputSpec> outputs;

outputs.emplace_back(ConcreteDataTypeMatcher{o2::calibration::Utils::gDataOriginCDBPayload, "TRD_DCSGasDPs"}, Lifetime::Sporadic);
outputs.emplace_back(ConcreteDataTypeMatcher{o2::calibration::Utils::gDataOriginCDBWrapper, "TRD_DCSGasDPs"}, Lifetime::Sporadic);
outputs.emplace_back(ConcreteDataTypeMatcher{o2::calibration::Utils::gDataOriginCDBPayload, "TRD_DCSUDPs"}, Lifetime::Sporadic);
outputs.emplace_back(ConcreteDataTypeMatcher{o2::calibration::Utils::gDataOriginCDBWrapper, "TRD_DCSUDPs"}, Lifetime::Sporadic);
outputs.emplace_back(ConcreteDataTypeMatcher{o2::calibration::Utils::gDataOriginCDBPayload, "TRD_DCSIDPs"}, Lifetime::Sporadic);
outputs.emplace_back(ConcreteDataTypeMatcher{o2::calibration::Utils::gDataOriginCDBWrapper, "TRD_DCSIDPs"}, Lifetime::Sporadic);
outputs.emplace_back(ConcreteDataTypeMatcher{o2::calibration::Utils::gDataOriginCDBPayload, "TRD_DCSRunDPs"}, Lifetime::Sporadic);
outputs.emplace_back(ConcreteDataTypeMatcher{o2::calibration::Utils::gDataOriginCDBWrapper, "TRD_DCSRunDPs"}, Lifetime::Sporadic);
outputs.emplace_back(ConcreteDataTypeMatcher{o2::calibration::Utils::gDataOriginCDBPayload, "TRD_DCSEnvDPs"}, Lifetime::Sporadic);
outputs.emplace_back(ConcreteDataTypeMatcher{o2::calibration::Utils::gDataOriginCDBWrapper, "TRD_DCSEnvDPs"}, Lifetime::Sporadic);
// LB: new DPs for Fed
// Must use reduced names due to initializer string cannot exceed descriptor size in Data Format
outputs.emplace_back(ConcreteDataTypeMatcher{o2::calibration::Utils::gDataOriginCDBPayload, "TRD_ChamberStat"}, Lifetime::Sporadic);
outputs.emplace_back(ConcreteDataTypeMatcher{o2::calibration::Utils::gDataOriginCDBWrapper, "TRD_ChamberStat"}, Lifetime::Sporadic);
Expand All @@ -429,7 +403,8 @@ DataProcessorSpec getTRDDCSDataProcessorSpec()
{"DPs-voltage-variation-trigger", VariantType::Int64, 1ll, {"Voltage variation trigger for upload of CCDB object"}},
{"DPs-update-interval-gas", VariantType::Int64, 900ll, {"Interval (in s) after which to update the DPs CCDB entry for gas parameters"}},
{"DPs-max-counter-alarm-fed", VariantType::Int, 1, {"Maximum number of alarms after FedChamberStatus and FedCFGtag changes, following changes are logged as warnings"}},
{"DPs-min-counter-update-fed", VariantType::Int, 522, {"Minimum number of DPs to update FedChamberStatus and FedCFGtag objects"}}}};
{"DPs-min-counter-update-fed", VariantType::Int, 522, {"Minimum number of DPs to update FedChamberStatus and FedCFGtag objects"}},
{"enable-uploadAtEoS", VariantType::Bool, false, {"Upload CCDB objects at end of stream"}}}};
}

} // namespace framework
Expand Down