From 609e5e080f5bd899709b200279088e61607f4757 Mon Sep 17 00:00:00 2001
From: Florian Uhlig <f.uhlig@gsi.de>
Date: Fri, 30 Jul 2021 11:17:09 +0200
Subject: [PATCH] Adapt code to new FairModule function

From FairRoot version v18.4.0 on the function CheckIfSensitive() of the class
FairModule is deprecated and replaced by the function IsSensitive(). The old
function is still available but usage results is a compilation error.
To be able to use FairRoot v18.2.1 and newer versions both functions are
implemented in the CbmRoot code where the old function simply forwards to the
new one. If there is no need to support older FairRoot versions the old
function can be simply removed from the source code.
---
 core/base/CMakeLists.txt             |  7 +++++++
 core/base/utils/CbmGeometryUtils.cxx |  4 ++++
 mvd/CbmMvd.cxx                       |  4 ++--
 mvd/CbmMvd.h                         |  1 +
 sim/detectors/much/CbmMuch.cxx       |  4 +++-
 sim/detectors/much/CbmMuch.h         |  1 +
 sim/detectors/psd/CbmPsdMC.h         | 11 ++++++++++-
 sim/detectors/rich/CbmRich.cxx       |  4 +++-
 sim/detectors/rich/CbmRich.h         |  1 +
 sim/detectors/sts/CbmStsMC.h         |  3 ++-
 sim/detectors/tof/CbmTof.cxx         |  5 ++++-
 sim/detectors/tof/CbmTof.h           |  4 +++-
 sim/detectors/trd/CbmTrd.cxx         |  4 +++-
 sim/detectors/trd/CbmTrd.h           |  1 +
 sim/passive/CbmMagnet.cxx            |  4 +++-
 sim/passive/CbmMagnet.h              |  1 +
 16 files changed, 49 insertions(+), 10 deletions(-)

diff --git a/core/base/CMakeLists.txt b/core/base/CMakeLists.txt
index b67dbdd8c2..225973166c 100644
--- a/core/base/CMakeLists.txt
+++ b/core/base/CMakeLists.txt
@@ -60,6 +60,13 @@ utils/CbmMediaList.cxx
 utils/CbmFileUtils.cxx
 )
 
