Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DChargedTrackHypothesis_factory.h
Go to the documentation of this file.
1 // $Id$
2 //
3 // File: DChargedTrackHypothesis_factory.h
4 // Created: Tue Aug 9 14:29:24 EST 2011
5 // Creator: pmatt (on Linux ifarml6 2.6.18-128.el5 x86_64)
6 //
7 
8 #ifndef _DChargedTrackHypothesis_factory_
9 #define _DChargedTrackHypothesis_factory_
10 
11 #include <iostream>
12 #include <iomanip>
13 
14 #include <JANA/JFactory.h>
16 #include <PID/DDetectorMatches.h>
18 #include <PID/DParticleID.h>
19 #include <TOF/DTOFPoint.h>
20 #include <BCAL/DBCALShower.h>
21 #include <FCAL/DFCALShower.h>
22 #include "DResourcePool.h"
23 
24 using namespace std;
25 using namespace jana;
26 
27 class DChargedTrackHypothesis_factory:public jana::JFactory<DChargedTrackHypothesis>
28 {
29  public:
30  DChargedTrackHypothesis* Create_ChargedTrackHypothesis(JEventLoop* locEventLoop, const DTrackTimeBased* locTrackTimeBased, const DDetectorMatches* locDetectorMatches, const DEventRFBunch* locEventRFBunch);
31  void Add_TimeToTrackingMatrix(DChargedTrackHypothesis* locChargedTrackHypothesis, TMatrixFSym* locCovarianceMatrix, double locFlightTimeVariance, double locHitTimeVariance, double locFlightTimePCorrelation) const;
32 
33  void Recycle_Hypotheses(vector<const DChargedTrackHypothesis*>& locHypos){dResourcePool_ChargedTrackHypothesis->Recycle(locHypos);}
34  void Recycle_Hypotheses(vector<DChargedTrackHypothesis*>& locHypos){dResourcePool_ChargedTrackHypothesis->Recycle(locHypos);}
35  void Recycle_Hypothesis(const DChargedTrackHypothesis* locHypo){dResourcePool_ChargedTrackHypothesis->Recycle(locHypo);}
36 
37  size_t Get_NumObjectsAllThreads(void) const{return dResourcePool_ChargedTrackHypothesis->Get_NumObjectsAllThreads();}
39  {
40  auto locHypo = dResourcePool_ChargedTrackHypothesis->Get_Resource();
41  return locHypo;
42  }
43 
44  private:
46 
47  //RESOURCE POOL
48  //For some reason, JANA doesn't call factory destructor until AFTER the threads have been closed
49  //This causes the pool destructor to crash. Instead, delete in fini();
50  vector<DChargedTrackHypothesis*> dCreated;
51  DResourcePool<DChargedTrackHypothesis>* dResourcePool_ChargedTrackHypothesis = nullptr;
52  shared_ptr<DResourcePool<TMatrixFSym>> dResourcePool_TMatrixFSym;
53 
54  jerror_t init(void); ///< Called once at program start.
55  jerror_t brun(jana::JEventLoop *locEventLoop, int32_t runnumber); ///< Called everytime a new run number is detected.
56  jerror_t evnt(jana::JEventLoop *locEventLoop, uint64_t eventnumber); ///< Called every event.
57  jerror_t fini(void)
58  {
59  for(auto locHypo : _data)
60  Recycle_Hypothesis(locHypo);
61  _data.clear();
62  delete dResourcePool_ChargedTrackHypothesis;
63  return NOERROR;
64  }
65 };
66 
67 #endif // _DChargedTrackHypothesis_factory_
68 
shared_ptr< DResourcePool< TMatrixFSym > > dResourcePool_TMatrixFSym
void Recycle_Hypotheses(vector< DChargedTrackHypothesis * > &locHypos)
vector< DChargedTrackHypothesis * > dCreated
DChargedTrackHypothesis * Get_Resource(void)
void Recycle_Hypothesis(const DChargedTrackHypothesis *locHypo)
void Recycle_Hypotheses(vector< const DChargedTrackHypothesis * > &locHypos)