File tree Expand file tree Collapse file tree
include/SimulationDataFormat Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -283,6 +283,28 @@ class MCTruthContainer
283283 }
284284 }
285285
286+ // merge part of another container ("n" entries starting from "from") to the back of this one
287+ void mergeAtBack (MCTruthContainer<TruthElement> const & other, size_t from, size_t n)
288+ {
289+ const auto oldtruthsize = mTruthArray .size ();
290+ const auto oldheadersize = mHeaderArray .size ();
291+ auto endIdx = from + n;
292+ assert (endIdx <= other.mHeaderArray .size ());
293+ const auto * headBeg = &other.mHeaderArray [from];
294+ const auto * headEnd = headBeg + n;
295+ const auto * trtArrBeg = &other.mTruthArray [other.getMCTruthHeader (from).index ];
296+ const auto * trtArrEnd = (endIdx == other.mHeaderArray .size ()) ? (&other.mTruthArray .back ()) + 1 : &other.mTruthArray [other.getMCTruthHeader (endIdx).index ];
297+
298+ // copy from other
299+ std::copy (headBeg, headEnd, std::back_inserter (mHeaderArray ));
300+ std::copy (trtArrBeg, trtArrEnd, std::back_inserter (mTruthArray ));
301+ long offset = long (oldtruthsize) - other.getMCTruthHeader (from).index ;
302+ // adjust information of newly attached part
303+ for (uint32_t i = oldheadersize; i < mHeaderArray .size (); ++i) {
304+ mHeaderArray [i].index += offset;
305+ }
306+ }
307+
286308 // / Flatten the internal arrays to the provided container
287309 // / Copies the content of the two vectors of PODs to a contiguous container.
288310 // / The flattened data starts with a specific header @ref FlatHeader describing
Original file line number Diff line number Diff line change @@ -95,13 +95,22 @@ BOOST_AUTO_TEST_CASE(MCTruth)
9595 container2.addElement (1 , TruthElement (1 ));
9696 container2.addElement (2 , TruthElement (10 ));
9797
98+ dataformats::MCTruthContainer<TruthElement> containerA;
99+
98100 container1.mergeAtBack (container2);
101+
102+ containerA.mergeAtBack (container1, 0 , 2 );
103+ containerA.mergeAtBack (container1, 2 , 2 );
104+
99105 auto lview = container1.getLabels (3 ); //
106+ auto lviewA = containerA.getLabels (3 );
100107 BOOST_CHECK (lview.size () == 2 );
101108 BOOST_CHECK (lview[0 ] == 11 );
102109 BOOST_CHECK (lview[1 ] == 12 );
103110 BOOST_CHECK (container1.getIndexedSize () == 6 );
104111 BOOST_CHECK (container1.getNElements () == 8 );
112+ BOOST_CHECK (lview.size () == lviewA.size ());
113+ BOOST_CHECK (lview[0 ] == lviewA[0 ] && lview[1 ] == lviewA[1 ]);
105114 }
106115}
107116
You can’t perform that action at this time.
0 commit comments