Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
JEventSource_EVIO.h
Go to the documentation of this file.
1 // $Id$
2 // $HeadURL$
3 //
4 // File: JEventSource_EVIO.h
5 // Created: Tue Aug 7 15:22:29 EDT 2012
6 // Creator: davidl (on Darwin harriet.jlab.org 11.4.0 i386)
7 //
8 
9 #ifndef _JEventSource_EVIO_
10 #define _JEventSource_EVIO_
11 
12 
13 #include <map>
14 #include <vector>
15 #include <queue>
16 #include <deque>
17 #include <list>
18 #include <set>
19 using std::map;
20 using std::vector;
21 using std::queue;
22 using std::set;
23 
24 #include <JANA/jerror.h>
25 #include <JANA/JEventSource.h>
26 #include <JANA/JEvent.h>
27 #include <JANA/JFactory.h>
28 #include <JANA/JStreamLog.h>
29 using namespace jana;
30 
31 #include "HDEVIO.h"
32 
33 #ifdef HAVE_EVIO
34 //#include <evioChannel.hxx>
35 #include <evioUtil.hxx>
36 using namespace evio;
37 #else
38 class evioDOMTree;
39 typedef pair<int,int> tagNum;
40 #endif // HAVE_EVIO
41 
42 #ifdef HAVE_ET
43 //#include <evioETChannel.hxx>
44 #include <et.h>
45 #endif // HAVE_ET
46 
47 #include "daq_param_type.h"
48 #include "DModuleType.h"
49 #include "Df250Config.h"
50 #include "Df250PulseIntegral.h"
51 #include "Df250StreamingRawData.h"
52 #include "Df250WindowSum.h"
53 #include "Df250PulseRawData.h"
54 #include "Df250TriggerTime.h"
55 #include "Df250PulseTime.h"
56 #include "Df250PulsePedestal.h"
57 #include "Df250WindowRawData.h"
58 #include "Df125Config.h"
59 #include "Df125TriggerTime.h"
60 #include "Df125PulseIntegral.h"
61 #include "Df125PulseTime.h"
62 #include "Df125PulsePedestal.h"
63 #include "Df125PulseRawData.h"
64 #include "Df125WindowRawData.h"
65 #include "Df125CDCPulse.h"
66 #include "Df125FDCPulse.h"
67 #include "DF1TDCConfig.h"
68 #include "DF1TDCHit.h"
69 #include "DF1TDCTriggerTime.h"
70 #include "DCAEN1290TDCConfig.h"
71 #include "DCAEN1290TDCHit.h"
72 #include "DCODAEventInfo.h"
73 #include "DCODAROCInfo.h"
74 #include "DTSscalers.h"
75 #include "DEPICSvalue.h"
76 #include "DEventTag.h"
77 #include "Df250BORConfig.h"
78 #include "Df125BORConfig.h"
79 #include "DF1TDCBORConfig.h"
80 #include "DCAEN1290TDCBORConfig.h"
81 #include "DL1Info.h"
82 #include "Df250Scaler.h"
83 #include "Df250AsyncPedestal.h"
84 
85 #include "Df125EmulatorAlgorithm.h"
86 #include "Df250EmulatorAlgorithm.h"
87 
88 #include <PID/DVertex.h>
89 
90 extern set<uint32_t> ROCIDS_TO_PARSE;
91 
92 
93 //-----------------------------------------------------------------------
94 /// The JEventSource_EVIO class implements a JEventSource capable of reading in
95 /// EVIO data from raw data files produced in Hall-D. It can read in entangled
96 /// (or blocked) events as well as single events. The low-level objects produced
97 /// reflect the data generated by the front end digitization electronics.
98 ///
99 /// The type of boards it can understand can be expanded to include additional
100 /// boards. To do this, files must be edited in a few places:
101 ///
102 /// In DModuleType.h
103 /// ------------------
104 /// 1.) The new module type must be added to the type_id_t enum.
105 /// Make sure "N_MODULE_TYPES" is the last item in the enum.
106 ///
107 /// 2.) Add a case for the module type to the switch in the
108 /// GetModule method.
109 ///
110 ///
111 /// Create Data Object files
112 /// -------------------------
113 ///
114 /// 1.) For each type of data produced by the new module, create
115 /// a class to represent it. It is highly recommended to use
116 /// a naming scheme that reflects the naming convention used
117 /// in the manual. This makes it easier for people trying to
118 /// understand the low-level data objects in terms of the
119 /// manual for the module. See Df250WindowSum.h or
120 /// Df250PulseIntegral.h for examples.
121 ///
122 ///
123 /// JEventSource_EVIO.h
124 /// -------------------
125 /// 1.) Add an appropriate #include near the top of the file for
126 /// each type of data object created in the previous step.
127 ///
128 /// 2.) Add an appropriate declaration for a "ParseXXXBank"
129 /// where the "XXX" is the new module type.
130 /// example:
131 /// void ParseF1TDCBank(evioDOMNodeP bankPtr, list<ObjList*> &events);
132 ///
133 /// 3.) If the routine JFactory_base_CopyTo() still exists at the
134 /// bottom of this file, then add a line for each data type to it.
135 ///
136 ///
137 /// JEventSource_EVIO.cc
138 /// --------------------
139 /// 1.) In the JEventSource_EVIO::JEventSource_EVIO() constructor,
140 /// add a line to insert the data type into event_source_data_types
141 /// for each data type the module produces.
142 ///
143 /// 2.) In the "ParseEVIOEvent()" method, add a case for the
144 /// new module type that calls the new "ParseXXXBank()"
145 /// method. (Note if this is JLab module, then you'll
146 /// need to add a case to ParseJLabModuleData() ).
147 ///
148 /// 3.) Add the new ParseXXXBank() method. Preferrably to the
149 /// end of the file or more importantly, in the order the
150 /// method appears in the class definition.
151 ///
152 ///
153 /// JFactoryGenerator_DAQ.h
154 /// --------------------
155 /// 1.) Add an include line to the top of the file for each new
156 /// data type.
157 ///
158 /// 2.) Add a line for each new data type to the GenerateFactories()
159 /// method of JFactoryGenerator_DAQ.
160 ///
161 ///----------------------------------------------------------------------
162 
163 class JEventSource_EVIO: public jana::JEventSource{
164  public:
165 
169  kETSource
170  };
171 
175  kEmulationAuto
176  };
177 
178 
179  JEventSource_EVIO(const char* source_name);
180  virtual ~JEventSource_EVIO();
181  virtual const char* className(void){return static_className();}
182  static const char* static_className(void){return "JEventSource_EVIO";}
183 
184  jerror_t GetEvent(jana::JEvent &event);
185  void FreeEvent(jana::JEvent &event);
186  jerror_t GetObjects(jana::JEvent &event, jana::JFactory_base *factory);
187 
189 
190  inline double GetTime(void);
191  void ReadOptionalModuleTypeTranslation(void);
192  uint32_t* GetPoolBuffer(void);
193  virtual jerror_t ReadEVIOEvent(uint32_t* &buf);
194  inline void GetEVIOBuffer(jana::JEvent &jevent, uint32_t* &buff, uint32_t &size) const;
195  EVIOSourceType GetEVIOSourceType(void){ return source_type; }
196  void AddROCIDtoParseList(uint32_t rocid){ ROCIDS_TO_PARSE.insert(rocid); }
197  set<uint32_t> GetROCIDParseList(uint32_t rocid){ return ROCIDS_TO_PARSE; }
198  static uint32_t* GetEVIOBufferFromRef(void *ref){ return ((ObjList*)ref)->eviobuff; }
199  static uint32_t GetEVIOBufferSizeFromRef(void *ref){ return ((ObjList*)ref)->eviobuff_size; }
200  static double GetEVIOReadTimeFromRef(void *ref){ return ((ObjList*)ref)->time_evio_read; }
201  static double GetDomTreeCreationTimeFromRef(void *ref){ return ((ObjList*)ref)->time_dom_tree; }
202  static double GetEVIOParseTimeFromRef(void *ref){ return ((ObjList*)ref)->time_evio_parse; }
203 
204 #ifdef HAVE_EVIO
205  inline evioDOMTree* GetEVIODOMTree(jana::JEvent &jevent) const;
206 #endif // HAVE_EVIO
207 
208  protected:
209 
210  void ConnectToET(const char* source_name);
211  void Cleanup(void);
212 
215 
216  uint32_t Nunparsed;
219  //evioChannel *chan;
222  map<tagNum, MODULE_TYPE> module_type;
223  map<MODULE_TYPE, MODULE_TYPE> modtype_translate;
224 
225  JStreamLog evioout;
226 
235  bool PARSE_BOR;
244  int VERBOSE;
245  float TIMEOUT;
249  string EVENT_MASK;
250 
251  EmulationModeType F125_EMULATION_MODE; ///< F125 emulation mode
252  EmulationModeType F250_EMULATION_MODE; ///< F250 emulation mode
253 
254  uint32_t F250_EMULATION_MIN_SWING; ///< Minimum difference between max and min samples to do emulation
255  uint32_t F250_THRESHOLD; ///< Threshold to use for firmware emulation
256  uint32_t F250_SPARSIFICATION_THRESHOLD; ///< Sparsification thresh. applied to non-ped-subtracted integral during emulation
257  uint32_t F250_NSA; ///< Number of samples to integrate after threshold crossing during emulation
258  uint32_t F250_NSB; ///< Number of samples to integrate before threshold crossing during emulation
259  uint32_t F250_NSPED; ///< Number of samples to integrate for pedestal during emulation
260 
261  uint32_t F125_EMULATION_MIN_SWING; ///< Minimum difference between max and min samples to do emulation
262  uint32_t F125_THRESHOLD; ///< Threshold to use for firmware emulation
263  uint32_t F125_SPARSIFICATION_THRESHOLD; ///< Sparsification thresh. applied to non-ped-subtracted integral during emulation
264  uint32_t F125_NSA; ///< Number of samples to integrate after threshold crossing during emulation
265  uint32_t F125_NSB; ///< Number of samples to integrate before threshold crossing during emulation
266  uint32_t F125_NSA_CDC; ///< Number of samples to integrate after thershold crossing during emulation rocid 24-28 only!
267  uint32_t F125_NSB_CDC; ///< Number of samples to integrate before thershold crossing during emulation rocid 24-28 only!
268  uint32_t F125_NSPED; ///< Number of samples to integrate for pedestal during emulation
269  uint32_t F125_TIME_UPSAMPLE; ///< Use the CMU upsampling algorithm when emulating f125 pulse times
270 
271 
272  uint32_t F125_CDC_WS; ///< FA125 emulation CDC hit window start
273  uint32_t F125_CDC_WE; ///< FA125 emulation CDC hit window end
274  uint32_t F125_CDC_IE; ///< FA125 emulation CDC number of integrated samples (unless WE is reached)
275  uint32_t F125_CDC_NP; ///< FA125 emulation CDC initial pedestal samples
276  uint32_t F125_CDC_NP2; ///< FA125 emulation CDC local pedestal samples
277  uint32_t F125_CDC_PG; ///< FA125 emulation CDC gap between pedestal and hit threshold crossing
278  uint32_t F125_CDC_H; ///< FA125 emulation CDC hit threshold
279  uint32_t F125_CDC_TH; ///< FA125 emulation CDC high timing threshold
280  uint32_t F125_CDC_TL; ///< FA125 emulation CDC low timing threshold
281 
282  uint32_t F125_FDC_WS; ///< FA125 emulation FDC hit window start
283  uint32_t F125_FDC_WE; ///< FA125 emulation FDC hit window end
284  uint32_t F125_FDC_IE; ///< FA125 emulation FDC number of integrated samples (unless WE is reached)
285  uint32_t F125_FDC_NP; ///< FA125 emulation FDC initial pedestal samples
286  uint32_t F125_FDC_NP2; ///< FA125 emulation FDC local pedestal samples
287  uint32_t F125_FDC_PG; ///< FA125 emulation FDC gap between pedestal and hit threshold crossing
288  uint32_t F125_FDC_H; ///< FA125 emulation FDC hit threshold
289  uint32_t F125_FDC_TH; ///< FA125 emulation FDC high timing threshold
290  uint32_t F125_FDC_TL; ///< FA125 emulation FDC low timing threshold
291 
292 
293 
294  uint32_t USER_RUN_NUMBER; ///< Run number supplied by user
295  uint32_t F125PULSE_NUMBER_FILTER; ///< Discard DF125PulseXXX objects with pulse number equal or greater than this
296  uint32_t F250PULSE_NUMBER_FILTER; ///< Discard DF250PulseXXX objects with pulse number equal or greater than this
297 
298  // Utility class with multiple roles:
299  //
300  // First is to hold pointers to input EVIO buffer and
301  // the evioDOMTree made out of it. When an event is
302  // first read in, the buffer pointer is set, but the
303  // DOM tree is not made until either GetObjects or
304  // FreeEvent are called. In the case of multiple physics
305  // events in a single DAQ event, the buffer pointer
306  // and DOM tree pointers will be NULL.
307  //
308  // Second is to hold pointers to containers for
309  // all types of data objects we produce. This gets passed
310  // into bank processor methods so that they can append
311  // to the lists. Note that the naming scheme here needs to
312  // include the exact name of the class with a "v" in front
313  // and an "s" in back. (See #define in JEventSource_EVIO.cc
314  // for more details.)
315  vector< vector<DDAQAddress*> > hit_objs;
316  class ObjList{
317  public:
318 
319  ObjList():run_number(0),own_objects(true),eviobuff_parsed(false)
320  ,eviobuff(NULL),eviobuff_size(0),DOMTree(NULL)
321  ,time_evio_read(0),time_dom_tree(0),time_evio_parse(0){}
322 
323  int32_t run_number;
324  uint64_t event_number;
325  bool own_objects; // keeps track of whether these objects were copied to factories or not
326 
327  vector<DDAQAddress*> hit_objs;
328  vector<DDAQConfig*> config_objs;
329  vector<JObject*> misc_objs;
330 
331  bool eviobuff_parsed; // flag used to keep track of whether this buffer has been parsed
332  uint32_t *eviobuff; // Only holds original EVIO event buffer
333  uint32_t eviobuff_size; // size of eviobuff in bytes
334  evioDOMTree *DOMTree; // DOM tree which may be modified before generating output buffer from it
338  };
339 
340  // EVIO events with more than one DAQ event ("blocked" or
341  // "entangled" events") are parsed and have the events
342  // stored in the following container so they can be dispensed
343  // as needed.
344  pthread_mutex_t stored_events_mutex;
345  queue<ObjList*> stored_events;
346 
347  // We need to keep the EVIO buffers around for events since they
348  // may be needed again before we are done with the event (especially
349  // for L3). It is more efficient to maintain a pool of such events
350  // and recycle them.
351  uint32_t BUFFER_SIZE;
352  pthread_mutex_t evio_buffer_pool_mutex;
353  deque<uint32_t*> evio_buffer_pool;
354 
355  // In order to efficiently free memory after this source has
356  // exhausted it's event supply, the last calls to FreeEvent
357  // must be able to recognize itself as such. Use the
358  // current_event_count counter to keep track of how many events
359  // are currently being processed by processing threads.
360  pthread_mutex_t current_event_count_mutex;
362 
363  // List of the data types this event source can provide
364  // (filled in the constructor)
366 
367  // BOR events must be kept around untill another BOR event is
368  // encountered. To make things simpler, a copy of all BOR objects
369  // is made for each event. The originals are replaced when new
370  // ones come in.
371  pthread_rwlock_t BOR_lock;
372  vector<JObject*> BORobjs;
373 
374  void CopyBOR(JEventLoop *loop, map<string, vector<JObject*> > &hit_objs_by_type);
375  void AddSourceObjectsToCallStack(JEventLoop *loop, string className);
376  void AddEmulatedObjectsToCallStack(JEventLoop *loop, string caller, string callee);
377  void EmulateDf250Firmware(JEvent &event, vector<JObject*> &wrd_objs, vector<JObject*> &pt_objs, vector<JObject*> &pp_objs, vector<JObject*> &pi_objs);
378  void EmulateDf125Firmware(JEvent &event, vector<JObject*> &wrd_objs, vector<JObject*> &cp_objs, vector<JObject*> &fp_objs);
379 
380  jerror_t ParseEvents(ObjList *objs_ptr);
381  int32_t FindRunNumber(uint32_t *iptr);
382  int32_t EpicQuestForRunNumber(void);
383  uint64_t FindEventNumber(uint32_t *iptr);
384  void FindEventType(uint32_t *iptr, JEvent &event);
385  MODULE_TYPE GuessModuleType(const uint32_t *istart, const uint32_t *iend);
386  bool IsF250ADC(const uint32_t *istart, const uint32_t *iend);
387  bool IsF1TDC(const uint32_t *istart, const uint32_t *iend);
388  void DumpModuleMap(void){}
389  void DumpBinary(const uint32_t *iptr, const uint32_t *iend=NULL, uint32_t MaxWords=0, const uint32_t *imark=NULL);
390 
391  void MergeObjLists(list<ObjList*> &events1, list<ObjList*> &events2);
392 
393 #if HAVE_EVIO
394  int32_t GetRunNumber(evioDOMTree *evt);
395  void ParseEVIOEvent(evioDOMTree *evt, list<ObjList*> &full_events);
396  void ParseBuiltTriggerBank(evioDOMNodeP trigbank, list<ObjList*> &tmp_events);
397  void ParseBORevent(evioDOMNodeP bankPtr);
398  void ParseEPICSevent(evioDOMNodeP bankPtr, list<ObjList*> &events);
399 #endif // HAVE_EVIO
400  void ParseModuleConfiguration(int32_t rocid, const uint32_t* &iptr, const uint32_t *iend, list<ObjList*> &events);
401  void ParseEventTag(const uint32_t* &iptr, const uint32_t *iend, list<ObjList*> &events);
402  void ParseJLabModuleData(int32_t rocid, const uint32_t* &iptr, const uint32_t *iend, list<ObjList*> &events);
403  void Parsef250Bank(int32_t rocid, const uint32_t* &iptr, const uint32_t *iend, list<ObjList*> &events);
404  void Parsef125Bank(int32_t rocid, const uint32_t* &iptr, const uint32_t *iend, list<ObjList*> &events);
405  void ParseF1TDCBank(int32_t rocid, const uint32_t* &iptr, const uint32_t *iend, list<ObjList*> &events);
406  uint32_t F1TDC_channel(uint32_t chip, uint32_t chan_on_chip, int modtype);
407  void ParseTSBank(int32_t rocid, const uint32_t* &iptr, const uint32_t *iend, list<ObjList*> &events);
408  void ParseTIBank(int32_t rocid, const uint32_t* &iptr, const uint32_t *iend, list<ObjList*> &events);
409  void ParseCAEN1190(int32_t rocid, const uint32_t* &iptr, const uint32_t *iend, list<ObjList*> &events);
410 
411 
412  // f250 methods
413  void MakeDf250WindowRawData(ObjList *objs, uint32_t rocid, uint32_t slot, uint32_t itrigger, const uint32_t* &iptr);
414  void MakeDf250PulseRawData(ObjList *objs, uint32_t rocid, uint32_t slot, uint32_t itrigger, const uint32_t* &iptr);
415  void MakeDf125WindowRawData(ObjList *objs, uint32_t rocid, uint32_t slot, uint32_t itrigger, const uint32_t* &iptr);
416  void MakeDf125PulseRawData(ObjList *objs, uint32_t rocid, uint32_t slot, uint32_t itrigger, const uint32_t* &iptr);
417 
418 #if HAVE_EVIO
419  void ParseTSSync(evioDOMNodeP bankPtr, list<ObjList*> &events);
420  void ParseDVertexBank(evioDOMNodeP bankPtr, list<ObjList*> &events);
421 
422  void ParseFA250Scalers(evioDOMNodeP bankPtr, list<ObjList*> &events, uint32_t rocid);
423  void ParseFA250AsyncPedestals(evioDOMNodeP bankPtr, list<ObjList*> &events, uint32_t rocid);
424 #endif // HAVE_EVIO
425 
426 
427 #ifdef HAVE_ET
428  et_sys_id sys_id;
429  et_att_id att_id;
430  et_stat_id sta_id;
431 #endif
432 };
433 
434 
435 
436 
437 //======================================================================================
438 // Some of the following methods are inlined so that
439 // they can be used by programs that only have access
440 // to this header at link time. (This class is normally
441 // compiled into a plugin so there is no library file
442 // available to link to.)
443 //
444 // There are also some templates that are used to make
445 // some of the code in the implmentation file cleaner.
446 //======================================================================================
447 
448 //----------------
449 // GetTime
450 //----------------
452 {
453  struct timeval tval;
454  struct timezone tzone;
455  gettimeofday(&tval, &tzone);
456  double t = (double)tval.tv_sec+(double)tval.tv_usec/1.0E6;
457  return t;
458 }
459 
460 //----------------
461 // GetEVIOBuffer
462 //----------------
463 void JEventSource_EVIO::GetEVIOBuffer(jana::JEvent &jevent, uint32_t* &buff, uint32_t &size) const
464 {
465  /// Use the reference stored in the supplied JEvent to extract the evio
466  /// buffer and size for the event. If there is no buffer for the event
467  /// then buff will be set to NULL and size to zero. This can happen if
468  /// reading entangled events and this is not the first event in the block.
469 
470  // In case we bail early
471  buff = NULL;
472  size = 0;
473 
474  // Make sure this JEvent actually came from this source
475  if(jevent.GetJEventSource() != this){
476  jerr<<" ERROR: Attempting to get EVIO buffer for event not produced by this source!!"<<endl;
477  return;
478  }
479 
480  // Get pointer to ObjList object
481  const ObjList *objs_ptr = (ObjList*)jevent.GetRef();
482  if(!objs_ptr) return;
483 
484  // Copy buffer pointer and size to user's variables
485  buff = objs_ptr->eviobuff;
486  size = objs_ptr->eviobuff_size;
487 }
488 
489 #ifdef HAVE_EVIO
490 
491 //----------------
492 // GetEVIODOMTree
493 //----------------
494 evioDOMTree* JEventSource_EVIO::GetEVIODOMTree(jana::JEvent &jevent) const
495 {
496  /// Use the reference stored in the supplied JEvent to extract the evio
497  /// DOM tree for the event. If there is no DOM tree for the event
498  /// then NULL will be returned. This can happen if reading entangled events
499  /// and this is not the first event in the block.
500 
501  // Make sure this JEvent actually came from this source
502  if(jevent.GetJEventSource() != this){
503  jerr<<" ERROR: Attempting to get EVIO buffer for event not produced by this source!!"<<endl;
504  return NULL;
505  }
506 
507  // Get pointer to ObjList object
508  const ObjList *objs_ptr = (ObjList*)jevent.GetRef();
509  if(!objs_ptr) return NULL;
510 
511  return objs_ptr->DOMTree;
512 }
513 #endif // HAVE_EVIO
514 
515 
516 ////----------------------------------------------------------------------
517 ///// JFactory_base_CopyToT and JFactory_base_CopyTo
518 /////
519 ///// A Mantis request has been submitted to add a virtual method to
520 ///// JFactory_base that takes a vector<JObject*>& with an overload
521 ///// of that method in the JFactory<T> subclass. The JFactory<T> method
522 ///// will then try to dynamically cast each JObject* into the appropriate
523 ///// type and store it in the factory. When that is working, these two
524 ///// routines will not be required here.
525 /////
526 ///// In the meantime, this serves as a placeholder that can be easily
527 ///// converted once JANA has been updated.
528 ////----------------------------------------------------------------------
529 //template<class T>
530 //bool JFactory_base_CopyToT(jana::JFactory_base *fac, vector<jana::JObject *>& objs)
531 //{
532 // // Try casting this factory to the desired type of JFactory<>
533 // jana::JFactory<T> *tfac = dynamic_cast<jana::JFactory<T>* >(fac);
534 // if(!tfac) return false;
535 //
536 // // Factory cast worked. Cast all pointers
537 // vector<T*> tobjs;
538 // for(unsigned int i=0; i<objs.size(); i++){
539 // T *tobj = dynamic_cast<T*>(objs[i]);
540 // if(tobj) tobjs.push_back(tobj);
541 // }
542 //
543 // // If all input objects weren't converted, then just return false
544 // if(tobjs.size() != objs.size()) return false;
545 //
546 // // Copy pointers into factory
547 // if(tobjs.size()>0) tfac->CopyTo(tobjs);
548 // return true;
549 //}
550 //
551 ////----------------------------
552 //// JFactory_base_CopyTo
553 ////----------------------------
554 //static bool JFactory_base_CopyTo(jana::JFactory_base *fac, vector<jana::JObject *>& objs)
555 //{
556 // // Eventually, this will be a virtual method of JFactory_base
557 // // that gets implemented in JFactory<T> which will know how
558 // // to cast the objects. For now though, we have to try all known
559 // // data types.
560 // if( JFactory_base_CopyToT<Df250PulseIntegral>(fac, objs) ) return true;
561 // if( JFactory_base_CopyToT<Df250StreamingRawData>(fac, objs) ) return true;
562 // if( JFactory_base_CopyToT<Df250WindowSum>(fac, objs) ) return true;
563 // if( JFactory_base_CopyToT<Df250PulseRawData>(fac, objs) ) return true;
564 // if( JFactory_base_CopyToT<Df250TriggerTime>(fac, objs) ) return true;
565 // if( JFactory_base_CopyToT<Df250PulseTime>(fac, objs) ) return true;
566 // if( JFactory_base_CopyToT<Df250WindowRawData>(fac, objs) ) return true;
567 // if( JFactory_base_CopyToT<Df125PulseIntegral>(fac, objs) ) return true;
568 // if( JFactory_base_CopyToT<Df125TriggerTime>(fac, objs) ) return true;
569 // if( JFactory_base_CopyToT<Df125PulseTime>(fac, objs) ) return true;
570 // if( JFactory_base_CopyToT<DF1TDCHit>(fac, objs) ) return true;
571 // if( JFactory_base_CopyToT<DF1TDCTriggerTime>(fac, objs) ) return true;
572 //
573 // return false;
574 //}
575 
576 //----------------------------
577 // AddIfAppropriate
578 //----------------------------
579 template<class T>
580 void AddIfAppropriate(DDAQAddress *obj, vector<T*> &v)
581 {
582  T *t = dynamic_cast<T*>(obj);
583  if(t!= NULL) v.push_back(t);
584 }
585 
586 //----------------------------
587 // LinkAssociationsWithPulseNumber
588 //----------------------------
589 template<class T, class U>
590 void LinkAssociationsWithPulseNumber(vector<T*> &a, vector<U*> &b)
591 {
592  /// Template routine to loop over two vectors of pointers to
593  /// objects derived from DDAQAddress. This will find any hits
594  /// coming from the same DAQ channel and add each to the other's
595  /// AssociatedObjects list. This will also check if the member
596  /// "pulse_number" is the same (use LinkAssociations to not check
597  /// the pulse_number such as when either "T" or "U" does not have
598  /// a member named "pulse_number".)
599  for(unsigned int j=0; j<a.size(); j++){
600  for(unsigned int k=0; k<b.size(); k++){
601  if(a[j]->pulse_number != b[k]->pulse_number) continue;
602  if(*a[j] == *b[k]){ // compare only the DDAQAddress parts
603  a[j]->AddAssociatedObject(b[k]);
604  b[k]->AddAssociatedObject(a[j]);
605  }
606  }
607  }
608 }
609 
610 //----------------------------
611 // LinkAssociations
612 //----------------------------
613 template<class T, class U>
614 void LinkAssociations(vector<T*> &a, vector<U*> &b)
615 {
616  /// Template routine to loop over two vectors of pointers to
617  /// objects derived from DDAQAddress. This will find any hits
618  /// coming from the same DAQ channel and add each to the other's
619  /// AssociatedObjects list. This will NOT check if the member
620  /// "pulse_number" is the same (use LinkAssociationsWithPulseNumber
621  /// for that.)
622  for(unsigned int j=0; j<a.size(); j++){
623  for(unsigned int k=0; k<b.size(); k++){
624  if( *((DDAQAddress*)a[j]) == *((DDAQAddress*)b[k]) ){ // compare only the DDAQAddress parts
625  a[j]->AddAssociatedObject(b[k]);
626  b[k]->AddAssociatedObject(a[j]);
627  }
628  }
629  }
630 }
631 
632 //----------------------------
633 // LinkAssociationsModuleOnly
634 //----------------------------
635 template<class T, class U>
636 void LinkAssociationsModuleOnly(vector<T*> &a, vector<U*> &b)
637 {
638  /// Template routine to loop over two vectors of pointers to
639  /// objects derived from DDAQAddress. This will find any hits
640  /// coming from the same DAQ module (channel number is not checked)
641  /// When a match is found, the pointer from "a" will be added
642  /// to "b"'s AssociatedObjects list. This will NOT do the inverse
643  /// of adding "b" to "a"'s list. It is intended for adding a module
644  /// level trigger time object to all hits from that module. Adding
645  /// all of the hits to the trigger time object seems like it would
646  /// be a little expensive with no real use case.
647  for(unsigned int j=0; j<a.size(); j++){
648  for(unsigned int k=0; k<b.size(); k++){
649  if(a[j]->rocid != b[k]->rocid) continue;
650  if(a[j]->slot != b[k]->slot) continue;
651 
652  b[k]->AddAssociatedObject(a[j]);
653  }
654  }
655 }
656 
657 //----------------------------
658 // LinkAssociationsModuleOnlyWithCast
659 //----------------------------
660 template<class T, class U>
661 void LinkAssociationsModuleOnlyWithCast(vector<JObject*> &a, vector<JObject*> &b)
662 {
663  /// Template routine to loop over two vectors of pointers to
664  /// JObjects derived from classes T and U. Both T and U must have
665  /// "rocid" and "slot" members. It is also assumed that all JObjects
666  /// in "a" are really of type "T" and that all objects in "b" are really
667  /// of type "U".
668  /// When a match is found, the pointer from "a" will be added
669  /// to "b"'s AssociatedObjects list. This will NOT do the inverse
670  /// of adding "b" to "a"'s list. It is intended for associating
671  /// BOR config objects with hit objects.
672  for(unsigned int j=0; j<a.size(); j++){
673  T *t = (T*)a[j];
674  for(unsigned int k=0; k<b.size(); k++){
675  U *u = (U*)b[k];
676  if(t->rocid != u->rocid) continue;
677  if(t->slot != u->slot) continue;
678 
679  u->AddAssociatedObject(t);
680  }
681  }
682 }
683 
684 //----------------------------
685 // LinkAssociationsROCIDOnly
686 //----------------------------
687 template<class T, class U>
688 void LinkAssociationsROCIDOnly(vector<T*> &a, vector<U*> &b)
689 {
690  /// Template routine to loop over two vectors of pointers to
691  /// objects derived from DDAQAddress. This will find any hits
692  /// coming from the same DAQ module (channel number is not checked)
693  /// When a match is found, the pointer from "a" will be added
694  /// to "b"'s AssociatedObjects list. This will NOT do the inverse
695  /// of adding "b" to "a"'s list. It is intended for adding a module
696  /// level trigger time object to all hits from that module. Adding
697  /// all of the hits to the trigger time object seems like it would
698  /// be a little expensive with no real use case.
699  for(unsigned int j=0; j<a.size(); j++){
700  for(unsigned int k=0; k<b.size(); k++){
701  if(a[j]->rocid != b[k]->rocid) continue;
702 
703  b[k]->AddAssociatedObject(a[j]);
704  }
705  }
706 }
707 
708 //----------------------------
709 // CopyContainerElementsWithCast
710 //----------------------------
711 template<class T, class U>
712 void CopyContainerElementsWithCast(vector<T*> &a, vector<U*> &b)
713 {
714  /// This is used to copy pointers from a vector of one type of
715  /// pointer to a vector of another type, doing a static cast
716  /// in the process. For example, to fill a vector<JObject*> a
717  /// from a vector<Df250PulseIntegral*> b, call:
718  ///
719  /// CopyContainerElementsWithCast(b, a);
720  ///
721  /// Note that this does not do any dynamic_cast-ing to ensure
722  /// that the objects really are of compatible types. So be
723  /// cautious.
724 
725  for(uint32_t i=0; i<a.size(); i++){
726  b.push_back((U*)a[i]);
727  }
728 }
729 
730 
731 
732 #endif // _JEventSourceGenerator_DAQ_
733 
set< uint32_t > GetROCIDParseList(uint32_t rocid)
uint32_t F125_FDC_WS
FA125 emulation FDC hit window start.
uint32_t F125_CDC_H
FA125 emulation CDC hit threshold.
EVIOSourceType source_type
EmulationModeType F125_EMULATION_MODE
F125 emulation mode.
uint32_t F125_NSA_CDC
Number of samples to integrate after thershold crossing during emulation rocid 24-28 only! ...
map< tagNum, MODULE_TYPE > module_type
map< MODULE_TYPE, MODULE_TYPE > modtype_translate
EmulationModeType F250_EMULATION_MODE
F250 emulation mode.
pthread_mutex_t current_event_count_mutex
void GetEVIOBuffer(jana::JEvent &jevent, uint32_t *&buff, uint32_t &size) const
uint32_t F250_EMULATION_MIN_SWING
Minimum difference between max and min samples to do emulation.
void LinkAssociationsWithPulseNumber(vector< T * > &a, vector< U * > &b)
pthread_rwlock_t BOR_lock
EVIOSourceType GetEVIOSourceType(void)
void LinkAssociationsROCIDOnly(vector< T * > &a, vector< U * > &b)
uint32_t USER_RUN_NUMBER
Run number supplied by user.
vector< JObject * > BORobjs
uint32_t F250_THRESHOLD
Threshold to use for firmware emulation.
void AddROCIDtoParseList(uint32_t rocid)
uint32_t F125_FDC_NP
FA125 emulation FDC initial pedestal samples.
pthread_mutex_t evio_buffer_pool_mutex
static const char * static_className(void)
pair< int, int > tagNum
uint32_t F125_CDC_NP
FA125 emulation CDC initial pedestal samples.
static double GetEVIOReadTimeFromRef(void *ref)
uint32_t F125_NSB
Number of samples to integrate before threshold crossing during emulation.
uint32_t F125_SPARSIFICATION_THRESHOLD
Sparsification thresh. applied to non-ped-subtracted integral during emulation.
vector< DDAQConfig * > config_objs
uint32_t F125_THRESHOLD
Threshold to use for firmware emulation.
uint32_t F125_EMULATION_MIN_SWING
Minimum difference between max and min samples to do emulation.
static uint32_t GetEVIOBufferSizeFromRef(void *ref)
vector< JObject * > misc_objs
uint32_t F125_FDC_TL
FA125 emulation FDC low timing threshold.
uint32_t F125_NSA
Number of samples to integrate after threshold crossing during emulation.
void LinkAssociations(vector< T * > &a, vector< U * > &b)
uint32_t F125_CDC_TL
FA125 emulation CDC low timing threshold.
void LinkAssociationsModuleOnly(vector< T * > &a, vector< U * > &b)
uint32_t F125PULSE_NUMBER_FILTER
Discard DF125PulseXXX objects with pulse number equal or greater than this.
static double GetDomTreeCreationTimeFromRef(void *ref)
void LinkAssociationsModuleOnlyWithCast(vector< JObject * > &a, vector< JObject * > &b)
static double GetEVIOParseTimeFromRef(void *ref)
uint32_t F125_FDC_IE
FA125 emulation FDC number of integrated samples (unless WE is reached)
uint32_t F250_NSPED
Number of samples to integrate for pedestal during emulation.
pthread_mutex_t stored_events_mutex
uint32_t F125_CDC_WS
FA125 emulation CDC hit window start.
uint64_t FindEventNumber(evioDOMTree *evt, uint64_t &block_size)
uint32_t F125_NSPED
Number of samples to integrate for pedestal during emulation.
set< string > event_source_data_types
uint32_t F250_SPARSIFICATION_THRESHOLD
Sparsification thresh. applied to non-ped-subtracted integral during emulation.
vector< DDAQAddress * > hit_objs
uint32_t F125_CDC_PG
FA125 emulation CDC gap between pedestal and hit threshold crossing.
Definition: HDEVIO.h:45
uint32_t F125_FDC_NP2
FA125 emulation FDC local pedestal samples.
uint32_t F125_CDC_WE
FA125 emulation CDC hit window end.
uint32_t F125_FDC_WE
FA125 emulation FDC hit window end.
uint32_t F125_FDC_PG
FA125 emulation FDC gap between pedestal and hit threshold crossing.
uint32_t F125_FDC_H
FA125 emulation FDC hit threshold.
virtual const char * className(void)
deque< uint32_t * > evio_buffer_pool
This class holds the Crate, Slot, Channel address for a digitized value from the DAQ system...
Definition: DDAQAddress.h:26
uint32_t F125_CDC_NP2
FA125 emulation CDC local pedestal samples.
uint32_t F250_NSA
Number of samples to integrate after threshold crossing during emulation.
uint32_t F250_NSB
Number of samples to integrate before threshold crossing during emulation.
uint32_t F250PULSE_NUMBER_FILTER
Discard DF250PulseXXX objects with pulse number equal or greater than this.
uint32_t F125_CDC_IE
FA125 emulation CDC number of integrated samples (unless WE is reached)
vector< vector< DDAQAddress * > > hit_objs
queue< ObjList * > stored_events
uint32_t F125_NSB_CDC
Number of samples to integrate before thershold crossing during emulation rocid 24-28 only! ...
set< uint32_t > ROCIDS_TO_PARSE
static uint32_t * GetEVIOBufferFromRef(void *ref)
uint32_t F125_FDC_TH
FA125 emulation FDC high timing threshold.
The JEventSource_EVIO class implements a JEventSource capable of reading in EVIO data from raw data f...
uint32_t F125_TIME_UPSAMPLE
Use the CMU upsampling algorithm when emulating f125 pulse times.
uint32_t F125_CDC_TH
FA125 emulation CDC high timing threshold.
union @6::@8 u
void AddIfAppropriate(DDAQAddress *obj, vector< T * > &v)
void CopyContainerElementsWithCast(vector< T * > &a, vector< U * > &b)