55 LOG(info) <<
"initializing cluster sink";
59 auto outputFileName = ic.
options().
get<std::string>(
"outfile");
60 mOutputFile.open(outputFileName, (mText ? ios::out : (ios::out | ios::binary)));
61 if (!mOutputFile.is_open()) {
62 throw invalid_argument(
"Cannot open output file" + outputFileName);
65 mUseRun2DigitUID = ic.
options().
get<
bool>(
"useRun2DigitUID");
67 auto stop = [
this]() {
69 LOG(info) <<
"stop cluster sink";
70 this->mOutputFile.close();
81 auto rofs = pc.
inputs().
get<gsl::span<ROFRecord>>(
"rofs");
83 gsl::span<const Digit>
digits;
88 std::vector<Cluster> eventClusters{};
89 for (
const auto& rof : rofs) {
94 mOutputFile << rof.getNEntries() <<
" clusters:" << endl;
95 for (
const auto& cluster :
clusters.subspan(rof.getFirstIdx(), rof.getNEntries())) {
96 mOutputFile << cluster << endl;
102 auto eventDigits = getEventClustersAndDigits(rof,
clusters,
digits, eventClusters);
106 mOutputFile.write(
reinterpret_cast<char*
>(&
nClusters),
sizeof(
int));
109 int nDigits = eventDigits.size();
110 mOutputFile.write(
reinterpret_cast<char*
>(&nDigits),
sizeof(
int));
113 mOutputFile.write(
reinterpret_cast<const char*
>(eventClusters.data()), eventClusters.size() *
sizeof(
Cluster));
117 if (mUseRun2DigitUID) {
118 std::vector<Digit> digitsCopy(eventDigits.begin(), eventDigits.end());
119 convertPadID2DigitUID(digitsCopy);
120 mOutputFile.write(
reinterpret_cast<char*
>(digitsCopy.data()), digitsCopy.size() *
sizeof(
Digit));
122 mOutputFile.write(
reinterpret_cast<const char*
>(eventDigits.data()), eventDigits.size_bytes());
131 gsl::span<const Digit> getEventClustersAndDigits(
const ROFRecord& rof, gsl::span<const Cluster>
clusters,
132 gsl::span<const Digit>
digits,
133 std::vector<Cluster>& eventClusters)
const
139 eventClusters.clear();
146 throw length_error(
"missing clusters");
154 auto digitOffset = eventClusters.front().firstDigit;
155 for (
auto& cluster : eventClusters) {
156 cluster.firstDigit -= digitOffset;
159 auto nDigits = eventClusters.back().firstDigit + eventClusters.back().nDigits;
160 if (digitOffset + nDigits >
digits.size()) {
161 throw length_error(
"missing digits");
164 return digits.subspan(digitOffset, nDigits);
171 void convertPadID2DigitUID(std::vector<Digit>&
digits)
176 static const std::array<std::vector<int>, 10> bendingCathodes{
181 {0, 0, 0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1},
182 {0, 0, 0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1},
183 {0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1},
184 {0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1},
185 {0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1},
186 {0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1}}};
188 for (
auto& digit :
digits) {
190 int deID = digit.getDetID();
192 int padID = digit.getPadID();
193 int cathode = bendingCathodes[deID / 100 - 1][deID % 100];
195 cathode = 1 - cathode;
200 int digitID = (deID) | (manuID << 12) | (manuCh << 24) | (cathode << 30);
201 digit.setPadID(digitID);
205 std::ofstream mOutputFile{};
207 bool mUseRun2DigitUID =
false;
208 bool mDoDigits =
true;
InputRecord & inputs()
The inputs associated with this processing context.