LCIO  02.17
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
LCEventImpl.cc
Go to the documentation of this file.
1 
2 #include "IMPL/LCEventImpl.h"
3 #include "IMPL/AccessChecked.h"
4 #include "IMPL/LCCollectionVec.h"
5 
6 #define EVT_WGT "_weight"
7 
8 #include <iostream>
9 #include <sstream>
10 
11 
12 using namespace EVENT ;
13 //using namespace DATA ;
14 
15 namespace IMPL {
16 
17 LCEventImpl::LCEventImpl() :
18  _runNumber(0),
19  _eventNumber(0),
20  _timeStamp(0),
21  _detectorName("unknown") {
22 }
23 
24 
26  // here we need to delete all collections in the event
27  for ( auto i=_colMap.begin() ; i != _colMap.end() ; i++ ){
28  // except collections whose ownership we gave away
29  if( _notOwned.find( i->second ) == _notOwned.end() )
30  delete i->second ;
31  }
32 
33 }
34 
36  return _runNumber ;
37 }
38 
39 
41  return _eventNumber ;
42 }
43 
44 
46  return _detectorName ;
47 }
48 
49 
51  return _timeStamp ;
52 }
53 
54 double LCEventImpl::getWeight() const {
55  double w = _params.getFloatVal( EVT_WGT ) ;
56  return w == 0 ? 1. : w ;
57 }
58 
59 
61  // return pointer to updated vector _colNames
62  _colNames.clear() ;
63  for ( auto i=_colMap.begin() ; i != _colMap.end() ; i++ ){
64  _colNames.push_back( i->first ) ;
65  }
66  return &_colNames ;
67 }
68 
69 
70 
72  {
73 
74  LCCollectionMap::iterator it = _colMap.find( name ) ;
75 
76  if( it == _colMap.end() ) {
77 
79  ss << "LCEventImpl::getCollection: collection not in event:" << name ;
80 
81  throw( DataNotAvailableException( ss.str() ) ) ;
82  }
83  return it->second ;
84 
85  // if( _colMap.find( name ) == _colMap.end() )
86  // throw(DataNotAvailableException( std::string("LCEventImpl::getCollection: collection not in event:" // + name) )) ;
87  // return _colMap[ name ] ;
88 
89 }
90 
91 
93  {
94 
95  LCCollectionVec* col = dynamic_cast<LCCollectionVec*> ( getCollection( name ) ) ;
96 
97  col->setTransient( true ) ;
98 
99  _notOwned.insert( col ) ;
100 
101  return col ;
102 }
103 
104 
105 
106 
108  {
109 
110 
111  if( ! validateCollectionName(name.c_str()) ){
112 
113  throw EventException( std::string("LCEventImpl::addCollection() invalid name (has to be C/C++ name): "
114  +name) ) ;
115  }
116 
117  // check if name exists
118  if( _colMap.find( name ) != _colMap.end() )
119 
120  throw EventException( std::string("LCEventImpl::addCollection() name already exists: "
121  +name) ) ;
122  // check if col != 0
123  if( col == 0 )
124 
125  throw EventException( std::string("LCEventImpl::addCollection() cannot add NULL collection for : "
126  +name) ) ;
127 
128  _colMap[ name ] = col ;
129 
130 }
131 
132 
133 
135 
136  // remove collection only, if access mode == update
137  checkAccess("LCEventImpl::removeCollection") ;
138  _colMap.erase( name ) ;
139 
140 }
141 
142 
143 
145  checkAccess("LCEventImpl::setRunNumber") ;
146  _runNumber = rn ;
147 }
148 
149 
151  checkAccess("LCEventImpl::setEventNumber") ;
152  _eventNumber = en ;
153 }
154 
155 
157  checkAccess("LCEventImpl::setDetectorName") ;
158  _detectorName = dn ;
159 }
160 
161 
163  checkAccess("LCEventImpl::setTimeStamp") ;
164  _timeStamp = ts ;
165 }
166 
167 
168 void LCEventImpl::setWeight(double w) {
169  checkAccess("LCEventImpl::setWeight") ;
170  _params.setValue( EVT_WGT , (float) w ) ;
171 }
172 
173 
174 void LCEventImpl::setAccessMode( int accessMode ) {
175 
176  // loop over all collections and set the access mode
177  bool readOnly = ( accessMode == LCIO::READ_ONLY ) ;
178 
179  setReadOnly( readOnly ) ;
180 
181  for ( auto i=_colMap.begin() ; i != _colMap.end() ; i++ ){
182 
183  AccessChecked* col = dynamic_cast<AccessChecked*>( i->second ) ;
184  if( col ){
185  col->setReadOnly( readOnly ) ;
186  }
187  }
188 
189 
190 }
191 
195  bool LCEventImpl::validateCollectionName( const char* name ){ //copy of SIO_functions::validateName
196 
197  if( *name < 0 )
198  return false ;
199 
200  if( !isalpha( (int)*name ) && *name != '_' )
201  return false ;
202 
203  for( name += 1; *name != '\0'; name++ ){
204  if( *name < 0 )
205  return false ;
206  if( !isalnum( (int)*name ) && *name != '_' )
207  return false ;
208  }
209  return true ;
210  }
211 
212 }
void setTimeStamp(EVENT::long64 ts)
Sets the event time stamp.
Definition: LCEventImpl.cc:162
void setWeight(double w)
Set the event weight.
Definition: LCEventImpl.cc:168
Implementation of the LCCollection using (inheriting from) an STL vector of LCObjects.
virtual EVENT::long64 getTimeStamp() const
Returns the time stamp of the event.
Definition: LCEventImpl.cc:50
#define EVT_WGT
Definition: LCEventImpl.cc:6
virtual const std::string & getDetectorName() const
Returns the name of the detector setup used in the simulation.
Definition: LCEventImpl.cc:45
virtual const std::vector< std::string > * getCollectionNames() const
Returns the names of the collections in the event.
Definition: LCEventImpl.cc:60
virtual double getWeight() const
Returns the event weight.
Definition: LCEventImpl.cc:54
virtual int getRunNumber() const
Return the run number off this event.
Definition: LCEventImpl.cc:35
T end(T...args)
void setTransient(bool val=true)
Sets the transient flag for this collection.
long long long64
64 bit signed integer,e.g.to be used for timestamps
Definition: LCIOTypes.h:14
STL class.
virtual void addCollection(EVENT::LCCollection *col, const std::string &name)
Adds a collection with the given name (has to be a valid C/C++ variable name).
Definition: LCEventImpl.cc:107
T push_back(T...args)
void setEventNumber(int en)
Sets the event number.
Definition: LCEventImpl.cc:150
virtual int getEventNumber() const
Returns this event&#39;s number .
Definition: LCEventImpl.cc:40
EventException used for errors accessing the event data.
Definition: Exceptions.h:44
virtual float getFloatVal(const std::string &key) const
Returns the first float value for the given key.
T erase(T...args)
T str(T...args)
LCCollectionMap _colMap
Definition: LCEventImpl.h:180
virtual EVENT::LCCollection * getCollection(const std::string &name) const
Returns the collection for the given name.
Definition: LCEventImpl.cc:71
virtual ~LCEventImpl()
Copy contructor, creates a deep copy of the event.
Definition: LCEventImpl.cc:25
EVENT::long64 _timeStamp
Definition: LCEventImpl.h:176
void setRunNumber(int rn)
Sets the run number.
Definition: LCEventImpl.cc:144
T clear(T...args)
bool validateCollectionName(const char *name)
Tests the validity of a collection name.
Definition: LCEventImpl.cc:195
T insert(T...args)
T find(T...args)
virtual void setReadOnly(bool readOnly)
EventException used for data not available.
Definition: Exceptions.h:60
LCCollectionSet _notOwned
Definition: LCEventImpl.h:186
The generic collection used in LCIO.
Definition: LCCollection.h:29
T begin(T...args)
void setDetectorName(const std::string &dn)
Sets the detector name.
Definition: LCEventImpl.cc:156
virtual EVENT::LCCollection * takeCollection(const std::string &name) const
Returns the collection for the given name and transfers the ownership of the collection to the caller...
Definition: LCEventImpl.cc:92
virtual void removeCollection(const std::string &name)
Removes (and deletes) the collection with name (if it exists in the event).
Definition: LCEventImpl.cc:134
T c_str(T...args)
std::string _detectorName
Definition: LCEventImpl.h:177
Controls access to objects.
Definition: AccessChecked.h:18
virtual void setValue(const std::string &key, int value)
Set integer value for the given key.
LCParametersImpl _params
Definition: LCEventImpl.h:183
std::vector< std::string > _colNames
Definition: LCEventImpl.h:181
void setAccessMode(int accessMode)
Definition: LCEventImpl.cc:174