ROOTANA
manalyzer_example_frontend.cxx
Go to the documentation of this file.
1 //
2 // MIDAS analyzer example: MIDAS frontend for sending analyzed data back into MIDAS
3 //
4 // K.Olchanski
5 //
6 
7 #undef NDEBUG // midas required assert() to be always enabled
8 
9 #include <stdio.h>
10 #include <cassert>
11 
12 #include "manalyzer.h"
13 #include "midasio.h"
14 
15 class TMEventFlow : public TAFlowEvent
16 {
17 public:
19 
20  TMEventFlow(TAFlowEvent* flow, const TMEvent& event)
21  : TAFlowEvent(flow)
22  {
23  fEvent = event;
24  }
25 };
26 
27 /*******************************************************************\
28 
29  Name: tmfe_example_everything.cxx
30  Created by: K.Olchanski
31 
32  Contents: Example Front end to demonstrate all functions of TMFE class
33 
34 \********************************************************************/
35 
36 
37 #include <stdio.h>
38 #include "tmfe.h"
39 
40 class EqAnalyzer :
41  public TMFeEquipment
42 {
43 public:
44  EqAnalyzer(const char* eqname, const char* eqfilename) // ctor
45  : TMFeEquipment(eqname, eqfilename)
46  {
47  printf("EqAnalyzer::ctor!\n");
48 
49  // configure the equipment here:
50 
51  fEqConfReadConfigFromOdb = false;
52  fEqConfEventID = 100;
53  fEqConfPeriodMilliSec = 0;
54  //fEqConfWriteEventsToOdb = true;
55  fEqConfBuffer = "ANAA";
56  }
57 
58  ~EqAnalyzer() // dtor
59  {
60  printf("EqAnalyzer::dtor!\n");
61  }
62 
63  void HandleUsage()
64  {
65  printf("EqAnalyzer::HandleUsage!\n");
66  }
67 
68  TMFeResult HandleInit(const std::vector<std::string>& args)
69  {
70  printf("EqAnalyzer::HandleInit!\n");
71  fEqConfReadOnlyWhenRunning = false; // overwrite ODB Common RO_RUNNING to false
72  //fEqConfWriteEventsToOdb = true; // overwrite ODB Common RO_ODB to true
73  //EqSetStatus("Started...", "white");
74  return TMFeOk();
75  }
76 };
77 
78 // example frontend
79 
80 class FeAnalyzer: public TMFrontend
81 {
82 public:
83 };
84 
85 /* emacs
86  * Local Variables:
87  * tab-width: 8
88  * c-basic-offset: 3
89  * indent-tabs-mode: nil
90  * End:
91  */
92 
94 {
95 public:
96  EqAnalyzer* fEq = NULL;
97 
98 public:
100  : TARunObject(runinfo)
101  {
102  printf("ExampleFrontend::ctor, run %d, file %s\n", runinfo->fRunNo, runinfo->fFileName.c_str());
103  fModuleName = "ExampleFrontend";
104  fEq = eq;
105  }
106 
108  {
109  printf("ExampleFrontend::dtor!\n");
110  }
111 
112  TAFlowEvent* Analyze(TARunInfo* runinfo, TMEvent* event, TAFlags* flags, TAFlowEvent* flow)
113  {
114  printf("ExampleFrontend::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);
115 
116  flow = new TMEventFlow(flow, *event);
117 
118  return flow;
119  }
120 
122  {
123  printf("ExampleFrontend::AnalyzeFlowEvent, run %d\n", runinfo->fRunNo);
124 
125  if (!flow)
126  return flow;
127 
128  TMEventFlow* ef = flow->Find<TMEventFlow>();
129 
130  if (!ef)
131  return flow;
132 
133  uint32_t anaa_bank[] = { 1, 2, 3, 4 };
134 
135  ef->fEvent.AddBank("ANAA", TID_UINT32, (const char*)&anaa_bank[0], sizeof(anaa_bank));
136 
137  ef->fEvent.PrintHeader();
138 
139  if (fEq) {
140  fEq->EqSendEvent(ef->fEvent.data);
141  fEq->EqWriteStatistics();
142  }
143 
144  return flow;
145  }
146 };
147 
149 {
150  FeAnalyzer* fFe = NULL;
151  EqAnalyzer* fEq = NULL;
152 
153  void Init(const std::vector<std::string> &args)
154  {
155  printf("ExampleFrontendFactory::Init!\n");
156 
157  assert(fEq == NULL);
158 
159  fFe = new FeAnalyzer();
160  fEq = new EqAnalyzer("analyzer", __FILE__);
161  fFe->FeAddEquipment(fEq);
162 
163  TMFeResult r = fFe->FeInitEquipments(args);
164 
165  if (r.error_flag) {
166  fprintf(stderr, "Cannot initialize equipments, error message: %s, bye.\n", r.error_message.c_str());
167  fFe->fMfe->Disconnect();
168  exit(1);
169  }
170  }
171 
172  void Finish()
173  {
174  printf("ExampleFrontendFactory::Finish!\n");
175 
176  //if (fEq) {
177  // delete fEq;
178  // fEq = NULL;
179  //}
180  if (fFe) {
181  delete fFe;
182  fFe = NULL;
183  }
184  }
185 
187  {
188  return new ExampleFrontend(runinfo, fEq);
189  }
190 };
191 
193 
194 /* emacs
195  * Local Variables:
196  * tab-width: 8
197  * c-basic-offset: 3
198  * indent-tabs-mode: nil
199  * End:
200  */
TMFeResult HandleInit(const std::vector< std::string > &args)
EqAnalyzer(const char *eqname, const char *eqfilename)
void Init(const std::vector< std::string > &args)
ExampleFrontend * NewRunObject(TARunInfo *runinfo)
TAFlowEvent * Analyze(TARunInfo *runinfo, TMEvent *event, TAFlags *flags, TAFlowEvent *flow)
TAFlowEvent * AnalyzeFlowEvent(TARunInfo *runinfo, TAFlags *flags, TAFlowEvent *flow)
ExampleFrontend(TARunInfo *runinfo, EqAnalyzer *eq)
T * Find()
Definition: manalyzer.h:57
std::string fFileName
Definition: manalyzer.h:25
int fRunNo
Definition: manalyzer.h:24
std::string fModuleName
Definition: manalyzer.h:84
TMEventFlow(TAFlowEvent *flow, const TMEvent &event)
void PrintHeader() const
Definition: midasio.cxx:1099
void AddBank(const char *bank_name, int tid, const char *buf, size_t size)
add new MIDAS bank
Definition: midasio.cxx:825
std::vector< char > data
MIDAS event bytes.
Definition: midasio.h:67
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
#define TID_UINT32
Definition: midasio.h:23
static TARegister tar(new ExampleFrontendFactory)