From 77f78ea9d8bdb37e4d91d5f1d29cbbf1960e1e37 Mon Sep 17 00:00:00 2001
From: Markus Frank <Markus.Frank@cern.ch>
Date: Fri, 16 Jun 2023 15:22:55 +0200
Subject: [PATCH] Fix compile error on MacOS

---
 DDCore/src/DetectorImp.cpp                 |  6 ++-
 DDCore/src/Primitives.cpp                  |  3 +-
 DDCore/src/plugins/DetectorChecksum.cpp    | 18 ++++-----
 DDDigi/include/DDDigi/DigiOutputAction.h   |  6 +--
 DDDigi/plugins/DigiSegmentDepositPrint.cpp | 47 +++++++++++-----------
 DDG4/src/Geant4Data.cpp                    | 26 ++++++------
 examples/ClientTests/src/MiniTel.cpp       |  8 ++--
 examples/DDG4/src/PropertyTestAction.cpp   |  6 +--
 8 files changed, 62 insertions(+), 58 deletions(-)

diff --git a/DDCore/src/DetectorImp.cpp b/DDCore/src/DetectorImp.cpp
index 15539f854..ee1680a62 100644
--- a/DDCore/src/DetectorImp.cpp
+++ b/DDCore/src/DetectorImp.cpp
@@ -643,8 +643,10 @@ Handle<NamedObject> DetectorImp::getRefChild(const HandleMap& e, const string& n
       ptr(const void* p) { other = p; }
     };
     std::string nam = "";
-    ptr m(&e), ref(this);
-    if ( ref.c > m.c && m.c < ref.c+sizeof(*this) ) nam = m.omap->name;
+    ptr mptr(&e), ref(this);
+    if ( ref.c > mptr.c && mptr.c < ref.c+sizeof(*this) )  {
+      nam = mptr.omap->name;
+    }
     std::stringstream err;
     err << "getRefChild: Failed to find child with name: " << name
         << " Map " << nam << " contains " << e.size() << " elements: {";
diff --git a/DDCore/src/Primitives.cpp b/DDCore/src/Primitives.cpp
index 0e892bf91..98439f8e9 100644
--- a/DDCore/src/Primitives.cpp
+++ b/DDCore/src/Primitives.cpp
@@ -173,7 +173,8 @@ namespace {
 /// Convert volumeID to string format (016X)
 std::string dd4hep::volumeID(VolumeID vid)   {
   char text[32];
-  ::snprintf(text,sizeof(text),"%016lx", vid);
+  unsigned long long id = (unsigned long long)vid;
+  ::snprintf(text,sizeof(text), "%016llx", id);
   return text;
 }
 
diff --git a/DDCore/src/plugins/DetectorChecksum.cpp b/DDCore/src/plugins/DetectorChecksum.cpp
index aabf69f3b..e1bddc7c9 100644
--- a/DDCore/src/plugins/DetectorChecksum.cpp
+++ b/DDCore/src/plugins/DetectorChecksum.cpp
@@ -1220,19 +1220,19 @@ void DetectorChecksum::dump_detelements()   const   {
     printout(ALWAYS, "DetectorChecksum", "+++ Detelement %-32s    0x%016lx%s",
 	     de.name(), e.second.hash, debug > 2 ? ("\n"+e.second.data).c_str() : "");
     if ( de.path() == "/world" )   {
-      PlacedVolume pv = de.placement();
-      Volume        v = pv.volume();
-      Solid         s = v.solid();
-      const auto&  es = handleSolid(s);
-      const auto&  ev = handleVolume(v);
-      const auto&  ep = handlePlacement(pv);
+      PlacedVolume pv  = de.placement();
+      Volume       vol = pv.volume();
+      Solid        sol = vol.solid();
+      const auto&   es = handleSolid(sol);
+      const auto&   ev = handleVolume(vol);
+      const auto&   ep = handlePlacement(pv);
 
       printout(ALWAYS, "DetectorChecksum", "    Solid     %-32s    0x%016lx%s",
-	       s.name(),  es.hash, debug > 2 ? ("\n"+es.data).c_str() : "");
+	       sol.name(), es.hash, debug > 2 ? ("\n"+es.data).c_str() : "");
       printout(ALWAYS, "DetectorChecksum", "    Volume    %-32s    0x%016lx%s",
-	       v.name(),  ev.hash, debug > 2 ? ("\n"+ev.data).c_str() : "");
+	       vol.name(), ev.hash, debug > 2 ? ("\n"+ev.data).c_str() : "");
       printout(ALWAYS, "DetectorChecksum", "    Placement %-32s    0x%016lx%s",
-	       pv.name(), ep.hash, debug > 2 ? ("\n"+ep.data).c_str() : "");
+	       pv.name(),  ep.hash, debug > 2 ? ("\n"+ep.data).c_str() : "");
     }
   }
 }
