The Gaudi Framework  master (37c0b60a)
Event.h
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2024 CERN for the benefit of the LHCb and ATLAS collaborations *
3 * *
4 * This software is distributed under the terms of the Apache version 2 licence, *
5 * copied verbatim in the file "LICENSE". *
6 * *
7 * In applying this licence, CERN does not waive the privileges and immunities *
8 * granted to it by virtue of its status as an Intergovernmental Organization *
9 * or submit itself to any jurisdiction. *
10 \***********************************************************************************/
11 #ifndef GAUDIEXAMPLES_EVENT_H
12 #define GAUDIEXAMPLES_EVENT_H 1
13 
14 // Include files
15 #include <GaudiKernel/DataObject.h>
16 #include <GaudiKernel/Kernel.h>
19 #include <GaudiKernel/Time.h>
20 #include <iostream>
21 
22 namespace Gaudi {
23  namespace Examples {
24 
25  class Collision;
26 
27  // CLID definition
28  static const CLID& CLID_Event = 110;
29 
39  class GAUDI_API Event : public DataObject {
40 
41  public:
43  Event();
44 
46  const CLID& clID() const override { return classID(); }
47  static const CLID& classID() { return CLID_Event; }
48 
50  int event() const { return m_event; }
52  void setEvent( int value ) { m_event = value; }
53 
55  int run() const { return m_run; }
57  void setRun( int value ) { m_run = value; }
58 
60  const Gaudi::Time& time() const { return m_time; }
62  void setTime( const Gaudi::Time& value ) { m_time = value; }
63 
65  const SmartRefVector<Collision>& collisions() const;
66 
68  void addCollision( Collision* vtx );
69 
71  void removeCollision( Collision* vtx );
72 
74  virtual StreamBuffer& serialize( StreamBuffer& s ) const;
76  virtual StreamBuffer& serialize( StreamBuffer& s );
77 
79  std::ostream& fillStream( std::ostream& s ) const override;
80 
81  private:
83  int m_event{ 0 };
85  int m_run{ 0 };
88 
91  };
92  } // namespace Examples
93 } // namespace Gaudi
94 
95 #include "Collision.h"
96 
97 namespace Gaudi {
98  namespace Examples {
99 
100  //
101  // Inline code must be outside the class definition
102  //
103 
106  return s << m_event << m_run << m_time << m_collisions( this );
107  }
108 
111  return s >> m_event >> m_run >> m_time >> m_collisions( this );
112  }
113 
116  return s << "class Event :"
117  << "\n Event number = " << std::setw( 12 ) << m_event << "\n Run number = " << std::setw( 12 )
118  << m_run << "\n Time = " << m_time;
119  }
120 
122  inline const SmartRefVector<Collision>& Event::collisions() const { return m_collisions; }
123 
125  inline void Event::addCollision( Collision* c ) { m_collisions.push_back( SmartRef<Collision>( c ) ); }
126 
129  for ( auto i = m_collisions.begin(); i != m_collisions.end(); ++i ) {
130  if ( i->target() == c ) {
131  m_collisions.erase( i );
132  return;
133  }
134  }
135  }
136 
138  inline std::ostream& operator<<( std::ostream& s, const Event& obj ) { return obj.fillStream( s ); }
139  } // namespace Examples
140 } // namespace Gaudi
141 #endif // GAUDIEXAMPLES_EVENT_H
Gaudi::Examples::Event::event
int event() const
Retrieve event number.
Definition: Event.h:50
Collision.h
SmartRefVector
Kernel objects: SmartRefVector.
Definition: SmartRefVector.h:79
gaudirun.s
string s
Definition: gaudirun.py:346
SmartRefVector.h
Gaudi::Examples::Event::addCollision
void addCollision(Collision *vtx)
Add collision.
Definition: Event.h:125
gaudirun.c
c
Definition: gaudirun.py:525
StreamBuffer.h
Gaudi::Examples::Event::removeCollision
void removeCollision(Collision *vtx)
Remove collision.
Definition: Event.h:128
Gaudi::Examples::operator<<
std::ostream & operator<<(std::ostream &s, const Event &obj)
Output operator (ASCII)
Definition: Event.h:138
StreamBuffer
Definition: StreamBuffer.h:52
Gaudi::Time
Definition: Time.h:241
Gaudi::Examples::Event::m_time
Gaudi::Time m_time
Time stamp.
Definition: Event.h:87
std::ostream
STL class.
Gaudi::Examples::Event::fillStream
std::ostream & fillStream(std::ostream &s) const override
Fill the output stream (ASCII)
Definition: Event.h:115
Gaudi::Examples::Event
Definition: Event.h:39
Gaudi::Examples::Collision
Definition: Collision.h:28
CLID
unsigned int CLID
Class ID definition.
Definition: ClassID.h:18
Gaudi::Examples::Event::run
int run() const
Retrieve run number.
Definition: Event.h:55
Gaudi::Examples::Event::collisions
const SmartRefVector< Collision > & collisions() const
Access to collisions.
Definition: Event.h:122
Gaudi
This file provides a Grammar for the type Gaudi::Accumulators::Axis It allows to use that type from p...
Definition: __init__.py:1
Gaudi::Examples::Event::m_event
int m_event
Event number.
Definition: Event.h:83
DataObject.h
Time.h
Gaudi::Examples::Event::time
const Gaudi::Time & time() const
Retrieve reference to event time stamp.
Definition: Event.h:60
Kernel.h
DataObject
Definition: DataObject.h:36
Gaudi::Examples::Event::setTime
void setTime(const Gaudi::Time &value)
Update reference to event time stamp.
Definition: Event.h:62
Gaudi::Examples::Event::serialize
virtual StreamBuffer & serialize(StreamBuffer &s) const
Serialize the object for writing.
Definition: Event.h:105
SmartRef
Kernel objects: SmartRef.
Definition: SmartRef.h:76
Gaudi::Examples::Event::m_collisions
SmartRefVector< Collision > m_collisions
Vector of collisions this object belongs to.
Definition: Event.h:90
Gaudi::Examples::Event::m_run
int m_run
Run number.
Definition: Event.h:85
std::setw
T setw(T... args)
Gaudi::Examples::Event::clID
const CLID & clID() const override
Retrieve reference to class definition structure.
Definition: Event.h:46
Gaudi::Examples::Event::classID
static const CLID & classID()
Definition: Event.h:47
Gaudi::Examples::Event::setEvent
void setEvent(int value)
Update event number.
Definition: Event.h:52
Gaudi::Examples::Event::setRun
void setRun(int value)
Update run number.
Definition: Event.h:57
GAUDI_API
#define GAUDI_API
Definition: Kernel.h:81