23#include "TObjString.h"
35 mLoggingInterval = ic.
options().
get<
int>(
"logging-interval") * 1000;
37 mCalibrator = std::make_unique<o2::mch::calibration::BadChannelCalibrator>();
39 mCalibrator->setUpdateAtTheEndOfRunOnly();
40 mTimeStamp = std::numeric_limits<uint64_t>::max();
49void BadChannelCalibrationDevice::logStats(
size_t dataSize)
51 static auto loggerStart = std::chrono::high_resolution_clock::now();
52 static auto loggerEnd = loggerStart;
53 static size_t nDigits = 0;
54 static size_t nTF = 0;
56 if (mLoggingInterval == 0) {
63 loggerEnd = std::chrono::high_resolution_clock::now();
64 std::chrono::duration<double, std::milli> loggerElapsed = loggerEnd - loggerStart;
65 if (loggerElapsed.count() > 1000) {
66 LOG(info) <<
"received " << nDigits <<
" digits in " << nTF <<
" time frames";
69 loggerStart = std::chrono::high_resolution_clock::now();
81 mTimeStamp = std::min(mTimeStamp, mCalibrator->getCurrentTFInfo().creation);
82 auto data = pc.
inputs().
get<gsl::span<o2::mch::calibration::PedestalDigit>>(
"digits");
83 mCalibrator->process(
data);
87 if (mCalibrator->readyToSend(reason)) {
88 mHasEnoughStat =
true;
89 LOGP(info,
"We're ready to send output to CCDB ({})", reason);
90 sendOutput(pc.
outputs(), reason);
102 std::map<std::string, std::string> md;
103 md[
"upload-reason"] = reason;
112 if (mCalibrator->readyToSend(reason)) {
113 mHasEnoughStat =
true;
115 sendOutput(ec.
outputs(),
"End Of Stream");
121 std::stringstream csv;
122 csv << fmt::format(
"solarid,dsid,ch\n");
125 csv << fmt::format(
"{},{},{}\n",
126 c.getSolarId(),
c.getElinkId(),
c.getChannel());
142 LOG(info) <<
"Sending object " << payloadInfo->
getPath()
145 <<
" of size " <<
image->size()
154 std::string_view reason)
156 auto& slot = mCalibrator->getFirstSlot();
157 const auto pedData = slot.getContainer();
158 uint64_t nentries = std::accumulate(pedData->cbegin(), pedData->cend(),
160 [&](uint64_t
n,
const PedestalChannel&
c) { return n +
161 static_cast<uint64_t>(c.mEntries); });
162 std::string reason_with_entries;
164 if (pedData->size() > 0) {
165 int mean =
static_cast<int>(std::round(
static_cast<float>(nentries) / pedData->size()));
166 reason_with_entries = fmt::format(
"{} ; <entries per channel>={}", reason, mean);
168 reason_with_entries = fmt::format(
"{} ; no entries", reason);
171 LOGP(info,
"sendOutput: {}", reason_with_entries);
172 mCalibrator->finalize();
175 if (mHasEnoughStat) {
178 const auto& badChannels = mCalibrator->getBadChannelsVector();
179 auto info =
createCcdbInfo(badChannels, mTimeStamp, reason_with_entries);
188 TObjString badChannelsPOD(
toCSV(badChannels).c_str());
189 auto infoPOD =
createCcdbInfo(badChannelsPOD, mTimeStamp, reason_with_entries);
193 LOGP(info,
"csv={}", badChannelsPOD.String().Data());
195 LOGP(error,
"CCDB not updated: {}", reason_with_entries);
202 mCalibrator->getPedestalsVector());
203 if (mHasEnoughStat) {
205 mCalibrator->getBadChannelsVector());
Utils and constants for calibration and related workflows.
void checkUpdates(o2::framework::ProcessingContext &pc)
bool finaliseCCDB(o2::framework::ConcreteDataMatcher &matcher, void *obj)
static GRPGeomHelper & instance()
void setRequest(std::shared_ptr< GRPGeomRequest > req)
static std::string generateFileName(const std::string &inp)
static std::unique_ptr< std::vector< char > > createObjectImage(const T *obj, CcdbObjectInfo *info=nullptr)
long getEndValidityTimestamp() const
const std::string & getPath() const
static constexpr long DAY
const std::string & getObjectType() const
long getStartValidityTimestamp() const
const std::string & getFileName() const
static const BadChannelCalibratorParam & Instance()
T get(const char *key) const
DataAllocator & outputs()
ConfigParamRegistry const & options()
DataAllocator & outputs()
The data allocator is used to allocate memory for the output data.
InputRecord & inputs()
The inputs associated with this processing context.
void logStats(size_t dataSize)
constexpr TFType INFINITE_TF
std::string toCSV(const std::vector< o2::mch::DsChannelId > &channels)
ccdb::CcdbObjectInfo createCcdbInfo(const T &object, uint64_t timeStamp, std::string_view reason)
void sendCalibrationOutput(o2::framework::DataAllocator &output, header::DataHeader::SubSpecificationType subSpec, T *payload, o2::ccdb::CcdbObjectInfo *payloadInfo)
static void fillTFIDInfo(o2::framework::ProcessingContext &pc, o2::dataformats::TFIDInfo &ti)
static constexpr o2::header::DataOrigin gDataOriginCDBWrapper
static constexpr o2::header::DataOrigin gDataOriginCDBPayload
static std::string getClassName(const T &obj)
get the class name of the object
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"
std::vector< ChannelData > channels