ATLAS Offline Software
BunchCrossing.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 // $Id: BunchCrossing.cxx 618129 2014-09-23 11:37:00Z krasznaa $
6 
7 // System include(s):
8 #include <iostream>
9 
10 // Gaudi/Athena include(s):
12 
13 // Local include(s):
15 
16 namespace Trig {
17 
18  //
19  // Initialize the static variables:
20  //
21  const int BunchCrossing::MAX_BCID = 3564;
22  const int BunchCrossing::BUNCH_SPACING = 25;
23 
33  BunchCrossing::BunchCrossing( int bcid, float intBeam1, float intBeam2 )
34  : m_bcid( bcid ), m_intensityBeam1( intBeam1 ),
35  m_intensityBeam2( intBeam2 ) {
36 
37  if( m_bcid < 0 ) {
39  }
40  while( m_bcid >= MAX_BCID ) {
41  m_bcid -= MAX_BCID;
42  }
43  }
44 
55  BunchCrossing::BunchCrossing( unsigned int bcid, float intBeam1,
56  float intBeam2 )
57  : m_bcid( static_cast< int >( bcid ) ), m_intensityBeam1( intBeam1 ),
58  m_intensityBeam2( intBeam2 ) {
59 
60  if( m_bcid < 0 ) {
62  }
63  while( m_bcid >= MAX_BCID ) {
64  m_bcid -= MAX_BCID;
65  }
66  }
67 
76  : m_bcid( parent.m_bcid ), m_intensityBeam1( parent.m_intensityBeam1 ),
77  m_intensityBeam2( parent.m_intensityBeam2 ) {
78 
79  }
80 
89 
90  // Check that it's not a self-assignment:
91  if( &parent == this ) return *this;
92 
93  m_bcid = parent.m_bcid;
94  m_intensityBeam1 = parent.m_intensityBeam1;
95  m_intensityBeam2 = parent.m_intensityBeam2;
96 
97  return *this;
98  }
99 
107  BunchCrossing::operator int&() {
108 
109  return m_bcid;
110  }
111 
119  BunchCrossing::operator const int&() const {
120 
121  return m_bcid;
122  }
123 
132 
133  m_bcid += bc.m_bcid;
134  while( m_bcid >= MAX_BCID ) {
135  m_bcid -= MAX_BCID;
136  }
137 
138  return *this;
139  }
140 
149 
150  m_bcid -= bc.m_bcid;
151  if( m_bcid < 0 ) {
152  m_bcid = MAX_BCID + m_bcid;
153  }
154 
155  return *this;
156  }
157 
165 
166  return operator+=( 1 );
167  }
168 
176 
177  BunchCrossing result = *this;
178  operator+=( 1 );
179  return result;
180  }
181 
189 
190  return operator-=( 1 );
191  }
192 
200 
201  BunchCrossing result = *this;
202  operator-=( 1 );
203  return result;
204  }
205 
216  int BunchCrossing::distance( const BunchCrossing& bc ) const {
217 
218  BunchCrossing ibc = *this - bc;
219  if( ibc.m_bcid > ( MAX_BCID / 2 ) ) {
220  return ( MAX_BCID - ibc.m_bcid );
221  } else {
222  return ibc.m_bcid;
223  }
224  }
225 
238  int BunchCrossing::gapFrom( const BunchCrossing& bc ) const {
239 
240  return ( *this - bc );
241  }
242 
255  int BunchCrossing::gapTo( const BunchCrossing& bc ) const {
256 
257  return ( bc - *this );
258  }
259 
267  int BunchCrossing::bcid() const {
268 
269  return m_bcid;
270  }
271 
279 
280  m_bcid = bcid;
281  return;
282  }
283 
292 
293  return m_intensityBeam1;
294  }
295 
300  void BunchCrossing::setIntensityBeam1( float intensity ) {
301 
302  if( intensity >= 0.0 ) {
303  m_intensityBeam1 = intensity;
304  } else {
305  asg::AsgMessaging logger( "Trig::BunchCrossing" );
306  logger.msg() << MSG::ERROR
307  << "Trying to set beam 1 intensity to negative number ("
308  << intensity << "). Using 0.0 instead." << endmsg;
309  m_intensityBeam1 = 0.0;
310  }
311  return;
312  }
313 
322 
323  return m_intensityBeam2;
324  }
325 
330  void BunchCrossing::setIntensityBeam2( float intensity ) {
331 
332  if( intensity >= 0.0 ) {
333  m_intensityBeam2 = intensity;
334  } else {
335  asg::AsgMessaging logger( "Trig::BunchCrossing" );
336  logger.msg() << MSG::ERROR
337  << "Trying to set beam 2 intensity to negative number ("
338  << intensity << "). Using 0.0 instead." << endmsg;
339  m_intensityBeam2 = 0.0;
340  }
341  return;
342  }
343 
354  bool BunchCrossing::operator== ( const BunchCrossing& bc ) const {
355 
356  return ( m_bcid == bc.m_bcid );
357  }
358 
368 
369  BunchCrossing result( bc1 );
370  result += bc2;
371 
372  return result;
373  }
374 
384 
385  BunchCrossing result( bc1 );
386  result -= bc2;
387 
388  return result;
389  }
390 
402  int distance( const BunchCrossing bc1, const BunchCrossing bc2 ) {
403 
404  return bc1.distance( bc2 );
405  }
406 
407 } // namespace Trig
408 
417 std::ostream& operator<< ( std::ostream& out, const Trig::BunchCrossing& bc ) {
418 
419  out << "[id:" << bc.bcid() << ";int1:" << bc.intensityBeam1()
420  << ";int2:" << bc.intensityBeam2() << "]";
421 
422  return out;
423 }
424 
433 MsgStream& operator<< ( MsgStream& out, const Trig::BunchCrossing& bc ) {
434 
435  out << "[id:" << bc.bcid() << ";int1:" << bc.intensityBeam1()
436  << ";int2:" << bc.intensityBeam2() << "]";
437 
438  return out;
439 }
Trig::BunchCrossing::setIntensityBeam1
void setIntensityBeam1(float intensity)
Set the "intensity" of beam 1 in this bunch crossing.
Definition: BunchCrossing.cxx:300
Trig::BunchCrossing::operator++
BunchCrossing & operator++()
Operator pushing the object to the next bunch crossing.
Definition: BunchCrossing.cxx:164
Trig::BunchCrossing::gapFrom
int gapFrom(const BunchCrossing &bc) const
Distance from a previous bunch crossing.
Definition: BunchCrossing.cxx:238
get_generator_info.result
result
Definition: get_generator_info.py:21
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
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::BunchCrossing::operator=
BunchCrossing & operator=(const BunchCrossing &parent)
Assignment operator.
Definition: BunchCrossing.cxx:88
Trig
The common trigger namespace for trigger analysis tools.
Definition: CaloTowerVecMon.h:44
Trig::BunchCrossing::m_intensityBeam1
float m_intensityBeam1
Intensity of the bunch in "beam 1" some measure.
Definition: BunchCrossing.h:100
Trig::BunchCrossing::m_intensityBeam2
float m_intensityBeam2
Intensity of the bunch in "beam 2" some measure.
Definition: BunchCrossing.h:102
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:71
Trig::distance
int distance(const BunchCrossing bc1, const BunchCrossing bc2)
I need this function only for technical reasons.
Definition: BunchCrossing.cxx:402
Trig::BunchCrossing::operator==
bool operator==(const BunchCrossing &bc) const
Equality operator for bunch crossings.
Definition: BunchCrossing.cxx:354
Trig::BunchCrossing::BUNCH_SPACING
static const int BUNCH_SPACING
Minimum spacing between the bunches, in nanoseconds.
Definition: BunchCrossing.h:48
Trig::BunchCrossing::m_bcid
int m_bcid
The BCID of this bunch crossing.
Definition: BunchCrossing.h:98
AsgMessaging.h
Trig::BunchCrossing::setIntensityBeam2
void setIntensityBeam2(float intensity)
Set the "intensity" of beam 2 in this bunch crossing.
Definition: BunchCrossing.cxx:330
BunchCrossing.h
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
Trig::BunchCrossing::bcid
int bcid() const
Get the BCID of this bunch crossing.
Definition: BunchCrossing.cxx:267
Trig::BunchCrossing::distance
int distance(const BunchCrossing &bc) const
The distance from another bunch crossing.
Definition: BunchCrossing.cxx:216
test_pyathena.parent
parent
Definition: test_pyathena.py:15
Trig::BunchCrossing::intensityBeam1
float intensityBeam1() const
Get the "intensity" of beam 1 in this bunch crossing.
Definition: BunchCrossing.cxx:291
operator<<
std::ostream & operator<<(std::ostream &out, const Trig::BunchCrossing &bc)
This operator is used to print the configuration of a BunchCrossing object in a nice way.
Definition: BunchCrossing.cxx:417
Trig::BunchCrossing::BunchCrossing
BunchCrossing(int bcid=0, float intBeam1=1.0, float intBeam2=1.0)
Constructor with a value.
Definition: BunchCrossing.cxx:33
Trig::BunchCrossing::intensityBeam2
float intensityBeam2() const
Get the "intensity" of beam 2 in this bunch crossing.
Definition: BunchCrossing.cxx:321
asg::AsgMessaging
Class mimicking the AthMessaging class from the offline software.
Definition: AsgMessaging.h:40
xAOD::bcid
setEventNumber setTimeStamp bcid
Definition: EventInfo_v1.cxx:133
Trig::operator+
BunchCrossing operator+(const BunchCrossing &bc1, const BunchCrossing &bc2)
Convenience operator taking advantage of the += operator defined in the BunchCrossing class.
Definition: BunchCrossing.cxx:367
Trig::BunchCrossing::operator--
BunchCrossing & operator--()
Operator pushing the object to the previous bunch crossing.
Definition: BunchCrossing.cxx:188
Trig::BunchCrossing::setBCID
void setBCID(int bcid)
Set the BCID of this bunch crossing.
Definition: BunchCrossing.cxx:278
Trig::BunchCrossing::operator-=
BunchCrossing & operator-=(const BunchCrossing &bc)
Operator subtracting another BunchCrossing object.
Definition: BunchCrossing.cxx:148
Trig::BunchCrossing
A smart integer class representing bunch crossings.
Definition: BunchCrossing.h:33
Trig::BunchCrossing::gapTo
int gapTo(const BunchCrossing &bc) const
Distance to a following bunch crossing.
Definition: BunchCrossing.cxx:255
Trig::BunchCrossing::operator+=
BunchCrossing & operator+=(const BunchCrossing &bc)
Operator adding another BunchCrossing object.
Definition: BunchCrossing.cxx:131
python.iconfTool.gui.pad.logger
logger
Definition: pad.py:14
Trig::operator-
BunchCrossing operator-(const BunchCrossing &bc1, const BunchCrossing &bc2)
Convenience operator taking advantage of the -= operator defined in the BunchCrossing class.
Definition: BunchCrossing.cxx:383