55 LOG(info) <<
"initializing precluster 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 precluster sink";
70 this->mOutputFile.close();
81 auto rofs = pc.
inputs().
get<gsl::span<ROFRecord>>(
"rofs");
82 auto preClusters = pc.
inputs().
get<gsl::span<PreCluster>>(
"preclusters");
86 std::vector<Digit> digitsCopy{};
87 if (mUseRun2DigitUID) {
88 digitsCopy.insert(digitsCopy.end(),
digits.begin(),
digits.end());
89 convertPadID2DigitUID(digitsCopy);
90 digits = gsl::span<const Digit>(digitsCopy);
93 std::vector<PreCluster> eventPreClusters{};
94 for (
const auto& rof : rofs) {
99 mOutputFile << rof.getNEntries() <<
" preclusters:" << endl;
100 for (
const auto& precluster : preClusters.subspan(rof.getFirstIdx(), rof.getNEntries())) {
101 precluster.print(mOutputFile,
digits);
107 auto eventDigits = getEventPreClustersAndDigits(rof, preClusters,
digits, eventPreClusters);
110 int nPreClusters = eventPreClusters.size();
111 mOutputFile.write(
reinterpret_cast<char*
>(&nPreClusters),
sizeof(
int));
112 int nDigits = eventDigits.size();
113 mOutputFile.write(
reinterpret_cast<char*
>(&nDigits),
sizeof(
int));
116 mOutputFile.write(
reinterpret_cast<const char*
>(eventPreClusters.data()),
117 eventPreClusters.size() *
sizeof(
PreCluster));
118 mOutputFile.write(
reinterpret_cast<const char*
>(eventDigits.data()), eventDigits.size_bytes());
125 gsl::span<const Digit> getEventPreClustersAndDigits(
const ROFRecord& rof, gsl::span<const PreCluster> preClusters,
126 gsl::span<const Digit>
digits,
127 std::vector<PreCluster>& eventPreClusters)
const
133 eventPreClusters.clear();
140 throw length_error(
"missing preclusters");
146 auto digitOffset = eventPreClusters.front().firstDigit;
147 for (
auto& preCluster : eventPreClusters) {
148 preCluster.firstDigit -= digitOffset;
151 if (eventPreClusters.back().lastDigit() + digitOffset >=
digits.size()) {
152 throw length_error(
"missing digits");
155 return digits.subspan(digitOffset, eventPreClusters.back().lastDigit() + 1);
159 void convertPadID2DigitUID(std::vector<Digit>&
digits)
164 static const std::array<std::vector<int>, 10> bendingCathodes{
169 {0, 0, 0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1},
170 {0, 0, 0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1},
171 {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},
172 {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},
173 {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},
174 {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}}};
176 for (
auto& digit :
digits) {
178 int deID = digit.getDetID();
180 int padID = digit.getPadID();
181 int cathode = bendingCathodes[deID / 100 - 1][deID % 100];
183 cathode = 1 - cathode;
188 int digitID = (deID) | (manuID << 12) | (manuCh << 24) | (cathode << 30);
189 digit.setPadID(digitID);
193 std::ofstream mOutputFile{};
195 bool mUseRun2DigitUID =
false;