From 228c4228b34ebdf4fd5f799c9f171e97616462b4 Mon Sep 17 00:00:00 2001
From: scott snyder <snyder@bnl.gov>
Date: Thu, 15 Apr 2021 21:03:35 +0200
Subject: [PATCH 1/2] PyAnalysisExamples: Move test classes to a namespace.

Move MyObj, etc to a namespace to avoid collisions with other packages.
See ATEAM-731.
---
 .../PyAnalysisExamples/MyCutClass.h           |  6 ++-
 .../PyAnalysisExamples/MyDetObj.h             |  8 +++-
 .../PyAnalysisExamples/MyObj.h                |  8 +++-
 .../PyAnalysisExamples/MySelectionAlg.h       |  4 +-
 .../PyAnalysisExamples/MyTool.h               |  6 +--
 .../PyAnalysisExamplesDict.h                  |  4 +-
 .../PyAnalysisExamples/selection.xml          |  6 +--
 .../PyAnalysisExamples/share/AlgorithmTest.py |  6 +--
 .../PyAnalysisExamples/share/BindingsTest.py  |  6 +--
 .../PyAnalysisExamples/share/CallBackTest.py  |  6 +--
 .../PyAnalysisExamples/share/ParticleTest.py  | 10 ++---
 .../PyAnalysisExamples/share/ToolTest.py      | 14 +++---
 .../PyAnalysisExamples/share/TriggerTest.py   | 44 +++++++++----------
 .../PyAnalysisExamples/share/TruthTest.py     |  6 +--
 14 files changed, 73 insertions(+), 61 deletions(-)

diff --git a/PhysicsAnalysis/PyAnalysis/PyAnalysisExamples/PyAnalysisExamples/MyCutClass.h b/PhysicsAnalysis/PyAnalysis/PyAnalysisExamples/PyAnalysisExamples/MyCutClass.h
index 2696a3eda9f2..0c7098752d6f 100755
--- a/PhysicsAnalysis/PyAnalysis/PyAnalysisExamples/PyAnalysisExamples/MyCutClass.h
+++ b/PhysicsAnalysis/PyAnalysis/PyAnalysisExamples/PyAnalysisExamples/MyCutClass.h
@@ -1,5 +1,5 @@
 /*
-  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
+  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
 */
 
 #ifndef PYANALYSISEXAMPLES_MYCUTCLASS_H
@@ -10,6 +10,8 @@
 
 #include "egammaEvent/Electron.h"
 
+namespace AthPyEx {
+
 class MyCutClass
 {
 public:
@@ -28,4 +30,6 @@ private:
   double m_Thr;
 };
 
+} // namespace AthPyEx
+
 #endif
diff --git a/PhysicsAnalysis/PyAnalysis/PyAnalysisExamples/PyAnalysisExamples/MyDetObj.h b/PhysicsAnalysis/PyAnalysis/PyAnalysisExamples/PyAnalysisExamples/MyDetObj.h
index d903201753df..e59386407822 100755
--- a/PhysicsAnalysis/PyAnalysis/PyAnalysisExamples/PyAnalysisExamples/MyDetObj.h
+++ b/PhysicsAnalysis/PyAnalysis/PyAnalysisExamples/PyAnalysisExamples/MyDetObj.h
@@ -1,5 +1,5 @@
 /*
-  Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
+  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
 */
 
 #ifndef PYANALYSISEXAMPLES_MYDETOBJ_H
@@ -9,6 +9,8 @@
 
 #include "AthenaKernel/CLASS_DEF.h"
 
+namespace AthPyEx {
+
 class MyDetObj
 {
 public:
@@ -21,7 +23,9 @@ private:
   std::string m_name;
 };
 
-CLASS_DEF(MyDetObj, 28914872, 1)
+} // namespace AthPyEx
+
+CLASS_DEF(AthPyEx::MyDetObj, 105730742, 1)
 
 #endif
 
diff --git a/PhysicsAnalysis/PyAnalysis/PyAnalysisExamples/PyAnalysisExamples/MyObj.h b/PhysicsAnalysis/PyAnalysis/PyAnalysisExamples/PyAnalysisExamples/MyObj.h
index b8e61ce860c8..f1d19fe89907 100755
--- a/PhysicsAnalysis/PyAnalysis/PyAnalysisExamples/PyAnalysisExamples/MyObj.h
+++ b/PhysicsAnalysis/PyAnalysis/PyAnalysisExamples/PyAnalysisExamples/MyObj.h
@@ -1,5 +1,5 @@
 /*
-  Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
+  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
 */
 
 #ifndef PYANALYSISEXAMPLES_MYOBJ_H
