MarlinMT  0.1.0
ReaderListener.cc
Go to the documentation of this file.
2 
3 // -- marlinmt headers
4 #include <marlinmt/RunHeader.h>
5 #include <marlinmt/EventStore.h>
6 #include <jenkinsHash.h>
7 
8 // -- lcio headers
9 #include <EVENT/LCEvent.h>
10 #include <EVENT/LCRunHeader.h>
11 
12 namespace marlinmt {
13 
15  _onEventRead = func ;
16  }
17 
18  //--------------------------------------------------------------------------
19 
21  _onRunHeaderRead = func ;
22  }
23 
24  //--------------------------------------------------------------------------
25 
26  void ReaderListener::processEvent( std::shared_ptr<EVENT::LCEvent> event ) {
27  if( nullptr != _onEventRead ) {
28  auto store = std::make_shared<EventStore>() ;
29  store->setEvent( event ) ;
30  // generate the event unique id
31  auto evtn = event->getEventNumber() ;
32  auto runn = event->getRunNumber() ;
33  unsigned char * c = (unsigned char *) &evtn ;
34  unsigned int uid = jenkins_hash( c, sizeof evtn, 0) ;
35  c = (unsigned char *) &runn ;
36  uid = jenkins_hash( c, sizeof runn, 0) ;
37  store->setUID( uid ) ;
38  _onEventRead( store ) ;
39  }
40  }
41 
42  //--------------------------------------------------------------------------
43 
44  void ReaderListener::processRunHeader( std::shared_ptr<EVENT::LCRunHeader> rhdr ) {
45  if( nullptr != _onRunHeaderRead ) {
46  auto header = std::make_shared<RunHeader>() ;
47  header->setRunNumber( rhdr->getRunNumber() ) ;
48  header->setDetectorName( rhdr->getDetectorName() ) ;
49  header->setDescription( rhdr->getDescription() ) ;
50  auto subdets = rhdr->getActiveSubdetectors() ;
51  header->setParameter( "ActiveSubdetectors", *subdets ) ;
52  auto &lcparams = rhdr->parameters() ;
53  EVENT::StringVec intKeys, floatKeys, strKeys ;
54  lcparams.getIntKeys( intKeys ) ;
55  lcparams.getFloatKeys( floatKeys ) ;
56  lcparams.getStringKeys( strKeys ) ;
57  header->setParameter( "LCIntKeys", intKeys ) ;
58  header->setParameter( "LCFloatKeys", floatKeys ) ;
59  header->setParameter( "LCStrKeys", strKeys ) ;
60  for( auto key : intKeys ) {
61  EVENT::IntVec values ;
62  lcparams.getIntVals( key, values ) ;
63  header->setParameter( key, values ) ;
64  }
65  for( auto key : intKeys ) {
66  EVENT::FloatVec values ;
67  lcparams.getFloatVals( key, values ) ;
68  header->setParameter( key, values ) ;
69  }
70  for( auto key : intKeys ) {
71  EVENT::StringVec values ;
72  lcparams.getStringVals( key, values ) ;
73  header->setParameter( key, values ) ;
74  }
75  _onRunHeaderRead( header ) ;
76  }
77  }
78 
79 }
EventFunction _onEventRead
Callback function on event read.
void processEvent(std::shared_ptr< EVENT::LCEvent > event) override
unsigned jenkins_hash(unsigned char *k, unsigned length, unsigned initval)
Definition: jenkinsHash.h:94
std::function< void(std::shared_ptr< RunHeader >)> RunHeaderFunction
std::function< void(std::shared_ptr< EventStore >)> EventFunction
void onEventRead(EventFunction func)
Set the callback function to process on event read.
RunHeaderFunction _onRunHeaderRead
Callback function on run info read.
void onRunHeaderRead(RunHeaderFunction func)
Set the callback function to process on run info read.
void processRunHeader(std::shared_ptr< EVENT::LCRunHeader > rhdr) override