Project
Loading...
Searching...
No Matches
GRPLHCIFfileSpec.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
13
16#include "Framework/Logger.h"
18#include "CCDB/CcdbApi.h"
19#include "CCDB/CcdbObjectInfo.h"
22#include "CommonTypes/Units.h"
23
24#include <chrono>
25#include <cstdint>
26
27using namespace o2::framework;
28using HighResClock = std::chrono::high_resolution_clock;
29using Duration = std::chrono::duration<double, std::ratio<1, 1>>;
31
32namespace o2
33{
34namespace grp
35{
36
38{
39 mVerbose = ic.options().get<bool>("use-verbose-mode");
40 LOG(info) << " ************************* Verbose?" << mVerbose;
41}
42
43//__________________________________________________________________
44
46{
47 auto configBuff = pc.inputs().get<gsl::span<char>>("inputConfig");
48 auto configFileName = pc.inputs().get<std::string>("inputConfigFileName");
49 auto timer = std::chrono::duration_cast<std::chrono::milliseconds>(HighResClock::now().time_since_epoch()).count();
50 LOG(info) << "got input file " << configFileName << " of size " << configBuff.size();
51 mReader.loadLHCIFfile(configBuff);
52 std::vector<std::pair<long, std::vector<int32_t>>> beamEnergy;
53 std::vector<std::pair<long, std::vector<std::string>>> injScheme;
54 std::vector<std::pair<long, std::vector<std::string>>> fillNb;
55 std::vector<std::pair<long, std::vector<int32_t>>> atomicNbB1;
56 std::vector<std::pair<long, std::vector<int32_t>>> atomicNbB2;
57 std::vector<std::pair<long, std::vector<o2::units::AngleRad_t>>> crossAngle;
58 std::vector<std::pair<long, std::vector<int32_t>>> bunchConfigB1;
59 std::vector<std::pair<long, std::vector<int32_t>>> bunchConfigB2;
60
61 int nEle = 0;
62 int nMeas = 0;
63 std::string type{""};
64
65 GRPLHCIFData lhcifdata;
66
67 // Beam Energy
68 mReader.readValue<int32_t>("BEAM_ENERGY", type, nEle, nMeas, beamEnergy);
69 if (nMeas == 0) {
70 LOG(warn) << "Beam energy not present/empty"; // RS: in absence of the beam it is empty, don't produce an error
71 }
72 if (nEle > 1 || nMeas > 1) {
73 LOGP(warn, "More than one value/measurement {}/{} found for Beam Energy, keeping the last one", nEle, nMeas);
74 }
75 if (!beamEnergy.empty()) {
76 lhcifdata.setBeamEnergyPerZWithTime(beamEnergy.back().first, beamEnergy.back().second.back());
77 }
78 // Injection scheme
79 mReader.readValue<std::string>("INJECTION_SCHEME", type, nEle, nMeas, injScheme);
80 if (nMeas == 0) {
81 LOG(warn) << "Injection scheme not present/empty"; // RS: same comment
82 }
83 if (nEle > 1 || nMeas > 1) {
84 LOGP(warn, "More than one value/measurement {}/{} found for Injection Scheme, keeping the last one", nEle, nMeas);
85 }
86 if (!injScheme.empty()) {
87 lhcifdata.setInjectionSchemeWithTime(injScheme.back().first, injScheme.back().second.back());
88 }
89
90 // fill number
91 mReader.readValue<std::string>("FILL_NUMBER", type, nEle, nMeas, fillNb);
92 if (nMeas == 0) {
93 LOG(warn) << "Fill Number not present/empty";
94 }
95 if (nEle > 1 || nMeas > 1) {
96 LOG(warn) << "More than one value/measurement found for Fill Number, keeping the last one";
97 }
98 if (!fillNb.empty()) {
99 lhcifdata.setFillNumberWithTime(fillNb.back().first, atoi(fillNb.back().second.back().c_str()));
100 }
101
102 // Atomic Number (Z) for B1
103 mReader.readValue<int32_t>("ATOMIC_NUMBER_B1", type, nEle, nMeas, atomicNbB1);
104 if (nMeas == 0) {
105 LOG(warn) << "Atomic Number Beam 1 (clockwise) not present/empty"; // RS same comment
106 }
107 if (nEle > 1 || nMeas > 1) {
108 LOGP(warn, "More than one value/measurement {}/{} found for Atomic Number Beam 1 (clockwise), keeping the last one", nEle, nMeas);
109 }
110 if (!atomicNbB1.empty()) {
111 lhcifdata.setAtomicNumberB1WithTime(atomicNbB1.back().first, atomicNbB1.back().second.back());
112 }
113
114 // Atomic Number (Z) for B2
115 mReader.readValue<int32_t>("ATOMIC_NUMBER_B2", type, nEle, nMeas, atomicNbB2);
116 if (nMeas == 0) {
117 LOG(warn) << "Atomic Number Beam 2 (anticlockwise) not present/empty";
118 }
119 if (nEle > 1 || nMeas > 1) {
120 LOGP(warn, "More than one value/measurement {}/{} found for Atomic Number Beam 2 (anticlockwise), keeping the last one", nEle, nMeas);
121 }
122 if (!atomicNbB2.empty()) {
123 lhcifdata.setAtomicNumberB2WithTime(atomicNbB2.back().first, atomicNbB2.back().second.back());
124 }
125
126 // Crossing Angle
127 mReader.readValue<float>("IP2_XING_V_MURAD", type, nEle, nMeas, crossAngle);
128 if (nMeas == 0) {
129 LOG(warn) << "Crossing Angle not present/empty";
130 }
131 if (nEle > 1 || nMeas > 1) {
132 LOGP(warn, "More than one value/measurement {}/{} found for Crossing Angle, keeping the last one", nEle, nMeas);
133 }
134 if (!crossAngle.empty()) {
135 lhcifdata.setCrossingAngleWithTime(crossAngle.back().first, crossAngle.back().second.back());
136 }
137
138 // Bunch Config for B1
139 mReader.readValue<int>("CIRCULATING_BUNCH_CONFIG_BEAM1", type, nEle, nMeas, bunchConfigB1);
140 if (nMeas == 0) {
141 LOG(warn) << "Bunch Config Beam 1 not present/empty";
142 }
143 if (nMeas > 1) {
144 LOGP(warn, "More than one measurement {} found for Bunch Config Beam 1, keeping the last one", nMeas);
145 }
146
147 // Bunch Config for B2
148 mReader.readValue<int>("CIRCULATING_BUNCH_CONFIG_BEAM2", type, nEle, nMeas, bunchConfigB2);
149 if (nMeas == 0) {
150 LOG(warn) << "Bunch Config Beam 2 not present/empty";
151 }
152 if (nMeas > 1) {
153 LOGP(warn, "More than one measurement {} found for Bunch Config Beam 2, keeping the last one", nMeas);
154 }
155
156 // Building Bunch Filling
157 if (!bunchConfigB1.empty() && !bunchConfigB2.empty()) {
158 o2::BunchFilling bunchFilling;
159 bunchFilling.buckets2BeamPattern(bunchConfigB1.back().second, 0);
160 bunchFilling.buckets2BeamPattern(bunchConfigB2.back().second, 1);
161 bunchFilling.setInteractingBCsFromBeams();
162 lhcifdata.setBunchFillingWithTime((bunchConfigB1.back().first + bunchConfigB2.back().first) / 2, bunchFilling);
163 }
164
165 lhcifdata.setBeamAZ();
166
167 if (mVerbose) {
168 LOG(info) << " **** Beam Energy ****";
169 for (auto& el : beamEnergy) {
170 for (auto elVect : el.second) {
171 std::cout << el.first << " --> " << elVect << std::endl;
172 }
173 }
174 LOG(info) << " **** Injection Scheme ****";
175 for (auto& el : injScheme) {
176 for (auto elVect : el.second) {
177 std::cout << el.first << " --> " << elVect << std::endl;
178 }
179 }
180 LOG(info) << " **** Fill Number ****";
181 for (auto& el : fillNb) {
182 for (auto elVect : el.second) {
183 std::cout << el.first << " --> " << elVect << std::endl;
184 }
185 }
186 LOG(info) << " **** Atomic Number Beam 1 (clockwise) ****";
187 for (auto& el : atomicNbB1) {
188 for (auto elVect : el.second) {
189 std::cout << el.first << " --> " << elVect << std::endl;
190 }
191 }
192 LOG(info) << " **** Atomic Number B2 (anticlockwise) ****";
193 for (auto& el : atomicNbB2) {
194 for (auto elVect : el.second) {
195 std::cout << el.first << " --> " << elVect << std::endl;
196 }
197 }
198 LOG(info) << " **** Crossing Angle ****";
199 for (auto& el : crossAngle) {
200 for (auto elVect : el.second) {
201 std::cout << el.first << " --> " << elVect << std::endl;
202 }
203 }
204 }
205
206 sendOutput(pc.outputs(), timer, lhcifdata);
207}
208
209//__________________________________________________________________
210
214
215//__________________________________________________________________
216
217void GRPLHCIFfileProcessor::sendOutput(DataAllocator& output, long start, const GRPLHCIFData& lhcifdata)
218{
219 // sending output to CCDB
220
222 auto clName = o2::utils::MemFileHelper::getClassName(lhcifdata);
223 auto flName = o2::ccdb::CcdbApi::generateFileName(clName);
224 std::map<std::string, std::string> md;
225 md.emplace("created_by", "dpl");
226 if (lhcifdata.getFillNumberTime()) {
227 md.emplace("fillNumber", fmt::format("{}", lhcifdata.getFillNumber()));
228 }
229 o2::ccdb::CcdbObjectInfo info("GLO/Config/GRPLHCIF", clName, flName, md, start, start + o2::ccdb::CcdbObjectInfo::MONTH);
230 auto image = o2::ccdb::CcdbApi::createObjectImage(&lhcifdata, &info);
231 LOG(info) << "Sending object " << info.getPath() << "/" << info.getFileName() << " of size " << image->size()
232 << " bytes, valid for " << info.getStartValidityTimestamp() << " : " << info.getEndValidityTimestamp();
233 output.snapshot(Output{o2::calibration::Utils::gDataOriginCDBPayload, "GRP_LHCIFData", 0}, *image.get()); // vector<char>
234 output.snapshot(Output{o2::calibration::Utils::gDataOriginCDBWrapper, "GRP_LHCIFData", 0}, info); // root-serialized
235}
236
237} // namespace grp
238
239namespace framework
240{
241DataProcessorSpec getGRPLHCIFfileSpec()
242{
243 std::vector<OutputSpec> outputs;
244 outputs.emplace_back(ConcreteDataTypeMatcher{o2::calibration::Utils::gDataOriginCDBPayload, "GRP_LHCIFData"}, Lifetime::Sporadic);
245 outputs.emplace_back(ConcreteDataTypeMatcher{o2::calibration::Utils::gDataOriginCDBWrapper, "GRP_LHCIFData"}, Lifetime::Sporadic);
246 return DataProcessorSpec{
247 "grp-lhc-if-file-processor",
248 Inputs{{"inputConfig", "GRP", "DCS_CONFIG_FILE", Lifetime::Sporadic},
249 {"inputConfigFileName", "GRP", "DCS_CONFIG_NAME", Lifetime::Sporadic}},
250 outputs,
251 AlgorithmSpec{adaptFromTask<o2::grp::GRPLHCIFfileProcessor>()},
252 Options{{"use-verbose-mode", VariantType::Bool, false, {"Use verbose mode"}}}};
253}
254
255} // namespace framework
256} // namespace o2
Utils and constants for calibration and related workflows.
std::chrono::duration< double, std::ratio< 1, 1 > > Duration
std::chrono::high_resolution_clock HighResClock
void output(const std::map< std::string, ChannelStat > &channels)
Definition rawdump.cxx:197
Header to collect definitions for different units.
void setInteractingBCsFromBeams()
void buckets2BeamPattern(const std::vector< int > &buckets, int ibeam)
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
static constexpr long MONTH
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.
void run(o2::framework::ProcessingContext &pc) final
void init(o2::framework::InitContext &ic) final
void endOfStream(o2::framework::EndOfStreamContext &ec) final
This is invoked whenever we have an EndOfStream event.
void readValue(const std::string &alias, std::string &type, int &nel, int &nmeas, std::vector< std::pair< long, std::vector< T > > > &meas)
void loadLHCIFfile(const std::string &fileName)
void setBeamAZ(int a, int z, beamDirection beam)
void setBunchFillingWithTime(std::pair< long, o2::BunchFilling > p)
void setBeamEnergyPerZWithTime(std::pair< long, int32_t > p)
void setCrossingAngleWithTime(std::pair< long, o2::units::AngleRad_t > p)
void setAtomicNumberB1WithTime(std::pair< long, int32_t > p)
void setFillNumberWithTime(std::pair< long, int32_t > p)
int32_t getFillNumber() const
void setInjectionSchemeWithTime(std::pair< long, std::string > p)
void setAtomicNumberB2WithTime(std::pair< long, int32_t > p)
GLeglImageOES image
Definition glcorearb.h:4021
GLint GLint GLsizei GLint GLenum GLenum type
Definition glcorearb.h:275
GLuint start
Definition glcorearb.h:469
Defining PrimaryVertex explicitly as messageable.
Definition TFIDInfo.h:20
std::vector< InputSpec > Inputs
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
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"