Project
Loading...
Searching...
No Matches
FITDCSDataProcessor.cxx
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
16
18
20#include "CCDB/CcdbApi.h"
27#include "Framework/Output.h"
28
29#include <cstdint>
30#include <chrono>
31#include <memory>
32#include <string>
33#include <unordered_map>
34#include <vector>
35
36using namespace o2::fit;
37
40using HighResClock = std::chrono::high_resolution_clock;
41using Duration = std::chrono::duration<double, std::ratio<1, 1>>;
42
44{
45 setVerboseMode(ic.options().get<bool>("use-verbose-mode"));
46 LOG(info) << "Verbose mode: " << getVerboseMode();
47
48 mDPsUpdateInterval = ic.options().get<int64_t>("DPs-update-interval");
49 if (mDPsUpdateInterval == 0) {
50 LOG(error) << mDetectorName << " DPs update interval set to zero seconds --> changed to 10 min.";
51 mDPsUpdateInterval = 600;
52 }
53
54 std::vector<DPID> vect;
55
56 const bool useCcdbToConfigure = ic.options().get<bool>("use-ccdb-to-configure");
57 if (useCcdbToConfigure) {
58 LOG(info) << "Configuring via CCDB";
59 const std::string ccdbPath = ic.options().get<std::string>("ccdb-path");
61 mgr.setURL(ccdbPath);
62 long timestamp = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
63 std::unordered_map<DPID, std::string>* dpid2DataDesc = mgr.getForTimeStamp<std::unordered_map<DPID, std::string>>(mDetectorName + "/Config/DCSDPconfig", timestamp);
64 for (auto& i : *dpid2DataDesc) {
65 vect.push_back(i.first);
66 }
67 } else {
68 LOG(info) << "Configuring via hardcoded strings";
69 vect = getHardCodedDPIDs();
70 }
71
72 if (getVerboseMode()) {
73 LOGP(info, "Listing Data Points for {}:", mDetectorName);
74 for (auto& i : vect) {
75 LOG(info) << i;
76 }
77 }
78
79 mDataReader = std::make_unique<o2::fit::FITDCSDataReader>();
80 mDataReader->setVerboseMode(getVerboseMode());
81 mDataReader->setCcdbPath(mDetectorName + "/Calib/DCSDPs");
82 mDataReader->init(vect);
83 mTimer = HighResClock::now();
84}
85
87{
88 auto timeNow = HighResClock::now();
89 long dataTime = (long)(pc.services().get<o2::framework::TimingInfo>().creation);
90
91 if (dataTime == 0xffffffffffffffff) { // it means it is not set
92 dataTime = std::chrono::duration_cast<std::chrono::milliseconds>(timeNow.time_since_epoch()).count(); // in ms
93 }
94
95 if (!mDataReader->isStartValiditySet()) {
96 if (getVerboseMode()) {
97 LOG(info) << "Start valitidy for DPs changed to = " << dataTime;
98 }
99 mDataReader->setStartValidity(dataTime);
100 }
101 auto dps = pc.inputs().get<gsl::span<DPCOM>>("input");
102 mDataReader->process(dps);
103 Duration elapsedTime = timeNow - mTimer; // in seconds
104 if (elapsedTime.count() >= mDPsUpdateInterval) {
105 sendDPsOutput(pc.outputs());
106 mTimer = timeNow;
107 }
108}
109
114
115const std::string& FITDCSDataProcessor::getDetectorName() const { return mDetectorName; }
117void FITDCSDataProcessor::setVerboseMode(bool verboseMode) { mVerbose = verboseMode; }
118
119void FITDCSDataProcessor::sendDPsOutput(o2::framework::DataAllocator& output)
120{
121 // extract CCDB infos and calibration object for DPs
122 mDataReader->updateCcdbObjectInfo();
123 const auto& payload = mDataReader->getDpData();
124 auto& info = mDataReader->getccdbDPsInfo();
125 auto image = o2::ccdb::CcdbApi::createObjectImage(&payload, &info);
126 LOG(info) << "Sending object " << info.getPath() << "/" << info.getFileName() << " of size " << image->size()
127 << " bytes, valid for " << info.getStartValidityTimestamp() << " : " << info.getEndValidityTimestamp();
130 mDataReader->resetDpData();
131 mDataReader->resetStartValidity();
132}
Utils and constants for calibration and related workflows.
std::chrono::duration< double, std::ratio< 1, 1 > > Duration
std::chrono::high_resolution_clock HighResClock
Task for processing FIT DCS data.
DCS data point reader for FIT.
int32_t i
std::string ccdbPath(const std::string badChannelType)
void output(const std::map< std::string, ChannelStat > &channels)
Definition rawdump.cxx:197
static BasicCCDBManager & instance()
static std::unique_ptr< std::vector< char > > createObjectImage(const T *obj, CcdbObjectInfo *info=nullptr)
Definition CcdbApi.h:103
virtual std::vector< o2::dcs::DataPointIdentifier > getHardCodedDPIDs()=0
std::string mDetectorName
Detector name.
void endOfStream(o2::framework::EndOfStreamContext &ec) final
This is invoked whenever we have an EndOfStream event.
void setVerboseMode(bool verboseMode=true)
void run(o2::framework::ProcessingContext &pc) final
const std::string & getDetectorName() const
void init(o2::framework::InitContext &ic) final
ConfigParamRegistry const & options()
Definition InitContext.h:33
decltype(auto) get(R binding, int part=0) const
DataAllocator & outputs()
The data allocator is used to allocate memory for the output data.
InputRecord & inputs()
The inputs associated with this processing context.
ServiceRegistryRef services()
The services registry associated with this processing context.
GLeglImageOES image
Definition glcorearb.h:4021
static constexpr o2::header::DataOrigin gDataOriginCDBWrapper
Definition Utils.h:44
static constexpr o2::header::DataOrigin gDataOriginCDBPayload
Definition Utils.h:43
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"