diff --git a/DDDigi/include/DDDigi/DigiOutputAction.h b/DDDigi/include/DDDigi/DigiOutputAction.h
index 9931520bb..0dd117f36 100644
--- a/DDDigi/include/DDDigi/DigiOutputAction.h
+++ b/DDDigi/include/DDDigi/DigiOutputAction.h
@@ -63,10 +63,10 @@ namespace dd4hep {
       DigiOutputAction(const kernel_t& kernel, const std::string& nam);
 
       /// Initialization callback
-      virtual void initialize();
+      virtual void initialize()  override;
 
       /// Finalization callback
-      virtual void finalize();
+      virtual void finalize()  override;
 
       /// Check for valid output stream
       virtual bool have_output()  const = 0;
@@ -89,7 +89,7 @@ namespace dd4hep {
 
       /// Adopt new parallel worker acting on multiple containers
       virtual void adopt_processor(DigiContainerProcessor* action,
-                                   const std::vector<std::string>& containers);
+                                   const std::vector<std::string>& containers)  override;
 
       /// Callback to read event output
       virtual void execute(context_t& context)  const override;
diff --git a/DDDigi/plugins/DigiSegmentDepositPrint.cpp b/DDDigi/plugins/DigiSegmentDepositPrint.cpp
index ea250f1d6..fc8a082ef 100644
--- a/DDDigi/plugins/DigiSegmentDepositPrint.cpp
+++ b/DDDigi/plugins/DigiSegmentDepositPrint.cpp
@@ -33,37 +33,38 @@ namespace dd4hep {
     public:
       /// Standard constructor
       DigiSegmentDepositPrint(const DigiKernel& kernel, const std::string& nam)
-	: DigiContainerProcessor(kernel, nam) {}
+        : DigiContainerProcessor(kernel, nam) {}
 
       /// Single container printout
       template <typename T> void
       print(const char* fmt, const T& cont, const predicate_t& predicate)  const   {
-	for( const auto& dep : cont )   {
-	  if( predicate(dep) )   {
-	    info(fmt, predicate.segmentation->split_id(dep.first), dep.first,
-		 dep.second.history.hits.size(), 
-		 dep.second.history.particles.size(),
-		 dep.second.deposit);
-	  }
-	}
+        for( const auto& dep : cont )   {
+          if( predicate(dep) )   {
+            info(fmt, predicate.segmentation->split_id(dep.first), dep.first,
+                 dep.second.history.hits.size(), 
+                 dep.second.history.particles.size(),
+                 dep.second.deposit);
+          }
+        }
       }
 
       /// Main functional callback
       virtual void execute(DigiContext& context, work_t& work, const predicate_t& predicate)  const override final  {
-	char format[256];
-	::snprintf(format, sizeof(format), 
-		   "%s[%s] %s-id: %%d [processor:%d] Cell: %%016lX mask: %016lX  "
-		   "hist:%%4ld hits %%4ld parts. "
-		   "entries deposit: %%f", 
-		   context.event->id(),
-		   predicate.segmentation->idspec.name(), predicate.segmentation->cname(),
-		   predicate.id, predicate.segmentation->split_mask);
-	if ( const auto* m = work.get_input<DepositMapping>() )
-	  print(format, *m, predicate);
-	else if ( const auto* v = work.get_input<DepositVector>() )
-	  print(format, *v, predicate);
-	else
-	  error("+++ Request to dump an invalid container %s", Key::key_name(work.input.key).c_str());
+        using ulonglong = unsigned long long;
+        char format[256];
+        ::snprintf(format, sizeof(format), 
+                   "%s[%s] %s-id: %%d [processor:%d] Cell: %%016lX mask: %016llX  "
+                   "hist:%%4ld hits %%4ld parts. "
+                   "entries deposit: %%f", 
+                   context.event->id(),
+                   predicate.segmentation->idspec.name(), predicate.segmentation->cname(),
+                   predicate.id, ulonglong(predicate.segmentation->split_mask));
+        if ( const auto* m = work.get_input<DepositMapping>() )
+          print(format, *m, predicate);
+        else if ( const auto* v = work.get_input<DepositVector>() )
+          print(format, *v, predicate);
+        else
+          error("+++ Request to dump an invalid container %s", Key::key_name(work.input.key).c_str());
       }
     };
   }    // End namespace digi
