Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-06 08:18:10

0001 /**
0002  * @file trackbase/RawHitSetContainerv1.cc
0003  * @author D. McGlinchey, H. PEREIRA DA COSTA
0004  * @date June 2018
0005  * @brief Implementation for RawHitSetContainerv1
0006  */
0007 #include "RawHitSetContainerv1.h"
0008 
0009 #include "RawHitSetv1.h"
0010 #include "TrkrDefs.h"
0011 
0012 #include <cstdlib>
0013 
0014 void RawHitSetContainerv1::Reset()
0015 {
0016   for (const auto& pair : m_hitmap)
0017   {
0018     delete pair.second;
0019   }
0020 
0021   m_hitmap.clear();
0022 }
0023 
0024 void RawHitSetContainerv1::identify(std::ostream& os) const
0025 {
0026   ConstIterator iter;
0027   os << "Number of hits: " << size() << std::endl;
0028   for (const auto& pair : m_hitmap)
0029   {
0030     int layer = TrkrDefs::getLayer(pair.first);
0031     os << "hitsetkey " << pair.first << " layer " << layer << std::endl;
0032     pair.second->identify();
0033   }
0034   return;
0035 }
0036 
0037 RawHitSetContainerv1::ConstIterator
0038 RawHitSetContainerv1::addHitSet(RawHitSet* newhit)
0039 {
0040   return addHitSetSpecifyKey(newhit->getHitSetKey(), newhit);
0041 }
0042 
0043 RawHitSetContainerv1::ConstIterator
0044 RawHitSetContainerv1::addHitSetSpecifyKey(const TrkrDefs::hitsetkey key, RawHitSet* newhit)
0045 {
0046   const auto ret = m_hitmap.insert(std::make_pair(key, newhit));
0047   if (!ret.second)
0048   {
0049     std::cout << "RawHitSetContainerv1::AddHitSpecifyKey: duplicate key: " << key << " exiting now" << std::endl;
0050     exit(1);
0051   }
0052   else
0053   {
0054     return ret.first;
0055   }
0056 }
0057 
0058 void RawHitSetContainerv1::removeHitSet(TrkrDefs::hitsetkey key)
0059 {
0060   m_hitmap.erase(key);
0061 }
0062 
0063 void RawHitSetContainerv1::removeHitSet(RawHitSet* hitset)
0064 {
0065   removeHitSet(hitset->getHitSetKey());
0066 }
0067 
0068 RawHitSetContainerv1::ConstRange
0069 RawHitSetContainerv1::getHitSets(const TrkrDefs::TrkrId trackerid) const
0070 {
0071   const TrkrDefs::hitsetkey keylo = TrkrDefs::getHitSetKeyLo(trackerid);
0072   const TrkrDefs::hitsetkey keyhi = TrkrDefs::getHitSetKeyHi(trackerid);
0073   return std::make_pair(m_hitmap.lower_bound(keylo), m_hitmap.upper_bound(keyhi));
0074 }
0075 
0076 RawHitSetContainerv1::ConstRange
0077 RawHitSetContainerv1::getHitSets(const TrkrDefs::TrkrId trackerid, const uint8_t layer) const
0078 {
0079   TrkrDefs::hitsetkey keylo = TrkrDefs::getHitSetKeyLo(trackerid, layer);
0080   TrkrDefs::hitsetkey keyhi = TrkrDefs::getHitSetKeyHi(trackerid, layer);
0081   return std::make_pair(m_hitmap.lower_bound(keylo), m_hitmap.upper_bound(keyhi));
0082 }
0083 
0084 RawHitSetContainerv1::ConstRange
0085 RawHitSetContainerv1::getHitSets() const
0086 {
0087   return std::make_pair(m_hitmap.cbegin(), m_hitmap.cend());
0088 }
0089 
0090 RawHitSetContainerv1::Iterator
0091 RawHitSetContainerv1::findOrAddHitSet(TrkrDefs::hitsetkey key)
0092 {
0093   auto it = m_hitmap.lower_bound(key);
0094   if (it == m_hitmap.end() || (key < it->first))
0095   {
0096     it = m_hitmap.insert(it, std::make_pair(key, new RawHitSetv1));
0097     it->second->setHitSetKey(key);
0098   }
0099   return it;
0100 }
0101 
0102 RawHitSet*
0103 RawHitSetContainerv1::findHitSet(TrkrDefs::hitsetkey key)
0104 {
0105   auto it = m_hitmap.find(key);
0106   if (it != m_hitmap.end())
0107   {
0108     return it->second;
0109   }
0110   else
0111   {
0112     return nullptr;
0113   }
0114 }