Project
Loading...
Searching...
No Matches
NoiseCalibSpec.h
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
12#ifndef O2_TRD_NOISECALIBSPEC_H
13#define O2_TRD_NOISECALIBSPEC_H
14
17
18#include "Framework/Task.h"
25
26using namespace o2::framework;
27
28namespace o2
29{
30namespace trd
31{
32
34{
35 public:
36 TRDNoiseCalibSpec(bool dummy) : mIsDummy(dummy) {}
38 {
39 // Do we need to initialize something?
40 }
41
43 {
44 auto digits = pc.inputs().get<gsl::span<Digit>>("trddigits");
45 auto trigRecs = pc.inputs().get<gsl::span<TriggerRecord>>("trdtriggerrec");
46
47 if (mIsDummy) {
48 return;
49 }
50
51 // Obtain rough time from the data header (done only once)
52 if (mStartTime == 0) {
55 if (!ti.isDummy()) {
56 mStartTime = ti.creation;
57 }
58 }
59
60 // process the digits, as long as we have not reached the limit
61 if (!mCalibrator.hasEnoughData()) {
62 mCalibrator.process(digits);
63 } else {
64 if (!mHaveSentOutput) {
65 LOGP(important, "Enough data received after {} TFs seen, finalizing noise calibration", mNTFsProcessed);
66 mCalibrator.collectChannelInfo();
67 sendOutput(pc.outputs());
68 mHaveSentOutput = true;
69 } else {
70 if ((mNTFsProcessed % 200) == 0) {
71 LOGP(important, "Not processing anymore. Seen {} TFs in total. Run can be stopped", mNTFsProcessed);
72 }
73 }
74 }
75 ++mNTFsProcessed;
76 }
77
79 {
80 // extract CCDB infos and calibration objects, convert it to TMemFile and send them to the output
81
82 const auto& payload = mCalibrator.getCcdbObject();
83
84 auto clName = o2::utils::MemFileHelper::getClassName(payload);
85 auto flName = o2::ccdb::CcdbApi::generateFileName(clName);
86 std::map<std::string, std::string> metadata; // do we want to add something?
87 long startValidity = mStartTime;
88 o2::ccdb::CcdbObjectInfo info("TRD/Calib/ChannelStatus", clName, flName, metadata, startValidity, startValidity + 3 * o2::ccdb::CcdbObjectInfo::MONTH);
89
90 auto image = o2::ccdb::CcdbApi::createObjectImage(&payload, &info);
91 LOG(info) << "Sending object " << info.getPath() << "/" << info.getFileName() << " of size " << image->size()
92 << " bytes, valid for " << info.getStartValidityTimestamp() << " : " << info.getEndValidityTimestamp();
93
94 output.snapshot(Output{o2::calibration::Utils::gDataOriginCDBPayload, "PADSTATUS", 0}, *image.get()); // vector<char>
95 output.snapshot(Output{o2::calibration::Utils::gDataOriginCDBWrapper, "PADSTATUS", 0}, info); // root-serialized
96 }
97
99 {
100 if (mHaveSentOutput) {
101 LOGP(important, "Received EoS after sending calibration object. All OK");
102 } else {
103 if (!mIsDummy) {
104 LOGP(alarm, "Received EoS before sending calibration object. Not enough digits received");
105 }
106 }
107 }
108
109 private:
110 CalibratorNoise mCalibrator{};
111 size_t mNTFsProcessed{0};
112 bool mHaveSentOutput{false};
113 bool mIsDummy{false};
114 uint64_t mStartTime{0};
115};
116
118{
119 std::vector<InputSpec> inputs;
120 inputs.emplace_back("trddigits", o2::header::gDataOriginTRD, "DIGITS", 0, Lifetime::Timeframe);
121 inputs.emplace_back("trdtriggerrec", o2::header::gDataOriginTRD, "TRKTRGRD", 0, Lifetime::Timeframe);
122
123 std::vector<OutputSpec> outputs;
124 outputs.emplace_back(ConcreteDataTypeMatcher{o2::calibration::Utils::gDataOriginCDBPayload, "PADSTATUS"}, Lifetime::Sporadic);
125 outputs.emplace_back(ConcreteDataTypeMatcher{o2::calibration::Utils::gDataOriginCDBWrapper, "PADSTATUS"}, Lifetime::Sporadic);
126
127 return DataProcessorSpec{
128 "trd-noise-calib",
129 inputs,
130 outputs,
131 AlgorithmSpec{adaptFromTask<TRDNoiseCalibSpec>(dummy)},
132 Options{}};
133}
134
135} // namespace trd
136} // namespace o2
137
138#endif // O2_TRD_NOISECALIBSPEC_H
TRD pad calibration.
void output(const std::map< std::string, ChannelStat > &channels)
Definition rawdump.cxx:197
static std::string generateFileName(const std::string &inp)
Definition CcdbApi.cxx:798
static std::unique_ptr< std::vector< char > > createObjectImage(const T *obj, CcdbObjectInfo *info=nullptr)
Definition CcdbApi.h:103
long getEndValidityTimestamp() const
static constexpr long MONTH
const std::string & getPath() const
long getStartValidityTimestamp() const
const std::string & getFileName() const
void process(const gsl::span< const Digit > &digits)
const ChannelInfoContainer & getCcdbObject() const
void run(o2::framework::ProcessingContext &pc) final
void sendOutput(DataAllocator &output)
void init(o2::framework::InitContext &ic) final
void endOfStream(o2::framework::EndOfStreamContext &ec) final
This is invoked whenever we have an EndOfStream event.
GLeglImageOES image
Definition glcorearb.h:4021
constexpr o2::header::DataOrigin gDataOriginTRD
Definition DataHeader.h:577
Defining PrimaryVertex explicitly as messageable.
Definition TFIDInfo.h:20
std::vector< ConfigParamSpec > Options
o2::framework::DataProcessorSpec getTRDNoiseCalibSpec(bool dummy)
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
static void fillTFIDInfo(o2::framework::ProcessingContext &pc, o2::dataformats::TFIDInfo &ti)
static constexpr o2::header::DataOrigin gDataOriginCDBWrapper
Definition Utils.h:44
static constexpr o2::header::DataOrigin gDataOriginCDBPayload
Definition Utils.h:43
static std::string getClassName(const T &obj)
get the class name of the object
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"
std::vector< Digit > digits