Project
Loading...
Searching...
No Matches
create-aligned-geometry.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
12#include <ctime>
13#include <chrono>
18#include <TGeoManager.h>
21#include "MFTBase/GeometryTGeo.h"
23#include "Framework/Task.h"
28#include "Headers/STFHeader.h"
30
32using namespace o2::framework;
33
34/*
35 Simple workflow to create aligned geometry file from the ideal geometry and alignment objects on the CCDB
36 One can profit from the DPL CCDB fetcher --condition-remap functionality to impose difference CCDB
37 servers for different alignment objects.
38 Also, one can use --configKeyValues "HBFUtils.startTime=... functionality to impose the timestamp for the objects to fetch.
39 E.g. to create the geometry using current timestamp and production server, use just
40 o2-create-aligned-geometry-workflow
41
42 To create the geometry using specific timestamp and ITS alignment from the test CCDB server and MFT alignment
43 from the local snapshot file in the locCCDB directory
44 o2-create-aligned-geometry-workflow --condition-remap http://ccdb-test.cern.ch:8080=ITS/Calib/Align;file://locCCDB=MFT/Calib/Align --configKeyValues "HBFUtils.startTime=1546300800000"
45 */
46
47namespace o2::base
48{
49
50class SeederTask : public Task
51{
52 public:
53 void run(ProcessingContext& pc) final
54 {
55 const auto& hbfu = o2::raw::HBFUtils::Instance();
56 auto& tinfo = pc.services().get<o2::framework::TimingInfo>();
57 if (hbfu.startTime != 0) {
58 tinfo.creation = hbfu.startTime;
59 } else {
60 tinfo.creation = std::chrono::time_point_cast<std::chrono::milliseconds>(std::chrono::system_clock::now()).time_since_epoch().count();
61 }
62 if (hbfu.orbitFirstSampled != 0) {
63 tinfo.firstTForbit = hbfu.orbitFirstSampled;
64 } else {
65 tinfo.firstTForbit = 0;
66 }
67 auto& stfDist = pc.outputs().make<o2::header::STFHeader>(Output{"FLP", "DISTSUBTIMEFRAME", 0});
68 pc.services().get<ControlService>().endOfStream();
69 pc.services().get<ControlService>().readyToQuit(QuitRequest::Me);
70 }
71};
72
73class AlignerTask : public Task
74{
75 public:
76 AlignerTask(DetID::mask_t dets, std::shared_ptr<o2::base::GRPGeomRequest> gr) : mDetsMask(dets), mGGCCDBRequest(gr) {}
77 ~AlignerTask() override = default;
78
79 void init(InitContext& ic) final
80 {
82 }
83
84 void run(ProcessingContext& pc) final
85 {
87 for (auto id = DetID::First; id <= DetID::Last; id++) {
88 if (mDetsMask[id]) {
90 if (!alg->empty()) {
91 LOGP(info, "Applying alignment for detector {}", DetID::getName(id));
93 } else {
94 LOGP(info, "Alignment for detector {} is empty", DetID::getName(id));
95 }
96 }
97 }
98 gGeoManager->SetName(std::string(o2::base::NameConf::CCDBOBJECT).c_str());
100 gGeoManager->Export(fnm.c_str());
101 LOGP(info, "Stored aligned geometry to local file {}", fnm);
102
103 // create GeometryTGeo for detectors which support it
104 if (mDetsMask[DetID::ITS]
105#ifdef ENABLE_UPGRADES
106 || mDetsMask[DetID::IT3]
107#endif
108 ) {
109 auto itsTGeo = o2::its::GeometryTGeo::Instance();
111 TFile outF("its_GeometryTGeo.root", "recreate");
112 outF.WriteObjectAny(itsTGeo, "o2::its::GeometryTGeo", "ccdb_object");
113 LOGP(info, "Stored ITS geometry to {}", outF.GetName());
114 outF.Close();
115 itsTGeo->destroy();
116 }
117 if (mDetsMask[DetID::MFT]) {
118 auto mftTGeo = o2::mft::GeometryTGeo::Instance();
120 TFile outF("mft_GeometryTGeo.root", "recreate");
121 outF.WriteObjectAny(mftTGeo, "o2::mft::GeometryTGeo", "ccdb_object");
122 LOGP(info, "Stored MFT geometry to {}", outF.GetName());
123 outF.Close();
124 mftTGeo->destroy();
125 }
126 // consider upgrades?
127
128 pc.services().get<ControlService>().endOfStream();
129 pc.services().get<ControlService>().readyToQuit(QuitRequest::Me);
130 }
131
132 void finaliseCCDB(ConcreteDataMatcher& matcher, void* obj) final
133 {
135 }
136
137 private:
138 DetID::mask_t mDetsMask{};
139 std::shared_ptr<o2::base::GRPGeomRequest> mGGCCDBRequest;
140};
141
142} // namespace o2::base
143
145{
146 std::vector<InputSpec> inputs{{"STFDist", "FLP", "DISTSUBTIMEFRAME", 0}}; // just to have some input
147 auto ggRequest = std::make_shared<o2::base::GRPGeomRequest>(false, // orbitResetTime
148 false, // GRPECS
149 false, // GRPLHCIF
150 false, // GRPMagField
151 false, // askMatLUT
153 inputs, // inputs
154 false, // ask-once
155 false, // dprop
156 DetID::getNames(dets)); // only selected detectors
157
158 return DataProcessorSpec{
159 "geometry-aligned-producer",
160 inputs,
161 {},
162 AlgorithmSpec{adaptFromTask<o2::base::AlignerTask>(dets, ggRequest)},
163 Options{}};
164}
165
167{
168 return DataProcessorSpec{
169 "seeder",
170 Inputs{},
171 Outputs{{"FLP", "DISTSUBTIMEFRAME", 0}},
172 AlgorithmSpec{adaptFromTask<o2::base::SeederTask>()},
173 Options{}};
174}
175
176// ------------------------------------------------------------------
177
178void customize(std::vector<o2::framework::ConfigParamSpec>& workflowOptions)
179{
180 // option allowing to set parameters
181 std::vector<o2::framework::ConfigParamSpec> options{
182 {"onlyDet", VariantType::String, std::string{DetID::ALL}, {"comma-separated list of detectors to account"}},
183 {"configKeyValues", VariantType::String, "", {"Semicolon separated key=value strings ..."}}};
184 std::swap(workflowOptions, options);
185}
186
188
190{
191 // Update the (declared) parameters if changed from the command line
192 o2::conf::ConfigurableParam::updateFromString(configcontext.options().get<std::string>("configKeyValues"));
193 DetID::mask_t dets = DetID::FullMask & DetID::getMask(configcontext.options().get<std::string>("onlyDet"));
195
196 return std::move(specs);
197}
Definition of the GeometryManager class.
Helper for geometry and GRP related CCDB requests.
Definition of the GeometryTGeo class.
Definition of the Names Generator class.
~AlignerTask() override=default
void run(ProcessingContext &pc) final
AlignerTask(DetID::mask_t dets, std::shared_ptr< o2::base::GRPGeomRequest > gr)
void init(InitContext &ic) final
void finaliseCCDB(ConcreteDataMatcher &matcher, void *obj) final
void checkUpdates(o2::framework::ProcessingContext &pc)
auto getAlignment(o2::detectors::DetID det) const
bool finaliseCCDB(o2::framework::ConcreteDataMatcher &matcher, void *obj)
static GRPGeomHelper & instance()
void setRequest(std::shared_ptr< GRPGeomRequest > req)
static bool applyAlignment(const std::vector< o2::detectors::AlignParam > &algPars)
misalign geometry with alignment objects from the array, optionaly check overlaps
static std::string getAlignedGeomFileName(const std::string_view prefix="")
Definition NameConf.cxx:46
static constexpr std::string_view CCDBOBJECT
Definition NameConf.h:66
void run(ProcessingContext &pc) final
static void updateFromString(std::string const &)
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:145
static constexpr std::string_view ALL
keywork for all detectors
Definition DetID.h:104
static std::string getNames(mask_t mask, char delimiter=',')
Definition DetID.cxx:74
static constexpr ID ITS
Definition DetID.h:63
static constexpr ID First
Definition DetID.h:94
static constexpr ID MFT
Definition DetID.h:71
static constexpr mask_t FullMask
Definition DetID.h:100
static constexpr ID Last
if extra detectors added, update this !!!
Definition DetID.h:92
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
ConfigParamRegistry & options() const
virtual void endOfStream(EndOfStreamContext &context)
This is invoked whenever we have an EndOfStream event.
Definition Task.h:43
static GeometryTGeo * Instance()
static GeometryTGeo * Instance()
void customize(std::vector< o2::framework::ConfigParamSpec > &workflowOptions)
WorkflowSpec defineDataProcessing(o2::framework::ConfigContext const &configcontext)
DataProcessorSpec getSeederSpec()
DataProcessorSpec getAlignerSpec(DetID::mask_t dets)
Defining PrimaryVertex explicitly as messageable.
Definition TFIDInfo.h:20
std::vector< DataProcessorSpec > WorkflowSpec
std::vector< InputSpec > Inputs
std::vector< OutputSpec > Outputs
static constexpr int L2G
Definition Cartesian.h:54
static constexpr int T2L
Definition Cartesian.h:55
static constexpr int T2GRot
Definition Cartesian.h:57
static constexpr int T2G
Definition Cartesian.h:56