ATLAS Offline Software
Loading...
Searching...
No Matches
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//____________________________________________________________________
23public:
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//____________________________________________________________________
48
49//____________________________________________________________________
51{
53 updatesnotcheduled = false;
54 QTimer::singleShot(0, theclass, SLOT(checkForChangeInTouchedChambers()));
55 }
56}
57
58//____________________________________________________________________
60{
61 std::map<GeoPVConstLink,unsigned>::iterator it(m_d->pv2count.find(chamberPV));
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//____________________________________________________________________
74{
75 std::map<GeoPVConstLink,unsigned>::iterator it(m_d->pv2count.find(chamberPV));
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//____________________________________________________________________
86bool 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
109void TouchedMuonChamberHelper::updateTouchedByTracks(const std::set<GeoPVConstLink>& set){
110 // std::cout<<"TouchedMuonChamberHelper::updateTouchedByTracks - set is this big: "<<set.size()<<std::endl;
111 m_d->touchedByTracksSet=set;
113}
114
115//____________________________________________________________________
117{
118 m_d->pv2count.clear();
119 m_d->touchedByTracksSet.clear();
121}
std::set< GeoPVConstLink > lastEmittedSet
std::set< GeoPVConstLink > touchedByTracksSet
std::map< GeoPVConstLink, unsigned > pv2count
TouchedMuonChamberHelper(QObject *parent=0)
void muonChambersTouchedByTracksChanged(void)
bool isTouchedByTrack(const GeoPVConstLink &chamberPV)
Returns true if the passed chamber link has a track or segment.
void decrementNumberOfObjectsForPV(const GeoPVConstLink &chamberPV)
void incrementNumberOfObjectsForPV(const GeoPVConstLink &chamberPV)
void updateTouchedByTracks(const std::set< GeoPVConstLink > &)
void touchedMuonChambersChanged(const std::set< GeoPVConstLink > &)
STL class.