Project
Loading...
Searching...
No Matches
TOFCalibCollectorSpec.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_CALIBRATION_TOFCALIB_COLLECTOR_H
13#define O2_CALIBRATION_TOFCALIB_COLLECTOR_H
14
17
21#include "Framework/Task.h"
26#include "TOFBase/Geo.h"
30
31#include <limits>
32
33using namespace o2::framework;
34
35namespace o2
36{
37namespace calibration
38{
39
41{
44
45 public:
46 TOFCalibCollectorDevice(std::shared_ptr<o2::base::GRPGeomRequest> req, bool useCCDB) : mCCDBRequest(req), mUseCCDB(useCCDB) {}
47
49 {
51 bool isTFsendingPolicy = ic.options().get<bool>("tf-sending-policy");
52 int maxEnt = ic.options().get<int>("max-number-hits-to-fill-tree");
53 bool isTest = ic.options().get<bool>("running-in-test-mode");
54 bool absMaxEnt = ic.options().get<bool>("is-max-number-hits-to-fill-tree-absolute");
55 auto updateInterval = ic.options().get<uint32_t>("update-interval");
56 mCollector = std::make_unique<o2::tof::TOFCalibCollector>(isTFsendingPolicy, maxEnt);
57 mCollector->setIsTest(isTest);
58 mCollector->setIsMaxNumberOfHitsAbsolute(absMaxEnt);
59 mCollector->setFinalizeWhenReady(); // finalize slot once stat is ok and create next one
60 mCollector->setCheckIntervalInfiniteSlot(updateInterval);
61 mCollector->setMaxSlotsDelay(0);
62 }
63
64 //_________________________________________________________________
65 void finaliseCCDB(o2::framework::ConcreteDataMatcher& matcher, void* obj) final
66 {
68 }
69
71 {
73 auto data = pc.inputs().get<gsl::span<o2::dataformats::CalibInfoTOF>>("input");
74
75 if (mUseCCDB) { // read calibration objects from ccdb
76 const auto lhcPhaseIn = pc.inputs().get<LHCphase*>("tofccdbLHCphase");
77 const auto channelCalibIn = pc.inputs().get<TimeSlewing*>("tofccdbChannelCalib");
78
79 float phase = lhcPhaseIn->getLHCphase(0);
80 int bcshift = (phase + 5000) * o2::tof::Geo::BC_TIME_INPS_INV;
81 mCollector->setLHCphase(phase - bcshift * o2::tof::Geo::BC_TIME_INPS);
82 }
83
84 o2::base::TFIDInfoHelper::fillTFIDInfo(pc, mCollector->getCurrentTFInfo());
85 LOG(detail) << "Processing TF " << mCollector->getCurrentTFInfo().tfCounter << " with " << data.size() << " tracks";
86 mCollector->process(data);
87 sendOutput(pc.outputs());
88 }
89
91 {
92 mCollector->checkSlotsToFinalize(o2::calibration::INFINITE_TF);
93 // we force finalizing slot zero (unless everything was already finalized), no matter how many entries we had
94 if (mCollector->getNSlots() != 0) {
95 mCollector->finalizeSlot(mCollector->getSlot(0));
96 }
97 sendOutput(ec.outputs());
98 }
99
100 private:
101 std::unique_ptr<o2::tof::TOFCalibCollector> mCollector;
102 std::shared_ptr<o2::base::GRPGeomRequest> mCCDBRequest;
103 int mMaxNumOfHits = 0;
104 bool mUseCCDB = false;
105
106 //________________________________________________________________
107 void sendOutput(DataAllocator& output)
108 {
109 // in output we send the calibration tree
110 auto& collectedInfo = mCollector->getCollectedCalibInfo();
111 LOG(debug) << "In CollectorSpec sendOutput: size = " << collectedInfo.size();
112 if (collectedInfo.size()) {
113 auto entries = collectedInfo.size();
114 // this means that we are ready to send the output
115 auto entriesPerChannel = mCollector->getEntriesPerChannel();
116 output.snapshot(Output{o2::header::gDataOriginTOF, "COLLECTEDINFO", 0}, collectedInfo);
117 output.snapshot(Output{o2::header::gDataOriginTOF, "ENTRIESCH", 0}, entriesPerChannel);
118 mCollector->initOutput(); // reset the output for the next round
119 }
120 }
121};
122
123} // namespace calibration
124
125namespace framework
126{
127
128DataProcessorSpec getTOFCalibCollectorDeviceSpec(bool useCCDB)
129{
132
133 std::vector<OutputSpec> outputs;
134 outputs.emplace_back(o2::header::gDataOriginTOF, "COLLECTEDINFO", 0, Lifetime::Timeframe);
135 outputs.emplace_back(o2::header::gDataOriginTOF, "ENTRIESCH", 0, Lifetime::Timeframe);
136
137 std::vector<InputSpec> inputs;
138 inputs.emplace_back("input", "TOF", "CALIBDATA");
139 auto ccdbRequest = std::make_shared<o2::base::GRPGeomRequest>(true, // orbitResetTime
140 true, // GRPECS=true
141 false, // GRPLHCIF
142 false, // GRPMagField
143 false, // askMatLUT
145 inputs);
146
147 if (useCCDB) {
148 inputs.emplace_back("tofccdbLHCphase", o2::header::gDataOriginTOF, "LHCphase", 0, Lifetime::Condition, ccdbParamSpec("TOF/Calib/LHCphase"));
149 inputs.emplace_back("tofccdbChannelCalib", o2::header::gDataOriginTOF, "ChannelCalib", 0, Lifetime::Condition, ccdbParamSpec("TOF/Calib/ChannelCalib"));
150 }
151
152 return DataProcessorSpec{
153 "calib-tofcalib-collector",
154 inputs,
155 outputs,
156 AlgorithmSpec{adaptFromTask<device>(ccdbRequest, useCCDB)},
157 Options{
158 {"max-number-hits-to-fill-tree", VariantType::Int, 500, {"maximum number of entries in one channel to trigger teh filling of the tree"}},
159 {"is-max-number-hits-to-fill-tree-absolute", VariantType::Bool, false, {"to decide if we want to multiply the max-number-hits-to-fill-tree by the number of channels (when set to true), or not (when set to false) for fast checks"}},
160 {"tf-sending-policy", VariantType::Bool, false, {"if we are sending output at every TF; otherwise, we use the max-number-hits-to-fill-tree"}},
161 {"running-in-test-mode", VariantType::Bool, false, {"to run in test mode for simplification"}},
162 {"update-interval", VariantType::UInt32, 10u, {"number of TF after which to try to finalize calibration"}}}};
163}
164
165} // namespace framework
166} // namespace o2
167
168#endif
Class to store the output of the matching to TOF for calibration.
Class to store the output of the matching to TOF for calibration.
Class to store the output of the matching to TOF for calibration.
Utils and constants for calibration and related workflows.
uint64_t phase
Definition RawEventData.h:7
Helper for geometry and GRP related CCDB requests.
void output(const std::map< std::string, ChannelStat > &channels)
Definition rawdump.cxx:197
std::ostringstream debug
void checkUpdates(o2::framework::ProcessingContext &pc)
bool finaliseCCDB(o2::framework::ConcreteDataMatcher &matcher, void *obj)
static GRPGeomHelper & instance()
void setRequest(std::shared_ptr< GRPGeomRequest > req)
void endOfStream(o2::framework::EndOfStreamContext &ec) final
This is invoked whenever we have an EndOfStream event.
TOFCalibCollectorDevice(std::shared_ptr< o2::base::GRPGeomRequest > req, bool useCCDB)
void init(o2::framework::InitContext &ic) final
void run(o2::framework::ProcessingContext &pc) final
void finaliseCCDB(o2::framework::ConcreteDataMatcher &matcher, void *obj) final
static constexpr Double_t BC_TIME_INPS
Definition Geo.h:103
static constexpr Double_t BC_TIME_INPS_INV
Definition Geo.h:104
GLboolean * data
Definition glcorearb.h:298
constexpr o2::header::DataOrigin gDataOriginTOF
Definition DataHeader.h:575
constexpr TFType INFINITE_TF
Definition TimeSlot.h:30
Defining PrimaryVertex explicitly as messageable.
Definition TFIDInfo.h:20
std::vector< ConfigParamSpec > ccdbParamSpec(std::string const &path, int runDependent, std::vector< CCDBMetadata > metadata={}, int qrate=0)
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)
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"