From 44015e1d44cca2fd338e831c24c8dfc45eb0b189 Mon Sep 17 00:00:00 2001
From: Siarhei Harkusha <Siarhei.Harkusha@cern.ch>
Date: Tue, 14 May 2019 11:28:07 +0200
Subject: [PATCH] TileByteStream: Clean up Tile ROD decoder

Tile ROD decoder has been cleaned up
from commented code and unused properties.
Additional properties have been added to set up
amplitude and time thresholds for parabolic amplitude correction.
Time thresholds have been set up to +/- 12.5ns by default (half bunch spacing).
All properties have been moved into hader file.
---
 .../TileByteStream/TileROD_Decoder.h          | 80 +++++++++----------
 .../TileByteStream/src/TileROD_Decoder.cxx    | 51 +++---------
 2 files changed, 46 insertions(+), 85 deletions(-)

diff --git a/TileCalorimeter/TileSvc/TileByteStream/TileByteStream/TileROD_Decoder.h b/TileCalorimeter/TileSvc/TileByteStream/TileByteStream/TileROD_Decoder.h
index bc1c4896c07..e7353766e23 100644
--- a/TileCalorimeter/TileSvc/TileByteStream/TileByteStream/TileROD_Decoder.h
+++ b/TileCalorimeter/TileSvc/TileByteStream/TileByteStream/TileROD_Decoder.h
@@ -500,30 +500,40 @@ class TileROD_Decoder: public AthAlgTool {
     TileRawChannel2Bytes m_rc2bytes;
     TileDigits2Bytes m_d2Bytes;
 
-//    std::string m_infoName; 
-
     const TileHWID* m_tileHWID;
-//    const TileInfo* m_tileInfo;
-
-    bool m_useFrag0;
-    bool m_useFrag1;
-    bool m_useFrag4;
-    bool m_useFrag5Raw;
-    bool m_useFrag5Reco;
-    bool m_ignoreFrag4HLT;
-
-    // thresholds for parabolic amplitude correction
-    float m_ampMinThresh; //!< correct amplitude if it's above amplitude threshold (in ADC counts)
-    float m_ampMinThresh_pC; //!< correct amplitude if it's above amplitude threshold (in pC)
-    float m_ampMinThresh_MeV; //!< correct amplitude if it's above amplitude threshold (in MeV)
-    float m_timeMinThresh; //!< correct amplitude is time is above time min threshold
-    float m_timeMaxThresh; //!< correct amplitude is time is below time max threshold
-    void updateAmpThreshold(float ampMinThresh);
 
-    // outsize this time withdow, all amplitudes taken from Reco fragment
-    // will be set to zero 
-    float m_allowedTimeMin; //!< set amp to zero if time is below allowed time min
-    float m_allowedTimeMax; //!< set amp to zero if time is above allowed time max
+    Gaudi::Property<bool> m_useFrag0{this, "useFrag0", true, "Use frag0"};
+    Gaudi::Property<bool> m_useFrag1{this, "useFrag1", true, "Use frag1"};
+    Gaudi::Property<bool> m_useFrag4{this, "useFrag4", true, "User frag4"};
+    Gaudi::Property<bool> m_useFrag5Raw{this, "useFrag5Raw", false, "Use frag5 raw"};
+    Gaudi::Property<bool> m_useFrag5Reco{this, "useFrag5Reco", false, "Use frag5 reco"};
+    Gaudi::Property<bool> m_ignoreFrag4HLT{this, "ignoreFrag4HLT", false, "Ignore frag4 HLT"};
+
+    // Outside this time withdow, all amplitudes taken from Reco fragment will be set to zero
+    Gaudi::Property<float> m_allowedTimeMin{this, "AllowedTimeMin", -50.0,
+        "Set amplitude to zero if time is below allowed time minimum"};
+    Gaudi::Property<float> m_allowedTimeMax{this, "AllowedTimeMax", 50.0,
+        "Set amplitude to zero if time is above allowed time maximum"};
+
+    // Thresholds for parabolic amplitude correction
+    Gaudi::Property<float> m_ampMinThresh{this, "AmpMinForAmpCorrection", 15.0,
+        "Correct amplitude if it's above amplitude threshold (in ADC counts)"};
+    Gaudi::Property<float> m_timeMinThresh{this, "TimeMinForAmpCorrection", -12.5,
+        "Correct amplitude is time is above time minimum threshold"};
+    Gaudi::Property<float> m_timeMaxThresh{this, "TimeMaxForAmpCorrection", 12.5,
+        "Correct amplitude is time is below time maximum threshold"};
+
+    Gaudi::Property<unsigned int> m_fullTileRODs{this, "fullTileMode", 320000,
+        "Run from which to take the cabling (for the moment, either 320000 - full 2017 mode (default) - or 0 - 2016 mode)"};
+
+    Gaudi::Property<bool> m_verbose{this, "VerboseOutput", false, "Print extra information"};
+    Gaudi::Property<bool> m_calibrateEnergy{this, "calibrateEnergy", true, "Convert ADC counts to pCb for RawChannels"};
+    Gaudi::Property<bool> m_suppressDummyFragments{this, "suppressDummyFragments", false, "Suppress dummy fragments"};
+    Gaudi::Property<bool> m_maskBadDigits{this, "maskBadDigits", false,
+        "Put -1 in digits vector for channels with bad BCID or CRC in unpack_frag0"};
+
+    Gaudi::Property<int> m_maxWarningPrint{this, "MaxWarningPrint", 1000, "Maximum warning messages to print"};
+    Gaudi::Property<int> m_maxErrorPrint{this, "MaxErrorPrint", 1000, "Maximum error messages to print"};
 
     ToolHandle<TileCondToolTiming> m_tileToolTiming{this,
         "TileCondToolTiming", "TileCondToolTiming", "Tile timing tool"};
@@ -536,6 +546,11 @@ class TileROD_Decoder: public AthAlgTool {
     ToolHandle<TileL2Builder> m_L2Builder{this,
         "TileL2Builder", "TileL2Builder", "Tile L2 builder tool"};
 
+    // thresholds for parabolic amplitude correction
+    float m_ampMinThresh_pC; //!< correct amplitude if it's above amplitude threshold (in pC)
+    float m_ampMinThresh_MeV; //!< correct amplitude if it's above amplitude threshold (in MeV)
+    void updateAmpThreshold();
+
     // OFWeights for different units and different drawers:
     // every element contains OFC for single drawer and one of 4 different units
     mutable std::vector<uint32_t> m_OFWeights[4 * TileCalibUtils::MAX_DRAWERIDX];
@@ -546,29 +561,13 @@ class TileROD_Decoder: public AthAlgTool {
     // Mutex protecting access to weight vectors.
     mutable std::mutex m_OFWeightMutex;
 
-    float m_TileCellEthreshold;
-    bool m_verbose;
-    bool m_suppressDummyFragments;
-    // next three are needed to handle automatic conversion digits->channels->cells,
-    // when HLT request for cells, and finds only digits.
-    //TileRawChannelBuilder* m_RCBuilder;
-    std::string m_TileDefaultChannelBuilder;
-    bool m_calibrateEnergy;
-    // next two are needed to handle automatic conversion channels->cells,
-    // when HLT request for cells,which are not normally present in ByteStream
-    // TileCellBuilder* m_CellBuilder;
-    std::string m_TileDefaultCellBuilder;
-
     // fast decoding
     std::vector<int> m_Rw2Cell[4];
     std::vector<int> m_Rw2Pmt[4];
 
     TileFragHash m_hashFunc;
-
     bool m_of2Default;
 
-    bool m_maskBadDigits;
-
     // FIXME: Non-MT safe members --- used only by trigger, not offline.
     // Pointer to a MBTS cell collection
     TileCellCollection* m_MBTS;
@@ -577,9 +576,6 @@ class TileROD_Decoder: public AthAlgTool {
     // index of the MBTS channel
     int m_MBTS_channel;
 
-    int m_maxWarningPrint;
-    int m_maxErrorPrint;
-
     mutable std::atomic<int> m_WarningCounter;
     mutable std::atomic<int> m_ErrorCounter;
 
@@ -592,8 +588,6 @@ class TileROD_Decoder: public AthAlgTool {
     void initTileMuRcvHid2re();
 
     unsigned int m_maxChannels;
-    unsigned int m_fullTileRODs;
-
     bool m_checkMaskedDrawers;
 
     const uint32_t * get_data(const ROBData * rob) const {
diff --git a/TileCalorimeter/TileSvc/TileByteStream/src/TileROD_Decoder.cxx b/TileCalorimeter/TileSvc/TileByteStream/src/TileROD_Decoder.cxx
index fd42ec9e601..39ca1ec0eb0 100644
--- a/TileCalorimeter/TileSvc/TileByteStream/src/TileROD_Decoder.cxx
+++ b/TileCalorimeter/TileSvc/TileByteStream/src/TileROD_Decoder.cxx
@@ -33,41 +33,15 @@ static const InterfaceID IID_ITileROD_Decoder("TileROD_Decoder", 1, 0);
 TileROD_Decoder::TileROD_Decoder(const std::string& type, const std::string& name,
                                  const IInterface* parent)
   : AthAlgTool(type, name, parent)
-  , m_hid2re(0)
-  , m_hid2reHLT(0)
+  , m_of2Default(true)
+  , m_MBTS(nullptr)
+  , m_hid2re(nullptr)
+  , m_hid2reHLT(nullptr)
   , m_maxChannels(TileCalibUtils::MAX_CHAN)
-  , m_fullTileRODs(320000) // default 2017 full mode
   , m_checkMaskedDrawers(false)
 {
   declareInterface<TileROD_Decoder>(this);
-  
-  declareProperty("useFrag0", m_useFrag0 = true);
-  declareProperty("useFrag1", m_useFrag1 = true);
-  declareProperty("useFrag4", m_useFrag4 = true);
-  declareProperty("useFrag5Raw", m_useFrag5Raw = false);
-  declareProperty("useFrag5Reco", m_useFrag5Reco = false);
-  declareProperty("ignoreFrag4HLT", m_ignoreFrag4HLT = false);
-  
-  declareProperty("TileCellEthresholdMeV", m_TileCellEthreshold = -100000.);
-  declareProperty("TileDefaultChannelBuilder", m_TileDefaultChannelBuilder = "TileRawChannelBuilderFlatFilter/TileROD_RCBuilder");
-
-  declareProperty("VerboseOutput", m_verbose = false);
-  declareProperty("calibrateEnergy", m_calibrateEnergy = true); // convert ADC counts to pCb for RawChannels
-  declareProperty("suppressDummyFragments", m_suppressDummyFragments = false);
-  declareProperty("maskBadDigits", m_maskBadDigits = false); // put -1 in digits vector for channels with bad BCID or CRC in unpack_frag0
-  declareProperty("MaxWarningPrint", m_maxWarningPrint = 1000);
-  declareProperty("MaxErrorPrint", m_maxErrorPrint = 100);
-
-  declareProperty("AllowedTimeMin", m_allowedTimeMin = -50.); // set amp to zero if time is below allowed time min
-  declareProperty("AllowedTimeMax", m_allowedTimeMax =  50.); // set amp to zero if time is above allowed time max
-  declareProperty("fullTileMode", m_fullTileRODs); // run from which to take the cabling (for the moment, either 320000 - full 2017 mode - or 0 - 2016 mode)
-
-  updateAmpThreshold(15.);
-  m_timeMinThresh = -25;
-  m_timeMaxThresh = 25;
-
-  m_of2Default = true;
-  m_MBTS = NULL;
+
   m_WarningCounter = 0;
   m_ErrorCounter = 0;
   
@@ -76,8 +50,7 @@ TileROD_Decoder::TileROD_Decoder(const std::string& type, const std::string& nam
   }
 }
 
-void TileROD_Decoder::updateAmpThreshold(float ampMinThresh) {
-  m_ampMinThresh = ampMinThresh;
+void TileROD_Decoder::updateAmpThreshold() {
   m_ampMinThresh_pC = m_ampMinThresh * (12.5 / 1023.);
   m_ampMinThresh_MeV = m_ampMinThresh * (12.5 / 1023. / 1.05 * 1000.);
 }
@@ -115,6 +88,8 @@ int TileROD_Decoder::getErrorCounter() {
 
 StatusCode TileROD_Decoder::initialize() {
   
+  updateAmpThreshold();
+
   m_rc2bytes5.setVerbose(m_verbose);
   m_rc2bytes2.setVerbose(m_verbose);
   m_rc2bytes.setVerbose(m_verbose);
@@ -145,14 +120,6 @@ StatusCode TileROD_Decoder::initialize() {
     ATH_CHECK( m_tileBadChanTool.retrieve() );
   }
 
-  // Get Tool to TileChannelBuilder, to be used to convert automatically digits->channels.
-  //ATH_MSG_DEBUG( "creating algtool " << m_TileDefaultChannelBuilder );
-  //ListItem algRC(m_TileDefaultChannelBuilder);
-  //ATH_CHECK( toolSvc->retrieveTool(algRC.type(), algRC.name(), m_RCBuilder, this) );
-  
-  //ATH_MSG_DEBUG( "algtool " << m_TileDefaultChannelBuilder << " created " );
-  //ATH_CHECK( m_RCBuilder->setProperty(BooleanProperty("calibrateEnergy", m_calibrateEnergy)) );
-  
   m_maxChannels = TileCablingService::getInstance()->getMaxChannels();
 
   m_Rw2Cell[0].reserve(m_maxChannels);
@@ -3530,7 +3497,7 @@ uint32_t TileROD_Decoder::make_copyHLT(bool of2,
       ATH_MSG_ERROR("TileROD_Decderr::make_copyHLT is not MT-safe but used in "
                     "a MT job.  Results will likely be wrong.");
     }
-    if (m_MBTS != NULL && MBTS_chan >= 0) {
+    if (m_MBTS && MBTS_chan >= 0) {
       auto it = m_mapMBTS.find (frag_id);
       unsigned int idx = it != m_mapMBTS.end() ? it->second : 0u;
       if (idx < (*m_MBTS).size()) { // MBTS present (always last channel)
-- 
GitLab