ATLAS Offline Software
TouchedMuonChamberHelper.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 
7 // //
8 // Implementation of class TouchedMuonChamberHelper //
9 // //
10 // Author: Thomas H. Kittelmann (Thomas.Kittelmann@cern.ch) //
11 // Initial version: January 2008 //
12 // //
14 
16 #include <QTimer>
17 #include <map>
18 #include <set>
19 #include <iostream>
20 
21 //____________________________________________________________________
23 public:
25  bool updatesnotcheduled = false;//true if a timer has already been fired to check status after
26  inline void ensureScheduleUpdate();
27  std::set<GeoPVConstLink> lastEmittedSet;
28  std::map<GeoPVConstLink,unsigned> pv2count;//For keeping track of the number
29  //of shown objects's within a given
30  //chamber at any given time.
31  std::set<GeoPVConstLink> touchedByTracksSet; // Filled by signal emitted by TrackSystem
32 };
33 
34 
35 //____________________________________________________________________
37  : QObject(parent), m_d(new Imp)
38 {
39  m_d->theclass = this;
40  m_d->updatesnotcheduled = true;
41 }
42 
43 //____________________________________________________________________
45 {
46  delete m_d;
47 }
48 
49 //____________________________________________________________________
51 {
52  if (updatesnotcheduled) {
53  updatesnotcheduled = false;
54  QTimer::singleShot(0, theclass, SLOT(checkForChangeInTouchedChambers()));
55  }
56 }
57 
58 //____________________________________________________________________
59 void TouchedMuonChamberHelper::incrementNumberOfObjectsForPV(const GeoPVConstLink& chamberPV)
60 {
62  if (it==m_d->pv2count.end()) {
63  m_d->pv2count[chamberPV] = 1;
64  m_d->ensureScheduleUpdate();//First object in chamber
65  return;
66  }
67  ++(it->second);
68  if (m_d->updatesnotcheduled&&it->second==1)
69  m_d->ensureScheduleUpdate();//First object in chamber
70 }
71 
72 //____________________________________________________________________
73 void TouchedMuonChamberHelper::decrementNumberOfObjectsForPV(const GeoPVConstLink& chamberPV)
74 {
76  if (it==m_d->pv2count.end()||it->second==0) {
77  std::cout<<" TouchedMuonChamberHelper::decrementNumberOfObjectsForPV Error: Asked to decrement to negative values!"<<std::endl;
78  return;
79  }
80  --(it->second);
81  if (m_d->updatesnotcheduled&&it->second==0)
82  m_d->ensureScheduleUpdate();//Last object in chamber
83 }
84 
85 //____________________________________________________________________
86 bool TouchedMuonChamberHelper::isTouchedByTrack(const GeoPVConstLink& chamberPV)
87 {
88  return (m_d->touchedByTracksSet.find(chamberPV)!=m_d->touchedByTracksSet.end());
89 }
90 
91 //____________________________________________________________________
93 {
94  m_d->updatesnotcheduled = true;
95 
96  std::set<GeoPVConstLink> touchedchambers;
97  std::map<GeoPVConstLink,unsigned>::const_iterator it(m_d->pv2count.begin()),itE(m_d->pv2count.end());
98  for (;it!=itE;++it) {
99  if (it->second>0)
100  touchedchambers.insert(it->first);
101  }
102 
103  if (m_d->lastEmittedSet!=touchedchambers) {
104  m_d->lastEmittedSet = touchedchambers;
105  emit touchedMuonChambersChanged(touchedchambers);
106  }
107 }
108 
109 void TouchedMuonChamberHelper::updateTouchedByTracks(const std::set<GeoPVConstLink>& set){
110  // std::cout<<"TouchedMuonChamberHelper::updateTouchedByTracks - set is this big: "<<set.size()<<std::endl;
113 }
114 
115 //____________________________________________________________________
117 {
118  m_d->pv2count.clear();
119  m_d->touchedByTracksSet.clear();
121 }
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
TouchedMuonChamberHelper::updateTouchedByTracks
void updateTouchedByTracks(const std::set< GeoPVConstLink > &)
Definition: TouchedMuonChamberHelper.cxx:109
TouchedMuonChamberHelper::m_d
Imp * m_d
Definition: TouchedMuonChamberHelper.h:55
TouchedMuonChamberHelper::incrementNumberOfObjectsForPV
void incrementNumberOfObjectsForPV(const GeoPVConstLink &chamberPV)
Definition: TouchedMuonChamberHelper.cxx:59
TouchedMuonChamberHelper::Imp
Definition: TouchedMuonChamberHelper.cxx:22
CSV_InDetExporter.new
new
Definition: CSV_InDetExporter.py:145
skel.it
it
Definition: skel.GENtoEVGEN.py:396
TouchedMuonChamberHelper::Imp::updatesnotcheduled
bool updatesnotcheduled
Definition: TouchedMuonChamberHelper.cxx:25
TouchedMuonChamberHelper::touchedMuonChambersChanged
void touchedMuonChambersChanged(const std::set< GeoPVConstLink > &)
TouchedMuonChamberHelper
Definition: TouchedMuonChamberHelper.h:30
TruthTest.itE
itE
Definition: TruthTest.py:25
TouchedMuonChamberHelper::isTouchedByTrack
bool isTouchedByTrack(const GeoPVConstLink &chamberPV)
Returns true if the passed chamber link has a track or segment.
Definition: TouchedMuonChamberHelper.cxx:86
TouchedMuonChamberHelper::TouchedMuonChamberHelper
TouchedMuonChamberHelper(QObject *parent=0)
Definition: TouchedMuonChamberHelper.cxx:36
test_pyathena.parent
parent
Definition: test_pyathena.py:15
TouchedMuonChamberHelper::muonChambersTouchedByTracksChanged
void muonChambersTouchedByTracksChanged(void)
TouchedMuonChamberHelper::Imp::touchedByTracksSet
std::set< GeoPVConstLink > touchedByTracksSet
Definition: TouchedMuonChamberHelper.cxx:31
CxxUtils::set
constexpr std::enable_if_t< is_bitmask_v< E >, E & > set(E &lhs, E rhs)
Convenience function to set bits in a class enum bitmask.
Definition: bitmask.h:232
TouchedMuonChamberHelper::Imp::ensureScheduleUpdate
void ensureScheduleUpdate()
Definition: TouchedMuonChamberHelper.cxx:50
TouchedMuonChamberHelper::Imp::theclass
TouchedMuonChamberHelper * theclass
Definition: TouchedMuonChamberHelper.cxx:24
TouchedMuonChamberHelper::Imp::lastEmittedSet
std::set< GeoPVConstLink > lastEmittedSet
Definition: TouchedMuonChamberHelper.cxx:27
TouchedMuonChamberHelper::checkForChangeInTouchedChambers
void checkForChangeInTouchedChambers()
Definition: TouchedMuonChamberHelper.cxx:92
TouchedMuonChamberHelper::decrementNumberOfObjectsForPV
void decrementNumberOfObjectsForPV(const GeoPVConstLink &chamberPV)
Definition: TouchedMuonChamberHelper.cxx:73
TouchedMuonChamberHelper::Imp::pv2count
std::map< GeoPVConstLink, unsigned > pv2count
Definition: TouchedMuonChamberHelper.cxx:28
TouchedMuonChamberHelper::eraseEventData
void eraseEventData()
Definition: TouchedMuonChamberHelper.cxx:116
TouchedMuonChamberHelper.h
TouchedMuonChamberHelper::~TouchedMuonChamberHelper
virtual ~TouchedMuonChamberHelper()
Definition: TouchedMuonChamberHelper.cxx:44