Project
Loading...
Searching...
No Matches
ClusterTransformerSpec.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
20#include "Framework/Lifetime.h"
21#include "Framework/Logger.h"
22#include "Framework/Output.h"
23#include "Framework/Task.h"
27#include "MathUtils/Cartesian.h"
28#include <algorithm>
29#include <chrono>
30#include <filesystem>
31#include <fstream>
32#include <vector>
34
35using namespace std;
36using namespace o2::framework;
37namespace fs = std::filesystem;
38
39namespace o2::mch
40{
41
42// convert all clusters from local to global reference frames
44 gsl::span<const Cluster> localClusters,
45 std::vector<Cluster, o2::pmr::polymorphic_allocator<Cluster>>& globalClusters)
46{
47 int i{0};
48 globalClusters.insert(globalClusters.end(), localClusters.begin(), localClusters.end());
49 for (auto& c : localClusters) {
50 auto deId = c.getDEId();
51 o2::math_utils::Point3D<float> local{c.x, c.y, c.z};
52 auto t = transformation(deId);
53 auto global = t(local);
54 auto& gcluster = globalClusters[i];
55 gcluster.x = global.x();
56 gcluster.y = global.y();
57 gcluster.z = global.z();
58 i++;
59 }
60}
61
63{
64 public:
65 ClusterTransformerTask(std::shared_ptr<base::GRPGeomRequest> req) : mCcdbRequest(req)
66 {
67 }
68
69 void finaliseCCDB(ConcreteDataMatcher& matcher, void* obj)
70 {
71 if (mCcdbRequest) {
74 }
75 }
76
77 void readGeometryFromFile(std::string geoFile)
78 {
79 std::string ext = fs::path(geoFile).extension();
80 std::transform(ext.begin(), ext.begin(), ext.end(), [](unsigned char c) { return std::tolower(c); });
81
82 if (ext == ".json") {
83 std::ifstream in(geoFile);
84 if (!in.is_open()) {
85 throw std::invalid_argument("cannot open geometry file" + geoFile);
86 }
88 } else if (ext == ".root") {
91 } else {
92 throw std::invalid_argument("Geometry from file can only be in JSON or Root format");
93 }
94 }
95
96 void init(InitContext& ic)
97 {
98 if (mCcdbRequest) {
100 } else {
101 auto geoFile = ic.options().get<std::string>("geometry");
102 readGeometryFromFile(geoFile);
103 }
104 }
105
106 // read the clusters (assumed to be in local reference frame) and
107 // tranform them into master reference frame.
109 {
110 if (mCcdbRequest) {
112 }
113
114 // get the input clusters
115 auto localClusters = pc.inputs().get<gsl::span<Cluster>>("clusters");
116
117 // create the output message
118 auto& globalClusters = pc.outputs().make<std::vector<Cluster>>(OutputRef{"globalclusters"});
119
120 local2global(transformation, localClusters, globalClusters);
121 }
122
123 public:
125 std::shared_ptr<base::GRPGeomRequest> mCcdbRequest;
126};
127
129{
130 std::string inputConfig = fmt::format("rofs:MCH/CLUSTERROFS;clusters:MCH/CLUSTERS");
131 auto inputs = o2::framework::select(inputConfig.c_str());
132
133 auto ccdbRequest = disableCcdb ? nullptr : std::make_shared<o2::base::GRPGeomRequest>(false, // orbitResetTime
134 false, // GRPECS=true
135 false, // GRPLHCIF
136 false, // GRPMagField
137 false, // askMatLUT
139 inputs);
140 return DataProcessorSpec{
141 specName,
142 inputs,
143 Outputs{OutputSpec{{"globalclusters"}, "MCH", "GLOBALCLUSTERS", 0, Lifetime::Timeframe}},
144 AlgorithmSpec{adaptFromTask<ClusterTransformerTask>(ccdbRequest)},
145 Options{
146 {"geometry", VariantType::String, o2::base::NameConf::getGeomFileName(), {"input geometry file (JSON or Root format)"}}}};
147}
148
149} // namespace o2::mch
Definition of the MCH cluster minimal structure.
Definition of the GeometryManager class.
int32_t i
Helper for geometry and GRP related CCDB requests.
Definition of the Names Generator class.
uint32_t c
Definition RawData.h:2
const char * specName
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 void loadGeometry(std::string_view geomFilePath="", bool applyMisalignment=false, bool preferAlignedFile=true)
static std::string getGeomFileName(const std::string_view prefix="")
Definition NameConf.cxx:40
decltype(auto) make(const Output &spec, Args... args)
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.
o2::mch::geo::TransformationCreator transformation
std::shared_ptr< base::GRPGeomRequest > mCcdbRequest
void finaliseCCDB(ConcreteDataMatcher &matcher, void *obj)
ClusterTransformerTask(std::shared_ptr< base::GRPGeomRequest > req)
void readGeometryFromFile(std::string geoFile)
Defining PrimaryVertex explicitly as messageable.
Definition TFIDInfo.h:20
std::vector< ConfigParamSpec > Options
std::vector< InputSpec > select(char const *matcher="")
std::vector< OutputSpec > Outputs
TransformationCreator transformationFromJSON(std::istream &in)
TransformationCreator transformationFromTGeoManager(const TGeoManager &geo)
std::function< o2::math_utils::Transform3D(int detElemId)> TransformationCreator
o2::framework::DataProcessorSpec getClusterTransformerSpec(const char *specName="mch-cluster-transformer", bool disableCcdb=false)
void local2global(geo::TransformationCreator transformation, gsl::span< const Cluster > localClusters, std::vector< Cluster, o2::pmr::polymorphic_allocator< Cluster > > &globalClusters)
Defining DataPointCompositeObject explicitly as copiable.
cluster minimal structure
Definition Cluster.h:31
auto transformation