LCIO  02.17
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
RunEventMap.cc
Go to the documentation of this file.
1 #include "SIO/RunEventMap.h"
2 
3 #include <iostream>
4 
5 namespace SIO {
6 
7  bool operator < ( const RunEvent& r0, const RunEvent& other) {
8 
9  //std::cout << r0 << " < " << other << " : ["
10  //<< ( r0.RunNum == other.RunNum ? r0.EvtNum < other.EvtNum : r0.RunNum < other.RunNum ) << "]" << std::endl;
11 
12  if( r0.EvtNum < 0 ) { // sort run records (evtNu == -1 ) first
13 
14  return ( other.EvtNum < 0 ? r0.RunNum < other.RunNum : true ) ;
15  }
16  else if( other.EvtNum < 0 ) return false ;
17 
18  return ( r0.RunNum == other.RunNum ? r0.EvtNum < other.EvtNum : r0.RunNum < other.RunNum ) ;
19  }
20 
21  //----------------------------------------------------------------------------
22 
24 
25  os << " run: " << re.RunNum << " - evt: " << re.EvtNum ;
26 
27  return os ;
28  }
29 
30  //----------------------------------------------------------------------------
31 
32  void RunEventMap::add(const RunEvent& re, long64 pos ) {
33  auto p = _map.insert( std::make_pair( (long64) re , pos ) ) ;
34  // if event/run exists don't count as new entry
35  if( p.second ) {
36  if( re.EvtNum > -1 ) {
37  ++_nEvt ;
38  }
39  else {
40  ++ _nRun ;
41  }
42 
43  }
44  // overwrite with new entry
45  else {
46  p.first->second = pos ;
47  }
48  }
49 
50  //----------------------------------------------------------------------------
51 
52  //----------------------------------------------------------------------------
53 
55  auto it = _map.find( re ) ;
56  return ( it != _map.end() ? it->second : npos ) ;
57  }
58 
59  //----------------------------------------------------------------------------
60 
62  if( _map.empty() ) {
63  return RunEvent( -1 , -1 ) ;
64  }
65  return _map.begin()->first ;
66  }
67 
68  //----------------------------------------------------------------------------
69 
71  if( _map.empty() ) {
72  return RunEvent( -1 , -1 ) ;
73  }
74  auto it = _map.rbegin() ;
75  return it->first ;
76  }
77 
78  //----------------------------------------------------------------------------
79 
80  //----------------------------------------------------------------------------
81 
83  os << " ------- RunEventMap : " << std::endl ;
84  for( auto it = rm.begin() ; it != rm.end() ; ++it ) {
85  os << " " << RunEvent( it->first ).RunNum << ", " << RunEvent( it->first ).EvtNum << " : " << it->second << std::endl;
86  }
87  return os ;
88  }
89 
90 }
RunEvent minRunEvent() const
Definition: RunEventMap.cc:61
T empty(T...args)
iterator begin()
Definition: RunEventMap.h:84
T endl(T...args)
T end(T...args)
Helper struct that stores run and event positions in the file.
Definition: RunEventMap.h:14
long long long64
Definition: RunEventMap.h:38
Map that holds positions of Run and Event records.
Definition: RunEventMap.h:37
std::ostream & operator<<(std::ostream &os, const LCIORandomAccess &ra)
long64 getPosition(const RunEvent &re)
Return the position of the specified Event record or Run record respectively (if EventNum == -1 )...
Definition: RunEventMap.h:59
static constexpr const int npos
Definition: RunEventMap.h:46
void add(const RunEvent &re, long64 pos)
Add a new entry to the event map - if the RunEvent already exists the new position will be stored...
Definition: RunEventMap.cc:32
T make_pair(T...args)
T insert(T...args)
T find(T...args)
iterator end()
Definition: RunEventMap.h:85
T begin(T...args)
RunEvent maxRunEvent() const
Definition: RunEventMap.cc:70
STL class.
bool operator<(const LCIORandomAccess &ra0, const LCIORandomAccess &other)
T rbegin(T...args)