ATLAS Offline Software
Loading...
Searching...
No Matches
AODHandleBase.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 AODHandleBase //
9// //
10// //
12
13#include "AODHandleBase.h"
18
21#include "VP1Base/VP1Msg.h"
23#include "VP1Base/VP1QtUtils.h"
24
26
27#include <Inventor/C/errors/debugerror.h>
28#include <Inventor/nodes/SoLineSet.h>
29#include <Inventor/nodes/SoVertexProperty.h>
30#include <Inventor/nodes/SoSeparator.h>
31#include <Inventor/nodes/SoMaterial.h>
32#include <Inventor/nodes/SoPickStyle.h>
33#include <Inventor/nodes/SoCylinder.h>
34#include <Inventor/nodes/SoMatrixTransform.h>
35#include <Inventor/SbRotation.h>
36#include <Inventor/SbMatrix.h>
37#include <Inventor/nodes/SoTranslation.h>
38#include <Inventor/nodes/SoText2.h>
39
42
43#include <cassert>
44
45#include "AODCollHandleBase.h"
46#include "AODSysCommonData.h"
47
48//#include "xAODBase/IParticle.h"
49
50
51//____________________________________________________________________
53public:
54 static double dist(const SbVec3f& p1,const SbVec3f& p2);
55
56 static std::atomic<int> nobjhandles;
57
60 ~Imp() { }
62
63 //For efficiency we cache parameterisations of the various track parts:
64
65 QTreeWidgetItem* m_objBrowseTree;
66};
67
68
69//____________________________________________________________________
70std::atomic<int> AODHandleBase::Imp::nobjhandles = 0;
71
72//____________________________________________________________________
78
79//____________________________________________________________________
85
86//____________________________________________________________________
91
92//____________________________________________________________________
94{
95 return std::as_const(m_collhandle)->common();
96}
97
98//____________________________________________________________________
100{
101 QString tmp = (vis==true)?"True":"False";
102 QString tmp2 = (m_visible==true)?"True":"False";
103 VP1Msg::messageDebug(QString("AODHandleBase calling setVisible with vis=")+tmp+QString(", and m_visible=")+tmp2 );
104 if (vis==m_visible)
105 return;
106
107 m_visible=vis;
108 if (vis) {
109 m_collhandle->incrementNShownHandles();
110
111 if (!has3DObjects())
112 rebuild3DObjects();//The call to rebuild also fixes attached state.
113 else
115 } else {
116 m_collhandle->decrementNShownHandles();
118 }
119
121}
122
123
124//____________________________________________________________________
126{
127 if (m_visible) {
129 } else {
130 //Simply clear the present 3D objects. They will only be recreated if/when the track/jet becomes visible again.
132 }
133}
134
135
136//____________________________________________________________________
138{
139 QString tmp2 = (m_visible==true)?"True":"False";
140 VP1Msg::messageDebug("AODHandleBase::rebuild3DObjects() - with m_visible="+tmp2 );
141
142 //Ensure we are always detached while updating.
143 if (m_visible) {
145 }
146
148 nodes(); // rebuilds the 3D shapes
149
150 //Attach if visible:
151 if (m_visible) {
153 }
154}
155
156//____________________________________________________________________
158{
159 VP1Msg::messageVerbose("AODHandleBase::attach3DObjects");
160
161 if (!m_currentmaterial) {
163 m_currentmaterial->ref();
165 }
166 if (has3DObjects() && m_collhandle->sepHelper()) {
167 VP1Msg::messageVerbose("Adding nodes to sep helper...");
168
169 m_collhandle->common()->registerHandle(this);
170
171 // debug
172 // std::cout<<"m_collhandle->sepHelper() = " << m_collhandle->sepHelper()<<std::endl;
173 SoNode* tmp = nodes();
174 // std::cout << "tmp nodes = "<< tmp << std::endl;
175
176 // m_collhandle->sepHelper()->addNodeUnderMaterial( nodes(), m_currentmaterial );
177 m_collhandle->sepHelper()->addNodeUnderMaterial( tmp, m_currentmaterial );
178
179 } else {
180 if (!has3DObjects()) {
181 VP1Msg::message("AODHandleBase::attach3DObjects() - No 3D objects to attach!");
182 }
183 if (!m_collhandle->sepHelper()) VP1Msg::message("AODHandleBase::attach3DObjects() - No sep helper!");
184 }
185 // if (label_sep && theclass->common()->textSep() && theclass->common()->controller()->doTrackLabels())
186 // theclass->common()->textSep()->addChild(label_sep);
187 //
188}
189
190//____________________________________________________________________
192{
193 VP1Msg::messageVerbose("AODHandleBase::detach3DObjects");
194
196 return;//Can never have been attached!
197 if (has3DObjects() && m_collhandle->sepHelper()) {
198 m_collhandle->sepHelper()->removeNodeUnderMaterial(nodes(),m_currentmaterial);
199 }
200
201 m_collhandle->common()->deregisterHandle(this);
202
203 // if (label_sep && theclass->common()->textSep())
204 // theclass->common()->textSep()->removeChild(label_sep);
205}
206
207//____________________________________________________________________
209{
210 VP1Msg::messageVerbose("AODHandleBase::updateMaterial()");
211
212 //We need to change the current material. This means we need to
213 //clear the cache. Only if we are visible do we need to do a
214 //detach->clear material->attach cycle to trigger attachment under new material.
215
217 return;//We have no material cached and is thus not attached either.
218 if (m_visible) {
219 //See if the material changed. If it did, detach, update the material, attach again.
220 SoMaterial * newmat = determineMaterial();
221 newmat->ref();
222 if (newmat!=m_currentmaterial) {
224 m_currentmaterial->unref();
225 m_currentmaterial = newmat;
228 } else {
229 newmat->unref();
230 }
231 } else {
232 //Just clear material.
233 m_currentmaterial->unref();
236 }
237}
238
240//double AODHandleBase::mass() const
241//{
242// return 0.0;
243//}
244
245
246//____________________________________________________________________
247QStringList AODHandleBase::baseInfo() const
248{
249 VP1Msg::messageDebug("AODHandleBase::baseInfo()");
250
251 QStringList l;
252
253
254 // Amg::Vector3D mom = momentum()/1000;
255 // if (mom.mag2()==0.0) {
256 // l << "Momentum : 0 (undefined)";
257 // } else {
258 // l << "Momentum [GeV]: "+VP1Msg::str(mom);
259 // l << "|Pt|/|P| [GeV]: "+VP1Msg::str(mom.perp())+" / " + VP1Msg::str(mom.mag());
260 // l << VP1Msg::str("(")+QChar(0x03B7)+","+QChar(0x03D5)+VP1Msg::str(")=(")
261 // +VP1Msg::str(mom.eta())+VP1Msg::str(",")+VP1Msg::str(VP1LinAlgUtils::phiFromXY(mom.x(), mom.y() ))+VP1Msg::str(")");
262 //
263 // l << "Eta: "+VP1Msg::str(mom.eta());
264 // l << "Phi: "+VP1Msg::str(VP1LinAlgUtils::phiFromXY(mom.x(), mom.y() ));
265 // }
266 // l<<"Hit summary: Pix["+VP1Msg::str(getNPixelHits())+"], SCT["+VP1Msg::str(getNSCTHits())+"], TRT["+VP1Msg::str(getNTRTHits())
267 // +"], MDT["+QString::number(getNMDTHits())+"], RPC["+QString::number(getNRPCHits())+"], TGC["+QString::number(getNTGCHits())+"], CSC["+QString::number(getNCSCHits())+"].";
268 //
269 // return l;
270 // int pdg = pdgCode();
271 // if (pdg) {
272 // bool ok;
273 // QString name = VP1ParticleData::particleName(pdg,ok);
274 // if (ok)
275 // l << "pdg: "+QString::number(pdg)+" ["+name+"]";
276 // else
277 // l << "pdg: "+QString::number(pdg);
278 // }
279
280 if (l.length() == 0)
281 l << "baseInfo : (undefined)";
282
283 return l;
284}
285
286
287//____________________________________________________________________
288void AODHandleBase::fillObjectBrowser( QList<QTreeWidgetItem *>& listOfItems) {
289
290 VP1Msg::messageDebug("AODHandleBase::fillObjectBrowser()");
291
292 if (m_d->m_objBrowseTree){
293 VP1Msg::message("ERROR: AODHandleBase::fillObjectBrowser - already have m_objBrowseTree. Aborting.");
294 return;
295 }
296
297 m_d->m_objBrowseTree = new QTreeWidgetItem();
298
299 QString l = shortInfo();
300
301 m_d->m_objBrowseTree->setText(0, type()+QString(QString::number(listOfItems.size())) );
302 m_d->m_objBrowseTree->setText(1, l );
303
304 if (!visible()) {
305 m_d->m_objBrowseTree->setFlags(Qt::ItemFlags()); // not selectable, not enabled
306 }
307 listOfItems << browserTreeItem();
308}
309
310//____________________________________________________________________
311QTreeWidgetItem* AODHandleBase::browserTreeItem() const {
312 return m_d->m_objBrowseTree;
313}
314
315//____________________________________________________________________
317{
318 if ( !browserTreeItem()) {
319 VP1Msg::messageVerbose("visibleStateChanged: No m_objBrowseTree!");
320 return;
321 }
322
323 if (!visible()) {
324 browserTreeItem()->setFlags(Qt::ItemFlags()); // not selectable, not enabled
325 } else {
326 browserTreeItem()->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); // selectable, enabled
327 }
328 QFont itemFont = browserTreeItem()->font(0);
329 itemFont.setStrikeOut(!visible());
330 browserTreeItem()->setFont(0, itemFont);
331 browserTreeItem()->setFont(1, itemFont);
332}
333
static Double_t tc
Base class for all AOD object collections This class primarily handles setting up the interface,...
QTreeWidgetItem * m_objBrowseTree
static double dist(const SbVec3f &p1, const SbVec3f &p2)
Imp(AODHandleBase *tc)
AODHandleBase * theclass
static std::atomic< int > nobjhandles
virtual QString type() const
return very short word with type (maybe link with collection type?)
virtual void currentMaterialChanged()
bool visible() const
void updateMaterial()
Called after some configuration related to material changes.
virtual void rebuild3DObjects()
SoMaterial * m_currentmaterial
virtual void update3DObjects()
Called after some configuration changes, or when the object is first created. Must be overloaded by c...
void setVisible(bool)
use by the collection handle.
virtual SoNode * nodes()=0
Returns the 3Dobjects.
virtual QStringList baseInfo() const
virtual void clear3DObjects()=0
Delete objects.
QTreeWidgetItem * browserTreeItem() const
Return the QTreeWidgetItem;.
virtual bool has3DObjects()
Returns true if the 3D objects have been created.
virtual QString shortInfo() const
returns mom and hit information about track
virtual void fillObjectBrowser(QList< QTreeWidgetItem * > &list)
Create and fill the object browser QTreeWidgetItem.
virtual ~AODHandleBase()
virtual void visibleStateChanged()
Dummy implementation does nothing.
static int numberOfInstances()
const AODSysCommonData * common() const
virtual void detach3DObjects()
Remove from the scene graph.
AODHandleBase(AODCollHandleBase *)
virtual SoMaterial * determineMaterial()=0
Should be implemented by children, in order to change the material depending on the interface etc.
virtual void attach3DObjects()
Connect to the scene graph.
AODCollHandleBase * m_collhandle
static void messageVerbose(const QString &)
Definition VP1Msg.cxx:84
static void messageDebug(const QString &)
Definition VP1Msg.cxx:39
static void message(const QString &, IVP1System *sys=0)
Definition VP1Msg.cxx:30