From b39e8f37fd7203bbeafff8223eab3c032c111315 Mon Sep 17 00:00:00 2001
From: scott snyder <snyder@bnl.gov>
Date: Wed, 17 Mar 2021 23:02:58 +0100
Subject: [PATCH] MuonReadoutGeometry: Speed up RpcReadoutElement ctor.

Use geoGetVolumes to avoid N^2 behavior in RpcReadoutElement ctor.
---
 .../MuonReadoutGeometry/src/RpcReadoutElement.cxx  | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/MuonSpectrometer/MuonDetDescr/MuonReadoutGeometry/src/RpcReadoutElement.cxx b/MuonSpectrometer/MuonDetDescr/MuonReadoutGeometry/src/RpcReadoutElement.cxx
index c4298ed2beab..c9c6da5e5e5e 100644
--- a/MuonSpectrometer/MuonDetDescr/MuonReadoutGeometry/src/RpcReadoutElement.cxx
+++ b/MuonSpectrometer/MuonDetDescr/MuonReadoutGeometry/src/RpcReadoutElement.cxx
@@ -18,6 +18,7 @@
 #include "AthenaKernel/getMessageSvc.h"
 #include "GaudiKernel/MsgStream.h"
 #include "GeoModelKernel/GeoFullPhysVol.h"
+#include "GeoModelUtilities/GeoVisitVolumes.h"
 #include "MuonReadoutGeometry/GenericRPCCache.h"
 #include "MuonReadoutGeometry/RpcReadoutSet.h"
 #include "TrkSurfaces/PlaneSurface.h"
@@ -61,24 +62,21 @@ namespace MuonGM {
 
     if (mgr->MinimalGeoFlag() == 0) {
       if (GeoFullPhysVol* pvc = dynamic_cast<GeoFullPhysVol*> (pv)) {
-	unsigned int nchildvol = pvc->getNChildVols();
 	int lgg = 0;
 	int llay = 0;
 	std::string::size_type npos;
-	for (unsigned ich=0; ich<nchildvol; ++ich) {
-	  PVConstLink pc = pvc->getChildVol(ich);
+        for (const GeoVolumeVec_t::value_type& p1 : geoGetVolumes (pvc)) {
+          const GeoVPhysVol* pc = p1.first;
 	  std::string childname = (pc->getLogVol())->getName();
 	  if ((npos = childname.find("layer")) != std::string::npos ) {
 	    llay ++;
-	    unsigned int nch1 = pc->getNChildVols();
 	    lgg = 0;
-	    for (unsigned ngv=0; ngv<nch1; ++ngv) {
-	      PVConstLink pcgv = pc->getChildVol(ngv);
+            for (const GeoVolumeVec_t::value_type& p2 : geoGetVolumes (pc)) {
+              const GeoVPhysVol* pcgv = p2.first;
 	      std::string childname1 = (pcgv->getLogVol())->getName();
 	      if ((npos = childname1.find("gas volume")) != std::string::npos ) {
 		lgg ++;
-		PVConstLink pcgg = pcgv->getChildVol(0);
-		GeoTrf::Transform3D trans = pvc->getXToChildVol(ich)*pc->getXToChildVol(ngv)*pcgv->getXToChildVol(0);
+		GeoTrf::Transform3D trans = p1.second*p2.second*pcgv->getXToChildVol(0);
 		m_Xlg[llay-1][lgg-1] = trans;
 	      }
 	    }
-- 
GitLab