ATLAS Offline Software
Public Member Functions | Public Attributes | Private Attributes | List of all members
Trig::BunchTrain Class Reference

A smart set of BunchCrossing objects. More...

#include <BunchTrain.h>

Inheritance diagram for Trig::BunchTrain:
Collaboration diagram for Trig::BunchTrain:

Public Member Functions

 BunchTrain ()
 Default constructor. More...
 
 BunchTrain (const BunchTrain &parent)
 Copy constructor. More...
 
BunchTrainoperator= (const BunchTrain &rhs)
 Assignment operator. More...
 
int spacing () const
 Spacing of the bunches in this train in nanoseconds. More...
 
int distance (const BunchCrossing &bc) const
 "Distance" of a bunch crossing from this bunch train More...
 
bool isInside (const BunchCrossing &bc) const
 Check if a bunch crossing is inside this train. More...
 
const_iterator train_front () const
 Iterator pointing to the first bunch in the train. More...
 
const_iterator train_back () const
 Iterator pointing to the last bunch in the train. More...
 
bool validate ()
 Check the spacing of the bunches in the train. More...
 

Public Attributes

keys
 STL member. More...
 

Private Attributes

int m_spacing
 Spacing of the bunches in nanoseconds. More...
 
const_iterator m_front
 Iterator pointing to the first bunch. More...
 
const_iterator m_back
 Iterator pointing to the last bunch. More...
 
bool m_gapFound
 Flag specifying if the train spreads over the "BCID turnover". More...
 

Detailed Description

A smart set of BunchCrossing objects.

   This class is used internally to describe a bunch train. It's basically
   just a list of BunchCrossing objects with a couple of convenience
   functions.
Author
Attila Krasznahorkay Attil.nosp@m.a.Kr.nosp@m.aszna.nosp@m.hork.nosp@m.ay@ce.nosp@m.rn.c.nosp@m.h
Revision
618129
Date
2014-09-23 13:37:00 +0200 (Tue, 23 Sep 2014)

Definition at line 35 of file BunchTrain.h.

Constructor & Destructor Documentation

◆ BunchTrain() [1/2]

Trig::BunchTrain::BunchTrain ( )

Default constructor.

Default constructor, creating an empty bunch train.

Definition at line 22 of file BunchTrain.cxx.

23  : std::set< BunchCrossing >(), m_spacing( -1 ),
24  m_front(), m_back(), m_gapFound( false ) {
25 
26  }

◆ BunchTrain() [2/2]

Trig::BunchTrain::BunchTrain ( const BunchTrain parent)

Copy constructor.

The internal iterators don't remain valid if we just use the default copy constructor.

Hence when the object is copied, the validation has to be run again.

Parameters
parentThe original BunchTrain object

Definition at line 35 of file BunchTrain.cxx.

36  : std::set< BunchCrossing >( parent ), m_spacing( -1 ),
37  m_front(), m_back(), m_gapFound( false ) {
38 
39  validate();
40  }

Member Function Documentation

◆ distance()

int Trig::BunchTrain::distance ( const BunchCrossing bc) const

"Distance" of a bunch crossing from this bunch train

This function is used by the code to determine if a new bunch crossing should be merged into this bunch train or not.

The calculation of the distance of a bunch crossing from a bunch train is pretty simple. If the train is empty, or the bunch crossing is already in it, the distance is 0. Otherwise the code calculates the distance of the reference bunch crossing from all the bunch crossings which are already in the train, and takes the smallest value. It's not the fastest method, but it's the only reliable method that I've found...

Parameters
bcThe reference bunch crossing
Returns
The distance of the reference bunch crossing from this bunch train

Definition at line 92 of file BunchTrain.cxx.

92  {
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  }

◆ isInside()

bool Trig::BunchTrain::isInside ( const BunchCrossing bc) const

Check if a bunch crossing is inside this train.

This function checks if the specified bunch crossing is "inside" this bunch train.

This can mean two different things. Either the bunch crossing is a filled bunch crossing which is part of the train, or the bunch crossing is an empty bunch crossing which is between the front and the tail of this train.

Parameters
bcThe reference bunch crossing
Returns
true if the reference bunch crossing is "inside" the train, or false if it isn't

Definition at line 125 of file BunchTrain.cxx.

125  {
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  }

◆ operator=()

BunchTrain & Trig::BunchTrain::operator= ( const BunchTrain rhs)

Assignment operator.

Definition at line 42 of file BunchTrain.cxx.

42  {
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  }

◆ spacing()

int Trig::BunchTrain::spacing ( ) const

Spacing of the bunches in this train in nanoseconds.

The spacing between the bunches in the train is calculated by the BunchTrain::validate() function, so you should only trust this value once the validation ran on this object.

The value is stored in nanoseconds to maybe make the meaning of the value a bit more obvious.

Returns
The bunch spacing in nanoseconds, or -1 if the object has not been validated yet

Definition at line 75 of file BunchTrain.cxx.

