ROOTANA
manalyzer_example_root.cxx
Go to the documentation of this file.
1 //
2 // MIDAS analyzer example 2: ROOT analyzer
3 //
4 // K.Olchanski
5 //
6 
7 #include <stdio.h>
8 
9 #include "manalyzer.h"
10 #include "midasio.h"
11 
12 #include "TH1D.h"
13 
14 struct ExampleRoot: public TARunObject
15 {
16  int fCounter;
17  TH1D* hperrun;
18 
20  : TARunObject(runinfo)
21  {
22  printf("ExampleRoot::ctor!\n");
23  fModuleName = "ExampleRoot";
24  }
25 
27  {
28  printf("ExampleRoot::dtor!\n");
29  }
30 
31  void BeginRun(TARunInfo* runinfo)
32  {
33  printf("BeginRun, run %d, file %s\n", runinfo->fRunNo, runinfo->fFileName.c_str());
34  uint32_t run_start_time_binary = 0;
35  runinfo->fOdb->RU32("/Runinfo/Start time binary", &run_start_time_binary);
36  time_t run_start_time = run_start_time_binary;
37  printf("ODB Run start time: %d: %s", (int)run_start_time, ctime(&run_start_time));
38  fCounter = 0;
39  runinfo->fRoot->fOutputFile->cd(); // select correct ROOT directory
40  hperrun = new TH1D("hperrun", "hperrun", 200, -100, 100);
41  }
42 
43  void EndRun(TARunInfo* runinfo)
44  {
45  printf("EndRun, run %d, events %d\n", runinfo->fRunNo, fCounter);
46  uint32_t run_stop_time_binary = 0;
47  runinfo->fOdb->RU32("/Runinfo/Stop time binary", &run_stop_time_binary);
48  time_t run_stop_time = run_stop_time_binary;
49  printf("ODB Run stop time: %d: %s", (int)run_stop_time, ctime(&run_stop_time));
50  hperrun->SaveAs("hperrun.root");
51  hperrun->SaveAs("hperrun.pdf");
52  }
53 
54  void PauseRun(TARunInfo* runinfo)
55  {
56  printf("PauseRun, run %d\n", runinfo->fRunNo);
57  }
58 
59  void ResumeRun(TARunInfo* runinfo)
60  {
61  printf("ResumeRun, run %d\n", runinfo->fRunNo);
62  }
63 
64  TAFlowEvent* Analyze(TARunInfo* runinfo, TMEvent* event, TAFlags* flags, TAFlowEvent* flow)
65  {
66  printf("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);
67  if (event->event_id != 2)
68  return flow;
69 
70  TMBank* bslow = event->FindBank("SLOW");
71  if (!bslow)
72  return flow;
73 
74  float* dslow = (float*)event->GetBankData(bslow);
75  if (!dslow)
76  return flow;
77 
78  double v = *dslow;
79 
80  printf("event %d, slow %f\n", event->serial_number, v);
81 
82  hperrun->Fill(v);
83  fCounter++;
84 
85  return flow;
86  }
87 
88  void AnalyzeSpecialEvent(TARunInfo* runinfo, TMEvent* event)
89  {
90  printf("AnalyzeSpecialEvent, run %d, event serno %d, id 0x%04x, data size %d\n", runinfo->fRunNo, event->serial_number, (int)event->event_id, event->data_size);
91  }
92 };
93 
95 {
96 public:
97  void Init(const std::vector<std::string> &args)
98  {
99  printf("Init!\n");
100  }
101 
102  void Finish()
103  {
104  printf("Finish!\n");
105  }
106 
108  {
109  printf("NewRunObject, run %d, file %s\n", runinfo->fRunNo, runinfo->fFileName.c_str());
110  return new ExampleRoot(runinfo);
111  }
112 };
113 
115 
116 /* emacs
117  * Local Variables:
118  * tab-width: 8
119  * c-basic-offset: 3
120  * indent-tabs-mode: nil
121  * End:
122  */
void Init(const std::vector< std::string > &args)
TARunObject * NewRunObject(TARunInfo *runinfo)
virtual void RU32(const char *varname, uint32_t *value, bool create=false, MVOdbError *error=NULL)=0
TFile * fOutputFile
Definition: manalyzer.h:154
std::string fFileName
Definition: manalyzer.h:25
MVOdb * fOdb
Definition: manalyzer.h:26
int fRunNo
Definition: manalyzer.h:24
TARootHelper * fRoot
Definition: manalyzer.h:27
std::string fModuleName
Definition: manalyzer.h:84
Definition: midasio.h:44
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
char * GetBankData(const TMBank *)
get pointer to MIDAS data bank
Definition: midasio.cxx:1022
int TAFlags
Definition: manalyzer.h:72
static TARegister tar(new ExampleRootFactory)
void EndRun(TARunInfo *runinfo)
void ResumeRun(TARunInfo *runinfo)
TAFlowEvent * Analyze(TARunInfo *runinfo, TMEvent *event, TAFlags *flags, TAFlowEvent *flow)
void BeginRun(TARunInfo *runinfo)
ExampleRoot(TARunInfo *runinfo)
void AnalyzeSpecialEvent(TARunInfo *runinfo, TMEvent *event)
void PauseRun(TARunInfo *runinfo)