diff --git a/DDG4/src/Geant4Data.cpp b/DDG4/src/Geant4Data.cpp
index 20961700c..f97c565f4 100644
--- a/DDG4/src/Geant4Data.cpp
+++ b/DDG4/src/Geant4Data.cpp
@@ -71,11 +71,11 @@ Geant4HitData::Contribution Geant4HitData::extractContribution(const G4Step* ste
     (h.trackDef() == G4OpticalPhoton::OpticalPhotonDefinition()) ? h.trkEnergy() : h.totalEnergy();
   const G4ThreeVector& pre   = h.prePosG4();
   const G4ThreeVector& post  = h.postPosG4();
-  G4ThreeVector        m     = h.track->GetMomentum();
+  G4ThreeVector        mom   = h.track->GetMomentum();
   double               len   = (post-pre).mag() ;
-  double               pos[] = { (pre.x()+post.x())/2.0,(pre.y()+post.y())/2.0,(pre.z()+post.z())/2.0 };
-  double               mom[] = { m.x(), m.y(), m.z() };
-  return Contribution(h.trkID(), h.trkPdgID(), deposit, h.trkTime(), len, pos, mom);
+  double               position[] = { (pre.x()+post.x())/2.0,(pre.y()+post.y())/2.0,(pre.z()+post.z())/2.0 };
+  double               momentum[] = { mom.x(), mom.y(), mom.z() };
+  return Contribution(h.trkID(), h.trkPdgID(), deposit, h.trkTime(), len, position, momentum);
 }
 
 /// Extract the MC contribution for a given hit from the step information with BirksLaw effect option
@@ -86,22 +86,22 @@ Geant4HitData::Contribution Geant4HitData::extractContribution(const G4Step* ste
     (h.trackDef() == G4OpticalPhoton::OpticalPhotonDefinition()) ? h.trkEnergy() : h.totalEnergy();
   const G4ThreeVector& pre  = h.prePosG4();
   const G4ThreeVector& post = h.postPosG4();
-  G4ThreeVector        m    = h.track->GetMomentum();
+  G4ThreeVector        mom  = h.track->GetMomentum();
   double length = (post-pre).mag() ;
-  double mom[] = { m.x(), m.y(), m.z() };
-  double pos[] = { (pre.x()+post.x())/2.0,(pre.y()+post.y())/2.0,(pre.z()+post.z())/2.0 };
-  return Contribution(h.trkID(), h.trkPdgID(), deposit, h.trkTime(), length, pos, mom);
+  double momentum[] = { mom.x(), mom.y(), mom.z() };
+  double position[] = { (pre.x()+post.x())/2.0,(pre.y()+post.y())/2.0,(pre.z()+post.z())/2.0 };
+  return Contribution(h.trkID(), h.trkPdgID(), deposit, h.trkTime(), length, position, momentum);
 }
 
 /// Extract the MC contribution for a given hit from the fast simulation spot information
 Geant4HitData::Contribution Geant4HitData::extractContribution(const Geant4FastSimSpot* spot) {
   Geant4FastSimHandler h(spot);
   const G4Track*       t = spot->primary;
-  G4ThreeVector        m = t->GetMomentum();
-  G4ThreeVector        p = h.avgPositionG4();
-  double               pos[] = { p.x(), p.y(), p.z() };
-  double               mom[] = { m.x(), m.y(), m.z() };
-  return Contribution( h.trkID(), h.trkPdgID(), h.energy(), h. trkTime(), 0e0, pos, mom);
+  G4ThreeVector        mom = t->GetMomentum();
+  G4ThreeVector        pos = h.avgPositionG4();
+  double               position[] = { pos.x(), pos.y(), pos.z() };
+  double               momentum[] = { mom.x(), mom.y(), mom.z() };
+  return Contribution( h.trkID(), h.trkPdgID(), h.energy(), h. trkTime(), 0e0, position, momentum);
 }
 
 /// Default constructor
