Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DRebuildFromRawFADC_factory.h
Go to the documentation of this file.
1 /*
2  * DRebuildFromRawFADC_factory.h
3  *
4  * Created on: May 26, 2017
5  * Author: Hovanes Egiyan
6  */
7 
8 #ifndef LIBRARIES_DREBUILDFROMRAWFADC_FACTORY_H_
9 #define LIBRARIES_DREBUILDFROMRAWFADC_FACTORY_H_
10 
11 #include <vector>
12 #include <set>
13 using namespace std;
14 
15 #include <JANA/JFactory.h>
16 #include <JANA/JEventLoop.h>
17 #include <DANA/ReadWriteLock.h>
18 #include <TTAB/DTTabUtilities.h>
19 #include <DAQ/Df250WindowRawData.h>
20 #include <DAQ/Df250PulseData.h>
21 
22 #include "DTACDigiHit.h"
23 #include "DTACTDCDigiHit.h"
24 #include "DTACHit.h"
25 
26 #include <TAC/HitRebuilderTAC.h>
27 
28 #include <TAC/DTACHit_factory.h>
29 
30 // We will use this factory to create TAC hits with "REBUILD" tag using the existing
31 // hits and the raw data. This method will skip the making a new DigiHit
32 // class and simply replace some of the hit info by reanalyzing the FADC250
33 // waveform. this class is not supposed to be considered as "another" way
34 // of getting a TACHit since it depends on the default TACHit building
35 // factory for the main part of the information contained on the TACHit objects
36 // produced.
37 
38 template<typename BASE_FACTORY = DTACHit_factory,
39  typename BUILDER = HitRebuilderTAC>
40 class DRebuildFromRawFADC_factory: public BASE_FACTORY {
41 protected:
42  BUILDER* hitBuilder = nullptr;
43 // std::set<const Df250WindowRawData*> rawDataPtrSet;
44 
45 // virtual jerror_t rebuildHit(jana::JEventLoop *eventLoop,
46 // uint64_t eventNumber, const DTACHit* baseHit);
47 // virtual const Df250WindowRawData* getRawData(const DTACHit* baseHit);
48 // virtual double getTimeFromRawData(const vector<uint16_t>& samples);
49 public:
51  BASE_FACTORY() {
52  }
53  virtual const char* Tag() {
54  return (std::string(BASE_FACTORY::Tag()) + BUILDER::getTagString()).c_str();
55  }
57  }
58  virtual jerror_t init(void) override;
59  virtual jerror_t brun(jana::JEventLoop *eventLoop, int32_t runnumber)
60  override; ///< Called everytime a new run number is detected
61  virtual jerror_t evnt(jana::JEventLoop *eventLoop, uint64_t eventNumber)
62  override; ///< Called every event
63  virtual jerror_t erun(void) override; ///< Called everytime run number changes, if brun has been called
64  virtual jerror_t fini(void) override; ///< Called after last event of last event source has been processed
65 };
66 
67 using namespace std;
68 
69 template<typename BASE_FACTORY, typename BUILDER>
71  BASE_FACTORY::init();
72 // this->setTimeScaleADC(this->getTimeScaleADC() * 64); // Time scale for a single FADC hit
73  return NOERROR;
74 }
75 
76 template<typename BASE_FACTORY, typename BUILDER>
78  jana::JEventLoop *eventLoop, int32_t runnumber) {
79  BASE_FACTORY::brun(eventLoop, runnumber);
80 // hitBuilder = new BUILDER(this->getTimeScaleADC(), this->getADCTimeOffset(),
81 // this->getTimeBaseADC());
82  hitBuilder = new BUILDER( eventLoop );
83 
84  return NOERROR;
85 }
86 
87 // override the event processing method
88 template<typename BASE_FACTORY, typename BUILDER>
90  jana::JEventLoop* eventLoop, uint64_t eventNumber) {
91 
92 // cout << "In DTACHit_Rebuild_factory::evnt" << endl;
93 //
94 // cout << "Data structure has " << _data.size() << " elements" << endl;
95  vector<const DTACHit*> baseHitVector;
96  eventLoop->Get(baseHitVector, "");
97 
98 // // Declare comparison functor for this TAC hits basedon pulse peak
99 // static auto compareHits =
100 // [](const DTACHit* lhs, const DTACHit* rhs ) ->
101 // bool {return( (lhs!=nullptr)&(rhs!=nullptr ) ? fabs(lhs->getPulsePeak()) > fabs(rhs->getPulsePeak() ) : false );};
102 //
103 // std::sort(baseHitVector.begin(), baseHitVector.end(), compareHits);
104 //
105 //// rawDataPtrSet = new set<const Df250WindowRawData*>();
106 // for (auto baseHit : baseHitVector) {
107 // rebuildHit(eventLoop, eventNumber, baseHit);
108 // vector<DTACHit*> newHitVec = BUILDER( baseHit );
109 // }
110 // cout << "Here are all the " << _data.size() << " new hits in the rebuild factory" << endl;
111 // for( auto hit : _data ) {
112 // vector<pair<string,string>> outputStrings;
113 //
114 // hit->toStrings( outputStrings );
115 // cout << endl << "Rebuild hit at " << hit << endl;
116 // for( auto& outputPair : outputStrings ) {
117 // cout << outputPair.first << " = " << outputPair.second << endl;
118 // }
119 // }
120 // if( rawDataPtrSet != 0 ) {
121 // delete rawDataPtrSet;
122 // }
123 
124 // rawDataPtrSet.clear();
125 
126  vector<DTACHit*> newHitVector = (*hitBuilder)(baseHitVector);
127  for (auto newHit : newHitVector) {
128  this->AppendData(newHit);
129 // _data.push_back(newHit);
130  }
131 
132 // cout << "Done rebuilding TACHit " << endl;
133 
134  return NOERROR;
135 }
136 
137 // erun
138 //------------------
139 template<typename BASE_FACTORY, typename BUILDER>
141  if (hitBuilder != nullptr) {
142  delete hitBuilder;
143  hitBuilder = nullptr;
144  }
145  BASE_FACTORY::erun();
146  return NOERROR;
147 }
148 
149 //------------------
150 // fini
151 //------------------
152 template<typename BASE_FACTORY, typename BUILDER>
154  BASE_FACTORY::fini();
155  return NOERROR;
156 }
157 
158 
159 //// Declare specializations
160 //
161 //class WaveformErfcFunctor;
162 //template <typename T> class HitRebuilderByFit;
163 //
164 //
165 //template<>
166 //jerror_t DRebuildFromRawFADC_factory<DTACHit_factory,
167 // HitRebuilderByFit<WaveformErfcFunctor>>::init(void);
168 //template<>
169 //jerror_t DRebuildFromRawFADC_factory<DTACHit_factory,
170 // HitRebuilderByFit<WaveformErfcFunctor>>::brun(
171 // jana::JEventLoop *eventLoop, int32_t runnumber);
172 
173 #endif /* LIBRARIES_DREBUILDFROMRAWFADC_FACTORY_H_ */
virtual jerror_t erun(void) override
Called everytime run number changes, if brun has been called.
char string[256]
virtual jerror_t brun(jana::JEventLoop *eventLoop, int32_t runnumber) override
Called everytime a new run number is detected.
virtual jerror_t fini(void) override
Called after last event of last event source has been processed.
virtual jerror_t init(void) override
virtual jerror_t evnt(jana::JEventLoop *eventLoop, uint64_t eventNumber) override
Called every event.