ATLAS Offline Software
Loading...
Searching...
No Matches
VP1AvailableToolsHelper.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 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//____________________________________________________________________
26public:
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) {
38 std::map<QString,QStringList>::iterator it = monitoredTypeToIgnoreList.find(type);
39 if (it!=monitoredTypeToIgnoreList.end())
41 }
42 QStringList availableTools;
43
45 QList<QComboBox*> handledComboBoxes;
46 QList<QWidget*> handledWidgets;
47
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//____________________________________________________________________
94
95//____________________________________________________________________
97{
98 m_d->restartTimer(0);
99}
100
101//____________________________________________________________________
102void 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//____________________________________________________________________
112void VP1AvailableToolsHelper::addMonitoredTypes(const QStringList& mts, const QStringList& ignoreList)
113{
114 bool added(false);
115 for (const 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 (const 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();
156 m_d->monitoredTypeToIgnoreList.clear();
158 }
159}
160
161//____________________________________________________________________
163{
164 return m_d->monitoredTypes;
165}
166
167//____________________________________________________________________
169{
170 QStringList l;
171 if (toolsvc) {
172 for ( const 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 (const 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())+")");
233 availableToolsChanged(m_d->availableTools);
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//____________________________________________________________________
308void VP1AvailableToolsHelper::timerEvent ( QTimerEvent * event )
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}
std::map< std::string, double > instance
std::map< QString, QStringList > monitoredTypeToIgnoreList
void removeIgnoreList(const QString &type)
QStringList ignoreList(const QString &type)
VP1AvailableToolsHelper(IToolSvc *, QObject *parent=0)
void addMonitoredTypes(const QStringList &, const QStringList &ignoreList=QStringList())
void addMonitoredType(const QString &, const QStringList &ignoreList=QStringList())
void removeMonitoredTypes(const QStringList &)
const QStringList & monitoredTypes() const
void removeMonitoredType(const QString &)
void timerEvent(QTimerEvent *event)
void clearMonitoredTypes(const QString &)
void availableToolsChanged(const QStringList &) const
VP1HelperClassBase(IVP1System *sys=0, QString helpername="")
void messageVerbose(const QString &) const
void message(const QString &) const
void messageDebug(const QString &) const
static bool verbose()
Definition VP1Msg.h:31
int ts
Definition globals.cxx:24