Project
Loading...
Searching...
No Matches
FiltererBC.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
18
19namespace o2
20{
21namespace mid
22{
23
24int FiltererBC::matchedCollision(int bc)
25{
26 // First we check the simple case to save time
27 if (mBunchFilling.testInteractingBC(bc)) {
28 return bc;
29 }
30
31 // Then we check for neighbor BCs
32 // We split the check in two so that we start the check from the input bc
33 // and we move farther from it.
34
35 int matchedBC = std::numeric_limits<int>::max();
36
37 // We start on the upper direction
38
39 // The allowed BC are o2::constants::lhc::LHCMaxBunches.
40 // Numeration starts from 0, so o2::constants::lhc::LHCMaxBunches is not allowed.
41 // This ensures that we do not check out of boundaries
42 int end = bc + mBCDiffHigh;
45 }
46 // We exclude the input BC since it was already checked before
47 for (int ibc = bc + 1; ibc <= end; ++ibc) {
48 if (mBunchFilling.testInteractingBC(ibc)) {
49 // We do not stop here because we want first to check that there is no closer matching in the other direction
50 matchedBC = ibc;
51 break;
52 }
53 }
54
55 // We then check the lower direction
56 end = bc + mBCDiffLow;
57 if (end < 0) {
58 end = 0;
59 }
60 // We exclude the input BC since it was already checked before
61 for (int ibc = bc - 1; ibc >= end; --ibc) {
62 if (mBunchFilling.testInteractingBC(ibc)) {
63 if (bc - ibc < matchedBC - bc) {
64 // This collision BC is closer to the input BC than the one found in the upper side
65 return ibc;
66 }
67 break;
68 }
69 }
70
71 return matchedBC;
72}
73
74std::vector<ROFRecord> FiltererBC::process(gsl::span<const ROFRecord> rofRecords)
75{
76 std::vector<ROFRecord> filteredROFs;
77 auto rofIt = rofRecords.begin();
78 auto end = rofRecords.end();
79 // Loop on ROFs
80 for (; rofIt != end; ++rofIt) {
81 // Check if BC matches a collision BC
82 auto matchedColl = matchedCollision(rofIt->interactionRecord.bc);
83 if (matchedColl < o2::constants::lhc::LHCMaxBunches) {
84 // Add this ROF to the filtered ones
85 filteredROFs.emplace_back(*rofIt);
86 if (mSelectOnly) {
87 continue;
88 }
89 // Use the BC of the matching collision
90 filteredROFs.back().interactionRecord.bc = matchedColl;
91 // Search for neighbor BCs
92 for (auto auxIt = rofIt + 1; auxIt != end; ++auxIt) {
93 // We assume that data are time-ordered
94 if (auxIt->interactionRecord.orbit != rofIt->interactionRecord.orbit) {
95 // Orbit does not match
96 break;
97 }
98 int bcDiff = auxIt->interactionRecord.bc - matchedColl;
99 if (bcDiff < mBCDiffLow || bcDiff > mBCDiffHigh) {
100 // BC is not in the allowed window
101 break;
102 }
103 filteredROFs.back().nEntries += auxIt->nEntries;
104 // CAVEAT: we are updating rofIt here. Do not use it in the following
105 rofIt = auxIt;
106 }
107 }
108 }
109 return filteredROFs;
110}
111
112} // namespace mid
113} // namespace o2
uint64_t bc
Definition RawEventData.h:5
BC filterer for MID.
bool testInteractingBC(int bcID) const
std::vector< ROFRecord > process(gsl::span< const ROFRecord > rofRecords)
Filters the data BC.
GLuint GLuint end
Definition glcorearb.h:469
constexpr int LHCMaxBunches
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...