+
+If(${FairRoot_VERSION} VERSION_LESS 18.4.0)
+  set_source_files_properties(utils/CbmGeometryUtils.cxx
+                              PROPERTIES COMPILE_DEFINITIONS OLD_MODULE_VERSION
+                             )
+EndIf()
+
 Set(LINKDEF CbmBaseLinkDef.h)
 Set(LIBRARY_NAME CbmBase)
 Set(DEPENDENCIES
diff --git a/core/base/utils/CbmGeometryUtils.cxx b/core/base/utils/CbmGeometryUtils.cxx
index 396877171f..cf094b6162 100644
--- a/core/base/utils/CbmGeometryUtils.cxx
+++ b/core/base/utils/CbmGeometryUtils.cxx
@@ -326,7 +326,11 @@ namespace Cbm
         if (fNode->GetNdaughters() > 0) { Cbm::GeometryUtils::ExpandNodes(v, mod); }
         Cbm::GeometryUtils::AssignMediumAtImport(v);
 
+#ifdef OLD_MODULE_VERSION
         if ((mod->InheritsFrom("FairDetector")) && mod->CheckIfSensitive(v->GetName())) {
+#else
+        if ((mod->InheritsFrom("FairDetector")) && mod->IsSensitive(v->GetName())) {
+#endif
           LOG(debug) << "Module " << v->GetName() << " of detector " << mod->GetName() << " is sensitive";
           mod->AddSensitiveVolume(v);
         }
diff --git a/mvd/CbmMvd.cxx b/mvd/CbmMvd.cxx
index d141143365..ced259652a 100644
--- a/mvd/CbmMvd.cxx
+++ b/mvd/CbmMvd.cxx
@@ -266,7 +266,7 @@ CbmMvdPoint* CbmMvd::AddHit(Int_t trackID, Int_t pdg, Int_t sensorNr, TVector3 p
 }
 // ----------------------------------------------------------------------------
 
-Bool_t CbmMvd::CheckIfSensitive(std::string name)
+Bool_t CbmMvd::IsSensitive(const std::string& name)
 {
   TString tsname = name;
   if (tsname.Contains("sensorActive") || tsname.Contains("MimosaActive")
@@ -282,8 +282,8 @@ Bool_t CbmMvd::CheckIfSensitive(std::string name)
   }
   return kFALSE;
 }
-// ----------------------------------------------------------------------------
 
+Bool_t CbmMvd::CheckIfSensitive(std::string name) { return IsSensitive(name); }
 // ----------------------------------------------------------------------------
 
 
diff --git a/mvd/CbmMvd.h b/mvd/CbmMvd.h
index 229e1c5ede..a377ddc998 100644
--- a/mvd/CbmMvd.h
+++ b/mvd/CbmMvd.h
@@ -125,6 +125,7 @@ public:
 
   virtual void ConstructRootGeometry(TGeoMatrix* shift = NULL);
 
+  virtual Bool_t IsSensitive(const std::string& name);
   virtual Bool_t CheckIfSensitive(std::string name);
 
   virtual map<Int_t, Int_t> GetMap() { return fStationMap; };
diff --git a/sim/detectors/much/CbmMuch.cxx b/sim/detectors/much/CbmMuch.cxx
index 5aa36c382b..73b4c08643 100644
--- a/sim/detectors/much/CbmMuch.cxx
+++ b/sim/detectors/much/CbmMuch.cxx
@@ -387,7 +387,7 @@ void CbmMuch::ConstructRootGeometry(TGeoMatrix*)
 
 
 // -----   CheckIfSensitive   -------------------------------------------------
-Bool_t CbmMuch::CheckIfSensitive(std::string name)
+Bool_t CbmMuch::IsSensitive(const std::string& name)
 {
   TString tsname = name;
 
@@ -398,3 +398,5 @@ Bool_t CbmMuch::CheckIfSensitive(std::string name)
   }
   return kFALSE;
 }
+
+Bool_t CbmMuch::CheckIfSensitive(std::string name) { return IsSensitive(name); }
diff --git a/sim/detectors/much/CbmMuch.h b/sim/detectors/much/CbmMuch.h
index 48c914ac93..a69580af62 100644
--- a/sim/detectors/much/CbmMuch.h
+++ b/sim/detectors/much/CbmMuch.h
@@ -112,6 +112,7 @@ public:
   virtual void ConstructGeometry();
   virtual void ConstructRootGeometry(TGeoMatrix* shift = NULL);
   Bool_t CheckIfSensitive(std::string name);
+  virtual Bool_t IsSensitive(const std::string& name);
 
 private:
   /** Track information to be stored until the track leaves the
diff --git a/sim/detectors/psd/CbmPsdMC.h b/sim/detectors/psd/CbmPsdMC.h
index 3b8da1f3c1..602a809ac8 100644
--- a/sim/detectors/psd/CbmPsdMC.h
+++ b/sim/detectors/psd/CbmPsdMC.h
@@ -52,11 +52,20 @@ public:
    ** The decision is based on the volume name (has to contain "scint").
    ** Virtual from FairModule.
    **/
-  virtual Bool_t CheckIfSensitive(std::string name)
+  virtual Bool_t IsSensitive(const std::string& name)
   {
     return (TString(name).Contains("scint", TString::kIgnoreCase) ? kTRUE : kFALSE);
   }
 
+  /** @brief Check whether a volume is sensitive.
+   ** @param(name)  Volume name
+   ** @value        kTRUE if volume is sensitive, else kFALSE
+   **
+   ** The decision is based on the volume name (has to contain "scint").
+   ** Virtual from FairModule.
+   **/
+  virtual Bool_t CheckIfSensitive(std::string name) { return IsSensitive(name); }
+
 
   /** @brief Construct the PSD geometry in the TGeoManager.
    **
diff --git a/sim/detectors/rich/CbmRich.cxx b/sim/detectors/rich/CbmRich.cxx
index 10760f91e5..011304952a 100644
--- a/sim/detectors/rich/CbmRich.cxx
+++ b/sim/detectors/rich/CbmRich.cxx
@@ -88,7 +88,7 @@ CbmRich::~CbmRich()
 
 void CbmRich::Initialize() { FairDetector::Initialize(); }
 
-Bool_t CbmRich::CheckIfSensitive(std::string name)
+Bool_t CbmRich::IsSensitive(const std::string& name)
 {
   //return true;
   TString volName = name;
@@ -98,6 +98,8 @@ Bool_t CbmRich::CheckIfSensitive(std::string name)
   return kFALSE;
 }
 
+Bool_t CbmRich::CheckIfSensitive(std::string name) { return IsSensitive(name); }
+
 
 Bool_t CbmRich::ProcessHits(FairVolume* vol)
 {
diff --git a/sim/detectors/rich/CbmRich.h b/sim/detectors/rich/CbmRich.h
index d84ec6e625..a057a51915 100644
--- a/sim/detectors/rich/CbmRich.h
+++ b/sim/detectors/rich/CbmRich.h
@@ -163,6 +163,7 @@ public:
     ** @value        kTRUE if volume is sensitive, else kFALSE
     **/
   virtual Bool_t CheckIfSensitive(std::string name);
+  virtual Bool_t IsSensitive(const std::string& name);
 
   /*
     * \brief set fRegisterPhotonsOnSensitivePlane parameter
diff --git a/sim/detectors/sts/CbmStsMC.h b/sim/detectors/sts/CbmStsMC.h
index f96e3ae0da..1066a7787d 100644
--- a/sim/detectors/sts/CbmStsMC.h
+++ b/sim/detectors/sts/CbmStsMC.h
@@ -59,7 +59,8 @@ public:
 		 ** The decision is based on the volume name (has to contain "Sensor").
 		 ** Virtual from FairModule.
 		 **/
-  virtual Bool_t CheckIfSensitive(std::string name) { return (TString(name).Contains("Sensor") ? kTRUE : kFALSE); }
+  virtual Bool_t IsSensitive(const std::string& name) { return (TString(name).Contains("Sensor") ? kTRUE : kFALSE); }
+  virtual Bool_t CheckIfSensitive(std::string name) { return IsSensitive(name); }
 
 
   /** @brief Construct the STS geometry in the TGeoManager.
diff --git a/sim/detectors/tof/CbmTof.cxx b/sim/detectors/tof/CbmTof.cxx
index c9eba6624f..77e8381338 100644
--- a/sim/detectors/tof/CbmTof.cxx
+++ b/sim/detectors/tof/CbmTof.cxx
@@ -543,7 +543,7 @@ void CbmTof::CreateInBeamNodes()
 // -------------------------------------------------------------------------
 
 // -----   Private method CheckIfSensitive   -------------------------------
-Bool_t CbmTof::CheckIfSensitive(std::string name)
+Bool_t CbmTof::IsSensitive(const std::string& name)
 {
   // If the current Cell volume belongs to a counter declared inactive w.r.t.
   // Monte Carlo point creation, it is not declared sensitive
@@ -561,6 +561,9 @@ Bool_t CbmTof::CheckIfSensitive(std::string name)
   }
   return kFALSE;
 }
+
+Bool_t CbmTof::CheckIfSensitive(std::string name) { return IsSensitive(name); }
+
 // -------------------------------------------------------------------------
 
 
diff --git a/sim/detectors/tof/CbmTof.h b/sim/detectors/tof/CbmTof.h
index 1b415d1d6d..fcce68b61c 100644
--- a/sim/detectors/tof/CbmTof.h
+++ b/sim/detectors/tof/CbmTof.h
@@ -145,6 +145,9 @@ public:
      **/
   void SetCounterInBeam(Int_t iModuleType, Int_t iModuleIndex, Int_t iCounterIndex);
 
+  Bool_t CheckIfSensitive(std::string name);
+  virtual Bool_t IsSensitive(const std::string& name);
+
 private:
   /** Track information to be stored until the track leaves the
       active volume. **/
@@ -199,7 +202,6 @@ private:
    **/
   void ResetParameters();
 
-  Bool_t CheckIfSensitive(std::string name);
 
   virtual void ConstructRootGeometry(TGeoMatrix* shift = NULL);
 
diff --git a/sim/detectors/trd/CbmTrd.cxx b/sim/detectors/trd/CbmTrd.cxx
index a512f5e57b..907d2a6101 100644
--- a/sim/detectors/trd/CbmTrd.cxx
+++ b/sim/detectors/trd/CbmTrd.cxx
@@ -321,7 +321,7 @@ void CbmTrd::ConstructRootGeometry(TGeoMatrix*)
 }
 
 // -----   CheckIfSensitive   -------------------------------------------------
