Project
Loading...
Searching...
No Matches
GRPGeomHelper.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
15
16#include <fmt/format.h>
17#include <TGeoGlobalMagField.h>
18#include <TGeoManager.h>
19#include "Field/MagneticField.h"
23#include "Framework/InputSpec.h"
33
35using namespace o2::base;
36using namespace o2::framework;
37namespace o2d = o2::dataformats;
38
39GRPGeomRequest::GRPGeomRequest(bool orbitResetTime, bool GRPECS, bool GRPLHCIF, bool GRPMagField, bool askMatLUT, GeomRequest geom, std::vector<o2::framework::InputSpec>& inputs, bool askOnce, bool needPropD, std::string detMaskString)
40 : askGRPECS(GRPECS), askGRPLHCIF(GRPLHCIF), askGRPMagField(GRPMagField), askMatLUT(askMatLUT), askTime(orbitResetTime), askOnceAllButField(askOnce), needPropagatorD(needPropD)
41{
42 if (geom == Aligned) {
43 askGeomAlign = true;
44 addInput({"geomAlg", "GLO", "GEOMALIGN", 0, Lifetime::Condition, ccdbParamSpec("GLO/Config/GeometryAligned")}, inputs);
45 } else if (geom == Ideal || geom == Alignments) {
46 askGeomIdeal = true;
47 addInput({"geomIdeal", "GLO", "GEOMIDEAL", 0, Lifetime::Condition, ccdbParamSpec("GLO/Config/Geometry")}, inputs);
48 }
49 if (geom == Alignments) {
50 askAlignments = true;
51 o2::detectors::DetID::mask_t algDetMask = DetID::getMask(detMaskString);
52 for (auto id = DetID::First; id <= DetID::Last; id++) {
53 if (algDetMask[id]) {
54 std::string binding = fmt::format("align{}", DetID::getName(id));
55 addInput({binding, DetID::getDataOrigin(id), "ALIGNMENT", 0, Lifetime::Condition, ccdbParamSpec(fmt::format("{}/Calib/Align", DetID::getName(id)))}, inputs);
56 }
57 }
58 }
59 if (askMatLUT) {
60 addInput({"matLUT", "GLO", "MATLUT", 0, Lifetime::Condition, ccdbParamSpec("GLO/Param/MatLUT")}, inputs);
61 }
62 if (askTime) {
63 addInput({"orbitReset", "CTP", "ORBITRESET", 0, Lifetime::Condition, ccdbParamSpec("CTP/Calib/OrbitReset")}, inputs);
64 }
65 if (askGRPECS) {
66 addInput({"grpecs", "GLO", "GRPECS", 0, Lifetime::Condition, ccdbParamSpec("GLO/Config/GRPECS", 1)}, inputs); // Run dependent !!!
67 }
68 if (askGRPLHCIF) {
69 addInput({"grplhcif", "GLO", "GRPLHCIF", 0, Lifetime::Condition, ccdbParamSpec("GLO/Config/GRPLHCIF")}, inputs);
70 }
71 if (askGRPMagField) {
72 addInput({"grpfield", "GLO", "GRPMAGFIELD", 0, Lifetime::Condition, ccdbParamSpec("GLO/Config/GRPMagField", {}, 1)}, inputs); // query every TF
73 }
74}
75
76void GRPGeomRequest::requireAggregateRunInfo(std::vector<o2::framework::InputSpec>& inputs)
77{
79 // require dependencies
80 if (!askGRPECS) {
81 askGRPECS = true;
82 addInput({"grpecs", "GLO", "GRPECS", 0, Lifetime::Condition, ccdbParamSpec("GLO/Config/GRPECS", 1)}, inputs);
83 }
84 if (!askTime) {
85 askTime = true;
86 addInput({"orbitReset", "CTP", "ORBITRESET", 0, Lifetime::Condition, ccdbParamSpec("CTP/Calib/OrbitReset")}, inputs);
87 }
88 addInput({"RCTRunInfo", "RCT", "RunInfo", 0, Lifetime::Condition, ccdbParamSpec("RCT/Info/RunInformation", 2)}, inputs);
89 addInput({"CTPRunOrbit", "CTP", "RunOrbit", 0, Lifetime::Condition, ccdbParamSpec("CTP/Calib/FirstRunOrbit")}, inputs); // TODO: should become run-depenendent (1) object
90}
91
92void GRPGeomRequest::addInput(const o2::framework::InputSpec&& isp, std::vector<o2::framework::InputSpec>& inputs)
93{
94 if (std::find(inputs.begin(), inputs.end(), isp) == inputs.end()) {
95 inputs.emplace_back(isp);
96 }
97}
98
99//=====================================================================================
100
101void GRPGeomHelper::setRequest(std::shared_ptr<GRPGeomRequest> req)
102{
103 if (mRequest) {
104 LOG(fatal) << "GRP/Geometry CCDB request was already set";
105 }
106 mRequest = req;
107}
108
110{
111 if (mRequest->askGRPMagField && matcher == ConcreteDataMatcher("GLO", "GRPMAGFIELD", 0)) {
112 bool needInit = mGRPMagField == nullptr;
113 mGRPMagField = (o2::parameters::GRPMagField*)obj;
114 LOG(info) << "GRP MagField object updated";
115 if (needInit) {
117 if (mRequest->needPropagatorD) {
119 }
120 } else {
121 auto field = TGeoGlobalMagField::Instance()->GetField();
122 if (field->InheritsFrom("o2::field::MagneticField")) {
123 ((o2::field::MagneticField*)field)->rescaleField(mGRPMagField->getL3Current(), mGRPMagField->getDipoleCurrent(), mGRPMagField->getFieldUniformity());
124 }
125 o2::base::Propagator::Instance(false)->updateField();
126 if (mRequest->needPropagatorD) {
127 o2::base::PropagatorD::Instance(false)->updateField();
128 }
129 }
130 return true;
131 }
132 if (mRequest->askGRPECS && matcher == ConcreteDataMatcher("GLO", "GRPECS", 0)) {
133 mGRPECS = (o2::parameters::GRPECSObject*)obj;
134 LOG(info) << "GRP ECS object updated";
135 return true;
136 }
137 if (mRequest->askGRPLHCIF && matcher == ConcreteDataMatcher("GLO", "GRPLHCIF", 0)) {
138 mGRPLHCIF = (o2::parameters::GRPLHCIFData*)obj;
139 LOG(info) << "GRP LHCIF object updated";
140 return true;
141 }
142 if (mRequest->askTime && matcher == ConcreteDataMatcher("CTP", "ORBITRESET", 0)) {
143 mOrbitResetTimeMUS = (*(std::vector<Long64_t>*)obj)[0];
144 LOG(info) << "orbit reset time updated to " << mOrbitResetTimeMUS;
145 return true;
146 }
147 if (mRequest->askMatLUT && matcher == ConcreteDataMatcher("GLO", "MATLUT", 0)) {
148 LOG(info) << "material LUT updated";
150 o2::base::Propagator::Instance(false)->setMatLUT(mMatLUT);
151 if (mRequest->needPropagatorD) {
152 o2::base::PropagatorD::Instance(false)->setMatLUT(mMatLUT);
153 }
154 return true;
155 }
156 if (mRequest->askGeomAlign && matcher == ConcreteDataMatcher("GLO", "GEOMALIGN", 0)) {
157 LOG(info) << "aligned geometry updated";
158 return true;
159 }
160 if (mRequest->askGeomIdeal && matcher == ConcreteDataMatcher("GLO", "GEOMIDEAL", 0)) {
161 LOG(info) << "ideal geometry updated";
162 return true;
163 }
164 constexpr o2::header::DataDescription algDesc{"ALIGNMENT"};
165 if (mRequest->askAlignments && matcher.description == algDesc) {
166 for (auto id = DetID::First; id <= DetID::Last; id++) {
167 if (matcher.origin == DetID::getDataOrigin(id)) {
168 LOG(info) << DetID::getName(id) << " alignment updated";
169 mAlignments[id] = (std::vector<o2::detectors::AlignParam>*)obj;
170 break;
171 }
172 }
173 return true;
174 }
175 return false;
176}
177
179{
180 // request input just to trigger finaliseCCDB if there was an update
181
182 if (mRequest->askGRPMagField) { // always check
183 if (pc.inputs().isValid("grpfield")) {
184 pc.inputs().get<o2::parameters::GRPMagField*>("grpfield");
185 } else {
186 return;
187 }
188 }
189
190 bool checkTF = pc.services().get<o2::framework::TimingInfo>().globalRunNumberChanged || !mRequest->askOnceAllButField;
191
192 if (checkTF) {
193 if (mRequest->askGRPLHCIF) {
194 if (pc.inputs().isValid("grplhcif")) {
195 pc.inputs().get<o2::parameters::GRPLHCIFData*>("grplhcif");
196 } else {
197 return;
198 }
199 }
200 if (mRequest->askGRPECS) {
201 if (pc.inputs().isValid("grpecs")) {
202 pc.inputs().get<o2::parameters::GRPECSObject*>("grpecs");
203 } else {
204 return;
205 }
206 }
207 if (mRequest->askTime) {
208 if (pc.inputs().isValid("orbitReset")) {
209 pc.inputs().get<std::vector<Long64_t>*>("orbitReset");
210 } else {
211 return;
212 }
213 }
214 if (mRequest->askMatLUT) {
215 if (pc.inputs().isValid("matLUT")) {
216 pc.inputs().get<o2::base::MatLayerCylSet*>("matLUT");
217 } else {
218 return;
219 }
220 }
221 if (mRequest->askGeomAlign) {
222 if (pc.inputs().isValid("geomAlg")) {
223 pc.inputs().get<TGeoManager*>("geomAlg");
224 } else {
225 return;
226 }
227 } else if (mRequest->askGeomIdeal) {
228 if (pc.inputs().isValid("geomIdeal")) {
229 pc.inputs().get<TGeoManager*>("geomIdeal");
230 } else {
231 return;
232 }
233 }
234 if (mRequest->askAlignments) {
235 for (auto id = DetID::First; id <= DetID::Last; id++) {
236 std::string binding = fmt::format("align{}", DetID::getName(id));
237 if (pc.inputs().getPos(binding.c_str()) < 0) {
238 continue;
239 } else {
240 pc.inputs().get<std::vector<o2::detectors::AlignParam>*>(binding);
241 }
242 }
243 }
244 if (mRequest->askAggregateRunInfo) {
245 const auto hmap = pc.inputs().get<o2::framework::CCDBMetadataExtractor>("RCTRunInfo"); // metadata only!
247 auto ctfFirstRunOrbitVec = pc.inputs().get<std::vector<Long64_t>*>("CTPRunOrbit");
248 mAggregatedRunInfo = o2::parameters::AggregatedRunInfo::buildAggregatedRunInfo(pc.services().get<o2::framework::TimingInfo>().runNumber, rl.first, rl.second, mOrbitResetTimeMUS, mGRPECS, ctfFirstRunOrbitVec.get());
249 LOGP(debug, "Extracted AggregateRunInfo: runNumber:{}, sor:{}, eor:{}, orbitsPerTF:{}, orbitReset:{}, orbitSOR:{}, orbitEOR:{}",
250 mAggregatedRunInfo.runNumber, mAggregatedRunInfo.sor, mAggregatedRunInfo.eor, mAggregatedRunInfo.orbitsPerTF, mAggregatedRunInfo.orbitReset, mAggregatedRunInfo.orbitSOR, mAggregatedRunInfo.orbitEOR);
251 }
252 }
253}
254
256{
257 return instance().mGRPECS ? instance().mGRPECS->getNHBFPerTF() : 128;
258}
std::string binding
Definition of the base alignment parameters class.
std::ostringstream debug
Header of the AggregatedRunInfo struct.
Helper for geometry and GRP related CCDB requests.
container for the LHC InterFace data
Header of the General Run Parameters object for B field values.
Definition of the MagF class.
Declarations for the wrapper for the set of cylindrical material layers.
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 MatLayerCylSet * rectifyPtrFromFile(MatLayerCylSet *ptr)
static int initFieldFromGRP(const o2::parameters::GRPMagField *grp, bool verbose=false)
GPUd() value_type estimateLTFast(o2 static GPUd() float estimateLTIncrement(const o2 PropagatorImpl * Instance(bool uninitialized=false)
Definition Propagator.h:147
std::pair< int64_t, int64_t > getRunDuration(int runnumber, bool fatal=true)
Static class with identifiers, bitmasks and names for ALICE detectors.
Definition DetID.h:58
static constexpr const char * getName(ID id)
names of defined detectors
Definition DetID.h:146
static constexpr ID First
Definition DetID.h:95
static constexpr ID Last
if extra detectors added, update this !!!
Definition DetID.h:93
static constexpr o2h::DataOrigin getDataOrigin(ID id)
Definition DetID.h:148
static mask_t getMask(const std::string_view detList)
detector masks from any non-alpha-num delimiter-separated list (empty if NONE is supplied)
Definition DetID.cxx:42
int getPos(const char *name) const
bool isValid(std::string const &s) const
Helper method to be used to check if a given part of the InputRecord is present.
decltype(auto) get(R binding, int part=0) const
InputRecord & inputs()
The inputs associated with this processing context.
ServiceRegistryRef services()
The services registry associated with this processing context.
uint32_t getNHBFPerTF() const
o2::units::Current_t getDipoleCurrent() const
Definition GRPMagField.h:43
bool getFieldUniformity() const
Definition GRPMagField.h:49
o2::units::Current_t getL3Current() const
getters/setters for magnets currents
Definition GRPMagField.h:37
GLuint id
Definition glcorearb.h:650
Definition of a container to keep/associate and arbitrary number of labels associated to an index wit...
Defining PrimaryVertex explicitly as messageable.
std::vector< ConfigParamSpec > ccdbParamSpec(std::string const &path, int runDependent, std::vector< CCDBMetadata > metadata={}, int qrate=0)
void requireAggregateRunInfo(std::vector< o2::framework::InputSpec > &inputs)
void addInput(const o2::framework::InputSpec &&isp, std::vector< o2::framework::InputSpec > &inputs)
static AggregatedRunInfo buildAggregatedRunInfo(int runnumber, long sorMS, long eorMS, long orbitResetMUS, const o2::parameters::GRPECSObject *grpecs, const std::vector< Long64_t > *ctfFirstRunOrbitVec)
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"