Project
Loading...
Searching...
No Matches
VertexSamplerSpec.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
16
17#include "VertexSamplerSpec.h"
18
19#include <iostream>
20#include <fstream>
21#include <string>
22
23#include <stdexcept>
24
29#include "Framework/Lifetime.h"
30#include "Framework/Output.h"
31#include "Framework/Task.h"
32#include "Framework/Logger.h"
33
34#include "MathUtils/Cartesian.h"
36
37namespace o2
38{
39namespace mch
40{
41
42using namespace std;
43using namespace o2::framework;
44
46{
47 public:
48 //_________________________________________________________________________________________________
50 {
52 LOG(info) << "initializing vertex sampler";
53
54 auto inputFileName = ic.options().get<std::string>("infile");
55 if (!inputFileName.empty()) {
56 mInputFile.open(inputFileName, ios::binary);
57 if (!mInputFile.is_open()) {
58 throw invalid_argument("Cannot open input file" + inputFileName);
59 }
60 }
61
62 auto stop = [this]() {
64 LOG(info) << "stop vertex sampler";
65 if (mInputFile.is_open()) {
66 this->mInputFile.close();
67 }
68 };
69 ic.services().get<CallbackService>().set<CallbackService::Id::Stop>(stop);
70 }
71
72 //_________________________________________________________________________________________________
74 {
77
78 // get the track ROFs for each event in the TF
79 auto rofs = pc.inputs().get<gsl::span<ROFRecord>>("rofs");
80
81 // create the output message to hold vertices
82 auto& vertices = pc.outputs().make<std::vector<math_utils::Point3D<double>>>(OutputRef{"vertices"});
83
84 // read the vertex of each event or set it to (0,0,0)
85 if (mInputFile.is_open()) {
86 int event(-1);
87 VertexStruct vtx{};
88 vertices.reserve(rofs.size());
89 for (const auto& rof : rofs) {
90 mInputFile.read(reinterpret_cast<char*>(&event), sizeof(int));
91 if (mInputFile.fail() || event != rof.getBCData().orbit) {
92 throw out_of_range(std::string("missing vertex for event ") + rof.getBCData().orbit);
93 }
94 mInputFile.read(reinterpret_cast<char*>(&vtx), sizeof(VertexStruct));
95 vertices.emplace_back(vtx.x, vtx.y, vtx.z);
96 }
97 } else {
98 vertices.resize(rofs.size(), math_utils::Point3D<double>(0., 0., 0.));
99 }
100 }
101
102 private:
103 struct VertexStruct {
104 double x;
105 double y;
106 double z;
107 };
108
109 std::ifstream mInputFile{};
110};
111
112//_________________________________________________________________________________________________
114{
115 return DataProcessorSpec{
116 specName,
117 Inputs{InputSpec{"rofs", "MCH", "TRACKROFS", 0, Lifetime::Timeframe},
118 // track and cluster messages are there just to keep things synchronized
119 InputSpec{"tracks", "MCH", "TRACKS", 0, Lifetime::Timeframe},
120 InputSpec{"clusters", "MCH", "TRACKCLUSTERS", 0, Lifetime::Timeframe}},
121 Outputs{OutputSpec{{"vertices"}, "MCH", "VERTICES", 0, Lifetime::Timeframe}},
122 AlgorithmSpec{adaptFromTask<VertexSamplerSpec>()},
123 Options{{"infile", VariantType::String, "", {"input filename"}}}};
124}
125
126} // end namespace mch
127} // end namespace o2
Definition of the MCH ROFrame record.
Definition of a data processor to read and send vertices.
const char * specName
decltype(auto) make(const Output &spec, Args... args)
ServiceRegistryRef services()
Definition InitContext.h:34
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(framework::ProcessingContext &pc)
void init(framework::InitContext &ic)
struct _cl_event * event
Definition glcorearb.h:2982
GLint GLenum GLint x
Definition glcorearb.h:403
GLdouble GLdouble GLdouble z
Definition glcorearb.h:843
Defining PrimaryVertex explicitly as messageable.
Definition TFIDInfo.h:20
std::vector< ConfigParamSpec > Options
std::vector< InputSpec > Inputs
std::vector< OutputSpec > Outputs
o2::framework::DataProcessorSpec getVertexSamplerSpec(const char *specName)
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
Defining DataPointCompositeObject explicitly as copiable.
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"