-Bool_t CbmTrd::CheckIfSensitive(std::string name)
+Bool_t CbmTrd::IsSensitive(const std::string& name)
 {
   TString tsname = name;
   if (tsname.EqualTo("gas")) {
@@ -332,4 +332,6 @@ Bool_t CbmTrd::CheckIfSensitive(std::string name)
 }
 // ----------------------------------------------------------------------------
 
+Bool_t CbmTrd::CheckIfSensitive(std::string name) { return IsSensitive(name); }
+
 ClassImp(CbmTrd)
diff --git a/sim/detectors/trd/CbmTrd.h b/sim/detectors/trd/CbmTrd.h
index a14eca8790..c33da858ba 100644
--- a/sim/detectors/trd/CbmTrd.h
+++ b/sim/detectors/trd/CbmTrd.h
@@ -99,6 +99,7 @@ public:
   virtual void ConstructGeometry();
 
   Bool_t CheckIfSensitive(std::string name);
+  virtual Bool_t IsSensitive(const std::string& name);
 
   void UseGlobalPhysicsProcesses(Bool_t use) { fUseGlobalPhysicsProcesses = use; }
 
diff --git a/sim/passive/CbmMagnet.cxx b/sim/passive/CbmMagnet.cxx
index 3e13fdc1be..f4c9de85e5 100644
--- a/sim/passive/CbmMagnet.cxx
+++ b/sim/passive/CbmMagnet.cxx
@@ -65,11 +65,13 @@ void CbmMagnet::ConstructGeometry()
   }
 }
 
-Bool_t CbmMagnet::CheckIfSensitive(std::string)
+Bool_t CbmMagnet::IsSensitive(const std::string&)
 {
   // There are no sensitive volumes in the magnet
   return kFALSE;
 }
 
+Bool_t CbmMagnet::CheckIfSensitive(std::string name) { return IsSensitive(name); }
+
 
 ClassImp(CbmMagnet)
diff --git a/sim/passive/CbmMagnet.h b/sim/passive/CbmMagnet.h
index f6f6288f3d..930cd7c6c5 100644
--- a/sim/passive/CbmMagnet.h
+++ b/sim/passive/CbmMagnet.h
@@ -18,6 +18,7 @@ public:
   virtual ~CbmMagnet();
   virtual void ConstructGeometry();
 
+  virtual Bool_t IsSensitive(const std::string& name);
   Bool_t CheckIfSensitive(std::string name);
 
 private:
-- 
GitLab