|
17 | 17 |
|
18 | 18 | #include <iostream> |
19 | 19 | #include <fstream> |
20 | | - |
21 | 20 | #include <array> |
22 | 21 | #include <stdexcept> |
23 | 22 | #include <vector> |
24 | 23 |
|
| 24 | +#include <gsl/span> |
| 25 | + |
25 | 26 | #include "Framework/CallbackService.h" |
26 | 27 | #include "Framework/ConfigParamRegistry.h" |
27 | 28 | #include "Framework/ControlService.h" |
|
30 | 31 | #include "Framework/Task.h" |
31 | 32 | #include "Framework/Logger.h" |
32 | 33 |
|
| 34 | +#include "DataFormatsMCH/ROFRecord.h" |
33 | 35 | #include "MCHBase/Digit.h" |
34 | 36 | #include "MCHBase/ClusterBlock.h" |
35 | 37 | #include "MCHMappingInterface/Segmentation.h" |
@@ -72,42 +74,89 @@ class ClusterSinkTask |
72 | 74 | //_________________________________________________________________________________________________ |
73 | 75 | void run(framework::ProcessingContext& pc) |
74 | 76 | { |
75 | | - /// dump the clusters with associated digits of the current event |
| 77 | + /// dump the clusters with associated digits of all events in the current TF |
76 | 78 |
|
77 | 79 | // get the input clusters and associated digits |
| 80 | + auto rofs = pc.inputs().get<gsl::span<ROFRecord>>("rofs"); |
78 | 81 | auto clusters = pc.inputs().get<gsl::span<ClusterStruct>>("clusters"); |
79 | 82 | auto digits = pc.inputs().get<gsl::span<Digit>>("digits"); |
80 | 83 |
|
81 | | - if (mText) { |
82 | | - // write the clusters in ascii format |
83 | | - mOutputFile << clusters.size() << " clusters:" << endl; |
84 | | - for (const auto& cluster : clusters) { |
85 | | - mOutputFile << cluster << endl; |
86 | | - } |
87 | | - } else { |
88 | | - // write the number of clusters |
89 | | - int nClusters = clusters.size(); |
90 | | - mOutputFile.write(reinterpret_cast<char*>(&nClusters), sizeof(int)); |
91 | | - |
92 | | - // write the total number of digits in these clusters |
93 | | - int nDigits = digits.size(); |
94 | | - mOutputFile.write(reinterpret_cast<char*>(&nDigits), sizeof(int)); |
95 | | - |
96 | | - // write the clusters |
97 | | - mOutputFile.write(reinterpret_cast<const char*>(clusters.data()), clusters.size_bytes()); |
98 | | - |
99 | | - // write the digits (after converting the pad ID into a digit UID if requested) |
100 | | - if (mUseRun2DigitUID) { |
101 | | - std::vector<Digit> digitsCopy(digits.begin(), digits.end()); |
102 | | - convertPadID2DigitUID(digitsCopy); |
103 | | - mOutputFile.write(reinterpret_cast<char*>(digitsCopy.data()), digitsCopy.size() * sizeof(Digit)); |
| 84 | + std::vector<ClusterStruct> eventClusters{}; |
| 85 | + for (const auto& rof : rofs) { |
| 86 | + |
| 87 | + if (mText) { |
| 88 | + |
| 89 | + // write the clusters in ascii format |
| 90 | + mOutputFile << rof.getNEntries() << " clusters:" << endl; |
| 91 | + for (const auto& cluster : clusters.subspan(rof.getFirstIdx(), rof.getNEntries())) { |
| 92 | + mOutputFile << cluster << endl; |
| 93 | + } |
| 94 | + |
104 | 95 | } else { |
105 | | - mOutputFile.write(reinterpret_cast<const char*>(digits.data()), digits.size_bytes()); |
| 96 | + |
| 97 | + // get the clusters and associated digits of the current event |
| 98 | + auto eventDigits = getEventClustersAndDigits(rof, clusters, digits, eventClusters); |
| 99 | + |
| 100 | + // write the number of clusters |
| 101 | + int nClusters = eventClusters.size(); |
| 102 | + mOutputFile.write(reinterpret_cast<char*>(&nClusters), sizeof(int)); |
| 103 | + |
| 104 | + // write the total number of digits in these clusters |
| 105 | + int nDigits = eventDigits.size(); |
| 106 | + mOutputFile.write(reinterpret_cast<char*>(&nDigits), sizeof(int)); |
| 107 | + |
| 108 | + // write the clusters |
| 109 | + mOutputFile.write(reinterpret_cast<const char*>(eventClusters.data()), |
| 110 | + eventClusters.size() * sizeof(ClusterStruct)); |
| 111 | + |
| 112 | + // write the digits (after converting the pad ID into a digit UID if requested) |
| 113 | + if (mUseRun2DigitUID) { |
| 114 | + std::vector<Digit> digitsCopy(eventDigits.begin(), eventDigits.end()); |
| 115 | + convertPadID2DigitUID(digitsCopy); |
| 116 | + mOutputFile.write(reinterpret_cast<char*>(digitsCopy.data()), digitsCopy.size() * sizeof(Digit)); |
| 117 | + } else { |
| 118 | + mOutputFile.write(reinterpret_cast<const char*>(eventDigits.data()), eventDigits.size_bytes()); |
| 119 | + } |
106 | 120 | } |
107 | 121 | } |
108 | 122 | } |
109 | 123 |
|
110 | 124 | private: |
| 125 | + //_________________________________________________________________________________________________ |
| 126 | + gsl::span<const Digit> getEventClustersAndDigits(const ROFRecord& rof, gsl::span<const ClusterStruct> clusters, |
| 127 | + gsl::span<const Digit> digits, |
| 128 | + std::vector<ClusterStruct>& eventClusters) const |
| 129 | + { |
| 130 | + /// copy the clusters of the current event (needed to edit the clusters) |
| 131 | + /// modify the references to the associated digits to start the indexing from 0 |
| 132 | + /// return a sub-span with the associated digits |
| 133 | + |
| 134 | + eventClusters.clear(); |
| 135 | + |
| 136 | + if (rof.getNEntries() < 1) { |
| 137 | + return {}; |
| 138 | + } |
| 139 | + |
| 140 | + if (rof.getLastIdx() >= clusters.size()) { |
| 141 | + throw length_error("missing clusters"); |
| 142 | + } |
| 143 | + |
| 144 | + eventClusters.insert(eventClusters.end(), clusters.begin() + rof.getFirstIdx(), |
| 145 | + clusters.begin() + rof.getLastIdx() + 1); |
| 146 | + |
| 147 | + auto digitOffset = eventClusters.front().firstDigit; |
| 148 | + for (auto& cluster : eventClusters) { |
| 149 | + cluster.firstDigit -= digitOffset; |
| 150 | + } |
| 151 | + |
| 152 | + auto nDigits = eventClusters.back().firstDigit + eventClusters.back().nDigits; |
| 153 | + if (digitOffset + nDigits > digits.size()) { |
| 154 | + throw length_error("missing digits"); |
| 155 | + } |
| 156 | + |
| 157 | + return digits.subspan(digitOffset, nDigits); |
| 158 | + } |
| 159 | + |
111 | 160 | //_________________________________________________________________________________________________ |
112 | 161 | void convertPadID2DigitUID(std::vector<Digit>& digits) |
113 | 162 | { |
@@ -153,7 +202,8 @@ o2::framework::DataProcessorSpec getClusterSinkSpec() |
153 | 202 | { |
154 | 203 | return DataProcessorSpec{ |
155 | 204 | "ClusterSink", |
156 | | - Inputs{InputSpec{"clusters", "MCH", "CLUSTERS", 0, Lifetime::Timeframe}, |
| 205 | + Inputs{InputSpec{"rofs", "MCH", "CLUSTERROFS", 0, Lifetime::Timeframe}, |
| 206 | + InputSpec{"clusters", "MCH", "CLUSTERS", 0, Lifetime::Timeframe}, |
157 | 207 | InputSpec{"digits", "MCH", "CLUSTERDIGITS", 0, Lifetime::Timeframe}}, |
158 | 208 | Outputs{}, |
159 | 209 | AlgorithmSpec{adaptFromTask<ClusterSinkTask>()}, |
|
0 commit comments