Project
Loading...
Searching...
No Matches
StandaloneAODProducerSpec.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#include "Framework/DataTypes.h"
18#include "Framework/Logger.h"
20#include "MathUtils/Utils.h"
21
22using namespace o2::framework;
23
24namespace o2
25{
26namespace emcal
27{
28
30{
31 mTimer.Stop();
32 mTimer.Reset();
33}
34
36{
37 mCaloEventHandler = new o2::emcal::EventHandler<o2::emcal::Cell>();
38 mCaloAmp = 0xFFFFFFFF;
39 mCaloTime = 0xFFFFFFFF;
40
41 mTFNumber = ic.options().get<int64_t>("aod-timeframe-id");
42 mRunNumber = ic.options().get<int>("run-number");
43}
44
46{
47 auto cput = mTimer.CpuTime();
48 mTimer.Start(false);
49
50 const auto& tinfo = pc.services().get<o2::framework::TimingInfo>();
51 uint64_t tfNumber;
52 if (mTFNumber == -1L) {
53 // TODO has to be made globally unique (by using absolute time of TF). For now is unique within the run
54 tfNumber = uint64_t(tinfo.firstTForbit) + (uint64_t(tinfo.runNumber) << 32); // getTFNumber(mStartIR, runNumber);
55 } else {
56 tfNumber = mTFNumber;
57 }
58 const int runNumber = (mRunNumber == -1) ? int(tinfo.runNumber) : mRunNumber;
59
60 auto cellsIn = pc.inputs().get<gsl::span<o2::emcal::Cell>>(getCellBinding());
61 auto triggersIn = pc.inputs().get<gsl::span<o2::emcal::TriggerRecord>>(getCellTriggerRecordBinding());
62
63 LOG(info) << "FOUND " << cellsIn.size() << " EMC cells in CTF";
64 LOG(info) << "FOUND " << triggersIn.size() << " EMC tiggers in CTF";
65
66 auto bcBuilder = pc.outputs().make<TableBuilder>(Output{"AOD", "BC"});
67 auto collisionsBuilder = pc.outputs().make<TableBuilder>(Output{"AOD", "COLLISION"});
68 auto caloCellsBuilder = pc.outputs().make<TableBuilder>(Output{"AOD", "CALO"});
69 auto caloCellsTRGTableBuilder = pc.outputs().make<TableBuilder>(Output{"AOD", "CALOTRIGGER"});
70
71 auto bcCursor = bcBuilder->cursor<o2::aod::BCs>();
72 auto collisionsCursor = collisionsBuilder->cursor<o2::aod::Collisions>();
73 auto caloCellsCursor = caloCellsBuilder->cursor<o2::aod::Calos>();
74 auto caloCellsTRGTableCursor = caloCellsTRGTableBuilder->cursor<o2::aod::CaloTriggers>();
75
76 // build event for easier handling
77 mCaloEventHandler->reset();
78 mCaloEventHandler->setCellData(cellsIn, triggersIn);
79
80 uint64_t triggerMask = 1, inputMask = 1;
81 // loop over events
82 for (int iev = 0; iev < mCaloEventHandler->getNumberOfEvents(); iev++) {
83 o2::emcal::EventData inputEvent = mCaloEventHandler->buildEvent(iev);
84 auto cellsInEvent = inputEvent.mCells; // get cells belonging to current event
85 auto interactionRecord = inputEvent.mInteractionRecord; // get interaction records belonging to current event
86
87 LOG(info) << "Found " << cellsInEvent.size() << " cells in event";
88
89 auto bcID = interactionRecord.toLong();
90 bcCursor(0,
91 runNumber,
92 bcID,
93 triggerMask,
94 inputMask);
95 auto indexBC = iev;
96
97 for (auto& cell : cellsInEvent) {
98
99 // fill table
100 caloCellsCursor(0,
101 indexBC,
102 cell.getTower(),
103 o2::math_utils::detail::truncateFloatFraction(cell.getAmplitude(), mCaloAmp),
104 o2::math_utils::detail::truncateFloatFraction(cell.getTimeStamp(), mCaloTime),
105 cell.getType(),
106 1); // hard coded for emcal (-1 would be undefined, 0 phos)
107 } // end of cell loop
108
109 // filled only with BCID, rest dummy for no2
110 caloCellsTRGTableCursor(0,
111 indexBC,
112 0, // fastOrAbsId (dummy value)
113 0., // lnAmplitude (dummy value)
114 0, // triggerBits (dummy value)
115 1); // caloType (dummy value)
116
117 // fill collision cursor
118 collisionsCursor(0,
119 indexBC,
120 0., // X-Pos dummy value
121 0., // Y Pos
122 0., // Z Pos
123 0, // cov 0
124 0, // cov 1
125 0, // cov 2
126 0, // cov 3
127 0, // cov 4
128 0, // cov 5
129 0, // vertex bit field for flags
130 0, // chi2
131 0, // ncontributors
132 0, // rel interaction time
133 0); // vertex time stamp
134
135 } // end of event loop
136 // std::cout << "Finished cell loop" << std::endl;
137
138 pc.outputs().snapshot(Output{"TFN", "TFNumber", 0}, tfNumber);
139 pc.outputs().snapshot(Output{"TFF", "TFFilename", 0}, "");
140
141 mTimer.Stop();
142}
143
145{
146 LOGF(info, "EMCAL Standalone AOD Producer total timing: Cpu: %.3e Real: %.3e s in %d slots",
147 mTimer.CpuTime(), mTimer.RealTime(), mTimer.Counter() - 1);
148}
149
151{
152 std::vector<OutputSpec> outputs;
153 outputs.emplace_back(OutputLabel{"O2bc"}, "AOD", "BC", 0, Lifetime::Timeframe);
154 outputs.emplace_back(OutputLabel{"O2collision"}, "AOD", "COLLISION", 0, Lifetime::Timeframe);
155 outputs.emplace_back(OutputLabel{"O2caloCell"}, "AOD", "CALO", 0, Lifetime::Timeframe);
156 outputs.emplace_back(OutputLabel{"O2caloCellTRGR"}, "AOD", "CALOTRIGGER", 0, Lifetime::Timeframe);
157 outputs.emplace_back(OutputSpec{"TFN", "TFNumber"});
158 outputs.emplace_back(OutputSpec{"TFF", "TFFilename"});
159
160 return DataProcessorSpec{
161 "standalone-aod-producer-workflow",
162 Inputs{
163 InputSpec{StandaloneAODProducerSpec::getCellTriggerRecordBinding(), "EMC", "CELLSTRGR", 0, Lifetime::Timeframe},
164 InputSpec{StandaloneAODProducerSpec::getCellBinding(), "EMC", "CELLS", 0, Lifetime::Timeframe}},
165 outputs,
166 AlgorithmSpec{adaptFromTask<StandaloneAODProducerSpec>()},
167 Options{
168 ConfigParamSpec{"run-number", VariantType::Int64, -1L, {"The run-number. If left default we try to get it from DPL header."}},
169 ConfigParamSpec{"aod-timeframe-id", VariantType::Int64, -1L, {"Set timeframe number"}}}};
170}
171
172} // namespace emcal
173} // namespace o2
General auxilliary methods.
Convert CTF (EncodedBlocks) to AO2D EMCal standalone.
A helper class to iteratate over all parts of all input routes.
Handler for EMCAL event data.
EventData< CellInputType > buildEvent(int eventID) const
Build event information for a given event number within the timeframe.
void reset()
Reset containers with empty ranges.
void setCellData(CellRange cells, TriggerRange triggers)
Setting the data at cell level.
int getNumberOfEvents() const
Get the number of events handled by the event handler.
void run(o2::framework::ProcessingContext &pc) final
void endOfStream(o2::framework::EndOfStreamContext &ec) final
This is invoked whenever we have an EndOfStream event.
void init(o2::framework::InitContext &ic) final
void snapshot(const Output &spec, T const &object)
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.
ServiceRegistryRef services()
The services registry associated with this processing context.
Collisions_001 Collisions
framework::DataProcessorSpec getStandaloneAODProducerSpec()
create a processor spec
Defining PrimaryVertex explicitly as messageable.
Definition TFIDInfo.h:20
std::vector< ConfigParamSpec > Options
std::vector< InputSpec > Inputs
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
EMCAL event information (per trigger)
Definition EventData.h:38
gsl::span< const InputType > mCells
EMCAL cells / digits.
Definition EventData.h:41
InteractionRecord mInteractionRecord
Interaction record for the trigger corresponding to this event.
Definition EventData.h:39
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"