diff --git a/examples/ClientTests/src/MiniTel.cpp b/examples/ClientTests/src/MiniTel.cpp
index f03ffd645..524b2a32c 100644
--- a/examples/ClientTests/src/MiniTel.cpp
+++ b/examples/ClientTests/src/MiniTel.cpp
@@ -85,8 +85,8 @@ static Ref_t create_detector(Detector &description, xml_h e, SensitiveDetector s
   Position     env_dim_min(sensor_box.x()+epsilon, sensor_box.y()+epsilon, +100000.0);
   Position     env_dim_max(sensor_box.x()+epsilon, sensor_box.y()+epsilon, -100000.0);
 
-  for( xml_coll_t m(x_det, _U(module_position)); m; m++ )    {
-    xml_comp_t x_pos = m;
+  for( xml_coll_t mod(x_det, _U(module_position)); mod; mod++ )    {
+    xml_comp_t x_pos = mod;
     if ( x_pos.z() > env_dim_max.z() ) {
       env_dim_max.SetZ(x_pos.z());
       printout(DEBUG,"MiniTel","Envelope z_max = %f",x_pos.z());
@@ -117,8 +117,8 @@ static Ref_t create_detector(Detector &description, xml_h e, SensitiveDetector s
   pv = assembly.placeVolume(side_vol, side_pos);
   pv.addPhysVolID("side",0);
   side_det.setPlacement(pv);
-  for( xml_coll_t m(x_det, _U(module_position)); m; m++ )    {
-    xml_comp_t x_pos = m;
+  for( xml_coll_t mpos(x_det, _U(module_position)); mpos; mpos++ )    {
+    xml_comp_t x_pos = mpos;
     DetElement module(side_det, _toString(count, "module_%d"), count);
     pv = side_vol.placeVolume(sensor_vol,Transform3D(Position(x_pos.x(),x_pos.y(),x_pos.z())));
     pv.addPhysVolID("module", ++count);
diff --git a/examples/DDG4/src/PropertyTestAction.cpp b/examples/DDG4/src/PropertyTestAction.cpp
index e18f7bea0..d256dce36 100644
--- a/examples/DDG4/src/PropertyTestAction.cpp
+++ b/examples/DDG4/src/PropertyTestAction.cpp
@@ -171,8 +171,8 @@ namespace {
     try  {
       stringstream log;
       log << "| " << setw(32) << left << tag << " ";
-      for(const auto& p : value)
-	log << setw(6) << left << p << "  ";
+      for(const auto& val : value)
+        log << setw(6) << left << val << "  ";
       _print(log);
     }
     catch(const exception& e)   {
@@ -186,7 +186,7 @@ namespace {
       stringstream log;
       log << "| " << setw(32) << left << tag << " ";
       for(const auto& p : value)
-	log << setw(6) << left << p.first << " = " << setw(10) << left << p.second << "  ";
+        log << setw(6) << left << p.first << " = " << setw(10) << left << p.second << "  ";
       _print(log);
     }
     catch(const exception& e)   {
-- 
GitLab