MarlinMT  0.1.0
Sequence.h
Go to the documentation of this file.
1 #ifndef MARLINMT_SEQUENCE_h
2 #define MARLINMT_SEQUENCE_h 1
3 
4 // -- std headers
5 #include <vector>
6 #include <unordered_set>
7 #include <memory>
8 #include <map>
9 #include <mutex>
10 #include <utility> // pair
11 #include <ctime>
12 
13 // -- marlinmt headers
14 #include <marlinmt/Logging.h>
15 #include <marlinmt/Utils.h>
16 
17 namespace marlinmt {
18 
19  class Application ;
20  class SequenceItem ;
21  class Processor ;
22  class EventStore ;
23  class RunHeader ;
24  class ConfigSection ;
25 
26  //--------------------------------------------------------------------------
27  //--------------------------------------------------------------------------
28 
34  class SequenceItem {
35  public:
36  ~SequenceItem() = default ;
37 
43  SequenceItem( std::shared_ptr<Processor> proc ) ;
44 
51  SequenceItem( std::shared_ptr<Processor> proc, std::shared_ptr<std::mutex> lock ) ;
52 
58  void processRunHeader( std::shared_ptr<RunHeader> rhdr ) ;
59 
68  clock::pair processEvent( std::shared_ptr<EventStore> event ) ;
69 
78  // clock::pair modifyEvent( std::shared_ptr<EVENT::LCEvent> event ) ;
79 
83  std::shared_ptr<Processor> processor() const ;
84 
88  const std::string &name() const ;
89 
90  private:
92  std::shared_ptr<Processor> _processor {nullptr} ;
94  std::shared_ptr<std::mutex> _mutex {nullptr} ;
95  };
96 
97  //--------------------------------------------------------------------------
98  //--------------------------------------------------------------------------
99 
104  struct ClockMeasure {
106  clock::duration_rep _appClock {0.} ;
108  clock::duration_rep _procClock {0.} ;
110  int _counter {0} ;
111  };
112 
113  //--------------------------------------------------------------------------
114  //--------------------------------------------------------------------------
115 
128  class Sequence {
129  public:
130  using Container = std::vector<std::shared_ptr<SequenceItem>> ;
131  using Index = Container::size_type ;
132  using SizeType = Container::size_type ;
133  using ClockMeasureMap = std::map<std::string, ClockMeasure> ;
134  using SkippedEventMap = std::map<std::string, int> ;
135 
136  public:
137  Sequence() = default ;
138  ~Sequence() = default ;
139  Sequence &operator=(const Sequence &) = delete ;
140  Sequence(const Sequence &) = delete ;
141 
142  public:
150  std::shared_ptr<SequenceItem> createItem( std::shared_ptr<Processor> processor, std::shared_ptr<std::mutex> lock ) const ;
151 
157  void addItem( std::shared_ptr<SequenceItem> item ) ;
158 
164  std::shared_ptr<SequenceItem> at( Index index ) const ;
165 
169  SizeType size() const ;
170 
176  void processRunHeader( std::shared_ptr<RunHeader> rhdr ) ;
177 
183  void processEvent( std::shared_ptr<EventStore> event ) ;
184 
188  ClockMeasure clockMeasureSummary() const ;
189 
193  const ClockMeasureMap &clockMeasures() const ;
194 
198  const SkippedEventMap &skippedEvents() const ;
199 
200  private:
202  Container _items {} ;
204  ClockMeasureMap _clockMeasures {} ;
206  SkippedEventMap _skipEventMap {} ;
207  };
208 
209  //--------------------------------------------------------------------------
210  //--------------------------------------------------------------------------
211 
217  private:
218  struct ItemEqual {
219  using Item = std::shared_ptr<SequenceItem> ;
220  bool operator()( const Item& lhs, const Item& rhs ) const {
221  return lhs->processor() == rhs->processor() ;
222  }
223  };
224 
225  using Sequences = std::vector<std::shared_ptr<Sequence>> ;
226  using Index = Sequences::size_type ;
227  using SizeType = Sequences::size_type ;
228  using SequenceItemList = std::unordered_set<
229  std::shared_ptr<SequenceItem>,
230  std::hash<std::shared_ptr<SequenceItem>>,
232 
233  public:
234  SuperSequence() = delete ;
235  ~SuperSequence() = default ;
236  SuperSequence(const SuperSequence &) = delete ;
237  SuperSequence &operator=(const SuperSequence &) = delete ;
238 
244  SuperSequence( std::size_t nseqs ) ;
245 
251  std::shared_ptr<Sequence> sequence( Index index ) const ;
252 
262  void addProcessor( const ConfigSection &parameters ) ;
263 
267  SizeType size() const ;
268 
274  void init( Application *app ) ;
275 
281  void processRunHeader( std::shared_ptr<RunHeader> rhdr ) ;
282 
286  void end() ;
287 
293  void printStatistics( Logging::Logger logger ) const ;
294 
295  private:
297  Sequences _sequences {} ;
299  SequenceItemList _uniqueItems {} ;
300  };
301 
302 } // end namespace marlinmt
303 
304 #endif
std::map< std::string, int > SkippedEventMap
Definition: Sequence.h:134
std::map< std::string, ClockMeasure > ClockMeasureMap
Definition: Sequence.h:133
Sequences::size_type SizeType
Definition: Sequence.h:227
Sequences::size_type Index
Definition: Sequence.h:226
std::vector< std::shared_ptr< SequenceItem > > Container
Definition: Sequence.h:130
clock::pair processEvent(std::shared_ptr< EventStore > event)
Call Processor::processEvent.
Definition: Sequence.cc:48
std::shared_ptr< Processor > processor() const
Call Processor::modifyEvent.
Definition: Sequence.cc:71
Container::size_type SizeType
Definition: Sequence.h:132
std::shared_ptr< Processor > _processor
< The processor instance
Definition: Sequence.h:92
Application class Base application interface for running a Marlin application.
Definition: Application.h:25
void processRunHeader(std::shared_ptr< RunHeader > rhdr)
Process the run header.
Definition: Sequence.cc:36
std::shared_ptr< SequenceItem > Item
Definition: Sequence.h:219
std::vector< std::shared_ptr< Sequence > > Sequences
Definition: Sequence.h:225
const std::string & name() const
Get the processor name.
Definition: Sequence.cc:77
SuperSequence class Manages a fixed list of Sequence objects.
Definition: Sequence.h:216
Container::size_type Index
Definition: Sequence.h:131
float duration_rep
Definition: Utils.h:32
SequenceItem(std::shared_ptr< Processor > proc)
Constructor.
Definition: Sequence.cc:16
SequenceItem class Handle a processor pointer and call Processor::processEvent in a critical section ...
Definition: Sequence.h:34
std::unordered_set< std::shared_ptr< SequenceItem >, std::hash< std::shared_ptr< SequenceItem > >, ItemEqual > SequenceItemList
Definition: Sequence.h:231
std::shared_ptr< streamlog::logstreamT< mutex_type > > Logger
Definition: Logging.h:73
bool operator()(const Item &lhs, const Item &rhs) const
Definition: Sequence.h:220
ConfigSection class Holds a set of parameters and subsection.
Definition: Configuration.h:20
std::pair< duration_rep, duration_rep > pair
Definition: Utils.h:33
Sequence class A sequence is a list of processors wrapped in SequenceItem objects.
Definition: Sequence.h:128
ClockMeasure struct Holds clock measurement data for processors.
Definition: Sequence.h:104
std::shared_ptr< std::mutex > _mutex
Definition: Sequence.h:94