@@ -11,6 +11,8 @@
 
 #include "AthenaKernel/CLASS_DEF.h"
 
+namespace AthPyEx {
+
 class MyObj
 {
 public:
@@ -31,7 +33,9 @@ private:
   int m_a;
 };
 
-CLASS_DEF(MyObj, 86839352, 1)
+} // namespace AthPyEx
+
+CLASS_DEF(AthPyEx::MyObj, 28807578, 1)
 
 #endif
 
diff --git a/PhysicsAnalysis/PyAnalysis/PyAnalysisExamples/PyAnalysisExamples/MySelectionAlg.h b/PhysicsAnalysis/PyAnalysis/PyAnalysisExamples/PyAnalysisExamples/MySelectionAlg.h
index ed13a5aa3d37..64e8924d6503 100755
--- a/PhysicsAnalysis/PyAnalysis/PyAnalysisExamples/PyAnalysisExamples/MySelectionAlg.h
+++ b/PhysicsAnalysis/PyAnalysis/PyAnalysisExamples/PyAnalysisExamples/MySelectionAlg.h
@@ -1,16 +1,16 @@
 /*
-  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
+  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
 */
 
 #ifndef PYANALYSISEXAMPLES_MYSELECTIONALG_H
 #define PYANALYSISEXAMPLES_MYSELECTIONALG_H
 
