ATLAS Offline Software
Loading...
Searching...
No Matches
BunchTrain.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3*/
4
5
6// System include(s):
7#include <cstdlib>
8#include <iostream>
9
10// Gaudi/Athena include(s):
12
13// Local include(s):
15#include "SetPrint.h"
16
17namespace Trig {
18
23 : std::set< BunchCrossing >(), m_spacing( -1 ),
24 m_front(), m_back(), m_gapFound( false ) {
25
26 }
27
36 : std::set< BunchCrossing >( parent ), m_spacing( -1 ),
37 m_front(), m_back(), m_gapFound( false ) {
38
39 validate();
40 }
41
43
44 // Protect against self-assignment:
45 if( this == &rhs ) {
46 return *this;
47 }
48
49 // Do the heavy lifting in the base class's assignment operator:
50 std::set< BunchCrossing >::operator=( rhs );
51
52 // Reset the cached variables:
53 m_front = end();
54 m_back = end();
55 m_gapFound = false;
56
57 // Cache the variables:
58 validate();
59
60 // Return the updated object:
61 return *this;
62 }
63
75 int BunchTrain::spacing() const {
76
77 return m_spacing;
78 }
79
92 int BunchTrain::distance( const BunchCrossing& bc ) const {
93
94 // If the train is empty, by definition the distance is 0:
95 if( ! size() ) return 0;
96
97 // If the BC is already in the train, it has a distance of 0 from it:
98 if( find( bc ) != end() ) return 0;
99
100 // Calculate the BC's distance from all the bunches in the train, and take the
101 // smallest one:
102 int min_distance = BunchCrossing::MAX_BCID;
103 BunchTrain::const_iterator itr = begin();
104 for( ; itr != end(); ++itr ) {
105 int diff;
106 if( ( diff = itr->distance( bc ) ) < min_distance ) {
107 min_distance = diff;
108 }
109 }
110
111 return min_distance;
112 }
113
125 bool BunchTrain::isInside( const BunchCrossing& bc ) const {
126
127 // If it's a filled bunch crossing in this train, then it's inside of it:
128 if( find( bc ) != end() ) return true;
129
130 // Check if the bunch crossing is an empty bunch crossing inside
131 // this train:
132 if( m_gapFound ) {
133 if( ( ( *begin() < bc ) && ( *train_back() > bc ) ) ||
134 ( ( *train_front() < bc ) && ( *( --end() ) > bc ) ) ) {
135 return true;
136 }
137 } else {
138 if( ( *train_front() < bc ) && ( *train_back() > bc ) ) {
139 return true;
140 }
141 }
142
143 // If none of the above are true, then the reference is not inside
144 // of this train:
145 return false;
146 }
147
165 BunchTrain::const_iterator BunchTrain::train_front() const {
166
167 if( m_gapFound ) {
168 return m_front;
169 } else {
170 return begin();
171 }
172 }
173
185 BunchTrain::const_iterator BunchTrain::train_back() const {
186
187 if( m_gapFound ) {
188 return m_back;
189 } else {
190 return ( --end() );
191 }
192 }
193
206
208 static const asg::AsgMessaging logger( "Trig::BunchTrain" );
209
210 // Reset the gap flag:
211 m_gapFound = false;
212
213 // Loop over all the bunch crossings of this train:
214 BunchTrain::const_iterator itr = begin();
215 size_t bunch_pos = 0;
216 BunchTrain::const_iterator next;
217 for( ; itr != end(); ++itr, ++bunch_pos ) {
218 // Set up an iterator to the next bunch crossing in the train:
219 next = itr; ++next;
220 if( next == end() ) continue;
221 // Calculate the spacing between these two:
222 int diff = BunchCrossing::BUNCH_SPACING * next->distance( *itr );
223 if( m_spacing < 0 ) { // If these are the first two bunches of the train
224 m_spacing = diff;
225 }
226 // Check if it is the same as the stored value:
227 else if( diff != m_spacing ) {
228 // If not, there can be a two valid reasons for it. First is that we've been seeing
229 // the correct bunch spacing so far, and we just reached the gap:
230 if( ( ! m_gapFound ) && ( diff > m_spacing ) ) {
231 m_gapFound = true;
232 m_front = next;
233 m_back = itr;
234 }
235 // Or that the spacing between the first two bunches was actually the gap,
236 // and not the train's bunch spacing. (For trains like: [0, 3561, 3562, 3563])
237 else if( ( bunch_pos == 1 ) && ( ! m_gapFound ) && ( diff < m_spacing ) ) {
238 m_gapFound = true;
239 m_front = itr;
240 m_back = itr; --m_back;
241 m_spacing = diff;
242 }
243 // Or finally it could be that the configuration is just weird...
244 else {
245 logger.msg() << MSG::WARNING << "Bunches don't appear to have "
246 << "equal spacing!" << endmsg;
247 return false;
248 }
249 }
250 }
251
252 // Report what we found out about this train:
253 if( m_gapFound ) {
254 logger.msg() << MSG::VERBOSE
255 << "Gap found in train! train_front = "
256 << *train_front() << "; train_back = "
257 << *train_back() << endmsg;
258 } else {
259 logger.msg() << MSG::VERBOSE
260 << "Gap not found in train! train_front = "
261 << *train_front() << "; train_back = "
262 << *train_back() << endmsg;
263 }
264
265 return true;
266 }
267
277 bool operator< ( const BunchTrain& bt1, const BunchTrain& bt2 ) {
278
279 if( ! bt2.size() ) return false;
280 if( ! bt1.size() ) return true;
281
282 return ( ( *bt1.begin() ) < ( *bt2.begin() ) );
283 }
284
285} // namespace Trig
286
295std::ostream& operator<< ( std::ostream& stream, const Trig::BunchTrain& bt ) {
296
297 // Take advantage of the output operator defined for std::set objects:
298 stream << "[spacing: " << bt.spacing() << "; bunches: "
299 << static_cast< const std::set< Trig::BunchCrossing >& >( bt )
300 << "; front: " << *bt.train_front() << "; back: "
301 << *bt.train_back() << "]";
302
303 return stream;
304}
305
314MsgStream& operator<< ( MsgStream& stream, const Trig::BunchTrain& bt ) {
315
316 // Take advantage of the output operator defined for std::set objects:
317 stream << "[spacing: " << bt.spacing() << "; bunches: "
318 << static_cast< const std::set< Trig::BunchCrossing >& >( bt )
319 << "; front: " << *bt.train_front() << "; back: "
320 << *bt.train_back() << "]";
321
322 return stream;
323}
#define endmsg
std::ostream & operator<<(std::ostream &stream, const Trig::BunchTrain &bt)
Operator for printing the configuration of bunch trains in a readable format.
void diff(const Jet &rJet1, const Jet &rJet2, std::map< std::string, double > varDiff)
Difference between jets - Non-Class function required by trigger.
Definition Jet.cxx:631
A smart integer class representing bunch crossings.
static const int MAX_BCID
The maximum number of bunches that can be in the LHC.
static const int BUNCH_SPACING
Minimum spacing between the bunches, in nanoseconds.
A smart set of BunchCrossing objects.
Definition BunchTrain.h:35
bool validate()
Check the spacing of the bunches in the train.
BunchTrain & operator=(const BunchTrain &rhs)
Assignment operator.
const_iterator m_front
Iterator pointing to the first bunch.
Definition BunchTrain.h:63
bool isInside(const BunchCrossing &bc) const
Check if a bunch crossing is inside this train.
const_iterator train_back() const
Iterator pointing to the last bunch in the train.
int m_spacing
Spacing of the bunches in nanoseconds.
Definition BunchTrain.h:62
BunchTrain()
Default constructor.
bool m_gapFound
Flag specifying if the train spreads over the "BCID turnover".
Definition BunchTrain.h:65
int distance(const BunchCrossing &bc) const
"Distance" of a bunch crossing from this bunch train
int spacing() const
Spacing of the bunches in this train in nanoseconds.
const_iterator train_front() const
Iterator pointing to the first bunch in the train.
const_iterator m_back
Iterator pointing to the last bunch.
Definition BunchTrain.h:64
Class mimicking the AthMessaging class from the offline software.
STL class.
std::string find(const std::string &s)
return a remapped string
Definition hcg.cxx:138
static Root::TMsgLogger logger("iLumiCalc")
The common trigger namespace for trigger analysis tools.
bool operator<(const BunchTrain &bt1, const BunchTrain &bt2)
This operator is here to be able to put BunchTrain objects into ordered containers like std::set and ...
STL namespace.