ROOTANA
manalyzer_example_flow_queue.cxx
Go to the documentation of this file.
1 //
2 // MIDAS analyzer example 4: C++ flow analyzer
3 //
4 // K.Olchanski
5 //
6 
7 #include <stdio.h>
8 
9 #include "manalyzer.h"
10 #include "midasio.h"
11 
12 class PhysicsEvent : public TAFlowEvent
13 {
14 public:
15  int fSeqNo;
16  static int gfCounter;
17 
19  : TAFlowEvent(flow)
20  {
21  fSeqNo = ++gfCounter;
22  printf("PhysicsEvent::ctor: %d\n", fSeqNo);
23  }
24 
26  {
27  printf("PhysicsEvent::dtor: %d\n", fSeqNo);
28  }
29 };
30 
32 
33 class Module1: public TARunObject
34 {
35 public:
36  Module1(TARunInfo* runinfo)
37  : TARunObject(runinfo)
38  {
39  printf("Module1::ctor, run %d, file %s\n", runinfo->fRunNo, runinfo->fFileName.c_str());
40  fModuleName = "Module1";
41  }
42 
44  {
45  printf("Module1::dtor!\n");
46  }
47 
48  TAFlowEvent* Analyze(TARunInfo* runinfo, TMEvent* event, TAFlags* flags, TAFlowEvent* flow)
49  {
50  printf("Module1::Analyze, run %d, event serno %d, id 0x%04x, data size %d\n", runinfo->fRunNo, event->serial_number, (int)event->event_id, event->data_size);
51 
52  //
53  // one midas event contains multiple physics events:
54  //
55  for (int i=0; i<3; i++) {
56  //
57  // unpack the physics events
58  //
59  // PhysicsEvent* e = unpack(event, i);
60  PhysicsEvent* e = new PhysicsEvent(NULL);
61 
62  // push physics events into the event queue
63  runinfo->AddToFlowQueue(e);
64 
65  // analysis of the PhysicsEvent should be done
66  // in AnalyzeFlowEvent()
67  }
68 
69  return flow; // normal flow mechanism is not used here
70  }
71 
72  void PreEndRun(TARunInfo* runinfo)
73  {
74  printf("Module1::PreEndRun, run %d\n", runinfo->fRunNo);
75 
76  // after receiving the last midas event in Analyze(),
77  // the upacking code may have some left-over data
78  // in it's buffers and queues, here we convert it into
79  // the last physics events
80 
81  for (int i=0; i<3; i++) {
82  //
83  // unpack the physics events
84  //
85  // PhysicsEvent* e = unpack_buffered_data(i);
86  PhysicsEvent* e = new PhysicsEvent(NULL);
87 
88  // push physics events into the event queue
89  runinfo->AddToFlowQueue(e);
90  }
91  }
92 
94  {
95  PhysicsEvent* e = flow->Find<PhysicsEvent>();
96  if (e) {
97  printf("Module1::AnalyzeFlowEvent, run %d, PhysicsEvent.seqno %d\n", runinfo->fRunNo, e->fSeqNo);
98  //
99  // analyze the physics event here
100  //
101  }
102  return flow;
103  }
104 
105  void EndRun(TARunInfo* runinfo)
106  {
107  printf("Module1::EndRun, run %d\n", runinfo->fRunNo);
108 
109  // NB: we should not create and queue any new PhysicsEvents
110  // because they will not be analyzed.
111  // not permitted: runinfo->fFlowQueue.push_back(e);
112  }
113 };
114 
115 class Module2: public TARunObject
116 {
117 public:
118  Module2(TARunInfo* runinfo)
119  : TARunObject(runinfo)
120  {
121  printf("Module2::ctor, run %d, file %s\n", runinfo->fRunNo, runinfo->fFileName.c_str());
122  fModuleName = "Module2";
123  }
124 
126  {
127  printf("Module2::dtor!\n");
128  }
129 
131  {
132  PhysicsEvent* e = flow->Find<PhysicsEvent>();
133  if (e) {
134  printf("Module2::AnalyzeFlowEvent, run %d, PhysicsEvent.seqno %d\n", runinfo->fRunNo, e->fSeqNo);
135  //
136  // do some additional analysis of PhysicsEvent here
137  //
138  }
139  return flow;
140  }
141 };
142 
145 
146 /* emacs
147  * Local Variables:
148  * tab-width: 8
149  * c-basic-offset: 3
150  * indent-tabs-mode: nil
151  * End:
152  */
TAFlowEvent * AnalyzeFlowEvent(TARunInfo *runinfo, TAFlags *flags, TAFlowEvent *flow)
void EndRun(TARunInfo *runinfo)
void PreEndRun(TARunInfo *runinfo)
TAFlowEvent * Analyze(TARunInfo *runinfo, TMEvent *event, TAFlags *flags, TAFlowEvent *flow)
Module1(TARunInfo *runinfo)
Module2(TARunInfo *runinfo)
TAFlowEvent * AnalyzeFlowEvent(TARunInfo *runinfo, TAFlags *flags, TAFlowEvent *flow)
PhysicsEvent(TAFlowEvent *flow)
T * Find()
Definition: manalyzer.h:57
void AddToFlowQueue(TAFlowEvent *)
Definition: manalyzer.cxx:1349
std::string fFileName
Definition: manalyzer.h:25
int fRunNo
Definition: manalyzer.h:24
std::string fModuleName
Definition: manalyzer.h:84
uint32_t serial_number
MIDAS event serial number.
Definition: midasio.h:59
uint32_t data_size
MIDAS event data size.
Definition: midasio.h:61
uint16_t event_id
MIDAS event ID.
Definition: midasio.h:57
int TAFlags
Definition: manalyzer.h:72
static TARegister tar2(new TAFactoryTemplate< Module2 >)
static TARegister tar1(new TAFactoryTemplate< Module1 >)