ATLAS Offline Software
VP1AvailableToolsHelper.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 
7 // //
8 // Implementation of class VP1AvailableToolsHelper //
9 // //
10 // Author: Thomas H. Kittelmann (Thomas.Kittelmann@cern.ch) //
11 // Initial version: February 2008 //
12 // //
14 
16 #include "VP1Base/IVP1System.h"
17 #include "VP1Base/VP1Msg.h"
18 
19 #include "GaudiKernel/IToolSvc.h"
20 #include <QComboBox>
21 #include <QTimerEvent>
22 #include <map>
23 
24 //____________________________________________________________________
26 public:
27  Imp() : theclass(0), toolsvc(0), timerid(0), updateinterval(5000), silent(false) {}
29  IToolSvc* toolsvc;
30 
31  QStringList monitoredTypes;
32  std::map<QString,QStringList> monitoredTypeToIgnoreList;
33  QStringList ignoreList(const QString& type) {
34  std::map<QString,QStringList>::const_iterator it = monitoredTypeToIgnoreList.find(type);
35  return it==monitoredTypeToIgnoreList.end() ? QStringList() : it->second;
36  }
37  void removeIgnoreList(const QString& type) {
39  if (it!=monitoredTypeToIgnoreList.end())
41  }
42  QStringList availableTools;
43 
44  QStringList actualCurrentlyAvailableTools();
45  QList<QComboBox*> handledComboBoxes;
46  QList<QWidget*> handledWidgets;
47 
48  int timerid;
49  void killTimer()
50  {
51  if (timerid)
52  theclass->killTimer(timerid);
53  }
54  void restartTimer(int time)
55  {
56  killTimer();
57  timerid = theclass->startTimer(time);
58  }
59  const int updateinterval;
60  bool silent;
61 };
62 
63 
64 //____________________________________________________________________
66  : QObject(parent), VP1HelperClassBase(0,"VP1AvailableToolsHelper"), m_d(new Imp)
67 {
68  m_d->theclass = this;
69  m_d->toolsvc = ts;
70  if (!m_d->toolsvc)
71  message("ERROR - received NULL ToolSvc Pointer");
72 
73  //Should go away in future gaudi versions:
74  m_d->restartTimer(0);
75 }
76 
77 //____________________________________________________________________
79  : QObject(parent), VP1HelperClassBase(sys,"VP1AvailableToolsHelper"), m_d(new Imp)
80 {
81  m_d->theclass = this;
82  m_d->toolsvc = sys ? sys->toolSvc() : 0;
83  if (!sys)
84  message("ERROR - received NULL system Pointer");
85  if (!m_d->toolsvc)
86  message("ERROR - could not get ToolSvc Pointer");
87 }
88 
89 //____________________________________________________________________
91 {
92  delete m_d;
93 }
94 
95 //____________________________________________________________________
97 {
98  m_d->restartTimer(0);
99 }
100 
101 //____________________________________________________________________
102 void VP1AvailableToolsHelper::addMonitoredType(const QString& mt, const QStringList& ignoreList)
103 {
104  m_d->monitoredTypeToIgnoreList[mt] = ignoreList;
105  if (!m_d->monitoredTypes.contains(mt)) {
106  m_d->monitoredTypes << mt;
108  }
109 }
110 
111 //____________________________________________________________________
112 void VP1AvailableToolsHelper::addMonitoredTypes(const QStringList& mts, const QStringList& ignoreList)
113 {
114  bool added(false);
115  for (QString mt : mts) {
116  m_d->monitoredTypeToIgnoreList[mt] = ignoreList;
117  if (!m_d->monitoredTypes.contains(mt)) {
118  m_d->monitoredTypes << mt;
119  added=true;
120  }
121  }
122  if (added)
124 }
125 
126 //____________________________________________________________________
128 {
129  if (m_d->monitoredTypes.contains(mt)) {
130  m_d->monitoredTypes.removeAll(mt);
131  m_d->removeIgnoreList(mt);
133  }
134 }
135 
136 //____________________________________________________________________
138 {
139  bool removed(false);
140  for (QString mt : mts) {
141  if (m_d->monitoredTypes.contains(mt)) {
142  m_d->monitoredTypes.removeAll(mt);
143  m_d->removeIgnoreList(mt);
144  removed = true;
145  }
146  }
147  if (removed)
149 }
150 
151 //____________________________________________________________________
153 {
154  if (m_d->monitoredTypes.count()>0) {
155  m_d->monitoredTypes.clear();
158  }
159 }
160 
161 //____________________________________________________________________
163 {
164  return m_d->monitoredTypes;
165 }
166 
167 //____________________________________________________________________
169 {
170  QStringList l;
171  if (toolsvc) {
172  for ( QString tooltype : monitoredTypes ) {
173  std::vector<std::string> instances;
174  instances = toolsvc->getInstances( tooltype.toStdString() );
175  if (!silent&&VP1Msg::verbose())
176  theclass->messageVerbose("Used toolsvc->getInstances(..) to find "+QString::number(instances.size())+" public tools of type "+tooltype );
177  for (unsigned i = 0; i < instances.size(); ++i ) {
178  QString instance(instances.at(i).c_str());
179  if (instance.startsWith("ToolSvc.",Qt::CaseInsensitive))
180  instance.remove(0,8);
181  //Check if we ignore this one:
182  QStringList ignorelist = ignoreList(tooltype);
183  if (!ignorelist.isEmpty()) {
184  bool ignore(false);
185  for (QString ignorepattern : ignorelist) {
186  if (QRegExp(ignorepattern,Qt::CaseSensitive,QRegExp::Wildcard).exactMatch(instance)) {
187  ignore = true;
188  break;
189  }
190  }
191  if (ignore) {
192  if (!silent&&VP1Msg::verbose())
193  theclass->messageVerbose(" --> Found but ignoring "+instance );
194  continue;
195  }
196  }
197  if (!silent&&VP1Msg::verbose())
198  theclass->messageVerbose(" --> Found "+instance );
199  l << tooltype+"/"+instance;
200  if (!silent&&VP1Msg::verbose())
201  theclass->messageVerbose(" --> Appended "+tooltype+"/"+instance+" to list" );
202  }
203  }
204  l.sort();
205  }
206  return l;
207 }
208 
209 //____________________________________________________________________
211 {
212  QStringList newtools = m_d->actualCurrentlyAvailableTools();
213  if ( newtools == m_d->availableTools ) {
214  m_d->restartTimer(2000);
215  return;
216  }
217  messageVerbose("update() found changes in tool list!");
218  m_d->availableTools = newtools;
219  bool notempty = ! m_d->availableTools.empty();
220 
221  if (notempty) {
222  for (QComboBox* cb : m_d->handledComboBoxes) {
223  cb->clear();
224  cb->addItems(m_d->availableTools);
225  }
226  }
227  for (QWidget* w : m_d->handledWidgets) {
228  if (w->isEnabled() != notempty)
229  w->setEnabled(notempty);
230  }
231 
232  messageDebug("Emitting availableToolsChanged (ntools="+QString::number(m_d->availableTools.count())+")");
234 
235  m_d->restartTimer(2000);
236 }
237 
238 //____________________________________________________________________
240 {
241  update();
242  return m_d->availableTools;
243 }
244 
245 //____________________________________________________________________
247 {
248  messageVerbose("setComboBoxData");
249  if (!cb) {
250  message("setComboBoxData ERROR: Null pointer to combobox");
251  return;
252  }
253  cb->clear();
254  cb->addItems(availableTools());
255 }
256 
257 //____________________________________________________________________
259 {
260  messageVerbose("disableIfNoTools");
261  if (!w) {
262  message("disableIfNoTools ERROR: Null pointer to widget");
263  return;
264  }
265  w->setEnabled(!availableTools().isEmpty());
266 }
267 
268 //____________________________________________________________________
270 {
271  messageVerbose("handleComboBox");
272  if (!cb) {
273  message("handleComboBox ERROR: Null pointer to combobox");
274  return;
275  }
276  if (!m_d->handledComboBoxes.contains(cb)) {
277  setComboBoxData(cb);
278  m_d->handledComboBoxes << cb;
279  connect(cb,SIGNAL(destroyed(QObject*)),this,SLOT(widgetDeleted(QObject*)));
280  }
281 }
282 
283 //____________________________________________________________________
285 {
286  messageVerbose("handleEnabledState");
287  if (!w) {
288  message("handleEnabledState ERROR: Null pointer to widget");
289  return;
290  }
291  if (!m_d->handledWidgets.contains(w)) {
293  m_d->handledWidgets << w;
294  connect(w,SIGNAL(destroyed(QObject*)),this,SLOT(widgetDeleted(QObject*)));
295  }
296 }
297 
298 //____________________________________________________________________
300 {
301  if ( o->inherits("QComboBox") && m_d->handledComboBoxes.contains(static_cast<QComboBox*>(o)))
302  m_d->handledComboBoxes.removeAll(static_cast<QComboBox*>(o));
303  if ( o->isWidgetType() && m_d->handledWidgets.contains(static_cast<QWidget*>(o)))
304  m_d->handledWidgets.removeAll(static_cast<QWidget*>(o));
305 }
306 
307 //____________________________________________________________________
309 {
310  event->accept();
311  if (event->timerId()!=m_d->timerid) {
312  message("ERROR: Bad timer ID!!");
313  killTimer(event->timerId());
314  }
315  m_d->silent = true;
316  update();
317  m_d->silent = false;
318  m_d->restartTimer(3000);
319 }
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
VP1AvailableToolsHelper::removeMonitoredTypes
void removeMonitoredTypes(const QStringList &)
Definition: VP1AvailableToolsHelper.cxx:137
VP1AvailableToolsHelper::monitoredTypes
QStringList monitoredTypes() const
Definition: VP1AvailableToolsHelper.cxx:162
VP1AvailableToolsHelper.h
VP1AvailableToolsHelper::addMonitoredType
void addMonitoredType(const QString &, const QStringList &ignoreList=QStringList())
Definition: VP1AvailableToolsHelper.cxx:102
VP1AvailableToolsHelper::Imp::actualCurrentlyAvailableTools
QStringList actualCurrentlyAvailableTools()
Definition: VP1AvailableToolsHelper.cxx:168
VP1AvailableToolsHelper::Imp::Imp
Imp()
Definition: VP1AvailableToolsHelper.cxx:27
VP1Msg.h
VP1HelperClassBase::messageVerbose
void messageVerbose(const QString &) const
Definition: VP1HelperClassBase.cxx:78
VP1AvailableToolsHelper::m_d
Imp * m_d
Definition: VP1AvailableToolsHelper.h:71
fillPileUpNoiseLumi.connect
string connect
Definition: fillPileUpNoiseLumi.py:70
CSV_InDetExporter.new
new
Definition: CSV_InDetExporter.py:145
skel.it
it
Definition: skel.GENtoEVGEN.py:396
VP1AvailableToolsHelper::update
void update() const
Definition: VP1AvailableToolsHelper.cxx:210
UploadAMITag.l
list l
Definition: UploadAMITag.larcaf.py:158
VP1HelperClassBase::messageDebug
void messageDebug(const QString &) const
Definition: VP1HelperClassBase.cxx:65
mapkey::sys
@ sys
Definition: TElectronEfficiencyCorrectionTool.cxx:42
VP1AvailableToolsHelper::Imp::monitoredTypes
QStringList monitoredTypes
Definition: VP1AvailableToolsHelper.cxx:31
VP1AvailableToolsHelper::Imp::ignoreList
QStringList ignoreList(const QString &type)
Definition: VP1AvailableToolsHelper.cxx:33
VP1AvailableToolsHelper::handleComboBox
void handleComboBox(QComboBox *)
Definition: VP1AvailableToolsHelper.cxx:269
instance
std::map< std::string, double > instance
Definition: Run_To_Get_Tags.h:8
VP1AvailableToolsHelper::Imp::restartTimer
void restartTimer(int time)
Definition: VP1AvailableToolsHelper.cxx:54
VP1AvailableToolsHelper::VP1AvailableToolsHelper
VP1AvailableToolsHelper(IToolSvc *, QObject *parent=0)
Definition: VP1AvailableToolsHelper.cxx:65
DiTauMassTools::ignore
void ignore(T &&)
Definition: PhysicsAnalysis/TauID/DiTauMassTools/DiTauMassTools/HelperFunctions.h:58
VP1AvailableToolsHelper::Imp::availableTools
QStringList availableTools
Definition: VP1AvailableToolsHelper.cxx:42
VP1AvailableToolsHelper::scheduleImmediateUpdate
void scheduleImmediateUpdate() const
Definition: VP1AvailableToolsHelper.cxx:96
IVP1System
Definition: IVP1System.h:36
VP1AvailableToolsHelper::~VP1AvailableToolsHelper
virtual ~VP1AvailableToolsHelper()
Definition: VP1AvailableToolsHelper.cxx:90
VP1AvailableToolsHelper::Imp::silent
bool silent
Definition: VP1AvailableToolsHelper.cxx:60
event
POOL::TEvent event(POOL::TEvent::kClassAccess)
VP1AvailableToolsHelper::handleEnabledState
void handleEnabledState(QWidget *)
Definition: VP1AvailableToolsHelper.cxx:284
lumiFormat.i
int i
Definition: lumiFormat.py:85
VP1AvailableToolsHelper::addMonitoredTypes
void addMonitoredTypes(const QStringList &, const QStringList &ignoreList=QStringList())
Definition: VP1AvailableToolsHelper.cxx:112
VP1AvailableToolsHelper::Imp::timerid
int timerid
Definition: VP1AvailableToolsHelper.cxx:48
test_pyathena.parent
parent
Definition: test_pyathena.py:15
VP1AvailableToolsHelper::Imp::monitoredTypeToIgnoreList
std::map< QString, QStringList > monitoredTypeToIgnoreList
Definition: VP1AvailableToolsHelper.cxx:32
VP1AvailableToolsHelper::removeMonitoredType
void removeMonitoredType(const QString &)
Definition: VP1AvailableToolsHelper.cxx:127
VP1AvailableToolsHelper::Imp
Definition: VP1AvailableToolsHelper.cxx:25
VP1HelperClassBase
Definition: VP1HelperClassBase.h:28
VP1AvailableToolsHelper::setComboBoxData
void setComboBoxData(QComboBox *)
Definition: VP1AvailableToolsHelper.cxx:246
VP1AvailableToolsHelper::Imp::toolsvc
IToolSvc * toolsvc
Definition: VP1AvailableToolsHelper.cxx:29
VP1AvailableToolsHelper::Imp::removeIgnoreList
void removeIgnoreList(const QString &type)
Definition: VP1AvailableToolsHelper.cxx:37
VP1AvailableToolsHelper::timerEvent
void timerEvent(QTimerEvent *event)
Definition: VP1AvailableToolsHelper.cxx:308
python.selection.number
number
Definition: selection.py:20
VP1AvailableToolsHelper::Imp::killTimer
void killTimer()
Definition: VP1AvailableToolsHelper.cxx:49
VP1AvailableToolsHelper::Imp::handledComboBoxes
QList< QComboBox * > handledComboBoxes
Definition: VP1AvailableToolsHelper.cxx:45
CaloSwCorrections.time
def time(flags, cells_name, *args, **kw)
Definition: CaloSwCorrections.py:242
VP1AvailableToolsHelper::disableIfNoTools
void disableIfNoTools(QWidget *)
Definition: VP1AvailableToolsHelper.cxx:258
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
VP1AvailableToolsHelper::widgetDeleted
void widgetDeleted(QObject *)
Definition: VP1AvailableToolsHelper.cxx:299
VP1AvailableToolsHelper::availableToolsChanged
void availableToolsChanged(const QStringList &) const
VP1HelperClassBase::message
void message(const QString &) const
Definition: VP1HelperClassBase.cxx:49
VP1AvailableToolsHelper::clearMonitoredTypes
void clearMonitoredTypes(const QString &)
Definition: VP1AvailableToolsHelper.cxx:152
VP1AvailableToolsHelper::availableTools
QStringList availableTools() const
Definition: VP1AvailableToolsHelper.cxx:239
VP1Msg::verbose
static bool verbose()
Definition: VP1Msg.h:31
VP1AvailableToolsHelper::Imp::handledWidgets
QList< QWidget * > handledWidgets
Definition: VP1AvailableToolsHelper.cxx:46
VP1AvailableToolsHelper::Imp::theclass
VP1AvailableToolsHelper * theclass
Definition: VP1AvailableToolsHelper.cxx:28
VP1AvailableToolsHelper
Definition: VP1AvailableToolsHelper.h:30
python.IoTestsLib.w
def w
Definition: IoTestsLib.py:200
python.CaloScaleNoiseConfig.ts
ts
Definition: CaloScaleNoiseConfig.py:86
IVP1System.h
VP1AvailableToolsHelper::Imp::updateinterval
const int updateinterval
Definition: VP1AvailableToolsHelper.cxx:59