Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DTranslationTable.h
Go to the documentation of this file.
1 // $Id$
2 //
3 // File: DTranslationTable.h
4 // Created: Thu Jun 27 15:33:38 EDT 2013
5 // Creator: davidl (on Darwin harriet.jlab.org 11.4.2 i386)
6 //
7 
8 #ifndef _DTranslationTable_
9 #define _DTranslationTable_
10 
11 #include <set>
12 #include <string>
13 
14 using namespace std;
15 
16 
17 #include <JANA/JObject.h>
18 #include <JANA/JFactory.h>
19 #include <JANA/JEventLoop.h>
20 #include <JANA/JCalibration.h>
21 #include <JANA/JException.h>
22 #include <JANA/JEventSource.h>
23 using namespace jana;
24 
25 #include <DAQ/DModuleType.h>
26 #include <DAQ/Df250PulseData.h>
27 #include <DAQ/Df250PulseIntegral.h>
29 #include <DAQ/Df250WindowSum.h>
30 #include <DAQ/Df250PulseRawData.h>
31 #include <DAQ/Df250TriggerTime.h>
32 #include <DAQ/Df250PulseTime.h>
33 #include <DAQ/Df250PulsePedestal.h>
34 #include <DAQ/Df250WindowRawData.h>
35 #include <DAQ/Df125PulseIntegral.h>
36 #include <DAQ/Df125PulseTime.h>
37 #include <DAQ/Df125PulsePedestal.h>
38 #include <DAQ/Df125TriggerTime.h>
39 #include <DAQ/Df125CDCPulse.h>
40 #include <DAQ/Df125FDCPulse.h>
41 #include <DAQ/DF1TDCHit.h>
42 #include <DAQ/DF1TDCTriggerTime.h>
43 #include <DAQ/DCAEN1290TDCHit.h>
44 #include <DAQ/DDIRCTDCHit.h>
45 
46 #include <BCAL/DBCALDigiHit.h>
47 #include <BCAL/DBCALTDCDigiHit.h>
48 #include <CDC/DCDCDigiHit.h>
49 #include <FCAL/DFCALDigiHit.h>
50 #include <CCAL/DCCALDigiHit.h>
51 #include <CCAL/DCCALRefDigiHit.h>
52 #include <FDC/DFDCCathodeDigiHit.h>
53 #include <FDC/DFDCWireDigiHit.h>
54 #include <RF/DRFDigiTime.h>
55 #include <RF/DRFTDCDigiTime.h>
58 #include <TOF/DTOFDigiHit.h>
59 #include <TOF/DTOFTDCDigiHit.h>
60 #include <TAGGER/DTAGMDigiHit.h>
61 #include <TAGGER/DTAGMTDCDigiHit.h>
62 #include <TAGGER/DTAGHDigiHit.h>
63 #include <TAGGER/DTAGHTDCDigiHit.h>
68 #include <TAC/DTACDigiHit.h>
69 #include <TAC/DTACTDCDigiHit.h>
70 #include <DIRC/DDIRCTDCDigiHit.h>
71 
72 // (See comments in DParsedEvent.h for enlightenment)
73 #define MyTypes(X) \
74  X(DBCALDigiHit) \
75  X(DBCALTDCDigiHit) \
76  X(DCDCDigiHit) \
77  X(DFCALDigiHit) \
78  X(DCCALDigiHit) \
79  X(DCCALRefDigiHit) \
80  X(DFDCCathodeDigiHit) \
81  X(DFDCWireDigiHit) \
82  X(DRFDigiTime) \
83  X(DRFTDCDigiTime) \
84  X(DSCDigiHit) \
85  X(DSCTDCDigiHit) \
86  X(DTOFDigiHit) \
87  X(DTOFTDCDigiHit) \
88  X(DTAGMDigiHit) \
89  X(DTAGMTDCDigiHit) \
90  X(DTAGHDigiHit) \
91  X(DTAGHTDCDigiHit) \
92  X(DPSDigiHit) \
93  X(DPSCDigiHit) \
94  X(DPSCTDCDigiHit) \
95  X(DTPOLSectorDigiHit) \
96  X(DTACDigiHit) \
97  X(DTACTDCDigiHit) \
98  X(DDIRCTDCDigiHit)
99 
100 #define MyfADCTypes(X) \
101  X(DBCALDigiHit) \
102  X(DCDCDigiHit) \
103  X(DFCALDigiHit) \
104  X(DCCALDigiHit) \
105  X(DCCALRefDigiHit) \
106  X(DFDCCathodeDigiHit) \
107  X(DSCDigiHit) \
108  X(DTOFDigiHit) \
109  X(DTAGMDigiHit) \
110  X(DTAGHDigiHit) \
111  X(DPSDigiHit) \
112  X(DPSCDigiHit) \
113  X(DTPOLSectorDigiHit) \
114  X(DTACDigiHit)
115 
116 
117 #include "GlueX.h"
118 
119 class DTranslationTable:public jana::JObject{
120  public:
121  JOBJECT_PUBLIC(DTranslationTable);
122 
123  DTranslationTable(JEventLoop *loop);
125 
126  // Each detector system has its own native indexing scheme.
127  // Here, we define a class for each of them that has those
128  // indexes. These are then used below in the DChannelInfo
129  // class to relate them to the DAQ indexing scheme of
130  // crate, slot, channel.
131  struct csc_t{
132  uint32_t rocid;
133  uint32_t slot;
134  uint32_t channel;
135 
136  inline bool operator==(const struct csc_t &rhs) const {
137  return (rocid==rhs.rocid) && (slot==rhs.slot) && (channel==rhs.channel);
138  }
139  };
140 
148  PS,
150  RF,
151  SC,
160  NUM_DETECTOR_TYPES
161  };
162 
163  static string DetectorName(Detector_t type) {
164  switch(type){
165  case BCAL: return "BCAL";
166  case CDC: return "CDC";
167  case FCAL: return "FCAL";
168  case CCAL: return "CCAL";
169  case CCAL_REF: return "CCAL_REF";
170  case FDC_CATHODES: return "FDC_CATHODES";
171  case FDC_WIRES: return "FDC_WIRES";
172  case PS: return "PS";
173  case PSC: return "PSC";
174  case RF: return "RF";
175  case SC: return "SC";
176  case TAGH: return "TAGH";
177  case TAGM: return "TAGM";
178  case TOF: return "TOF";
179  case TPOLSECTOR: return "TPOL"; // is set to TPOL to match what is in CCDB, fix later
180  case TAC: return "TAC";
181  case DIRC: return "DIRC";
182  case UNKNOWN_DETECTOR:
183  default:
184  return "UNKNOWN";
185  }
186  }
187 
188  class BCALIndex_t{
189  public:
190  uint32_t module;
191  uint32_t layer;
192  uint32_t sector;
193  uint32_t end;
194 
195  inline bool operator==(const BCALIndex_t &rhs) const {
196  return (module==rhs.module) && (layer==rhs.layer)
197  && (sector==rhs.sector) && (end==rhs.end);
198  }
199  };
200 
201  class CDCIndex_t{
202  public:
203  uint32_t ring;
204  uint32_t straw;
205 
206  inline bool operator==(const CDCIndex_t &rhs) const {
207  return (ring==rhs.ring) && (straw==rhs.straw);
208  }
209  };
210 
211  class FCALIndex_t{
212  public:
213  uint32_t row;
214  uint32_t col;
215 
216  inline bool operator==(const FCALIndex_t &rhs) const {
217  return (row==rhs.row) && (col==rhs.col);
218  }
219  };
220 
221  class CCALIndex_t{
222  public:
223  int row;
224  int col;
225 
226  inline bool operator==(const CCALIndex_t &rhs) const {
227  return (row==rhs.row) && (col==rhs.col);
228  }
229  };
230 
232  public:
233  int id;
234 
235  inline bool operator==(const CCALRefIndex_t &rhs) const {
236  return (id==rhs.id);
237  }
238  };
239 
240 
242  public:
243  uint32_t package;
244  uint32_t chamber;
245  uint32_t view;
246  uint32_t strip;
247  uint32_t strip_type;
248 
249  inline bool operator==(const FDC_CathodesIndex_t &rhs) const {
250  return (package==rhs.package) && (chamber==rhs.chamber) && (view==rhs.view)
251  && (strip==rhs.strip) && (strip_type==rhs.strip_type);
252  }
253  };
254 
256  public:
257  uint32_t package;
258  uint32_t chamber;
259  uint32_t wire;
260 
261  inline bool operator==(const FDC_WiresIndex_t &rhs) const {
262  return (package==rhs.package) && (chamber==rhs.chamber) && (wire==rhs.wire);
263  }
264  };
265 
266  class PSIndex_t{
267  public:
268  uint32_t side;
269  uint32_t id;
270 
271  inline bool operator==(const PSIndex_t &rhs) const {
272  return (side==rhs.side) && (id==rhs.id);
273  }
274  };
275 
276  class PSCIndex_t{
277  public:
278  uint32_t id;
279 
280  inline bool operator==(const PSCIndex_t &rhs) const {
281  return (id==rhs.id);
282  }
283  };
284 
285  class RFIndex_t{
286  public:
288 
289  inline bool operator==(const RFIndex_t &rhs) const {
290  return (dSystem == rhs.dSystem);
291  }
292  };
293 
294  class SCIndex_t{
295  public:
296  uint32_t sector;
297 
298  inline bool operator==(const SCIndex_t &rhs) const {
299  return (sector==rhs.sector);
300  }
301  };
302 
303  class TAGHIndex_t{
304  public:
305  uint32_t id;
306 
307  inline bool operator==(const TAGHIndex_t &rhs) const {
308  return (id==rhs.id);
309  }
310  };
311 
312  class TAGMIndex_t{
313  public:
314  uint32_t col;
315  uint32_t row;
316 
317  inline bool operator==(const TAGMIndex_t &rhs) const {
318  return (col==rhs.col) && (row==rhs.row);
319  }
320  };
321 
322  class TOFIndex_t{
323  public:
324  uint32_t plane;
325  uint32_t bar;
326  uint32_t end;
327 
328  inline bool operator==(const TOFIndex_t &rhs) const {
329  return (plane==rhs.plane) && (bar==rhs.bar) && (end==rhs.end);
330  }
331  };
332 
334  public:
335  uint32_t sector;
336 
337  inline bool operator==(const TPOLSECTORIndex_t &rhs) const {
338  return (sector==rhs.sector);
339  }
340  };
341 
342  class TACIndex_t {
343  public:
344  inline bool operator==( const TACIndex_t& rhs ) const {
345  return true;
346  }
347  };
348 
349  class DIRCIndex_t {
350  public:
351  uint32_t pixel;
352 
353  inline bool operator==( const DIRCIndex_t& rhs ) const {
354  return (pixel==rhs.pixel);
355  }
356  };
357 
358  // DChannelInfo holds translation between indexing schemes
359  // for one channel.
361  public:
365  union{
383  };
384  };
385 
386  //-----------------------------------------------------------------------
387  //
388  // Pre-processor macro monkey shines using the MyTypes define above to repeat
389  // lots of code for all types in a compact and robust way.
390  //
391  // For each type defined in "MyTypes" above, define a vector of
392  // pointers to it with a name made by prepending a "v" to the classname
393  // The following expands to things like e.g.
394  //
395  // vector<DBCALDigiHit*> vDBCALDigiHit;
396  //
397  #define makevector(A) mutable vector<A*> v##A;
399 
400  // Similarly, define a pointer to the factory for each type.
401  #define makefactoryptr(A) JFactory<A> *fac_##A;
403 
404  // Method to initialize factory pointers
405  #define copyfactoryptr(A) fac_##A = (JFactory<A>*)loop->GetFactory(#A);
406  void InitFactoryPointers(JEventLoop *loop){ MyTypes(copyfactoryptr) }
407 
408  // Method to clear each of the vectors at beginning of event
409  #define clearvector(A) v##A.clear();
410  void ClearVectors(void) const { MyTypes(clearvector) }
411 
412  // Method to copy all produced objects to respective factories
413  #define copytofactory(A) fac_##A->CopyTo(v##A);
414  void CopyToFactories(void) const { MyTypes(copytofactory) }
415 
416  // Method to check class name against each classname in MyTypes returning
417  // true if found and false if not.
418  #define checkclassname(A) if(classname==#A) return true;
419  bool IsSuppliedType(string &classname) const {
421  return false;
422  }
423 
424  // Method to print sizes of all vectors (for debugging)
425  #define printvectorsize(A) ttout << " v" #A ".size() = " << v##A.size() << std::endl;
427 
428 
429  // -- Here are some to help with overriding the nsamples_X fields
430  // -- of all of the fADC types
431 
432  // Create config. param. members for all fADC types
433  #define makefadcconfigparam1(A) uint32_t NSAMPLES_INTEGRAL_##A;
434  #define makefadcconfigparam2(A) uint32_t NSAMPLES_PEDESTAL_##A;
437 
438  // Method to initialize variables and create/get config. parameters
439  void InitNsamplesOverride(void){
440  #define setdefaultfadc(A) {\
441  NSAMPLES_INTEGRAL_##A = NSAMPLES_PEDESTAL_##A = 0; \
442  gPARMS->SetDefaultParameter("TT:NSAMPLES_INTEGRAL_" #A, NSAMPLES_INTEGRAL_##A, "Overwrite the nsamples_integral field of all " #A " objects with this"); \
443  gPARMS->SetDefaultParameter("TT:NSAMPLES_PEDESTAL_" #A, NSAMPLES_PEDESTAL_##A, "Overwrite the nsamples_pedestal field of all " #A " objects with this"); \
444  }
446  }
447 
448  // Method to overwrite nsamples_X fields if config. param is set
449  void OverwriteNsamples(void) const {
450  #define overwritensamples(A) {\
451  if(NSAMPLES_INTEGRAL_##A > 0) for(auto h : v##A) h->nsamples_integral = NSAMPLES_INTEGRAL_##A; \
452  if(NSAMPLES_PEDESTAL_##A > 0) for(auto h : v##A) h->nsamples_pedestal = NSAMPLES_PEDESTAL_##A; \
453  }
455  }
456 
457 
458  //-----------------------------------------------------------------------
459 
460  // Methods
461  void ApplyTranslationTable(jana::JEventLoop *loop) const;
462 
463  // fADC250 -- Fall 2016 -> ?
464  DBCALDigiHit* MakeBCALDigiHit( const BCALIndex_t &idx, const Df250PulseData *pd) const;
465  DFCALDigiHit* MakeFCALDigiHit( const FCALIndex_t &idx, const Df250PulseData *pd) const;
466  DCCALDigiHit* MakeCCALDigiHit( const CCALIndex_t &idx, const Df250PulseData *pd) const;
467  DCCALRefDigiHit* MakeCCALRefDigiHit( const CCALRefIndex_t &idx, const Df250PulseData *pd) const;
468  DSCDigiHit* MakeSCDigiHit( const SCIndex_t &idx, const Df250PulseData *pd) const;
469  DTOFDigiHit* MakeTOFDigiHit( const TOFIndex_t &idx, const Df250PulseData *pd) const;
470  DTAGMDigiHit* MakeTAGMDigiHit( const TAGMIndex_t &idx, const Df250PulseData *pd) const;
471  DTAGHDigiHit* MakeTAGHDigiHit( const TAGHIndex_t &idx, const Df250PulseData *pd) const;
472  DPSDigiHit* MakePSDigiHit( const PSIndex_t &idx, const Df250PulseData *pd) const;
473  DPSCDigiHit* MakePSCDigiHit( const PSCIndex_t &idx, const Df250PulseData *pd) const;
474  DRFDigiTime* MakeRFDigiTime( const RFIndex_t &idx, const Df250PulseData *pd) const;
475  DTPOLSectorDigiHit* MakeTPOLSectorDigiHit( const TPOLSECTORIndex_t &idx, const Df250PulseData *pd) const;
476  DTACDigiHit* MakeTACDigiHit( const TACIndex_t &idx, const Df250PulseData *pd) const;
477 
478  // fADC250 -- commissioning -> Fall 2016
479  DBCALDigiHit* MakeBCALDigiHit(const BCALIndex_t &idx, const Df250PulseIntegral *pi, const Df250PulseTime *pt, const Df250PulsePedestal *pp) const;
480  DFCALDigiHit* MakeFCALDigiHit(const FCALIndex_t &idx, const Df250PulseIntegral *pi, const Df250PulseTime *pt, const Df250PulsePedestal *pp) const;
481  DCCALDigiHit* MakeCCALDigiHit(const CCALIndex_t &idx, const Df250PulseIntegral *pi, const Df250PulseTime *pt, const Df250PulsePedestal *pp) const;
482  DCCALRefDigiHit* MakeCCALRefDigiHit(const CCALRefIndex_t &idx, const Df250PulseIntegral *pi, const Df250PulseTime *pt, const Df250PulsePedestal *pp) const;
483  DSCDigiHit* MakeSCDigiHit( const SCIndex_t &idx, const Df250PulseIntegral *pi, const Df250PulseTime *pt, const Df250PulsePedestal *pp) const;
484  DTOFDigiHit* MakeTOFDigiHit( const TOFIndex_t &idx, const Df250PulseIntegral *pi, const Df250PulseTime *pt, const Df250PulsePedestal *pp) const;
485  DTAGMDigiHit* MakeTAGMDigiHit(const TAGMIndex_t &idx, const Df250PulseIntegral *pi, const Df250PulseTime *pt, const Df250PulsePedestal *pp) const;
486  DTAGHDigiHit* MakeTAGHDigiHit(const TAGHIndex_t &idx, const Df250PulseIntegral *pi, const Df250PulseTime *pt, const Df250PulsePedestal *pp) const;
487  DPSDigiHit* MakePSDigiHit( const PSIndex_t &idx, const Df250PulseIntegral *pi, const Df250PulseTime *pt, const Df250PulsePedestal *pp) const;
488  DPSCDigiHit* MakePSCDigiHit( const PSCIndex_t &idx, const Df250PulseIntegral *pi, const Df250PulseTime *pt, const Df250PulsePedestal *pp) const;
489  DRFDigiTime* MakeRFDigiTime( const RFIndex_t &idx, const Df250PulseTime *hit) const;
490  DTPOLSectorDigiHit* MakeTPOLSectorDigiHit(const TPOLSECTORIndex_t &idx, const Df250PulseIntegral *pi, const Df250PulseTime *pt, const Df250PulsePedestal *pp) const;
491  DTACDigiHit* MakeTACDigiHit( const TACIndex_t &idx, const Df250PulseIntegral *pi, const Df250PulseTime *pt, const Df250PulsePedestal *pp) const;
492 
493  // fADC125
494  DCDCDigiHit* MakeCDCDigiHit(const CDCIndex_t &idx, const Df125PulseIntegral *pi, const Df125PulseTime *pt, const Df125PulsePedestal *pp) const;
495  DCDCDigiHit* MakeCDCDigiHit(const CDCIndex_t &idx, const Df125CDCPulse *p) const;
496  DCDCDigiHit* MakeCDCDigiHit(const CDCIndex_t &idx, const Df125FDCPulse *p) const;
497  DFDCCathodeDigiHit* MakeFDCCathodeDigiHit(const FDC_CathodesIndex_t &idx, const Df125PulseIntegral *pi, const Df125PulseTime *pt, const Df125PulsePedestal *pp) const;
498  DFDCCathodeDigiHit* MakeFDCCathodeDigiHit(const FDC_CathodesIndex_t &idx, const Df125FDCPulse *p) const;
499 
500  // F1TDC
501  DBCALTDCDigiHit* MakeBCALTDCDigiHit(const BCALIndex_t &idx, const DF1TDCHit *hit) const;
502  DFDCWireDigiHit* MakeFDCWireDigiHit(const FDC_WiresIndex_t &idx, const DF1TDCHit *hit) const;
503  DRFTDCDigiTime* MakeRFTDCDigiTime( const RFIndex_t &idx, const DF1TDCHit *hit) const;
504  DSCTDCDigiHit* MakeSCTDCDigiHit( const SCIndex_t &idx, const DF1TDCHit *hit) const;
505  DTAGMTDCDigiHit* MakeTAGMTDCDigiHit(const TAGMIndex_t &idx, const DF1TDCHit *hit) const;
506  DTAGHTDCDigiHit* MakeTAGHTDCDigiHit(const TAGHIndex_t &idx, const DF1TDCHit *hit) const;
507  DPSCTDCDigiHit* MakePSCTDCDigiHit( const PSCIndex_t &idx, const DF1TDCHit *hit) const;
508 
509  // CAEN1290TDC
510  DTOFTDCDigiHit* MakeTOFTDCDigiHit(const TOFIndex_t &idx, const DCAEN1290TDCHit *hit) const;
511  DRFTDCDigiTime* MakeRFTDCDigiTime(const RFIndex_t &idx, const DCAEN1290TDCHit *hit) const;
512  DTACTDCDigiHit* MakeTACTDCDigiHit( const TACIndex_t &idx, const DCAEN1290TDCHit *hit) const;
513 
514  DDIRCTDCDigiHit* MakeDIRCTDCDigiHit( const DIRCIndex_t &idx, const DDIRCTDCHit *hit) const;
515 
516  void Addf250ObjectsToCallStack(JEventLoop *loop, string caller) const;
517  void Addf125CDCObjectsToCallStack(JEventLoop *loop, string caller, bool addpulseobjs) const;
518  void Addf125FDCObjectsToCallStack(JEventLoop *loop, string caller, bool addpulseobjs) const;
519  void AddF1TDCObjectsToCallStack(JEventLoop *loop, string caller) const;
520  void AddCAEN1290TDCObjectsToCallStack(JEventLoop *loop, string caller) const;
521  void AddToCallStack(JEventLoop *loop, string caller, string callee) const;
522 
523  void ReadOptionalROCidTranslation(void);
524  static void SetSystemsToParse(string systems, JEventSource *eventsource);
525  void SetSystemsToParse(JEventSource *eventsource){SetSystemsToParse(SYSTEMS_TO_PARSE, eventsource);}
526  void ReadTranslationTable(JCalibration *jcalib=NULL);
527 
528  template<class T> void CopyDf250Info(T *h, const Df250PulseIntegral *pi, const Df250PulseTime *pt, const Df250PulsePedestal *pp) const;
529  template<class T> void CopyDf250Info(T *h, const Df250PulseData *pd) const;
530  template<class T> void CopyDf125Info(T *h, const Df125PulseIntegral *pi, const Df125PulseTime *pt, const Df125PulsePedestal *pp) const;
531  template<class T> void CopyDF1TDCInfo(T *h, const DF1TDCHit *hit) const;
532  template<class T> void CopyDCAEN1290TDCInfo(T *h, const DCAEN1290TDCHit *hit) const;
533  template<class T> void CopyDIRCTDCInfo(T *h, const DDIRCTDCHit *hit) const;
534 
535 
536  // methods for others to search the Translation Table
537  const DChannelInfo &GetDetectorIndex(const csc_t &in_daq_index) const;
538  const csc_t &GetDAQIndex(const DChannelInfo &in_channel) const;
539 
540  //public so that StartElement can access it
541  static map<DTranslationTable::Detector_t, set<uint32_t> >& Get_ROCID_By_System(void); //this is static so that StartElement can access it
542 
543  // This was left over from long ago and is not currently used. It seems
544  // potentially useful though in the future so I don't want to get rid
545  // of it. However, it was causing "defined but not used" warnings when
546  // defined as a simple C function. Moved it here just to prevent those
547  // warnings.
548  static int ModuleStr2ModID(string &type)
549  {
550  if (type == "vmecpu") {
551  return(DModuleType::VMECPU);
552  } else if (type == "tid") {
553  return(DModuleType::TID);
554  } else if (type == "fadc250") {
555  return(DModuleType::FADC250);
556  } else if (type == "fadc125") {
557  return(DModuleType::FADC125);
558  } else if (type == "f1tdcv2") {
559  return(DModuleType::F1TDC32);
560  } else if (type == "f1tdcv3") {
561  return(DModuleType::F1TDC48);
562  } else if (type == "jldisc") {
563  return(DModuleType::JLAB_DISC);
564  } else if (type == "vx1290a") {
565  return(DModuleType::CAEN1290);
566  } else {
567  return(DModuleType::UNKNOWN);
568  }
569  }
570 
571  protected:
572  string XML_FILENAME;
573  bool NO_CCDB;
574  set<string> supplied_data_types;
575  int VERBOSE;
579 
580  mutable JStreamLog ttout;
581 
582  string Channel2Str(const DChannelInfo &in_channel) const;
583 
584  private:
585 
586  /****************************************** STATIC-VARIABLE-ACCESSING PRIVATE MEMBER FUNCTIONS ******************************************/
587 
588  //Some variables needs to be shared amongst threads (e.g. the memory used for the branch variables)
589  //However, you cannot make them global/extern/static/static-member variables in the header file:
590  //The header file is included in the TTAB library AND in each plugin that uses it
591  //When a header file is included in a src file, it's contents are essentially copied directly into it
592  //Thus there are two instances of each static variable: one in each translation unit (library)
593  //Supposedly(?) they are linked together during runtime when loading, so there is (supposedly) no undefined behavior.
594  //However, this causes a double free (double-deletion) when these libraries are closed at the end of the program, crashing it.
595  //Thus the variables must be in a single source file that is compiled into a single library
596  //However, you (somehow?) cannot make them global/extern variables in the cpp function
597  //This also (somehow?) causes the double-free problem above for (at least) stl containers
598  //It works for pointers-to-stl-containers and fundamental types, but I dunno why.
599  //It's not good encapsulation anyway though.
600  //THE SOLUTION:
601  //Define the variables as static, in the source file, WITHIN A PRIVATE MEMBER FUNCTION.
602  //Thus the static variables themselves only have function scope.
603  //Access is only available via the private member functions, thus access is fully controlled.
604  //They are shared amongst threads, so locks are necessary, but since they are private this class can handle it internally
605 
606  pthread_mutex_t& Get_TT_Mutex(void) const;
607  bool& Get_TT_Initialized(void) const;
608  map<DTranslationTable::csc_t, DTranslationTable::DChannelInfo>& Get_TT(void) const;
609  map<uint32_t, uint32_t>& Get_ROCID_Map(void) const;
610  map<uint32_t, uint32_t>& Get_ROCID_Inv_Map(void) const;
611 };
612 
613 //---------------------------------
614 // CopyDf250Info
615 //---------------------------------
616 template<class T>
618 {
619  /// Copy info from the fADC250 into a hit object.
620  h->pulse_integral = pi->integral;
621  h->pulse_time = pt==NULL ? 0:pt->time;
622  h->pulse_peak = pp==NULL ? 0:pp->pulse_peak;
623  h->pedestal = pi->pedestal;
624  h->QF = pi->quality_factor;
625  h->nsamples_integral = pi->nsamples_integral;
626  h->nsamples_pedestal = pi->nsamples_pedestal;
627  h->datasource = pi->emulated ? 0:1;
628 
629  h->AddAssociatedObject(pi);
630  if(pt) h->AddAssociatedObject(pt);
631  if(pp) h->AddAssociatedObject(pp);
632 }
633 
634 //---------------------------------
635 // CopyDf250Info
636 //---------------------------------
637 template<class T>
639 {
640  /// Copy info from the fADC250 into a hit object.
641  h->pulse_integral = pd->integral;
642  h->pulse_time = (pd->course_time<<6) + pd->fine_time;
643  h->pulse_peak = pd->pulse_peak;
644  h->pedestal = pd->pedestal;
645  h->nsamples_integral = pd->nsamples_integral;
646  h->nsamples_pedestal = pd->nsamples_pedestal;
647  h->datasource = pd->emulated ? 0:2;
648 
649  uint32_t QF = 0; // make single quality factor number for compactness
650  if( pd->QF_pedestal ) QF |= (1<<0);
651  if( pd->QF_NSA_beyond_PTW ) QF |= (1<<1);
652  if( pd->QF_overflow ) QF |= (1<<2);
653  if( pd->QF_underflow ) QF |= (1<<3);
654  if( pd->QF_vpeak_beyond_NSA ) QF |= (1<<4);
655  if( pd->QF_vpeak_not_found ) QF |= (1<<5);
656  if( pd->QF_bad_pedestal ) QF |= (1<<6);
657  h->QF = QF;
658 
659  h->AddAssociatedObject(pd);
660 }
661 
662 //---------------------------------
663 // CopyDf125Info
664 //---------------------------------
665 template<class T>
667 {
668  /// Copy info from the fADC125 into a hit object.
669  h->pulse_integral = pi->integral;
670  h->pulse_time = pt==NULL ? 0:pt->time;
671  h->pedestal = pi->pedestal;
672  h->QF = pi->quality_factor;
673  h->nsamples_integral = pi->nsamples_integral;
674  h->nsamples_pedestal = pi->nsamples_pedestal;
675 
676  h->AddAssociatedObject(pi);
677  if(pt) h->AddAssociatedObject(pt);
678  if(pp) h->AddAssociatedObject(pp);
679 }
680 
681 //---------------------------------
682 // CopyDF1TDCInfo
683 //---------------------------------
684 template<class T>
686 {
687  /// Copy info from the f1tdc into a hit object.
688 
689  h->time = hit->time;
690  h->AddAssociatedObject(hit);
691 }
692 
693 //---------------------------------
694 // CopyDCAEN1290TDCInfo
695 //---------------------------------
696 template<class T>
698 {
699  /// Copy info from the CAEN1290 into a hit object.
700  h->time = hit->time;
701 
702  h->AddAssociatedObject(hit);
703 }
704 
705 //---------------------------------
706 // CopyDIRCTDCInfo
707 //---------------------------------
708 template<class T>
710 {
711  /// Copy info from the DIRCTDC into a hit object.
712  h->time = hit->time;
713  h->edge = hit->edge;
714 
715  h->AddAssociatedObject(hit);
716 }
717 
718 #undef MyTypes
719 #undef MyfADCTypes
720 #undef makevector
721 #undef makefactoryptr
722 #undef copyfactoryptr
723 #undef clearvector
724 #undef copytofactory
725 #undef checkclassname
726 #undef printvectorsize
727 #undef makefadcconfigparam1
728 #undef makefadcconfigparam2
729 #undef setdefaultfadc
730 #undef overwritensamples
731 
732 #endif // _DTranslationTable_
733 
#define overwritensamples(A)
bool operator==(const CCALIndex_t &rhs) const
uint32_t nsamples_integral
number of samples used in integral
#define makevector(A)
void CopyDf125Info(T *h, const Df125PulseIntegral *pi, const Df125PulseTime *pt, const Df125PulsePedestal *pp) const
uint32_t nsamples_pedestal
number of samples used in pedestal
uint32_t pedestal
from Pulse Integral Data word (future)
uint32_t fine_time
bool operator==(const TAGMIndex_t &rhs) const
bool operator==(const TPOLSECTORIndex_t &rhs) const
uint32_t time
16 bit relative to beginning of defined readout window
Definition: DDIRCTDCHit.h:28
bool operator==(const FDC_CathodesIndex_t &rhs) const
Int_t layer
void ClearVectors(void) const
bool IsSuppliedType(string &classname) const
uint32_t quality_factor
from Pulse Integral Data word
void CopyDCAEN1290TDCInfo(T *h, const DCAEN1290TDCHit *hit) const
bool emulated
true if made from Window Raw Data
uint32_t quality_factor
from Pulse Integral Data word
#define makefactoryptr(A)
bool operator==(const TOFIndex_t &rhs) const
bool operator==(const CCALRefIndex_t &rhs) const
#define makefadcconfigparam1(A)
void OverwriteNsamples(void) const
static int ModuleStr2ModID(string &type)
uint32_t nsamples_integral
number of samples used in integral
bool operator==(const PSIndex_t &rhs) const
DetectorSystem_t
Definition: GlueX.h:15
uint32_t pulse_peak
from Pulse Pedestal Data word
#define clearvector(A)
#define printvectorsize(A)
Definition: CDC.h:14
bool operator==(const BCALIndex_t &rhs) const
bool operator==(const PSCIndex_t &rhs) const
bool operator==(const TACIndex_t &rhs) const
bool operator==(const DIRCIndex_t &rhs) const
uint32_t edge
0=leading edge 1=trailing edge
Definition: DDIRCTDCHit.h:27
bool emulated
true if made from Window Raw Data
DModuleType::type_id_t module_type
uint32_t integral
uint32_t time
Definition: DF1TDCHit.h:30
uint32_t nsamples_integral
number of samples used in integral
uint32_t pedestal
#define TAGM
Definition: PSEcorr.C:20
#define makefadcconfigparam2(A)
uint32_t time
from Pulse Time Data word
bool operator==(const FCALIndex_t &rhs) const
void PrintVectorSizes(void) const
void CopyDF1TDCInfo(T *h, const DF1TDCHit *hit) const
void CopyDIRCTDCInfo(T *h, const DDIRCTDCHit *hit) const
#define copytofactory(A)
uint32_t time
from Pulse Time Data word
Definition: FCAL.h:14
void CopyToFactories(void) const
void SetSystemsToParse(JEventSource *eventsource)
uint32_t integral
from Pulse Integral Data word
uint32_t pedestal
from Pulse Integral Data word (future)
bool operator==(const FDC_WiresIndex_t &rhs) const
uint32_t integral
from Pulse Integral Data word
#define TAGH
Definition: PSEcorr.C:21
bool operator==(const RFIndex_t &rhs) const
#define MyfADCTypes(X)
bool operator==(const SCIndex_t &rhs) const
void CopyDf250Info(T *h, const Df250PulseIntegral *pi, const Df250PulseTime *pt, const Df250PulsePedestal *pp) const
set< string > supplied_data_types
uint32_t pulse_peak
uint32_t nsamples_pedestal
number of samples used in pedestal
uint32_t course_time
bool operator==(const CDCIndex_t &rhs) const
uint32_t nsamples_pedestal
number of samples used in pedestal
bool operator==(const TAGHIndex_t &rhs) const
Definition: TOF.h:14
void InitFactoryPointers(JEventLoop *loop)
#define copyfactoryptr(A)
#define MyTypes(X)
bool operator==(const struct csc_t &rhs) const
static string DetectorName(Detector_t type)
#define setdefaultfadc(A)
#define checkclassname(A)