clang -cc1 -cc1 -triple x86_64-unknown-linux-gnu -analyze -disable-free -main-file-name DParticleComboCreator.cc -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 2 -fhalf-no-semantic-interposition -mframe-pointer=none -fmath-errno -fno-rounding-math -mconstructor-aliases -munwind-tables -target-cpu x86-64 -tune-cpu generic -fno-split-dwarf-inlining -debugger-tuning=gdb -resource-dir /w/halld-scifs17exp/home/sdobbs/clang/llvm-project/install/lib/clang/12.0.0 -D HAVE_CCDB -D HAVE_RCDB -D HAVE_EVIO -D HAVE_TMVA=1 -D RCDB_MYSQL=1 -D RCDB_SQLITE=1 -D SQLITE_USE_LEGACY_STRUCT=ON -I .Linux_CentOS7.7-x86_64-gcc4.8.5/libraries/ANALYSIS -I libraries/ANALYSIS -I . -I libraries -I libraries/include -I /w/halld-scifs17exp/home/sdobbs/clang/halld_recon/Linux_CentOS7.7-x86_64-gcc4.8.5/include -I external/xstream/include -I /usr/include/tirpc -I /group/halld/Software/builds/Linux_CentOS7.7-x86_64-gcc4.8.5/root/root-6.08.06/include -I /w/halld-scifs17exp/halld2/home/sdobbs/Software/jana/jana_0.8.2/Linux_CentOS7.7-x86_64-gcc4.8.5/include -I /group/halld/Software/builds/Linux_CentOS7.7-x86_64-gcc4.8.5/ccdb/ccdb_1.06.06/include -I /group/halld/Software/builds/Linux_CentOS7.7-x86_64-gcc4.8.5/rcdb/rcdb_0.06.00/cpp/include -I /usr/include/mysql -I /group/halld/Software/builds/Linux_CentOS7.7-x86_64-gcc4.8.5/sqlitecpp/SQLiteCpp-2.2.0^bs130/include -I /group/halld/Software/builds/Linux_CentOS7.7-x86_64-gcc4.8.5/sqlite/sqlite-3.13.0^bs130/include -I /group/halld/Software/builds/Linux_CentOS7.7-x86_64-gcc4.8.5/hdds/hdds-4.9.0/Linux_CentOS7.7-x86_64-gcc4.8.5/src -I /group/halld/Software/builds/Linux_CentOS7.7-x86_64-gcc4.8.5/xerces-c/xerces-c-3.1.4/include -I /group/halld/Software/builds/Linux_CentOS7.7-x86_64-gcc4.8.5/evio/evio-4.4.6/Linux-x86_64/include -internal-isystem /usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../include/c++/4.8.5 -internal-isystem /usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../include/c++/4.8.5/x86_64-redhat-linux -internal-isystem /usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../include/c++/4.8.5/backward -internal-isystem /usr/local/include -internal-isystem /w/halld-scifs17exp/home/sdobbs/clang/llvm-project/install/lib/clang/12.0.0/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -O2 -std=c++11 -fdeprecated-macro -fdebug-compilation-dir /home/sdobbs/work/clang/halld_recon/src -ferror-limit 19 -fgnuc-version=4.2.1 -fcxx-exceptions -fexceptions -vectorize-loops -vectorize-slp -analyzer-output=html -faddrsig -o /tmp/scan-build-2021-01-21-110224-160369-1 -x c++ libraries/ANALYSIS/DParticleComboCreator.cc
1 | #include "ANALYSIS/DParticleComboCreator.h" |
2 | #include "ANALYSIS/DSourceComboer.h" |
3 | #include "ANALYSIS/DAnalysisUtilities.h" |
4 | |
5 | namespace DAnalysis |
6 | { |
7 | |
8 | DParticleComboCreator::DParticleComboCreator(JEventLoop* locEventLoop, const DSourceComboer* locSourceComboer, DSourceComboTimeHandler* locSourceComboTimeHandler, const DSourceComboVertexer* locSourceComboVertexer) : |
9 | dSourceComboer(locSourceComboer), dSourceComboTimeHandler(locSourceComboTimeHandler), dSourceComboVertexer(locSourceComboVertexer) |
10 | { |
11 | gPARMS->SetDefaultParameter("COMBO:DEBUG_LEVEL", dDebugLevel); |
12 | dKinFitUtils = new DKinFitUtils_GlueX(locEventLoop); |
13 | |
14 | Set_RunDependent_Data(locEventLoop); |
| 1 | Calling 'DParticleComboCreator::Set_RunDependent_Data' | |
|
15 | |
16 | dResourcePool_KinematicData.Set_ControlParams(20, 20, 200, 1000, 0); |
17 | dResourcePool_ParticleCombo.Set_ControlParams(100, 20, 1000, 3000, 0); |
18 | dResourcePool_ParticleComboStep.Set_ControlParams(100, 50, 1500, 4000, 0); |
19 | |
20 | vector<const DNeutralParticleHypothesis*> locNeutralParticleHypotheses; |
21 | locEventLoop->Get(locNeutralParticleHypotheses); |
22 | dNeutralParticleHypothesisFactory = static_cast<DNeutralParticleHypothesis_factory*>(locEventLoop->GetFactory("DNeutralParticleHypothesis")); |
23 | |
24 | vector<const DChargedTrackHypothesis*> locChargedTrackHypotheses; |
25 | locEventLoop->Get(locChargedTrackHypotheses); |
26 | dChargedTrackHypothesisFactory = static_cast<DChargedTrackHypothesis_factory*>(locEventLoop->GetFactory("DChargedTrackHypothesis")); |
27 | |
28 | vector<const DBeamPhoton*> locBeamPhotons; |
29 | locEventLoop->Get(locBeamPhotons); |
30 | dBeamPhotonfactory = static_cast<DBeamPhoton_factory*>(locEventLoop->GetFactory("DBeamPhoton")); |
31 | |
32 | |
33 | dVertexCovMatrix.ResizeTo(4, 4); |
34 | dVertexCovMatrix.Zero(); |
35 | dVertexCovMatrix(0, 0) = 0.65; |
36 | dVertexCovMatrix(1, 1) = 0.65; |
37 | dVertexCovMatrix(2, 2) = 1.5; |
38 | dVertexCovMatrix(3, 3) = 0.0; |
39 | } |
40 | |
41 | void DParticleComboCreator::Set_RunDependent_Data(JEventLoop *locEventLoop) |
42 | { |
43 | |
44 | DApplication* locApplication = dynamic_cast<DApplication*>(locEventLoop->GetJApplication()); |
45 | DGeometry* locGeometry = locApplication->GetDGeometry(locEventLoop->GetJEvent().GetRunNumber()); |
46 | |
47 | |
48 | double locTargetCenterZ = 65.0; |
49 | locGeometry->GetTargetZ(locTargetCenterZ); |
50 | dTargetCenter.SetXYZ(0.0, 0.0, locTargetCenterZ); |
51 | |
52 | locEventLoop->GetSingle(dParticleID); |
| 2 | | Calling 'JEventLoop::GetSingle' | |
|
53 | |
54 | dKinFitUtils->Set_RunDependent_Data(locEventLoop); |
55 | } |
56 | |
57 | void DParticleComboCreator::Reset(void) |
58 | { |
59 | if(dDebugLevel >= 5) |
60 | { |
61 | cout << "Total # of RF Bunches Allocated (All threads): " << dResourcePool_EventRFBunch.Get_NumObjectsAllThreads() << endl; |
62 | cout << "Total # of Particle Combo Steps Allocated (All threads): " << dResourcePool_ParticleComboStep.Get_NumObjectsAllThreads() << endl; |
63 | cout << "Total # of Particle Combos Allocated (All threads): " << dResourcePool_ParticleCombo.Get_NumObjectsAllThreads() << endl; |
64 | cout << "Total # of Charged Hypos (All threads): " << dChargedTrackHypothesisFactory->Get_NumObjectsAllThreads() << endl; |
65 | cout << "Total # of Neutral Hypos (All threads): " << dNeutralParticleHypothesisFactory->Get_NumObjectsAllThreads() << endl; |
66 | cout << "Total # of Beam Photons (All threads): " << dBeamPhotonfactory->Get_NumObjectsAllThreads() << endl; |
67 | cout << "Total # of KinematicDatas (All threads): " << dResourcePool_KinematicData.Get_NumObjectsAllThreads() << endl; |
68 | } |
69 | |
70 | for(const auto& locRFPair : dRFBunchMap) |
71 | dResourcePool_EventRFBunch.Recycle(locRFPair.second); |
72 | dRFBunchMap.clear(); |
73 | |
74 | dResourcePool_ParticleComboStep.Recycle(dCreated_ParticleComboStep); |
75 | dComboStepMap.clear(); |
76 | |
77 | dResourcePool_ParticleCombo.Recycle(dCreated_ParticleCombo); |
78 | dComboMap.clear(); |
79 | |
80 | dChargedTrackHypothesisFactory->Recycle_Hypotheses(dCreated_ChargedHypo); |
81 | dChargedHypoMap.clear(); |
82 | dKinFitChargedHypoMap.clear(); |
83 | |
84 | dNeutralParticleHypothesisFactory->Recycle_Hypotheses(dCreated_NeutralHypo); |
85 | dNeutralHypoMap.clear(); |
86 | dKinFitNeutralHypoMap.clear(); |
87 | |
88 | dBeamPhotonfactory->Recycle_Resources(dCreated_BeamPhoton); |
89 | dKinFitBeamPhotonMap.clear(); |
90 | |
91 | dResourcePool_KinematicData.Recycle(dCreated_KinematicData); |
92 | |
93 | |
94 | decltype(dCreated_KinematicData)().swap(dCreated_KinematicData); |
95 | decltype(dCreated_ParticleCombo)().swap(dCreated_ParticleCombo); |
96 | decltype(dCreated_ParticleComboStep)().swap(dCreated_ParticleComboStep); |
97 | decltype(dCreated_ChargedHypo)().swap(dCreated_ChargedHypo); |
98 | decltype(dCreated_NeutralHypo)().swap(dCreated_NeutralHypo); |
99 | decltype(dCreated_BeamPhoton)().swap(dCreated_BeamPhoton); |
100 | } |
101 | |
102 | bool DParticleComboCreator::Get_CreateNeutralErrorMatrixFlag_Combo(const DReactionVertexInfo* locReactionVertexInfo, DKinFitType locKinFitType) |
103 | { |
104 | |
105 | auto locDanglingIterator = dDanglingNeutralsFlagMap.find(locReactionVertexInfo); |
106 | bool locDanglingNeutralsFlag = false; |
107 | if(locDanglingIterator != dDanglingNeutralsFlagMap.end()) |
108 | locDanglingNeutralsFlag = locDanglingIterator->second; |
109 | else |
110 | { |
111 | for(auto locStepVertexInfo : locReactionVertexInfo->Get_StepVertexInfos()) |
112 | { |
113 | if(locStepVertexInfo->Get_FittableVertexFlag()) |
114 | continue; |
115 | if(!locStepVertexInfo->Get_OnlyConstrainTimeParticles().empty()) |
116 | { |
117 | locDanglingNeutralsFlag = true; |
118 | break; |
119 | } |
120 | if(!locStepVertexInfo->Get_NoConstrainParticles(true, d_FinalState, d_Neutral, false, false, false).empty()) |
121 | { |
122 | locDanglingNeutralsFlag = true; |
123 | break; |
124 | } |
125 | } |
126 | dDanglingNeutralsFlagMap.emplace(locReactionVertexInfo, locDanglingNeutralsFlag); |
127 | } |
128 | return ((locKinFitType != d_NoFit) && ((locKinFitType == d_P4Fit) || locDanglingNeutralsFlag)); |
129 | } |
130 | |
131 | const DParticleCombo* DParticleComboCreator::Build_ParticleCombo(const DReactionVertexInfo* locReactionVertexInfo, const DSourceCombo* locFullCombo, const DKinematicData* locBeamParticle, int locRFBunchShift, DKinFitType locKinFitType) |
132 | { |
133 | if(dDebugLevel > 0) |
134 | cout << "Building particle combo" << endl; |
135 | auto locCreateNeutralErrorMatrixFlag_Combo = Get_CreateNeutralErrorMatrixFlag_Combo(locReactionVertexInfo, locKinFitType); |
136 | auto locSpactimeIsFitFlag = ((locKinFitType == d_SpacetimeFit) || (locKinFitType == d_P4AndSpacetimeFit)); |
137 | auto locComboTuple = std::make_tuple(locReactionVertexInfo, locFullCombo, locBeamParticle, locRFBunchShift, locCreateNeutralErrorMatrixFlag_Combo); |
138 | auto locComboIterator = dComboMap.find(locComboTuple); |
139 | if(locComboIterator != dComboMap.end()) |
140 | { |
141 | if(dDebugLevel > 0) |
142 | cout << "Combo previously created, returning." << endl; |
143 | return locComboIterator->second; |
144 | } |
145 | |
146 | auto locParticleCombo = Get_ParticleComboResource(); |
147 | dComboMap.emplace(locComboTuple, locParticleCombo); |
148 | |
149 | auto locReaction = locReactionVertexInfo->Get_Reaction(); |
150 | auto locPrimaryVertexZ = dSourceComboVertexer->Get_PrimaryVertex(locReactionVertexInfo, locFullCombo, locBeamParticle).Z(); |
151 | |
152 | |
153 | const DEventRFBunch* locEventRFBunch = nullptr; |
154 | auto locRFIterator = dRFBunchMap.find(locRFBunchShift); |
155 | if(locRFIterator != dRFBunchMap.end()) |
156 | locEventRFBunch = locRFIterator->second; |
157 | else |
158 | { |
159 | auto locInitialEventRFBunch = dSourceComboTimeHandler->Get_InitialEventRFBunch(); |
160 | auto locNewEventRFBunch = dResourcePool_EventRFBunch.Get_Resource(); |
161 | locNewEventRFBunch->Reset(); |
162 | auto locRFTime = dSourceComboTimeHandler->Calc_RFTime(locRFBunchShift); |
163 | locNewEventRFBunch->Set_Content(locInitialEventRFBunch->dTimeSource, locRFTime, locInitialEventRFBunch->dTimeVariance, 0); |
164 | locEventRFBunch = locNewEventRFBunch; |
165 | dRFBunchMap.emplace(locRFBunchShift, locEventRFBunch); |
166 | } |
167 | locParticleCombo->Set_EventRFBunch(locEventRFBunch); |
168 | if(dDebugLevel >= 5) |
169 | cout << "RF Bunch set, shift = " << locRFBunchShift << endl; |
170 | |
171 | auto locReactionSteps = locReaction->Get_ReactionSteps(); |
172 | for(size_t loc_i = 0; loc_i < locReactionSteps.size(); ++loc_i) |
173 | { |
174 | if(dDebugLevel >= 5) |
175 | cout << "Step: " << loc_i << endl; |
176 | |
177 | auto locReactionStep = locReactionSteps[loc_i]; |
178 | auto locStepVertexInfo = locReactionVertexInfo->Get_StepVertexInfo(loc_i); |
179 | auto locStepBeamParticle = (loc_i == 0) ? locBeamParticle : nullptr; |
180 | auto locIsProductionVertex = locStepVertexInfo->Get_ProductionVertexFlag(); |
181 | |
182 | auto locVertexPrimaryCombo = dSourceComboer->Get_VertexPrimaryCombo(locFullCombo, locStepVertexInfo); |
183 | if(dDebugLevel >= 5) |
184 | { |
185 | cout << "VERTEX PRIMARY COMBO:" << endl; |
186 | Print_SourceCombo(locVertexPrimaryCombo); |
187 | } |
188 | |
189 | auto locSourceCombo = (loc_i == 0) ? locFullCombo : dSourceComboer->Get_StepSourceCombo(locReaction, loc_i, locVertexPrimaryCombo, locStepVertexInfo->Get_StepIndices().front()); |
190 | if(dDebugLevel >= 5) |
191 | { |
192 | cout << "STEP " << loc_i << ", SOURCE COMBO:" << endl; |
193 | Print_SourceCombo(locSourceCombo); |
194 | } |
195 | |
196 | bool locCreateNeutralErrorMatrixFlag = (locKinFitType != d_NoFit) && ((locKinFitType == d_P4Fit) || !locStepVertexInfo->Get_FittableVertexFlag()); |
197 | if(locReactionStep->Get_FinalPIDs(false, d_Neutral, false).empty()) |
198 | locCreateNeutralErrorMatrixFlag = false; |
199 | |
200 | |
201 | auto locStepTuple = std::make_tuple(*locReactionStep, locSourceCombo, locCreateNeutralErrorMatrixFlag, locIsProductionVertex, locFullCombo, locBeamParticle); |
202 | auto locStepIterator = dComboStepMap.find(locStepTuple); |
203 | if(locStepIterator != dComboStepMap.end()) |
204 | { |
205 | locParticleCombo->Add_ParticleComboStep(locStepIterator->second); |
206 | if(dDebugLevel >= 5) |
207 | cout << "step already created, reuse" << endl; |
208 | continue; |
209 | } |
210 | |
211 | |
212 | auto locParticleComboStep = Get_ParticleComboStepResource(); |
213 | |
214 | |
215 | auto locVertex = dSourceComboVertexer->Get_Vertex(locStepVertexInfo, locFullCombo, locBeamParticle, false); |
216 | if(dDebugLevel >= 20) |
217 | cout << "vertex: " << locVertex.X() << ", " << locVertex.Y() << ", " << locVertex.Z() << endl; |
218 | auto locTimeOffset = dSourceComboVertexer->Get_TimeOffset(locReactionVertexInfo, locStepVertexInfo, locFullCombo, locBeamParticle); |
219 | if(dDebugLevel >= 20) |
220 | cout << "time offset: " << locTimeOffset << endl; |
221 | |
222 | |
223 | auto locPropagatedRFTime = dSourceComboTimeHandler->Calc_PropagatedRFTime(locPrimaryVertexZ, locRFBunchShift, locTimeOffset); |
224 | if(dDebugLevel >= 20) |
225 | cout << "prop rf time: " << locPropagatedRFTime << endl; |
226 | DLorentzVector locSpacetimeVertex(locVertex, locPropagatedRFTime); |
227 | if(dDebugLevel >= 5) |
228 | cout << "spacetime vertex xyzt: " << locSpacetimeVertex.X() << ", " << locSpacetimeVertex.Y() << ", " << locSpacetimeVertex.Z() << ", " << locSpacetimeVertex.T() << endl; |
229 | |
230 | |
231 | if((locBeamParticle != nullptr) && (loc_i == 0)) |
232 | { |
233 | if(dDebugLevel >= 5) |
234 | cout << "beam particle set: " << locBeamParticle << endl; |
235 | locParticleComboStep->Set_InitialParticle(locBeamParticle); |
236 | } |
237 | else |
238 | locParticleComboStep->Set_InitialParticle(nullptr); |
239 | |
240 | |
241 | auto locFinalPIDs = locReactionStep->Get_FinalPIDs(); |
242 | map<Particle_t, size_t> locPIDCountMap; |
243 | vector<const DKinematicData*> locFinalParticles; |
244 | for(size_t loc_j = 0; loc_j < locFinalPIDs.size(); ++loc_j) |
245 | { |
246 | |
247 | if((int(loc_j) == locReactionStep->Get_MissingParticleIndex()) || (DAnalysis::Get_DecayStepIndex(locReaction, loc_i, loc_j) >= 0)) |
248 | { |
249 | locFinalParticles.push_back(nullptr); |
250 | continue; |
251 | } |
252 | |
253 | |
254 | auto locPID = locFinalPIDs[loc_j]; |
255 | auto locPIDIterator = locPIDCountMap.find(locPID); |
256 | if(locPIDIterator != locPIDCountMap.end()) |
257 | ++(locPIDIterator->second); |
258 | else |
259 | locPIDCountMap.emplace(locPID, 1); |
260 | |
261 | size_t locPIDCountSoFar = 0; |
262 | |
263 | auto locSourceParticle = DAnalysis::Get_SourceParticle_ThisStep(locSourceCombo, locPID, locPIDCountMap[locPID], locPIDCountSoFar); |
264 | if(dDebugLevel >= 5) |
265 | cout << "pid index, pid, source particle: " << loc_j << ", " << locPID << ", " << locSourceParticle << endl; |
266 | |
267 | |
268 | if(ParticleCharge(locPID) == 0) |
269 | { |
270 | auto locNeutralShower = static_cast<const DNeutralShower*>(locSourceParticle); |
271 | auto locHypoTuple = std::make_tuple(locNeutralShower, locPID, locRFBunchShift, locCreateNeutralErrorMatrixFlag, locIsProductionVertex, locFullCombo, locVertexPrimaryCombo, locBeamParticle); |
272 | const DNeutralParticleHypothesis* locNewNeutralHypo = nullptr; |
273 | |
274 | auto locHypoIterator = dNeutralHypoMap.find(locHypoTuple); |
275 | if(locHypoIterator != dNeutralHypoMap.end()) |
276 | locNewNeutralHypo = locHypoIterator->second; |
277 | else |
278 | { |
279 | |
280 | auto locCreateThisNeutralErrorMatrixFlag = locCreateNeutralErrorMatrixFlag ? true : ((ParticleMass(locPID) > 0.0) && !locSpactimeIsFitFlag); |
281 | auto locVertexCovMatrix = locCreateThisNeutralErrorMatrixFlag ? &dVertexCovMatrix : nullptr; |
282 | locNewNeutralHypo = dNeutralParticleHypothesisFactory->Create_DNeutralParticleHypothesis(locNeutralShower, locPID, locEventRFBunch, locSpacetimeVertex, locVertexCovMatrix, false); |
283 | assert(locNewNeutralHypo != nullptr); |
284 | dCreated_NeutralHypo.push_back(const_cast<DNeutralParticleHypothesis*>(locNewNeutralHypo)); |
285 | dNeutralHypoMap.emplace(locHypoTuple, locNewNeutralHypo); |
286 | } |
287 | |
288 | locFinalParticles.push_back(static_cast<const DKinematicData*>(locNewNeutralHypo)); |
289 | } |
290 | else |
291 | { |
292 | auto locChargedTrack = static_cast<const DChargedTrack*>(locSourceParticle); |
293 | auto locHypoTuple = std::make_tuple(locChargedTrack, locPID, locRFBunchShift, locIsProductionVertex, locFullCombo, locVertexPrimaryCombo, locBeamParticle); |
294 | const DChargedTrackHypothesis* locNewChargedHypo = nullptr; |
295 | |
296 | auto locHypoIterator = dChargedHypoMap.find(locHypoTuple); |
297 | if(locHypoIterator != dChargedHypoMap.end()) |
298 | locNewChargedHypo = locHypoIterator->second; |
299 | else |
300 | { |
301 | locNewChargedHypo = Create_ChargedHypo(locChargedTrack, locPID, locPropagatedRFTime, locIsProductionVertex, locFullCombo, locVertexPrimaryCombo, locBeamParticle, locSpacetimeVertex.Vect()); |
302 | dChargedHypoMap.emplace(locHypoTuple, locNewChargedHypo); |
303 | } |
304 | |
305 | locFinalParticles.push_back(static_cast<const DKinematicData*>(locNewChargedHypo)); |
306 | } |
307 | } |
308 | locParticleComboStep->Set_Contents(locStepBeamParticle, locFinalParticles, locSpacetimeVertex); |
309 | |
310 | |
311 | locParticleCombo->Add_ParticleComboStep(locParticleComboStep); |
312 | dComboStepMap.emplace(locStepTuple, locParticleComboStep); |
313 | } |
314 | |
315 | return locParticleCombo; |
316 | } |
317 | |
318 | const DChargedTrackHypothesis* DParticleComboCreator::Create_ChargedHypo(const DChargedTrack* locChargedTrack, Particle_t locPID, double locPropagatedRFTime, bool locIsProductionVertex, const DSourceCombo* locReactionFullCombo, const DSourceCombo* locVertexPrimaryFullCombo, const DKinematicData* locBeamParticle, DVector3 locVertex) |
319 | { |
320 | |
321 | auto locOrigHypo = locChargedTrack->Get_Hypothesis(locPID); |
322 | auto locNewHypo = dChargedTrackHypothesisFactory->Get_Resource(); |
323 | dCreated_ChargedHypo.push_back(locNewHypo); |
324 | locNewHypo->Share_FromInput(locOrigHypo, true, false, true, true); |
325 | |
326 | auto locTrackPOCAX4 = dSourceComboTimeHandler->Get_ChargedPOCAToVertexX4(locOrigHypo, locIsProductionVertex, locReactionFullCombo, locVertexPrimaryFullCombo, locBeamParticle, false, locVertex); |
327 | locNewHypo->Set_TimeAtPOCAToVertex(locTrackPOCAX4.T()); |
328 | |
329 | locNewHypo->Set_T0(locPropagatedRFTime, locOrigHypo->t0_err(), locOrigHypo->t0_detector()); |
330 | locNewHypo->AddAssociatedObject(locChargedTrack); |
331 | |
332 | dParticleID->Calc_ChargedPIDFOM(locNewHypo); |
333 | |
334 | return locNewHypo; |
335 | } |
336 | |
337 | const DParticleCombo* DParticleComboCreator::Create_KinFitCombo_NewCombo(const DParticleCombo* locOrigCombo, const DReaction* locReaction, const DKinFitResults* locKinFitResults, const shared_ptr<const DKinFitChain>& locKinFitChain) |
338 | { |
339 | if(dDebugLevel > 0) |
340 | cout << "Create kinfit combo" << endl; |
341 | dKinFitUtils->Set_UpdateCovarianceMatricesFlag(locReaction->Get_KinFitUpdateCovarianceMatricesFlag()); |
342 | |
343 | auto locNewCombo = Get_ParticleComboResource(); |
344 | locNewCombo->Set_KinFitResults(locKinFitResults); |
345 | locNewCombo->Set_EventRFBunch(locOrigCombo->Get_EventRFBunch()); |
346 | auto locOutputKinFitParticles = locKinFitResults->Get_OutputKinFitParticles(); |
347 | auto locOrigShiftedRFTime = locOrigCombo->Get_EventRFBunch()->dTime; |
348 | |
349 | for(size_t loc_j = 0; loc_j < locOrigCombo->Get_NumParticleComboSteps(); ++loc_j) |
350 | { |
351 | if(dDebugLevel >= 5) |
352 | cout << "Step: " << loc_j << endl; |
353 | auto locComboStep = locOrigCombo->Get_ParticleComboStep(loc_j); |
354 | auto locReactionStep = locReaction->Get_ReactionStep(loc_j); |
355 | |
356 | auto locNewComboStep = Get_ParticleComboStepResource(); |
357 | locNewCombo->Add_ParticleComboStep(locNewComboStep); |
358 | locNewComboStep->Set_MeasuredParticleComboStep(locComboStep); |
359 | |
360 | |
361 | locNewComboStep->Set_SpacetimeVertex(locComboStep->Get_SpacetimeVertex()); |
362 | Set_SpacetimeVertex(locReaction, locNewCombo, locOrigCombo, locNewComboStep, loc_j, locKinFitResults, locKinFitChain, locOrigShiftedRFTime); |
363 | auto locSpacetimeVertex = locNewComboStep->Get_SpacetimeVertex(); |
364 | if(dDebugLevel >= 5) |
365 | cout << "spacetime vertex set" << endl; |
366 | |
367 | |
368 | auto locInitialParticle_Measured = locComboStep->Get_InitialParticle_Measured(); |
369 | if(locInitialParticle_Measured != nullptr) |
370 | { |
371 | auto locKinFitParticle = locKinFitResults->Get_OutputKinFitParticle(locInitialParticle_Measured); |
372 | if(locKinFitParticle == NULL) |
373 | locNewComboStep->Set_InitialParticle(locInitialParticle_Measured); |
374 | else |
375 | { |
376 | locNewComboStep->Set_InitialParticle(Create_BeamPhoton_KinFit(static_cast<const DBeamPhoton*>(locInitialParticle_Measured), locKinFitParticle.get(), locSpacetimeVertex)); |
377 | locNewComboStep->Set_InitialKinFitParticle(locKinFitParticle); |
378 | } |
379 | } |
380 | else |
381 | Set_DecayingParticles(locReaction, locNewCombo, locOrigCombo, loc_j, locNewComboStep, locKinFitChain, locKinFitResults); |
382 | |
383 | |
384 | for(size_t loc_k = 0; loc_k < locComboStep->Get_NumFinalParticles(); ++loc_k) |
385 | { |
386 | auto locKinematicData_Measured = locComboStep->Get_FinalParticle_Measured(loc_k); |
387 | if(locReactionStep->Get_MissingParticleIndex() == int(loc_k)) |
388 | { |
389 | auto locMissingParticles = locKinFitResults->Get_OutputKinFitParticles(d_MissingParticle); |
390 | if(!locMissingParticles.empty()) |
391 | { |
392 | auto locNewKinematicData = Build_KinematicData(locKinFitResults, (*locMissingParticles.begin()).get(), locSpacetimeVertex, true); |
393 | locNewComboStep->Add_FinalParticle(locNewKinematicData); |
394 | } |
395 | else |
396 | locNewComboStep->Add_FinalParticle(NULL); |
397 | } |
398 | else if(locKinematicData_Measured == nullptr) |
399 | locNewComboStep->Add_FinalParticle(nullptr); |
400 | else if(ParticleCharge(locKinematicData_Measured->PID()) == 0) |
401 | { |
402 | auto locNeutralHypo = static_cast<const DNeutralParticleHypothesis*>(locKinematicData_Measured); |
403 | |
404 | auto locKinFitParticle = locKinFitResults->Get_OutputKinFitParticle(locNeutralHypo); |
405 | if(locKinFitParticle == NULL) |
406 | locKinFitParticle = locKinFitResults->Get_OutputKinFitParticle(locNeutralHypo->Get_NeutralShower()); |
407 | if(locKinFitParticle == NULL) |
408 | locNewComboStep->Add_FinalParticle(locKinematicData_Measured); |
409 | else |
410 | locNewComboStep->Add_FinalParticle(Create_NeutralHypo_KinFit(locNeutralHypo, locKinFitParticle.get(), locSpacetimeVertex.T())); |
411 | } |
412 | else |
413 | { |
414 | auto locChargedHypo = static_cast<const DChargedTrackHypothesis*>(locKinematicData_Measured); |
415 | auto locKinFitParticle = locKinFitResults->Get_OutputKinFitParticle(locChargedHypo); |
416 | if(locKinFitParticle == NULL) |
417 | locNewComboStep->Add_FinalParticle(locKinematicData_Measured); |
418 | else |
419 | { |
420 | auto locChargedTrack = static_cast<const DChargedTrack*>(locComboStep->Get_FinalParticle_SourceObject(loc_k)); |
421 | auto locNewHypo = Create_ChargedHypo_KinFit(locChargedTrack, locKinematicData_Measured->PID(), locKinFitParticle.get(), locSpacetimeVertex.T()); |
422 | locNewComboStep->Add_FinalParticle(locNewHypo); |
423 | } |
424 | } |
425 | } |
426 | } |
427 | |
428 | return locNewCombo; |
429 | } |
430 | |
431 | void DParticleComboCreator::Set_SpacetimeVertex(const DReaction* locReaction, const DParticleCombo* locNewParticleCombo, const DParticleCombo* locOldParticleCombo, DParticleComboStep* locNewParticleComboStep, size_t locStepIndex, const DKinFitResults* locKinFitResults, const shared_ptr<const DKinFitChain>& locKinFitChain, double locOrigShiftedRFTime) const |
432 | { |
433 | if(dDebugLevel >= 5) |
434 | cout << "DParticleComboCreator::Set_SpacetimeVertex" << endl; |
435 | |
436 | DKinFitType locKinFitType = locReaction->Get_KinFitType(); |
437 | if((locKinFitType == d_NoFit) || (locKinFitType == d_P4Fit)) |
438 | return; |
439 | |
440 | |
441 | |
442 | |
443 | auto locAllParticles = locKinFitChain->Get_KinFitChainStep(locStepIndex)->Get_FinalParticles(); |
444 | if(locAllParticles.empty()) |
445 | { |
446 | if(dDebugLevel >= 5) |
447 | cout << "somehow no particles at this step" << endl; |
448 | if(locStepIndex == 0) |
449 | { |
450 | size_t locNextStepIndex = 1; |
451 | while(locAllParticles.empty() && (locNextStepIndex < locKinFitChain->Get_NumKinFitChainSteps())) |
452 | { |
453 | locAllParticles = locKinFitChain->Get_KinFitChainStep(locNextStepIndex)->Get_FinalParticles(); |
454 | ++locNextStepIndex; |
455 | } |
456 | } |
457 | else |
458 | { |
459 | |
460 | auto locDecayFromStepIndex = Get_InitialParticleDecayFromIndices(locReaction, locStepIndex).first; |
461 | auto locPreviousParticleComboStep = locNewParticleCombo->Get_ParticleComboStep(locDecayFromStepIndex); |
462 | locNewParticleComboStep->Set_SpacetimeVertex(locPreviousParticleComboStep->Get_SpacetimeVertex()); |
463 | return; |
464 | } |
465 | } |
466 | |
467 | auto locKinFitParticle = locAllParticles[0]; |
468 | auto locParticleType = locKinFitParticle->Get_KinFitParticleType(); |
469 | if(dDebugLevel >= 20) |
470 | cout << "particle type, common vx param index, vx param index: " << locParticleType << ", " << int(locKinFitParticle->Get_CommonVxParamIndex()) << ", " << int(locKinFitParticle->Get_VxParamIndex()) << endl; |
471 | if((locParticleType == d_DetectedParticle) && (locKinFitParticle->Get_CommonVxParamIndex() < 0)) |
472 | return; |
473 | if((locParticleType != d_DetectedParticle) && (locKinFitParticle->Get_VxParamIndex() < 0)) |
474 | return; |
475 | |
476 | |
477 | TLorentzVector locSpacetimeVertex; |
478 | if(locKinFitParticle->Get_VertexP4AtProductionVertex()) |
479 | locSpacetimeVertex = locKinFitParticle->Get_SpacetimeVertex(); |
480 | else |
481 | locSpacetimeVertex = locKinFitParticle->Get_CommonSpacetimeVertex(); |
482 | locNewParticleComboStep->Set_SpacetimeVertex(locSpacetimeVertex); |
483 | |
484 | |
485 | if(dDebugLevel >= 20) |
486 | cout << "particle type, common t param index, t param index: " << locParticleType << ", " << int(locKinFitParticle->Get_CommonTParamIndex()) << ", " << int(locKinFitParticle->Get_TParamIndex()) << endl; |
487 | if((locParticleType == d_DetectedParticle) && (locKinFitParticle->Get_CommonTParamIndex() >= 0)) |
488 | return; |
489 | if((locParticleType != d_DetectedParticle) && (locKinFitParticle->Get_TParamIndex() >= 0)) |
490 | return; |
491 | |
492 | |
493 | if(locStepIndex == 0) |
494 | { |
495 | locSpacetimeVertex.SetT(locOrigShiftedRFTime + (locSpacetimeVertex.Z() - dTargetCenter.Z())/SPEED_OF_LIGHT); |
496 | if(dDebugLevel >= 5) |
497 | cout << "step 0: orig rf time, vertex-z, targz, shifted rf time: " << locOrigShiftedRFTime << ", " << locSpacetimeVertex.Z() << ", " << dTargetCenter.Z() << ", " << locSpacetimeVertex.T() << endl; |
498 | } |
499 | else |
500 | { |
501 | auto locDecayFromStepIndices = Get_InitialParticleDecayFromIndices(locReaction, locStepIndex); |
502 | if(dDebugLevel >= 20) |
503 | cout << "decay from indices: " << locDecayFromStepIndices.first << ", " << locDecayFromStepIndices.second << endl; |
504 | auto locPreviousParticleComboStep = locNewParticleCombo->Get_ParticleComboStep(locDecayFromStepIndices.first); |
505 | auto locPreviousSpacetimeVertex = locPreviousParticleComboStep->Get_SpacetimeVertex(); |
506 | if(dDebugLevel >= 20) |
507 | cout << "previous spacetime vertex: " << locPreviousSpacetimeVertex.X() << ", " << locPreviousSpacetimeVertex.Y() << ", " << locPreviousSpacetimeVertex.Z() << ", " << locPreviousSpacetimeVertex.T() << endl; |
508 | |
509 | auto locDecayingParticle = Get_DecayingParticle(locReaction, locOldParticleCombo, locStepIndex, locKinFitChain, locKinFitResults); |
510 | if((locDecayingParticle == nullptr) || !IsDetachedVertex(PDGtoPType(locDecayingParticle->Get_PID()))) |
511 | locSpacetimeVertex.SetT(locPreviousSpacetimeVertex.T()); |
512 | else |
513 | { |
514 | auto locBeta = locDecayingParticle->Get_P4().Beta(); |
515 | auto locPathLength = (locSpacetimeVertex.Vect() - locPreviousSpacetimeVertex.Vect()).Mag(); |
516 | auto locTime = locPreviousSpacetimeVertex.T() + locPathLength/(locBeta*SPEED_OF_LIGHT); |
517 | if(dDebugLevel >= 20) |
518 | cout << "calced beta, path, time: " << locBeta << ", " << locPathLength << ", " << locTime << endl; |
519 | locSpacetimeVertex.SetT(locTime); |
520 | } |
521 | } |
522 | |
523 | locNewParticleComboStep->Set_SpacetimeVertex(locSpacetimeVertex); |
524 | } |
525 | |
526 | void DParticleComboCreator::Set_DecayingParticles(const DReaction* locReaction, const DParticleCombo* locNewParticleCombo, const DParticleCombo* locOldParticleCombo, size_t locStepIndex, DParticleComboStep* locNewParticleComboStep, const shared_ptr<const DKinFitChain>& locKinFitChain, const DKinFitResults* locKinFitResults) |
527 | { |
528 | auto locKinFitParticle = Get_DecayingParticle(locReaction, locOldParticleCombo, locStepIndex, locKinFitChain, locKinFitResults); |
529 | if(locKinFitParticle == nullptr) |
530 | { |
531 | locNewParticleComboStep->Set_InitialParticle(nullptr); |
532 | return; |
533 | } |
534 | |
535 | auto locEventVertex = locOldParticleCombo->Get_ParticleComboStep(0)->Get_SpacetimeVertex().Vect(); |
536 | auto locPID = PDGtoPType(locKinFitParticle->Get_PID()); |
537 | auto locFromStepIndex = DAnalysis::Get_InitialParticleDecayFromIndices(locReaction, locStepIndex).first; |
538 | |
539 | auto locProductionSpacetimeVertex = locNewParticleCombo->Get_ParticleComboStep(locFromStepIndex)->Get_SpacetimeVertex(); |
540 | auto locKinematicData_Production = Build_KinematicData(locKinFitResults, locKinFitParticle.get(), locProductionSpacetimeVertex, true); |
541 | |
542 | bool locCreate2ndObjectFlag = (IsDetachedVertex(locPID) && (locStepIndex != 0) && (locFromStepIndex >= 0)); |
543 | auto locDecaySpacetimeVertex = locNewParticleCombo->Get_ParticleComboStep(locStepIndex)->Get_SpacetimeVertex(); |
544 | auto locKinematicData_Decay = locCreate2ndObjectFlag ? Build_KinematicData(locKinFitResults, locKinFitParticle.get(), locDecaySpacetimeVertex, false) : locKinematicData_Production; |
545 | |
546 | locNewParticleComboStep->Set_InitialParticle(locKinematicData_Decay); |
547 | locNewParticleComboStep->Set_InitialKinFitParticle(locKinFitParticle); |
548 | |
549 | |
550 | if((locStepIndex == 0) || (locFromStepIndex < 0)) |
551 | return; |
552 | |
553 | auto locParticleComboStep = const_cast<DParticleComboStep*>(locNewParticleCombo->Get_ParticleComboStep(locFromStepIndex)); |
554 | |
555 | for(size_t loc_i = 0; loc_i < locParticleComboStep->Get_NumFinalParticles(); ++loc_i) |
556 | { |
557 | auto locDecayStepIndex = DAnalysis::Get_DecayStepIndex(locReaction, locFromStepIndex, loc_i); |
558 | if(locDecayStepIndex != int(locStepIndex)) |
559 | continue; |
560 | locParticleComboStep->Set_FinalParticle(locKinematicData_Production, loc_i); |
561 | break; |
562 | } |
563 | } |
564 | |
565 | shared_ptr<DKinFitParticle> DParticleComboCreator::Get_DecayingParticle(const DReaction* locReaction, const DParticleCombo* locOldParticleCombo, size_t locComboStepIndex, const shared_ptr<const DKinFitChain>& locKinFitChain, const DKinFitResults* locKinFitResults) const |
566 | { |
567 | auto locReactionStep = locReaction->Get_ReactionStep(locComboStepIndex); |
568 | Particle_t locPID = locReactionStep->Get_InitialPID(); |
569 | if(!IsFixedMass(locPID)) |
570 | return nullptr; |
571 | |
572 | |
573 | for(size_t loc_i = 0; loc_i < locKinFitChain->Get_NumKinFitChainSteps(); ++loc_i) |
574 | { |
575 | auto locKinFitChainStep = locKinFitChain->Get_KinFitChainStep(loc_i); |
576 | |
577 | |
578 | shared_ptr<DKinFitParticle> locDecayingParticle = nullptr; |
579 | auto locInitialParticles = locKinFitChainStep->Get_InitialParticles(); |
580 | for(auto locKinFitParticle : locInitialParticles) |
581 | { |
582 | if(locKinFitParticle == nullptr) |
583 | continue; |
584 | if(locKinFitParticle->Get_KinFitParticleType() != d_DecayingParticle) |
585 | continue; |
586 | locDecayingParticle = locKinFitParticle; |
587 | break; |
588 | } |
589 | if(locDecayingParticle == nullptr) |
590 | continue; |
591 | if(PDGtoPType(locDecayingParticle->Get_PID()) != locPID) |
592 | continue; |
593 | |
594 | |
595 | |
596 | |
597 | |
598 | |
599 | auto locMeasuredParticles = locOldParticleCombo->Get_DecayChainParticles_Measured(locReaction, locComboStepIndex); |
600 | const DKinematicData* locMeasuredParticle = locMeasuredParticles[0]; |
601 | auto locKinFitParticle = locKinFitResults->Get_OutputKinFitParticle(locMeasuredParticle); |
602 | if(locKinFitParticle == NULL) |
603 | { |
604 | const DNeutralShower* locNeutralShower = static_cast<const DNeutralParticleHypothesis*>(locMeasuredParticle)->Get_NeutralShower(); |
605 | locKinFitParticle = locKinFitResults->Get_OutputKinFitParticle(locNeutralShower); |
606 | } |
607 | |
608 | if(!Search_ForParticleInDecay(locKinFitChain, loc_i, locKinFitParticle)) |
609 | continue; |
610 | |
611 | |
612 | return locDecayingParticle; |
613 | } |
614 | |
615 | return NULL; |
616 | } |
617 | |
618 | bool DParticleComboCreator::Search_ForParticleInDecay(const shared_ptr<const DKinFitChain>& locKinFitChain, size_t locStepToSearch, const shared_ptr<DKinFitParticle>& locParticleToFind) const |
619 | { |
620 | auto locKinFitChainStep = locKinFitChain->Get_KinFitChainStep(locStepToSearch); |
621 | auto locFinalParticles = locKinFitChainStep->Get_FinalParticles(); |
622 | std::sort(locFinalParticles.begin(), locFinalParticles.end()); |
623 | if(std::binary_search(locFinalParticles.begin(), locFinalParticles.end(), locParticleToFind)) |
624 | return true; |
625 | |
626 | |
627 | for(auto locKinFitParticle : locFinalParticles) |
628 | { |
629 | if(locKinFitParticle == nullptr) |
630 | continue; |
631 | if(locKinFitParticle->Get_KinFitParticleType() != d_DecayingParticle) |
632 | continue; |
633 | |
634 | int locDecayStepIndex = locKinFitChain->Get_DecayStepIndex(locKinFitParticle); |
635 | if(Search_ForParticleInDecay(locKinFitChain, locDecayStepIndex, locParticleToFind)) |
636 | return true; |
637 | } |
638 | return false; |
639 | } |
640 | |
641 | const DBeamPhoton* DParticleComboCreator::Create_BeamPhoton_KinFit(const DBeamPhoton* locBeamPhoton, const DKinFitParticle* locKinFitParticle, const DLorentzVector& locSpacetimeVertex) |
642 | { |
643 | auto locBeamIterator = dKinFitBeamPhotonMap.find(locKinFitParticle); |
644 | if(locBeamIterator != dKinFitBeamPhotonMap.end()) |
645 | return locBeamIterator->second; |
646 | |
647 | DBeamPhoton* locNewBeamPhoton = dBeamPhotonfactory->Get_Resource(); |
648 | dCreated_BeamPhoton.push_back(locNewBeamPhoton); |
649 | dKinFitBeamPhotonMap.emplace(locKinFitParticle, locNewBeamPhoton); |
650 | |
651 | locNewBeamPhoton->dCounter = locBeamPhoton->dCounter; |
652 | locNewBeamPhoton->dSystem = locBeamPhoton->dSystem; |
653 | locNewBeamPhoton->setPID(locBeamPhoton->PID()); |
654 | locNewBeamPhoton->setMomentum(DVector3(locKinFitParticle->Get_Momentum().X(),locKinFitParticle->Get_Momentum().Y(),locKinFitParticle->Get_Momentum().Z())); |
655 | if(locKinFitParticle->Get_CommonVxParamIndex() >= 0) |
656 | locNewBeamPhoton->setPosition(DVector3(locKinFitParticle->Get_Position().X(),locKinFitParticle->Get_Position().Y(),locKinFitParticle->Get_Position().Z())); |
657 | else |
658 | locNewBeamPhoton->setPosition(locSpacetimeVertex.Vect()); |
659 | if(locKinFitParticle->Get_CommonTParamIndex() >= 0) |
660 | locNewBeamPhoton->setTime(locKinFitParticle->Get_Time()); |
661 | else |
662 | locNewBeamPhoton->setTime(locBeamPhoton->time() + (locNewBeamPhoton->position().Z() - locBeamPhoton->position().Z())/SPEED_OF_LIGHT); |
663 | locNewBeamPhoton->setErrorMatrix(locKinFitParticle->Get_CovarianceMatrix()); |
664 | return locNewBeamPhoton; |
665 | } |
666 | |
667 | const DChargedTrackHypothesis* DParticleComboCreator::Create_ChargedHypo_KinFit(const DChargedTrack* locChargedTrack, Particle_t locPID, const DKinFitParticle* locKinFitParticle, double locPropagatedRFTime) |
668 | { |
669 | auto locOrigHypo = locChargedTrack->Get_Hypothesis(locPID); |
670 | auto locHypoIterator = dKinFitChargedHypoMap.find(locKinFitParticle); |
671 | if(locHypoIterator != dKinFitChargedHypoMap.end()) |
672 | return locHypoIterator->second; |
673 | |
674 | |
675 | auto locNewHypo = dChargedTrackHypothesisFactory->Get_Resource(); |
676 | dKinFitChargedHypoMap.emplace(locKinFitParticle, locNewHypo); |
677 | dCreated_ChargedHypo.push_back(locNewHypo); |
678 | locNewHypo->setPID(locPID); |
679 | locNewHypo->AddAssociatedObject(locChargedTrack); |
680 | |
681 | |
682 | TVector3 locFitMomentum = locKinFitParticle->Get_Momentum(); |
683 | TVector3 locFitVertex = locKinFitParticle->Get_Position(); |
684 | locNewHypo->setMomentum(DVector3(locFitMomentum.X(), locFitMomentum.Y(), locFitMomentum.Z())); |
685 | locNewHypo->setPosition(DVector3(locFitVertex.X(), locFitVertex.Y(), locFitVertex.Z())); |
686 | |
687 | |
688 | locNewHypo->setTime(locKinFitParticle->Get_Time()); |
689 | locNewHypo->setErrorMatrix(locKinFitParticle->Get_CovarianceMatrix()); |
690 | |
691 | |
692 | |
693 | if(locKinFitParticle->Get_CommonTParamIndex() >= 0) |
694 | { |
695 | locNewHypo->Share_FromInput(locOrigHypo, true, true, true, false); |
696 | return locNewHypo; |
697 | } |
698 | |
699 | |
700 | locNewHypo->Share_FromInput(locOrigHypo, true, false, false, false); |
701 | |
702 | |
703 | if(locKinFitParticle->Get_CommonVxParamIndex() >= 0) |
704 | { |
705 | |
706 | locNewHypo->Set_T0(locPropagatedRFTime, locOrigHypo->t0_err(), locOrigHypo->t0_detector()); |
707 | locNewHypo->Set_TimeAtPOCAToVertex(locNewHypo->time()); |
708 | } |
709 | else |
710 | { |
711 | locNewHypo->Set_T0(locOrigHypo->t0(), locOrigHypo->t0_err(), locOrigHypo->t0_detector()); |
712 | locNewHypo->Set_TimeAtPOCAToVertex(locOrigHypo->Get_TimeAtPOCAToVertex() + locNewHypo->time() - locOrigHypo->time()); |
713 | } |
714 | |
715 | dParticleID->Calc_ChargedPIDFOM(locNewHypo); |
716 | return locNewHypo; |
717 | } |
718 | |
719 | const DNeutralParticleHypothesis* DParticleComboCreator::Create_NeutralHypo_KinFit(const DNeutralParticleHypothesis* locOrigHypo, DKinFitParticle* locKinFitParticle, double locPropagatedRFTime) |
720 | { |
721 | auto locHypoIterator = dKinFitNeutralHypoMap.find(locKinFitParticle); |
722 | if(locHypoIterator != dKinFitNeutralHypoMap.end()) |
723 | return locHypoIterator->second; |
724 | |
725 | auto locNewHypo = dNeutralParticleHypothesisFactory->Get_Resource(); |
726 | dCreated_NeutralHypo.push_back(locNewHypo); |
727 | dKinFitNeutralHypoMap.emplace(locKinFitParticle, locNewHypo); |
728 | locNewHypo->setPID(locOrigHypo->PID()); |
729 | locNewHypo->Set_NeutralShower(locOrigHypo->Get_NeutralShower()); |
730 | |
731 | |
732 | auto locWasNeutralShowerInFit = (locKinFitParticle->Get_EParamIndex() >= 0); |
733 | TVector3 locFitMomentum = locKinFitParticle->Get_Momentum(); |
734 | TVector3 locFitVertex = locWasNeutralShowerInFit ? locKinFitParticle->Get_CommonVertex() : locKinFitParticle->Get_Position(); |
735 | locNewHypo->setMomentum(DVector3(locFitMomentum.X(), locFitMomentum.Y(), locFitMomentum.Z())); |
736 | locNewHypo->setPosition(DVector3(locFitVertex.X(), locFitVertex.Y(), locFitVertex.Z())); |
737 | |
738 | |
739 | auto locTime = locWasNeutralShowerInFit ? locKinFitParticle->Get_CommonTime() : locKinFitParticle->Get_Time(); |
740 | locNewHypo->setTime(locTime); |
741 | locNewHypo->setErrorMatrix(locKinFitParticle->Get_CovarianceMatrix()); |
742 | |
743 | |
744 | |
745 | |
746 | if((locKinFitParticle->Get_CommonVxParamIndex() < 0) || (locKinFitParticle->Get_CommonTParamIndex() >= 0)) |
747 | { |
748 | locNewHypo->Share_FromInput(locOrigHypo, true, false); |
749 | return locNewHypo; |
750 | } |
751 | |
752 | |
753 | if(dDebugLevel >= 20) |
754 | cout << "orig hypo time, orig vertz, new hypo time, new hypo vertz, t0: " << locOrigHypo->time() << ", " << locOrigHypo->position().Z() << ", " << locNewHypo->time() << ", " << locNewHypo->position().Z() << ", " << locPropagatedRFTime << endl; |
755 | locNewHypo->Set_T0(locPropagatedRFTime, locOrigHypo->t0_err(), locOrigHypo->t0_detector()); |
756 | |
757 | |
758 | unsigned int locNDF = 0; |
759 | double locChiSq = 0.0; |
760 | double locFOM = -1.0; |
761 | if(locNewHypo->PID() == Gamma) |
762 | { |
763 | double locTimePull = 0.0; |
764 | |
765 | locChiSq = dParticleID->Calc_TimingChiSq(locNewHypo, locNDF, locTimePull); |
766 | locFOM = TMath::Prob(locChiSq, locNDF); |
767 | } |
768 | locNewHypo->Set_ChiSq_Overall(locChiSq, locNDF, locFOM); |
769 | |
770 | return locNewHypo; |
771 | } |
772 | |
773 | DKinematicData* DParticleComboCreator::Build_KinematicData(const DKinFitResults* locKinFitResults, DKinFitParticle* locKinFitParticle, DLorentzVector locSpacetimeVertex, bool locProductionVertexFlag) |
774 | { |
775 | auto locKinematicData = dResourcePool_KinematicData.Get_Resource(); |
776 | dCreated_KinematicData.push_back(locKinematicData); |
777 | auto locPID = PDGtoPType(locKinFitParticle->Get_PID()); |
778 | locKinematicData->setPID(locPID); |
779 | |
780 | |
781 | |
782 | if((locProductionVertexFlag == locKinFitParticle->Get_VertexP4AtProductionVertex()) || (locKinFitParticle->Get_VxParamIndex() < 0) || !IsDetachedVertex(locPID)) |
783 | { |
784 | locKinematicData->setMomentum(DVector3(locKinFitParticle->Get_Momentum().X(),locKinFitParticle->Get_Momentum().Y(),locKinFitParticle->Get_Momentum().Z())); |
785 | if(locKinFitParticle->Get_VxParamIndex() < 0) |
786 | locKinematicData->setPosition(locSpacetimeVertex.Vect()); |
787 | else |
788 | { |
789 | auto locVertex = locKinFitParticle->Get_Position(); |
790 | locKinematicData->setPosition(DVector3(locVertex.X(), locVertex.Y(), locVertex.Z())); |
791 | } |
792 | if(locKinFitParticle->Get_TParamIndex() < 0) |
793 | locKinematicData->setTime(locSpacetimeVertex.T()); |
794 | else |
795 | locKinematicData->setTime(locKinFitParticle->Get_Time()); |
796 | locKinematicData->setErrorMatrix(locKinFitParticle->Get_CovarianceMatrix()); |
797 | } |
798 | else |
799 | dKinFitUtils->Propagate_TrackInfoToCommonVertex(locKinematicData, locKinFitParticle, &locKinFitResults->Get_VXi()); |
800 | |
801 | |
802 | return locKinematicData; |
803 | } |
804 | |
805 | const DParticleCombo* DParticleComboCreator::Build_ThrownCombo(JEventLoop* locEventLoop) |
806 | { |
807 | deque<pair<const DMCThrown*, deque<const DMCThrown*> > > locThrownSteps; |
808 | if(dAnalysisUtilities == nullptr) |
809 | locEventLoop->GetSingle(dAnalysisUtilities); |
810 | dAnalysisUtilities->Get_ThrownParticleSteps(locEventLoop, locThrownSteps); |
811 | if(locThrownSteps.empty()) |
812 | return nullptr; |
813 | |
814 | vector<const DReaction*> locReactions; |
815 | locEventLoop->Get(locReactions, "Thrown"); |
816 | return Build_ThrownCombo(locEventLoop, locReactions[0], locThrownSteps); |
817 | } |
818 | |
819 | const DParticleCombo* DParticleComboCreator::Build_ThrownCombo(JEventLoop* locEventLoop, const DReaction* locThrownReaction, deque<pair<const DMCThrown*, deque<const DMCThrown*> > >& locThrownSteps) |
820 | { |
821 | auto locThrownComboTuple = std::make_tuple((const DReactionVertexInfo*)nullptr, (const DSourceCombo*)nullptr, (const DKinematicData*)nullptr, 1, true); |
822 | auto locComboMapIterator = dComboMap.find(locThrownComboTuple); |
823 | if(locComboMapIterator != dComboMap.end()) |
824 | return locComboMapIterator->second; |
825 | |
826 | vector<const DMCReaction*> locMCReactions; |
827 | locEventLoop->Get(locMCReactions); |
828 | |
829 | vector<const DEventRFBunch*> locEventRFBunches; |
830 | locEventLoop->Get(locEventRFBunches, "Thrown"); |
831 | |
832 | auto locParticleCombo = Get_ParticleComboResource(); |
833 | auto locParticleComboStep = Get_ParticleComboStepResource(); |
834 | locParticleCombo->Set_EventRFBunch(locEventRFBunches[0]); |
835 | |
836 | locParticleComboStep->Set_InitialParticle(&locMCReactions[0]->beam); |
837 | locParticleComboStep->Set_SpacetimeVertex(DLorentzVector(locMCReactions[0]->beam.position(), locMCReactions[0]->beam.time())); |
838 | |
839 | for(size_t loc_i = 0; loc_i < locThrownSteps.size(); ++loc_i) |
840 | { |
841 | if(loc_i != 0) |
842 | { |
843 | auto locMCThrown = locThrownSteps[loc_i].first; |
844 | locParticleComboStep = Get_ParticleComboStepResource(); |
845 | |
846 | int locInitialParticleDecayFromStepIndex = -1; |
847 | for(size_t loc_j = 0; loc_j < loc_i; ++loc_j) |
848 | { |
849 | for(size_t loc_k = 0; loc_k < locThrownSteps[loc_j].second.size(); ++loc_k) |
850 | { |
851 | if(locMCThrown != locThrownSteps[loc_j].second[loc_k]) |
852 | continue; |
853 | locInitialParticleDecayFromStepIndex = loc_j; |
854 | break; |
855 | } |
856 | if(locInitialParticleDecayFromStepIndex != -1) |
857 | break; |
858 | } |
859 | locParticleComboStep->Set_InitialParticle(locMCThrown); |
860 | locParticleComboStep->Set_SpacetimeVertex(DLorentzVector(locMCThrown->position(), locMCThrown->time())); |
861 | } |
862 | for(size_t loc_j = 0; loc_j < locThrownSteps[loc_i].second.size(); ++loc_j) |
863 | locParticleComboStep->Add_FinalParticle(locThrownSteps[loc_i].second[loc_j]); |
864 | locParticleCombo->Add_ParticleComboStep(locParticleComboStep); |
865 | } |
866 | |
867 | dComboMap.emplace(locThrownComboTuple, locParticleCombo); |
868 | return locParticleCombo; |
869 | } |
870 | |
871 | } |
1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | #ifndef _JEventLoop_ |
9 | #define _JEventLoop_ |
10 | |
11 | #include <sys/time.h> |
12 | |
13 | #include <vector> |
14 | #include <list> |
15 | #include <string> |
16 | #include <utility> |
17 | #include <typeinfo> |
18 | #include <string.h> |
19 | #include <map> |
20 | #include <utility> |
21 | using std::vector; |
22 | using std::list; |
23 | using std::string; |
24 | using std::type_info; |
25 | |
26 | #include <JANA/jerror.h> |
27 | #include <JANA/JObject.h> |
28 | #include <JANA/JException.h> |
29 | #include <JANA/JEvent.h> |
30 | #include <JANA/JThread.h> |
31 | #include <JANA/JFactory_base.h> |
32 | #include <JANA/JCalibration.h> |
33 | #include <JANA/JGeometry.h> |
34 | #include <JANA/JResourceManager.h> |
35 | #include <JANA/JStreamLog.h> |
36 | |
37 | |
38 | #include "cint.h" |
39 | |
40 | |
41 | |
42 | namespace jana{ |
43 | |
44 | |
45 | template<class T> class JFactory; |
46 | class JApplication; |
47 | class JEventProcessor; |
48 | |
49 | |
50 | class JEventLoop{ |
51 | public: |
52 | |
53 | friend class JApplication; |
54 | |
55 | enum data_source_t{ |
56 | DATA_NOT_AVAILABLE = 1, |
57 | DATA_FROM_CACHE, |
58 | DATA_FROM_SOURCE, |
59 | DATA_FROM_FACTORY |
60 | }; |
61 | |
62 | typedef struct{ |
63 | string caller_name; |
64 | string caller_tag; |
65 | string callee_name; |
66 | string callee_tag; |
67 | double start_time; |
68 | double end_time; |
69 | data_source_t data_source; |
70 | }call_stack_t; |
71 | |
72 | typedef struct{ |
73 | const char* factory_name; |
74 | string tag; |
75 | const char* filename; |
76 | int line; |
77 | }error_call_stack_t; |
78 | |
79 | JEventLoop(JApplication *app); |
80 | virtual ~JEventLoop(); |
81 | virtual const char* className(void){return static_className();} |
82 | static const char* static_className(void){return "JEventLoop";} |
83 | |
84 | JApplication* GetJApplication(void) const {return app;} |
85 | void RefreshProcessorListFromJApplication(void); |
86 | virtual jerror_t AddFactory(JFactory_base* factory); |
87 | jerror_t RemoveFactory(JFactory_base* factory); |
88 | JFactory_base* GetFactory(const string data_name, const char *tag="", bool allow_deftag=true); |
89 | vector<JFactory_base*> GetFactories(void) const {return factories;} |
90 | void GetFactoryNames(vector<string> &factorynames); |
91 | void GetFactoryNames(map<string,string> &factorynames); |
92 | map<string,string> GetDefaultTags(void) const {return default_tags;} |
93 | jerror_t ClearFactories(void); |
94 | jerror_t PrintFactories(int sparsify=0); |
95 | jerror_t Print(const string data_name, const char *tag=""); |
96 | |
97 | JCalibration* GetJCalibration(); |
98 | template<class T> bool GetCalib(string namepath, map<string,T> &vals); |
99 | template<class T> bool GetCalib(string namepath, vector<T> &vals); |
100 | template<class T> bool GetCalib(string namepath, T &val); |
101 | |
102 | JGeometry* GetJGeometry(); |
103 | template<class T> bool GetGeom(string namepath, map<string,T> &vals); |
104 | template<class T> bool GetGeom(string namepath, T &val); |
105 | |
106 | JResourceManager* GetJResourceManager(void); |
107 | string GetResource(string namepath); |
108 | template<class T> bool GetResource(string namepath, T vals, int event_number=0); |
109 | |
110 | void Initialize(void); |
111 | jerror_t Loop(void); |
112 | jerror_t OneEvent(uint64_t event_number); |
113 | jerror_t OneEvent(void); |
114 | inline void Pause(void){pause = 1;} |
115 | inline void Resume(void){pause = 0;} |
116 | inline void Quit(void){quit = 1;} |
117 | inline bool GetQuit(void) const {return quit;} |
118 | void QuitProgram(void); |
119 | |
120 | |
121 | bool HasRandomAccess(void); |
122 | void AddToEventQueue(uint64_t event_number){ next_events_to_process.push_back(event_number); } |
123 | void AddToEventQueue(list<uint64_t> &event_numbers) { next_events_to_process.insert(next_events_to_process.end(), event_numbers.begin(), event_numbers.end()); } |
124 | list<uint64_t> GetEventQueue(void){ return next_events_to_process; } |
125 | void ClearEventQueue(void){ next_events_to_process.clear(); } |
126 | |
127 | template<class T> JFactory<T>* GetSingle(const T* &t, const char *tag="", bool exception_if_not_one=true); |
128 | template<class T> JFactory<T>* Get(vector<const T*> &t, const char *tag="", bool allow_deftag=true); |
129 | template<class T> JFactory<T>* GetFromFactory(vector<const T*> &t, const char *tag="", data_source_t &data_source=null_data_source, bool allow_deftag=true); |
130 | template<class T> jerror_t GetFromSource(vector<const T*> &t, JFactory_base *factory=NULL); |
131 | inline JEvent& GetJEvent(void){return event;} |
132 | inline void SetJEvent(JEvent *event){this->event = *event;} |
133 | inline void SetAutoFree(int auto_free){this->auto_free = auto_free;} |
134 | inline pthread_t GetPThreadID(void) const {return pthread_id;} |
135 | double GetInstantaneousRate(void) const {return rate_instantaneous;} |
136 | double GetIntegratedRate(void) const {return rate_integrated;} |
137 | double GetLastEventProcessingTime(void) const {return delta_time_single;} |
138 | unsigned int GetNevents(void) const {return Nevents;} |
139 | |
140 | inline bool CheckEventBoundary(uint64_t event_numberA, uint64_t event_numberB); |
141 | |
142 | inline bool GetCallStackRecordingStatus(void){ return record_call_stack; } |
143 | inline void DisableCallStackRecording(void){ record_call_stack = false; } |
144 | inline void EnableCallStackRecording(void){ record_call_stack = true; } |
145 | inline void CallStackStart(JEventLoop::call_stack_t &cs, const string &caller_name, const string &caller_tag, const string callee_name, const string callee_tag); |
146 | inline void CallStackEnd(JEventLoop::call_stack_t &cs); |
147 | inline vector<call_stack_t> GetCallStack(void){return call_stack;} |
148 | inline void AddToCallStack(call_stack_t &cs){if(record_call_stack) call_stack.push_back(cs);} |
149 | inline void AddToErrorCallStack(error_call_stack_t &cs){error_call_stack.push_back(cs);} |
150 | inline vector<error_call_stack_t> GetErrorCallStack(void){return error_call_stack;} |
151 | void PrintErrorCallStack(void); |
152 | |
153 | const JObject* FindByID(JObject::oid_t id); |
154 | template<class T> const T* FindByID(JObject::oid_t id); |
155 | JFactory_base* FindOwner(const JObject *t); |
156 | JFactory_base* FindOwner(JObject::oid_t id); |
157 | |
158 | |
159 | template<class T> void SetRef(T *t); |
160 | template<class T> T* GetRef(void); |
161 | template<class T> vector<T*> GetRefsT(void); |
162 | vector<pair<const char*, void*> > GetRefs(void){ return user_refs; } |
163 | template<class T> void RemoveRef(T *t); |
164 | |
165 | |
166 | uint64_t GetStatus(void){return event.GetStatus();} |
167 | bool GetStatusBit(uint32_t bit){return event.GetStatusBit(bit);} |
168 | bool SetStatusBit(uint32_t bit, bool val=true){return event.SetStatusBit(bit, val);} |
169 | bool ClearStatusBit(uint32_t bit){return event.ClearStatusBit(bit);} |
170 | void ClearStatus(void){event.ClearStatus();} |
171 | void SetStatusBitDescription(uint32_t bit, string description){event.SetStatusBitDescription(bit, description);} |
172 | string GetStatusBitDescription(uint32_t bit){return event.GetStatusBitDescription(bit);} |
173 | void GetStatusBitDescriptions(map<uint32_t, string> &status_bit_descriptions){return event.GetStatusBitDescriptions(status_bit_descriptions);} |
174 | string StatusWordToString(void); |
175 | |
176 | private: |
177 | JEvent event; |
178 | vector<JFactory_base*> factories; |
179 | vector<JEventProcessor*> processors; |
180 | vector<error_call_stack_t> error_call_stack; |
181 | vector<call_stack_t> call_stack; |
182 | JApplication *app; |
183 | JThread *jthread; |
184 | bool initialized; |
185 | bool print_parameters_called; |
186 | int pause; |
187 | int quit; |
188 | int auto_free; |
189 | pthread_t pthread_id; |
190 | map<string, string> default_tags; |
191 | vector<pair<string,string> > auto_activated_factories; |
192 | bool record_call_stack; |
193 | string caller_name; |
194 | string caller_tag; |
195 | vector<uint64_t> event_boundaries; |
196 | int32_t event_boundaries_run; |
197 | list<uint64_t> next_events_to_process; |
198 | |
199 | uint64_t Nevents; |
200 | uint64_t Nevents_rate; |
201 | double delta_time_single; |
202 | double delta_time_rate; |
203 | double delta_time; |
204 | double rate_instantaneous; |
205 | double rate_integrated; |
206 | |
207 | static data_source_t null_data_source; |
208 | |
209 | vector<pair<const char*, void*> > user_refs; |
210 | }; |
211 | |
212 | |
213 | |
214 | #ifdef G__DICTIONARY |
215 | typedef JEventLoop::call_stack_t call_stack_t; |
216 | typedef JEventLoop::error_call_stack_t error_call_stack_t; |
217 | #endif |
218 | |
219 | #if !defined(__CINT__) && !defined(__CLING__) |
220 | |
221 | |
222 | |
223 | |
224 | template<class T> |
225 | JFactory<T>* JEventLoop::GetSingle(const T* &t, const char *tag, bool exception_if_not_one) |
226 | { |
227 | |
228 | |
229 | |
230 | |
231 | |
232 | |
233 | |
234 | |
235 | |
236 | |
237 | |
238 | vector<const T*> v; |
239 | JFactory<T> *fac = Get(v, tag); |
| 3 | | Calling 'JEventLoop::Get' | |
|
240 | |
241 | if(v.size()!=1){ |
242 | t = NULL; |
243 | if(exception_if_not_one) throw v.size(); |
244 | } |
245 | |
246 | t = v[0]; |
247 | |
248 | return fac; |
249 | } |
250 | |
251 | |
252 | |
253 | |
254 | template<class T> |
255 | JFactory<T>* JEventLoop::Get(vector<const T*> &t, const char *tag, bool allow_deftag) |
256 | { |
257 | |
258 | |
259 | |
260 | |
261 | |
262 | |
263 | |
264 | |
265 | |
266 | |
267 | |
268 | |
269 | |
270 | |
271 | |
272 | |
273 | |
274 | |
275 | |
276 | |
277 | |
278 | |
279 | |
280 | |
281 | |
282 | |
283 | |
284 | |
285 | |
286 | |
287 | |
288 | |
289 | |
290 | const char *mytag = tag==NULL ? "":tag; |
| |
291 | if(strlen(mytag)==0 && allow_deftag){ |
| |
292 | map<string, string>::const_iterator iter = default_tags.find(T::static_className()); |
293 | if(iter!=default_tags.end())tag = iter->second.c_str(); |
| 6 | | Assuming the condition is true | |
|
| |
| |
294 | } |
295 | |
296 | |
297 | |
298 | |
299 | |
300 | |
301 | call_stack_t cs; |
302 | |
303 | |
304 | if(record_call_stack) CallStackStart(cs, caller_name, caller_tag, T::static_className(), tag); |
| 9 | | Assuming field 'record_call_stack' is false | |
|
| |
305 | |
306 | |
307 | JFactory<T>* factory=NULL; |
308 | try{ |
309 | factory = GetFromFactory(t, tag, cs.data_source, allow_deftag); |
| 11 | | Passing value via 2nd parameter 'tag' | |
|
| 12 | | Calling 'JEventLoop::GetFromFactory' | |
|
310 | if(!factory){ |
311 | |
312 | |
313 | |
314 | |
315 | |
316 | |
317 | |
318 | string p; |
319 | try{ |
320 | gPARMS->GetParameter("JANA:AUTOFACTORYCREATE", p); |
321 | }catch(...){} |
322 | if(p.size()==0){ |
323 | jout<<std::endl; |
324 | _DBG__; |
325 | jout<<"No factory of type \""<<T::static_className()<<"\" with tag \""<<tag<<"\" exists."<<std::endl; |
326 | jout<<"If you are reading objects from a file, I can auto-create a factory"<<std::endl; |
327 | jout<<"of the appropriate type to hold the objects, but this feature is turned"<<std::endl; |
328 | jout<<"off by default. To turn it on, set the \"JANA:AUTOFACTORYCREATE\""<<std::endl; |
329 | jout<<"configuration parameter. This can usually be done by passing the"<<std::endl; |
330 | jout<<"following argument to the program from the command line:"<<std::endl; |
331 | jout<<std::endl; |
332 | jout<<" -PJANA:AUTOFACTORYCREATE=1"<<std::endl; |
333 | jout<<std::endl; |
334 | jout<<"Note that since the most commonly expected occurance of this situation."<<std::endl; |
335 | jout<<"is an error, the program will now throw an exception so that the factory."<<std::endl; |
336 | jout<<"call stack can be printed."<<std::endl; |
337 | jout<<std::endl; |
338 | throw exception(); |
339 | }else{ |
340 | AddFactory(new JFactory<T>(tag)); |
341 | jout<<__FILE__<<":"<<__LINE__<<" Auto-created "<<T::static_className()<<":"<<tag<<" factory"<<std::endl; |
342 | |
343 | |
344 | |
345 | factory = GetFromFactory(t, tag, cs.data_source, allow_deftag); |
346 | } |
347 | } |
348 | }catch(exception &e){ |
349 | |
350 | |
351 | error_call_stack_t ecs; |
352 | ecs.factory_name = T::static_className(); |
353 | ecs.tag = tag; |
354 | ecs.filename = NULL; |
355 | error_call_stack.push_back(ecs); |
356 | throw e; |
357 | } |
358 | |
359 | |
360 | if(record_call_stack) CallStackEnd(cs); |
361 | |
362 | return factory; |
363 | } |
364 | |
365 | |
366 | |
367 | |
368 | template<class T> |
369 | JFactory<T>* JEventLoop::GetFromFactory(vector<const T*> &t, const char *tag, data_source_t &data_source, bool allow_deftag) |
370 | { |
371 | |
372 | |
373 | vector<JFactory_base*>::iterator iter=factories.begin(); |
374 | JFactory<T> *factory = NULL; |
375 | string className(T::static_className()); |
376 | |
377 | |
378 | |
379 | const char *mytag = tag==NULL ? "":tag; |
| 13 | | Assuming 'tag' is equal to NULL | |
|
| 14 | | Assuming pointer value is null | |
|
| |
380 | if(strlen(mytag)==0 && allow_deftag){ |
| |
381 | map<string, string>::const_iterator iter = default_tags.find(className); |
382 | if(iter!=default_tags.end())tag = iter->second.c_str(); |
| 17 | | Assuming the condition is false | |
|
| |
383 | } |
384 | |
385 | for(; iter!=factories.end(); iter++){ |
| 19 | | Calling 'operator!=<jana::JFactory_base **, std::vector<jana::JFactory_base *>>' | |
|
| 22 | | Returning from 'operator!=<jana::JFactory_base **, std::vector<jana::JFactory_base *>>' | |
|
| 23 | | Loop condition is true. Entering loop body | |
|
386 | |
387 | |
388 | |
389 | |
390 | |
391 | |
392 | |
393 | |
394 | |
395 | if(className == (*iter)->GetDataClassName())factory = (JFactory<T>*)(*iter); |
| |
396 | if(factory == NULL)continue; |
| 25 | | Assuming 'factory' is not equal to NULL | |
|
| |
397 | const char *factag = factory->Tag()==NULL ? "":factory->Tag(); |
| 27 | | Assuming the condition is true | |
|
| |
398 | if(!strcmp(factag, tag)){ |
| 29 | | Null pointer passed to 2nd parameter expecting 'nonnull' |
|
399 | break; |
400 | }else{ |
401 | factory=NULL; |
402 | } |
403 | } |
404 | |
405 | |
406 | if(!factory){ |
407 | data_source = DATA_NOT_AVAILABLE; |
408 | return NULL; |
409 | } |
410 | |
411 | |
412 | |
413 | |
414 | if(factory->evnt_was_called()){ |
415 | factory->CopyFrom(t); |
416 | data_source = DATA_FROM_CACHE; |
417 | return factory; |
418 | } |
419 | |
420 | |
421 | if(factory->GetCheckSourceFirst()){ |
422 | |
423 | |
424 | |
425 | |
426 | |
427 | jerror_t err = GetFromSource(t, factory); |
428 | if(err == NOERROR){ |
429 | |
430 | |
431 | |
432 | |
433 | |
434 | |
435 | |
436 | |
437 | |
438 | |
439 | |
440 | |
441 | |
442 | |
443 | factory->SetFactoryPointers(); |
444 | data_source = DATA_FROM_SOURCE; |
445 | |
446 | return factory; |
447 | } |
448 | } |
449 | |
450 | |
451 | |
452 | factory->Get(t); |
453 | factory->SetFactoryPointers(); |
454 | data_source = DATA_FROM_FACTORY; |
455 | |
456 | return factory; |
457 | } |
458 | |
459 | |
460 | |
461 | |
462 | template<class T> |
463 | jerror_t JEventLoop::GetFromSource(vector<const T*> &t, JFactory_base *factory) |
464 | { |
465 | |
466 | |
467 | |
468 | |
469 | |
470 | |
471 | |
472 | |
473 | |
474 | |
475 | if(!factory)throw OBJECT_NOT_AVAILABLE; |
476 | |
477 | return event.GetObjects(t, factory); |
478 | } |
479 | |
480 | |
481 | |
482 | |
483 | inline void JEventLoop::CallStackStart(JEventLoop::call_stack_t &cs, const string &caller_name, const string &caller_tag, const string callee_name, const string callee_tag) |
484 | { |
485 | |
486 | |
487 | |
488 | |
489 | |
490 | |
491 | struct itimerval tmr; |
492 | getitimer(ITIMER_PROF, &tmr); |
493 | |
494 | cs.caller_name = this->caller_name; |
495 | cs.caller_tag = this->caller_tag; |
496 | this->caller_name = cs.callee_name = callee_name; |
497 | this->caller_tag = cs.callee_tag = callee_tag; |
498 | cs.start_time = tmr.it_value.tv_sec + tmr.it_value.tv_usec/1.0E6; |
499 | } |
500 | |
501 | |
502 | |
503 | |
504 | inline void JEventLoop::CallStackEnd(JEventLoop::call_stack_t &cs) |
505 | { |
506 | |
507 | |
508 | |
509 | |
510 | struct itimerval tmr; |
511 | getitimer(ITIMER_PROF, &tmr); |
512 | cs.end_time = tmr.it_value.tv_sec + tmr.it_value.tv_usec/1.0E6; |
513 | caller_name = cs.caller_name; |
514 | caller_tag = cs.caller_tag; |
515 | call_stack.push_back(cs); |
516 | } |
517 | |
518 | |
519 | |
520 | |
521 | inline bool JEventLoop::CheckEventBoundary(uint64_t event_numberA, uint64_t event_numberB) |
522 | { |
523 | |
524 | |
525 | |
526 | |
527 | |
528 | |
529 | |
530 | |
531 | |
532 | |
533 | |
534 | if(event.GetRunNumber()!=event_boundaries_run){ |
535 | event_boundaries.clear(); |
536 | JCalibration *jcalib = GetJCalibration(); |
537 | if(jcalib)jcalib->GetEventBoundaries(event_boundaries); |
538 | event_boundaries_run = event.GetRunNumber(); |
539 | } |
540 | |
541 | |
542 | for(unsigned int i=0; i<event_boundaries.size(); i++){ |
543 | uint64_t eb = event_boundaries[i]; |
544 | if((eb - event_numberA)*(eb - event_numberB) < 0.0 || eb==event_numberA){ |
545 | |
546 | return true; |
547 | } |
548 | } |
549 | |
550 | return false; |
551 | } |
552 | |
553 | |
554 | |
555 | |
556 | template<class T> |
557 | const T* JEventLoop::FindByID(JObject::oid_t id) |
558 | { |
559 | |
560 | |
561 | |
562 | |
563 | |
564 | |
565 | |
566 | |
567 | |
568 | |
569 | |
570 | |
571 | |
572 | |
573 | |
574 | for(unsigned int i=0; i<factories.size(); i++){ |
575 | if(factories[i]->GetDataClassName() != T::static_className())continue; |
576 | |
577 | |
578 | |
579 | const JObject *my_obj = factories[i]->GetByID(id); |
580 | if(my_obj)return dynamic_cast<const T*>(my_obj); |
581 | } |
582 | |
583 | return NULL; |
584 | } |
585 | |
586 | |
587 | |
588 | |
589 | template<class T> |
590 | bool JEventLoop::GetCalib(string namepath, map<string,T> &vals) |
591 | { |
592 | |
593 | |
594 | |
595 | |
596 | |
597 | |
598 | |
599 | vals.clear(); |
600 | |
601 | JCalibration *calib = GetJCalibration(); |
602 | if(!calib){ |
603 | _DBG_<<"Unable to get JCalibration object for run "<<event.GetRunNumber()<<std::endl; |
604 | return true; |
605 | } |
606 | |
607 | return calib->Get(namepath, vals, event.GetEventNumber()); |
608 | } |
609 | |
610 | |
611 | |
612 | |
613 | template<class T> bool JEventLoop::GetCalib(string namepath, vector<T> &vals) |
614 | { |
615 | |
616 | |
617 | |
618 | vals.clear(); |
619 | |
620 | JCalibration *calib = GetJCalibration(); |
621 | if(!calib){ |
622 | _DBG_<<"Unable to get JCalibration object for run "<<event.GetRunNumber()<<std::endl; |
623 | return true; |
624 | } |
625 | |
626 | return calib->Get(namepath, vals, event.GetEventNumber()); |
627 | } |
628 | |
629 | |
630 | |
631 | |
632 | template<class T> bool JEventLoop::GetCalib(string namepath, T &val) |
633 | { |
634 | |
635 | |
636 | |
637 | |
638 | |
639 | |
640 | vector<T> vals; |
641 | bool ret = GetCalib(namepath, vals); |
642 | if(vals.empty()) return true; |
643 | val = vals[0]; |
644 | |
645 | return ret; |
646 | } |
647 | |
648 | |
649 | |
650 | |
651 | template<class T> |
652 | bool JEventLoop::GetGeom(string namepath, map<string,T> &vals) |
653 | { |
654 | |
655 | |
656 | |
657 | |
658 | |
659 | |
660 | |
661 | vals.clear(); |
662 | |
663 | JGeometry *geom = GetJGeometry(); |
664 | if(!geom){ |
665 | _DBG_<<"Unable to get JGeometry object for run "<<event.GetRunNumber()<<std::endl; |
666 | return true; |
667 | } |
668 | |
669 | return geom->Get(namepath, vals); |
670 | } |
671 | |
672 | |
673 | |
674 | |
675 | template<class T> bool JEventLoop::GetGeom(string namepath, T &val) |
676 | { |
677 | |
678 | |
679 | |
680 | JGeometry *geom = GetJGeometry(); |
681 | if(!geom){ |
682 | _DBG_<<"Unable to get JGeometry object for run "<<event.GetRunNumber()<<std::endl; |
683 | return true; |
684 | } |
685 | |
686 | return geom->Get(namepath, val); |
687 | } |
688 | |
689 | |
690 | |
691 | |
692 | template<class T> |
693 | void JEventLoop::SetRef(T *t) |
694 | { |
695 | pair<const char*, void*> p(typeid(T).name(), (void*)t); |
696 | user_refs.push_back(p); |
697 | } |
698 | |
699 | |
700 | |
701 | |
702 | template<class T> bool JEventLoop::GetResource(string namepath, T vals, int event_number) |
703 | { |
704 | JResourceManager *resource_manager = GetJResourceManager(); |
705 | if(!resource_manager){ |
706 | string mess = string("Unable to get the JResourceManager object (namepath=\"")+namepath+"\")"; |
707 | throw JException(mess); |
708 | } |
709 | |
710 | return resource_manager->Get(namepath, vals, event_number); |
711 | } |
712 | |
713 | |
714 | |
715 | |
716 | template<class T> |
717 | T* JEventLoop::GetRef(void) |
718 | { |
719 | |
720 | for(unsigned int i=0; i<user_refs.size(); i++){ |
721 | if(user_refs[i].first == typeid(T).name()) return (T*)user_refs[i].second; |
722 | } |
723 | |
724 | return NULL; |
725 | } |
726 | |
727 | |
728 | |
729 | |
730 | template<class T> |
731 | vector<T*> JEventLoop::GetRefsT(void) |
732 | { |
733 | vector<T*> refs; |
734 | for(unsigned int i=0; i<user_refs.size(); i++){ |
735 | if(user_refs[i].first == typeid(T).name()){ |
736 | refs.push_back((T*)user_refs[i].second); |
737 | } |
738 | } |
739 | |
740 | return refs; |
741 | } |
742 | |
743 | |
744 | |
745 | |
746 | template<class T> |
747 | void JEventLoop::RemoveRef(T *t) |
748 | { |
749 | vector<pair<const char*, void*> >::iterator iter; |
750 | for(iter=user_refs.begin(); iter!= user_refs.end(); iter++){ |
751 | if(iter->second == (void*)t){ |
752 | user_refs.erase(iter); |
753 | return; |
754 | } |
755 | } |
756 | _DBG_<<" Attempt to remove user reference not in event loop!" << std::endl; |
757 | } |
758 | |
759 | |
760 | #endif //__CINT__ __CLING__ |
761 | |
762 | } |
763 | |
764 | |
765 | |
766 | #endif // _JEventLoop_ |
767 | |
1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
11 | |
12 | |
13 | |
14 | |
15 | |
16 | |
17 | |
18 | |
19 | |
20 | |
21 | |
22 | |
23 | |
24 | |
25 | |
26 | |
27 | |
28 | |
29 | |
30 | |
31 | |
32 | |
33 | |
34 | |
35 | |
36 | |
37 | |
38 | |
39 | |
40 | |
41 | |
42 | |
43 | |
44 | |
45 | |
46 | |
47 | |
48 | |
49 | |
50 | |
51 | |
52 | |
53 | |
54 | |
55 | |
56 | |
57 | |
58 | |
59 | |
60 | #ifndef _STL_ITERATOR_H |
61 | #define _STL_ITERATOR_H 1 |
62 | |
63 | #include <bits/cpp_type_traits.h> |
64 | #include <ext/type_traits.h> |
65 | #include <bits/move.h> |
66 | |
67 | namespace std _GLIBCXX_VISIBILITY(default) |
68 | { |
69 | _GLIBCXX_BEGIN_NAMESPACE_VERSION |
70 | |
71 | |
72 | |
73 | |
74 | |
75 | |
76 | |
77 | |
78 | |
79 | |
80 | |
81 | |
82 | |
83 | |
84 | |
85 | |
86 | |
87 | |
88 | |
89 | |
90 | |
91 | |
92 | |
93 | |
94 | |
95 | template<typename _Iterator> |
96 | class reverse_iterator |
97 | : public iterator<typename iterator_traits<_Iterator>::iterator_category, |
98 | typename iterator_traits<_Iterator>::value_type, |
99 | typename iterator_traits<_Iterator>::difference_type, |
100 | typename iterator_traits<_Iterator>::pointer, |
101 | typename iterator_traits<_Iterator>::reference> |
102 | { |
103 | protected: |
104 | _Iterator current; |
105 | |
106 | typedef iterator_traits<_Iterator> __traits_type; |
107 | |
108 | public: |
109 | typedef _Iterator iterator_type; |
110 | typedef typename __traits_type::difference_type difference_type; |
111 | typedef typename __traits_type::pointer pointer; |
112 | typedef typename __traits_type::reference reference; |
113 | |
114 | |
115 | |
116 | |
117 | |
118 | |
119 | |
120 | reverse_iterator() : current() { } |
121 | |
122 | |
123 | |
124 | |
125 | explicit |
126 | reverse_iterator(iterator_type __x) : current(__x) { } |
127 | |
128 | |
129 | |
130 | |
131 | reverse_iterator(const reverse_iterator& __x) |
132 | : current(__x.current) { } |
133 | |
134 | |
135 | |
136 | |
137 | |
138 | template<typename _Iter> |
139 | reverse_iterator(const reverse_iterator<_Iter>& __x) |
140 | : current(__x.base()) { } |
141 | |
142 | |
143 | |
144 | |
145 | iterator_type |
146 | base() const |
147 | { return current; } |
148 | |
149 | |
150 | |
151 | |
152 | |
153 | |
154 | |
155 | |
156 | |
157 | |
158 | |
159 | reference |
160 | operator*() const |
161 | { |
162 | _Iterator __tmp = current; |
163 | return *--__tmp; |
164 | } |
165 | |
166 | |
167 | |
168 | |
169 | |
170 | |
171 | pointer |
172 | operator->() const |
173 | { return &(operator*()); } |
174 | |
175 | |
176 | |
177 | |
178 | |
179 | |
180 | reverse_iterator& |
181 | operator++() |
182 | { |
183 | --current; |
184 | return *this; |
185 | } |
186 | |
187 | |
188 | |
189 | |
190 | |
191 | |
192 | reverse_iterator |
193 | operator++(int) |
194 | { |
195 | reverse_iterator __tmp = *this; |
196 | --current; |
197 | return __tmp; |
198 | } |
199 | |
200 | |
201 | |
202 | |
203 | |
204 | |
205 | reverse_iterator& |
206 | operator--() |
207 | { |
208 | ++current; |
209 | return *this; |
210 | } |
211 | |
212 | |
213 | |
214 | |
215 | |
216 | |
217 | reverse_iterator |
218 | operator--(int) |
219 | { |
220 | reverse_iterator __tmp = *this; |
221 | ++current; |
222 | return __tmp; |
223 | } |
224 | |
225 | |
226 | |
227 | |
228 | |
229 | |
230 | reverse_iterator |
231 | operator+(difference_type __n) const |
232 | { return reverse_iterator(current - __n); } |
233 | |
234 | |
235 | |
236 | |
237 | |
238 | |
239 | |
240 | reverse_iterator& |
241 | operator+=(difference_type __n) |
242 | { |
243 | current -= __n; |
244 | return *this; |
245 | } |
246 | |
247 | |
248 | |
249 | |
250 | |
251 | |
252 | reverse_iterator |
253 | operator-(difference_type __n) const |
254 | { return reverse_iterator(current + __n); } |
255 | |
256 | |
257 | |
258 | |
259 | |
260 | |
261 | |
262 | reverse_iterator& |
263 | operator-=(difference_type __n) |
264 | { |
265 | current += __n; |
266 | return *this; |
267 | } |
268 | |
269 | |
270 | |
271 | |
272 | |
273 | |
274 | reference |
275 | operator[](difference_type __n) const |
276 | { return *(*this + __n); } |
277 | }; |
278 | |
279 | |
280 | |
281 | |
282 | |
283 | |
284 | |
285 | |
286 | |
287 | |
288 | |
289 | template<typename _Iterator> |
290 | inline bool |
291 | operator==(const reverse_iterator<_Iterator>& __x, |
292 | const reverse_iterator<_Iterator>& __y) |
293 | { return __x.base() == __y.base(); } |
294 | |
295 | template<typename _Iterator> |
296 | inline bool |
297 | operator<(const reverse_iterator<_Iterator>& __x, |
298 | const reverse_iterator<_Iterator>& __y) |
299 | { return __y.base() < __x.base(); } |
300 | |
301 | template<typename _Iterator> |
302 | inline bool |
303 | operator!=(const reverse_iterator<_Iterator>& __x, |
304 | const reverse_iterator<_Iterator>& __y) |
305 | { return !(__x == __y); } |
306 | |
307 | template<typename _Iterator> |
308 | inline bool |
309 | operator>(const reverse_iterator<_Iterator>& __x, |
310 | const reverse_iterator<_Iterator>& __y) |
311 | { return __y < __x; } |
312 | |
313 | template<typename _Iterator> |
314 | inline bool |
315 | operator<=(const reverse_iterator<_Iterator>& __x, |
316 | const reverse_iterator<_Iterator>& __y) |
317 | { return !(__y < __x); } |
318 | |
319 | template<typename _Iterator> |
320 | inline bool |
321 | operator>=(const reverse_iterator<_Iterator>& __x, |
322 | const reverse_iterator<_Iterator>& __y) |
323 | { return !(__x < __y); } |
324 | |
325 | template<typename _Iterator> |
326 | inline typename reverse_iterator<_Iterator>::difference_type |
327 | operator-(const reverse_iterator<_Iterator>& __x, |
328 | const reverse_iterator<_Iterator>& __y) |
329 | { return __y.base() - __x.base(); } |
330 | |
331 | template<typename _Iterator> |
332 | inline reverse_iterator<_Iterator> |
333 | operator+(typename reverse_iterator<_Iterator>::difference_type __n, |
334 | const reverse_iterator<_Iterator>& __x) |
335 | { return reverse_iterator<_Iterator>(__x.base() - __n); } |
336 | |
337 | |
338 | |
339 | template<typename _IteratorL, typename _IteratorR> |
340 | inline bool |
341 | operator==(const reverse_iterator<_IteratorL>& __x, |
342 | const reverse_iterator<_IteratorR>& __y) |
343 | { return __x.base() == __y.base(); } |
344 | |
345 | template<typename _IteratorL, typename _IteratorR> |
346 | inline bool |
347 | operator<(const reverse_iterator<_IteratorL>& __x, |
348 | const reverse_iterator<_IteratorR>& __y) |
349 | { return __y.base() < __x.base(); } |
350 | |
351 | template<typename _IteratorL, typename _IteratorR> |
352 | inline bool |
353 | operator!=(const reverse_iterator<_IteratorL>& __x, |
354 | const reverse_iterator<_IteratorR>& __y) |
355 | { return !(__x == __y); } |
356 | |
357 | template<typename _IteratorL, typename _IteratorR> |
358 | inline bool |
359 | operator>(const reverse_iterator<_IteratorL>& __x, |
360 | const reverse_iterator<_IteratorR>& __y) |
361 | { return __y < __x; } |
362 | |
363 | template<typename _IteratorL, typename _IteratorR> |
364 | inline bool |
365 | operator<=(const reverse_iterator<_IteratorL>& __x, |
366 | const reverse_iterator<_IteratorR>& __y) |
367 | { return !(__y < __x); } |
368 | |
369 | template<typename _IteratorL, typename _IteratorR> |
370 | inline bool |
371 | operator>=(const reverse_iterator<_IteratorL>& __x, |
372 | const reverse_iterator<_IteratorR>& __y) |
373 | { return !(__x < __y); } |
374 | |
375 | template<typename _IteratorL, typename _IteratorR> |
376 | #if __cplusplus >= 201103L |
377 | |
378 | inline auto |
379 | operator-(const reverse_iterator<_IteratorL>& __x, |
380 | const reverse_iterator<_IteratorR>& __y) |
381 | -> decltype(__y.base() - __x.base()) |
382 | #else |
383 | inline typename reverse_iterator<_IteratorL>::difference_type |
384 | operator-(const reverse_iterator<_IteratorL>& __x, |
385 | const reverse_iterator<_IteratorR>& __y) |
386 | #endif |
387 | { return __y.base() - __x.base(); } |
388 | |
389 | |
390 | |
391 | |
392 | |
393 | |
394 | |
395 | |
396 | |
397 | |
398 | |
399 | |
400 | |
401 | template<typename _Container> |
402 | class back_insert_iterator |
403 | : public iterator<output_iterator_tag, void, void, void, void> |
404 | { |
405 | protected: |
406 | _Container* container; |
407 | |
408 | public: |
409 | |
410 | typedef _Container container_type; |
411 | |
412 | |
413 | explicit |
414 | back_insert_iterator(_Container& __x) : container(&__x) { } |
415 | |
416 | |
417 | |
418 | |
419 | |
420 | |
421 | |
422 | |
423 | |
424 | |
425 | |
426 | |
427 | #if __cplusplus < 201103L |
428 | back_insert_iterator& |
429 | operator=(typename _Container::const_reference __value) |
430 | { |
431 | container->push_back(__value); |
432 | return *this; |
433 | } |
434 | #else |
435 | back_insert_iterator& |
436 | operator=(const typename _Container::value_type& __value) |
437 | { |
438 | container->push_back(__value); |
439 | return *this; |
440 | } |
441 | |
442 | back_insert_iterator& |
443 | operator=(typename _Container::value_type&& __value) |
444 | { |
445 | container->push_back(std::move(__value)); |
446 | return *this; |
447 | } |
448 | #endif |
449 | |
450 | |
451 | back_insert_iterator& |
452 | operator*() |
453 | { return *this; } |
454 | |
455 | |
456 | back_insert_iterator& |
457 | operator++() |
458 | { return *this; } |
459 | |
460 | |
461 | back_insert_iterator |
462 | operator++(int) |
463 | { return *this; } |
464 | }; |
465 | |
466 | |
467 | |
468 | |
469 | |
470 | |
471 | |
472 | |
473 | |
474 | |
475 | |
476 | |
477 | template<typename _Container> |
478 | inline back_insert_iterator<_Container> |
479 | back_inserter(_Container& __x) |
480 | { return back_insert_iterator<_Container>(__x); } |
481 | |
482 | |
483 | |
484 | |
485 | |
486 | |
487 | |
488 | |
489 | |
490 | |
491 | |
492 | template<typename _Container> |
493 | class front_insert_iterator |
494 | : public iterator<output_iterator_tag, void, void, void, void> |
495 | { |
496 | protected: |
497 | _Container* container; |
498 | |
499 | public: |
500 | |
501 | typedef _Container container_type; |
502 | |
503 | |
504 | explicit front_insert_iterator(_Container& __x) : container(&__x) { } |
505 | |
506 | |
507 | |
508 | |
509 | |
510 | |
511 | |
512 | |
513 | |
514 | |
515 | |
516 | |
517 | #if __cplusplus < 201103L |
518 | front_insert_iterator& |
519 | operator=(typename _Container::const_reference __value) |
520 | { |
521 | container->push_front(__value); |
522 | return *this; |
523 | } |
524 | #else |
525 | front_insert_iterator& |
526 | operator=(const typename _Container::value_type& __value) |
527 | { |
528 | container->push_front(__value); |
529 | return *this; |
530 | } |
531 | |
532 | front_insert_iterator& |
533 | operator=(typename _Container::value_type&& __value) |
534 | { |
535 | container->push_front(std::move(__value)); |
536 | return *this; |
537 | } |
538 | #endif |
539 | |
540 | |
541 | front_insert_iterator& |
542 | operator*() |
543 | { return *this; } |
544 | |
545 | |
546 | front_insert_iterator& |
547 | operator++() |
548 | { return *this; } |
549 | |
550 | |
551 | front_insert_iterator |
552 | operator++(int) |
553 | { return *this; } |
554 | }; |
555 | |
556 | |
557 | |
558 | |
559 | |
560 | |
561 | |
562 | |
563 | |
564 | |
565 | |
566 | |
567 | template<typename _Container> |
568 | inline front_insert_iterator<_Container> |
569 | front_inserter(_Container& __x) |
570 | { return front_insert_iterator<_Container>(__x); } |
571 | |
572 | |
573 | |
574 | |
575 | |
576 | |
577 | |
578 | |
579 | |
580 | |
581 | |
582 | |
583 | |
584 | |
585 | |
586 | template<typename _Container> |
587 | class insert_iterator |
588 | : public iterator<output_iterator_tag, void, void, void, void> |
589 | { |
590 | protected: |
591 | _Container* container; |
592 | typename _Container::iterator iter; |
593 | |
594 | public: |
595 | |
596 | typedef _Container container_type; |
597 | |
598 | |
599 | |
600 | |
601 | |
602 | insert_iterator(_Container& __x, typename _Container::iterator __i) |
603 | : container(&__x), iter(__i) {} |
604 | |
605 | |
606 | |
607 | |
608 | |
609 | |
610 | |
611 | |
612 | |
613 | |
614 | |
615 | |
616 | |
617 | |
618 | |
619 | |
620 | |
621 | |
622 | |
623 | |
624 | |
625 | |
626 | |
627 | |
628 | #if __cplusplus < 201103L |
629 | insert_iterator& |
630 | operator=(typename _Container::const_reference __value) |
631 | { |
632 | iter = container->insert(iter, __value); |
633 | ++iter; |
634 | return *this; |
635 | } |
636 | #else |
637 | insert_iterator& |
638 | operator=(const typename _Container::value_type& __value) |
639 | { |
640 | iter = container->insert(iter, __value); |
641 | ++iter; |
642 | return *this; |
643 | } |
644 | |
645 | insert_iterator& |
646 | operator=(typename _Container::value_type&& __value) |
647 | { |
648 | iter = container->insert(iter, std::move(__value)); |
649 | ++iter; |
650 | return *this; |
651 | } |
652 | #endif |
653 | |
654 | |
655 | insert_iterator& |
656 | operator*() |
657 | { return *this; } |
658 | |
659 | |
660 | insert_iterator& |
661 | operator++() |
662 | { return *this; } |
663 | |
664 | |
665 | insert_iterator& |
666 | operator++(int) |
667 | { return *this; } |
668 | }; |
669 | |
670 | |
671 | |
672 | |
673 | |
674 | |
675 | |
676 | |
677 | |
678 | |
679 | |
680 | |
681 | template<typename _Container, typename _Iterator> |
682 | inline insert_iterator<_Container> |
683 | inserter(_Container& __x, _Iterator __i) |
684 | { |
685 | return insert_iterator<_Container>(__x, |
686 | typename _Container::iterator(__i)); |
687 | } |
688 | |
689 | |
690 | |
691 | _GLIBCXX_END_NAMESPACE_VERSION |
692 | } |
693 | |
694 | namespace __gnu_cxx _GLIBCXX_VISIBILITY(default) |
695 | { |
696 | _GLIBCXX_BEGIN_NAMESPACE_VERSION |
697 | |
698 | |
699 | |
700 | |
701 | |
702 | |
703 | |
704 | |
705 | using std::iterator_traits; |
706 | using std::iterator; |
707 | template<typename _Iterator, typename _Container> |
708 | class __normal_iterator |
709 | { |
710 | protected: |
711 | _Iterator _M_current; |
712 | |
713 | typedef iterator_traits<_Iterator> __traits_type; |
714 | |
715 | public: |
716 | typedef _Iterator iterator_type; |
717 | typedef typename __traits_type::iterator_category iterator_category; |
718 | typedef typename __traits_type::value_type value_type; |
719 | typedef typename __traits_type::difference_type difference_type; |
720 | typedef typename __traits_type::reference reference; |
721 | typedef typename __traits_type::pointer pointer; |
722 | |
723 | _GLIBCXX_CONSTEXPR __normal_iterator() : _M_current(_Iterator()) { } |
724 | |
725 | explicit |
726 | __normal_iterator(const _Iterator& __i) : _M_current(__i) { } |
727 | |
728 | |
729 | template<typename _Iter> |
730 | __normal_iterator(const __normal_iterator<_Iter, |
731 | typename __enable_if< |
732 | (std::__are_same<_Iter, typename _Container::pointer>::__value), |
733 | _Container>::__type>& __i) |
734 | : _M_current(__i.base()) { } |
735 | |
736 | |
737 | reference |
738 | operator*() const |
739 | { return *_M_current; } |
740 | |
741 | pointer |
742 | operator->() const |
743 | { return _M_current; } |
744 | |
745 | __normal_iterator& |
746 | operator++() |
747 | { |
748 | ++_M_current; |
749 | return *this; |
750 | } |
751 | |
752 | __normal_iterator |
753 | operator++(int) |
754 | { return __normal_iterator(_M_current++); } |
755 | |
756 | |
757 | __normal_iterator& |
758 | operator--() |
759 | { |
760 | --_M_current; |
761 | return *this; |
762 | } |
763 | |
764 | __normal_iterator |
765 | operator--(int) |
766 | { return __normal_iterator(_M_current--); } |
767 | |
768 | |
769 | reference |
770 | operator[](const difference_type& __n) const |
771 | { return _M_current[__n]; } |
772 | |
773 | __normal_iterator& |
774 | operator+=(const difference_type& __n) |
775 | { _M_current += __n; return *this; } |
776 | |
777 | __normal_iterator |
778 | operator+(const difference_type& __n) const |
779 | { return __normal_iterator(_M_current + __n); } |
780 | |
781 | __normal_iterator& |
782 | operator-=(const difference_type& __n) |
783 | { _M_current -= __n; return *this; } |
784 | |
785 | __normal_iterator |
786 | operator-(const difference_type& __n) const |
787 | { return __normal_iterator(_M_current - __n); } |
788 | |
789 | const _Iterator& |
790 | base() const |
791 | { return _M_current; } |
792 | }; |
793 | |
794 | |
795 | |
796 | |
797 | |
798 | |
799 | |
800 | |
801 | |
802 | |
803 | template<typename _IteratorL, typename _IteratorR, typename _Container> |
804 | inline bool |
805 | operator==(const __normal_iterator<_IteratorL, _Container>& __lhs, |
806 | const __normal_iterator<_IteratorR, _Container>& __rhs) |
807 | { return __lhs.base() == __rhs.base(); } |
808 | |
809 | template<typename _Iterator, typename _Container> |
810 | inline bool |
811 | operator==(const __normal_iterator<_Iterator, _Container>& __lhs, |
812 | const __normal_iterator<_Iterator, _Container>& __rhs) |
813 | { return __lhs.base() == __rhs.base(); } |
814 | |
815 | template<typename _IteratorL, typename _IteratorR, typename _Container> |
816 | inline bool |
817 | operator!=(const __normal_iterator<_IteratorL, _Container>& __lhs, |
818 | const __normal_iterator<_IteratorR, _Container>& __rhs) |
819 | { return __lhs.base() != __rhs.base(); } |
820 | |
821 | template<typename _Iterator, typename _Container> |
822 | inline bool |
823 | operator!=(const __normal_iterator<_Iterator, _Container>& __lhs, |
824 | const __normal_iterator<_Iterator, _Container>& __rhs) |
825 | { return __lhs.base() != __rhs.base(); } |
| 20 | | Assuming the condition is true | |
|
| 21 | | Returning the value 1, which participates in a condition later | |
|
826 | |
827 | |
828 | template<typename _IteratorL, typename _IteratorR, typename _Container> |
829 | inline bool |
830 | operator<(const __normal_iterator<_IteratorL, _Container>& __lhs, |
831 | const __normal_iterator<_IteratorR, _Container>& __rhs) |
832 | { return __lhs.base() < __rhs.base(); } |
833 | |
834 | template<typename _Iterator, typename _Container> |
835 | inline bool |
836 | operator<(const __normal_iterator<_Iterator, _Container>& __lhs, |
837 | const __normal_iterator<_Iterator, _Container>& __rhs) |
838 | { return __lhs.base() < __rhs.base(); } |
839 | |
840 | template<typename _IteratorL, typename _IteratorR, typename _Container> |
841 | inline bool |
842 | operator>(const __normal_iterator<_IteratorL, _Container>& __lhs, |
843 | const __normal_iterator<_IteratorR, _Container>& __rhs) |
844 | { return __lhs.base() > __rhs.base(); } |
845 | |
846 | template<typename _Iterator, typename _Container> |
847 | inline bool |
848 | operator>(const __normal_iterator<_Iterator, _Container>& __lhs, |
849 | const __normal_iterator<_Iterator, _Container>& __rhs) |
850 | { return __lhs.base() > __rhs.base(); } |
851 | |
852 | template<typename _IteratorL, typename _IteratorR, typename _Container> |
853 | inline bool |
854 | operator<=(const __normal_iterator<_IteratorL, _Container>& __lhs, |
855 | const __normal_iterator<_IteratorR, _Container>& __rhs) |
856 | { return __lhs.base() <= __rhs.base(); } |
857 | |
858 | template<typename _Iterator, typename _Container> |
859 | inline bool |
860 | operator<=(const __normal_iterator<_Iterator, _Container>& __lhs, |
861 | const __normal_iterator<_Iterator, _Container>& __rhs) |
862 | { return __lhs.base() <= __rhs.base(); } |
863 | |
864 | template<typename _IteratorL, typename _IteratorR, typename _Container> |
865 | inline bool |
866 | operator>=(const __normal_iterator<_IteratorL, _Container>& __lhs, |
867 | const __normal_iterator<_IteratorR, _Container>& __rhs) |
868 | { return __lhs.base() >= __rhs.base(); } |
869 | |
870 | template<typename _Iterator, typename _Container> |
871 | inline bool |
872 | operator>=(const __normal_iterator<_Iterator, _Container>& __lhs, |
873 | const __normal_iterator<_Iterator, _Container>& __rhs) |
874 | { return __lhs.base() >= __rhs.base(); } |
875 | |
876 | |
877 | |
878 | |
879 | |
880 | template<typename _IteratorL, typename _IteratorR, typename _Container> |
881 | #if __cplusplus >= 201103L |
882 | |
883 | inline auto |
884 | operator-(const __normal_iterator<_IteratorL, _Container>& __lhs, |
885 | const __normal_iterator<_IteratorR, _Container>& __rhs) |
886 | -> decltype(__lhs.base() - __rhs.base()) |
887 | #else |
888 | inline typename __normal_iterator<_IteratorL, _Container>::difference_type |
889 | operator-(const __normal_iterator<_IteratorL, _Container>& __lhs, |
890 | const __normal_iterator<_IteratorR, _Container>& __rhs) |
891 | #endif |
892 | { return __lhs.base() - __rhs.base(); } |
893 | |
894 | template<typename _Iterator, typename _Container> |
895 | inline typename __normal_iterator<_Iterator, _Container>::difference_type |
896 | operator-(const __normal_iterator<_Iterator, _Container>& __lhs, |
897 | const __normal_iterator<_Iterator, _Container>& __rhs) |
898 | { return __lhs.base() - __rhs.base(); } |
899 | |
900 | template<typename _Iterator, typename _Container> |
901 | inline __normal_iterator<_Iterator, _Container> |
902 | operator+(typename __normal_iterator<_Iterator, _Container>::difference_type |
903 | __n, const __normal_iterator<_Iterator, _Container>& __i) |
904 | { return __normal_iterator<_Iterator, _Container>(__i.base() + __n); } |
905 | |
906 | _GLIBCXX_END_NAMESPACE_VERSION |
907 | } |
908 | |
909 | #if __cplusplus >= 201103L |
910 | |
911 | namespace std _GLIBCXX_VISIBILITY(default) |
912 | { |
913 | _GLIBCXX_BEGIN_NAMESPACE_VERSION |
914 | |
915 | |
916 | |
917 | |
918 | |
919 | |
920 | |
921 | |
922 | |
923 | |
924 | |
925 | |
926 | |
927 | |
928 | |
929 | template<typename _Iterator> |
930 | class move_iterator |
931 | { |
932 | protected: |
933 | _Iterator _M_current; |
934 | |
935 | typedef iterator_traits<_Iterator> __traits_type; |
936 | |
937 | public: |
938 | typedef _Iterator iterator_type; |
939 | typedef typename __traits_type::iterator_category iterator_category; |
940 | typedef typename __traits_type::value_type value_type; |
941 | typedef typename __traits_type::difference_type difference_type; |
942 | |
943 | typedef _Iterator pointer; |
944 | typedef value_type&& reference; |
945 | |
946 | move_iterator() |
947 | : _M_current() { } |
948 | |
949 | explicit |
950 | move_iterator(iterator_type __i) |
951 | : _M_current(__i) { } |
952 | |
953 | template<typename _Iter> |
954 | move_iterator(const move_iterator<_Iter>& __i) |
955 | : _M_current(__i.base()) { } |
956 | |
957 | iterator_type |
958 | base() const |
959 | { return _M_current; } |
960 | |
961 | reference |
962 | operator*() const |
963 | { return std::move(*_M_current); } |
964 | |
965 | pointer |
966 | operator->() const |
967 | { return _M_current; } |
968 | |
969 | move_iterator& |
970 | operator++() |
971 | { |
972 | ++_M_current; |
973 | return *this; |
974 | } |
975 | |
976 | move_iterator |
977 | operator++(int) |
978 | { |
979 | move_iterator __tmp = *this; |
980 | ++_M_current; |
981 | return __tmp; |
982 | } |
983 | |
984 | move_iterator& |
985 | operator--() |
986 | { |
987 | --_M_current; |
988 | return *this; |
989 | } |
990 | |
991 | move_iterator |
992 | operator--(int) |
993 | { |
994 | move_iterator __tmp = *this; |
995 | --_M_current; |
996 | return __tmp; |
997 | } |
998 | |
999 | move_iterator |
1000 | operator+(difference_type __n) const |
1001 | { return move_iterator(_M_current + __n); } |
1002 | |
1003 | move_iterator& |
1004 | operator+=(difference_type __n) |
1005 | { |
1006 | _M_current += __n; |
1007 | return *this; |
1008 | } |
1009 | |
1010 | move_iterator |
1011 | operator-(difference_type __n) const |
1012 | { return move_iterator(_M_current - __n); } |
1013 | |
1014 | move_iterator& |
1015 | operator-=(difference_type __n) |
1016 | { |
1017 | _M_current -= __n; |
1018 | return *this; |
1019 | } |
1020 | |
1021 | reference |
1022 | operator[](difference_type __n) const |
1023 | { return std::move(_M_current[__n]); } |
1024 | }; |
1025 | |
1026 | |
1027 | |
1028 | |
1029 | template<typename _IteratorL, typename _IteratorR> |
1030 | inline bool |
1031 | operator==(const move_iterator<_IteratorL>& __x, |
1032 | const move_iterator<_IteratorR>& __y) |
1033 | { return __x.base() == __y.base(); } |
1034 | |
1035 | template<typename _Iterator> |
1036 | inline bool |
1037 | operator==(const move_iterator<_Iterator>& __x, |
1038 | const move_iterator<_Iterator>& __y) |
1039 | { return __x.base() == __y.base(); } |
1040 | |
1041 | template<typename _IteratorL, typename _IteratorR> |
1042 | inline bool |
1043 | operator!=(const move_iterator<_IteratorL>& __x, |
1044 | const move_iterator<_IteratorR>& __y) |
1045 | { return !(__x == __y); } |
1046 | |
1047 | template<typename _Iterator> |
1048 | inline bool |
1049 | operator!=(const move_iterator<_Iterator>& __x, |
1050 | const move_iterator<_Iterator>& __y) |
1051 | { return !(__x == __y); } |
1052 | |
1053 | template<typename _IteratorL, typename _IteratorR> |
1054 | inline bool |
1055 | operator<(const move_iterator<_IteratorL>& __x, |
1056 | const move_iterator<_IteratorR>& __y) |
1057 | { return __x.base() < __y.base(); } |
1058 | |
1059 | template<typename _Iterator> |
1060 | inline bool |
1061 | operator<(const move_iterator<_Iterator>& __x, |
1062 | const move_iterator<_Iterator>& __y) |
1063 | { return __x.base() < __y.base(); } |
1064 | |
1065 | template<typename _IteratorL, typename _IteratorR> |
1066 | inline bool |
1067 | operator<=(const move_iterator<_IteratorL>& __x, |
1068 | const move_iterator<_IteratorR>& __y) |
1069 | { return !(__y < __x); } |
1070 | |
1071 | template<typename _Iterator> |
1072 | inline bool |
1073 | operator<=(const move_iterator<_Iterator>& __x, |
1074 | const move_iterator<_Iterator>& __y) |
1075 | { return !(__y < __x); } |
1076 | |
1077 | template<typename _IteratorL, typename _IteratorR> |
1078 | inline bool |
1079 | operator>(const move_iterator<_IteratorL>& __x, |
1080 | const move_iterator<_IteratorR>& __y) |
1081 | { return __y < __x; } |
1082 | |
1083 | template<typename _Iterator> |
1084 | inline bool |
1085 | operator>(const move_iterator<_Iterator>& __x, |
1086 | const move_iterator<_Iterator>& __y) |
1087 | { return __y < __x; } |
1088 | |
1089 | template<typename _IteratorL, typename _IteratorR> |
1090 | inline bool |
1091 | operator>=(const move_iterator<_IteratorL>& __x, |
1092 | const move_iterator<_IteratorR>& __y) |
1093 | { return !(__x < __y); } |
1094 | |
1095 | template<typename _Iterator> |
1096 | inline bool |
1097 | operator>=(const move_iterator<_Iterator>& __x, |
1098 | const move_iterator<_Iterator>& __y) |
1099 | { return !(__x < __y); } |
1100 | |
1101 | |
1102 | template<typename _IteratorL, typename _IteratorR> |
1103 | inline auto |
1104 | operator-(const move_iterator<_IteratorL>& __x, |
1105 | const move_iterator<_IteratorR>& __y) |
1106 | -> decltype(__x.base() - __y.base()) |
1107 | { return __x.base() - __y.base(); } |
1108 | |
1109 | template<typename _Iterator> |
1110 | inline auto |
1111 | operator-(const move_iterator<_Iterator>& __x, |
1112 | const move_iterator<_Iterator>& __y) |
1113 | -> decltype(__x.base() - __y.base()) |
1114 | { return __x.base() - __y.base(); } |
1115 | |
1116 | template<typename _Iterator> |
1117 | inline move_iterator<_Iterator> |
1118 | operator+(typename move_iterator<_Iterator>::difference_type __n, |
1119 | const move_iterator<_Iterator>& __x) |
1120 | { return __x + __n; } |
1121 | |
1122 | template<typename _Iterator> |
1123 | inline move_iterator<_Iterator> |
1124 | make_move_iterator(_Iterator __i) |
1125 | { return move_iterator<_Iterator>(__i); } |
1126 | |
1127 | template<typename _Iterator, typename _ReturnType |
1128 | = typename conditional<__move_if_noexcept_cond |
1129 | <typename iterator_traits<_Iterator>::value_type>::value, |
1130 | _Iterator, move_iterator<_Iterator>>::type> |
1131 | inline _ReturnType |
1132 | __make_move_if_noexcept_iterator(_Iterator __i) |
1133 | { return _ReturnType(__i); } |
1134 | |
1135 | |
1136 | |
1137 | _GLIBCXX_END_NAMESPACE_VERSION |
1138 | } |
1139 | |
1140 | #define _GLIBCXX_MAKE_MOVE_ITERATOR(_Iter) std::make_move_iterator(_Iter) |
1141 | #define _GLIBCXX_MAKE_MOVE_IF_NOEXCEPT_ITERATOR(_Iter) \ |
1142 | std::__make_move_if_noexcept_iterator(_Iter) |
1143 | #else |
1144 | #define _GLIBCXX_MAKE_MOVE_ITERATOR(_Iter) (_Iter) |
1145 | #define _GLIBCXX_MAKE_MOVE_IF_NOEXCEPT_ITERATOR(_Iter) (_Iter) |
1146 | #endif // C++11 |
1147 | |
1148 | #endif |