ATLAS Offline Software
TimedHitCollection.icc
Go to the documentation of this file.
1 /* -*- C++ -*- */
2 
3 /*
4  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
5 */
6 
7 #include <algorithm>
8 #include <exception>
9 template <class HIT>
10 void
11 TimedHitCollection<HIT>::insert(const PileUpTimeEventIndex& timeEventIndex,
12  const AtlasHitsVector<HIT>* inputCollection) {
13  if (!inputCollection){
14  throw("Empty input collection!");
15  }
16  typename AtlasHitsVector<HIT>::const_iterator i(inputCollection->begin());
17  typename AtlasHitsVector<HIT>::const_iterator e(inputCollection->end());
18  while (i!=e) m_hits.push_back(TimedHitPtr<HIT>(timeEventIndex.time(), timeEventIndex.index(), &(*i++), timeEventIndex.type() ));
19  if (m_sorted) {
20  m_sorted=false;
21  throw SortedException();
22  }
23 }
24 
25 template <class HIT>
26 void
27 TimedHitCollection<HIT>::insert(float evtTime,
28  const AtlasHitsVector<HIT>* inputCollection) {
29  if (!inputCollection){
30  throw("Empty input collection!");
31  }
32  typename AtlasHitsVector<HIT>::const_iterator i(inputCollection->begin());
33  typename AtlasHitsVector<HIT>::const_iterator e(inputCollection->end());
34  while (i!=e) m_hits.push_back(TimedHitPtr<HIT>(evtTime, &(*i++)));
35  if (m_sorted) {
36  m_sorted=false;
37  throw SortedException();
38  }
39 }
40 
41 template <class HIT>
42 void
43 TimedHitCollection<HIT>::reserve(unsigned int numberOfHits) {
44  m_hits.reserve(numberOfHits);
45  return;
46 }
47 
48 ///returns an iterator range with the hits of current detector element
49 template <class HIT>
50 bool
51 TimedHitCollection<HIT>::nextDetectorElement(const_iterator& b, const_iterator& e) {
52  if (!m_sorted) sortVector();
53  b = m_currentHit;
54  while (m_currentHit != m_hits.end() && !(*b < *m_currentHit)) ++m_currentHit;
55  e = m_currentHit;
56  return (b != e);
57 }
58 
59 template <class HIT>
60 void
61 TimedHitCollection<HIT>::sortVector() {
62  std::stable_sort(m_hits.begin(), m_hits.end());
63  m_currentHit = m_hits.begin();
64  m_sorted=true;
65 }