Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
JEventProcessor_EVNT_online.cc
Go to the documentation of this file.
1 // $Id$
2 //
3 // File: JEventProcessor_EVNT_online.cc
4 // Created: Fri Nov 9 11:58:09 EST 2012
5 // Creator: wolin (on Linux stan.jlab.org 2.6.32-279.11.1.el6.x86_64 x86_64)
6 
7 
8 #include <stdint.h>
9 #include <vector>
10 #include <random>
11 
12 
13 #include <DAQ/JEventSource_EVIO.h>
14 
16 #include <JANA/JApplication.h>
17 
18 
19 using namespace std;
20 using namespace jana;
21 
22 
23 // for random numbers
24 // static mt19937 generator;
25 // static normal_distribution<float> normal_dist(150.,150.);
26 
27 #include <TDirectory.h>
28 #include <TH1.h>
29 #include <TH2.h>
30 
31 
32 // root hist pointers
33 static TH1I * evntdata;
34 static TH2I * rocdata;
35 
36 
37 
38 //----------------------------------------------------------------------------------
39 
40 
41 // Routine used to create our JEventProcessor
42 extern "C"{
43  void InitPlugin(JApplication *app){
44  InitJANAPlugin(app);
45  app->AddProcessor(new JEventProcessor_EVNT_online());
46  }
47 }
48 
49 
50 //----------------------------------------------------------------------------------
51 
52 
54 }
55 
56 
57 //----------------------------------------------------------------------------------
58 
59 
61 }
62 
63 
64 //----------------------------------------------------------------------------------
65 
67 
68  // create root folder for evnt and cd to it, store main dir
69  TDirectory *main = gDirectory;
70  gDirectory->mkdir("evnt")->cd();
71 
72 
73  // book hist
74  evntdata = new TH1I("evntdata","Total data words in event",100,0,30000);
75  rocdata = new TH2I("rocdata","ROC vs data words",80,0.5,80.5,2000,0.,2000.);
76 
77 
78  // back to main dir
79  main->cd();
80 
81  return NOERROR;
82 }
83 
84 
85 //----------------------------------------------------------------------------------
86 
87 
88 jerror_t JEventProcessor_EVNT_online::brun(JEventLoop *eventLoop, int32_t runnumber) {
89  // This is called whenever the run number changes
90  return NOERROR;
91 }
92 
93 
94 //----------------------------------------------------------------------------------
95 
96 
97 jerror_t JEventProcessor_EVNT_online::evnt(JEventLoop *eventLoop, uint64_t eventnumber) {
98 
99  int nword,ntot;
100  // uint32_t *buff;
101  // uint32_t buff_size;
102 
103 
104  // Get pointer to JEventSource base class
105  JEvent &jevent = eventLoop->GetJEvent();
106  JEventSource *source = jevent.GetJEventSource();
107 
108  // Cast source to type JEventSource_EVIO. You could use a
109  // dynamic_cast here but that sometimes has problems when
110  // used through a plugin. It is also notoriously inefficient so
111  // checking a string is probably no worse.
112  if( string("JEventSource_EVIO") == source->className() ) {
113  JEventSource_EVIO *eviosource = (JEventSource_EVIO*)source;
114 
115  // Get EVIO buffer pointer and size (yes, I know, size is redundant)
116  // eviosource->GetEVIOBuffer(jevent,buff,buff_size);
117 
118  // Get evioDOMTree pointer and list of data banks
119  evioDOMTree *dom = eviosource->GetEVIODOMTree(jevent);
120  evioDOMNodeListP bankList = dom->getNodeList([](evioDOMNodeP n) {
121  return (n->tag==1)&&(n->getContentType()==0x1)&&(n->getParent()->tag>0)&&(n->getSize()>0);
122  });
123 
124  // loop over data banks and hist bank sizes, etc.
125  // FILL HISTOGRAMS
126  // Since we are filling histograms local to this plugin, it will not interfere with other ROOT operations: can use plugin-wide ROOT fill lock
127  japp->RootFillLock(this); //ACQUIRE ROOT FILL LOCK
128  ntot=0;
129  for(auto bank : *bankList.get()) {
130  nword=bank->getSize();
131  rocdata->Fill(bank->getParent()->tag,nword);
132  ntot+=nword;
133  }
134  evntdata->Fill(ntot);
135  japp->RootFillUnLock(this); //RELEASE ROOT FILL LOCK
136  }
137 
138 
139  // fake data for the moment...
140  // japp->RootFillLock(this); //ACQUIRE ROOT FILL LOCK
141  // ntot=0;
142  // for(auto roc=1; roc<=60; roc++) {
143  // nword = 25+normal_dist(generator);
144  // rochist->Fill(roc,nword);
145  // ntot+=nword;
146  // }
147  // evntsize->Fill(ntot);
148  // japp->RootFillUnLock(this); //RELEASE ROOT FILL LOCK
149 
150  return NOERROR;
151 }
152 
153 
154 //----------------------------------------------------------------------------------
155 
156 
158  // This is called whenever the run number changes, before it is
159  // changed to give you a chance to clean up before processing
160  // events from the next run number.
161  return NOERROR;
162 }
163 
164 
165 //----------------------------------------------------------------------------------
166 
167 
169  // Called before program exit after event processing is finished.
170  return NOERROR;
171 }
172 
173 
174 //----------------------------------------------------------------------------------
175 //----------------------------------------------------------------------------------
jerror_t init(void)
Called once at program start.
jerror_t erun(void)
Called everytime run number changes, provided brun has been called.
jerror_t brun(jana::JEventLoop *eventLoop, int32_t runnumber)
Called everytime a new run number is detected.
JApplication * japp
InitPlugin_t InitPlugin
static TH2I * rocdata
jerror_t fini(void)
Called after last event of last event source has been processed.
static TH1I * evntdata
The JEventSource_EVIO class implements a JEventSource capable of reading in EVIO data from raw data f...
jerror_t evnt(jana::JEventLoop *eventLoop, uint64_t eventnumber)
Called every event.
int main(int argc, char *argv[])
Definition: gendoc.cc:6