-class MyCutClass;
 
 #include "AthenaBaseComps/AthAlgorithm.h"
 
 namespace AthPyEx {
 class MyTool;
+class MyCutClass;
 
 class MySelectionAlg : public AthAlgorithm
 {
diff --git a/PhysicsAnalysis/PyAnalysis/PyAnalysisExamples/PyAnalysisExamples/MyTool.h b/PhysicsAnalysis/PyAnalysis/PyAnalysisExamples/PyAnalysisExamples/MyTool.h
index 59c554fbc6aa..9f12f595f1f9 100755
--- a/PhysicsAnalysis/PyAnalysis/PyAnalysisExamples/PyAnalysisExamples/MyTool.h
+++ b/PhysicsAnalysis/PyAnalysis/PyAnalysisExamples/PyAnalysisExamples/MyTool.h
@@ -1,5 +1,5 @@
 /*
-  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
+  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
 */
 
 #ifndef PYANALYSISEXAMPLES_MYTOOL_H
@@ -15,10 +15,10 @@
 #include "Python.h"
 #include "AthenaBaseComps/AthAlgTool.h"
 
-class MyObj;
-
 namespace AthPyEx {
 
+class MyObj;
+
 class MyTool : public AthAlgTool
 {
 public:
diff --git a/PhysicsAnalysis/PyAnalysis/PyAnalysisExamples/PyAnalysisExamples/PyAnalysisExamplesDict.h b/PhysicsAnalysis/PyAnalysis/PyAnalysisExamples/PyAnalysisExamples/PyAnalysisExamplesDict.h
index b6df71076445..dda0fa9231e9 100755
--- a/PhysicsAnalysis/PyAnalysis/PyAnalysisExamples/PyAnalysisExamples/PyAnalysisExamplesDict.h
+++ b/PhysicsAnalysis/PyAnalysis/PyAnalysisExamples/PyAnalysisExamples/PyAnalysisExamplesDict.h
@@ -1,5 +1,5 @@
 /*
-  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
+  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
 */
 
 #ifndef PYANALYSISEXAMPLES_PYANALYSISEXAMPLESDICT_H
@@ -14,7 +14,7 @@ namespace  PyAnalysisExamplesDict
 {
   void tmp ()
   {
-    MyObj *obj = new MyObj("cccc");
+    auto obj = std::make_unique<MyObj>("cccc");
     obj->setA<float>(0);    
     obj->setA<double>(0);    
     obj->setA<int>(0);
diff --git a/PhysicsAnalysis/PyAnalysis/PyAnalysisExamples/PyAnalysisExamples/selection.xml b/PhysicsAnalysis/PyAnalysis/PyAnalysisExamples/PyAnalysisExamples/selection.xml
index 7ab4576fe075..5eeeb6308088 100755
--- a/PhysicsAnalysis/PyAnalysis/PyAnalysisExamples/PyAnalysisExamples/selection.xml
+++ b/PhysicsAnalysis/PyAnalysis/PyAnalysisExamples/PyAnalysisExamples/selection.xml
@@ -1,8 +1,8 @@
 <lcgdict>
 
-  <class name="MyCutClass" />
-  <class name="MyObj" />
-  <class name="MyDetObj" />
+  <class name="AthPyEx::MyCutClass" />
+  <class name="AthPyEx::MyObj" />
+  <class name="AthPyEx::MyDetObj" />
   <class name="AthPyEx::MyTool" />
   
 </lcgdict>
diff --git a/PhysicsAnalysis/PyAnalysis/PyAnalysisExamples/share/AlgorithmTest.py b/PhysicsAnalysis/PyAnalysis/PyAnalysisExamples/share/AlgorithmTest.py
index 1926f2d6d6fb..93fd5e5a0e60 100755
--- a/PhysicsAnalysis/PyAnalysis/PyAnalysisExamples/share/AlgorithmTest.py
+++ b/PhysicsAnalysis/PyAnalysis/PyAnalysisExamples/share/AlgorithmTest.py
@@ -30,11 +30,11 @@ theApp.nextEvent()
 # get transient Electrons which are recorded into SG by MySelectonAlg
 econ = PyParticleTools.getElectrons(myNewKey)
 for ie in range(len(econ)):
-    print "pt %f" % econ[ie].pt()
+    print ("pt %f" % econ[ie].pt())
 
 # load dict for MyDetObj
 pylcgdict.load_library("libPyAnalysisExamplesDict")
 
 # retrieve an object from DetectorStore
-obj = PyKernel.retrieveDet(g.MyDetObj,'myDetObj')
-print obj.name()
+obj = PyKernel.retrieveDet(g.AthPyEx.MyDetObj,'myDetObj')
+print (obj.name())
diff --git a/PhysicsAnalysis/PyAnalysis/PyAnalysisExamples/share/BindingsTest.py b/PhysicsAnalysis/PyAnalysis/PyAnalysisExamples/share/BindingsTest.py
index fa43689ab9cd..d81b400d19ea 100755
--- a/PhysicsAnalysis/PyAnalysis/PyAnalysisExamples/share/BindingsTest.py
+++ b/PhysicsAnalysis/PyAnalysis/PyAnalysisExamples/share/BindingsTest.py
@@ -10,7 +10,7 @@
 pylcgdict.load_library("libPyAnalysisExamplesDict")
 
 # instantiate a C++ class from python
-cut = g.MyCutClass(30*GeV)
+cut = g.AthPyEx.MyCutClass(30*GeV)
 
 # init application mgr
 theApp.initialize()
@@ -32,10 +32,10 @@ for ievent in range(5):
     for ie in range(len(econ)):
         eobj = econ[ie]
         if cut.isAccepted(eobj):
-            print "accept %f" % eobj.pt()
+            print ("accept %f" % eobj.pt())
             ha.Fill(eobj.pt())
         else:
-            print "reject %f" % eobj.pt()
+            print ("reject %f" % eobj.pt())
             hr.Fill(eobj.pt())            
 
 ha.Draw()
diff --git a/PhysicsAnalysis/PyAnalysis/PyAnalysisExamples/share/CallBackTest.py b/PhysicsAnalysis/PyAnalysis/PyAnalysisExamples/share/CallBackTest.py
index fde090ddec1f..f782e3f8f000 100755
--- a/PhysicsAnalysis/PyAnalysis/PyAnalysisExamples/share/CallBackTest.py
+++ b/PhysicsAnalysis/PyAnalysis/PyAnalysisExamples/share/CallBackTest.py
@@ -12,12 +12,12 @@ pylcgdict.load_library("libPyAnalysisExamplesDict")
 obj = g.CallBackTest()
 
 # setup reverse proxy
-g.PyReverseProxy(g.MyDetObj).setConv(g.PyReverseProxy(g.MyDetObj).getObj)
+g.PyReverseProxy(g.AthPyEx.MyDetObj).setConv(g.PyReverseProxy(g.AthPyEx.MyDetObj).getObj)
 
 # define a python function
 def aPyFunc(dobj):
-    print "   aPyFunc called"
-    print dobj.name()
+    print ("   aPyFunc called")
+    print (dobj.name())
     
 # set callback
 obj.setCallBack(aPyFunc)
diff --git a/PhysicsAnalysis/PyAnalysis/PyAnalysisExamples/share/ParticleTest.py b/PhysicsAnalysis/PyAnalysis/PyAnalysisExamples/share/ParticleTest.py
index d3e6b9f18840..bce919d95807 100755
--- a/PhysicsAnalysis/PyAnalysis/PyAnalysisExamples/share/ParticleTest.py
+++ b/PhysicsAnalysis/PyAnalysis/PyAnalysisExamples/share/ParticleTest.py
@@ -15,16 +15,16 @@ theApp.nextEvent()
 
 # get ElectronContainer from AOD
 econ = PyParticleTools.getElectrons("ElectronCollection")
-print "Electron"
-print econ.size()
+print ("Electron")
+print (econ.size())
 
 for i in range(econ.size()):
     eobj = econ[i]
-    print "Electron pt:%f" % eobj.pt()
+    print ("Electron pt:%f" % eobj.pt())
     # get TrackParticle via ElementLink
     tp = eobj.track()
-    print "TrackParticle px:%f" % tp.px()
+    print ("TrackParticle px:%f" % tp.px())
     # get egamma via Navigation
     # this should be retrieved from ESD
     eg = eobj.eg()
-    print "egamma eta:%f" % eg.eta()
+    print ("egamma eta:%f" % eg.eta())
diff --git a/PhysicsAnalysis/PyAnalysis/PyAnalysisExamples/share/ToolTest.py b/PhysicsAnalysis/PyAnalysis/PyAnalysisExamples/share/ToolTest.py
index a7b22f3f9640..e6c4f99d1ae4 100755
--- a/PhysicsAnalysis/PyAnalysis/PyAnalysisExamples/share/ToolTest.py
+++ b/PhysicsAnalysis/PyAnalysis/PyAnalysisExamples/share/ToolTest.py
@@ -30,7 +30,7 @@ tool.setPython(tool)
 
 # set proxy
 def convFunc():
-    ptr = cppyy.libPyROOT.MakeNullPointer(g.MyObj)
+    ptr = cppyy.libPyROOT.MakeNullPointer(g.AthPyEx.MyObj)
     proxy = g.PyReverseProxy.getProxy("MyObj_Proxy")
     proxy.getObj(ptr)
     return ptr
@@ -40,16 +40,16 @@ proxy.setFunc(convFunc)
 counter=567
 # callback
 def py_execute(obj):
-    print "PyExecute begin"
-    print "   name : %s" % obj.name()
-    print "      A : %s" % obj.getA()
-    print "setA float in Python"
+    print ("PyExecute begin")
+    print ("   name : %s" % obj.name())
+    print ("      A : %s" % obj.getA())
+    print ("setA float in Python")
     obj.setA(1.22)
-    print "setA int in Python"    
+    print ("setA int in Python"    )
     global counter
     obj.setA(counter)
     counter += 1
-    print "PyExecute end"    
+    print ("PyExecute end"    )
     return True
 tool.py_execute = py_execute
 
diff --git a/PhysicsAnalysis/PyAnalysis/PyAnalysisExamples/share/TriggerTest.py b/PhysicsAnalysis/PyAnalysis/PyAnalysisExamples/share/TriggerTest.py
index f019821a977d..4fc3cdd82ce3 100755
--- a/PhysicsAnalysis/PyAnalysis/PyAnalysisExamples/share/TriggerTest.py
+++ b/PhysicsAnalysis/PyAnalysis/PyAnalysisExamples/share/TriggerTest.py
@@ -12,42 +12,42 @@ theApp.nextEvent()
 
 # CTP
 ctp = PyTriggerTools.getCTP_Decision ("CTP_Decision")
-print "CTP"
-print ctp.getTriggerTypeWord()
-print "-------------------------"
+print ("CTP")
+print (ctp.getTriggerTypeWord())
+print ("-------------------------")
 
 # L1 ROI
 L1rois = PyTriggerTools.getLVL1_ROI ("LVL1_ROI")
 
-print "Muon"
+print ("Muon")
 rois = L1rois.getMuonROIs()
 for roi in rois:
-    print "Eta:%s" % roi.getEta()
-    print "Phi:%s" % roi.getPhi()
-print "-------------------------"
+    print ("Eta:%s" % roi.getEta())
+    print ("Phi:%s" % roi.getPhi())
+print ("-------------------------")
 
-print "EmTau"
+print ("EmTau")
 rois = L1rois.getEmTauROIs()
 for roi in rois:    
-    print "Eta:%s" % roi.getEta()
-    print "Phi:%s" % roi.getPhi()
-print "-------------------------"
+    print ("Eta:%s" % roi.getEta())
+    print ("Phi:%s" % roi.getPhi())
+print ("-------------------------")
 
-print "Jet"
+print ("Jet")
 rois = L1rois.getJetROIs()
 for roi in rois:
-    print "Eta:%s" % roi.getEta()
-    print "Phi:%s" % roi.getPhi()
-print "-------------------------"
+    print ("Eta:%s" % roi.getEta())
+    print ("Phi:%s" % roi.getPhi())
+print ("-------------------------")
 
-print "JetET"
+print ("JetET")
 rois = L1rois.getJetEtROIs()
-print "-------------------------"
+print ("-------------------------")
 
-print "EnergySum"
+print ("EnergySum")
 rois = L1rois.getEnergySumROIs()
 for i in range(len(rois)):
-    print "EX:%s" % rois[i].getEnergyX()
-    print "EY:%s" % rois[i].getEnergyY()
-    print "ET:%s" % rois[i].getEnergyT()
-print "-------------------------"
+    print ("EX:%s" % rois[i].getEnergyX())
+    print ("EY:%s" % rois[i].getEnergyY())
+    print ("ET:%s" % rois[i].getEnergyT())
+print ("-------------------------")
diff --git a/PhysicsAnalysis/PyAnalysis/PyAnalysisExamples/share/TruthTest.py b/PhysicsAnalysis/PyAnalysis/PyAnalysisExamples/share/TruthTest.py
index bb4ea23570c5..5040960bc916 100755
--- a/PhysicsAnalysis/PyAnalysis/PyAnalysisExamples/share/TruthTest.py
+++ b/PhysicsAnalysis/PyAnalysis/PyAnalysisExamples/share/TruthTest.py
@@ -17,7 +17,7 @@ mcc = PyTruthTools.getMcEvents('GEN_AOD')
 mc = mcc[0]
 
 # call a normal method
-print mc.alphaQCD()
+print (mc.alphaQCD())
 
 # get particle-iterators
 # GenEvent::particles_begin() and _end() give ietrators
@@ -32,7 +32,7 @@ while (it != itE):
     # dereference and increment the iterator
     # this corresponds to "p = *it++" 
     p = it.next()
-    print p.pdg_id()
+    print (p.pdg_id())
 
 # get vertex-iterator
 it = mc.vertices_begin()
@@ -49,5 +49,5 @@ itpE = v.particles_end(0)
 itp.end = v.particles_end
 
 while (itp != itpE):
-    print itp.next().pdg_id()
+    print (itp.next().pdg_id())
 
-- 
GitLab


From 45e8bc26dd66f97630eb2d784eb95ed75cf53d28 Mon Sep 17 00:00:00 2001
From: scott snyder <snyder@bnl.gov>
Date: Fri, 16 Apr 2021 23:51:49 +0200
Subject: [PATCH 2/2] Fix errors in dictionary header.

---
 .../PyAnalysisExamples/PyAnalysisExamplesDict.h                | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/PhysicsAnalysis/PyAnalysis/PyAnalysisExamples/PyAnalysisExamples/PyAnalysisExamplesDict.h b/PhysicsAnalysis/PyAnalysis/PyAnalysisExamples/PyAnalysisExamples/PyAnalysisExamplesDict.h
index dda0fa9231e9..1bcf511f9504 100755
--- a/PhysicsAnalysis/PyAnalysis/PyAnalysisExamples/PyAnalysisExamples/PyAnalysisExamplesDict.h
+++ b/PhysicsAnalysis/PyAnalysis/PyAnalysisExamples/PyAnalysisExamples/PyAnalysisExamplesDict.h
@@ -14,13 +14,12 @@ namespace  PyAnalysisExamplesDict
 {
   void tmp ()
   {
-    auto obj = std::make_unique<MyObj>("cccc");
+    auto obj = std::make_unique<AthPyEx::MyObj>("cccc");
     obj->setA<float>(0);    
     obj->setA<double>(0);    
     obj->setA<int>(0);
     obj->setA<long>(0);
     obj->setA<bool>(false);    
-    delete obj;
   }
 }
 
-- 
GitLab