forked from AliceO2Group/AliceO2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGRPGeomHelper.cxx
More file actions
258 lines (244 loc) · 10.2 KB
/
GRPGeomHelper.cxx
File metadata and controls
258 lines (244 loc) · 10.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.
/// \file GRPGeomHelper.cxx
/// \brief Helper for geometry and GRP related CCDB requests
/// \author ruben.shahoyan@cern.ch
#include <fmt/format.h>
#include <TGeoGlobalMagField.h>
#include <TGeoManager.h>
#include "Field/MagneticField.h"
#include "DetectorsBase/GRPGeomHelper.h"
#include "Framework/ProcessingContext.h"
#include "Framework/DataRefUtils.h"
#include "Framework/InputSpec.h"
#include "Framework/InputRecord.h"
#include "Framework/TimingInfo.h"
#include "Framework/CCDBParamSpec.h"
#include "DetectorsBase/MatLayerCylSet.h"
#include "DetectorsBase/Propagator.h"
#include "DetectorsCommonDataFormats/AlignParam.h"
#include "DataFormatsParameters/GRPLHCIFData.h"
#include "DataFormatsParameters/GRPECSObject.h"
#include "DataFormatsParameters/GRPMagField.h"
using DetID = o2::detectors::DetID;
using namespace o2::base;
using namespace o2::framework;
namespace o2d = o2::dataformats;
GRPGeomRequest::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)
: askGRPECS(GRPECS), askGRPLHCIF(GRPLHCIF), askGRPMagField(GRPMagField), askMatLUT(askMatLUT), askTime(orbitResetTime), askOnceAllButField(askOnce), needPropagatorD(needPropD)
{
if (geom == Aligned) {
askGeomAlign = true;
addInput({"geomAlg", "GLO", "GEOMALIGN", 0, Lifetime::Condition, ccdbParamSpec("GLO/Config/GeometryAligned")}, inputs);
} else if (geom == Ideal || geom == Alignments) {
askGeomIdeal = true;
addInput({"geomIdeal", "GLO", "GEOMIDEAL", 0, Lifetime::Condition, ccdbParamSpec("GLO/Config/Geometry")}, inputs);
}
if (geom == Alignments) {
askAlignments = true;
o2::detectors::DetID::mask_t algDetMask = DetID::getMask(detMaskString);
for (auto id = DetID::First; id <= DetID::Last; id++) {
if (algDetMask[id]) {
std::string binding = fmt::format("align{}", DetID::getName(id));
addInput({binding, DetID::getDataOrigin(id), "ALIGNMENT", 0, Lifetime::Condition, ccdbParamSpec(fmt::format("{}/Calib/Align", DetID::getName(id)))}, inputs);
}
}
}
if (askMatLUT) {
addInput({"matLUT", "GLO", "MATLUT", 0, Lifetime::Condition, ccdbParamSpec("GLO/Param/MatLUT")}, inputs);
}
if (askTime) {
addInput({"orbitReset", "CTP", "ORBITRESET", 0, Lifetime::Condition, ccdbParamSpec("CTP/Calib/OrbitReset")}, inputs);
}
if (askGRPECS) {
addInput({"grpecs", "GLO", "GRPECS", 0, Lifetime::Condition, ccdbParamSpec("GLO/Config/GRPECS", 1)}, inputs); // Run dependent !!!
}
if (askGRPLHCIF) {
addInput({"grplhcif", "GLO", "GRPLHCIF", 0, Lifetime::Condition, ccdbParamSpec("GLO/Config/GRPLHCIF")}, inputs);
}
if (askGRPMagField) {
addInput({"grpfield", "GLO", "GRPMAGFIELD", 0, Lifetime::Condition, ccdbParamSpec("GLO/Config/GRPMagField", {}, 1)}, inputs); // query every TF
}
}
void GRPGeomRequest::requireAggregateRunInfo(std::vector<o2::framework::InputSpec>& inputs)
{
askAggregateRunInfo = true;
// require dependencies
if (!askGRPECS) {
askGRPECS = true;
addInput({"grpecs", "GLO", "GRPECS", 0, Lifetime::Condition, ccdbParamSpec("GLO/Config/GRPECS", 1)}, inputs);
}
if (!askTime) {
askTime = true;
addInput({"orbitReset", "CTP", "ORBITRESET", 0, Lifetime::Condition, ccdbParamSpec("CTP/Calib/OrbitReset")}, inputs);
}
addInput({"RCTRunInfo", "RCT", "RunInfo", 0, Lifetime::Condition, ccdbParamSpec("RCT/Info/RunInformation", 2)}, inputs);
addInput({"CTPRunOrbit", "CTP", "RunOrbit", 0, Lifetime::Condition, ccdbParamSpec("CTP/Calib/FirstRunOrbit")}, inputs); // TODO: should become run-depenendent (1) object
}
void GRPGeomRequest::addInput(const o2::framework::InputSpec&& isp, std::vector<o2::framework::InputSpec>& inputs)
{
if (std::find(inputs.begin(), inputs.end(), isp) == inputs.end()) {
inputs.emplace_back(isp);
}
}
//=====================================================================================
void GRPGeomHelper::setRequest(std::shared_ptr<GRPGeomRequest> req)
{
if (mRequest) {
LOG(fatal) << "GRP/Geometry CCDB request was already set";
}
mRequest = req;
}
bool GRPGeomHelper::finaliseCCDB(ConcreteDataMatcher& matcher, void* obj)
{
if (mRequest->askGRPMagField && matcher == ConcreteDataMatcher("GLO", "GRPMAGFIELD", 0)) {
bool needInit = mGRPMagField == nullptr;
mGRPMagField = (o2::parameters::GRPMagField*)obj;
LOG(info) << "GRP MagField object updated";
if (needInit) {
o2::base::Propagator::initFieldFromGRP(mGRPMagField);
if (mRequest->needPropagatorD) {
o2::base::PropagatorD::initFieldFromGRP(mGRPMagField);
}
} else {
auto field = TGeoGlobalMagField::Instance()->GetField();
if (field->InheritsFrom("o2::field::MagneticField")) {
((o2::field::MagneticField*)field)->rescaleField(mGRPMagField->getL3Current(), mGRPMagField->getDipoleCurrent(), mGRPMagField->getFieldUniformity());
}
o2::base::Propagator::Instance(false)->updateField();
if (mRequest->needPropagatorD) {
o2::base::PropagatorD::Instance(false)->updateField();
}
}
return true;
}
if (mRequest->askGRPECS && matcher == ConcreteDataMatcher("GLO", "GRPECS", 0)) {
mGRPECS = (o2::parameters::GRPECSObject*)obj;
LOG(info) << "GRP ECS object updated";
return true;
}
if (mRequest->askGRPLHCIF && matcher == ConcreteDataMatcher("GLO", "GRPLHCIF", 0)) {
mGRPLHCIF = (o2::parameters::GRPLHCIFData*)obj;
LOG(info) << "GRP LHCIF object updated";
return true;
}
if (mRequest->askTime && matcher == ConcreteDataMatcher("CTP", "ORBITRESET", 0)) {
mOrbitResetTimeMUS = (*(std::vector<Long64_t>*)obj)[0];
LOG(info) << "orbit reset time updated to " << mOrbitResetTimeMUS;
return true;
}
if (mRequest->askMatLUT && matcher == ConcreteDataMatcher("GLO", "MATLUT", 0)) {
LOG(info) << "material LUT updated";
mMatLUT = o2::base::MatLayerCylSet::rectifyPtrFromFile((o2::base::MatLayerCylSet*)obj);
o2::base::Propagator::Instance(false)->setMatLUT(mMatLUT);
if (mRequest->needPropagatorD) {
o2::base::PropagatorD::Instance(false)->setMatLUT(mMatLUT);
}
return true;
}
if (mRequest->askGeomAlign && matcher == ConcreteDataMatcher("GLO", "GEOMALIGN", 0)) {
LOG(info) << "aligned geometry updated";
return true;
}
if (mRequest->askGeomIdeal && matcher == ConcreteDataMatcher("GLO", "GEOMIDEAL", 0)) {
LOG(info) << "ideal geometry updated";
return true;
}
constexpr o2::header::DataDescription algDesc{"ALIGNMENT"};
if (mRequest->askAlignments && matcher.description == algDesc) {
for (auto id = DetID::First; id <= DetID::Last; id++) {
if (matcher.origin == DetID::getDataOrigin(id)) {
LOG(info) << DetID::getName(id) << " alignment updated";
mAlignments[id] = (std::vector<o2::detectors::AlignParam>*)obj;
break;
}
}
return true;
}
return false;
}
void GRPGeomHelper::checkUpdates(ProcessingContext& pc)
{
// request input just to trigger finaliseCCDB if there was an update
if (mRequest->askGRPMagField) { // always check
if (pc.inputs().isValid("grpfield")) {
pc.inputs().get<o2::parameters::GRPMagField*>("grpfield");
} else {
return;
}
}
bool checkTF = pc.services().get<o2::framework::TimingInfo>().globalRunNumberChanged || !mRequest->askOnceAllButField;
if (checkTF) {
if (mRequest->askGRPLHCIF) {
if (pc.inputs().isValid("grplhcif")) {
pc.inputs().get<o2::parameters::GRPLHCIFData*>("grplhcif");
} else {
return;
}
}
if (mRequest->askGRPECS) {
if (pc.inputs().isValid("grpecs")) {
pc.inputs().get<o2::parameters::GRPECSObject*>("grpecs");
} else {
return;
}
}
if (mRequest->askTime) {
if (pc.inputs().isValid("orbitReset")) {
pc.inputs().get<std::vector<Long64_t>*>("orbitReset");
} else {
return;
}
}
if (mRequest->askMatLUT) {
if (pc.inputs().isValid("matLUT")) {
pc.inputs().get<o2::base::MatLayerCylSet*>("matLUT");
} else {
return;
}
}
if (mRequest->askGeomAlign) {
if (pc.inputs().isValid("geomAlg")) {
pc.inputs().get<TGeoManager*>("geomAlg");
} else {
return;
}
} else if (mRequest->askGeomIdeal) {
if (pc.inputs().isValid("geomIdeal")) {
pc.inputs().get<TGeoManager*>("geomIdeal");
} else {
return;
}
}
if (mRequest->askAlignments) {
for (auto id = DetID::First; id <= DetID::Last; id++) {
std::string binding = fmt::format("align{}", DetID::getName(id));
if (pc.inputs().getPos(binding.c_str()) < 0) {
continue;
} else {
pc.inputs().get<std::vector<o2::detectors::AlignParam>*>(binding);
}
}
}
if (mRequest->askAggregateRunInfo) {
const auto hmap = pc.inputs().get<o2::framework::CCDBMetadataExtractor>("RCTRunInfo"); // metadata only!
auto rl = o2::ccdb::BasicCCDBManager::getRunDuration(hmap);
auto ctfFirstRunOrbitVec = pc.inputs().get<std::vector<Long64_t>*>("CTPRunOrbit");
mAggregatedRunInfo = o2::parameters::AggregatedRunInfo::buildAggregatedRunInfo(pc.services().get<o2::framework::TimingInfo>().runNumber, rl.first, rl.second, mOrbitResetTimeMUS, mGRPECS, ctfFirstRunOrbitVec.get());
LOGP(debug, "Extracted AggregateRunInfo: runNumber:{}, sor:{}, eor:{}, orbitsPerTF:{}, orbitReset:{}, orbitSOR:{}, orbitEOR:{}",
mAggregatedRunInfo.runNumber, mAggregatedRunInfo.sor, mAggregatedRunInfo.eor, mAggregatedRunInfo.orbitsPerTF, mAggregatedRunInfo.orbitReset, mAggregatedRunInfo.orbitSOR, mAggregatedRunInfo.orbitEOR);
}
}
}
int GRPGeomHelper::getNHBFPerTF()
{
return instance().mGRPECS ? instance().mGRPECS->getNHBFPerTF() : 128;
}