ATLAS Offline Software
TrackLODManager.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 
7 // //
8 // Implementation of class TrackLODManager //
9 // //
10 // Author: Thomas H. Kittelmann (Thomas.Kittelmann@cern.ch) //
11 // Initial version: March 2008 //
12 // //
14 
16 #include "VP1Base/VP1Msg.h"
18 #include <Inventor/nodes/SoLevelOfDetail.h>
19 #include <Inventor/nodes/SoSeparator.h>
20 #include <map>
21 
22 //____________________________________________________________________
24 public:
25  Imp() : attachnode(nullptr),
26  attachnode_lod(nullptr),
27  attachsep_simple(nullptr),
28  attachsep_detailed(nullptr),
29  attachHelper_simple(nullptr),
30  attachHelper_detailed(nullptr),
32  SoGroup * attachnode;
33  SoGroup * attachnode_lod;
34  SoSeparator * attachsep_simple;
35  SoSeparator * attachsep_detailed;
38  void ensureLODDetached() const;
39  void ensureSimpleDetached() const;
40  void ensureDetailedDetached() const;
42 
44  std::map<std::pair<int,double>,TrackLODHandle* > id_2_lodhandle;
45 };
46 
47 
48 //____________________________________________________________________
50  : QObject(parent), VP1HelperClassBase(sys,"TrackLODManager"), m_d(new Imp)
51 {
52 }
53 
54 //____________________________________________________________________
56 {
57  if (m_d->attachnode) {
58  messageDebug("WARNING: Destructed before event data cleared!");
60  }
61  delete m_d;
62 }
63 
64 //____________________________________________________________________
66 {
68  attachnode->removeChild(attachsep_detailed);
69 }
70 
71 //____________________________________________________________________
73 {
74  if ( attachnode && attachsep_simple && attachnode->findChild(attachsep_simple)>-1)
75  attachnode->removeChild(attachsep_simple);
76 }
77 
78 //____________________________________________________________________
80 {
81  if ( attachnode && attachnode_lod && attachnode->findChild(attachnode_lod)>-1)
82  attachnode->removeChild(attachnode_lod);
83 }
84 
85 //____________________________________________________________________
87 {
89  if ( attachnode && attachsep_simple && attachnode->findChild(attachsep_simple)<0)
90  attachnode->addChild(attachsep_simple);
91  } else {
92  ensureSimpleDetached();
93  }
94 
96  if ( attachnode && attachsep_detailed && attachnode->findChild(attachsep_detailed)<0)
97  attachnode->addChild(attachsep_detailed);
98  } else {
99  ensureDetailedDetached();
100  }
101 
102  if (dl == TrackCommonFlags::AUTO) {
103  if ( attachnode && attachnode_lod && attachnode->findChild(attachnode_lod)<0)
104  attachnode->addChild(attachnode_lod);
105  } else {
106  ensureLODDetached();
107  }
108 }
109 
110 //____________________________________________________________________
112 {
113  if (VP1Msg::verbose())
114  messageVerbose("signal received in setDetailLevel (old = "+TrackCommonFlags::toString(m_d->detailLevel)+", new = "+TrackCommonFlags::toString(dl));
115  if ( m_d->detailLevel == dl )
116  return;
117  m_d->detailLevel = dl;
119 }
120 
121 //____________________________________________________________________
123 {
124  if (!an) {
125  message("setAttachNode ERROR: Received null pointer!");
126  return;
127  }
128  if (m_d->attachnode) {
129  message("setAttachNode ERROR: Received new attachment group pointer while still having previous one!");
130  eraseEventData();
131  return;
132  }
133 
134  m_d->attachnode = an;
135  m_d->attachnode->ref();
136 
137  m_d->attachsep_simple = new SoSeparator;
138  m_d->attachsep_simple->ref();
139  m_d->attachsep_detailed = new SoSeparator;
140  m_d->attachsep_detailed->ref();
141  m_d->attachnode_lod = new SoGroup;
142  m_d->attachnode_lod->ref();
143 
146 
148 }
149 
150 //____________________________________________________________________
152 {
153  messageVerbose("eraseEventData start");
154  if (!m_d->attachnode) {
155  messageDebug("eraseEventData WARNING: - called before attachment node was set!");
156  return;
157  }
161 
162  std::map<std::pair<int,double>,TrackLODHandle* >::iterator it, itE(m_d->id_2_lodhandle.end());
163  for (it = m_d->id_2_lodhandle.begin(); it!=itE;++it) {
164  delete it->second;
165  }
166  m_d->id_2_lodhandle.clear();
167 
168  if (m_d->attachnode_lod) {
169  m_d->attachnode_lod->unref();
170  m_d->attachnode_lod = nullptr;
171  }
172 
173  if (m_d->attachsep_simple) {
174  delete m_d->attachHelper_simple;
175  m_d->attachHelper_simple = nullptr;
176  m_d->attachsep_simple->unref();
177  m_d->attachsep_simple = nullptr;
178  }
179 
180  if (m_d->attachsep_detailed) {
181  delete m_d->attachHelper_detailed;
182  m_d->attachHelper_detailed = nullptr;
183  m_d->attachsep_detailed->unref();
184  m_d->attachsep_detailed = nullptr;
185  }
186 
187  m_d->attachnode->unref();
188  m_d->attachnode = nullptr;
189  messageVerbose("eraseEventData end");
190 
191 }
192 
193 //____________________________________________________________________
194 TrackLODHandle * TrackLODManager::getLODHandle(int regionindex, const double& crossover_value)
195 {
196  std::map<std::pair<int,double>,TrackLODHandle* >::iterator it = m_d->id_2_lodhandle.find(std::make_pair(regionindex,crossover_value));
197  if (it!=m_d->id_2_lodhandle.end())
198  return it->second;
199  if (!m_d->attachnode) {
200  message("getTrackLODHandle ERROR: Called before attachment node was set!");
201  return nullptr;
202  }
204  m_d->id_2_lodhandle[std::make_pair(regionindex,crossover_value)] = lh;
205  return lh;
206 }
207 
208 
210 // TrackLODHandle implementation //
212 
213 
214 //____________________________________________________________________
216 public:
217  Imp( SoGroup* ag,
220  int i, const double& c)
221  : attachGroup_LOD(ag),
222  attachHelper_simple(shs),
223  attachHelper_detailed(shd),
224  regIdx(i),
225  crossVal(c),
226  lod(nullptr),
227  sep_detailed(nullptr),
228  sep_simple(nullptr) {}
229  SoGroup* attachGroup_LOD;
232  int regIdx;
233  double crossVal;
234  SoLevelOfDetail * lod;
235  SoSeparator * sep_detailed;
236  SoSeparator * sep_simple;
237  void updateCrossOverField() const
238  {
239  //Fixme: We should scale this with complexity! I.e. multiply the value with 1.0/(complexity+0.5)
240  // lod->screenArea.setValue(crossVal/sqrt(sep_detailed->getNumChildren()+1.0));
241  lod->screenArea.setValue(crossVal*sqrt(sep_detailed->getNumChildren())+0.1);
242  }
243 };
244 
245 
246 //____________________________________________________________________
247 TrackLODHandle::TrackLODHandle(SoGroup* attachgroup_LOD,
248  VP1ExtraSepLayerHelper * sephelper_simple,
249  VP1ExtraSepLayerHelper * sephelper_detailed,
250  int regionindex, const double& crossover_value)
251  : m_d(new Imp(attachgroup_LOD,sephelper_simple,sephelper_detailed,regionindex,crossover_value))
252 {
253 // if (VP1Msg::verbose())
254 // VP1Msg::messageVerbose("TrackLODHandle Constructed with regionIndex = "+QString::number(regionindex)
255 // +" and nominal crossover value = "+QString::number(crossover_value));
256  if (!attachgroup_LOD||!sephelper_simple||!sephelper_detailed)
257  VP1Msg::messageDebug("TrackLODHandle ERROR: Received null pointer!");
258 }
259 
260 //____________________________________________________________________
262 {
263  if (m_d->lod) {
264  if (m_d->attachGroup_LOD->findChild(m_d->lod)>-1) {
265  m_d->attachGroup_LOD->removeChild(m_d->lod);
268  }
269  m_d->lod->unref();
270  m_d->sep_detailed->unref();
271  m_d->sep_simple->unref();
272  }
273  delete m_d;
274 }
275 
276 //____________________________________________________________________
277 void TrackLODHandle::addNodes(SoGroup* simple,SoGroup*detailed )
278 {
279  if (!m_d->lod) {
280 // if (VP1Msg::verbose())
281 // VP1Msg::messageVerbose( "TrackLODHandle addNodes: Initialising nodes: LOD, sep_detailed and sep_simple.");
282  m_d->lod = new SoLevelOfDetail;
283  m_d->sep_detailed = new SoSeparator;
284  m_d->sep_simple = new SoSeparator;
285  m_d->lod->ref();
286  m_d->sep_detailed->ref();
287  m_d->sep_simple->ref();
288  m_d->lod->addChild(m_d->sep_detailed);
289  m_d->lod->addChild(m_d->sep_simple);
290  }
291 
292  if (VP1Msg::verbose()) {
293  //Extra sanity checks:
294  if (!detailed) {
295  VP1Msg::messageVerbose("TrackLODHandle ERROR: addNodes received null pointer for detailed node");
296  return;
297  }
298  if (!simple) {
299  VP1Msg::messageVerbose("TrackLODHandle ERROR: addNodes received null pointer for simple node");
300  return;
301  }
302  if (m_d->sep_detailed->findChild(detailed)>=0) {
303  VP1Msg::messageVerbose("TrackLODHandle ERROR: addNodes called for detailed node which is already added");
304  return;
305  }
306  if (m_d->sep_simple->findChild(simple)>=0) {
307  VP1Msg::messageVerbose("TrackLODHandle ERROR: addNodes called for simple node which is already added");
308  return;
309  }
310  }
311 
312  m_d->sep_detailed->addChild(detailed);
313  m_d->sep_simple->addChild(simple);
314 
315  if (m_d->sep_detailed->getNumChildren()==1) {
316  //We went from 0 to 1 children!
317  if (VP1Msg::verbose()&&m_d->attachGroup_LOD->findChild(m_d->lod)>=0)
318  VP1Msg::messageVerbose("TrackLODHandle ERROR: adding lod, but it is already a child!!");
319  m_d->attachGroup_LOD->addChild(m_d->lod);
322  }
324 }
325 
326 //____________________________________________________________________
327 void TrackLODHandle::removeNodes(SoGroup* simple,SoGroup*detailed )
328 {
329  if (!m_d->lod)
330  return;
331 
332  if (VP1Msg::verbose()) {
333  //Extra sanity checks:
334  if (!detailed) {
335  VP1Msg::messageVerbose("TrackLODHandle ERROR: removeNodes received null pointer for detailed node");
336  return;
337  }
338  if (!simple) {
339  VP1Msg::messageVerbose("TrackLODHandle ERROR: removeNodes received null pointer for simple node");
340  return;
341  }
342  if (m_d->sep_detailed->findChild(detailed)<0) {
343  VP1Msg::messageVerbose("TrackLODHandle ERROR: removeNodes called for detailed node which is not already added");
344  return;
345  }
346  if (m_d->sep_simple->findChild(simple)<0) {
347  VP1Msg::messageVerbose("TrackLODHandle ERROR: removeNodes called for simple node which is not already added");
348  return;
349  }
350  }
351  m_d->sep_detailed->removeChild(detailed);
352  m_d->sep_simple->removeChild(simple);
353 
354  if (m_d->sep_detailed->getNumChildren()<1) {
355  //We went from 1 to 0 children
356  if (VP1Msg::verbose()&&m_d->attachGroup_LOD->findChild(m_d->lod)<0)
357  VP1Msg::messageVerbose("TrackLODHandle ERROR: removing child, but node is not currently a child!!");
358  m_d->attachGroup_LOD->removeChild(m_d->lod);
361  } else {
363  }
364 }
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
TrackLODHandle::removeNodes
void removeNodes(SoGroup *simple, SoGroup *detailed)
Definition: TrackLODManager.cxx:327
TrackLODManager::Imp::attachHelper_simple
VP1ExtraSepLayerHelper * attachHelper_simple
Definition: TrackLODManager.cxx:36
TrackLODHandle::Imp::Imp
Imp(SoGroup *ag, VP1ExtraSepLayerHelper *shs, VP1ExtraSepLayerHelper *shd, int i, const double &c)
Definition: TrackLODManager.cxx:217
TrackLODManager::Imp::attachnode
SoGroup * attachnode
Definition: TrackLODManager.cxx:32
DiTauMassTools::TauTypes::lh
@ lh
Definition: PhysicsAnalysis/TauID/DiTauMassTools/DiTauMassTools/HelperFunctions.h:49
TestSUSYToolsAlg.dl
dl
Definition: TestSUSYToolsAlg.py:83
VP1ExtraSepLayerHelper::removeNode
void removeNode(SoNode *)
Definition: VP1ExtraSepLayerHelper.cxx:95
TrackLODManager::m_d
Imp * m_d
Definition: TrackLODManager.h:50
TrackCommonFlags::SIMPLE
@ SIMPLE
Definition: TrackCommonFlags.h:39
TrackLODManager::setDetailLevel
void setDetailLevel(TrackCommonFlags::DETAILLEVEL)
Definition: TrackLODManager.cxx:111
TrackLODHandle
Definition: TrackLODManager.h:56
TrackLODManager::Imp::updateAttachmentForDetailLevel
void updateAttachmentForDetailLevel(TrackCommonFlags::DETAILLEVEL) const
Definition: TrackLODManager.cxx:86
TrackLODManager::Imp::ensureSimpleDetached
void ensureSimpleDetached() const
Definition: TrackLODManager.cxx:72
TrackLODManager::Imp::ensureDetailedDetached
void ensureDetailedDetached() const
Definition: TrackLODManager.cxx:65
VP1ExtraSepLayerHelper.h
VP1Msg.h
VP1HelperClassBase::messageVerbose
void messageVerbose(const QString &) const
Definition: VP1HelperClassBase.cxx:78
TrackLODHandle::Imp
Definition: TrackLODManager.cxx:215
TrackCommonFlags::AUTO
@ AUTO
Definition: TrackCommonFlags.h:39
CSV_InDetExporter.new
new
Definition: CSV_InDetExporter.py:145
TrackCommonFlags
Definition: TrackCommonFlags.h:21
skel.it
it
Definition: skel.GENtoEVGEN.py:423
TrackLODManager.h
TrackLODHandle::Imp::sep_detailed
SoSeparator * sep_detailed
Definition: TrackLODManager.cxx:235
TrackLODHandle::Imp::lod
SoLevelOfDetail * lod
Definition: TrackLODManager.cxx:234
TrackLODHandle::Imp::crossVal
double crossVal
Definition: TrackLODManager.cxx:233
TrackLODHandle::Imp::attachHelper_detailed
VP1ExtraSepLayerHelper * attachHelper_detailed
Definition: TrackLODManager.cxx:231
VP1HelperClassBase::messageDebug
void messageDebug(const QString &) const
Definition: VP1HelperClassBase.cxx:65
TrackLODManager::Imp::attachHelper_detailed
VP1ExtraSepLayerHelper * attachHelper_detailed
Definition: TrackLODManager.cxx:37
mapkey::sys
@ sys
Definition: TElectronEfficiencyCorrectionTool.cxx:42
TruthTest.itE
itE
Definition: TruthTest.py:25
TrackLODHandle::Imp::regIdx
int regIdx
Definition: TrackLODManager.cxx:232
TrackLODManager::Imp::detailLevel
TrackCommonFlags::DETAILLEVEL detailLevel
Definition: TrackLODManager.cxx:43
TrackLODHandle::addNodes
void addNodes(SoGroup *simple, SoGroup *detailed)
Definition: TrackLODManager.cxx:277
IVP1System
Definition: IVP1System.h:36
TrackLODManager::Imp::ensureLODDetached
void ensureLODDetached() const
Definition: TrackLODManager.cxx:79
VP1ExtraSepLayerHelper
Definition: VP1ExtraSepLayerHelper.h:22
TrackLODHandle::Imp::updateCrossOverField
void updateCrossOverField() const
Definition: TrackLODManager.cxx:237
TrackCommonFlags::DETAILED
@ DETAILED
Definition: TrackCommonFlags.h:39
lumiFormat.i
int i
Definition: lumiFormat.py:92
TrackLODManager::TrackLODManager
TrackLODManager(QObject *parent=0, IVP1System *sys=0)
Definition: TrackLODManager.cxx:49
TrackLODManager::Imp
Definition: TrackLODManager.cxx:23
TrackLODHandle::~TrackLODHandle
~TrackLODHandle()
Definition: TrackLODManager.cxx:261
test_pyathena.parent
parent
Definition: test_pyathena.py:15
TrackLODManager::TrackLODHandle
friend class TrackLODHandle
Definition: TrackLODManager.h:52
VP1HelperClassBase
Definition: VP1HelperClassBase.h:28
TrackLODHandle::TrackLODHandle
TrackLODHandle(SoGroup *, VP1ExtraSepLayerHelper *, VP1ExtraSepLayerHelper *, int, const double &)
Definition: TrackLODManager.cxx:247
TrackLODManager::Imp::attachnode_lod
SoGroup * attachnode_lod
Definition: TrackLODManager.cxx:33
VP1Msg::messageVerbose
static void messageVerbose(const QString &)
Definition: VP1Msg.cxx:84
TrackLODManager::getLODHandle
TrackLODHandle * getLODHandle(int regionindex, const double &crossover_value)
Definition: TrackLODManager.cxx:194
TrackLODManager::Imp::Imp
Imp()
Definition: TrackLODManager.cxx:25
VP1ExtraSepLayerHelper::addNode
void addNode(SoNode *)
Definition: VP1ExtraSepLayerHelper.cxx:54
TrackLODManager::Imp::attachsep_detailed
SoSeparator * attachsep_detailed
Definition: TrackLODManager.cxx:35
VP1Msg::messageDebug
static void messageDebug(const QString &)
Definition: VP1Msg.cxx:39
TrackLODHandle::Imp::attachGroup_LOD
SoGroup * attachGroup_LOD
Definition: TrackLODManager.cxx:229
TrackLODManager::Imp::attachsep_simple
SoSeparator * attachsep_simple
Definition: TrackLODManager.cxx:34
TrackCommonFlags::toString
static QString toString(const SELECTIONMODE &)
Definition: TrackCommonFlags.cxx:18
VP1HelperClassBase::message
void message(const QString &) const
Definition: VP1HelperClassBase.cxx:49
TrackCommonFlags::DETAILLEVEL
DETAILLEVEL
Definition: TrackCommonFlags.h:39
VP1Msg::verbose
static bool verbose()
Definition: VP1Msg.h:31
TrackLODManager::~TrackLODManager
virtual ~TrackLODManager()
Definition: TrackLODManager.cxx:55
TrackLODManager::Imp::id_2_lodhandle
std::map< std::pair< int, double >, TrackLODHandle * > id_2_lodhandle
Definition: TrackLODManager.cxx:44
python.compressB64.c
def c
Definition: compressB64.py:93
TrackLODManager::setAttachNode
void setAttachNode(SoGroup *attachnode)
Definition: TrackLODManager.cxx:122
TrackLODHandle::Imp::sep_simple
SoSeparator * sep_simple
Definition: TrackLODManager.cxx:236
TrackLODManager::eraseEventData
void eraseEventData()
Definition: TrackLODManager.cxx:151
TrackLODHandle::Imp::attachHelper_simple
VP1ExtraSepLayerHelper * attachHelper_simple
Definition: TrackLODManager.cxx:230
TrackLODHandle::m_d
Imp * m_d
Definition: TrackLODManager.h:67