75  {
76 
77  return m_spacing;
78  }

◆ train_back()

BunchTrain::const_iterator Trig::BunchTrain::train_back ( ) const

Iterator pointing to the last bunch in the train.

The returned iterator always points to the last bunch of the train.

Note that it is a valid iterator, which actually points to the end of the train. So you shouldn't use it in for loops like end().

The rest of the logic is the same as with train_front().

See also
train_front
Returns
The element that is logically at the back of the train

Definition at line 185 of file BunchTrain.cxx.

185  {
186 
187  if( m_gapFound ) {
188  return m_back;
189  } else {
190  return ( --end() );
191  }
192  }

◆ train_front()

BunchTrain::const_iterator Trig::BunchTrain::train_front ( ) const

Iterator pointing to the first bunch in the train.

The returned iterator always points to the first bunch of the train.

Note however, that can only be "logically" the first bunch of the train. When a train stretches over the "BCID turnover" region, the underlying std::set object will order the bunches like this:

0, 1, 2, 3562, 3563

In this case 3562 is the first bunch of the train, and this function will return an iterator pointing to that element.

This iterator is determined in the validate() function, so the code must always call validate() at least once before using this iterator.

Returns
The element that is logically the front of the train

Definition at line 165 of file BunchTrain.cxx.

165  {
166 
167  if( m_gapFound ) {
168  return m_front;
169  } else {
170  return begin();
171  }
172  }

◆ validate()

bool Trig::BunchTrain::validate ( )

Check the spacing of the bunches in the train.

The function checks if the bunches in the train have equal spacing in between them.

This should be the case if everything went correctly with the code...

It also checks whether the train stretches over the "BCID turnover" or not. If it does, it sets the m_front and m_back variables correctly. If it does not, then the train doesn't have to be treated in a special way.

Returns
true if the validation passes, false otherwise

Helper object to print logging messages:

Definition at line 205 of file BunchTrain.cxx.

205  {
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  }

Member Data Documentation

◆ keys

K std::set< K >::keys
inherited

STL member.

◆ m_back

const_iterator Trig::BunchTrain::m_back
private

Iterator pointing to the last bunch.

Definition at line 64 of file BunchTrain.h.

◆ m_front

const_iterator Trig::BunchTrain::m_front
private

Iterator pointing to the first bunch.

Definition at line 63 of file BunchTrain.h.

◆ m_gapFound

bool Trig::BunchTrain::m_gapFound
private

Flag specifying if the train spreads over the "BCID turnover".

Definition at line 65 of file BunchTrain.h.

◆ m_spacing

int Trig::BunchTrain::m_spacing
private

Spacing of the bunches in nanoseconds.

Definition at line 62 of file BunchTrain.h.


The documentation for this class was generated from the following files:
find
std::string find(const std::string &s)
return a remapped string
Definition: hcg.cxx:135
Trig::BunchCrossing::MAX_BCID
static const int MAX_BCID
The maximum number of bunches that can be in the LHC.
Definition: BunchCrossing.h:50
Trig::BunchTrain::m_front
const_iterator m_front
Iterator pointing to the first bunch.
Definition: BunchTrain.h:63
Trig::BunchTrain::validate
bool validate()
Check the spacing of the bunches in the train.
Definition: BunchTrain.cxx:205
Trig::BunchTrain::train_back
const_iterator train_back() const
Iterator pointing to the last bunch in the train.
Definition: BunchTrain.cxx:185
PlotCalibFromCool.begin
begin
Definition: PlotCalibFromCool.py:94
mc.diff
diff
Definition: mc.SFGenPy8_MuMu_DD.py:14
mergePhysValFiles.end
end
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:93
Trig::BunchCrossing::BUNCH_SPACING
static const int BUNCH_SPACING
Minimum spacing between the bunches, in nanoseconds.
Definition: BunchCrossing.h:48
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
Trig::BunchTrain::m_gapFound
bool m_gapFound
Flag specifying if the train spreads over the "BCID turnover".
Definition: BunchTrain.h:65
fillPileUpNoiseLumi.next
next
Definition: fillPileUpNoiseLumi.py:52
Trig::BunchTrain::m_spacing
int m_spacing
Spacing of the bunches in nanoseconds.
Definition: BunchTrain.h:62
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
test_pyathena.parent
parent
Definition: test_pyathena.py:15
asg::AsgMessaging
Class mimicking the AthMessaging class from the offline software.
Definition: AsgMessaging.h:40
Trig::BunchTrain::train_front
const_iterator train_front() const
Iterator pointing to the first bunch in the train.
Definition: BunchTrain.cxx:165
Trig::BunchTrain::m_back
const_iterator m_back
Iterator pointing to the last bunch.
Definition: BunchTrain.h:64
python.Constants.VERBOSE
int VERBOSE
Definition: Control/AthenaCommon/python/Constants.py:14
python.iconfTool.gui.pad.logger
logger
Definition: pad.py:14