Line data Source code
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 :
18 0 : PhysicsEvent(TAFlowEvent* flow)
19 0 : : TAFlowEvent(flow)
20 : {
21 0 : fSeqNo = ++gfCounter;
22 0 : printf("PhysicsEvent::ctor: %d\n", fSeqNo);
23 0 : }
24 :
25 0 : ~PhysicsEvent()
26 0 : {
27 0 : printf("PhysicsEvent::dtor: %d\n", fSeqNo);
28 0 : }
29 : };
30 :
31 : int PhysicsEvent::gfCounter = 0;
32 :
33 : class Module1: public TARunObject
34 : {
35 : public:
36 0 : Module1(TARunInfo* runinfo)
37 0 : : TARunObject(runinfo)
38 : {
39 0 : printf("Module1::ctor, run %d, file %s\n", runinfo->fRunNo, runinfo->fFileName.c_str());
40 0 : fModuleName = "Module1";
41 0 : }
42 :
43 0 : ~Module1()
44 0 : {
45 0 : printf("Module1::dtor!\n");
46 0 : }
47 :
48 0 : TAFlowEvent* Analyze(TARunInfo* runinfo, TMEvent* event, TAFlags* flags, TAFlowEvent* flow)
49 : {
50 0 : 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 0 : for (int i=0; i<3; i++) {
56 : //
57 : // unpack the physics events
58 : //
59 : // PhysicsEvent* e = unpack(event, i);
60 0 : PhysicsEvent* e = new PhysicsEvent(NULL);
61 :
62 : // push physics events into the event queue
63 0 : runinfo->AddToFlowQueue(e);
64 :
65 : // analysis of the PhysicsEvent should be done
66 : // in AnalyzeFlowEvent()
67 : }
68 :
69 0 : return flow; // normal flow mechanism is not used here
70 : }
71 :
72 0 : void PreEndRun(TARunInfo* runinfo)
73 : {
74 0 : 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 0 : for (int i=0; i<3; i++) {
82 : //
83 : // unpack the physics events
84 : //
85 : // PhysicsEvent* e = unpack_buffered_data(i);
86 0 : PhysicsEvent* e = new PhysicsEvent(NULL);
87 :
88 : // push physics events into the event queue
89 0 : runinfo->AddToFlowQueue(e);
90 : }
91 0 : }
92 :
93 0 : TAFlowEvent* AnalyzeFlowEvent(TARunInfo* runinfo, TAFlags* flags, TAFlowEvent* flow)
94 : {
95 0 : PhysicsEvent* e = flow->Find<PhysicsEvent>();
96 0 : if (e) {
97 0 : printf("Module1::AnalyzeFlowEvent, run %d, PhysicsEvent.seqno %d\n", runinfo->fRunNo, e->fSeqNo);
98 : //
99 : // analyze the physics event here
100 : //
101 : }
102 0 : return flow;
103 : }
104 :
105 0 : void EndRun(TARunInfo* runinfo)
106 : {
107 0 : 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 0 : }
113 : };
114 :
115 : class Module2: public TARunObject
116 : {
117 : public:
118 0 : Module2(TARunInfo* runinfo)
119 0 : : TARunObject(runinfo)
120 : {
121 0 : printf("Module2::ctor, run %d, file %s\n", runinfo->fRunNo, runinfo->fFileName.c_str());
122 0 : fModuleName = "Module2";
123 0 : }
124 :
125 0 : ~Module2()
126 0 : {
127 0 : printf("Module2::dtor!\n");
128 0 : }
129 :
130 0 : TAFlowEvent* AnalyzeFlowEvent(TARunInfo* runinfo, TAFlags* flags, TAFlowEvent* flow)
131 : {
132 0 : PhysicsEvent* e = flow->Find<PhysicsEvent>();
133 0 : if (e) {
134 0 : 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 0 : return flow;
140 : }
141 : };
142 :
143 : static TARegister tar1(new TAFactoryTemplate<Module1>);
144 : static TARegister tar2(new TAFactoryTemplate<Module2>);
145 :
146 : /* emacs
147 : * Local Variables:
148 : * tab-width: 8
149 : * c-basic-offset: 3
150 : * indent-tabs-mode: nil
151 : * End:
152 : */
|