Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
JEventProcessor_CODA_online.cc
Go to the documentation of this file.
1 // $Id$
2 //
3 // File: JEventProcessor_CODA_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 // Note...user must set eventCount and dataCount in statistics_thread for monitoring purposes
8 
9 // ejw, 8-Nov-2013
10 
11 
12 // still to do:
13 
14 // need unique name
15 // set event count and data count
16 // implement Vardan's new status reporting scheme
17 // check for missing thread.join(), likely in codaObject library
18 // turn off debug
19 // is singleton the correct pattern?
20 // is unique_ptr needed since pointer to object is passed to JANA?
21 
22 
24 #include <JANA/JApplication.h>
25 
26 
27 using namespace std;
28 using namespace codaObject;
29 using namespace jana;
30 
31 
32 // for testing
33 static bool debug = true;
34 int CodaObject::debug = 1;
35 
36 
37 //----------------------------------------------------------------------------------
38 
39 
40 /**
41  * Initializes the plugin.
42  *
43  * Creates JEventProcessor/RunObject. Only called once by JANA framework.
44  */
45 extern "C" {
46  void InitPlugin(JApplication *app) {
47 
48  string UDL = "cMsg://localhost/cMsg";
49  string name = "JEventProcessor_codaObject"; // ???
50  string descr = "JEventProcessor coda object"; // ???
51  string theSession = "halldsession";
52 
53 
54  // initialize the plugin
55  InitJANAPlugin(app);
56 
57 
58  // get parameters from command line
59  gPARMS->SetDefaultParameter("CODAOBJECT:UDL", UDL, "UDL to use for connecting to cMsg server");
60  gPARMS->SetDefaultParameter("CODAOBJECT:NAME", name, "Name to use for connecting to cMsg server");
61  gPARMS->SetDefaultParameter("CODAOBJECT:DESCR", descr, "Description to use for connecting to cMsg server");
62  gPARMS->SetDefaultParameter("CODAOBJECT:SESSION", theSession, "Session name to use");
63 
64 
65  // create object, add to JANA event processor list
66  app->AddProcessor(new JEventProcessor_CODA_online(UDL,name,descr,theSession));
67 
68 
69  if(debug)jout << "leaving InitPlugin" << endl;
70  }
71 }
72 
73 
74 //----------------------------------------------------------------------------------
75 
76 
77 /**
78  * Constructor sets session, launches statistics thread, automatically starts processing and reporting.
79  */
80 JEventProcessor_CODA_online::JEventProcessor_CODA_online(const string &UDL, const string &name, const string &descr,
81  const string &theSession)
82  : RunObject(UDL,name,descr), done(false) {
83 
84 
85  // set session if specified
86  if(!theSession.empty())handleSetSession(theSession);
87 
88 
89  // launch statistics thread
91 
92 
93  // set state and status
94  changeState("active");
95  changeStatus("ok");
96 
97 
98  // start processing
99  startProcessing();
100 
101 
102  // start reporting
103  handleStartReporting(nullptr);
104 
105 
106  if(debug)jout << "leaving JEventProcessor_CODA_online constructor" << endl;
107 }
108 
109 
110 //----------------------------------------------------------------------------------
111 
112 
113 /**
114  * Destructor stops processing.
115  */
117  if(debug)jout << "in destructor" << endl;
118  done=true;
119  stopProcessing();
120 }
121 
122 
123 //-----------------------------------------------------------------------------
124 
125 
126 /**
127  * Called during configure transition.
128  */
129 bool JEventProcessor_CODA_online::userConfigure(const string& s) throw(CodaException) {
130  if(debug)jout << "in userConfigure" << endl;
131  return(true);
132 }
133 
134 
135 
136 //-----------------------------------------------------------------------------
137 
138 
139 /**
140  * Called during download transition.
141  */
142 bool JEventProcessor_CODA_online::userDownload(const string& s) throw(CodaException) {
143  if(debug)jout << "in userDownload" << endl;
144  return(true);
145 }
146 
147 
148 //-----------------------------------------------------------------------------
149 
150 
151 /**
152  * Called during prestart transition.
153  */
154 bool JEventProcessor_CODA_online::userPrestart(const string& s) throw(CodaException) {
155  if(debug)jout << "in userPrestart" << endl;
156  return(true);
157 }
158 
159 
160 //-----------------------------------------------------------------------------
161 
162 
163 /**
164  * Called during go transition.
165  */
166 bool JEventProcessor_CODA_online::userGo(const string& s) throw(CodaException) {
167  if(debug)jout << "in userGo" << endl;
168  return(true);
169 }
170 
171 
172 //-----------------------------------------------------------------------------
173 
174 
175 /**
176  * Called during pause transition.
177  */
178 bool JEventProcessor_CODA_online::userPause(const string& s) throw(CodaException) {
179  if(debug)jout << "in userPause" << endl;
180  japp->Pause();
181  return(true);
182 }
183 
184 
185 //-----------------------------------------------------------------------------
186 
187 
188 /**
189  * Called during resume transition.
190  */
191 bool JEventProcessor_CODA_online::userResume(const string& s) throw(CodaException) {
192  if(debug)jout << "in userResum" << endl;
193  japp->Resume();
194  return(true);
195 }
196 
197 
198 //-----------------------------------------------------------------------------
199 
200 
201 /**
202  * Called during end transition.
203  */
204 bool JEventProcessor_CODA_online::userEnd(const string& s) throw(CodaException) {
205  if(debug)jout << "in userEnd" << endl;
206  return(true);
207 }
208 
209 
210 //-----------------------------------------------------------------------------
211 
212 
213 /**
214  * Called during reset transition.
215  */
216 bool JEventProcessor_CODA_online::userReset(const string& s) throw(CodaException) {
217  if(debug)jout << "in userReset" << endl;
218  return(true);
219 }
220 
221 
222 //-----------------------------------------------------------------------------
223 
224 
225 /**
226  * Called when exit command received.
227  */
228 void JEventProcessor_CODA_online::exit(const string& s) throw(CodaException) {
229  if(debug)jout << "in exit" << endl;
230  done=true;
231  stopProcessing();
232  stat_thread->join();
233  japp->Quit();
234 }
235 
236 
237 //-----------------------------------------------------------------------------
238 
239 
240 /**
241  * Called when unknown message type received.
242  */
243 void JEventProcessor_CODA_online::userMsgHandler(cMsgMessage *msgp, void *userArg) throw(CodaException) {
244  unique_ptr<cMsgMessage> msg(msgp);
245  jerr << "?JEventProcessor_CODA_online...received unknown message subject,type: "
246  << msg->getSubject() << "," << msg->getType() << endl << endl;
247 }
248 
249 
250 //-----------------------------------------------------------------------------
251 
252 
253 /**
254  * fills rc/report/status message
255  *
256  * @param m message
257  */
258 void JEventProcessor_CODA_online::fillReport(cMsgMessage *m) throw() {
259  RunObject::fillReport(m);
260  m->add("test1",0);
261  m->add("test2","fred");
262 }
263 
264 
265 //-----------------------------------------------------------------------------
266 
267 
268 /**
269  * Thread in which user must set event number and data count manually, used for monitoring purposes.
270  */
272 
273  if(debug)jout << "entering JEventProcessor_CODA_online statistics_thread" << endl;
274 
275  while(!done) {
276  sleep(1);
277  eventNumber=0;
278  dataCount=0;
279  rcConn->setMonitoringString(" <test> This is a test monitoring string </test>\n");
280  }
281 }
282 
283 
284 //----------------------------------------------------------------------------------
285 
286 
288  // Called before program exit after event processing is finished.
289  return NOERROR;
290 }
291 
292 
293 //-------------------------------------------------------------------------------
294 // end class definition
295 //----------------------------------------------------------------------------------
virtual bool userPrestart(const string &s) override
virtual bool userGo(const string &s) override
virtual bool userEnd(const string &s) override
JEventProcessor_CODA_online(void)=delete
virtual const void statistics_thread(void)
static bool debug
JApplication * japp
InitPlugin_t InitPlugin
virtual bool userResume(const string &s) override
virtual bool userConfigure(const string &s) override
virtual void userMsgHandler(cMsgMessage *msgp, void *userArg) override
virtual bool userReset(const string &s) override
virtual void exit(const string &s) override
virtual bool userDownload(const string &s) override
virtual bool userPause(const string &s) override