clang -cc1 -cc1 -triple x86_64-unknown-linux-gnu -analyze -disable-free -main-file-name DEventSourceHDDM.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/HDDM -I libraries/HDDM -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/HDDM/DEventSourceHDDM.cc
1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
11 | |
12 | |
13 | |
14 | |
15 | |
16 | |
17 | |
18 | |
19 | |
20 | |
21 | #include <iostream> |
22 | #include <iomanip> |
23 | #include <cmath> |
24 | using namespace std; |
25 | |
26 | #include <JANA/JFactory_base.h> |
27 | #include <JANA/JEventLoop.h> |
28 | #include <JANA/JEvent.h> |
29 | #include <DANA/DStatusBits.h> |
30 | |
31 | #include <JANA/JGeometryXML.h> |
32 | #include "BCAL/DBCALGeometry.h" |
33 | #include "PAIR_SPECTROMETER/DPSGeometry.h" |
34 | |
35 | #include <DVector2.h> |
36 | #include <DEventSourceHDDM.h> |
37 | #include <FDC/DFDCGeometry.h> |
38 | #include <FCAL/DFCALGeometry.h> |
39 | #include <FCAL/DFCALHit.h> |
40 | #include <CCAL/DCCALGeometry.h> |
41 | #include <CCAL/DCCALHit.h> |
42 | |
43 | |
44 | |
45 | |
46 | |
47 | class MCTrackHitSort{ |
48 | public: |
49 | bool operator()(DMCTrackHit* const &thit1, |
50 | DMCTrackHit* const &thit2) const { |
51 | return thit1->z < thit2->z; |
52 | } |
53 | }; |
54 | |
55 | bool MCTrackHitSort_C(DMCTrackHit* const &thit1, |
56 | DMCTrackHit* const &thit2) { |
57 | return thit1->z < thit2->z; |
58 | } |
59 | |
60 | |
61 | |
62 | |
63 | |
64 | DEventSourceHDDM::DEventSourceHDDM(const char* source_name) |
65 | : JEventSource(source_name) |
66 | { |
67 | |
68 | ifs = new ifstream(source_name); |
69 | ifs->get(); |
70 | ifs->unget(); |
71 | if (ifs->rdbuf()->in_avail() > 30) { |
72 | class nonstd_streambuf: public std::streambuf { |
73 | public: char *pub_gptr() {return gptr();} |
74 | }; |
75 | void *buf = (void*)ifs->rdbuf(); |
76 | std::stringstream sbuf(((nonstd_streambuf*)buf)->pub_gptr()); |
77 | std::string head; |
78 | std::getline(sbuf, head); |
79 | std::string expected = " class=\"s\" "; |
80 | std::string also_supported = " class=\"mc_s\" "; |
81 | if (head.find(expected) == head.npos && |
82 | head.find(also_supported) == head.npos) |
83 | { |
84 | std::string msg("Unexpected header found in input HDDM stream: "); |
85 | throw std::runtime_error(msg + head + source_name); |
86 | } |
87 | } |
88 | |
89 | fin = new hddm_s::istream(*ifs); |
90 | initialized = false; |
91 | dapp = NULL; |
92 | bfield = NULL; |
93 | geom = NULL; |
94 | |
95 | dRunNumber = -1; |
96 | |
97 | if( (!gPARMS->Exists("JANA_CALIB_CONTEXT")) && (getenv("JANA_CALIB_CONTEXT")==NULL) ){ |
98 | cout << "============================================================" << endl; |
99 | cout << " WARNING: JANA_CALIB_CONTEXT not set. " << endl; |
100 | cout << "You are reading from an HDDM file which is most likely" << endl; |
101 | cout << "MC data. In most cases, you will want to set this parameter" << endl; |
102 | cout << "to get proper reconstruction." << endl; |
103 | cout << "(usually something like \"variation=mc\")" << endl; |
104 | cout << "============================================================" << endl; |
105 | } |
106 | } |
107 | |
108 | |
109 | |
110 | |
111 | DEventSourceHDDM::~DEventSourceHDDM() |
112 | { |
113 | if (fin) |
114 | delete fin; |
115 | if (ifs) |
116 | delete ifs; |
117 | } |
118 | |
119 | |
120 | |
121 | |
122 | jerror_t DEventSourceHDDM::GetEvent(JEvent &event) |
123 | { |
124 | |
125 | |
126 | if (!fin) |
127 | return EVENT_SOURCE_NOT_OPEN; |
128 | |
129 | |
130 | |
131 | else if (!ifs->good()) { |
132 | delete fin; |
133 | fin = NULL; |
134 | delete ifs; |
135 | ifs = NULL; |
136 | return NO_MORE_EVENTS_IN_SOURCE; |
137 | } |
138 | |
139 | hddm_s::HDDM *record = new hddm_s::HDDM(); |
140 | while (record->getPhysicsEvents().size() == 0) { |
141 | if (! (*fin >> *record)) { |
142 | delete fin; |
143 | fin = NULL; |
144 | delete ifs; |
145 | ifs = NULL; |
146 | return NO_MORE_EVENTS_IN_SOURCE; |
147 | } |
148 | } |
149 | |
150 | ++Nevents_read; |
151 | |
152 | int event_number = -1; |
153 | int run_number = -1; |
154 | |
155 | if(!record->getPhysicsEvents().empty()) { |
156 | |
157 | hddm_s::PhysicsEvent &pe = record->getPhysicsEvent(0); |
158 | event_number = pe.getEventNo(); |
159 | run_number = pe.getRunNo(); |
160 | } |
161 | |
162 | |
163 | event.SetJEventSource(this); |
164 | event.SetEventNumber(event_number); |
165 | event.SetRunNumber(run_number); |
166 | event.SetRef(record); |
167 | event.SetStatusBit(kSTATUS_HDDM); |
168 | event.SetStatusBit(kSTATUS_FROM_FILE); |
169 | event.SetStatusBit(kSTATUS_PHYSICS_EVENT); |
170 | |
171 | return NOERROR; |
172 | } |
173 | |
174 | |
175 | |
176 | |
177 | void DEventSourceHDDM::FreeEvent(JEvent &event) |
178 | { |
179 | hddm_s::HDDM *record = (hddm_s::HDDM*)event.GetRef(); |
180 | delete record; |
181 | } |
182 | |
183 | |
184 | |
185 | |
186 | jerror_t DEventSourceHDDM::GetObjects(JEvent &event, JFactory_base *factory) |
187 | { |
188 | |
189 | |
190 | |
191 | |
192 | |
193 | |
194 | if (!factory) |
| 1 | Assuming 'factory' is non-null | |
|
| |
195 | throw RESOURCE_UNAVAILABLE; |
196 | |
197 | |
198 | |
199 | string tag = (factory->Tag()==NULL)? "" : factory->Tag(); |
| 3 | | Assuming the condition is false | |
|
| |
200 | |
201 | |
202 | hddm_s::HDDM *record = (hddm_s::HDDM*)event.GetRef(); |
203 | if (!record) |
| 5 | | Assuming 'record' is non-null | |
|
| |
204 | throw RESOURCE_UNAVAILABLE; |
205 | |
206 | |
207 | JEventLoop *loop = event.GetJEventLoop(); |
| |
208 | if (initialized == false && loop) { |
| 8 | | Assuming the condition is true | |
|
| 9 | | Assuming pointer value is null | |
|
| 10 | | Assuming 'loop' is null | |
|
| |
209 | initialized = true; |
210 | dRunNumber = event.GetRunNumber(); |
211 | dapp = dynamic_cast<DApplication*>(loop->GetJApplication()); |
212 | if (dapp) { |
213 | jcalib = dapp->GetJCalibration(event.GetRunNumber()); |
214 | |
215 | if (!jcalib) { |
216 | _DBG_ << "ERROR - no jcalib set!" <<endl; |
217 | return RESOURCE_UNAVAILABLE; |
218 | } |
219 | |
220 | vector< map<string, float> > tvals; |
221 | if(jcalib->Get("FDC/strip_calib", tvals)) |
222 | throw JException("Could not load CCDB table: FDC/strip_calib"); |
223 | |
224 | if (tvals.size() != 192) { |
225 | _DBG_ << "ERROR - strip calibration vectors are not the right size!" |
226 | << endl; |
227 | return VALUE_OUT_OF_RANGE; |
228 | } |
229 | map<string,float>::iterator iter; |
230 | for (iter=tvals[0].begin(); iter!=tvals[0].end(); iter++) { |
231 | |
232 | |
233 | for (unsigned int i=0; i<tvals.size(); i++) { |
234 | map<string, float> &row = tvals[i]; |
235 | uscale[i]=row["qru"]; |
236 | vscale[i]=row["qrv"]; |
237 | } |
238 | } |
239 | } |
240 | |
241 | vector<const DBCALGeometry *> BCALGeomVec; |
242 | loop->Get(BCALGeomVec); |
243 | if(BCALGeomVec.size() == 0) |
244 | throw JException("Could not load DBCALGeometry object!"); |
245 | dBCALGeom = BCALGeomVec[0]; |
246 | |
247 | |
248 | vector<const DPSGeometry*> psGeomVect; |
249 | loop->Get(psGeomVect); |
250 | if (psGeomVect.size() < 1) |
251 | return OBJECT_NOT_AVAILABLE; |
252 | psGeom = psGeomVect[0]; |
253 | |
254 | |
255 | } |
256 | |
257 | |
258 | |
259 | |
260 | |
261 | |
262 | if(dRunNumber != event.GetRunNumber()) { |
| 12 | | Assuming the condition is false | |
|
| |
263 | jerr << endl |
264 | << "WARNING: DEventSourceHDDM cannot currently handle HDDM files containing" << endl |
265 | << "events with multiple runs! If you encounter this error message," << endl |
266 | << "please contact the GlueX Offline Software Group: halld-offline@jlab.org" << endl |
267 | << endl; |
268 | exit(-1); |
269 | } |
270 | |
271 | |
272 | |
273 | bool locNewRunNumber = false; |
274 | unsigned int locRunNumber = event.GetRunNumber(); |
275 | LockRead(); |
276 | { |
277 | locNewRunNumber = (dTargetCenterZMap.find(locRunNumber) == dTargetCenterZMap.end()); |
278 | } |
279 | UnlockRead(); |
280 | if(locNewRunNumber) |
| 14 | | Assuming 'locNewRunNumber' is false | |
|
| |
281 | { |
282 | DApplication* dapp = dynamic_cast<DApplication*>(loop->GetJApplication()); |
283 | DGeometry* locGeometry = dapp->GetDGeometry(loop->GetJEvent().GetRunNumber()); |
284 | double locTargetCenterZ = 0.0; |
285 | locGeometry->GetTargetZ(locTargetCenterZ); |
286 | |
287 | JGeometryXML *jgeom = dynamic_cast<JGeometryXML *>(locGeometry); |
288 | hddm_s::GeometryList geolist = record->getGeometrys(); |
289 | if (jgeom != 0 && geolist.size() > 0) { |
290 | std::string md5sim = geolist(0).getMd5simulation(); |
291 | std::string md5smear = geolist(0).getMd5smear(); |
292 | std::string md5recon = jgeom->GetChecksum(); |
293 | geolist(0).setMd5reconstruction(md5recon); |
294 | if (md5sim != md5smear) { |
295 | jerr << std::endl |
296 | << "WARNING: simulation geometry checksum does not match" |
297 | << " that shown for the mcsmear step." |
298 | << std::endl; |
299 | } |
300 | else if (md5sim != md5recon) { |
301 | jerr << endl |
302 | << "WARNING: simulation geometry checksum does not match" |
303 | << " the geometry being used for reconstruction." |
304 | << std::endl; |
305 | } |
306 | } |
307 | |
308 | vector<double> locBeamPeriodVector; |
309 | if(loop->GetCalib("PHOTON_BEAM/RF/beam_period", locBeamPeriodVector)) |
310 | throw runtime_error("Could not load CCDB table: PHOTON_BEAM/RF/beam_period"); |
311 | double locBeamBunchPeriod = locBeamPeriodVector[0]; |
312 | |
313 | LockRead(); |
314 | { |
315 | dTargetCenterZMap[locRunNumber] = locTargetCenterZ; |
316 | dBeamBunchPeriodMap[locRunNumber] = locBeamBunchPeriod; |
317 | } |
318 | UnlockRead(); |
319 | } |
320 | |
321 | |
322 | string dataClassName = factory->GetDataClassName(); |
323 | |
324 | if (dataClassName == "DPSHit") |
| 16 | | Calling 'operator==<char, std::char_traits<char>, std::allocator<char>>' | |
|
| 19 | | Returning from 'operator==<char, std::char_traits<char>, std::allocator<char>>' | |
|
| |
325 | return Extract_DPSHit(record, |
326 | dynamic_cast<JFactory<DPSHit>*>(factory), tag); |
327 | |
328 | if (dataClassName == "DPSTruthHit") |
| 21 | | Calling 'operator==<char, std::char_traits<char>, std::allocator<char>>' | |
|
| 24 | | Returning from 'operator==<char, std::char_traits<char>, std::allocator<char>>' | |
|
| |
329 | return Extract_DPSTruthHit(record, |
330 | dynamic_cast<JFactory<DPSTruthHit>*>(factory), tag); |
331 | |
332 | if (dataClassName == "DPSCHit") |
| 26 | | Calling 'operator==<char, std::char_traits<char>, std::allocator<char>>' | |
|
| 29 | | Returning from 'operator==<char, std::char_traits<char>, std::allocator<char>>' | |
|
| |
333 | return Extract_DPSCHit(record, |
334 | dynamic_cast<JFactory<DPSCHit>*>(factory), tag); |
335 | |
336 | if (dataClassName == "DPSCTruthHit") |
| 31 | | Calling 'operator==<char, std::char_traits<char>, std::allocator<char>>' | |
|
| 34 | | Returning from 'operator==<char, std::char_traits<char>, std::allocator<char>>' | |
|
| |
337 | return Extract_DPSCTruthHit(record, |
338 | dynamic_cast<JFactory<DPSCTruthHit>*>(factory), tag); |
339 | |
340 | if (dataClassName == "DRFTime") |
| 36 | | Calling 'operator==<char, std::char_traits<char>, std::allocator<char>>' | |
|
| 39 | | Returning from 'operator==<char, std::char_traits<char>, std::allocator<char>>' | |
|
| |
341 | return Extract_DRFTime(record, |
342 | dynamic_cast<JFactory<DRFTime>*>(factory), loop); |
343 | |
344 | if (dataClassName == "DTAGMHit") |
| 41 | | Calling 'operator==<char, std::char_traits<char>, std::allocator<char>>' | |
|
| 44 | | Returning from 'operator==<char, std::char_traits<char>, std::allocator<char>>' | |
|
| |
345 | return Extract_DTAGMHit(record, |
346 | dynamic_cast<JFactory<DTAGMHit>*>(factory), tag); |
347 | |
348 | if (dataClassName == "DTAGHHit") |
| 46 | | Calling 'operator==<char, std::char_traits<char>, std::allocator<char>>' | |
|
| 49 | | Returning from 'operator==<char, std::char_traits<char>, std::allocator<char>>' | |
|
| |
349 | return Extract_DTAGHHit(record, |
350 | dynamic_cast<JFactory<DTAGHHit>*>(factory), tag); |
351 | |
352 | if (dataClassName == "DMCTrackHit") |
| 51 | | Calling 'operator==<char, std::char_traits<char>, std::allocator<char>>' | |
|
| 54 | | Returning from 'operator==<char, std::char_traits<char>, std::allocator<char>>' | |
|
| |
353 | return Extract_DMCTrackHit(record, |
354 | dynamic_cast<JFactory<DMCTrackHit>*>(factory), tag); |
355 | |
356 | if (dataClassName == "DMCReaction") |
| 56 | | Calling 'operator==<char, std::char_traits<char>, std::allocator<char>>' | |
|
| 59 | | Returning from 'operator==<char, std::char_traits<char>, std::allocator<char>>' | |
|
| |
357 | return Extract_DMCReaction(record, |
| 62 | | Calling 'DEventSourceHDDM::Extract_DMCReaction' | |
|
358 | dynamic_cast<JFactory<DMCReaction>*>(factory), tag, loop); |
| 61 | | Passing null pointer value via 4th parameter 'loop' | |
|
359 | |
360 | if (dataClassName == "DMCThrown") |
361 | return Extract_DMCThrown(record, |
362 | dynamic_cast<JFactory<DMCThrown>*>(factory), tag); |
363 | |
364 | if (dataClassName == "DBCALTruthShower") |
365 | return Extract_DBCALTruthShower(record, |
366 | dynamic_cast<JFactory<DBCALTruthShower>*>(factory), tag); |
367 | |
368 | if (dataClassName == "DBCALSiPMSpectrum") |
369 | return Extract_DBCALSiPMSpectrum(record, |
370 | dynamic_cast<JFactory<DBCALSiPMSpectrum>*>(factory), tag); |
371 | |
372 | if (dataClassName == "DBCALTruthCell") |
373 | return Extract_DBCALTruthCell(record, |
374 | dynamic_cast<JFactory<DBCALTruthCell>*>(factory), tag); |
375 | |
376 | if (dataClassName == "DBCALSiPMHit") |
377 | return Extract_DBCALSiPMHit(record, |
378 | dynamic_cast<JFactory<DBCALSiPMHit>*>(factory), tag); |
379 | |
380 | if (dataClassName == "DBCALDigiHit") |
381 | return Extract_DBCALDigiHit(record, |
382 | dynamic_cast<JFactory<DBCALDigiHit>*>(factory), tag); |
383 | |
384 | if (dataClassName == "DBCALIncidentParticle") |
385 | return Extract_DBCALIncidentParticle(record, |
386 | dynamic_cast<JFactory<DBCALIncidentParticle>*>(factory), tag); |
387 | |
388 | if (dataClassName == "DBCALTDCDigiHit") |
389 | return Extract_DBCALTDCDigiHit(record, |
390 | dynamic_cast<JFactory<DBCALTDCDigiHit>*>(factory), tag); |
391 | |
392 | if (dataClassName == "DCDCHit") |
393 | return Extract_DCDCHit(loop, record, |
394 | dynamic_cast<JFactory<DCDCHit>*>(factory) , tag); |
395 | |
396 | if (dataClassName == "DFDCHit") |
397 | return Extract_DFDCHit(record, |
398 | dynamic_cast<JFactory<DFDCHit>*>(factory), tag); |
399 | |
400 | if (dataClassName == "DFCALTruthShower") |
401 | return Extract_DFCALTruthShower(record, |
402 | dynamic_cast<JFactory<DFCALTruthShower>*>(factory), tag); |
403 | |
404 | if (dataClassName == "DFCALHit") |
405 | return Extract_DFCALHit(record, |
406 | dynamic_cast<JFactory<DFCALHit>*>(factory), tag, |
407 | event.GetJEventLoop()); |
408 | |
409 | if (dataClassName == "DCCALTruthShower") |
410 | return Extract_DCCALTruthShower(record, |
411 | dynamic_cast<JFactory<DCCALTruthShower>*>(factory), tag); |
412 | |
413 | if (dataClassName == "DCCALHit") |
414 | return Extract_DCCALHit(record, |
415 | dynamic_cast<JFactory<DCCALHit>*>(factory), tag, |
416 | event.GetJEventLoop()); |
417 | |
418 | if (dataClassName == "DMCTrajectoryPoint" && tag == "") |
419 | return Extract_DMCTrajectoryPoint(record, |
420 | dynamic_cast<JFactory<DMCTrajectoryPoint>*>(factory), tag); |
421 | |
422 | if (dataClassName == "DTOFTruth") |
423 | return Extract_DTOFTruth(record, |
424 | dynamic_cast<JFactory<DTOFTruth>*>(factory), tag); |
425 | |
426 | |
427 | |
428 | if (dataClassName == "DTOFHit") { |
429 | JFactory_base* factory2 = loop->GetFactory("DTOFHitMC", tag.c_str()); |
430 | return Extract_DTOFHit(record, |
431 | dynamic_cast<JFactory<DTOFHit>*>(factory), |
432 | dynamic_cast<JFactory<DTOFHitMC>*>(factory2), tag); |
433 | } |
434 | if (dataClassName == "DTOFHitMC") { |
435 | JFactory_base* factory2 = loop->GetFactory("DTOFHit", tag.c_str()); |
436 | return Extract_DTOFHit(record, |
437 | dynamic_cast<JFactory<DTOFHit>*>(factory2), |
438 | dynamic_cast<JFactory<DTOFHitMC>*>(factory), tag); |
439 | } |
440 | |
441 | if (dataClassName == "DSCHit") |
442 | return Extract_DSCHit(record, |
443 | dynamic_cast<JFactory<DSCHit>*>(factory), tag); |
444 | |
445 | if (dataClassName == "DSCTruthHit") |
446 | return Extract_DSCTruthHit(record, |
447 | dynamic_cast<JFactory<DSCTruthHit>*>(factory), tag); |
448 | |
449 | if (dataClassName == "DFMWPCTruthHit") |
450 | return Extract_DFMWPCTruthHit(record, |
451 | dynamic_cast<JFactory<DFMWPCTruthHit>*>(factory), tag); |
452 | |
453 | if (dataClassName == "DFMWPCHit") |
454 | return Extract_DFMWPCHit(record, |
455 | dynamic_cast<JFactory<DFMWPCHit>*>(factory), tag); |
456 | |
457 | if (dataClassName == "DDIRCTruthBarHit") |
458 | return Extract_DDIRCTruthBarHit(record, |
459 | dynamic_cast<JFactory<DDIRCTruthBarHit>*>(factory), tag); |
460 | |
461 | if (dataClassName == "DDIRCTruthPmtHit") |
462 | return Extract_DDIRCTruthPmtHit(record, |
463 | dynamic_cast<JFactory<DDIRCTruthPmtHit>*>(factory), tag); |
464 | |
465 | if (dataClassName == "DDIRCPmtHit") |
466 | return Extract_DDIRCPmtHit(record, |
467 | dynamic_cast<JFactory<DDIRCPmtHit>*>(factory), tag, event.GetJEventLoop()); |
468 | |
469 | |
470 | |
471 | if (dataClassName == "DCereHit") |
472 | return Extract_DCereHit(record, |
473 | dynamic_cast<JFactory<DCereHit>*>(factory), tag); |
474 | |
475 | if (dataClassName == "DTPOLHit") |
476 | return Extract_DTPOLHit(record, |
477 | dynamic_cast<JFactory<DTPOLHit>*>(factory), tag); |
478 | |
479 | if (dataClassName == "DTPOLTruthHit") |
480 | return Extract_DTPOLTruthHit(record, |
481 | dynamic_cast<JFactory<DTPOLTruthHit>*>(factory), tag); |
482 | |
483 | return OBJECT_NOT_AVAILABLE; |
484 | } |
485 | |
486 | |
487 | |
488 | |
489 | jerror_t DEventSourceHDDM::Extract_DRFTime(hddm_s::HDDM *record, |
490 | JFactory<DRFTime> *factory, JEventLoop* locEventLoop) |
491 | { |
492 | if (factory==NULL) |
493 | return OBJECT_NOT_AVAILABLE; |
494 | string tag = (factory->Tag())? factory->Tag() : ""; |
495 | |
496 | vector<DRFTime*> locRFTimes; |
497 | |
498 | |
499 | const hddm_s::RFtimeList &rftimes = record->getRFtimes(); |
500 | hddm_s::RFtimeList::iterator iter; |
501 | for (iter = rftimes.begin(); iter != rftimes.end(); ++iter) |
502 | { |
503 | if (iter->getJtag() != tag) |
504 | continue; |
505 | DRFTime *locRFTime = new DRFTime; |
506 | locRFTime->dTime = iter->getTsync(); |
507 | locRFTime->dTimeVariance = 0.0; |
508 | locRFTimes.push_back(locRFTime); |
509 | } |
510 | |
511 | if(!locRFTimes.empty()) |
512 | { |
513 | |
514 | factory->CopyTo(locRFTimes); |
515 | return NOERROR; |
516 | } |
517 | |
518 | |
519 | |
520 | |
521 | |
522 | vector<const DBeamPhoton*> locMCGENPhotons; |
523 | locEventLoop->Get(locMCGENPhotons, "MCGEN"); |
524 | if(locMCGENPhotons.empty()) |
525 | return OBJECT_NOT_AVAILABLE; |
526 | |
527 | |
528 | |
529 | |
530 | |
531 | if(tag == "TRUTH") |
532 | { |
533 | DRFTime *locRFTime = new DRFTime; |
534 | locRFTime->dTime = locMCGENPhotons[0]->time(); |
535 | locRFTime->dTimeVariance = 0.0; |
536 | locRFTimes.push_back(locRFTime); |
537 | } |
538 | else |
539 | { |
540 | double locBeamBunchPeriod = 0.0; |
541 | int locRunNumber = locEventLoop->GetJEvent().GetRunNumber(); |
542 | LockRead(); |
543 | { |
544 | locBeamBunchPeriod = dBeamBunchPeriodMap[locRunNumber]; |
545 | } |
546 | UnlockRead(); |
547 | |
548 | |
549 | double locTime = locMCGENPhotons[0]->time(); |
550 | int locNumRFBuckets = int(locTime/locBeamBunchPeriod); |
551 | locTime -= double(locNumRFBuckets)*locBeamBunchPeriod; |
552 | while(locTime > 0.5*locBeamBunchPeriod) |
553 | locTime -= locBeamBunchPeriod; |
554 | while(locTime < -0.5*locBeamBunchPeriod) |
555 | locTime += locBeamBunchPeriod; |
556 | |
557 | DRFTime *locRFTime = new DRFTime; |
558 | locRFTime->dTime = locTime; |
559 | locRFTime->dTimeVariance = 0.0; |
560 | locRFTimes.push_back(locRFTime); |
561 | } |
562 | |
563 | |
564 | factory->CopyTo(locRFTimes); |
565 | |
566 | return NOERROR; |
567 | } |
568 | |
569 | |
570 | |
571 | |
572 | jerror_t DEventSourceHDDM::Extract_DMCTrackHit(hddm_s::HDDM *record, |
573 | JFactory<DMCTrackHit> *factory, string tag) |
574 | { |
575 | |
576 | |
577 | |
578 | |
579 | if (factory == NULL) |
580 | return OBJECT_NOT_AVAILABLE; |
581 | if (tag != "") |
582 | return OBJECT_NOT_AVAILABLE; |
583 | |
584 | |
585 | |
586 | vector<DMCTrackHit*> data; |
587 | GetCDCTruthHits(record, data); |
588 | GetFDCTruthHits(record, data); |
589 | GetBCALTruthHits(record, data); |
590 | GetTOFTruthHits(record, data); |
591 | GetCherenkovTruthHits(record, data); |
592 | GetFCALTruthHits(record, data); |
593 | GetSCTruthHits(record, data); |
594 | |
595 | |
596 | |
597 | |
598 | |
599 | |
600 | |
601 | for (unsigned int i=0; i < data.size(); i++) |
602 | if (!isfinite(data[i]->z)) |
603 | data[i]->z = -1000.0; |
604 | |
605 | |
606 | sort(data.begin(), data.end(), MCTrackHitSort_C); |
607 | |
608 | |
609 | |
610 | for (unsigned int i=0; i < data.size(); i++) { |
611 | DMCTrackHit *mctrackhit = data[i]; |
612 | if (mctrackhit->phi < 0.0) |
613 | mctrackhit->phi += 2.0*M_PI; |
614 | } |
615 | |
616 | |
617 | factory->CopyTo(data); |
618 | |
619 | return NOERROR; |
620 | } |
621 | |
622 | |
623 | |
624 | |
625 | jerror_t DEventSourceHDDM::GetCDCTruthHits(hddm_s::HDDM *record, |
626 | vector<DMCTrackHit*>& data) |
627 | { |
628 | const hddm_s::CdcTruthPointList &points = record->getCdcTruthPoints(); |
629 | hddm_s::CdcTruthPointList::iterator iter; |
630 | for (iter = points.begin(); iter != points.end(); ++iter) { |
631 | DMCTrackHit *mctrackhit = new DMCTrackHit; |
632 | mctrackhit->r = iter->getR(); |
633 | mctrackhit->phi = iter->getPhi(); |
634 | mctrackhit->z = iter->getZ(); |
635 | mctrackhit->track = iter->getTrack(); |
636 | mctrackhit->primary = iter->getPrimary(); |
637 | mctrackhit->ptype = iter->getPtype(); |
638 | mctrackhit->system = SYS_CDC; |
639 | const hddm_s::TrackIDList &ids = iter->getTrackIDs(); |
640 | mctrackhit->itrack = (ids.size())? ids.begin()->getItrack() : 0; |
641 | data.push_back(mctrackhit); |
642 | } |
643 | |
644 | return NOERROR; |
645 | } |
646 | |
647 | |
648 | |
649 | |
650 | jerror_t DEventSourceHDDM::GetFDCTruthHits(hddm_s::HDDM *record, |
651 | vector<DMCTrackHit*>& data) |
652 | { |
653 | const hddm_s::FdcTruthPointList &points = record->getFdcTruthPoints(); |
654 | hddm_s::FdcTruthPointList::iterator iter; |
655 | for (iter = points.begin(); iter != points.end(); ++iter) { |
656 | float x = iter->getX(); |
657 | float y = iter->getY(); |
658 | DMCTrackHit *mctrackhit = new DMCTrackHit; |
659 | mctrackhit->r = sqrt(x*x + y*y); |
660 | mctrackhit->phi = atan2(y,x); |
661 | mctrackhit->z = iter->getZ(); |
662 | mctrackhit->track = iter->getTrack(); |
663 | mctrackhit->primary = iter->getPrimary(); |
664 | mctrackhit->ptype = iter->getPtype(); |
665 | mctrackhit->system = SYS_FDC; |
666 | const hddm_s::TrackIDList &ids = iter->getTrackIDs(); |
667 | mctrackhit->itrack = (ids.size())? ids.begin()->getItrack() : 0; |
668 | data.push_back(mctrackhit); |
669 | } |
670 | |
671 | return NOERROR; |
672 | } |
673 | |
674 | |
675 | |
676 | |
677 | jerror_t DEventSourceHDDM::GetBCALTruthHits(hddm_s::HDDM *record, |
678 | vector<DMCTrackHit*>& data) |
679 | { |
680 | const hddm_s::BcalTruthShowerList &showers = record->getBcalTruthShowers(); |
681 | hddm_s::BcalTruthShowerList::iterator iter; |
682 | for (iter = showers.begin(); iter != showers.end(); ++iter) { |
683 | DMCTrackHit *mctrackhit = new DMCTrackHit; |
684 | mctrackhit->r = iter->getR(); |
685 | mctrackhit->phi = iter->getPhi(); |
686 | mctrackhit->z = iter->getZ(); |
687 | mctrackhit->track = iter->getTrack(); |
688 | mctrackhit->primary = iter->getPrimary(); |
689 | mctrackhit->ptype = iter->getPtype(); |
690 | mctrackhit->system = SYS_BCAL; |
691 | const hddm_s::TrackIDList &ids = iter->getTrackIDs(); |
692 | mctrackhit->itrack = (ids.size())? ids.begin()->getItrack() : 0; |
693 | data.push_back(mctrackhit); |
694 | } |
695 | |
696 | return NOERROR; |
697 | } |
698 | |
699 | |
700 | |
701 | |
702 | jerror_t DEventSourceHDDM::GetTOFTruthHits(hddm_s::HDDM *record, |
703 | vector<DMCTrackHit*>& data) |
704 | { |
705 | const hddm_s::FtofTruthPointList &points = record->getFtofTruthPoints(); |
706 | hddm_s::FtofTruthPointList::iterator iter; |
707 | for (iter = points.begin(); iter != points.end(); ++iter) { |
708 | float x = iter->getX(); |
709 | float y = iter->getY(); |
710 | DMCTrackHit *mctrackhit = new DMCTrackHit; |
711 | mctrackhit->r = sqrt(x*x + y*y); |
712 | mctrackhit->phi = atan2(y,x); |
713 | mctrackhit->z = iter->getZ(); |
714 | mctrackhit->track = iter->getTrack(); |
715 | mctrackhit->primary = iter->getPrimary(); |
716 | mctrackhit->ptype = iter->getPtype(); |
717 | mctrackhit->system = SYS_TOF; |
718 | const hddm_s::TrackIDList &ids = iter->getTrackIDs(); |
719 | mctrackhit->itrack = (ids.size())? ids.begin()->getItrack() : 0; |
720 | data.push_back(mctrackhit); |
721 | } |
722 | |
723 | return NOERROR; |
724 | } |
725 | |
726 | |
727 | |
728 | |
729 | |
730 | jerror_t DEventSourceHDDM::GetCherenkovTruthHits(hddm_s::HDDM *record, |
731 | vector<DMCTrackHit*>& data) |
732 | { |
733 | const hddm_s::CereTruthPointList &points = record->getCereTruthPoints(); |
734 | hddm_s::CereTruthPointList::iterator iter; |
735 | for (iter = points.begin(); iter != points.end(); ++iter) { |
736 | float x = iter->getX(); |
737 | float y = iter->getY(); |
738 | DMCTrackHit *mctrackhit = new DMCTrackHit; |
739 | mctrackhit->r = sqrt(x*x + y*y); |
740 | mctrackhit->phi = atan2(y,x); |
741 | mctrackhit->z = iter->getZ(); |
742 | mctrackhit->track = iter->getTrack(); |
743 | mctrackhit->primary = iter->getPrimary(); |
744 | mctrackhit->ptype = iter->getPtype(); |
745 | mctrackhit->system = SYS_CHERENKOV; |
746 | const hddm_s::TrackIDList &ids = iter->getTrackIDs(); |
747 | mctrackhit->itrack = (ids.size())? ids.begin()->getItrack() : 0; |
748 | data.push_back(mctrackhit); |
749 | } |
750 | |
751 | return NOERROR; |
752 | } |
753 | |
754 | |
755 | |
756 | |
757 | jerror_t DEventSourceHDDM::GetFCALTruthHits(hddm_s::HDDM *record, |
758 | vector<DMCTrackHit*>& data) |
759 | { |
760 | const hddm_s::FcalTruthShowerList &points = record->getFcalTruthShowers(); |
761 | hddm_s::FcalTruthShowerList::iterator iter; |
762 | for (iter = points.begin(); iter != points.end(); ++iter) { |
763 | float x = iter->getX(); |
764 | float y = iter->getY(); |
765 | DMCTrackHit *mctrackhit = new DMCTrackHit; |
766 | mctrackhit->r = sqrt(x*x + y*y); |
767 | mctrackhit->phi = atan2(y,x); |
768 | mctrackhit->z = iter->getZ(); |
769 | mctrackhit->track = iter->getTrack(); |
770 | mctrackhit->primary = iter->getPrimary(); |
771 | mctrackhit->ptype = iter->getPtype(); |
772 | mctrackhit->system = SYS_FCAL; |
773 | const hddm_s::TrackIDList &ids = iter->getTrackIDs(); |
774 | mctrackhit->itrack = (ids.size())? ids.begin()->getItrack() : 0; |
775 | data.push_back(mctrackhit); |
776 | } |
777 | |
778 | return NOERROR; |
779 | } |
780 | |
781 | |
782 | |
783 | |
784 | jerror_t DEventSourceHDDM::GetCCALTruthHits(hddm_s::HDDM *record, |
785 | vector<DMCTrackHit*>& data) |
786 | { |
787 | const hddm_s::CcalTruthShowerList &points = record->getCcalTruthShowers(); |
788 | hddm_s::CcalTruthShowerList::iterator iter; |
789 | for (iter = points.begin(); iter != points.end(); ++iter) { |
790 | float x = iter->getX(); |
791 | float y = iter->getY(); |
792 | DMCTrackHit *mctrackhit = new DMCTrackHit; |
793 | mctrackhit->r = sqrt(x*x + y*y); |
794 | mctrackhit->phi = atan2(y,x); |
795 | mctrackhit->z = iter->getZ(); |
796 | mctrackhit->track = iter->getTrack(); |
797 | mctrackhit->primary = iter->getPrimary(); |
798 | mctrackhit->ptype = iter->getPtype(); |
799 | mctrackhit->system = SYS_CCAL; |
800 | const hddm_s::TrackIDList &ids = iter->getTrackIDs(); |
801 | mctrackhit->itrack = (ids.size())? ids.begin()->getItrack() : 0; |
802 | data.push_back(mctrackhit); |
803 | } |
804 | |
805 | return NOERROR; |
806 | } |
807 | |
808 | |
809 | |
810 | |
811 | |
812 | jerror_t DEventSourceHDDM::GetSCTruthHits(hddm_s::HDDM *record, |
813 | vector<DMCTrackHit*>& data) |
814 | { |
815 | const hddm_s::StcTruthPointList &points = record->getStcTruthPoints(); |
816 | hddm_s::StcTruthPointList::iterator iter; |
817 | for (iter = points.begin(); iter != points.end(); ++iter) { |
818 | DMCTrackHit *mctrackhit = new DMCTrackHit; |
819 | mctrackhit->r = iter->getR(); |
820 | mctrackhit->phi = iter->getPhi(); |
821 | mctrackhit->z = iter->getZ(); |
822 | mctrackhit->track = iter->getTrack(); |
823 | mctrackhit->primary = iter->getPrimary(); |
824 | mctrackhit->ptype = iter->getPtype(); |
825 | mctrackhit->system = SYS_START; |
826 | const hddm_s::TrackIDList &ids = iter->getTrackIDs(); |
827 | mctrackhit->itrack = (ids.size())? ids.begin()->getItrack() : 0; |
828 | data.push_back(mctrackhit); |
829 | } |
830 | |
831 | return NOERROR; |
832 | } |
833 | |
834 | |
835 | |
836 | |
837 | jerror_t DEventSourceHDDM::Extract_DBCALSiPMHit(hddm_s::HDDM *record, |
838 | JFactory<DBCALSiPMHit> *factory, string tag) |
839 | { |
840 | |
841 | |
842 | |
843 | |
844 | if (factory == NULL) |
845 | return OBJECT_NOT_AVAILABLE; |
846 | if (tag != "") |
847 | return OBJECT_NOT_AVAILABLE; |
848 | |
849 | vector<DBCALSiPMHit*> data; |
850 | |
851 | const hddm_s::BcalSiPMUpHitList &uphits = record->getBcalSiPMUpHits(); |
852 | hddm_s::BcalSiPMUpHitList::iterator uiter; |
853 | for (uiter = uphits.begin(); uiter != uphits.end(); ++uiter) { |
854 | DBCALSiPMHit *response = new DBCALSiPMHit; |
855 | response->module = uiter->getModule(); |
856 | response->layer = uiter->getLayer(); |
857 | response->sector = uiter->getSector(); |
858 | response->E = uiter->getE(); |
859 | response->t = uiter->getT(); |
860 | response->end = DBCALGeometry::kUpstream; |
861 | response->cellId = dBCALGeom->cellId(uiter->getModule(), |
862 | uiter->getLayer(), |
863 | uiter->getSector()); |
864 | data.push_back(response); |
865 | } |
866 | |
867 | const hddm_s::BcalSiPMDownHitList &downhits = record->getBcalSiPMDownHits(); |
868 | hddm_s::BcalSiPMDownHitList::iterator diter; |
869 | for (diter = downhits.begin(); diter != downhits.end(); ++diter) { |
870 | DBCALSiPMHit *response = new DBCALSiPMHit; |
871 | response->module = diter->getModule(); |
872 | response->layer = diter->getLayer(); |
873 | response->sector = diter->getSector(); |
874 | response->E = diter->getE(); |
875 | response->t = diter->getT(); |
876 | response->end = DBCALGeometry::kDownstream; |
877 | response->cellId = dBCALGeom->cellId(diter->getModule(), |
878 | diter->getLayer(), |
879 | diter->getSector()); |
880 | data.push_back(response); |
881 | } |
882 | |
883 | |
884 | factory->CopyTo(data); |
885 | |
886 | return NOERROR; |
887 | } |
888 | |
889 | |
890 | |
891 | |
892 | jerror_t DEventSourceHDDM::Extract_DBCALDigiHit(hddm_s::HDDM *record, |
893 | JFactory<DBCALDigiHit> *factory, string tag) |
894 | { |
895 | |
896 | |
897 | |
898 | |
899 | if (factory == NULL) |
900 | return OBJECT_NOT_AVAILABLE; |
901 | if (tag != "") |
902 | return OBJECT_NOT_AVAILABLE; |
903 | |
904 | vector<DBCALDigiHit*> data; |
905 | |
906 | const hddm_s::BcalfADCDigiHitList &digihits = record->getBcalfADCDigiHits(); |
907 | hddm_s::BcalfADCDigiHitList::iterator iter; |
908 | for (iter = digihits.begin(); iter != digihits.end(); ++iter) { |
909 | DBCALDigiHit *response = new DBCALDigiHit; |
910 | response->module = iter->getModule(); |
911 | response->layer = iter->getLayer(); |
912 | response->sector = iter->getSector(); |
913 | response->pulse_integral = (uint32_t)iter->getPulse_integral(); |
914 | response->pulse_peak = 0; |
915 | if(iter->getBcalfADCPeaks().size() > 0) { |
916 | response->pulse_peak = iter->getBcalfADCPeak().getPeakAmp(); |
917 | } |
918 | response->pulse_time = (uint32_t)iter->getPulse_time(); |
919 | response->pedestal = 1; |
920 | response->QF = 1; |
921 | response->nsamples_integral = 1; |
922 | response->nsamples_pedestal = 1; |
923 | response->datasource = 3; |
924 | response->end = (iter->getEnd() == 0)? DBCALGeometry::kUpstream : |
925 | DBCALGeometry::kDownstream; |
926 | data.push_back(response); |
927 | } |
928 | |
929 | |
930 | factory->CopyTo(data); |
931 | |
932 | return NOERROR; |
933 | } |
934 | |
935 | |
936 | |
937 | |
938 | jerror_t DEventSourceHDDM::Extract_DBCALIncidentParticle(hddm_s::HDDM *record, |
939 | JFactory<DBCALIncidentParticle> *factory, |
940 | string tag) |
941 | { |
942 | |
943 | |
944 | |
945 | |
946 | if (factory == NULL) |
947 | return OBJECT_NOT_AVAILABLE; |
948 | if (tag != "") |
949 | return OBJECT_NOT_AVAILABLE; |
950 | |
951 | vector<DBCALIncidentParticle*> data; |
952 | |
953 | const hddm_s::BcalTruthIncidentParticleList &plist = |
954 | record->getBcalTruthIncidentParticles(); |
955 | hddm_s::BcalTruthIncidentParticleList::iterator iter; |
956 | for (iter = plist.begin(); iter != plist.end(); ++iter) { |
957 | DBCALIncidentParticle *part = new DBCALIncidentParticle; |
958 | part->ptype = iter->getPtype(); |
959 | part->px = iter->getPx(); |
960 | part->py = iter->getPy(); |
961 | part->pz = iter->getPz(); |
962 | part->x = iter->getX(); |
963 | part->y = iter->getY(); |
964 | part->z = iter->getZ(); |
965 | data.push_back(part); |
966 | } |
967 | |
968 | factory->CopyTo(data); |
969 | |
970 | return NOERROR; |
971 | } |
972 | |
973 | |
974 | |
975 | |
976 | jerror_t DEventSourceHDDM::Extract_DBCALSiPMSpectrum(hddm_s::HDDM *record, |
977 | JFactory<DBCALSiPMSpectrum> *factory, |
978 | string tag) |
979 | { |
980 | |
981 | |
982 | |
983 | |
984 | if (factory == NULL) |
985 | return OBJECT_NOT_AVAILABLE; |
986 | if (tag != "" && tag != "TRUTH") |
987 | return OBJECT_NOT_AVAILABLE; |
988 | |
989 | vector<DBCALSiPMSpectrum*> data; |
990 | |
991 | const hddm_s::BcalSiPMSpectrumList &specs = record->getBcalSiPMSpectrums(); |
992 | hddm_s::BcalSiPMSpectrumList::iterator iter; |
993 | for (iter = specs.begin(); iter != specs.end(); ++iter) { |
994 | DBCALSiPMSpectrum *dana_spectrum = new DBCALSiPMSpectrum; |
995 | dana_spectrum->module = iter->getModule(); |
996 | dana_spectrum->layer = iter->getLayer(); |
997 | dana_spectrum->sector = iter->getSector(); |
998 | dana_spectrum->end = (iter->getEnd()==0)? |
999 | DBCALGeometry::kUpstream : |
1000 | DBCALGeometry::kDownstream; |
1001 | if (tag == "") |
1002 | dana_spectrum->incident_id = 0; |
1003 | else if (tag == "TRUTH") { |
1004 | const hddm_s::BcalSiPMTruthList &truths = iter->getBcalSiPMTruths(); |
1005 | if (truths.size() > 0) |
1006 | dana_spectrum->incident_id = truths.begin()->getIncident_id(); |
1007 | else |
1008 | dana_spectrum->incident_id = 0; |
1009 | } |
1010 | |
1011 | double t = iter->getTstart(); |
1012 | double bin_width = iter->getBin_width(); |
1013 | stringstream ss(iter->getVals()); |
1014 | |
1015 | |
1016 | string entry; |
1017 | while (ss >> entry) { |
1018 | if (entry[0] == 'X') { |
1019 | |
1020 | stringstream sss(entry.substr(1)); |
1021 | int num_zeros; |
1022 | sss >> num_zeros; |
1023 | |
1024 | for(int i=0; i<num_zeros; i++) { |
1025 | dana_spectrum->spectrum.Fill(t, 0.0); |
1026 | t += bin_width; |
1027 | } |
1028 | } else { |
1029 | stringstream sss(entry); |
1030 | double dE; |
1031 | sss >> dE; |
1032 | dana_spectrum->spectrum.Fill(t, dE); |
1033 | t += bin_width; |
1034 | } |
1035 | } |
1036 | |
1037 | data.push_back(dana_spectrum); |
1038 | } |
1039 | |
1040 | |
1041 | factory->CopyTo(data); |
1042 | |
1043 | return NOERROR; |
1044 | } |
1045 | |
1046 | |
1047 | |
1048 | |
1049 | jerror_t DEventSourceHDDM::Extract_DBCALTDCDigiHit(hddm_s::HDDM *record, |
1050 | JFactory<DBCALTDCDigiHit> *factory, string tag) |
1051 | { |
1052 | |
1053 | |
1054 | |
1055 | |
1056 | if (factory == NULL) |
1057 | return OBJECT_NOT_AVAILABLE; |
1058 | if (tag != "") |
1059 | return OBJECT_NOT_AVAILABLE; |
1060 | |
1061 | vector<DBCALTDCDigiHit*> data; |
1062 | |
1063 | const hddm_s::BcalTDCDigiHitList &hits = record->getBcalTDCDigiHits(); |
1064 | hddm_s::BcalTDCDigiHitList::iterator iter; |
1065 | for (iter = hits.begin(); iter != hits.end(); ++iter) { |
1066 | DBCALTDCDigiHit *bcaltdchit = new DBCALTDCDigiHit; |
1067 | bcaltdchit->module = iter->getModule(); |
1068 | bcaltdchit->layer = iter->getLayer(); |
1069 | bcaltdchit->sector = iter->getSector(); |
1070 | bcaltdchit->end = (iter->getEnd() == 0)? DBCALGeometry::kUpstream : |
1071 | DBCALGeometry::kDownstream; |
1072 | bcaltdchit->time = (uint32_t)iter->getTime(); |
1073 | data.push_back(bcaltdchit); |
1074 | } |
1075 | |
1076 | |
1077 | factory->CopyTo(data); |
1078 | |
1079 | return NOERROR; |
1080 | } |
1081 | |
1082 | |
1083 | |
1084 | |
1085 | jerror_t DEventSourceHDDM::Extract_DMCReaction(hddm_s::HDDM *record, |
1086 | JFactory<DMCReaction> *factory, string tag, |
1087 | JEventLoop *loop) |
1088 | { |
1089 | |
1090 | |
1091 | |
1092 | |
1093 | if (tag != "") |
| 63 | | Calling 'operator!=<char, std::char_traits<char>, std::allocator<char>>' | |
|
| 69 | | Returning from 'operator!=<char, std::char_traits<char>, std::allocator<char>>' | |
|
| |
1094 | return OBJECT_NOT_AVAILABLE; |
1095 | |
1096 | if (factory == NULL) |
| |
1097 | return OBJECT_NOT_AVAILABLE; |
1098 | |
1099 | double locTargetCenterZ = 0.0; |
1100 | int locRunNumber = loop->GetJEvent().GetRunNumber(); |
| 72 | | Called C++ object pointer is null |
|
1101 | LockRead(); |
1102 | { |
1103 | locTargetCenterZ = dTargetCenterZMap[locRunNumber]; |
1104 | } |
1105 | UnlockRead(); |
1106 | DVector3 locPosition(0.0, 0.0, locTargetCenterZ); |
1107 | |
1108 | vector<DMCReaction*> dmcreactions; |
1109 | |
1110 | const hddm_s::ReactionList &reacts = record->getReactions(); |
1111 | hddm_s::ReactionList::iterator iter; |
1112 | for (iter = reacts.begin(); iter != reacts.end(); ++iter) { |
1113 | DMCReaction *mcreaction = new DMCReaction; |
1114 | dmcreactions.push_back(mcreaction); |
1115 | mcreaction->type = iter->getType(); |
1116 | mcreaction->weight = iter->getWeight(); |
1117 | hddm_s::Origin &origin = iter->getVertex().getOrigin(); |
1118 | double torig = origin.getT(); |
1119 | double zorig = origin.getVz(); |
1120 | |
1121 | const hddm_s::BeamList &beams = record->getBeams(); |
1122 | if (beams.size() > 0) { |
1123 | hddm_s::Beam &beam = iter->getBeam(); |
1124 | DVector3 mom(beam.getMomentum().getPx(), |
1125 | beam.getMomentum().getPy(), |
1126 | beam.getMomentum().getPz()); |
1127 | mcreaction->beam.setPosition(locPosition); |
1128 | mcreaction->beam.setMomentum(mom); |
1129 | mcreaction->beam.setPID(Gamma); |
1130 | mcreaction->target.setPID(IDTrack(mcreaction->beam.charge(), |
1131 | mcreaction->beam.mass())); |
1132 | mcreaction->beam.setTime(torig - (zorig - locTargetCenterZ)/29.9792458); |
1133 | } |
1134 | else { |
1135 | |
1136 | mcreaction->beam.setPosition(locPosition); |
1137 | mcreaction->beam.setPID(Gamma); |
1138 | } |
1139 | |
1140 | const hddm_s::TargetList &targets = record->getTargets(); |
1141 | if (targets.size() > 0) { |
1142 | hddm_s::Target &target = iter->getTarget(); |
1143 | DKinematicData target_kd; |
1144 | DVector3 mom(target.getMomentum().getPx(), |
1145 | target.getMomentum().getPy(), |
1146 | target.getMomentum().getPz()); |
1147 | mcreaction->target.setPosition(locPosition); |
1148 | mcreaction->target.setMomentum(mom); |
1149 | mcreaction->target.setPID(IDTrack(target.getProperties().getCharge(), |
1150 | target.getProperties().getMass())); |
1151 | mcreaction->target.setTime(torig - (zorig - locTargetCenterZ)/29.9792458); |
1152 | } |
1153 | else { |
1154 | |
1155 | mcreaction->target.setPosition(locPosition); |
1156 | } |
1157 | } |
1158 | |
1159 | |
1160 | |
1161 | |
1162 | factory->CopyTo(dmcreactions); |
1163 | |
1164 | return NOERROR; |
1165 | } |
1166 | |
1167 | |
1168 | |
1169 | |
1170 | jerror_t DEventSourceHDDM::Extract_DMCThrown(hddm_s::HDDM *record, |
1171 | JFactory<DMCThrown> *factory, string tag) |
1172 | { |
1173 | |
1174 | |
1175 | |
1176 | |
1177 | if (factory == NULL) |
1178 | return OBJECT_NOT_AVAILABLE; |
1179 | if (tag != "") |
1180 | return OBJECT_NOT_AVAILABLE; |
1181 | |
1182 | vector<DMCThrown*> data; |
1183 | |
1184 | const hddm_s::VertexList &verts = record->getVertices(); |
1185 | hddm_s::VertexList::iterator iter; |
1186 | for (iter = verts.begin(); iter != verts.end(); ++iter) { |
1187 | const hddm_s::OriginList &origs = iter->getOrigins(); |
1188 | const hddm_s::ProductList &prods = iter->getProducts(); |
1189 | double vertex[4] = {0., 0., 0., 0.}; |
1190 | if (origs.size() > 0) { |
1191 | vertex[0] = iter->getOrigin().getT(); |
1192 | vertex[1] = iter->getOrigin().getVx(); |
1193 | vertex[2] = iter->getOrigin().getVy(); |
1194 | vertex[3] = iter->getOrigin().getVz(); |
1195 | } |
1196 | hddm_s::ProductList::iterator piter; |
1197 | for (piter = prods.begin(); piter != prods.end(); ++piter) { |
1198 | double E = piter->getMomentum().getE(); |
1199 | double px = piter->getMomentum().getPx(); |
1200 | double py = piter->getMomentum().getPy(); |
1201 | double pz = piter->getMomentum().getPz(); |
1202 | double mass = sqrt(E*E - (px*px + py*py + pz*pz)); |
1203 | if (!isfinite(mass)) |
1204 | mass = 0.0; |
1205 | DMCThrown *mcthrown = new DMCThrown; |
1206 | mcthrown->type = piter->getType(); |
1207 | mcthrown->myid = piter->getId(); |
1208 | mcthrown->parentid = piter->getParentid(); |
1209 | mcthrown->mech = piter->getMech(); |
1210 | mcthrown->pdgtype = piter->getPdgtype(); |
1211 | mcthrown->setPID((Particle_t)mcthrown->type); |
1212 | mcthrown->setMomentum(DVector3(px, py, pz)); |
1213 | mcthrown->setPosition(DVector3(vertex[1], vertex[2], vertex[3])); |
1214 | mcthrown->setTime(vertex[0]); |
1215 | data.push_back(mcthrown); |
1216 | } |
1217 | } |
1218 | |
1219 | |
1220 | factory->CopyTo(data); |
1221 | |
1222 | return NOERROR; |
1223 | } |
1224 | |
1225 | |
1226 | |
1227 | |
1228 | jerror_t DEventSourceHDDM::Extract_DCDCHit(JEventLoop* locEventLoop, hddm_s::HDDM *record, |
1229 | JFactory<DCDCHit> *factory, string tag) |
1230 | { |
1231 | |
1232 | |
1233 | |
1234 | |
1235 | if (factory == NULL) |
1236 | return OBJECT_NOT_AVAILABLE; |
1237 | |
1238 | |
1239 | |
1240 | |
1241 | |
1242 | |
1243 | if (tag != "TRUTH" && tag != "Calib") |
1244 | return OBJECT_NOT_AVAILABLE; |
1245 | |
1246 | vector<DCDCHit*> data; |
1247 | |
1248 | if ( tag == "" || tag == "Calib" ) { |
1249 | vector<const DCDCHit*> locTruthHits; |
1250 | locEventLoop->Get(locTruthHits, "TRUTH"); |
1251 | |
1252 | |
1253 | map<pair<int, int>, vector<const DCDCHit*>> locTruthHitMap; |
1254 | for(auto& locTruthHit : locTruthHits) |
1255 | locTruthHitMap[std::make_pair(locTruthHit->ring, locTruthHit->straw)].push_back(locTruthHit); |
1256 | |
1257 | const hddm_s::CdcStrawHitList &hits = record->getCdcStrawHits(); |
1258 | hddm_s::CdcStrawHitList::iterator iter; |
1259 | int locIndex = 0; |
1260 | for (iter = hits.begin(); iter != hits.end(); ++iter) { |
1261 | DCDCHit *hit = new DCDCHit; |
1262 | hit->ring = iter->getRing(); |
1263 | hit->straw = iter->getStraw(); |
1264 | hit->q = iter->getQ(); |
1265 | hit->t = iter->getT(); |
1266 | if(iter->getCdcDigihits().size() > 0) { |
1267 | hit->amp = iter->getCdcDigihit().getPeakAmp(); |
1268 | } |
1269 | else{ |
1270 | |
1271 | |
1272 | hit->amp=hit->q; |
1273 | } |
1274 | hit->QF = 0; |
1275 | if(iter->getCdcHitQFs().size() > 0) { |
1276 | hit->QF = iter->getCdcHitQF().getQF(); |
1277 | } |
1278 | hit->d = 0.; |
1279 | hit->itrack = 0; |
1280 | hit->ptype = 0; |
1281 | |
1282 | |
1283 | auto& locPotentialTruthHits = locTruthHitMap[std::make_pair(hit->ring, hit->straw)]; |
1284 | double locBestDeltaT = 9.9E99; |
1285 | const DCDCHit* locBestTruthHit = nullptr; |
1286 | for(auto& locTruthHit : locPotentialTruthHits) |
1287 | { |
1288 | auto locDeltaT = fabs(hit->t - locTruthHit->t); |
1289 | if(locDeltaT >= locBestDeltaT) |
1290 | continue; |
1291 | locBestDeltaT = locDeltaT; |
1292 | locBestTruthHit = locTruthHit; |
1293 | } |
1294 | if(locBestTruthHit != nullptr) |
1295 | hit->AddAssociatedObject(locBestTruthHit); |
1296 | |
1297 | data.push_back(hit); |
1298 | ++locIndex; |
1299 | } |
1300 | } |
1301 | else if (tag == "TRUTH") { |
1302 | const hddm_s::CdcStrawTruthHitList &thits = record->getCdcStrawTruthHits(); |
1303 | hddm_s::CdcStrawTruthHitList::iterator iter; |
1304 | for (iter = thits.begin(); iter != thits.end(); ++iter) { |
1305 | DCDCHit *hit = new DCDCHit; |
1306 | hit->ring = iter->getRing(); |
1307 | hit->straw = iter->getStraw(); |
1308 | hit->q = iter->getQ(); |
1309 | hit->t = iter->getT(); |
1310 | hit->d = iter->getD(); |
1311 | hit->itrack = iter->getItrack(); |
1312 | hit->ptype = iter->getPtype(); |
1313 | data.push_back(hit); |
1314 | } |
1315 | } |
1316 | |
1317 | |
1318 | factory->CopyTo(data); |
1319 | |
1320 | return NOERROR; |
1321 | } |
1322 | |
1323 | |
1324 | |
1325 | |
1326 | |
1327 | jerror_t DEventSourceHDDM::Extract_DFDCHit(hddm_s::HDDM *record, |
1328 | JFactory<DFDCHit> *factory, string tag) |
1329 | { |
1330 | |
1331 | |
1332 | |
1333 | |
1334 | if (factory == NULL) |
1335 | return OBJECT_NOT_AVAILABLE; |
1336 | if (tag != "" && tag != "TRUTH" && tag != "CALIB") |
1337 | return OBJECT_NOT_AVAILABLE; |
1338 | |
1339 | vector<DFDCHit*> data; |
1340 | |
1341 | if (tag == "") { |
1342 | const hddm_s::FdcAnodeHitList &ahits = record->getFdcAnodeHits(); |
1343 | hddm_s::FdcAnodeHitList::iterator ahiter; |
1344 | for (ahiter = ahits.begin(); ahiter != ahits.end(); ++ahiter) { |
1345 | DFDCHit* newHit = new DFDCHit(); |
1346 | newHit->layer = ahiter->getLayer(); |
1347 | newHit->module = ahiter->getModule(); |
1348 | newHit->element = ahiter->getWire(); |
1349 | newHit->q = ahiter->getDE(); |
1350 | newHit->pulse_height = 0.; |
1351 | newHit->t = ahiter->getT(); |
1352 | newHit->d = 0.; |
1353 | newHit->itrack = 0; |
1354 | newHit->ptype = 0; |
1355 | newHit->plane = 2; |
1356 | newHit->type = 0; |
1357 | newHit->gPlane = DFDCGeometry::gPlane(newHit); |
1358 | newHit->gLayer = DFDCGeometry::gLayer(newHit); |
1359 | newHit->r = DFDCGeometry::getWireR(newHit); |
1360 | data.push_back(newHit); |
1361 | } |
1362 | |
1363 | |
1364 | const hddm_s::FdcCathodeHitList &chits = record->getFdcCathodeHits(); |
1365 | hddm_s::FdcCathodeHitList::iterator chiter; |
1366 | for (chiter = chits.begin(); chiter != chits.end(); ++chiter) { |
1367 | DFDCHit* newHit = new DFDCHit(); |
1368 | newHit->layer = chiter->getLayer(); |
1369 | newHit->module = chiter->getModule(); |
1370 | newHit->element = chiter->getStrip(); |
1371 | if (newHit->element > 1000) |
1372 | newHit->element -= 1000; |
1373 | newHit->plane = chiter->getPlane(); |
1374 | newHit->q = chiter->getQ(); |
1375 | newHit->pulse_height = newHit->q; |
1376 | if(chiter->getFdcDigihits().size() > 0) { |
1377 | newHit->pulse_height = chiter->getFdcDigihit().getPeakAmp(); |
1378 | } |
1379 | newHit->t = chiter->getT(); |
1380 | newHit->d = 0.; |
1381 | newHit->itrack = 0; |
1382 | newHit->ptype = 0; |
1383 | newHit->type = 1; |
1384 | newHit->gPlane = DFDCGeometry::gPlane(newHit); |
1385 | newHit->gLayer = DFDCGeometry::gLayer(newHit); |
1386 | newHit->r = DFDCGeometry::getStripR(newHit); |
1387 | data.push_back(newHit); |
1388 | } |
1389 | } |
1390 | |
1391 | else if (tag == "TRUTH"){ |
1392 | const hddm_s::FdcAnodeTruthHitList &aths = record->getFdcAnodeTruthHits(); |
1393 | hddm_s::FdcAnodeTruthHitList::iterator atiter; |
1394 | for (atiter = aths.begin(); atiter != aths.end(); ++atiter) { |
1395 | DFDCHit* newHit = new DFDCHit(); |
1396 | newHit->layer = atiter->getLayer(); |
1397 | newHit->module = atiter->getModule(); |
1398 | newHit->element = atiter->getWire(); |
1399 | newHit->q = atiter->getDE(); |
1400 | newHit->pulse_height=0.; |
1401 | newHit->t = atiter->getT(); |
1402 | newHit->d = atiter->getD(); |
1403 | newHit->itrack = atiter->getItrack(); |
1404 | newHit->ptype = atiter->getPtype(); |
1405 | newHit->plane = 2; |
1406 | newHit->type = 0; |
1407 | newHit->gPlane = DFDCGeometry::gPlane(newHit); |
1408 | newHit->gLayer = DFDCGeometry::gLayer(newHit); |
1409 | newHit->r = DFDCGeometry::getWireR(newHit); |
1410 | data.push_back(newHit); |
1411 | } |
1412 | |
1413 | |
1414 | const hddm_s::FdcCathodeTruthHitList &cths = |
1415 | record->getFdcCathodeTruthHits(); |
1416 | hddm_s::FdcCathodeTruthHitList::iterator ctiter; |
1417 | for (ctiter = cths.begin(); ctiter != cths.end(); ++ctiter) { |
1418 | DFDCHit* newHit = new DFDCHit(); |
1419 | newHit->layer = ctiter->getLayer(); |
1420 | newHit->module = ctiter->getModule(); |
1421 | newHit->element = ctiter->getStrip(); |
1422 | if (newHit->element > 1000) |
1423 | newHit->element -= 1000; |
1424 | newHit->plane = ctiter->getPlane(); |
1425 | newHit->q = ctiter->getQ(); |
1426 | newHit->pulse_height = newHit->q; |
1427 | newHit->t = ctiter->getT(); |
1428 | newHit->d = 0.; |
1429 | newHit->itrack = ctiter->getItrack(); |
1430 | newHit->ptype = ctiter->getPtype(); |
1431 | newHit->type = 1; |
1432 | newHit->gPlane = DFDCGeometry::gPlane(newHit); |
1433 | newHit->gLayer = DFDCGeometry::gLayer(newHit); |
1434 | newHit->r = DFDCGeometry::getStripR(newHit); |
1435 | data.push_back(newHit); |
1436 | } |
1437 | } |
1438 | |
1439 | else if (tag == "CALIB") { |
1440 | |
1441 | const hddm_s::FdcAnodeHitList &ahits = record->getFdcAnodeHits(); |
1442 | hddm_s::FdcAnodeHitList::iterator ahiter; |
1443 | for (ahiter = ahits.begin(); ahiter != ahits.end(); ++ahiter) { |
1444 | DFDCHit* newHit = new DFDCHit(); |
1445 | newHit->layer = ahiter->getLayer(); |
1446 | newHit->module = ahiter->getModule(); |
1447 | newHit->element = ahiter->getWire(); |
1448 | newHit->q = ahiter->getDE(); |
1449 | newHit->t = ahiter->getT(); |
1450 | newHit->d = 0.; |
1451 | newHit->itrack = 0; |
1452 | newHit->ptype = 0; |
1453 | newHit->plane = 2; |
1454 | newHit->type = 0; |
1455 | newHit->gPlane = DFDCGeometry::gPlane(newHit); |
1456 | newHit->gLayer = DFDCGeometry::gLayer(newHit); |
1457 | newHit->r = DFDCGeometry::getWireR(newHit); |
1458 | data.push_back(newHit); |
1459 | } |
1460 | |
1461 | |
1462 | const hddm_s::FdcCathodeHitList &chits = record->getFdcCathodeHits(); |
1463 | hddm_s::FdcCathodeHitList::iterator chiter; |
1464 | for (chiter = chits.begin(); chiter != chits.end(); ++chiter) { |
1465 | DFDCHit* newHit = new DFDCHit(); |
1466 | newHit->layer = chiter->getLayer(); |
1467 | newHit->module = chiter->getModule(); |
1468 | newHit->element = chiter->getStrip(); |
1469 | if (newHit->element > 1000) |
1470 | newHit->element-=1000; |
1471 | newHit->plane = chiter->getPlane(); |
1472 | if (newHit->plane == 1) |
1473 | newHit->q = chiter->getQ()*vscale[newHit->element-1]; |
1474 | else |
1475 | newHit->q = chiter->getQ()*uscale[newHit->element-1]; |
1476 | newHit->t = chiter->getT(); |
1477 | newHit->d = 0.; |
1478 | newHit->itrack = 0; |
1479 | newHit->ptype = 0; |
1480 | newHit->type = 1; |
1481 | newHit->gPlane = DFDCGeometry::gPlane(newHit); |
1482 | newHit->gLayer = DFDCGeometry::gLayer(newHit); |
1483 | newHit->r = DFDCGeometry::getStripR(newHit); |
1484 | data.push_back(newHit); |
1485 | } |
1486 | } |
1487 | |
1488 | |
1489 | factory->CopyTo(data); |
1490 | |
1491 | return NOERROR; |
1492 | } |
1493 | |
1494 | |
1495 | |
1496 | |
1497 | jerror_t DEventSourceHDDM::Extract_DBCALTruthShower(hddm_s::HDDM *record, |
1498 | JFactory<DBCALTruthShower> *factory, |
1499 | string tag) |
1500 | { |
1501 | |
1502 | |
1503 | |
1504 | |
1505 | if (factory == NULL) |
1506 | return OBJECT_NOT_AVAILABLE; |
1507 | if (tag != "") |
1508 | return OBJECT_NOT_AVAILABLE; |
1509 | |
1510 | vector<DBCALTruthShower*> data; |
1511 | |
1512 | const hddm_s::BcalTruthShowerList &shows = record->getBcalTruthShowers(); |
1513 | hddm_s::BcalTruthShowerList::iterator iter; |
1514 | for (iter = shows.begin(); iter != shows.end(); ++iter) { |
1515 | DBCALTruthShower *bcaltruth = new DBCALTruthShower; |
1516 | bcaltruth->track = iter->getTrack(); |
1517 | bcaltruth->ptype = iter->getPtype(); |
1518 | bcaltruth->primary = (iter->getPrimary())? 1 : 0; |
1519 | bcaltruth->phi = iter->getPhi(); |
1520 | bcaltruth->r = iter->getR(); |
1521 | bcaltruth->z = iter->getZ(); |
1522 | bcaltruth->t = iter->getT(); |
1523 | bcaltruth->E = iter->getE(); |
1524 | bcaltruth->px = iter->getPx(); |
1525 | bcaltruth->py = iter->getPy(); |
1526 | bcaltruth->pz = iter->getPz(); |
1527 | const hddm_s::TrackIDList &ids = iter->getTrackIDs(); |
1528 | bcaltruth->itrack = (ids.size())? ids.begin()->getItrack() : 0; |
1529 | data.push_back(bcaltruth); |
1530 | } |
1531 | |
1532 | |
1533 | factory->CopyTo(data); |
1534 | |
1535 | return NOERROR; |
1536 | } |
1537 | |
1538 | |
1539 | |
1540 | |
1541 | jerror_t DEventSourceHDDM::Extract_DBCALTruthCell(hddm_s::HDDM *record, |
1542 | JFactory<DBCALTruthCell> *factory, |
1543 | string tag) |
1544 | { |
1545 | |
1546 | |
1547 | |
1548 | |
1549 | if (factory == NULL) |
1550 | return OBJECT_NOT_AVAILABLE; |
1551 | if (tag != "") |
1552 | return OBJECT_NOT_AVAILABLE; |
1553 | |
1554 | vector<DBCALTruthCell*> data; |
1555 | |
1556 | const hddm_s::BcalTruthHitList &hits = record->getBcalTruthHits(); |
1557 | hddm_s::BcalTruthHitList::iterator hiter; |
1558 | for (hiter = hits.begin(); hiter != hits.end(); ++hiter) { |
1559 | DBCALTruthCell *truthcell = new DBCALTruthCell(); |
1560 | truthcell->module = hiter->getModule(); |
1561 | truthcell->layer = hiter->getLayer(); |
1562 | truthcell->sector = hiter->getSector(); |
1563 | truthcell->E = hiter->getE(); |
1564 | truthcell->t = hiter->getT(); |
1565 | truthcell->zLocal = hiter->getZLocal(); |
1566 | data.push_back(truthcell); |
1567 | } |
1568 | |
1569 | |
1570 | factory->CopyTo(data); |
1571 | |
1572 | return NOERROR; |
1573 | } |
1574 | |
1575 | |
1576 | |
1577 | |
1578 | jerror_t DEventSourceHDDM::Extract_DFCALTruthShower(hddm_s::HDDM *record, |
1579 | JFactory<DFCALTruthShower> *factory, |
1580 | string tag) |
1581 | { |
1582 | |
1583 | |
1584 | |
1585 | |
1586 | if (factory == NULL) |
1587 | return OBJECT_NOT_AVAILABLE; |
1588 | if (tag != "") |
1589 | return OBJECT_NOT_AVAILABLE; |
1590 | |
1591 | vector<DFCALTruthShower*> data; |
1592 | JObject::oid_t id=1; |
1593 | |
1594 | const hddm_s::FcalTruthShowerList &shows = record->getFcalTruthShowers(); |
1595 | hddm_s::FcalTruthShowerList::iterator iter; |
1596 | for (iter = shows.begin(); iter != shows.end(); ++iter) { |
1597 | const hddm_s::TrackIDList &ids = iter->getTrackIDs(); |
1598 | int itrack = (ids.size())? ids.begin()->getItrack() : 0; |
1599 | DFCALTruthShower *dfcaltruthshower = new DFCALTruthShower( |
1600 | id++, |
1601 | iter->getX(), |
1602 | iter->getY(), |
1603 | iter->getZ(), |
1604 | iter->getPx(), |
1605 | iter->getPy(), |
1606 | iter->getPz(), |
1607 | iter->getE(), |
1608 | iter->getT(), |
1609 | iter->getPrimary(), |
1610 | iter->getTrack(), |
1611 | iter->getPtype(), |
1612 | itrack |
1613 | ); |
1614 | data.push_back(dfcaltruthshower); |
1615 | } |
1616 | |
1617 | |
1618 | factory->CopyTo(data); |
1619 | |
1620 | return NOERROR; |
1621 | } |
1622 | |
1623 | |
1624 | |
1625 | |
1626 | jerror_t DEventSourceHDDM::Extract_DFCALHit(hddm_s::HDDM *record, |
1627 | JFactory<DFCALHit> *factory, string tag, |
1628 | JEventLoop* eventLoop) |
1629 | { |
1630 | |
1631 | |
1632 | |
1633 | |
1634 | if (factory == NULL) |
1635 | return OBJECT_NOT_AVAILABLE; |
1636 | if (tag != "" && tag != "TRUTH") |
1637 | return OBJECT_NOT_AVAILABLE; |
1638 | |
1639 | |
1640 | vector<const DFCALGeometry*> fcalGeomVect; |
1641 | eventLoop->Get( fcalGeomVect ); |
1642 | if (fcalGeomVect.size() < 1) |
1643 | return OBJECT_NOT_AVAILABLE; |
1644 | const DFCALGeometry& fcalGeom = *(fcalGeomVect[0]); |
1645 | |
1646 | vector<DFCALHit*> data; |
1647 | |
1648 | if (tag == "") { |
1649 | const hddm_s::FcalHitList &hits = record->getFcalHits(); |
1650 | hddm_s::FcalHitList::iterator iter; |
1651 | for (iter = hits.begin(); iter != hits.end(); ++iter) { |
1652 | int row = iter->getRow(); |
1653 | int column = iter->getColumn(); |
1654 | |
1655 | |
1656 | if (!fcalGeom.isBlockActive(row, column)) |
1657 | continue; |
1658 | |
1659 | |
1660 | |
1661 | DVector2 pos = fcalGeom.positionOnFace(row, column); |
1662 | |
1663 | DFCALHit *mchit = new DFCALHit(); |
1664 | mchit->row = row; |
1665 | mchit->column = column; |
1666 | mchit->x = pos.X(); |
1667 | mchit->y = pos.Y(); |
1668 | mchit->E = iter->getE(); |
1669 | mchit->t = iter->getT(); |
1670 | mchit->intOverPeak = 6.; |
1671 | if(iter->getFcalDigihits().size() > 0) { |
1672 | mchit->intOverPeak = iter->getFcalDigihit().getIntegralOverPeak(); |
1673 | } |
1674 | data.push_back(mchit); |
1675 | } |
1676 | } |
1677 | else if (tag == "TRUTH") { |
1678 | const hddm_s::FcalTruthHitList &hits = record->getFcalTruthHits(); |
1679 | hddm_s::FcalTruthHitList::iterator iter; |
1680 | for (iter = hits.begin(); iter != hits.end(); ++iter) { |
1681 | int row = iter->getRow(); |
1682 | int column = iter->getColumn(); |
1683 | |
1684 | |
1685 | if (!fcalGeom.isBlockActive(row, column)) |
1686 | continue; |
1687 | |
1688 | |
1689 | |
1690 | DVector2 pos = fcalGeom.positionOnFace(row, column); |
1691 | |
1692 | DFCALHit *mchit = new DFCALHit(); |
1693 | mchit->row = row; |
1694 | mchit->column = column; |
1695 | mchit->x = pos.X(); |
1696 | mchit->y = pos.Y(); |
1697 | mchit->E = iter->getE(); |
1698 | mchit->t = iter->getT(); |
1699 | mchit->intOverPeak = 6.; |
1700 | data.push_back(mchit); |
1701 | } |
1702 | } |
1703 | |
1704 | |
1705 | factory->CopyTo(data); |
1706 | |
1707 | return NOERROR; |
1708 | } |
1709 | |
1710 | |
1711 | |
1712 | |
1713 | jerror_t DEventSourceHDDM::Extract_DCCALTruthShower(hddm_s::HDDM *record, |
1714 | JFactory<DCCALTruthShower> *factory, |
1715 | string tag) |
1716 | { |
1717 | |
1718 | |
1719 | |
1720 | |
1721 | if (factory == NULL) |
1722 | return OBJECT_NOT_AVAILABLE; |
1723 | if (tag != "") |
1724 | return OBJECT_NOT_AVAILABLE; |
1725 | |
1726 | vector<DCCALTruthShower*> data; |
1727 | JObject::oid_t id=1; |
1728 | |
1729 | const hddm_s::CcalTruthShowerList &shows = record->getCcalTruthShowers(); |
1730 | hddm_s::CcalTruthShowerList::iterator iter; |
1731 | for (iter = shows.begin(); iter != shows.end(); ++iter) { |
1732 | const hddm_s::TrackIDList &ids = iter->getTrackIDs(); |
1733 | int itrack = (ids.size())? ids.begin()->getItrack() : 0; |
1734 | DCCALTruthShower *dccaltruthshower = new DCCALTruthShower( |
1735 | id++, |
1736 | iter->getX(), |
1737 | iter->getY(), |
1738 | iter->getZ(), |
1739 | iter->getPx(), |
1740 | iter->getPy(), |
1741 | iter->getPz(), |
1742 | iter->getE(), |
1743 | iter->getT(), |
1744 | iter->getPrimary(), |
1745 | iter->getTrack(), |
1746 | iter->getPtype(), |
1747 | itrack |
1748 | ); |
1749 | data.push_back(dccaltruthshower); |
1750 | } |
1751 | |
1752 | |
1753 | factory->CopyTo(data); |
1754 | |
1755 | return NOERROR; |
1756 | } |
1757 | |
1758 | |
1759 | |
1760 | |
1761 | jerror_t DEventSourceHDDM::Extract_DCCALHit(hddm_s::HDDM *record, |
1762 | JFactory<DCCALHit> *factory, string tag, |
1763 | JEventLoop* eventLoop) |
1764 | { |
1765 | |
1766 | |
1767 | |
1768 | |
1769 | if (factory == NULL) |
1770 | return OBJECT_NOT_AVAILABLE; |
1771 | if (tag != "" && tag != "TRUTH") |
1772 | return OBJECT_NOT_AVAILABLE; |
1773 | |
1774 | |
1775 | vector<const DCCALGeometry*> ccalGeomVect; |
1776 | eventLoop->Get( ccalGeomVect ); |
1777 | if (ccalGeomVect.size() < 1) |
1778 | return OBJECT_NOT_AVAILABLE; |
1779 | const DCCALGeometry& ccalGeom = *(ccalGeomVect[0]); |
1780 | |
1781 | vector<DCCALHit*> data; |
1782 | int hitId = 0; |
1783 | |
1784 | if (tag == "") { |
1785 | const hddm_s::CcalHitList &hits = record->getCcalHits(); |
1786 | hddm_s::CcalHitList::iterator iter; |
1787 | for (iter = hits.begin(); iter != hits.end(); ++iter) { |
1788 | int row = iter->getRow(); |
1789 | int column = iter->getColumn(); |
1790 | |
1791 | |
1792 | if (!ccalGeom.isBlockActive(row, column)) |
1793 | continue; |
1794 | |
1795 | |
1796 | |
1797 | DVector2 pos = ccalGeom.positionOnFace(row, column); |
1798 | |
1799 | DCCALHit *mchit = new DCCALHit(); |
1800 | mchit->row = row; |
1801 | mchit->column = column; |
1802 | mchit->x = pos.X(); |
1803 | mchit->y = pos.Y(); |
1804 | mchit->E = iter->getE(); |
1805 | mchit->t = iter->getT(); |
1806 | mchit->id = hitId++; |
1807 | data.push_back(mchit); |
1808 | } |
1809 | } |
1810 | |
1811 | else if (tag == "TRUTH") { |
1812 | const hddm_s::CcalTruthHitList &hits = record->getCcalTruthHits(); |
1813 | hddm_s::CcalTruthHitList::iterator iter; |
1814 | for (iter = hits.begin(); iter != hits.end(); ++iter) { |
1815 | int row = iter->getRow(); |
1816 | int column = iter->getColumn(); |
1817 | |
1818 | |
1819 | if (!ccalGeom.isBlockActive(row, column)) |
1820 | continue; |
1821 | |
1822 | |
1823 | |
1824 | DVector2 pos = ccalGeom.positionOnFace(row, column); |
1825 | |
1826 | DCCALHit *mchit = new DCCALHit(); |
1827 | mchit->row = row; |
1828 | mchit->column = column; |
1829 | mchit->x = pos.X(); |
1830 | mchit->y = pos.Y(); |
1831 | mchit->E = iter->getE(); |
1832 | mchit->t = iter->getT(); |
1833 | mchit->id = hitId++; |
1834 | data.push_back(mchit); |
1835 | } |
1836 | } |
1837 | |
1838 | |
1839 | factory->CopyTo(data); |
1840 | |
1841 | return NOERROR; |
1842 | } |
1843 | |
1844 | |
1845 | |
1846 | |
1847 | jerror_t DEventSourceHDDM::Extract_DMCTrajectoryPoint(hddm_s::HDDM *record, |
1848 | JFactory<DMCTrajectoryPoint> *factory, |
1849 | string tag) |
1850 | { |
1851 | |
1852 | |
1853 | |
1854 | |
1855 | if (factory == NULL) |
1856 | return OBJECT_NOT_AVAILABLE; |
1857 | if (tag != "") |
1858 | return OBJECT_NOT_AVAILABLE; |
1859 | |
1860 | vector<DMCTrajectoryPoint*> data; |
1861 | |
1862 | const hddm_s::McTrajectoryPointList &pts = record->getMcTrajectoryPoints(); |
1863 | hddm_s::McTrajectoryPointList::iterator iter; |
1864 | for (iter = pts.begin(); iter != pts.end(); ++iter) { |
1865 | DMCTrajectoryPoint *p = new DMCTrajectoryPoint; |
1866 | p->x = iter->getX(); |
1867 | p->y = iter->getY(); |
1868 | p->z = iter->getZ(); |
1869 | p->t = iter->getT(); |
1870 | p->px = iter->getPx(); |
1871 | p->py = iter->getPy(); |
1872 | p->pz = iter->getPz(); |
1873 | p->E = iter->getE(); |
1874 | p->dE = iter->getDE(); |
1875 | p->primary_track = iter->getPrimary_track(); |
1876 | p->track = iter->getTrack(); |
1877 | p->part = iter->getPart(); |
1878 | p->radlen = iter->getRadlen(); |
1879 | p->step = iter->getStep(); |
1880 | p->mech = iter->getMech(); |
1881 | data.push_back(p); |
1882 | } |
1883 | |
1884 | |
1885 | factory->CopyTo(data); |
1886 | |
1887 | return NOERROR; |
1888 | } |
1889 | |
1890 | |
1891 | |
1892 | |
1893 | jerror_t DEventSourceHDDM::Extract_DTOFTruth(hddm_s::HDDM *record, |
1894 | JFactory<DTOFTruth>* factory, string tag) |
1895 | { |
1896 | |
1897 | |
1898 | |
1899 | |
1900 | if (factory == NULL) |
1901 | return OBJECT_NOT_AVAILABLE; |
1902 | if (tag != "") |
1903 | return OBJECT_NOT_AVAILABLE; |
1904 | |
1905 | vector<DTOFTruth*> data; |
1906 | |
1907 | const hddm_s::FtofTruthPointList &points = record->getFtofTruthPoints(); |
1908 | hddm_s::FtofTruthPointList::iterator iter; |
1909 | for (iter = points.begin(); iter != points.end(); ++iter) { |
1910 | DTOFTruth *toftruth = new DTOFTruth; |
1911 | toftruth->primary = iter->getPrimary(); |
1912 | toftruth->track = iter->getTrack(); |
1913 | toftruth->x = iter->getX(); |
1914 | toftruth->y = iter->getY(); |
1915 | toftruth->z = iter->getZ(); |
1916 | toftruth->t = iter->getT(); |
1917 | toftruth->px = iter->getPx(); |
1918 | toftruth->py = iter->getPy(); |
1919 | toftruth->pz = iter->getPz(); |
1920 | toftruth->E = iter->getE(); |
1921 | toftruth->ptype = iter->getPtype(); |
1922 | const hddm_s::TrackIDList &ids = iter->getTrackIDs(); |
1923 | toftruth->itrack = (ids.size())? ids.begin()->getItrack() : 0; |
1924 | data.push_back(toftruth); |
1925 | } |
1926 | |
1927 | |
1928 | factory->CopyTo(data); |
1929 | |
1930 | return NOERROR; |
1931 | } |
1932 | |
1933 | |
1934 | |
1935 | |
1936 | jerror_t DEventSourceHDDM::Extract_DTOFHit( hddm_s::HDDM *record, |
1937 | JFactory<DTOFHit>* factory, |
1938 | JFactory<DTOFHitMC> *factoryMC, |
1939 | string tag) |
1940 | { |
1941 | |
1942 | |
1943 | |
1944 | |
1945 | if (factory == NULL) |
1946 | return OBJECT_NOT_AVAILABLE; |
1947 | if (tag != "" && tag != "TRUTH") |
1948 | return OBJECT_NOT_AVAILABLE; |
1949 | |
1950 | vector<DTOFHit*> data; |
1951 | vector<DTOFHitMC*> dataMC; |
1952 | |
1953 | const hddm_s::FtofCounterList &ctrs = record->getFtofCounters(); |
1954 | hddm_s::FtofCounterList::iterator iter; |
1955 | for (iter = ctrs.begin(); iter != ctrs.end(); ++iter) { |
1956 | if (tag == "") { |
1957 | vector<DTOFHit*> north_hits; |
1958 | vector<DTOFHit*> south_hits; |
1959 | |
1960 | |
1961 | const hddm_s::FtofHitList &hits = iter->getFtofHits(); |
1962 | hddm_s::FtofHitList::iterator hiter; |
1963 | for (hiter = hits.begin(); hiter != hits.end(); ++hiter) { |
1964 | DTOFHit *tofhit = new DTOFHit; |
1965 | tofhit->bar = hiter->getBar(); |
1966 | tofhit->plane = hiter->getPlane(); |
1967 | tofhit->end = hiter->getEnd(); |
1968 | tofhit->dE = hiter->getDE(); |
1969 | tofhit->Amp = 0.; |
1970 | if(hiter->getFtofDigihits().size() > 0) { |
1971 | tofhit->Amp = hiter->getFtofDigihit().getPeakAmp(); |
1972 | } |
1973 | tofhit->t = hiter->getT(); |
1974 | tofhit->t_TDC = tofhit->t; |
1975 | tofhit->t_fADC= tofhit->t; |
1976 | tofhit->has_TDC=true; |
1977 | tofhit->has_fADC=true; |
1978 | data.push_back(tofhit); |
1979 | if (tofhit->end == 0) |
1980 | north_hits.push_back(tofhit); |
1981 | else |
1982 | south_hits.push_back(tofhit); |
1983 | } |
1984 | |
1985 | |
1986 | const hddm_s::FtofTruthHitList &truths = iter->getFtofTruthHits(); |
1987 | hddm_s::FtofTruthHitList::iterator titer; |
1988 | unsigned int north_mchits = 0; |
1989 | unsigned int south_mchits = 0; |
1990 | for (titer = truths.begin(); titer != truths.end(); ++titer) { |
1991 | DTOFHitMC *tofmchit = new DTOFHitMC; |
1992 | tofmchit->bar = titer->getBar(); |
1993 | tofmchit->plane = titer->getPlane(); |
1994 | tofmchit->end = titer->getEnd(); |
1995 | tofmchit->itrack = titer->getFtofTruthExtra(0).getItrack(); |
1996 | tofmchit->ptype = titer->getFtofTruthExtra(0).getPtype(); |
1997 | tofmchit->dist = titer->getFtofTruthExtra(0).getDist(); |
1998 | tofmchit->x = titer->getFtofTruthExtra(0).getX(); |
1999 | tofmchit->y = titer->getFtofTruthExtra(0).getY(); |
2000 | tofmchit->z = titer->getFtofTruthExtra(0).getZ(); |
2001 | tofmchit->px = titer->getFtofTruthExtra(0).getPx(); |
2002 | tofmchit->py = titer->getFtofTruthExtra(0).getPy(); |
2003 | tofmchit->pz = titer->getFtofTruthExtra(0).getPz(); |
2004 | tofmchit->E = titer->getFtofTruthExtra(0).getE(); |
2005 | dataMC.push_back(tofmchit); |
2006 | |
2007 | |
2008 | if (tofmchit->end == 0) { |
2009 | if (north_mchits < north_hits.size()) { |
2010 | north_hits[north_mchits]->AddAssociatedObject(tofmchit); |
2011 | } |
2012 | north_mchits++; |
2013 | } |
2014 | else { |
2015 | if (south_mchits < south_hits.size()) { |
2016 | south_hits[south_mchits]->AddAssociatedObject(tofmchit); |
2017 | } |
2018 | south_mchits++; |
2019 | } |
2020 | } |
2021 | } |
2022 | |
2023 | else if (tag == "TRUTH") { |
2024 | const hddm_s::FtofTruthHitList &truths = iter->getFtofTruthHits(); |
2025 | hddm_s::FtofTruthHitList::iterator titer; |
2026 | for (titer = truths.begin(); titer != truths.end(); ++titer) { |
2027 | DTOFHit *tofhit = new DTOFHit; |
2028 | tofhit->bar = titer->getBar(); |
2029 | tofhit->plane = titer->getPlane(); |
2030 | tofhit->end = titer->getEnd(); |
2031 | tofhit->dE = titer->getDE(); |
2032 | tofhit->t = titer->getT(); |
2033 | tofhit->t_fADC= tofhit->t; |
2034 | tofhit->t_TDC = tofhit->t; |
2035 | tofhit->has_TDC=true; |
2036 | tofhit->has_fADC=true; |
2037 | data.push_back(tofhit); |
2038 | |
2039 | DTOFHitMC *tofmchit = new DTOFHitMC; |
2040 | tofmchit->bar = tofhit->bar; |
2041 | tofmchit->plane = tofhit->plane; |
2042 | tofmchit->end = tofhit->end; |
2043 | tofmchit->itrack = titer->getFtofTruthExtra().getItrack(); |
2044 | tofmchit->ptype = titer->getFtofTruthExtra().getPtype(); |
2045 | tofmchit->dist = titer->getFtofTruthExtra().getDist(); |
2046 | tofmchit->x = titer->getFtofTruthExtra().getX(); |
2047 | tofmchit->y = titer->getFtofTruthExtra().getY(); |
2048 | tofmchit->z = titer->getFtofTruthExtra().getZ(); |
2049 | tofmchit->px = titer->getFtofTruthExtra().getPx(); |
2050 | tofmchit->py = titer->getFtofTruthExtra().getPy(); |
2051 | tofmchit->pz = titer->getFtofTruthExtra().getPz(); |
2052 | tofmchit->E = titer->getFtofTruthExtra().getE(); |
2053 | dataMC.push_back(tofmchit); |
2054 | tofhit->AddAssociatedObject(tofmchit); |
2055 | } |
2056 | } |
2057 | } |
2058 | |
2059 | |
2060 | factory->CopyTo(data); |
2061 | factoryMC->CopyTo(dataMC); |
2062 | |
2063 | return NOERROR; |
2064 | } |
2065 | |
2066 | |
2067 | |
2068 | |
2069 | jerror_t DEventSourceHDDM::Extract_DSCHit(hddm_s::HDDM *record, |
2070 | JFactory<DSCHit>* factory, string tag) |
2071 | { |
2072 | |
2073 | |
2074 | |
2075 | |
2076 | if (factory == NULL) |
2077 | return OBJECT_NOT_AVAILABLE; |
2078 | if (tag != "" && tag != "TRUTH") |
2079 | return OBJECT_NOT_AVAILABLE; |
2080 | |
2081 | vector<DSCHit*> data; |
2082 | |
2083 | if (tag == "") { |
2084 | const hddm_s::StcHitList &hits = record->getStcHits(); |
2085 | hddm_s::StcHitList::iterator iter; |
2086 | for (iter = hits.begin(); iter != hits.end(); ++iter) { |
2087 | DSCHit *hit = new DSCHit; |
2088 | hit->sector = iter->getSector(); |
2089 | hit->dE = iter->getDE(); |
2090 | hit->t = iter->getT(); |
2091 | hit->t_TDC=hit->t; |
2092 | hit->t_fADC=hit->t; |
2093 | hit->pulse_height = 0.; |
2094 | if(iter->getStcDigihits().size() > 0) { |
2095 | hit->pulse_height = iter->getStcDigihit().getPeakAmp(); |
2096 | } |
2097 | hit->has_TDC=true; |
2098 | hit->has_fADC=true; |
2099 | data.push_back(hit); |
2100 | } |
2101 | } |
2102 | else if (tag == "TRUTH") { |
2103 | const hddm_s::StcTruthHitList &hits = record->getStcTruthHits(); |
2104 | hddm_s::StcTruthHitList::iterator iter; |
2105 | for (iter = hits.begin(); iter != hits.end(); ++iter) { |
2106 | DSCHit *hit = new DSCHit; |
2107 | hit->sector = iter->getSector(); |
2108 | hit->dE = iter->getDE(); |
2109 | hit->t = iter->getT(); |
2110 | hit->t_TDC=hit->t; |
2111 | hit->t_fADC=hit->t; |
2112 | hit->has_TDC=true; |
2113 | hit->has_fADC=true; |
2114 | data.push_back(hit); |
2115 | } |
2116 | } |
2117 | |
2118 | |
2119 | factory->CopyTo(data); |
2120 | |
2121 | return NOERROR; |
2122 | } |
2123 | |
2124 | |
2125 | |
2126 | |
2127 | jerror_t DEventSourceHDDM::Extract_DSCTruthHit(hddm_s::HDDM *record, |
2128 | JFactory<DSCTruthHit>* factory, string tag) |
2129 | { |
2130 | |
2131 | |
2132 | |
2133 | |
2134 | if (factory == NULL) |
2135 | return OBJECT_NOT_AVAILABLE; |
2136 | if (tag != "") |
2137 | return OBJECT_NOT_AVAILABLE; |
2138 | |
2139 | vector<DSCTruthHit*> data; |
2140 | |
2141 | const hddm_s::StcTruthPointList &points = record->getStcTruthPoints(); |
2142 | hddm_s::StcTruthPointList::iterator iter; |
2143 | for (iter = points.begin(); iter != points.end(); ++iter) { |
2144 | DSCTruthHit *hit = new DSCTruthHit; |
2145 | hit->dEdx = iter->getDEdx(); |
2146 | hit->phi = iter->getPhi(); |
2147 | hit->primary = iter->getPrimary(); |
2148 | hit->ptype = iter->getPtype(); |
2149 | hit->r = iter->getR(); |
2150 | hit->t = iter->getT(); |
2151 | hit->z = iter->getZ(); |
2152 | hit->track = iter->getTrack(); |
2153 | hit->sector = iter->getSector(); |
2154 | const hddm_s::TrackIDList &ids = iter->getTrackIDs(); |
2155 | hit->itrack = (ids.size())? ids.begin()->getItrack() : 0; |
2156 | data.push_back(hit); |
2157 | } |
2158 | |
2159 | |
2160 | factory->CopyTo(data); |
2161 | |
2162 | return NOERROR; |
2163 | } |
2164 | |
2165 | |
2166 | |
2167 | |
2168 | jerror_t DEventSourceHDDM::Extract_DTrackTimeBased(hddm_s::HDDM *record, |
2169 | JFactory<DTrackTimeBased> *factory, |
2170 | string tag, int32_t runnumber, JEventLoop* locEventLoop) |
2171 | { |
2172 | |
2173 | |
2174 | |
2175 | |
2176 | |
2177 | |
2178 | if (factory == NULL) |
2179 | return OBJECT_NOT_AVAILABLE; |
2180 | if (tag != "") |
2181 | return OBJECT_NOT_AVAILABLE; |
2182 | |
2183 | vector<DTrackTimeBased*> data; |
2184 | vector<DReferenceTrajectory*> rts; |
2185 | |
2186 | const hddm_s::TracktimebasedList &ttbs = record->getTracktimebaseds(); |
2187 | hddm_s::TracktimebasedList::iterator iter; |
2188 | for (iter = ttbs.begin(); iter != ttbs.end(); ++iter) { |
2189 | DVector3 mom(iter->getMomentum().getPx(), |
2190 | iter->getMomentum().getPy(), |
2191 | iter->getMomentum().getPz()); |
2192 | DVector3 pos(iter->getOrigin().getVx(), |
2193 | iter->getOrigin().getVy(), |
2194 | iter->getOrigin().getVz()); |
2195 | DTrackTimeBased *track = new DTrackTimeBased(); |
2196 | track->setMomentum(mom); |
2197 | track->setPosition(pos); |
2198 | track->setPID(IDTrack(iter->getProperties().getCharge(), |
2199 | iter->getProperties().getMass())); |
2200 | track->chisq = iter->getChisq(); |
2201 | track->Ndof = iter->getNdof(); |
2202 | track->FOM = iter->getFOM(); |
2203 | track->candidateid = iter->getCandidateid(); |
2204 | track->id = iter->getId(); |
2205 | |
2206 | |
2207 | auto locCovarianceMatrix = dResourcePool_TMatrixFSym->Get_SharedResource(); |
2208 | locCovarianceMatrix->ResizeTo(7, 7); |
2209 | string str_vals = iter->getErrorMatrix().getVals(); |
2210 | StringToTMatrixFSym(str_vals, locCovarianceMatrix.get(), |
2211 | iter->getErrorMatrix().getNrows(), |
2212 | iter->getErrorMatrix().getNcols()); |
2213 | track->setErrorMatrix(locCovarianceMatrix); |
2214 | |
2215 | |
2216 | str_vals = iter->getTrackingErrorMatrix().getVals(); |
2217 | auto TrackingErrorMatrix = dResourcePool_TMatrixFSym->Get_SharedResource(); |
2218 | TrackingErrorMatrix->ResizeTo(5, 5); |
2219 | StringToTMatrixFSym(str_vals, TrackingErrorMatrix.get(), |
2220 | iter->getTrackingErrorMatrix().getNrows(), |
2221 | iter->getTrackingErrorMatrix().getNcols()); |
2222 | track->setTrackingErrorMatrix(TrackingErrorMatrix); |
2223 | |
2224 | data.push_back(track); |
2225 | } |
2226 | |
2227 | |
2228 | if (ttbs.size() > 0){ |
2229 | factory->CopyTo(data); |
2230 | |
2231 | |
2232 | |
2233 | |
2234 | return NOERROR; |
2235 | } |
2236 | |
2237 | |
2238 | |
2239 | return OBJECT_NOT_AVAILABLE; |
2240 | } |
2241 | |
2242 | |
2243 | |
2244 | |
2245 | |
2246 | string DEventSourceHDDM::StringToTMatrixFSym(string &str_vals, TMatrixFSym* mat, |
2247 | int Nrows, int Ncols) |
2248 | { |
2249 | |
2250 | |
2251 | |
2252 | |
2253 | mat->ResizeTo(Nrows, Ncols); |
2254 | stringstream ss(str_vals); |
2255 | for (int irow=0; irow<mat->GetNrows(); irow++) { |
2256 | for (int icol=irow; icol<mat->GetNcols(); icol++) { |
2257 | ss >> (*mat)[irow][icol]; |
2258 | (*mat)[icol][irow] = (*mat)[irow][icol]; |
2259 | } |
2260 | } |
2261 | |
2262 | return ss.str(); |
2263 | } |
2264 | |
2265 | |
2266 | |
2267 | |
2268 | jerror_t DEventSourceHDDM::Extract_DTAGMHit(hddm_s::HDDM *record, |
2269 | JFactory<DTAGMHit>* factory, |
2270 | string tag) |
2271 | { |
2272 | |
2273 | |
2274 | |
2275 | |
2276 | if (factory == NULL) |
2277 | return OBJECT_NOT_AVAILABLE; |
2278 | if (tag != "" && tag != "TRUTH") |
2279 | return OBJECT_NOT_AVAILABLE; |
2280 | |
2281 | vector<DTAGMHit*> data; |
2282 | |
2283 | |
2284 | const hddm_s::MicroChannelList &tags = record->getMicroChannels(); |
2285 | hddm_s::MicroChannelList::iterator iter; |
2286 | for (iter = tags.begin(); iter != tags.end(); ++iter) { |
2287 | if (tag == "") { |
2288 | const hddm_s::TaggerHitList &hits = iter->getTaggerHits(); |
2289 | hddm_s::TaggerHitList::iterator hiter; |
2290 | for (hiter = hits.begin(); hiter != hits.end(); ++hiter) { |
2291 | DTAGMHit *taghit = new DTAGMHit(); |
2292 | taghit->E = hiter->getE(); |
2293 | taghit->t = hiter->getT(); |
2294 | taghit->npix_fadc = hiter->getNpe(); |
2295 | taghit->time_fadc = hiter->getTADC(); |
2296 | taghit->column = hiter->getColumn(); |
2297 | taghit->row = hiter->getRow(); |
2298 | taghit->has_fADC = true; |
2299 | taghit->has_TDC = true; |
2300 | data.push_back(taghit); |
2301 | } |
2302 | } |
2303 | else if (tag == "TRUTH") { |
2304 | const hddm_s::TaggerTruthHitList &hits = iter->getTaggerTruthHits(); |
2305 | hddm_s::TaggerTruthHitList::iterator hiter; |
2306 | for (hiter = hits.begin(); hiter != hits.end(); ++hiter) { |
2307 | DTAGMHit *taghit = new DTAGMHit(); |
2308 | taghit->E = hiter->getE(); |
2309 | taghit->t = hiter->getT(); |
2310 | taghit->npix_fadc = hiter->getDE() * 1e5; |
2311 | taghit->time_fadc = hiter->getT(); |
2312 | taghit->column = hiter->getColumn(); |
2313 | taghit->row = hiter->getRow(); |
2314 | taghit->has_fADC = true; |
2315 | taghit->has_TDC = true; |
2316 | taghit->bg = hiter->getBg(); |
2317 | data.push_back(taghit); |
2318 | } |
2319 | } |
2320 | } |
2321 | |
2322 | |
2323 | factory->CopyTo(data); |
2324 | |
2325 | return NOERROR; |
2326 | } |
2327 | |
2328 | |
2329 | |
2330 | |
2331 | jerror_t DEventSourceHDDM::Extract_DTAGHHit( hddm_s::HDDM *record, |
2332 | JFactory<DTAGHHit>* factory, |
2333 | string tag) |
2334 | { |
2335 | |
2336 | |
2337 | |
2338 | |
2339 | if (factory == NULL) |
2340 | return OBJECT_NOT_AVAILABLE; |
2341 | if (tag != "" && tag != "TRUTH") |
2342 | return OBJECT_NOT_AVAILABLE; |
2343 | |
2344 | vector<DTAGHHit*> data; |
2345 | |
2346 | |
2347 | const hddm_s::HodoChannelList &tags = record->getHodoChannels(); |
2348 | hddm_s::HodoChannelList::iterator iter; |
2349 | for (iter = tags.begin(); iter != tags.end(); ++iter) { |
2350 | if (tag == "") { |
2351 | const hddm_s::TaggerHitList &hits = iter->getTaggerHits(); |
2352 | hddm_s::TaggerHitList::iterator hiter; |
2353 | for (hiter = hits.begin(); hiter != hits.end(); ++hiter) { |
2354 | DTAGHHit *taghit = new DTAGHHit(); |
2355 | taghit->E = hiter->getE(); |
2356 | taghit->t = hiter->getT(); |
2357 | taghit->npe_fadc = hiter->getNpe(); |
2358 | taghit->time_fadc = hiter->getTADC(); |
2359 | taghit->counter_id = hiter->getCounterId(); |
2360 | taghit->has_fADC = true; |
2361 | taghit->has_TDC = true; |
2362 | data.push_back(taghit); |
2363 | } |
2364 | } |
2365 | else if (tag == "TRUTH") { |
2366 | const hddm_s::TaggerTruthHitList &hits = iter->getTaggerTruthHits(); |
2367 | hddm_s::TaggerTruthHitList::iterator hiter; |
2368 | for (hiter = hits.begin(); hiter != hits.end(); ++hiter) { |
2369 | DTAGHHit *taghit = new DTAGHHit(); |
2370 | taghit->E = hiter->getE(); |
2371 | taghit->t = hiter->getT(); |
2372 | taghit->npe_fadc = hiter->getDE() * 5e5; |
2373 | taghit->time_fadc = hiter->getT(); |
2374 | taghit->counter_id = hiter->getCounterId(); |
2375 | taghit->has_fADC = true; |
2376 | taghit->has_TDC = true; |
2377 | taghit->bg = hiter->getBg(); |
2378 | |
2379 | data.push_back(taghit); |
2380 | } |
2381 | } |
2382 | } |
2383 | |
2384 | |
2385 | factory->CopyTo(data); |
2386 | |
2387 | return NOERROR; |
2388 | } |
2389 | |
2390 | |
2391 | |
2392 | |
2393 | jerror_t DEventSourceHDDM::Extract_DPSHit(hddm_s::HDDM *record, |
2394 | JFactory<DPSHit>* factory, string tag) |
2395 | { |
2396 | |
2397 | |
2398 | |
2399 | |
2400 | if (factory == NULL) |
2401 | return OBJECT_NOT_AVAILABLE; |
2402 | if (tag != "" && tag != "TRUTH") |
2403 | return OBJECT_NOT_AVAILABLE; |
2404 | |
2405 | vector<DPSHit*> data; |
2406 | |
2407 | if (tag == "") { |
2408 | const hddm_s::PsHitList &hits = record->getPsHits(); |
2409 | hddm_s::PsHitList::iterator iter; |
2410 | for (iter = hits.begin(); iter != hits.end(); ++iter) { |
2411 | DPSHit *hit = new DPSHit; |
2412 | if(iter->getArm() == 0) |
2413 | hit->arm = DPSGeometry::Arm::kNorth; |
2414 | else |
2415 | hit->arm = DPSGeometry::Arm::kSouth; |
2416 | hit->column = iter->getColumn(); |
2417 | double npix_fadc = iter->getDE()*0.5e5; |
2418 | hit->npix_fadc = npix_fadc; |
2419 | hit->t = iter->getT(); |
2420 | |
2421 | hit->E = 0.5*(psGeom->getElow(hit->arm,hit->column) + psGeom->getEhigh(hit->arm,hit->column)); |
2422 | hit->pulse_peak = npix_fadc*21; |
2423 | hit->integral = npix_fadc*21*5.1; |
2424 | data.push_back(hit); |
2425 | } |
2426 | } |
2427 | else if (tag == "TRUTH") { |
2428 | const hddm_s::PsTruthHitList &hits = record->getPsTruthHits(); |
2429 | hddm_s::PsTruthHitList::iterator iter; |
2430 | for (iter = hits.begin(); iter != hits.end(); ++iter) { |
2431 | DPSHit *hit = new DPSHit; |
2432 | if(iter->getArm() == 0) |
2433 | hit->arm = DPSGeometry::Arm::kNorth; |
2434 | else |
2435 | hit->arm = DPSGeometry::Arm::kSouth; |
2436 | hit->column = iter->getColumn(); |
2437 | hit->npix_fadc = iter->getDE() * 1e5; |
2438 | hit->t = iter->getT(); |
2439 | data.push_back(hit); |
2440 | } |
2441 | } |
2442 | |
2443 | |
2444 | factory->CopyTo(data); |
2445 | |
2446 | return NOERROR; |
2447 | } |
2448 | |
2449 | |
2450 | |
2451 | |
2452 | jerror_t DEventSourceHDDM::Extract_DPSTruthHit(hddm_s::HDDM *record, |
2453 | JFactory<DPSTruthHit>* factory, string tag) |
2454 | { |
2455 | |
2456 | |
2457 | |
2458 | |
2459 | if (factory == NULL) |
2460 | return OBJECT_NOT_AVAILABLE; |
2461 | if (tag != "") |
2462 | return OBJECT_NOT_AVAILABLE; |
2463 | |
2464 | vector<DPSTruthHit*> data; |
2465 | |
2466 | const hddm_s::PsTruthPointList &points = record->getPsTruthPoints(); |
2467 | hddm_s::PsTruthPointList::iterator iter; |
2468 | for (iter = points.begin(); iter != points.end(); ++iter) { |
2469 | DPSTruthHit *hit = new DPSTruthHit; |
2470 | hit->dEdx = iter->getDEdx(); |
2471 | hit->primary = iter->getPrimary(); |
2472 | hit->ptype = iter->getPtype(); |
2473 | hit->t = iter->getT(); |
2474 | hit->x = iter->getX(); |
2475 | hit->y = iter->getY(); |
2476 | hit->z = iter->getZ(); |
2477 | hit->track = iter->getTrack(); |
2478 | hit->column = iter->getColumn(); |
2479 | const hddm_s::TrackIDList &ids = iter->getTrackIDs(); |
2480 | hit->itrack = (ids.size())? ids.begin()->getItrack() : 0; |
2481 | data.push_back(hit); |
2482 | } |
2483 | |
2484 | |
2485 | factory->CopyTo(data); |
2486 | |
2487 | return NOERROR; |
2488 | } |
2489 | |
2490 | |
2491 | |
2492 | |
2493 | jerror_t DEventSourceHDDM::Extract_DPSCHit(hddm_s::HDDM *record, |
2494 | JFactory<DPSCHit>* factory, string tag) |
2495 | { |
2496 | |
2497 | |
2498 | |
2499 | |
2500 | if (factory == NULL) |
2501 | return OBJECT_NOT_AVAILABLE; |
2502 | if (tag != "" && tag != "TRUTH") |
2503 | return OBJECT_NOT_AVAILABLE; |
2504 | |
2505 | vector<DPSCHit*> data; |
2506 | |
2507 | if (tag == "") { |
2508 | const hddm_s::PscHitList &hits = record->getPscHits(); |
2509 | hddm_s::PscHitList::iterator iter; |
2510 | for (iter = hits.begin(); iter != hits.end(); ++iter) { |
2511 | DPSCHit *hit = new DPSCHit; |
2512 | if(iter->getArm() == 0) |
2513 | hit->arm = DPSGeometry::Arm::kNorth; |
2514 | else |
2515 | hit->arm = DPSGeometry::Arm::kSouth; |
2516 | hit->module = iter->getModule(); |
2517 | |
2518 | double npe_fadc = iter->getDE()*2.5e5; |
2519 | hit->npe_fadc = npe_fadc; |
2520 | hit->pulse_peak = npe_fadc*0.4; |
2521 | hit->integral = npe_fadc*0.4*3; |
2522 | |
2523 | hit->t = iter->getT(); |
2524 | hit->time_tdc = iter->getT(); |
2525 | hit->time_fadc = iter->getT(); |
2526 | |
2527 | hit->has_fADC = true; |
2528 | hit->has_TDC = true; |
2529 | |
2530 | data.push_back(hit); |
2531 | } |
2532 | } |
2533 | else if (tag == "TRUTH") { |
2534 | const hddm_s::PscTruthHitList &hits = record->getPscTruthHits(); |
2535 | hddm_s::PscTruthHitList::iterator iter; |
2536 | for (iter = hits.begin(); iter != hits.end(); ++iter) { |
2537 | DPSCHit *hit = new DPSCHit; |
2538 | if(iter->getArm() == 0) |
2539 | hit->arm = DPSGeometry::Arm::kNorth; |
2540 | else |
2541 | hit->arm = DPSGeometry::Arm::kSouth; |
2542 | hit->module = iter->getModule(); |
2543 | hit->npe_fadc = iter->getDE() * 5e5; |
2544 | hit->t = iter->getT(); |
2545 | data.push_back(hit); |
2546 | } |
2547 | } |
2548 | |
2549 | |
2550 | factory->CopyTo(data); |
2551 | |
2552 | return NOERROR; |
2553 | } |
2554 | |
2555 | |
2556 | |
2557 | |
2558 | jerror_t DEventSourceHDDM::Extract_DPSCTruthHit(hddm_s::HDDM *record, |
2559 | JFactory<DPSCTruthHit>* factory, string tag) |
2560 | { |
2561 | |
2562 | |
2563 | |
2564 | |
2565 | if (factory == NULL) |
2566 | return OBJECT_NOT_AVAILABLE; |
2567 | if (tag != "") |
2568 | return OBJECT_NOT_AVAILABLE; |
2569 | |
2570 | vector<DPSCTruthHit*> data; |
2571 | |
2572 | const hddm_s::PscTruthPointList &points = record->getPscTruthPoints(); |
2573 | hddm_s::PscTruthPointList::iterator iter; |
2574 | for (iter = points.begin(); iter != points.end(); ++iter) { |
2575 | DPSCTruthHit *hit = new DPSCTruthHit; |
2576 | hit->dEdx = iter->getDEdx(); |
2577 | hit->primary = iter->getPrimary(); |
2578 | hit->ptype = iter->getPtype(); |
2579 | hit->t = iter->getT(); |
2580 | hit->x = iter->getX(); |
2581 | hit->y = iter->getY(); |
2582 | hit->z = iter->getZ(); |
2583 | hit->track = iter->getTrack(); |
2584 | hit->column = iter->getModule(); |
2585 | const hddm_s::TrackIDList &ids = iter->getTrackIDs(); |
2586 | hit->itrack = (ids.size())? ids.begin()->getItrack() : 0; |
2587 | data.push_back(hit); |
2588 | } |
2589 | |
2590 | |
2591 | factory->CopyTo(data); |
2592 | |
2593 | return NOERROR; |
2594 | } |
2595 | |
2596 | |
2597 | |
2598 | |
2599 | jerror_t DEventSourceHDDM::Extract_DTPOLHit(hddm_s::HDDM *record, |
2600 | JFactory<DTPOLHit>* factory, string tag) |
2601 | { |
2602 | if (factory == NULL) |
2603 | return OBJECT_NOT_AVAILABLE; |
2604 | if (tag != "") |
2605 | return OBJECT_NOT_AVAILABLE; |
2606 | |
2607 | vector<DTPOLHit*> data; |
2608 | |
2609 | if (tag == "") |
2610 | { |
2611 | const hddm_s::TpolHitList &hits = record->getTpolHits(); |
2612 | hddm_s::TpolHitList::iterator iter; |
2613 | for (iter = hits.begin(); iter != hits.end(); ++iter) |
2614 | { |
2615 | DTPOLHit *hit = new DTPOLHit; |
2616 | hit->sector = iter->getSector(); |
2617 | hit->ring = iter->getRing(); |
2618 | hit->dE = iter->getDE(); |
2619 | hit->t = iter->getT(); |
2620 | |
2621 | data.push_back(hit); |
2622 | } |
2623 | } |
2624 | else if (tag == "Truth") |
2625 | { |
2626 | const hddm_s::TpolTruthHitList &truthHits = record->getTpolTruthHits(); |
2627 | hddm_s::TpolTruthHitList::iterator iter; |
2628 | for (iter = truthHits.begin(); iter != truthHits.end(); ++iter) |
2629 | { |
2630 | DTPOLHit *hit = new DTPOLHit; |
2631 | hit->sector = iter->getSector(); |
2632 | hit->t = iter->getT(); |
2633 | |
2634 | data.push_back(hit); |
2635 | } |
2636 | } |
2637 | |
2638 | factory->CopyTo(data); |
2639 | |
2640 | return NOERROR; |
2641 | } |
2642 | |
2643 | |
2644 | |
2645 | |
2646 | jerror_t DEventSourceHDDM::Extract_DTPOLTruthHit(hddm_s::HDDM *record, JFactory<DTPOLTruthHit>* factory, string tag) |
2647 | { |
2648 | if (factory == NULL) |
2649 | return OBJECT_NOT_AVAILABLE; |
2650 | if (tag != "") |
2651 | return OBJECT_NOT_AVAILABLE; |
2652 | |
2653 | vector<DTPOLTruthHit*> data; |
2654 | |
2655 | const hddm_s::TpolTruthPointList &points = record->getTpolTruthPoints(); |
2656 | hddm_s::TpolTruthPointList::iterator iter; |
2657 | for (iter = points.begin(); iter != points.end(); ++iter) |
2658 | { |
2659 | DTPOLTruthHit *hit = new DTPOLTruthHit; |
2660 | hit->dEdx = iter->getDEdx(); |
2661 | hit->primary = iter->getPrimary(); |
2662 | hit->track = iter->getTrack(); |
2663 | hit->ptype = iter->getPtype(); |
2664 | hit->r = iter->getR(); |
2665 | hit->phi = iter->getPhi(); |
2666 | hit->t = iter->getT(); |
2667 | const hddm_s::TrackIDList &ids = iter->getTrackIDs(); |
2668 | hit->itrack = (ids.size())? ids.begin()->getItrack() : 0; |
2669 | |
2670 | data.push_back(hit); |
2671 | } |
2672 | |
2673 | factory->CopyTo(data); |
2674 | |
2675 | return NOERROR; |
2676 | } |
2677 | |
2678 | Particle_t DEventSourceHDDM::IDTrack(float locCharge, float locMass) const |
2679 | { |
2680 | float locMassTolerance = 0.010; |
2681 | if (locCharge > 0.1) |
2682 | { |
2683 | if (fabs(locMass - ParticleMass(Proton)) < locMassTolerance) return Proton; |
2684 | if (fabs(locMass - ParticleMass(PiPlus)) < locMassTolerance) return PiPlus; |
2685 | if (fabs(locMass - ParticleMass(KPlus)) < locMassTolerance) return KPlus; |
2686 | if (fabs(locMass - ParticleMass(Positron)) < locMassTolerance) return Positron; |
2687 | if (fabs(locMass - ParticleMass(MuonPlus)) < locMassTolerance) return MuonPlus; |
2688 | } |
2689 | else if(locCharge < -0.1) |
2690 | { |
2691 | if (fabs(locMass - ParticleMass(PiMinus)) < locMassTolerance) return PiMinus; |
2692 | if (fabs(locMass - ParticleMass(KMinus)) < locMassTolerance) return KMinus; |
2693 | if (fabs(locMass - ParticleMass(MuonMinus)) < locMassTolerance) return MuonMinus; |
2694 | if (fabs(locMass - ParticleMass(Electron)) < locMassTolerance) return Electron; |
2695 | if (fabs(locMass - ParticleMass(AntiProton)) < locMassTolerance) return AntiProton; |
2696 | } |
2697 | else |
2698 | { |
2699 | if (fabs(locMass - ParticleMass(Gamma)) < locMassTolerance) return Gamma; |
2700 | if (fabs(locMass - ParticleMass(Neutron)) < locMassTolerance) return Neutron; |
2701 | } |
2702 | return Unknown; |
2703 | } |
2704 | |
2705 | |
2706 | |
2707 | |
2708 | jerror_t DEventSourceHDDM::Extract_DFMWPCTruthHit(hddm_s::HDDM *record, JFactory<DFMWPCTruthHit> *factory, string tag) |
2709 | { |
2710 | |
2711 | |
2712 | |
2713 | |
2714 | if (factory == NULL) return OBJECT_NOT_AVAILABLE; |
2715 | if (tag != "") return OBJECT_NOT_AVAILABLE; |
2716 | |
2717 | vector<DFMWPCTruthHit*> data; |
2718 | |
2719 | const hddm_s::FmwpcTruthHitList &points = record->getFmwpcTruthHits(); |
2720 | hddm_s::FmwpcTruthHitList::iterator iter; |
2721 | for (iter = points.begin(); iter != points.end(); ++iter) { |
2722 | DFMWPCTruthHit *hit = new DFMWPCTruthHit; |
2723 | hit->layer = iter->getLayer(); |
2724 | hit->wire = iter->getWire(); |
2725 | hit->dE = iter->getDE(); |
2726 | hit->dx = iter->getDx(); |
2727 | hit->t = iter->getT(); |
2728 | data.push_back(hit); |
2729 | } |
2730 | |
2731 | |
2732 | factory->CopyTo(data); |
2733 | |
2734 | return NOERROR; |
2735 | } |
2736 | |
2737 | |
2738 | |
2739 | |
2740 | jerror_t DEventSourceHDDM::Extract_DFMWPCHit(hddm_s::HDDM *record, JFactory<DFMWPCHit> *factory, string tag) |
2741 | { |
2742 | |
2743 | |
2744 | |
2745 | |
2746 | if (factory == NULL) return OBJECT_NOT_AVAILABLE; |
2747 | if (tag != "") return OBJECT_NOT_AVAILABLE; |
2748 | |
2749 | vector<DFMWPCHit*> data; |
2750 | |
2751 | const hddm_s::FmwpcHitList &points = record->getFmwpcHits(); |
2752 | hddm_s::FmwpcHitList::iterator iter; |
2753 | for (iter = points.begin(); iter != points.end(); ++iter) { |
2754 | DFMWPCHit *hit = new DFMWPCHit; |
2755 | hit->layer = iter->getLayer(); |
2756 | hit->wire = iter->getWire(); |
2757 | hit->dE = iter->getDE(); |
2758 | hit->t = iter->getT(); |
2759 | data.push_back(hit); |
2760 | } |
2761 | |
2762 | |
2763 | factory->CopyTo(data); |
2764 | |
2765 | return NOERROR; |
2766 | } |
2767 | |
2768 | |
2769 | |
2770 | |
2771 | jerror_t DEventSourceHDDM::Extract_DDIRCPmtHit(hddm_s::HDDM *record, |
2772 | JFactory<DDIRCPmtHit> *factory, string tag, |
2773 | JEventLoop* eventLoop) |
2774 | { |
2775 | |
2776 | |
2777 | |
2778 | |
2779 | if (factory == NULL) |
2780 | return OBJECT_NOT_AVAILABLE; |
2781 | if (tag != "") |
2782 | return OBJECT_NOT_AVAILABLE; |
2783 | |
2784 | vector<DDIRCPmtHit*> data; |
2785 | |
2786 | if (tag == "") { |
2787 | vector<const DDIRCTruthPmtHit*> locDIRCTruthPmtHit; |
2788 | eventLoop->Get(locDIRCTruthPmtHit); |
2789 | |
2790 | const hddm_s::DircPmtHitList &hits = record->getDircPmtHits(); |
2791 | hddm_s::DircPmtHitList::iterator iter; |
2792 | for (iter = hits.begin(); iter != hits.end(); ++iter) { |
2793 | double time = iter->getT(); |
2794 | int channel = iter->getCh(); |
2795 | |
2796 | DDIRCPmtHit *hit = new DDIRCPmtHit(); |
2797 | hit->t = time; |
2798 | hit->ch = channel; |
2799 | |
2800 | for (auto& iterTruth : locDIRCTruthPmtHit) { |
2801 | |
2802 | |
2803 | if(channel == iterTruth->ch && fabs(time-iterTruth->t) < 5.0) { |
2804 | |
2805 | hit->AddAssociatedObject(iterTruth); |
2806 | |
2807 | break; |
2808 | } |
2809 | } |
2810 | |
2811 | data.push_back(hit); |
2812 | } |
2813 | } |
2814 | |
2815 | |
2816 | factory->CopyTo(data); |
2817 | |
2818 | return NOERROR; |
2819 | } |
2820 | |
2821 | |
2822 | |
2823 | |
2824 | |
2825 | jerror_t DEventSourceHDDM::Extract_DCereHit(hddm_s::HDDM *record, |
2826 | JFactory<DCereHit>* factory, string tag) |
2827 | { |
2828 | if (factory == NULL) |
2829 | return OBJECT_NOT_AVAILABLE; |
2830 | if (tag != "" && tag != "TRUTH") |
2831 | return OBJECT_NOT_AVAILABLE; |
2832 | |
2833 | vector<DCereHit*> data; |
2834 | |
2835 | if (tag == "") { |
2836 | const hddm_s::CereHitList &hits = record->getCereHits(); |
2837 | hddm_s::CereHitList::iterator iter; |
2838 | for (iter = hits.begin(); iter != hits.end(); ++iter) { |
2839 | DCereHit *hit = new DCereHit; |
2840 | hit->sector = iter->getSector(); |
2841 | hit->pe = iter->getPe(); |
2842 | hit->t = iter->getT(); |
2843 | data.push_back(hit); |
2844 | } |
2845 | } |
2846 | else if (tag == "TRUTH") { |
2847 | const hddm_s::CereTruthHitList &hits = record->getCereTruthHits(); |
2848 | hddm_s::CereTruthHitList::iterator iter; |
2849 | for (iter = hits.begin(); iter != hits.end(); ++iter) { |
2850 | DCereHit *hit = new DCereHit; |
2851 | hit->sector = iter->getSector(); |
2852 | hit->pe = iter->getPe(); |
2853 | hit->t = iter->getT(); |
2854 | data.push_back(hit); |
2855 | } |
2856 | } |
2857 | |
2858 | |
2859 | factory->CopyTo(data); |
2860 | |
2861 | return NOERROR; |
2862 | } |
2863 | |
2864 | |
2865 | |
2866 | |
2867 | jerror_t DEventSourceHDDM::Extract_DDIRCTruthBarHit(hddm_s::HDDM *record, |
2868 | JFactory<DDIRCTruthBarHit>* factory, string tag) |
2869 | { |
2870 | |
2871 | |
2872 | |
2873 | |
2874 | if (factory == NULL) |
2875 | return OBJECT_NOT_AVAILABLE; |
2876 | if (tag != "") |
2877 | return OBJECT_NOT_AVAILABLE; |
2878 | |
2879 | vector<DDIRCTruthBarHit*> data; |
2880 | |
2881 | const hddm_s::DircTruthBarHitList &hits = record->getDircTruthBarHits(); |
2882 | hddm_s::DircTruthBarHitList::iterator iter; |
2883 | for (iter = hits.begin(); iter != hits.end(); ++iter) { |
2884 | DDIRCTruthBarHit *hit = new DDIRCTruthBarHit; |
2885 | hit->x = iter->getX(); |
2886 | hit->y = iter->getY(); |
2887 | hit->z = iter->getZ(); |
2888 | hit->px = iter->getPx(); |
2889 | hit->py = iter->getPy(); |
2890 | hit->pz = iter->getPz(); |
2891 | hit->t = iter->getT(); |
2892 | hit->E = iter->getE(); |
2893 | hit->pdg = iter->getPdg(); |
2894 | hit->bar = iter->getBar(); |
2895 | hit->track = iter->getTrack(); |
2896 | data.push_back(hit); |
2897 | } |
2898 | |
2899 | |
2900 | factory->CopyTo(data); |
2901 | |
2902 | return NOERROR; |
2903 | } |
2904 | |
2905 | |
2906 | |
2907 | |
2908 | jerror_t DEventSourceHDDM::Extract_DDIRCTruthPmtHit(hddm_s::HDDM *record, |
2909 | JFactory<DDIRCTruthPmtHit>* factory, string tag) |
2910 | { |
2911 | |
2912 | |
2913 | |
2914 | |
2915 | if (factory == NULL) |
2916 | return OBJECT_NOT_AVAILABLE; |
2917 | if (tag != "") |
2918 | return OBJECT_NOT_AVAILABLE; |
2919 | |
2920 | vector<DDIRCTruthPmtHit*> data; |
2921 | |
2922 | |
2923 | const hddm_s::DircTruthPmtHitList &hits = record->getDircTruthPmtHits(); |
2924 | hddm_s::DircTruthPmtHitList::iterator iter; |
2925 | for (iter = hits.begin(); iter != hits.end(); ++iter) { |
2926 | DDIRCTruthPmtHit *hit = new DDIRCTruthPmtHit; |
2927 | hit->x = iter->getX(); |
2928 | hit->y = iter->getY(); |
2929 | hit->z = iter->getZ(); |
2930 | hit->t = iter->getT(); |
2931 | hit->E = iter->getE(); |
2932 | hit->ch = iter->getCh(); |
2933 | hit->key_bar = iter->getKey_bar(); |
2934 | hddm_s::DircTruthPmtHitExtraList &hitextras = iter->getDircTruthPmtHitExtras(); |
2935 | if(hitextras.size() > 0) { |
2936 | hit->t_fixed = hitextras(0).getT_fixed(); |
2937 | hit->path = hitextras(0).getPath(); |
2938 | hit->refl = hitextras(0).getRefl(); |
2939 | hit->bbrefl = hitextras(0).getBbrefl(); |
2940 | } |
2941 | data.push_back(hit); |
2942 | } |
2943 | |
2944 | |
2945 | factory->CopyTo(data); |
2946 | |
2947 | return NOERROR; |
2948 | } |
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 | #ifndef _BASIC_STRING_H |
35 | #define _BASIC_STRING_H 1 |
36 | |
37 | #pragma GCC system_header |
38 | |
39 | #include <ext/atomicity.h> |
40 | #include <debug/debug.h> |
41 | #if __cplusplus >= 201103L |
42 | #include <initializer_list> |
43 | #endif |
44 | |
45 | namespace std _GLIBCXX_VISIBILITY(default) |
46 | { |
47 | _GLIBCXX_BEGIN_NAMESPACE_VERSION |
48 | |
49 | |
50 | |
51 | |
52 | |
53 | |
54 | |
55 | |
56 | |
57 | |
58 | |
59 | |
60 | |
61 | |
62 | |
63 | |
64 | |
65 | |
66 | |
67 | |
68 | |
69 | |
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 | |
96 | |
97 | |
98 | |
99 | |
100 | |
101 | |
102 | |
103 | |
104 | |
105 | |
106 | |
107 | |
108 | |
109 | |
110 | |
111 | template<typename _CharT, typename _Traits, typename _Alloc> |
112 | class basic_string |
113 | { |
114 | typedef typename _Alloc::template rebind<_CharT>::other _CharT_alloc_type; |
115 | |
116 | |
117 | public: |
118 | typedef _Traits traits_type; |
119 | typedef typename _Traits::char_type value_type; |
120 | typedef _Alloc allocator_type; |
121 | typedef typename _CharT_alloc_type::size_type size_type; |
122 | typedef typename _CharT_alloc_type::difference_type difference_type; |
123 | typedef typename _CharT_alloc_type::reference reference; |
124 | typedef typename _CharT_alloc_type::const_reference const_reference; |
125 | typedef typename _CharT_alloc_type::pointer pointer; |
126 | typedef typename _CharT_alloc_type::const_pointer const_pointer; |
127 | typedef __gnu_cxx::__normal_iterator<pointer, basic_string> iterator; |
128 | typedef __gnu_cxx::__normal_iterator<const_pointer, basic_string> |
129 | const_iterator; |
130 | typedef std::reverse_iterator<const_iterator> const_reverse_iterator; |
131 | typedef std::reverse_iterator<iterator> reverse_iterator; |
132 | |
133 | private: |
134 | |
135 | |
136 | |
137 | |
138 | |
139 | |
140 | |
141 | |
142 | |
143 | |
144 | |
145 | |
146 | |
147 | |
148 | struct _Rep_base |
149 | { |
150 | size_type _M_length; |
151 | size_type _M_capacity; |
152 | _Atomic_word _M_refcount; |
153 | }; |
154 | |
155 | struct _Rep : _Rep_base |
156 | { |
157 | |
158 | typedef typename _Alloc::template rebind<char>::other _Raw_bytes_alloc; |
159 | |
160 | |
161 | |
162 | |
163 | |
164 | |
165 | |
166 | |
167 | |
168 | |
169 | |
170 | |
171 | |
172 | |
173 | static const size_type _S_max_size; |
174 | static const _CharT _S_terminal; |
175 | |
176 | |
177 | |
178 | static size_type _S_empty_rep_storage[]; |
179 | |
180 | static _Rep& |
181 | _S_empty_rep() |
182 | { |
183 | |
184 | |
185 | |
186 | void* __p = reinterpret_cast<void*>(&_S_empty_rep_storage); |
187 | return *reinterpret_cast<_Rep*>(__p); |
188 | } |
189 | |
190 | bool |
191 | _M_is_leaked() const |
192 | { return this->_M_refcount < 0; } |
193 | |
194 | bool |
195 | _M_is_shared() const |
196 | { return this->_M_refcount > 0; } |
197 | |
198 | void |
199 | _M_set_leaked() |
200 | { this->_M_refcount = -1; } |
201 | |
202 | void |
203 | _M_set_sharable() |
204 | { this->_M_refcount = 0; } |
205 | |
206 | void |
207 | _M_set_length_and_sharable(size_type __n) |
208 | { |
209 | #if _GLIBCXX_FULLY_DYNAMIC_STRING == 0 |
210 | if (__builtin_expect(this != &_S_empty_rep(), false)) |
211 | #endif |
212 | { |
213 | this->_M_set_sharable(); |
214 | this->_M_length = __n; |
215 | traits_type::assign(this->_M_refdata()[__n], _S_terminal); |
216 | |
217 | |
218 | } |
219 | } |
220 | |
221 | _CharT* |
222 | _M_refdata() throw() |
223 | { return reinterpret_cast<_CharT*>(this + 1); } |
224 | |
225 | _CharT* |
226 | _M_grab(const _Alloc& __alloc1, const _Alloc& __alloc2) |
227 | { |
228 | return (!_M_is_leaked() && __alloc1 == __alloc2) |
229 | ? _M_refcopy() : _M_clone(__alloc1); |
230 | } |
231 | |
232 | |
233 | static _Rep* |
234 | _S_create(size_type, size_type, const _Alloc&); |
235 | |
236 | void |
237 | _M_dispose(const _Alloc& __a) |
238 | { |
239 | #if _GLIBCXX_FULLY_DYNAMIC_STRING == 0 |
240 | if (__builtin_expect(this != &_S_empty_rep(), false)) |
241 | #endif |
242 | { |
243 | |
244 | _GLIBCXX_SYNCHRONIZATION_HAPPENS_BEFORE(&this->_M_refcount); |
245 | if (__gnu_cxx::__exchange_and_add_dispatch(&this->_M_refcount, |
246 | -1) <= 0) |
247 | { |
248 | _GLIBCXX_SYNCHRONIZATION_HAPPENS_AFTER(&this->_M_refcount); |
249 | _M_destroy(__a); |
250 | } |
251 | } |
252 | } |
253 | |
254 | void |
255 | _M_destroy(const _Alloc&) throw(); |
256 | |
257 | _CharT* |
258 | _M_refcopy() throw() |
259 | { |
260 | #if _GLIBCXX_FULLY_DYNAMIC_STRING == 0 |
261 | if (__builtin_expect(this != &_S_empty_rep(), false)) |
262 | #endif |
263 | __gnu_cxx::__atomic_add_dispatch(&this->_M_refcount, 1); |
264 | return _M_refdata(); |
265 | } |
266 | |
267 | _CharT* |
268 | _M_clone(const _Alloc&, size_type __res = 0); |
269 | }; |
270 | |
271 | |
272 | struct _Alloc_hider : _Alloc |
273 | { |
274 | _Alloc_hider(_CharT* __dat, const _Alloc& __a) |
275 | : _Alloc(__a), _M_p(__dat) { } |
276 | |
277 | _CharT* _M_p; |
278 | }; |
279 | |
280 | public: |
281 | |
282 | |
283 | |
284 | |
285 | static const size_type npos = static_cast<size_type>(-1); |
286 | |
287 | private: |
288 | |
289 | mutable _Alloc_hider _M_dataplus; |
290 | |
291 | _CharT* |
292 | _M_data() const |
293 | { return _M_dataplus._M_p; } |
294 | |
295 | _CharT* |
296 | _M_data(_CharT* __p) |
297 | { return (_M_dataplus._M_p = __p); } |
298 | |
299 | _Rep* |
300 | _M_rep() const |
301 | { return &((reinterpret_cast<_Rep*> (_M_data()))[-1]); } |
302 | |
303 | |
304 | |
305 | iterator |
306 | _M_ibegin() const |
307 | { return iterator(_M_data()); } |
308 | |
309 | iterator |
310 | _M_iend() const |
311 | { return iterator(_M_data() + this->size()); } |
312 | |
313 | void |
314 | _M_leak() |
315 | { |
316 | if (!_M_rep()->_M_is_leaked()) |
317 | _M_leak_hard(); |
318 | } |
319 | |
320 | size_type |
321 | _M_check(size_type __pos, const char* __s) const |
322 | { |
323 | if (__pos > this->size()) |
324 | __throw_out_of_range(__N(__s)); |
325 | return __pos; |
326 | } |
327 | |
328 | void |
329 | _M_check_length(size_type __n1, size_type __n2, const char* __s) const |
330 | { |
331 | if (this->max_size() - (this->size() - __n1) < __n2) |
332 | __throw_length_error(__N(__s)); |
333 | } |
334 | |
335 | |
336 | size_type |
337 | _M_limit(size_type __pos, size_type __off) const |
338 | { |
339 | const bool __testoff = __off < this->size() - __pos; |
340 | return __testoff ? __off : this->size() - __pos; |
341 | } |
342 | |
343 | |
344 | bool |
345 | _M_disjunct(const _CharT* __s) const |
346 | { |
347 | return (less<const _CharT*>()(__s, _M_data()) |
348 | || less<const _CharT*>()(_M_data() + this->size(), __s)); |
349 | } |
350 | |
351 | |
352 | |
353 | static void |
354 | _M_copy(_CharT* __d, const _CharT* __s, size_type __n) |
355 | { |
356 | if (__n == 1) |
357 | traits_type::assign(*__d, *__s); |
358 | else |
359 | traits_type::copy(__d, __s, __n); |
360 | } |
361 | |
362 | static void |
363 | _M_move(_CharT* __d, const _CharT* __s, size_type __n) |
364 | { |
365 | if (__n == 1) |
366 | traits_type::assign(*__d, *__s); |
367 | else |
368 | traits_type::move(__d, __s, __n); |
369 | } |
370 | |
371 | static void |
372 | _M_assign(_CharT* __d, size_type __n, _CharT __c) |
373 | { |
374 | if (__n == 1) |
375 | traits_type::assign(*__d, __c); |
376 | else |
377 | traits_type::assign(__d, __n, __c); |
378 | } |
379 | |
380 | |
381 | |
382 | template<class _Iterator> |
383 | static void |
384 | _S_copy_chars(_CharT* __p, _Iterator __k1, _Iterator __k2) |
385 | { |
386 | for (; __k1 != __k2; ++__k1, ++__p) |
387 | traits_type::assign(*__p, *__k1); |
388 | } |
389 | |
390 | static void |
391 | _S_copy_chars(_CharT* __p, iterator __k1, iterator __k2) |
392 | { _S_copy_chars(__p, __k1.base(), __k2.base()); } |
393 | |
394 | static void |
395 | _S_copy_chars(_CharT* __p, const_iterator __k1, const_iterator __k2) |
396 | { _S_copy_chars(__p, __k1.base(), __k2.base()); } |
397 | |
398 | static void |
399 | _S_copy_chars(_CharT* __p, _CharT* __k1, _CharT* __k2) |
400 | { _M_copy(__p, __k1, __k2 - __k1); } |
401 | |
402 | static void |
403 | _S_copy_chars(_CharT* __p, const _CharT* __k1, const _CharT* __k2) |
404 | { _M_copy(__p, __k1, __k2 - __k1); } |
405 | |
406 | static int |
407 | _S_compare(size_type __n1, size_type __n2) |
408 | { |
409 | const difference_type __d = difference_type(__n1 - __n2); |
410 | |
411 | if (__d > __gnu_cxx::__numeric_traits<int>::__max) |
412 | return __gnu_cxx::__numeric_traits<int>::__max; |
413 | else if (__d < __gnu_cxx::__numeric_traits<int>::__min) |
414 | return __gnu_cxx::__numeric_traits<int>::__min; |
415 | else |
416 | return int(__d); |
417 | } |
418 | |
419 | void |
420 | _M_mutate(size_type __pos, size_type __len1, size_type __len2); |
421 | |
422 | void |
423 | _M_leak_hard(); |
424 | |
425 | static _Rep& |
426 | _S_empty_rep() |
427 | { return _Rep::_S_empty_rep(); } |
428 | |
429 | public: |
430 | |
431 | |
432 | |
433 | |
434 | |
435 | |
436 | |
437 | basic_string() |
438 | #if _GLIBCXX_FULLY_DYNAMIC_STRING == 0 |
439 | : _M_dataplus(_S_empty_rep()._M_refdata(), _Alloc()) { } |
440 | #else |
441 | : _M_dataplus(_S_construct(size_type(), _CharT(), _Alloc()), _Alloc()){ } |
442 | #endif |
443 | |
444 | |
445 | |
446 | |
447 | explicit |
448 | basic_string(const _Alloc& __a); |
449 | |
450 | |
451 | |
452 | |
453 | |
454 | |
455 | basic_string(const basic_string& __str); |
456 | |
457 | |
458 | |
459 | |
460 | |
461 | |
462 | basic_string(const basic_string& __str, size_type __pos, |
463 | size_type __n = npos); |
464 | |
465 | |
466 | |
467 | |
468 | |
469 | |
470 | |
471 | basic_string(const basic_string& __str, size_type __pos, |
472 | size_type __n, const _Alloc& __a); |
473 | |
474 | |
475 | |
476 | |
477 | |
478 | |
479 | |
480 | |
481 | |
482 | |
483 | basic_string(const _CharT* __s, size_type __n, |
484 | const _Alloc& __a = _Alloc()); |
485 | |
486 | |
487 | |
488 | |
489 | |
490 | basic_string(const _CharT* __s, const _Alloc& __a = _Alloc()); |
491 | |
492 | |
493 | |
494 | |
495 | |
496 | |
497 | basic_string(size_type __n, _CharT __c, const _Alloc& __a = _Alloc()); |
498 | |
499 | #if __cplusplus >= 201103L |
500 | |
501 | |
502 | |
503 | |
504 | |
505 | |
506 | |
507 | basic_string(basic_string&& __str) noexcept |
508 | : _M_dataplus(__str._M_dataplus) |
509 | { |
510 | #if _GLIBCXX_FULLY_DYNAMIC_STRING == 0 |
511 | __str._M_data(_S_empty_rep()._M_refdata()); |
512 | #else |
513 | __str._M_data(_S_construct(size_type(), _CharT(), get_allocator())); |
514 | #endif |
515 | } |
516 | |
517 | |
518 | |
519 | |
520 | |
521 | |
522 | basic_string(initializer_list<_CharT> __l, const _Alloc& __a = _Alloc()); |
523 | #endif // C++11 |
524 | |
525 | |
526 | |
527 | |
528 | |
529 | |
530 | |
531 | template<class _InputIterator> |
532 | basic_string(_InputIterator __beg, _InputIterator __end, |
533 | const _Alloc& __a = _Alloc()); |
534 | |
535 | |
536 | |
537 | |
538 | ~basic_string() _GLIBCXX_NOEXCEPT |
539 | { _M_rep()->_M_dispose(this->get_allocator()); } |
540 | |
541 | |
542 | |
543 | |
544 | |
545 | basic_string& |
546 | operator=(const basic_string& __str) |
547 | { return this->assign(__str); } |
548 | |
549 | |
550 | |
551 | |
552 | |
553 | basic_string& |
554 | operator=(const _CharT* __s) |
555 | { return this->assign(__s); } |
556 | |
557 | |
558 | |
559 | |
560 | |
561 | |
562 | |
563 | |
564 | basic_string& |
565 | operator=(_CharT __c) |
566 | { |
567 | this->assign(1, __c); |
568 | return *this; |
569 | } |
570 | |
571 | #if __cplusplus >= 201103L |
572 | |
573 | |
574 | |
575 | |
576 | |
577 | |
578 | |
579 | basic_string& |
580 | operator=(basic_string&& __str) |
581 | { |
582 | |
583 | this->swap(__str); |
584 | return *this; |
585 | } |
586 | |
587 | |
588 | |
589 | |
590 | |
591 | basic_string& |
592 | operator=(initializer_list<_CharT> __l) |
593 | { |
594 | this->assign(__l.begin(), __l.size()); |
595 | return *this; |
596 | } |
597 | #endif // C++11 |
598 | |
599 | |
600 | |
601 | |
602 | |
603 | |
604 | iterator |
605 | begin() _GLIBCXX_NOEXCEPT |
606 | { |
607 | _M_leak(); |
608 | return iterator(_M_data()); |
609 | } |
610 | |
611 | |
612 | |
613 | |
614 | |
615 | const_iterator |
616 | begin() const _GLIBCXX_NOEXCEPT |
617 | { return const_iterator(_M_data()); } |
618 | |
619 | |
620 | |
621 | |
622 | |
623 | iterator |
624 | end() _GLIBCXX_NOEXCEPT |
625 | { |
626 | _M_leak(); |
627 | return iterator(_M_data() + this->size()); |
628 | } |
629 | |
630 | |
631 | |
632 | |
633 | |
634 | const_iterator |
635 | end() const _GLIBCXX_NOEXCEPT |
636 | { return const_iterator(_M_data() + this->size()); } |
637 | |
638 | |
639 | |
640 | |
641 | |
642 | |
643 | reverse_iterator |
644 | rbegin() _GLIBCXX_NOEXCEPT |
645 | { return reverse_iterator(this->end()); } |
646 | |
647 | |
648 | |
649 | |
650 | |
651 | |
652 | const_reverse_iterator |
653 | rbegin() const _GLIBCXX_NOEXCEPT |
654 | { return const_reverse_iterator(this->end()); } |
655 | |
656 | |
657 | |
658 | |
659 | |
660 | |
661 | reverse_iterator |
662 | rend() _GLIBCXX_NOEXCEPT |
663 | { return reverse_iterator(this->begin()); } |
664 | |
665 | |
666 | |
667 | |
668 | |
669 | |
670 | const_reverse_iterator |
671 | rend() const _GLIBCXX_NOEXCEPT |
672 | { return const_reverse_iterator(this->begin()); } |
673 | |
674 | #if __cplusplus >= 201103L |
675 | |
676 | |
677 | |
678 | |
679 | const_iterator |
680 | cbegin() const noexcept |
681 | { return const_iterator(this->_M_data()); } |
682 | |
683 | |
684 | |
685 | |
686 | |
687 | const_iterator |
688 | cend() const noexcept |
689 | { return const_iterator(this->_M_data() + this->size()); } |
690 | |
691 | |
692 | |
693 | |
694 | |
695 | |
696 | const_reverse_iterator |
697 | crbegin() const noexcept |
698 | { return const_reverse_iterator(this->end()); } |
699 | |
700 | |
701 | |
702 | |
703 | |
704 | |
705 | const_reverse_iterator |
706 | crend() const noexcept |
707 | { return const_reverse_iterator(this->begin()); } |
708 | #endif |
709 | |
710 | public: |
711 | |
712 | |
713 | |
714 | size_type |
715 | size() const _GLIBCXX_NOEXCEPT |
716 | { return _M_rep()->_M_length; } |
717 | |
718 | |
719 | |
720 | size_type |
721 | length() const _GLIBCXX_NOEXCEPT |
722 | { return _M_rep()->_M_length; } |
723 | |
724 | |
725 | size_type |
726 | max_size() const _GLIBCXX_NOEXCEPT |
727 | { return _Rep::_S_max_size; } |
728 | |
729 | |
730 | |
731 | |
732 | |
733 | |
734 | |
735 | |
736 | |
737 | |
738 | |
739 | void |
740 | resize(size_type __n, _CharT __c); |
741 | |
742 | |
743 | |
744 | |
745 | |
746 | |
747 | |
748 | |
749 | |
750 | |
751 | |
752 | void |
753 | resize(size_type __n) |
754 | { this->resize(__n, _CharT()); } |
755 | |
756 | #if __cplusplus >= 201103L |
757 | |
758 | void |
759 | shrink_to_fit() |
760 | { |
761 | if (capacity() > size()) |
762 | { |
763 | __try |
764 | { reserve(0); } |
765 | __catch(...) |
766 | { } |
767 | } |
768 | } |
769 | #endif |
770 | |
771 | |
772 | |
773 | |
774 | |
775 | size_type |
776 | capacity() const _GLIBCXX_NOEXCEPT |
777 | { return _M_rep()->_M_capacity; } |
778 | |
779 | |
780 | |
781 | |
782 | |
783 | |
784 | |
785 | |
786 | |
787 | |
788 | |
789 | |
790 | |
791 | |
792 | |
793 | |
794 | |
795 | |
796 | void |
797 | reserve(size_type __res_arg = 0); |
798 | |
799 | |
800 | |
801 | |
802 | void |
803 | clear() _GLIBCXX_NOEXCEPT |
804 | { _M_mutate(0, this->size(), 0); } |
805 | |
806 | |
807 | |
808 | |
809 | |
810 | bool |
811 | empty() const _GLIBCXX_NOEXCEPT |
812 | { return this->size() == 0; } |
813 | |
814 | |
815 | |
816 | |
817 | |
818 | |
819 | |
820 | |
821 | |
822 | |
823 | |
824 | |
825 | const_reference |
826 | operator[] (size_type __pos) const |
827 | { |
828 | _GLIBCXX_DEBUG_ASSERT(__pos <= size()); |
829 | return _M_data()[__pos]; |
830 | } |
831 | |
832 | |
833 | |
834 | |
835 | |
836 | |
837 | |
838 | |
839 | |
840 | |
841 | |
842 | reference |
843 | operator[](size_type __pos) |
844 | { |
845 | |
846 | _GLIBCXX_DEBUG_ASSERT(__pos <= size()); |
847 | |
848 | _GLIBCXX_DEBUG_PEDASSERT(__pos < size()); |
849 | _M_leak(); |
850 | return _M_data()[__pos]; |
851 | } |
852 | |
853 | |
854 | |
855 | |
856 | |
857 | |
858 | |
859 | |
860 | |
861 | |
862 | |
863 | const_reference |
864 | at(size_type __n) const |
865 | { |
866 | if (__n >= this->size()) |
867 | __throw_out_of_range(__N("basic_string::at")); |
868 | return _M_data()[__n]; |
869 | } |
870 | |
871 | |
872 | |
873 | |
874 | |
875 | |
876 | |
877 | |
878 | |
879 | |
880 | |
881 | |
882 | reference |
883 | at(size_type __n) |
884 | { |
885 | if (__n >= size()) |
886 | __throw_out_of_range(__N("basic_string::at")); |
887 | _M_leak(); |
888 | return _M_data()[__n]; |
889 | } |
890 | |
891 | #if __cplusplus >= 201103L |
892 | |
893 | |
894 | |
895 | |
896 | reference |
897 | front() |
898 | { return operator[](0); } |
899 | |
900 | |
901 | |
902 | |
903 | |
904 | const_reference |
905 | front() const |
906 | { return operator[](0); } |
907 | |
908 | |
909 | |
910 | |
911 | |
912 | reference |
913 | back() |
914 | { return operator[](this->size() - 1); } |
915 | |
916 | |
917 | |
918 | |
919 | |
920 | const_reference |
921 | back() const |
922 | { return operator[](this->size() - 1); } |
923 | #endif |
924 | |
925 | |
926 | |
927 | |
928 | |
929 | |
930 | |
931 | basic_string& |
932 | operator+=(const basic_string& __str) |
933 | { return this->append(__str); } |
934 | |
935 | |
936 | |
937 | |
938 | |
939 | |
940 | basic_string& |
941 | operator+=(const _CharT* __s) |
942 | { return this->append(__s); } |
943 | |
944 | |
945 | |
946 | |
947 | |
948 | |
949 | basic_string& |
950 | operator+=(_CharT __c) |
951 | { |
952 | this->push_back(__c); |
953 | return *this; |
954 | } |
955 | |
956 | #if __cplusplus >= 201103L |
957 | |
958 | |
959 | |
960 | |
961 | |
962 | basic_string& |
963 | operator+=(initializer_list<_CharT> __l) |
964 | { return this->append(__l.begin(), __l.size()); } |
965 | #endif // C++11 |
966 | |
967 | |
968 | |
969 | |
970 | |
971 | |
972 | basic_string& |
973 | append(const basic_string& __str); |
974 | |
975 | |
976 | |
977 | |
978 | |
979 | |
980 | |
981 | |
982 | |
983 | |
984 | |
985 | |
986 | |
987 | |
988 | basic_string& |
989 | append(const basic_string& __str, size_type __pos, size_type __n); |
990 | |
991 | |
992 | |
993 | |
994 | |
995 | |
996 | |
997 | basic_string& |
998 | append(const _CharT* __s, size_type __n); |
999 | |
1000 | |
1001 | |
1002 | |
1003 | |
1004 | |
1005 | basic_string& |
1006 | append(const _CharT* __s) |
1007 | { |
1008 | __glibcxx_requires_string(__s); |
1009 | return this->append(__s, traits_type::length(__s)); |
1010 | } |
1011 | |
1012 | |
1013 | |
1014 | |
1015 | |
1016 | |
1017 | |
1018 | |
1019 | |
1020 | basic_string& |
1021 | append(size_type __n, _CharT __c); |
1022 | |
1023 | #if __cplusplus >= 201103L |
1024 | |
1025 | |
1026 | |
1027 | |
1028 | |
1029 | basic_string& |
1030 | append(initializer_list<_CharT> __l) |
1031 | { return this->append(__l.begin(), __l.size()); } |
1032 | #endif // C++11 |
1033 | |
1034 | |
1035 | |
1036 | |
1037 | |
1038 | |
1039 | |
1040 | |
1041 | |
1042 | template<class _InputIterator> |
1043 | basic_string& |
1044 | append(_InputIterator __first, _InputIterator __last) |
1045 | { return this->replace(_M_iend(), _M_iend(), __first, __last); } |
1046 | |
1047 | |
1048 | |
1049 | |
1050 | |
1051 | void |
1052 | push_back(_CharT __c) |
1053 | { |
1054 | const size_type __len = 1 + this->size(); |
1055 | if (__len > this->capacity() || _M_rep()->_M_is_shared()) |
1056 | this->reserve(__len); |
1057 | traits_type::assign(_M_data()[this->size()], __c); |
1058 | _M_rep()->_M_set_length_and_sharable(__len); |
1059 | } |
1060 | |
1061 | |
1062 | |
1063 | |
1064 | |
1065 | |
1066 | basic_string& |
1067 | assign(const basic_string& __str); |
1068 | |
1069 | #if __cplusplus >= 201103L |
1070 | |
1071 | |
1072 | |
1073 | |
1074 | |
1075 | |
1076 | |
1077 | |
1078 | basic_string& |
1079 | assign(basic_string&& __str) |
1080 | { |
1081 | this->swap(__str); |
1082 | return *this; |
1083 | } |
1084 | #endif // C++11 |
1085 | |
1086 | |
1087 | |
1088 | |
1089 | |
1090 | |
1091 | |
1092 | |
1093 | |
1094 | |
1095 | |
1096 | |
1097 | |
1098 | |
1099 | basic_string& |
1100 | assign(const basic_string& __str, size_type __pos, size_type __n) |
1101 | { return this->assign(__str._M_data() |
1102 | + __str._M_check(__pos, "basic_string::assign"), |
1103 | __str._M_limit(__pos, __n)); } |
1104 | |
1105 | |
1106 | |
1107 | |
1108 | |
1109 | |
1110 | |
1111 | |
1112 | |
1113 | |
1114 | |
1115 | basic_string& |
1116 | assign(const _CharT* __s, size_type __n); |
1117 | |
1118 | |
1119 | |
1120 | |
1121 | |
1122 | |
1123 | |
1124 | |
1125 | |
1126 | |
1127 | basic_string& |
1128 | assign(const _CharT* __s) |
1129 | { |
1130 | __glibcxx_requires_string(__s); |
1131 | return this->assign(__s, traits_type::length(__s)); |
1132 | } |
1133 | |
1134 | |
1135 | |
1136 | |
1137 | |
1138 | |
1139 | |
1140 | |
1141 | |
1142 | |
1143 | basic_string& |
1144 | assign(size_type __n, _CharT __c) |
1145 | { return _M_replace_aux(size_type(0), this->size(), __n, __c); } |
1146 | |
1147 | |
1148 | |
1149 | |
1150 | |
1151 | |
1152 | |
1153 | |
1154 | |
1155 | template<class _InputIterator> |
1156 | basic_string& |
1157 | assign(_InputIterator __first, _InputIterator __last) |
1158 | { return this->replace(_M_ibegin(), _M_iend(), __first, __last); } |
1159 | |
1160 | #if __cplusplus >= 201103L |
1161 | |
1162 | |
1163 | |
1164 | |
1165 | |
1166 | basic_string& |
1167 | assign(initializer_list<_CharT> __l) |
1168 | { return this->assign(__l.begin(), __l.size()); } |
1169 | #endif // C++11 |
1170 | |
1171 | |
1172 | |
1173 | |
1174 | |
1175 | |
1176 | |
1177 | |
1178 | |
1179 | |
1180 | |
1181 | |
1182 | |
1183 | |
1184 | void |
1185 | insert(iterator __p, size_type __n, _CharT __c) |
1186 | { this->replace(__p, __p, __n, __c); } |
1187 | |
1188 | |
1189 | |
1190 | |
1191 | |
1192 | |
1193 | |
1194 | |
1195 | |
1196 | |
1197 | |
1198 | |
1199 | |
1200 | template<class _InputIterator> |
1201 | void |
1202 | insert(iterator __p, _InputIterator __beg, _InputIterator __end) |
1203 | { this->replace(__p, __p, __beg, __end); } |
1204 | |
1205 | #if __cplusplus >= 201103L |
1206 | |
1207 | |
1208 | |
1209 | |
1210 | |
1211 | |
1212 | void |
1213 | insert(iterator __p, initializer_list<_CharT> __l) |
1214 | { |
1215 | _GLIBCXX_DEBUG_PEDASSERT(__p >= _M_ibegin() && __p <= _M_iend()); |
1216 | this->insert(__p - _M_ibegin(), __l.begin(), __l.size()); |
1217 | } |
1218 | #endif // C++11 |
1219 | |
1220 | |
1221 | |
1222 | |
1223 | |
1224 | |
1225 | |
1226 | |
1227 | |
1228 | |
1229 | |
1230 | |
1231 | |
1232 | basic_string& |
1233 | insert(size_type __pos1, const basic_string& __str) |
1234 | { return this->insert(__pos1, __str, size_type(0), __str.size()); } |
1235 | |
1236 | |
1237 | |
1238 | |
1239 | |
1240 | |
1241 | |
1242 | |
1243 | |
1244 | |
1245 | |
1246 | |
1247 | |
1248 | |
1249 | |
1250 | |
1251 | |
1252 | |
1253 | |
1254 | basic_string& |
1255 | insert(size_type __pos1, const basic_string& __str, |
1256 | size_type __pos2, size_type __n) |
1257 | { return this->insert(__pos1, __str._M_data() |
1258 | + __str._M_check(__pos2, "basic_string::insert"), |
1259 | __str._M_limit(__pos2, __n)); } |
1260 | |
1261 | |
1262 | |
1263 | |
1264 | |
1265 | |
1266 | |
1267 | |
1268 | |
1269 | |
1270 | |
1271 | |
1272 | |
1273 | |
1274 | |
1275 | |
1276 | |
1277 | basic_string& |
1278 | insert(size_type __pos, const _CharT* __s, size_type __n); |
1279 | |
1280 | |
1281 | |
1282 | |
1283 | |
1284 | |
1285 | |
1286 | |
1287 | |
1288 | |
1289 | |
1290 | |
1291 | |
1292 | |
1293 | |
1294 | |
1295 | basic_string& |
1296 | insert(size_type __pos, const _CharT* __s) |
1297 | { |
1298 | __glibcxx_requires_string(__s); |
1299 | return this->insert(__pos, __s, traits_type::length(__s)); |
1300 | } |
1301 | |
1302 | |
1303 | |
1304 | |
1305 | |
1306 | |
1307 | |
1308 | |
1309 | |
1310 | |
1311 | |
1312 | |
1313 | |
1314 | |
1315 | |
1316 | |
1317 | |
1318 | basic_string& |
1319 | insert(size_type __pos, size_type __n, _CharT __c) |
1320 | { return _M_replace_aux(_M_check(__pos, "basic_string::insert"), |
1321 | size_type(0), __n, __c); } |
1322 | |
1323 | |
1324 | |
1325 | |
1326 | |
1327 | |
1328 | |
1329 | |
1330 | |
1331 | |
1332 | |
1333 | |
1334 | |
1335 | |
1336 | iterator |
1337 | insert(iterator __p, _CharT __c) |
1338 | { |
1339 | _GLIBCXX_DEBUG_PEDASSERT(__p >= _M_ibegin() && __p <= _M_iend()); |
1340 | const size_type __pos = __p - _M_ibegin(); |
1341 | _M_replace_aux(__pos, size_type(0), size_type(1), __c); |
1342 | _M_rep()->_M_set_leaked(); |
1343 | return iterator(_M_data() + __pos); |
1344 | } |
1345 | |
1346 | |
1347 | |
1348 | |
1349 | |
1350 | |
1351 | |
1352 | |
1353 | |
1354 | |
1355 | |
1356 | |
1357 | |
1358 | |
1359 | |
1360 | |
1361 | basic_string& |
1362 | erase(size_type __pos = 0, size_type __n = npos) |
1363 | { |
1364 | _M_mutate(_M_check(__pos, "basic_string::erase"), |
1365 | _M_limit(__pos, __n), size_type(0)); |
1366 | return *this; |
1367 | } |
1368 | |
1369 | |
1370 | |
1371 | |
1372 | |
1373 | |
1374 | |
1375 | |
1376 | |
1377 | iterator |
1378 | erase(iterator __position) |
1379 | { |
1380 | _GLIBCXX_DEBUG_PEDASSERT(__position >= _M_ibegin() |
1381 | && __position < _M_iend()); |
1382 | const size_type __pos = __position - _M_ibegin(); |
1383 | _M_mutate(__pos, size_type(1), size_type(0)); |
1384 | _M_rep()->_M_set_leaked(); |
1385 | return iterator(_M_data() + __pos); |
1386 | } |
1387 | |
1388 | |
1389 | |
1390 | |
1391 | |
1392 | |
1393 | |
1394 | |
1395 | |
1396 | |
1397 | iterator |
1398 | erase(iterator __first, iterator __last); |
1399 | |
1400 | #if __cplusplus >= 201103L |
1401 | |
1402 | |
1403 | |
1404 | |
1405 | |
1406 | void |
1407 | pop_back() |
1408 | { erase(size()-1, 1); } |
1409 | #endif // C++11 |
1410 | |
1411 | |
1412 | |
1413 | |
1414 | |
1415 | |
1416 | |
1417 | |
1418 | |
1419 | |
1420 | |
1421 | |
1422 | |
1423 | |
1424 | |
1425 | |
1426 | |
1427 | |
1428 | basic_string& |
1429 | replace(size_type __pos, size_type __n, const basic_string& __str) |
1430 | { return this->replace(__pos, __n, __str._M_data(), __str.size()); } |
1431 | |
1432 | |
1433 | |
1434 | |
1435 | |
1436 | |
1437 | |
1438 | |
1439 | |
1440 | |
1441 | |
1442 | |
1443 | |
1444 | |
1445 | |
1446 | |
1447 | |
1448 | |
1449 | |
1450 | basic_string& |
1451 | replace(size_type __pos1, size_type __n1, const basic_string& __str, |
1452 | size_type __pos2, size_type __n2) |
1453 | { return this->replace(__pos1, __n1, __str._M_data() |
1454 | + __str._M_check(__pos2, "basic_string::replace"), |
1455 | __str._M_limit(__pos2, __n2)); } |
1456 | |
1457 | |
1458 | |
1459 | |
1460 | |
1461 | |
1462 | |
1463 | |
1464 | |
1465 | |
1466 | |
1467 | |
1468 | |
1469 | |
1470 | |
1471 | |
1472 | |
1473 | |
1474 | |
1475 | basic_string& |
1476 | replace(size_type __pos, size_type __n1, const _CharT* __s, |
1477 | size_type __n2); |
1478 | |
1479 | |
1480 | |
1481 | |
1482 | |
1483 | |
1484 | |
1485 | |
1486 | |
1487 | |
1488 | |
1489 | |
1490 | |
1491 | |
1492 | |
1493 | |
1494 | |
1495 | basic_string& |
1496 | replace(size_type __pos, size_type __n1, const _CharT* __s) |
1497 | { |
1498 | __glibcxx_requires_string(__s); |
1499 | return this->replace(__pos, __n1, __s, traits_type::length(__s)); |
1500 | } |
1501 | |
1502 | |
1503 | |
1504 | |
1505 | |
1506 | |
1507 | |
1508 | |
1509 | |
1510 | |
1511 | |
1512 | |
1513 | |
1514 | |
1515 | |
1516 | |
1517 | |
1518 | |
1519 | basic_string& |
1520 | replace(size_type __pos, size_type __n1, size_type __n2, _CharT __c) |
1521 | { return _M_replace_aux(_M_check(__pos, "basic_string::replace"), |
1522 | _M_limit(__pos, __n1), __n2, __c); } |
1523 | |
1524 | |
1525 | |
1526 | |
1527 | |
1528 | |
1529 | |
1530 | |
1531 | |
1532 | |
1533 | |
1534 | |
1535 | |
1536 | |
1537 | basic_string& |
1538 | replace(iterator __i1, iterator __i2, const basic_string& __str) |
1539 | { return this->replace(__i1, __i2, __str._M_data(), __str.size()); } |
1540 | |
1541 | |
1542 | |
1543 | |
1544 | |
1545 | |
1546 | |
1547 | |
1548 | |
1549 | |
1550 | |
1551 | |
1552 | |
1553 | |
1554 | |
1555 | |
1556 | basic_string& |
1557 | replace(iterator __i1, iterator __i2, const _CharT* __s, size_type __n) |
1558 | { |
1559 | _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2 |
1560 | && __i2 <= _M_iend()); |
1561 | return this->replace(__i1 - _M_ibegin(), __i2 - __i1, __s, __n); |
1562 | } |
1563 | |
1564 | |
1565 | |
1566 | |
1567 | |
1568 | |
1569 | |
1570 | |
1571 | |
1572 | |
1573 | |
1574 | |
1575 | |
1576 | |
1577 | basic_string& |
1578 | replace(iterator __i1, iterator __i2, const _CharT* __s) |
1579 | { |
1580 | __glibcxx_requires_string(__s); |
1581 | return this->replace(__i1, __i2, __s, traits_type::length(__s)); |
1582 | } |
1583 | |
1584 | |
1585 | |
1586 | |
1587 | |
1588 | |
1589 | |
1590 | |
1591 | |
1592 | |
1593 | |
1594 | |
1595 | |
1596 | |
1597 | |
1598 | basic_string& |
1599 | replace(iterator __i1, iterator __i2, size_type __n, _CharT __c) |
1600 | { |
1601 | _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2 |
1602 | && __i2 <= _M_iend()); |
1603 | return _M_replace_aux(__i1 - _M_ibegin(), __i2 - __i1, __n, __c); |
1604 | } |
1605 | |
1606 | |
1607 | |
1608 | |
1609 | |
1610 | |
1611 | |
1612 | |
1613 | |
1614 | |
1615 | |
1616 | |
1617 | |
1618 | |
1619 | |
1620 | |
1621 | template<class _InputIterator> |
1622 | basic_string& |
1623 | replace(iterator __i1, iterator __i2, |
1624 | _InputIterator __k1, _InputIterator __k2) |
1625 | { |
1626 | _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2 |
1627 | && __i2 <= _M_iend()); |
1628 | __glibcxx_requires_valid_range(__k1, __k2); |
1629 | typedef typename std::__is_integer<_InputIterator>::__type _Integral; |
1630 | return _M_replace_dispatch(__i1, __i2, __k1, __k2, _Integral()); |
1631 | } |
1632 | |
1633 | |
1634 | |
1635 | basic_string& |
1636 | replace(iterator __i1, iterator __i2, _CharT* __k1, _CharT* __k2) |
1637 | { |
1638 | _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2 |
1639 | && __i2 <= _M_iend()); |
1640 | __glibcxx_requires_valid_range(__k1, __k2); |
1641 | return this->replace(__i1 - _M_ibegin(), __i2 - __i1, |
1642 | __k1, __k2 - __k1); |
1643 | } |
1644 | |
1645 | basic_string& |
1646 | replace(iterator __i1, iterator __i2, |
1647 | const _CharT* __k1, const _CharT* __k2) |
1648 | { |
1649 | _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2 |
1650 | && __i2 <= _M_iend()); |
1651 | __glibcxx_requires_valid_range(__k1, __k2); |
1652 | return this->replace(__i1 - _M_ibegin(), __i2 - __i1, |
1653 | __k1, __k2 - __k1); |
1654 | } |
1655 | |
1656 | basic_string& |
1657 | replace(iterator __i1, iterator __i2, iterator __k1, iterator __k2) |
1658 | { |
1659 | _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2 |
1660 | && __i2 <= _M_iend()); |
1661 | __glibcxx_requires_valid_range(__k1, __k2); |
1662 | return this->replace(__i1 - _M_ibegin(), __i2 - __i1, |
1663 | __k1.base(), __k2 - __k1); |
1664 | } |
1665 | |
1666 | basic_string& |
1667 | replace(iterator __i1, iterator __i2, |
1668 | const_iterator __k1, const_iterator __k2) |
1669 | { |
1670 | _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2 |
1671 | && __i2 <= _M_iend()); |
1672 | __glibcxx_requires_valid_range(__k1, __k2); |
1673 | return this->replace(__i1 - _M_ibegin(), __i2 - __i1, |
1674 | __k1.base(), __k2 - __k1); |
1675 | } |
1676 | |
1677 | #if __cplusplus >= 201103L |
1678 | |
1679 | |
1680 | |
1681 | |
1682 | |
1683 | |
1684 | |
1685 | |
1686 | |
1687 | |
1688 | |
1689 | |
1690 | |
1691 | |
1692 | basic_string& replace(iterator __i1, iterator __i2, |
1693 | initializer_list<_CharT> __l) |
1694 | { return this->replace(__i1, __i2, __l.begin(), __l.end()); } |
1695 | #endif // C++11 |
1696 | |
1697 | private: |
1698 | template<class _Integer> |
1699 | basic_string& |
1700 | _M_replace_dispatch(iterator __i1, iterator __i2, _Integer __n, |
1701 | _Integer __val, __true_type) |
1702 | { return _M_replace_aux(__i1 - _M_ibegin(), __i2 - __i1, __n, __val); } |
1703 | |
1704 | template<class _InputIterator> |
1705 | basic_string& |
1706 | _M_replace_dispatch(iterator __i1, iterator __i2, _InputIterator __k1, |
1707 | _InputIterator __k2, __false_type); |
1708 | |
1709 | basic_string& |
1710 | _M_replace_aux(size_type __pos1, size_type __n1, size_type __n2, |
1711 | _CharT __c); |
1712 | |
1713 | basic_string& |
1714 | _M_replace_safe(size_type __pos1, size_type __n1, const _CharT* __s, |
1715 | size_type __n2); |
1716 | |
1717 | |
1718 | |
1719 | template<class _InIterator> |
1720 | static _CharT* |
1721 | _S_construct_aux(_InIterator __beg, _InIterator __end, |
1722 | const _Alloc& __a, __false_type) |
1723 | { |
1724 | typedef typename iterator_traits<_InIterator>::iterator_category _Tag; |
1725 | return _S_construct(__beg, __end, __a, _Tag()); |
1726 | } |
1727 | |
1728 | |
1729 | |
1730 | template<class _Integer> |
1731 | static _CharT* |
1732 | _S_construct_aux(_Integer __beg, _Integer __end, |
1733 | const _Alloc& __a, __true_type) |
1734 | { return _S_construct_aux_2(static_cast<size_type>(__beg), |
1735 | __end, __a); } |
1736 | |
1737 | static _CharT* |
1738 | _S_construct_aux_2(size_type __req, _CharT __c, const _Alloc& __a) |
1739 | { return _S_construct(__req, __c, __a); } |
1740 | |
1741 | template<class _InIterator> |
1742 | static _CharT* |
1743 | _S_construct(_InIterator __beg, _InIterator __end, const _Alloc& __a) |
1744 | { |
1745 | typedef typename std::__is_integer<_InIterator>::__type _Integral; |
1746 | return _S_construct_aux(__beg, __end, __a, _Integral()); |
1747 | } |
1748 | |
1749 | |
1750 | template<class _InIterator> |
1751 | static _CharT* |
1752 | _S_construct(_InIterator __beg, _InIterator __end, const _Alloc& __a, |
1753 | input_iterator_tag); |
1754 | |
1755 | |
1756 | |
1757 | template<class _FwdIterator> |
1758 | static _CharT* |
1759 | _S_construct(_FwdIterator __beg, _FwdIterator __end, const _Alloc& __a, |
1760 | forward_iterator_tag); |
1761 | |
1762 | static _CharT* |
1763 | _S_construct(size_type __req, _CharT __c, const _Alloc& __a); |
1764 | |
1765 | public: |
1766 | |
1767 | |
1768 | |
1769 | |
1770 | |
1771 | |
1772 | |
1773 | |
1774 | |
1775 | |
1776 | |
1777 | |
1778 | |
1779 | size_type |
1780 | copy(_CharT* __s, size_type __n, size_type __pos = 0) const; |
1781 | |
1782 | |
1783 | |
1784 | |
1785 | |
1786 | |
1787 | |
1788 | |
1789 | void |
1790 | swap(basic_string& __s); |
1791 | |
1792 | |
1793 | |
1794 | |
1795 | |
1796 | |
1797 | |
1798 | |
1799 | const _CharT* |
1800 | c_str() const _GLIBCXX_NOEXCEPT |
1801 | { return _M_data(); } |
1802 | |
1803 | |
1804 | |
1805 | |
1806 | |
1807 | |
1808 | |
1809 | const _CharT* |
1810 | data() const _GLIBCXX_NOEXCEPT |
1811 | { return _M_data(); } |
1812 | |
1813 | |
1814 | |
1815 | |
1816 | allocator_type |
1817 | get_allocator() const _GLIBCXX_NOEXCEPT |
1818 | { return _M_dataplus; } |
1819 | |
1820 | |
1821 | |
1822 | |
1823 | |
1824 | |
1825 | |
1826 | |
1827 | |
1828 | |
1829 | |
1830 | |
1831 | |
1832 | size_type |
1833 | find(const _CharT* __s, size_type __pos, size_type __n) const; |
1834 | |
1835 | |
1836 | |
1837 | |
1838 | |
1839 | |
1840 | |
1841 | |
1842 | |
1843 | |
1844 | |
1845 | size_type |
1846 | find(const basic_string& __str, size_type __pos = 0) const |
1847 | _GLIBCXX_NOEXCEPT |
1848 | { return this->find(__str.data(), __pos, __str.size()); } |
1849 | |
1850 | |
1851 | |
1852 | |
1853 | |
1854 | |
1855 | |
1856 | |
1857 | |
1858 | |
1859 | |
1860 | size_type |
1861 | find(const _CharT* __s, size_type __pos = 0) const |
1862 | { |
1863 | __glibcxx_requires_string(__s); |
1864 | return this->find(__s, __pos, traits_type::length(__s)); |
1865 | } |
1866 | |
1867 | |
1868 | |
1869 | |
1870 | |
1871 | |
1872 | |
1873 | |
1874 | |
1875 | |
1876 | |
1877 | size_type |
1878 | find(_CharT __c, size_type __pos = 0) const _GLIBCXX_NOEXCEPT; |
1879 | |
1880 | |
1881 | |
1882 | |
1883 | |
1884 | |
1885 | |
1886 | |
1887 | |
1888 | |
1889 | |
1890 | size_type |
1891 | rfind(const basic_string& __str, size_type __pos = npos) const |
1892 | _GLIBCXX_NOEXCEPT |
1893 | { return this->rfind(__str.data(), __pos, __str.size()); } |
1894 | |
1895 | |
1896 | |
1897 | |
1898 | |
1899 | |
1900 | |
1901 | |
1902 | |
1903 | |
1904 | |
1905 | |
1906 | |
1907 | size_type |
1908 | rfind(const _CharT* __s, size_type __pos, size_type __n) const; |
1909 | |
1910 | |
1911 | |
1912 | |
1913 | |
1914 | |
1915 | |
1916 | |
1917 | |
1918 | |
1919 | |
1920 | size_type |
1921 | rfind(const _CharT* __s, size_type __pos = npos) const |
1922 | { |
1923 | __glibcxx_requires_string(__s); |
1924 | return this->rfind(__s, __pos, traits_type::length(__s)); |
1925 | } |
1926 | |
1927 | |
1928 | |
1929 | |
1930 | |
1931 | |
1932 | |
1933 | |
1934 | |
1935 | |
1936 | |
1937 | size_type |
1938 | rfind(_CharT __c, size_type __pos = npos) const _GLIBCXX_NOEXCEPT; |
1939 | |
1940 | |
1941 | |
1942 | |
1943 | |
1944 | |
1945 | |
1946 | |
1947 | |
1948 | |
1949 | |
1950 | |
1951 | size_type |
1952 | find_first_of(const basic_string& __str, size_type __pos = 0) const |
1953 | _GLIBCXX_NOEXCEPT |
1954 | { return this->find_first_of(__str.data(), __pos, __str.size()); } |
1955 | |
1956 | |
1957 | |
1958 | |
1959 | |
1960 | |
1961 | |
1962 | |
1963 | |
1964 | |
1965 | |
1966 | |
1967 | |
1968 | size_type |
1969 | find_first_of(const _CharT* __s, size_type __pos, size_type __n) const; |
1970 | |
1971 | |
1972 | |
1973 | |
1974 | |
1975 | |
1976 | |
1977 | |
1978 | |
1979 | |
1980 | |
1981 | size_type |
1982 | find_first_of(const _CharT* __s, size_type __pos = 0) const |
1983 | { |
1984 | __glibcxx_requires_string(__s); |
1985 | return this->find_first_of(__s, __pos, traits_type::length(__s)); |
1986 | } |
1987 | |
1988 | |
1989 | |
1990 | |
1991 | |
1992 | |
1993 | |
1994 | |
1995 | |
1996 | |
1997 | |
1998 | |
1999 | |
2000 | size_type |
2001 | find_first_of(_CharT __c, size_type __pos = 0) const _GLIBCXX_NOEXCEPT |
2002 | { return this->find(__c, __pos); } |
2003 | |
2004 | |
2005 | |
2006 | |
2007 | |
2008 | |
2009 | |
2010 | |
2011 | |
2012 | |
2013 | |
2014 | |
2015 | size_type |
2016 | find_last_of(const basic_string& __str, size_type __pos = npos) const |
2017 | _GLIBCXX_NOEXCEPT |
2018 | { return this->find_last_of(__str.data(), __pos, __str.size()); } |
2019 | |
2020 | |
2021 | |
2022 | |
2023 | |
2024 | |
2025 | |
2026 | |
2027 | |
2028 | |
2029 | |
2030 | |
2031 | |
2032 | size_type |
2033 | find_last_of(const _CharT* __s, size_type __pos, size_type __n) const; |
2034 | |
2035 | |
2036 | |
2037 | |
2038 | |
2039 | |
2040 | |
2041 | |
2042 | |
2043 | |
2044 | |
2045 | size_type |
2046 | find_last_of(const _CharT* __s, size_type __pos = npos) const |
2047 | { |
2048 | __glibcxx_requires_string(__s); |
2049 | return this->find_last_of(__s, __pos, traits_type::length(__s)); |
2050 | } |
2051 | |
2052 | |
2053 | |
2054 | |
2055 | |
2056 | |
2057 | |
2058 | |
2059 | |
2060 | |
2061 | |
2062 | |
2063 | |
2064 | size_type |
2065 | find_last_of(_CharT __c, size_type __pos = npos) const _GLIBCXX_NOEXCEPT |
2066 | { return this->rfind(__c, __pos); } |
2067 | |
2068 | |
2069 | |
2070 | |
2071 | |
2072 | |
2073 | |
2074 | |
2075 | |
2076 | |
2077 | |
2078 | size_type |
2079 | find_first_not_of(const basic_string& __str, size_type __pos = 0) const |
2080 | _GLIBCXX_NOEXCEPT |
2081 | { return this->find_first_not_of(__str.data(), __pos, __str.size()); } |
2082 | |
2083 | |
2084 | |
2085 | |
2086 | |
2087 | |
2088 | |
2089 | |
2090 | |
2091 | |
2092 | |
2093 | |
2094 | |
2095 | size_type |
2096 | find_first_not_of(const _CharT* __s, size_type __pos, |
2097 | size_type __n) const; |
2098 | |
2099 | |
2100 | |
2101 | |
2102 | |
2103 | |
2104 | |
2105 | |
2106 | |
2107 | |
2108 | |
2109 | size_type |
2110 | find_first_not_of(const _CharT* __s, size_type __pos = 0) const |
2111 | { |
2112 | __glibcxx_requires_string(__s); |
2113 | return this->find_first_not_of(__s, __pos, traits_type::length(__s)); |
2114 | } |
2115 | |
2116 | |
2117 | |
2118 | |
2119 | |
2120 | |
2121 | |
2122 | |
2123 | |
2124 | |
2125 | |
2126 | size_type |
2127 | find_first_not_of(_CharT __c, size_type __pos = 0) const |
2128 | _GLIBCXX_NOEXCEPT; |
2129 | |
2130 | |
2131 | |
2132 | |
2133 | |
2134 | |
2135 | |
2136 | |
2137 | |
2138 | |
2139 | |
2140 | |
2141 | size_type |
2142 | find_last_not_of(const basic_string& __str, size_type __pos = npos) const |
2143 | _GLIBCXX_NOEXCEPT |
2144 | { return this->find_last_not_of(__str.data(), __pos, __str.size()); } |
2145 | |
2146 | |
2147 | |
2148 | |
2149 | |
2150 | |
2151 | |
2152 | |
2153 | |
2154 | |
2155 | |
2156 | |
2157 | |
2158 | size_type |
2159 | find_last_not_of(const _CharT* __s, size_type __pos, |
2160 | size_type __n) const; |
2161 | |
2162 | |
2163 | |
2164 | |
2165 | |
2166 | |
2167 | |
2168 | |
2169 | |
2170 | |
2171 | |
2172 | size_type |
2173 | find_last_not_of(const _CharT* __s, size_type __pos = npos) const |
2174 | { |
2175 | __glibcxx_requires_string(__s); |
2176 | return this->find_last_not_of(__s, __pos, traits_type::length(__s)); |
2177 | } |
2178 | |
2179 | |
2180 | |
2181 | |
2182 | |
2183 | |
2184 | |
2185 | |
2186 | |
2187 | |
2188 | |
2189 | size_type |
2190 | find_last_not_of(_CharT __c, size_type __pos = npos) const |
2191 | _GLIBCXX_NOEXCEPT; |
2192 | |
2193 | |
2194 | |
2195 | |
2196 | |
2197 | |
2198 | |
2199 | |
2200 | |
2201 | |
2202 | |
2203 | |
2204 | |
2205 | basic_string |
2206 | substr(size_type __pos = 0, size_type __n = npos) const |
2207 | { return basic_string(*this, |
2208 | _M_check(__pos, "basic_string::substr"), __n); } |
2209 | |
2210 | |
2211 | |
2212 | |
2213 | |
2214 | |
2215 | |
2216 | |
2217 | |
2218 | |
2219 | |
2220 | |
2221 | |
2222 | |
2223 | |
2224 | int |
2225 | compare(const basic_string& __str) const |
2226 | { |
2227 | const size_type __size = this->size(); |
2228 | const size_type __osize = __str.size(); |
2229 | const size_type __len = std::min(__size, __osize); |
2230 | |
2231 | int __r = traits_type::compare(_M_data(), __str.data(), __len); |
2232 | if (!__r) |
2233 | __r = _S_compare(__size, __osize); |
2234 | return __r; |
2235 | } |
2236 | |
2237 | |
2238 | |
2239 | |
2240 | |
2241 | |
2242 | |
2243 | |
2244 | |
2245 | |
2246 | |
2247 | |
2248 | |
2249 | |
2250 | |
2251 | |
2252 | |
2253 | |
2254 | |
2255 | |
2256 | int |
2257 | compare(size_type __pos, size_type __n, const basic_string& __str) const; |
2258 | |
2259 | |
2260 | |
2261 | |
2262 | |
2263 | |
2264 | |
2265 | |
2266 | |
2267 | |
2268 | |
2269 | |
2270 | |
2271 | |
2272 | |
2273 | |
2274 | |
2275 | |
2276 | |
2277 | |
2278 | |
2279 | |
2280 | |
2281 | |
2282 | int |
2283 | compare(size_type __pos1, size_type __n1, const basic_string& __str, |
2284 | size_type __pos2, size_type __n2) const; |
2285 | |
2286 | |
2287 | |
2288 | |
2289 | |
2290 | |
2291 | |
2292 | |
2293 | |
2294 | |
2295 | |
2296 | |
2297 | |
2298 | |
2299 | |
2300 | int |
2301 | compare(const _CharT* __s) const; |
2302 | |
2303 | |
2304 | |
2305 | |
2306 | |
2307 | |
2308 | |
2309 | |
2310 | |
2311 | |
2312 | |
2313 | |
2314 | |
2315 | |
2316 | |
2317 | |
2318 | |
2319 | |
2320 | |
2321 | |
2322 | |
2323 | |
2324 | int |
2325 | compare(size_type __pos, size_type __n1, const _CharT* __s) const; |
2326 | |
2327 | |
2328 | |
2329 | |
2330 | |
2331 | |
2332 | |
2333 | |
2334 | |
2335 | |
2336 | |
2337 | |
2338 | |
2339 | |
2340 | |
2341 | |
2342 | |
2343 | |
2344 | |
2345 | |
2346 | |
2347 | |
2348 | |
2349 | |
2350 | |
2351 | int |
2352 | compare(size_type __pos, size_type __n1, const _CharT* __s, |
2353 | size_type __n2) const; |
2354 | }; |
2355 | |
2356 | |
2357 | |
2358 | |
2359 | |
2360 | |
2361 | |
2362 | |
2363 | template<typename _CharT, typename _Traits, typename _Alloc> |
2364 | basic_string<_CharT, _Traits, _Alloc> |
2365 | operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs, |
2366 | const basic_string<_CharT, _Traits, _Alloc>& __rhs) |
2367 | { |
2368 | basic_string<_CharT, _Traits, _Alloc> __str(__lhs); |
2369 | __str.append(__rhs); |
2370 | return __str; |
2371 | } |
2372 | |
2373 | |
2374 | |
2375 | |
2376 | |
2377 | |
2378 | |
2379 | template<typename _CharT, typename _Traits, typename _Alloc> |
2380 | basic_string<_CharT,_Traits,_Alloc> |
2381 | operator+(const _CharT* __lhs, |
2382 | const basic_string<_CharT,_Traits,_Alloc>& __rhs); |
2383 | |
2384 | |
2385 | |
2386 | |
2387 | |
2388 | |
2389 | |
2390 | template<typename _CharT, typename _Traits, typename _Alloc> |
2391 | basic_string<_CharT,_Traits,_Alloc> |
2392 | operator+(_CharT __lhs, const basic_string<_CharT,_Traits,_Alloc>& __rhs); |
2393 | |
2394 | |
2395 | |
2396 | |
2397 | |
2398 | |
2399 | |
2400 | template<typename _CharT, typename _Traits, typename _Alloc> |
2401 | inline basic_string<_CharT, _Traits, _Alloc> |
2402 | operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs, |
2403 | const _CharT* __rhs) |
2404 | { |
2405 | basic_string<_CharT, _Traits, _Alloc> __str(__lhs); |
2406 | __str.append(__rhs); |
2407 | return __str; |
2408 | } |
2409 | |
2410 | |
2411 | |
2412 | |
2413 | |
2414 | |
2415 | |
2416 | template<typename _CharT, typename _Traits, typename _Alloc> |
2417 | inline basic_string<_CharT, _Traits, _Alloc> |
2418 | operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs, _CharT __rhs) |
2419 | { |
2420 | typedef basic_string<_CharT, _Traits, _Alloc> __string_type; |
2421 | typedef typename __string_type::size_type __size_type; |
2422 | __string_type __str(__lhs); |
2423 | __str.append(__size_type(1), __rhs); |
2424 | return __str; |
2425 | } |
2426 | |
2427 | #if __cplusplus >= 201103L |
2428 | template<typename _CharT, typename _Traits, typename _Alloc> |
2429 | inline basic_string<_CharT, _Traits, _Alloc> |
2430 | operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs, |
2431 | const basic_string<_CharT, _Traits, _Alloc>& __rhs) |
2432 | { return std::move(__lhs.append(__rhs)); } |
2433 | |
2434 | template<typename _CharT, typename _Traits, typename _Alloc> |
2435 | inline basic_string<_CharT, _Traits, _Alloc> |
2436 | operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs, |
2437 | basic_string<_CharT, _Traits, _Alloc>&& __rhs) |
2438 | { return std::move(__rhs.insert(0, __lhs)); } |
2439 | |
2440 | template<typename _CharT, typename _Traits, typename _Alloc> |
2441 | inline basic_string<_CharT, _Traits, _Alloc> |
2442 | operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs, |
2443 | basic_string<_CharT, _Traits, _Alloc>&& __rhs) |
2444 | { |
2445 | const auto __size = __lhs.size() + __rhs.size(); |
2446 | const bool __cond = (__size > __lhs.capacity() |
2447 | && __size <= __rhs.capacity()); |
2448 | return __cond ? std::move(__rhs.insert(0, __lhs)) |
2449 | : std::move(__lhs.append(__rhs)); |
2450 | } |
2451 | |
2452 | template<typename _CharT, typename _Traits, typename _Alloc> |
2453 | inline basic_string<_CharT, _Traits, _Alloc> |
2454 | operator+(const _CharT* __lhs, |
2455 | basic_string<_CharT, _Traits, _Alloc>&& __rhs) |
2456 | { return std::move(__rhs.insert(0, __lhs)); } |
2457 | |
2458 | template<typename _CharT, typename _Traits, typename _Alloc> |
2459 | inline basic_string<_CharT, _Traits, _Alloc> |
2460 | operator+(_CharT __lhs, |
2461 | basic_string<_CharT, _Traits, _Alloc>&& __rhs) |
2462 | { return std::move(__rhs.insert(0, 1, __lhs)); } |
2463 | |
2464 | template<typename _CharT, typename _Traits, typename _Alloc> |
2465 | inline basic_string<_CharT, _Traits, _Alloc> |
2466 | operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs, |
2467 | const _CharT* __rhs) |
2468 | { return std::move(__lhs.append(__rhs)); } |
2469 | |
2470 | template<typename _CharT, typename _Traits, typename _Alloc> |
2471 | inline basic_string<_CharT, _Traits, _Alloc> |
2472 | operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs, |
2473 | _CharT __rhs) |
2474 | { return std::move(__lhs.append(1, __rhs)); } |
2475 | #endif |
2476 | |
2477 | |
2478 | |
2479 | |
2480 | |
2481 | |
2482 | |
2483 | |
2484 | template<typename _CharT, typename _Traits, typename _Alloc> |
2485 | inline bool |
2486 | operator==(const basic_string<_CharT, _Traits, _Alloc>& __lhs, |
2487 | const basic_string<_CharT, _Traits, _Alloc>& __rhs) |
2488 | { return __lhs.compare(__rhs) == 0; } |
2489 | |
2490 | template<typename _CharT> |
2491 | inline |
2492 | typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value, bool>::__type |
2493 | operator==(const basic_string<_CharT>& __lhs, |
2494 | const basic_string<_CharT>& __rhs) |
2495 | { return (__lhs.size() == __rhs.size() |
2496 | && !std::char_traits<_CharT>::compare(__lhs.data(), __rhs.data(), |
2497 | __lhs.size())); } |
2498 | |
2499 | |
2500 | |
2501 | |
2502 | |
2503 | |
2504 | |
2505 | template<typename _CharT, typename _Traits, typename _Alloc> |
2506 | inline bool |
2507 | operator==(const _CharT* __lhs, |
2508 | const basic_string<_CharT, _Traits, _Alloc>& __rhs) |
2509 | { return __rhs.compare(__lhs) == 0; } |
2510 | |
2511 | |
2512 | |
2513 | |
2514 | |
2515 | |
2516 | |
2517 | template<typename _CharT, typename _Traits, typename _Alloc> |
2518 | inline bool |
2519 | operator==(const basic_string<_CharT, _Traits, _Alloc>& __lhs, |
2520 | const _CharT* __rhs) |
2521 | { return __lhs.compare(__rhs) == 0; } |
| 17 | | Assuming the condition is false | |
|
| 18 | | Returning zero, which participates in a condition later | |
|
| 22 | | Assuming the condition is false | |
|
| 23 | | Returning zero, which participates in a condition later | |
|
| 27 | | Assuming the condition is false | |
|
| 28 | | Returning zero, which participates in a condition later | |
|
| 32 | | Assuming the condition is false | |
|
| 33 | | Returning zero, which participates in a condition later | |
|
| 37 | | Assuming the condition is false | |
|
| 38 | | Returning zero, which participates in a condition later | |
|
| 42 | | Assuming the condition is false | |
|
| 43 | | Returning zero, which participates in a condition later | |
|
| 47 | | Assuming the condition is false | |
|
| 48 | | Returning zero, which participates in a condition later | |
|
| 52 | | Assuming the condition is false | |
|
| 53 | | Returning zero, which participates in a condition later | |
|
| 57 | | Assuming the condition is true | |
|
| 58 | | Returning the value 1, which participates in a condition later | |
|
| 65 | | Assuming the condition is true | |
|
| 66 | | Returning the value 1, which participates in a condition later | |
|
2522 | |
2523 | |
2524 | |
2525 | |
2526 | |
2527 | |
2528 | |
2529 | |
2530 | template<typename _CharT, typename _Traits, typename _Alloc> |
2531 | inline bool |
2532 | operator!=(const basic_string<_CharT, _Traits, _Alloc>& __lhs, |
2533 | const basic_string<_CharT, _Traits, _Alloc>& __rhs) |
2534 | { return !(__lhs == __rhs); } |
2535 | |
2536 | |
2537 | |
2538 | |
2539 | |
2540 | |
2541 | |
2542 | template<typename _CharT, typename _Traits, typename _Alloc> |
2543 | inline bool |
2544 | operator!=(const _CharT* __lhs, |
2545 | const basic_string<_CharT, _Traits, _Alloc>& __rhs) |
2546 | { return !(__lhs == __rhs); } |
2547 | |
2548 | |
2549 | |
2550 | |
2551 | |
2552 | |
2553 | |
2554 | template<typename _CharT, typename _Traits, typename _Alloc> |
2555 | inline bool |
2556 | operator!=(const basic_string<_CharT, _Traits, _Alloc>& __lhs, |
2557 | const _CharT* __rhs) |
2558 | { return !(__lhs == __rhs); } |
| 64 | | Calling 'operator==<char, std::char_traits<char>, std::allocator<char>>' | |
|
| 67 | | Returning from 'operator==<char, std::char_traits<char>, std::allocator<char>>' | |
|
| 68 | | Returning zero, which participates in a condition later | |
|
2559 | |
2560 | |
2561 | |
2562 | |
2563 | |
2564 | |
2565 | |
2566 | |
2567 | template<typename _CharT, typename _Traits, typename _Alloc> |
2568 | inline bool |
2569 | operator<(const basic_string<_CharT, _Traits, _Alloc>& __lhs, |
2570 | const basic_string<_CharT, _Traits, _Alloc>& __rhs) |
2571 | { return __lhs.compare(__rhs) < 0; } |
2572 | |
2573 | |
2574 | |
2575 | |
2576 | |
2577 | |
2578 | |
2579 | template<typename _CharT, typename _Traits, typename _Alloc> |
2580 | inline bool |
2581 | operator<(const basic_string<_CharT, _Traits, _Alloc>& __lhs, |
2582 | const _CharT* __rhs) |
2583 | { return __lhs.compare(__rhs) < 0; } |
2584 | |
2585 | |
2586 | |
2587 | |
2588 | |
2589 | |
2590 | |
2591 | template<typename _CharT, typename _Traits, typename _Alloc> |
2592 | inline bool |
2593 | operator<(const _CharT* __lhs, |
2594 | const basic_string<_CharT, _Traits, _Alloc>& __rhs) |
2595 | { return __rhs.compare(__lhs) > 0; } |
2596 | |
2597 | |
2598 | |
2599 | |
2600 | |
2601 | |
2602 | |
2603 | |
2604 | template<typename _CharT, typename _Traits, typename _Alloc> |
2605 | inline bool |
2606 | operator>(const basic_string<_CharT, _Traits, _Alloc>& __lhs, |
2607 | const basic_string<_CharT, _Traits, _Alloc>& __rhs) |
2608 | { return __lhs.compare(__rhs) > 0; } |
2609 | |
2610 | |
2611 | |
2612 | |
2613 | |
2614 | |
2615 | |
2616 | template<typename _CharT, typename _Traits, typename _Alloc> |
2617 | inline bool |
2618 | operator>(const basic_string<_CharT, _Traits, _Alloc>& __lhs, |
2619 | const _CharT* __rhs) |
2620 | { return __lhs.compare(__rhs) > 0; } |
2621 | |
2622 | |
2623 | |
2624 | |
2625 | |
2626 | |
2627 | |
2628 | template<typename _CharT, typename _Traits, typename _Alloc> |
2629 | inline bool |
2630 | operator>(const _CharT* __lhs, |
2631 | const basic_string<_CharT, _Traits, _Alloc>& __rhs) |
2632 | { return __rhs.compare(__lhs) < 0; } |
2633 | |
2634 | |
2635 | |
2636 | |
2637 | |
2638 | |
2639 | |
2640 | |
2641 | template<typename _CharT, typename _Traits, typename _Alloc> |
2642 | inline bool |
2643 | operator<=(const basic_string<_CharT, _Traits, _Alloc>& __lhs, |
2644 | const basic_string<_CharT, _Traits, _Alloc>& __rhs) |
2645 | { return __lhs.compare(__rhs) <= 0; } |
2646 | |
2647 | |
2648 | |
2649 | |
2650 | |
2651 | |
2652 | |
2653 | template<typename _CharT, typename _Traits, typename _Alloc> |
2654 | inline bool |
2655 | operator<=(const basic_string<_CharT, _Traits, _Alloc>& __lhs, |
2656 | const _CharT* __rhs) |
2657 | { return __lhs.compare(__rhs) <= 0; } |
2658 | |
2659 | |
2660 | |
2661 | |
2662 | |
2663 | |
2664 | |
2665 | template<typename _CharT, typename _Traits, typename _Alloc> |
2666 | inline bool |
2667 | operator<=(const _CharT* __lhs, |
2668 | const basic_string<_CharT, _Traits, _Alloc>& __rhs) |
2669 | { return __rhs.compare(__lhs) >= 0; } |
2670 | |
2671 | |
2672 | |
2673 | |
2674 | |
2675 | |
2676 | |
2677 | |
2678 | template<typename _CharT, typename _Traits, typename _Alloc> |
2679 | inline bool |
2680 | operator>=(const basic_string<_CharT, _Traits, _Alloc>& __lhs, |
2681 | const basic_string<_CharT, _Traits, _Alloc>& __rhs) |
2682 | { return __lhs.compare(__rhs) >= 0; } |
2683 | |
2684 | |
2685 | |
2686 | |
2687 | |
2688 | |
2689 | |
2690 | template<typename _CharT, typename _Traits, typename _Alloc> |
2691 | inline bool |
2692 | operator>=(const basic_string<_CharT, _Traits, _Alloc>& __lhs, |
2693 | const _CharT* __rhs) |
2694 | { return __lhs.compare(__rhs) >= 0; } |
2695 | |
2696 | |
2697 | |
2698 | |
2699 | |
2700 | |
2701 | |
2702 | template<typename _CharT, typename _Traits, typename _Alloc> |
2703 | inline bool |
2704 | operator>=(const _CharT* __lhs, |
2705 | const basic_string<_CharT, _Traits, _Alloc>& __rhs) |
2706 | { return __rhs.compare(__lhs) <= 0; } |
2707 | |
2708 | |
2709 | |
2710 | |
2711 | |
2712 | |
2713 | |
2714 | |
2715 | template<typename _CharT, typename _Traits, typename _Alloc> |
2716 | inline void |
2717 | swap(basic_string<_CharT, _Traits, _Alloc>& __lhs, |
2718 | basic_string<_CharT, _Traits, _Alloc>& __rhs) |
2719 | { __lhs.swap(__rhs); } |
2720 | |
2721 | |
2722 | |
2723 | |
2724 | |
2725 | |
2726 | |
2727 | |
2728 | |
2729 | |
2730 | |
2731 | |
2732 | |
2733 | template<typename _CharT, typename _Traits, typename _Alloc> |
2734 | basic_istream<_CharT, _Traits>& |
2735 | operator>>(basic_istream<_CharT, _Traits>& __is, |
2736 | basic_string<_CharT, _Traits, _Alloc>& __str); |
2737 | |
2738 | template<> |
2739 | basic_istream<char>& |
2740 | operator>>(basic_istream<char>& __is, basic_string<char>& __str); |
2741 | |
2742 | |
2743 | |
2744 | |
2745 | |
2746 | |
2747 | |
2748 | |
2749 | |
2750 | |
2751 | template<typename _CharT, typename _Traits, typename _Alloc> |
2752 | inline basic_ostream<_CharT, _Traits>& |
2753 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
2754 | const basic_string<_CharT, _Traits, _Alloc>& __str) |
2755 | { |
2756 | |
2757 | |
2758 | return __ostream_insert(__os, __str.data(), __str.size()); |
2759 | } |
2760 | |
2761 | |
2762 | |
2763 | |
2764 | |
2765 | |
2766 | |
2767 | |
2768 | |
2769 | |
2770 | |
2771 | |
2772 | |
2773 | |
2774 | template<typename _CharT, typename _Traits, typename _Alloc> |
2775 | basic_istream<_CharT, _Traits>& |
2776 | getline(basic_istream<_CharT, _Traits>& __is, |
2777 | basic_string<_CharT, _Traits, _Alloc>& __str, _CharT __delim); |
2778 | |
2779 | |
2780 | |
2781 | |
2782 | |
2783 | |
2784 | |
2785 | |
2786 | |
2787 | |
2788 | |
2789 | |
2790 | |
2791 | template<typename _CharT, typename _Traits, typename _Alloc> |
2792 | inline basic_istream<_CharT, _Traits>& |
2793 | getline(basic_istream<_CharT, _Traits>& __is, |
2794 | basic_string<_CharT, _Traits, _Alloc>& __str) |
2795 | { return getline(__is, __str, __is.widen('\n')); } |
2796 | |
2797 | template<> |
2798 | basic_istream<char>& |
2799 | getline(basic_istream<char>& __in, basic_string<char>& __str, |
2800 | char __delim); |
2801 | |
2802 | #ifdef _GLIBCXX_USE_WCHAR_T |
2803 | template<> |
2804 | basic_istream<wchar_t>& |
2805 | getline(basic_istream<wchar_t>& __in, basic_string<wchar_t>& __str, |
2806 | wchar_t __delim); |
2807 | #endif |
2808 | |
2809 | _GLIBCXX_END_NAMESPACE_VERSION |
2810 | } |
2811 | |
2812 | #if ((__cplusplus >= 201103L) && defined(_GLIBCXX_USE_C99) \ |
2813 | && !defined(_GLIBCXX_HAVE_BROKEN_VSWPRINTF)) |
2814 | |
2815 | #include <ext/string_conversions.h> |
2816 | |
2817 | namespace std _GLIBCXX_VISIBILITY(default) |
2818 | { |
2819 | _GLIBCXX_BEGIN_NAMESPACE_VERSION |
2820 | |
2821 | |
2822 | inline int |
2823 | stoi(const string& __str, size_t* __idx = 0, int __base = 10) |
2824 | { return __gnu_cxx::__stoa<long, int>(&std::strtol, "stoi", __str.c_str(), |
2825 | __idx, __base); } |
2826 | |
2827 | inline long |
2828 | stol(const string& __str, size_t* __idx = 0, int __base = 10) |
2829 | { return __gnu_cxx::__stoa(&std::strtol, "stol", __str.c_str(), |
2830 | __idx, __base); } |
2831 | |
2832 | inline unsigned long |
2833 | stoul(const string& __str, size_t* __idx = 0, int __base = 10) |
2834 | { return __gnu_cxx::__stoa(&std::strtoul, "stoul", __str.c_str(), |
2835 | __idx, __base); } |
2836 | |
2837 | inline long long |
2838 | stoll(const string& __str, size_t* __idx = 0, int __base = 10) |
2839 | { return __gnu_cxx::__stoa(&std::strtoll, "stoll", __str.c_str(), |
2840 | __idx, __base); } |
2841 | |
2842 | inline unsigned long long |
2843 | stoull(const string& __str, size_t* __idx = 0, int __base = 10) |
2844 | { return __gnu_cxx::__stoa(&std::strtoull, "stoull", __str.c_str(), |
2845 | __idx, __base); } |
2846 | |
2847 | |
2848 | inline float |
2849 | stof(const string& __str, size_t* __idx = 0) |
2850 | { return __gnu_cxx::__stoa(&std::strtof, "stof", __str.c_str(), __idx); } |
2851 | |
2852 | inline double |
2853 | stod(const string& __str, size_t* __idx = 0) |
2854 | { return __gnu_cxx::__stoa(&std::strtod, "stod", __str.c_str(), __idx); } |
2855 | |
2856 | inline long double |
2857 | stold(const string& __str, size_t* __idx = 0) |
2858 | { return __gnu_cxx::__stoa(&std::strtold, "stold", __str.c_str(), __idx); } |
2859 | |
2860 | |
2861 | |
2862 | |
2863 | inline string |
2864 | to_string(int __val) |
2865 | { return __gnu_cxx::__to_xstring<string>(&std::vsnprintf, 4 * sizeof(int), |
2866 | "%d", __val); } |
2867 | |
2868 | inline string |
2869 | to_string(unsigned __val) |
2870 | { return __gnu_cxx::__to_xstring<string>(&std::vsnprintf, |
2871 | 4 * sizeof(unsigned), |
2872 | "%u", __val); } |
2873 | |
2874 | inline string |
2875 | to_string(long __val) |
2876 | { return __gnu_cxx::__to_xstring<string>(&std::vsnprintf, 4 * sizeof(long), |
2877 | "%ld", __val); } |
2878 | |
2879 | inline string |
2880 | to_string(unsigned long __val) |
2881 | { return __gnu_cxx::__to_xstring<string>(&std::vsnprintf, |
2882 | 4 * sizeof(unsigned long), |
2883 | "%lu", __val); } |
2884 | |
2885 | inline string |
2886 | to_string(long long __val) |
2887 | { return __gnu_cxx::__to_xstring<string>(&std::vsnprintf, |
2888 | 4 * sizeof(long long), |
2889 | "%lld", __val); } |
2890 | |
2891 | inline string |
2892 | to_string(unsigned long long __val) |
2893 | { return __gnu_cxx::__to_xstring<string>(&std::vsnprintf, |
2894 | 4 * sizeof(unsigned long long), |
2895 | "%llu", __val); } |
2896 | |
2897 | inline string |
2898 | to_string(float __val) |
2899 | { |
2900 | const int __n = |
2901 | __gnu_cxx::__numeric_traits<float>::__max_exponent10 + 20; |
2902 | return __gnu_cxx::__to_xstring<string>(&std::vsnprintf, __n, |
2903 | "%f", __val); |
2904 | } |
2905 | |
2906 | inline string |
2907 | to_string(double __val) |
2908 | { |
2909 | const int __n = |
2910 | __gnu_cxx::__numeric_traits<double>::__max_exponent10 + 20; |
2911 | return __gnu_cxx::__to_xstring<string>(&std::vsnprintf, __n, |
2912 | "%f", __val); |
2913 | } |
2914 | |
2915 | inline string |
2916 | to_string(long double __val) |
2917 | { |
2918 | const int __n = |
2919 | __gnu_cxx::__numeric_traits<long double>::__max_exponent10 + 20; |
2920 | return __gnu_cxx::__to_xstring<string>(&std::vsnprintf, __n, |
2921 | "%Lf", __val); |
2922 | } |
2923 | |
2924 | #ifdef _GLIBCXX_USE_WCHAR_T |
2925 | inline int |
2926 | stoi(const wstring& __str, size_t* __idx = 0, int __base = 10) |
2927 | { return __gnu_cxx::__stoa<long, int>(&std::wcstol, "stoi", __str.c_str(), |
2928 | __idx, __base); } |
2929 | |
2930 | inline long |
2931 | stol(const wstring& __str, size_t* __idx = 0, int __base = 10) |
2932 | { return __gnu_cxx::__stoa(&std::wcstol, "stol", __str.c_str(), |
2933 | __idx, __base); } |
2934 | |
2935 | inline unsigned long |
2936 | stoul(const wstring& __str, size_t* __idx = 0, int __base = 10) |
2937 | { return __gnu_cxx::__stoa(&std::wcstoul, "stoul", __str.c_str(), |
2938 | __idx, __base); } |
2939 | |
2940 | inline long long |
2941 | stoll(const wstring& __str, size_t* __idx = 0, int __base = 10) |
2942 | { return __gnu_cxx::__stoa(&std::wcstoll, "stoll", __str.c_str(), |
2943 | __idx, __base); } |
2944 | |
2945 | inline unsigned long long |
2946 | stoull(const wstring& __str, size_t* __idx = 0, int __base = 10) |
2947 | { return __gnu_cxx::__stoa(&std::wcstoull, "stoull", __str.c_str(), |
2948 | __idx, __base); } |
2949 | |
2950 | |
2951 | inline float |
2952 | stof(const wstring& __str, size_t* __idx = 0) |
2953 | { return __gnu_cxx::__stoa(&std::wcstof, "stof", __str.c_str(), __idx); } |
2954 | |
2955 | inline double |
2956 | stod(const wstring& __str, size_t* __idx = 0) |
2957 | { return __gnu_cxx::__stoa(&std::wcstod, "stod", __str.c_str(), __idx); } |
2958 | |
2959 | inline long double |
2960 | stold(const wstring& __str, size_t* __idx = 0) |
2961 | { return __gnu_cxx::__stoa(&std::wcstold, "stold", __str.c_str(), __idx); } |
2962 | |
2963 | |
2964 | inline wstring |
2965 | to_wstring(int __val) |
2966 | { return __gnu_cxx::__to_xstring<wstring>(&std::vswprintf, 4 * sizeof(int), |
2967 | L"%d", __val); } |
2968 | |
2969 | inline wstring |
2970 | to_wstring(unsigned __val) |
2971 | { return __gnu_cxx::__to_xstring<wstring>(&std::vswprintf, |
2972 | 4 * sizeof(unsigned), |
2973 | L"%u", __val); } |
2974 | |
2975 | inline wstring |
2976 | to_wstring(long __val) |
2977 | { return __gnu_cxx::__to_xstring<wstring>(&std::vswprintf, 4 * sizeof(long), |
2978 | L"%ld", __val); } |
2979 | |
2980 | inline wstring |
2981 | to_wstring(unsigned long __val) |
2982 | { return __gnu_cxx::__to_xstring<wstring>(&std::vswprintf, |
2983 | 4 * sizeof(unsigned long), |
2984 | L"%lu", __val); } |
2985 | |
2986 | inline wstring |
2987 | to_wstring(long long __val) |
2988 | { return __gnu_cxx::__to_xstring<wstring>(&std::vswprintf, |
2989 | 4 * sizeof(long long), |
2990 | L"%lld", __val); } |
2991 | |
2992 | inline wstring |
2993 | to_wstring(unsigned long long __val) |
2994 | { return __gnu_cxx::__to_xstring<wstring>(&std::vswprintf, |
2995 | 4 * sizeof(unsigned long long), |
2996 | L"%llu", __val); } |
2997 | |
2998 | inline wstring |
2999 | to_wstring(float __val) |
3000 | { |
3001 | const int __n = |
3002 | __gnu_cxx::__numeric_traits<float>::__max_exponent10 + 20; |
3003 | return __gnu_cxx::__to_xstring<wstring>(&std::vswprintf, __n, |
3004 | L"%f", __val); |
3005 | } |
3006 | |
3007 | inline wstring |
3008 | to_wstring(double __val) |
3009 | { |
3010 | const int __n = |
3011 | __gnu_cxx::__numeric_traits<double>::__max_exponent10 + 20; |
3012 | return __gnu_cxx::__to_xstring<wstring>(&std::vswprintf, __n, |
3013 | L"%f", __val); |
3014 | } |
3015 | |
3016 | inline wstring |
3017 | to_wstring(long double __val) |
3018 | { |
3019 | const int __n = |
3020 | __gnu_cxx::__numeric_traits<long double>::__max_exponent10 + 20; |
3021 | return __gnu_cxx::__to_xstring<wstring>(&std::vswprintf, __n, |
3022 | L"%Lf", __val); |
3023 | } |
3024 | #endif |
3025 | |
3026 | _GLIBCXX_END_NAMESPACE_VERSION |
3027 | } |
3028 | |
3029 | #endif /* C++11 && _GLIBCXX_USE_C99 ... */ |
3030 | |
3031 | #if __cplusplus >= 201103L |
3032 | |
3033 | #include <bits/functional_hash.h> |
3034 | |
3035 | namespace std _GLIBCXX_VISIBILITY(default) |
3036 | { |
3037 | _GLIBCXX_BEGIN_NAMESPACE_VERSION |
3038 | |
3039 | |
3040 | |
3041 | #ifndef _GLIBCXX_COMPATIBILITY_CXX0X |
3042 | |
3043 | template<> |
3044 | struct hash<string> |
3045 | : public __hash_base<size_t, string> |
3046 | { |
3047 | size_t |
3048 | operator()(const string& __s) const noexcept |
3049 | { return std::_Hash_impl::hash(__s.data(), __s.length()); } |
3050 | }; |
3051 | |
3052 | template<> |
3053 | struct __is_fast_hash<hash<string>> : std::false_type |
3054 | { }; |
3055 | |
3056 | #ifdef _GLIBCXX_USE_WCHAR_T |
3057 | |
3058 | template<> |
3059 | struct hash<wstring> |
3060 | : public __hash_base<size_t, wstring> |
3061 | { |
3062 | size_t |
3063 | operator()(const wstring& __s) const noexcept |
3064 | { return std::_Hash_impl::hash(__s.data(), |
3065 | __s.length() * sizeof(wchar_t)); } |
3066 | }; |
3067 | |
3068 | template<> |
3069 | struct __is_fast_hash<hash<wstring>> : std::false_type |
3070 | { }; |
3071 | #endif |
3072 | #endif /* _GLIBCXX_COMPATIBILITY_CXX0X */ |
3073 | |
3074 | #ifdef _GLIBCXX_USE_C99_STDINT_TR1 |
3075 | |
3076 | template<> |
3077 | struct hash<u16string> |
3078 | : public __hash_base<size_t, u16string> |
3079 | { |
3080 | size_t |
3081 | operator()(const u16string& __s) const noexcept |
3082 | { return std::_Hash_impl::hash(__s.data(), |
3083 | __s.length() * sizeof(char16_t)); } |
3084 | }; |
3085 | |
3086 | template<> |
3087 | struct __is_fast_hash<hash<u16string>> : std::false_type |
3088 | { }; |
3089 | |
3090 | |
3091 | template<> |
3092 | struct hash<u32string> |
3093 | : public __hash_base<size_t, u32string> |
3094 | { |
3095 | size_t |
3096 | operator()(const u32string& __s) const noexcept |
3097 | { return std::_Hash_impl::hash(__s.data(), |
3098 | __s.length() * sizeof(char32_t)); } |
3099 | }; |
3100 | |
3101 | template<> |
3102 | struct __is_fast_hash<hash<u32string>> : std::false_type |
3103 | { }; |
3104 | #endif |
3105 | |
3106 | _GLIBCXX_END_NAMESPACE_VERSION |
3107 | } |
3108 | |
3109 | #endif // C++11 |
3110 | |
3111 | #endif /* _BASIC_STRING_H */ |