From f5d67efe66869ce761aeba10bd3a315534b7b3da Mon Sep 17 00:00:00 2001
From: Mark Hodgkinson <m.hodgkinson@sheffield.ac.uk>
Date: Fri, 7 Dec 2018 16:26:11 +0000
Subject: [PATCH] Add constAcessor to PFoAttributesAccessor_v1 and use it where
 appropriate.

Former-commit-id: 0b0890cdcb0b401c2e6b72df769502cc39a7699b
---
 Event/xAOD/xAODPFlow/Root/PFO_v1.cxx          |  18 +--
 .../versions/PFOAttributesAccessor_v1.h       | 130 ++++++++++++++++++
 .../xAODPFlow/xAODPFlow/versions/PFO_v1.icc   |   2 +-
 3 files changed, 140 insertions(+), 10 deletions(-)

diff --git a/Event/xAOD/xAODPFlow/Root/PFO_v1.cxx b/Event/xAOD/xAODPFlow/Root/PFO_v1.cxx
index 5467331d13e..1fba9bdac12 100644
--- a/Event/xAOD/xAODPFlow/Root/PFO_v1.cxx
+++ b/Event/xAOD/xAODPFlow/Root/PFO_v1.cxx
@@ -294,7 +294,7 @@ namespace xAOD {
       return isValid;
     }
     else{
-      const ConstAccessor<float>* p_acc = PFOAttributesAccessor_v1<float>::accessor(AttributeType);
+      const static ConstAccessor<float>* p_acc = PFOAttributesAccessor_v1<float>::constAccessor(AttributeType);
       //check if accessor pointer is NULL
       if( ! p_acc ) {  return false ;}
       //check if variable is avaialable
@@ -563,7 +563,7 @@ namespace xAOD {
   }
 
   bool PFO_v1::addAssociatedParticleLink(PFODetails::PFOParticleType ParticleType,  const ElementLink<IParticleContainer>& theParticle) {
-    const Accessor<std::vector<ElementLink<IParticleContainer > > >* p_acc = PFOParticleTypeMapper_temp::getAccessor(ParticleType);
+    const static Accessor<std::vector<ElementLink<IParticleContainer > > >* p_acc = PFOParticleTypeMapper_temp::getAccessor(ParticleType);
     if (!p_acc) return false;
     else{
       if (!p_acc->isAvailable(*this)) return false;
@@ -593,7 +593,7 @@ namespace xAOD {
   
   bool PFO_v1::setAssociatedParticleLinks(PFODetails::PFOParticleType ParticleType,  const std::vector<ElementLink<IParticleContainer> >& theParticles) {
 
-    const Accessor<std::vector<ElementLink<IParticleContainer > > >* p_acc = PFOParticleTypeMapper_temp::getAccessor(ParticleType);
+    const static Accessor<std::vector<ElementLink<IParticleContainer > > >* p_acc = PFOParticleTypeMapper_temp::getAccessor(ParticleType);
     if (!p_acc) return false;
     else{
       (*p_acc)(*this) = theParticles;
@@ -603,7 +603,7 @@ namespace xAOD {
   
   bool PFO_v1::associatedParticles(PFODetails::PFOParticleType ParticleType, std::vector<const IParticle*>& theParticles ) const{
 
-    const ConstAccessor<std::vector<ElementLink<IParticleContainer > > >* p_acc = PFOParticleTypeMapper_temp::getAccessor(ParticleType);
+    const static ConstAccessor<std::vector<ElementLink<IParticleContainer > > >* p_acc = PFOParticleTypeMapper_temp::getAccessor(ParticleType);
     if (!p_acc) return false;
     else{
       if (!p_acc->isAvailable(*this)) return false;
@@ -652,7 +652,7 @@ namespace xAOD {
 
   const CaloCluster* PFO_v1::cluster(unsigned int index) const {
     
-    const ConstAccessor<std::vector<ElementLink<IParticleContainer > > >* p_acc = PFOParticleTypeMapper_temp::getAccessor(PFODetails::CaloCluster);
+    const static ConstAccessor<std::vector<ElementLink<IParticleContainer > > >* p_acc = PFOParticleTypeMapper_temp::getAccessor(PFODetails::CaloCluster);
     if (!p_acc) return nullptr;
     else if (!p_acc->isAvailable(*this)) {return nullptr;}
     else {
@@ -674,7 +674,7 @@ namespace xAOD {
 
   const TrackParticle* PFO_v1::track(unsigned int index) const {
 
-    const ConstAccessor<std::vector<ElementLink<IParticleContainer > > >* p_acc = PFOParticleTypeMapper_temp::getAccessor(PFODetails::Track);
+    const static ConstAccessor<std::vector<ElementLink<IParticleContainer > > >* p_acc = PFOParticleTypeMapper_temp::getAccessor(PFODetails::Track);
     if (!p_acc) return nullptr;
     else if (!p_acc->isAvailable(*this)) {return nullptr;}
     else {
@@ -761,7 +761,7 @@ namespace xAOD {
     //if you added your own consituents the links will not be correctly persistified
 
     //clusters
-    const Accessor<std::vector<ElementLink<IParticleContainer > > >* p_accClusters = PFOParticleTypeMapper_temp::getAccessor(PFODetails::CaloCluster);
+    const static Accessor<std::vector<ElementLink<IParticleContainer > > >* p_accClusters = PFOParticleTypeMapper_temp::getAccessor(PFODetails::CaloCluster);
     if (p_accClusters){
       const static Accessor<std::vector<ElementLink<IParticleContainer > > >& accClusters = *p_accClusters;
       if ( accClusters.isAvailableWritable(*this) ){
@@ -773,7 +773,7 @@ namespace xAOD {
     }
     
     //tracks
-    const Accessor<std::vector<ElementLink<IParticleContainer > > >* p_accTracks = PFOParticleTypeMapper_temp::getAccessor(PFODetails::Track);
+    const static Accessor<std::vector<ElementLink<IParticleContainer > > >* p_accTracks = PFOParticleTypeMapper_temp::getAccessor(PFODetails::Track);
     if (p_accTracks){
       const static Accessor<std::vector<ElementLink<IParticleContainer > > >& accTracks = *p_accTracks;
       if ( accTracks.isAvailableWritable(*this) ){
@@ -786,7 +786,7 @@ namespace xAOD {
     }
 
     //shots    
-    const Accessor<std::vector<ElementLink<IParticleContainer > > >* p_accShots = PFOParticleTypeMapper_temp::getAccessor(PFODetails::TauShot);
+    const static Accessor<std::vector<ElementLink<IParticleContainer > > >* p_accShots = PFOParticleTypeMapper_temp::getAccessor(PFODetails::TauShot);
     if (p_accShots){
       const static Accessor<std::vector<ElementLink<IParticleContainer > > >& accShots = *p_accShots;
       if ( accShots.isAvailableWritable(*this) ){
diff --git a/Event/xAOD/xAODPFlow/xAODPFlow/versions/PFOAttributesAccessor_v1.h b/Event/xAOD/xAODPFlow/xAODPFlow/versions/PFOAttributesAccessor_v1.h
index b253224d125..4b33a5095a7 100644
--- a/Event/xAOD/xAODPFlow/xAODPFlow/versions/PFOAttributesAccessor_v1.h
+++ b/Event/xAOD/xAODPFlow/xAODPFlow/versions/PFOAttributesAccessor_v1.h
@@ -26,6 +26,14 @@ This is pretty much based on the class xAODJets/JetMomentsAccessor.h - i.e I cop
   }									\
   break
 
+#define DEFINE_PFO_CONSTACCESSOR( NAME )                                    \
+  case xAOD::PFODetails::NAME:				\
+  {									\
+    static const SG::AuxElement::Accessor< T > a( #NAME );			\
+    return &a;								\
+  }									\
+  break
+
 namespace xAOD{
 
   template<class T> struct PFOAttributesAccessor_v1 {
@@ -149,6 +157,128 @@ namespace xAOD{
 	  return 0;
       }//switch on variable names
     }//accessor
+
+    static const SG::AuxElement::Accessor<T>* constAccessor (xAOD::PFODetails::PFOAttributes variable){
+      switch (variable){
+	DEFINE_PFO_CONSTACCESSOR(nPi0);
+	DEFINE_PFO_CONSTACCESSOR(nPi0Proto);
+	DEFINE_PFO_CONSTACCESSOR(eflowRec_EM_FRAC_ENHANCED);
+	DEFINE_PFO_CONSTACCESSOR(eflowRec_ENG_FRAC_CORE);
+	DEFINE_PFO_CONSTACCESSOR(eflowRec_FIRST_ENG_DENS);
+	DEFINE_PFO_CONSTACCESSOR(eflowRec_CENTER_LAMBDA);
+	DEFINE_PFO_CONSTACCESSOR(eflowRec_SECOND_R);
+	DEFINE_PFO_CONSTACCESSOR(eflowRec_DELTA_ALPHA);
+	DEFINE_PFO_CONSTACCESSOR(eflowRec_HOT_STRIP_FRAC);
+	DEFINE_PFO_CONSTACCESSOR(eflowRec_THREE_CELL_STRIP_FRAC);
+	DEFINE_PFO_CONSTACCESSOR(eflowRec_LATERAL);
+	DEFINE_PFO_CONSTACCESSOR(eflowRec_LONGITUDINAL);
+	DEFINE_PFO_CONSTACCESSOR(eflowRec_SECOND_LAMBDA);
+	DEFINE_PFO_CONSTACCESSOR(eflowRec_ISOLATION);
+	DEFINE_PFO_CONSTACCESSOR(eflowRec_ENG_FRAC_MAX); 
+	DEFINE_PFO_CONSTACCESSOR(eflowRec_ENG_BAD_CELLS);
+	DEFINE_PFO_CONSTACCESSOR(eflowRec_N_BAD_CELLS);
+	DEFINE_PFO_CONSTACCESSOR(eflowRec_BADLARQ_FRAC);
+	DEFINE_PFO_CONSTACCESSOR(eflowRec_ENG_POS);
+	DEFINE_PFO_CONSTACCESSOR(eflowRec_SIGNIFICANCE);
+	DEFINE_PFO_CONSTACCESSOR(eflowRec_CELL_SIGNIFICANCE);
+	DEFINE_PFO_CONSTACCESSOR(eflowRec_CELL_SIG_SAMPLING);
+	DEFINE_PFO_CONSTACCESSOR(eflowRec_AVG_LAR_Q);
+	DEFINE_PFO_CONSTACCESSOR(eflowRec_AVG_TILE_Q);
+	DEFINE_PFO_CONSTACCESSOR(eflowRec_LAYERENERGY_EM3);
+	DEFINE_PFO_CONSTACCESSOR(eflowRec_LAYERENERGY_HEC0);
+	DEFINE_PFO_CONSTACCESSOR(eflowRec_LAYERENERGY_Tile0);
+	DEFINE_PFO_CONSTACCESSOR(eflowRec_LAYERENERGY_HEC);
+	DEFINE_PFO_CONSTACCESSOR(eflowRec_TIMING);
+	DEFINE_PFO_CONSTACCESSOR(eflowRec_tracksExpectedEnergyDeposit);
+	DEFINE_PFO_CONSTACCESSOR(eflowRec_isInDenseEnvironment);
+	DEFINE_PFO_CONSTACCESSOR(eflowRec_LAYERENERGY_EM);
+        DEFINE_PFO_CONSTACCESSOR(eflowRec_LAYERENERGY_PreSamplerB);
+        DEFINE_PFO_CONSTACCESSOR(eflowRec_LAYERENERGY_EMB1);
+        DEFINE_PFO_CONSTACCESSOR(eflowRec_LAYERENERGY_EMB2);
+        DEFINE_PFO_CONSTACCESSOR(eflowRec_LAYERENERGY_EMB3);
+        DEFINE_PFO_CONSTACCESSOR(eflowRec_LAYERENERGY_PreSamplerE);
+        DEFINE_PFO_CONSTACCESSOR(eflowRec_LAYERENERGY_EME1);
+        DEFINE_PFO_CONSTACCESSOR(eflowRec_LAYERENERGY_EME2);
+        DEFINE_PFO_CONSTACCESSOR(eflowRec_LAYERENERGY_EME3);
+        DEFINE_PFO_CONSTACCESSOR(eflowRec_LAYERENERGY_HEC1);
+        DEFINE_PFO_CONSTACCESSOR(eflowRec_LAYERENERGY_HEC2);
+        DEFINE_PFO_CONSTACCESSOR(eflowRec_LAYERENERGY_HEC3);
+        DEFINE_PFO_CONSTACCESSOR(eflowRec_LAYERENERGY_TileBar0);
+        DEFINE_PFO_CONSTACCESSOR(eflowRec_LAYERENERGY_TileBar1);
+        DEFINE_PFO_CONSTACCESSOR(eflowRec_LAYERENERGY_TileBar2);
+        DEFINE_PFO_CONSTACCESSOR(eflowRec_LAYERENERGY_TileGap1);
+        DEFINE_PFO_CONSTACCESSOR(eflowRec_LAYERENERGY_TileGap2);
+        DEFINE_PFO_CONSTACCESSOR(eflowRec_LAYERENERGY_TileGap3);
+        DEFINE_PFO_CONSTACCESSOR(eflowRec_LAYERENERGY_TileExt0);
+        DEFINE_PFO_CONSTACCESSOR(eflowRec_LAYERENERGY_TileExt1);
+        DEFINE_PFO_CONSTACCESSOR(eflowRec_LAYERENERGY_TileExt2);
+        DEFINE_PFO_CONSTACCESSOR(eflowRec_LAYERENERGY_FCAL0);
+        DEFINE_PFO_CONSTACCESSOR(eflowRec_LAYERENERGY_FCAL1);
+        DEFINE_PFO_CONSTACCESSOR(eflowRec_LAYERENERGY_FCAL2);
+        DEFINE_PFO_CONSTACCESSOR(eflowRec_LAYERENERGY_MINIFCAL0);
+        DEFINE_PFO_CONSTACCESSOR(eflowRec_LAYERENERGY_MINIFCAL1);
+        DEFINE_PFO_CONSTACCESSOR(eflowRec_LAYERENERGY_MINIFCAL2);
+        DEFINE_PFO_CONSTACCESSOR(eflowRec_LAYERENERGY_MINIFCAL3);
+        DEFINE_PFO_CONSTACCESSOR(eflowRec_layerVectorCellOrdering);
+        DEFINE_PFO_CONSTACCESSOR(eflowRec_radiusVectorCellOrdering);
+        DEFINE_PFO_CONSTACCESSOR(eflowRec_avgEdensityVectorCellOrdering);
+        DEFINE_PFO_CONSTACCESSOR(eflowRec_layerHED);
+	DEFINE_PFO_CONSTACCESSOR(eflowRec_EM_PROBABILITY);
+	DEFINE_PFO_CONSTACCESSOR(eflowRec_ENG_CALIB_TOT);
+	DEFINE_PFO_CONSTACCESSOR(eflowRec_ENG_CALIB_FRAC_EM);
+	DEFINE_PFO_CONSTACCESSOR(eflowRec_ENG_CALIB_FRAC_HAD);
+	DEFINE_PFO_CONSTACCESSOR(eflowRec_ENG_CALIB_FRAC_REST);
+	DEFINE_PFO_CONSTACCESSOR(cellBased_FIRST_ETA); 
+	DEFINE_PFO_CONSTACCESSOR(cellBased_SECOND_R); 
+	DEFINE_PFO_CONSTACCESSOR(cellBased_SECOND_LAMBDA); 
+	DEFINE_PFO_CONSTACCESSOR(cellBased_DELTA_PHI); 
+	DEFINE_PFO_CONSTACCESSOR(cellBased_DELTA_THETA); 
+	DEFINE_PFO_CONSTACCESSOR(cellBased_CENTER_LAMBDA); 
+	DEFINE_PFO_CONSTACCESSOR(cellBased_LATERAL); 
+	DEFINE_PFO_CONSTACCESSOR(cellBased_LONGITUDINAL); 
+	DEFINE_PFO_CONSTACCESSOR(cellBased_ENG_FRAC_EM); 
+	DEFINE_PFO_CONSTACCESSOR(cellBased_ENG_FRAC_MAX); 
+	DEFINE_PFO_CONSTACCESSOR(cellBased_ENG_FRAC_CORE); 
+	DEFINE_PFO_CONSTACCESSOR(cellBased_SECOND_ENG_DENS); 
+	DEFINE_PFO_CONSTACCESSOR(cellBased_EM1CoreFrac); 
+	DEFINE_PFO_CONSTACCESSOR(cellBased_asymmetryInEM1WRTTrk); 
+	DEFINE_PFO_CONSTACCESSOR(cellBased_NHitsInEM1); 
+	DEFINE_PFO_CONSTACCESSOR(cellBased_NPosECells_PS); 
+	DEFINE_PFO_CONSTACCESSOR(cellBased_NPosECells_EM1); 
+	DEFINE_PFO_CONSTACCESSOR(cellBased_NPosECells_EM2); 
+	DEFINE_PFO_CONSTACCESSOR(cellBased_firstEtaWRTClusterPosition_EM1); 
+	DEFINE_PFO_CONSTACCESSOR(cellBased_firstEtaWRTClusterPosition_EM2); 
+	DEFINE_PFO_CONSTACCESSOR(cellBased_secondEtaWRTClusterPosition_EM1); 
+	DEFINE_PFO_CONSTACCESSOR(cellBased_secondEtaWRTClusterPosition_EM2); 
+	DEFINE_PFO_CONSTACCESSOR(cellBased_energy_EM1); 
+	DEFINE_PFO_CONSTACCESSOR(cellBased_energy_EM2); 
+	DEFINE_PFO_CONSTACCESSOR(tauShots_nCellsInEta);
+	DEFINE_PFO_CONSTACCESSOR(tauShots_pt1); 
+	DEFINE_PFO_CONSTACCESSOR(tauShots_pt3); 
+	DEFINE_PFO_CONSTACCESSOR(tauShots_pt5); 
+	DEFINE_PFO_CONSTACCESSOR(tauShots_ws5); 
+	DEFINE_PFO_CONSTACCESSOR(tauShots_sdevEta5_WRTmean); 
+	DEFINE_PFO_CONSTACCESSOR(tauShots_sdevEta5_WRTmode); 
+	DEFINE_PFO_CONSTACCESSOR(tauShots_sdevPt5); 
+	DEFINE_PFO_CONSTACCESSOR(tauShots_deltaPt12_min); 
+	DEFINE_PFO_CONSTACCESSOR(tauShots_Fside_3not1); 
+	DEFINE_PFO_CONSTACCESSOR(tauShots_Fside_5not1); 
+	DEFINE_PFO_CONSTACCESSOR(tauShots_Fside_5not3); 
+	DEFINE_PFO_CONSTACCESSOR(tauShots_fracSide_3not1); 
+	DEFINE_PFO_CONSTACCESSOR(tauShots_fracSide_5not1); 
+	DEFINE_PFO_CONSTACCESSOR(tauShots_fracSide_5not3); 
+	DEFINE_PFO_CONSTACCESSOR(tauShots_pt1OverPt3); 
+	DEFINE_PFO_CONSTACCESSOR(tauShots_pt3OverPt5); 
+	DEFINE_PFO_CONSTACCESSOR(tauShots_mergedScore); 
+	DEFINE_PFO_CONSTACCESSOR(tauShots_signalScore); 
+	DEFINE_PFO_CONSTACCESSOR(tauShots_nPhotons); 
+	DEFINE_PFO_CONSTACCESSOR(tauShots_seedHash);
+	default:
+	  std::cerr << "xAOD::PFO_v1 ERROR Unknown float/double variable (" << static_cast<int>(variable) << ") requested" << std::endl;
+	  return 0;
+      }//switch on variable names
+    }//const accessor
+    
   }//struct
   ;
   
diff --git a/Event/xAOD/xAODPFlow/xAODPFlow/versions/PFO_v1.icc b/Event/xAOD/xAODPFlow/xAODPFlow/versions/PFO_v1.icc
index 8fbe601a2f2..35221aeef04 100644
--- a/Event/xAOD/xAODPFlow/xAODPFlow/versions/PFO_v1.icc
+++ b/Event/xAOD/xAODPFlow/xAODPFlow/versions/PFO_v1.icc
@@ -15,7 +15,7 @@ namespace xAOD{
   
   template<class T> bool PFO_v1::attribute(PFODetails::PFOAttributes AttributeType, T& anAttribute) const {
     
-    const ConstAccessor<T>* acc = PFOAttributesAccessor_v1<T>::accessor(AttributeType);
+    const static ConstAccessor<T>* acc = PFOAttributesAccessor_v1<T>::accessor(AttributeType);
     //check if accessor pointer is NULL
     if( ! acc ) {  return false ;}
     //check if variable is avaialable
-- 
GitLab