diff --git a/Calorimeter/CaloClusterCorrection/python/CaloSwDeadOTX_back.py b/Calorimeter/CaloClusterCorrection/python/CaloSwDeadOTX_back.py
index b07e14d78e215856996adde7bb80b90a12d3c755..4ff5bb36e6ff9ef290b076885c0d46024a1744b8 100755
--- a/Calorimeter/CaloClusterCorrection/python/CaloSwDeadOTX_back.py
+++ b/Calorimeter/CaloClusterCorrection/python/CaloSwDeadOTX_back.py
@@ -55,10 +55,8 @@ def make_CaloSwDeadOTX_back(name = None,
                     confclass = None,
                     **kw):
 
-    from CaloTools.CaloAffectedToolDefault import CaloAffectedToolDefault
-    theAffectedTool = CaloAffectedToolDefault()
-    from AthenaCommon.AppMgr import ToolSvc
-    ToolSvc += theAffectedTool
+    from CaloTools.CaloToolsConf import CaloAffectedTool
+    theAffectedTool = CaloAffectedTool("CaloAffectedForDeadOTX_back")
 
     # Make the tool.
     return makecorr (versions  = CaloSwDeadOTX_back_versions,
diff --git a/Calorimeter/CaloClusterCorrection/python/CaloSwDeadOTX_ps.py b/Calorimeter/CaloClusterCorrection/python/CaloSwDeadOTX_ps.py
index 0cc786e0daf41b8a39cd84db19dba9e80130b7e7..2a29c68f2366fa3047188a398c6e325913f37cc3 100755
--- a/Calorimeter/CaloClusterCorrection/python/CaloSwDeadOTX_ps.py
+++ b/Calorimeter/CaloClusterCorrection/python/CaloSwDeadOTX_ps.py
@@ -55,10 +55,8 @@ def make_CaloSwDeadOTX_ps(name = None,
                     confclass = None,
                     **kw):
 
-    from CaloTools.CaloAffectedToolDefault import CaloAffectedToolDefault
-    theAffectedTool = CaloAffectedToolDefault()
-    from AthenaCommon.AppMgr import ToolSvc
-    ToolSvc += theAffectedTool
+    from CaloTools.CaloToolsConf import CaloAffectedTool
+    theAffectedTool = CaloAffectedTool("CaloAffectedToolForDeadOTX_ps")
 
     # Make the tool.
     return makecorr (versions     = CaloSwDeadOTX_ps_versions,
diff --git a/Calorimeter/CaloClusterCorrection/src/CaloSwDeadOTX_back.cxx b/Calorimeter/CaloClusterCorrection/src/CaloSwDeadOTX_back.cxx
index 3927c83ca633db52ddca2818cb3d445a6233e6f7..3b1650e85639734737abde34894255db001baa47 100755
--- a/Calorimeter/CaloClusterCorrection/src/CaloSwDeadOTX_back.cxx
+++ b/Calorimeter/CaloClusterCorrection/src/CaloSwDeadOTX_back.cxx
@@ -33,8 +33,7 @@ CaloSwDeadOTX_back::CaloSwDeadOTX_back
   (const std::string& type,
    const std::string& name,
    const IInterface* parent)
-   : CaloClusterCorrectionCommon(type, name, parent) , 
-         m_affectedTool("CaloAffectedTool")
+   : CaloClusterCorrectionCommon(type, name, parent) 
 {
    declareConstant("correction"      , m_correction);
    declareConstant("sampling_depth"  , m_sampling_depth);
@@ -42,7 +41,6 @@ CaloSwDeadOTX_back::CaloSwDeadOTX_back
    declareConstant("eta_end_crack"   , m_eta_end_crack);
    declareConstant("etamax"          , m_etamax);
    declareConstant("use_raw_eta"     , m_use_raw_eta);
-   declareProperty("affectedTool"    , m_affectedTool); 
 }
 
 StatusCode CaloSwDeadOTX_back::initialize()
@@ -53,7 +51,8 @@ StatusCode CaloSwDeadOTX_back::initialize()
   // the template in AlgTool.
   //  CHECK( setProperty ("isDummy", std::string("1")) );
 
-  
+  ATH_CHECK(m_affKey.initialize());
+
   ATH_MSG_DEBUG( " --------------->>>>> CaloSwDeadOTX_back :: retrieving affectedTool" << endmsg);
 
   if (m_affectedTool.retrieve().isFailure()){
@@ -67,7 +66,7 @@ StatusCode CaloSwDeadOTX_back::initialize()
 }
 
 void CaloSwDeadOTX_back::makeTheCorrection
-   (const EventContext& /*ctx*/,
+   (const EventContext& ctx,
     CaloCluster* cluster,
     const CaloDetDescrElement* /*elt*/,
     float eta,
@@ -80,6 +79,13 @@ void CaloSwDeadOTX_back::makeTheCorrection
 // ??? In principle, we should use adj_eta for the interpolation
 //     and range checks.  However, the v2 corrections were derived
 //     using regular eta instead.
+//
+   //Get affected info for this event
+   SG::ReadCondHandle<CaloAffectedRegionInfoVec> affHdl{m_affKey,ctx};
+   const CaloAffectedRegionInfoVec* affCont=*affHdl;
+   if(!affCont) {
+     ATH_MSG_WARNING("Do not have affected regions info, is this expected ?");
+   }
 
    float the_aeta;
    if (m_use_raw_eta)
@@ -129,10 +135,8 @@ void CaloSwDeadOTX_back::makeTheCorrection
    float dphi = 0.025;     
 
    int layer = si * 4 + 3 ;
-   bool check = m_affectedTool->isAffected(cluster ,deta , dphi ,layer,layer,0) ; //  check dead OTX in barrel PS 
+   bool check = m_affectedTool->isAffected(cluster, affCont, deta , dphi ,layer,layer,0) ; //  check dead OTX in barrel PS 
 
-// bool checke = m_affectedTool->isAffected(cluster ,deta , dphi ,4,4,0) ; //  check dead OTX in endcap PS 
-// bool checkb = m_affectedTool->isAffected(cluster ,deta , dphi ,0,0,0) ; //  check dead OTX in barrel PS 
  
 // if a cluster is in an affected region set the back energy to zero else return
 
diff --git a/Calorimeter/CaloClusterCorrection/src/CaloSwDeadOTX_back.h b/Calorimeter/CaloClusterCorrection/src/CaloSwDeadOTX_back.h
index 5ad5618d1b81749d81575448b72233a4d3056693..412f989651614c20880017c20552d99b8ea0b362 100755
--- a/Calorimeter/CaloClusterCorrection/src/CaloSwDeadOTX_back.h
+++ b/Calorimeter/CaloClusterCorrection/src/CaloSwDeadOTX_back.h
@@ -15,6 +15,7 @@ PACKAGE:  offline/Calorimeter/CaloClusterCorrection
 #include "CaloInterface/ICaloAffectedTool.h"
 #include "CaloClusterCorrection/CaloClusterCorrectionCommon.h"
 #include "CaloConditions/Array.h"
+#include "CaloConditions/CaloAffectedRegionInfoVec.h"
 
 class CaloSwDeadOTX_back : public CaloClusterCorrectionCommon
 {
@@ -57,8 +58,10 @@ public:
 
  private:
 
-  //  std::string m_affectedTool;
-  ToolHandle<ICaloAffectedTool> m_affectedTool;
+  SG::ReadCondHandleKey<CaloAffectedRegionInfoVec> m_affKey{this,
+    "LArAffectedRegionKey", "LArAffectedRegionInfo", "SG key for affected regions cond object"};
+
+  ToolHandle<ICaloAffectedTool> m_affectedTool{this, "AffectedTool", "CaloAffectedTool", "affected tool instance"};
   
   CaloRec::Array<3>     m_correction;
   CaloRec::Array<2>     m_sampling_depth;
diff --git a/Calorimeter/CaloClusterCorrection/src/CaloSwDeadOTX_ps.cxx b/Calorimeter/CaloClusterCorrection/src/CaloSwDeadOTX_ps.cxx
index 7f04ef73729dc65390a50ea89b8a03ab8bbbf111..907e6cb861317ca3011ea82e84f71f3a6d15a9d4 100755
--- a/Calorimeter/CaloClusterCorrection/src/CaloSwDeadOTX_ps.cxx
+++ b/Calorimeter/CaloClusterCorrection/src/CaloSwDeadOTX_ps.cxx
@@ -32,8 +32,7 @@ CaloSwDeadOTX_ps::CaloSwDeadOTX_ps
   (const std::string& type,
    const std::string& name,
    const IInterface* parent)
-   : CaloClusterCorrectionCommon(type, name, parent) ,
-        m_affectedTool("CaloAffectedTool")
+   : CaloClusterCorrectionCommon(type, name, parent) 
 {
    declareConstant("correction"      , m_correction);
    declareConstant("sampling_depth"  , m_sampling_depth);
@@ -41,7 +40,6 @@ CaloSwDeadOTX_ps::CaloSwDeadOTX_ps
    declareConstant("eta_end_crack"   , m_eta_end_crack);
    declareConstant("etamax"          , m_etamax);
    declareConstant("use_raw_eta"     , m_use_raw_eta);
-   declareProperty("affectedTool"    , m_affectedTool); 
 }
 
 StatusCode CaloSwDeadOTX_ps::initialize()
@@ -52,6 +50,7 @@ StatusCode CaloSwDeadOTX_ps::initialize()
   // the template in AlgTool.
   //  CHECK( setProperty ("isDummy", std::string("1")) );
 
+  ATH_CHECK(m_affKey.initialize());
 
   ATH_MSG_DEBUG( " --------------->>>>> CaloSwDeadOTX_ps :: retrieving affectedTool" << endmsg);
 
@@ -66,7 +65,7 @@ StatusCode CaloSwDeadOTX_ps::initialize()
 }
 
 void CaloSwDeadOTX_ps::makeTheCorrection
-   (const EventContext& /*ctx*/,
+   (const EventContext& ctx,
     CaloCluster* cluster,
     const CaloDetDescrElement* /*elt*/,
     float eta,
@@ -80,6 +79,13 @@ void CaloSwDeadOTX_ps::makeTheCorrection
 //     and range checks.  However, the v2 corrections were derived
 //     using regular eta instead.
 
+   //Get affected info for this event
+   SG::ReadCondHandle<CaloAffectedRegionInfoVec> affHdl{m_affKey,ctx};
+   const CaloAffectedRegionInfoVec* affCont=*affHdl;
+   if(!affCont) {
+     ATH_MSG_WARNING("Do not have affected regions info, is this expected ?");
+   }
+
    float the_aeta;
    if (m_use_raw_eta)
       the_aeta = std::abs (adj_eta);
@@ -129,10 +135,8 @@ void CaloSwDeadOTX_ps::makeTheCorrection
    float dphi = 0.025;     
 
    int layer = si * 4 ;
-   bool check = m_affectedTool->isAffected(cluster ,deta , dphi ,layer,layer,0) ; //  check dead OTX in barrel PS 
+   bool check = m_affectedTool->isAffected(cluster, affCont, deta , dphi ,layer,layer,0) ; //  check dead OTX in barrel PS 
 
-// bool checke = m_affectedTool->isAffected(cluster ,deta , dphi ,4,4,0) ; //  check dead OTX in endcap PS 
-// bool checkb = m_affectedTool->isAffected(cluster ,deta , dphi ,0,0,0) ; //  check dead OTX in barrel PS 
  
 // if a cluster is in an affected region set the PS energy to zero else return
 
diff --git a/Calorimeter/CaloClusterCorrection/src/CaloSwDeadOTX_ps.h b/Calorimeter/CaloClusterCorrection/src/CaloSwDeadOTX_ps.h
index f6c540b195ccfb3feca83a80939c4cce0e9ab59d..fe5185fe7c859455f4d09cc11d862c2412125fa4 100755
--- a/Calorimeter/CaloClusterCorrection/src/CaloSwDeadOTX_ps.h
+++ b/Calorimeter/CaloClusterCorrection/src/CaloSwDeadOTX_ps.h
@@ -15,6 +15,7 @@ PACKAGE:  offline/Calorimeter/CaloClusterCorrection
 #include "CaloInterface/ICaloAffectedTool.h"
 #include "CaloClusterCorrection/CaloClusterCorrectionCommon.h"
 #include "CaloConditions/Array.h"
+#include "CaloConditions/CaloAffectedRegionInfoVec.h"
 
 class CaloSwDeadOTX_ps : public CaloClusterCorrectionCommon
 {
@@ -57,8 +58,9 @@ public:
 
  private:
 
-  //  std::string m_affectedTool;
-  ToolHandle<ICaloAffectedTool> m_affectedTool;
+  SG::ReadCondHandleKey<CaloAffectedRegionInfoVec> m_affKey{this,
+     "LArAffectedRegionKey", "LArAffectedRegionInfo", "SG key for affected regions cond object"};
+  ToolHandle<ICaloAffectedTool> m_affectedTool{this, "AffectedTool", "CaloAffectedTool", "affected tool instance"};
   
   CaloRec::Array<3>     m_correction;
   CaloRec::Array<2>     m_sampling_depth;
diff --git a/Calorimeter/CaloConditions/CaloConditions/CaloAffectedRegionInfoVec.h b/Calorimeter/CaloConditions/CaloConditions/CaloAffectedRegionInfoVec.h
index 280145efd594b9a217139e30b6cf27b0f9230823..1e4a6c60d25f2d7e79c75de21133d1365ca6ef53 100644
--- a/Calorimeter/CaloConditions/CaloConditions/CaloAffectedRegionInfoVec.h
+++ b/Calorimeter/CaloConditions/CaloConditions/CaloAffectedRegionInfoVec.h
@@ -12,5 +12,5 @@ typedef std::vector<CaloAffectedRegionInfo>  CaloAffectedRegionInfoVec;
 
 #include "AthenaKernel/CLASS_DEF.h"
 CLASS_DEF( CaloAffectedRegionInfoVec , 36372397, 1 )
-
+CLASS_DEF( CondCont<CaloAffectedRegionInfoVec>, 162668004 , 1 )
 #endif
diff --git a/Calorimeter/CaloInterface/CMakeLists.txt b/Calorimeter/CaloInterface/CMakeLists.txt
index fce9e50d787af106d34282dacd8383a1b5f1b62f..52a82e0a61d6cbe03b1b9c625fc347c07ff53f8c 100644
--- a/Calorimeter/CaloInterface/CMakeLists.txt
+++ b/Calorimeter/CaloInterface/CMakeLists.txt
@@ -9,6 +9,7 @@ atlas_subdir( CaloInterface )
 atlas_depends_on_subdirs( PUBLIC
                           Calorimeter/CaloEvent
                           Calorimeter/CaloIdentifier
+                          Calorimeter/CaloConditions
                           Control/AthenaKernel
                           DetectorDescription/Identifier
                           Event/xAOD/xAODCaloEvent
@@ -22,7 +23,7 @@ atlas_add_dictionary( CaloInterfaceDict
                       CaloInterface/CaloInterfaceDict.h
                       CaloInterface/selection.xml
                       INCLUDE_DIRS ${ROOT_INCLUDE_DIRS}
-                      LINK_LIBRARIES ${ROOT_LIBRARIES} CaloEvent CaloIdentifier AthenaKernel Identifier xAODCaloEvent GaudiKernel )
+                      LINK_LIBRARIES ${ROOT_LIBRARIES} CaloEvent CaloIdentifier CaloConditions AthenaKernel Identifier xAODCaloEvent GaudiKernel )
 
 # Install files from the package:
 atlas_install_headers( CaloInterface )
diff --git a/Calorimeter/CaloInterface/CaloInterface/ICaloAffectedTool.h b/Calorimeter/CaloInterface/CaloInterface/ICaloAffectedTool.h
index c0358e1cb34a6f468a06c49ab5a7eca597a21570..505d02888e096bdcdcf3ddb06cb57e99d89bf010 100755
--- a/Calorimeter/CaloInterface/CaloInterface/ICaloAffectedTool.h
+++ b/Calorimeter/CaloInterface/CaloInterface/ICaloAffectedTool.h
@@ -1,5 +1,5 @@
 /*
-  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
+  Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
 */
 
 ///////////////////////////////////////////////////////////////////////////////
@@ -7,6 +7,7 @@
 ///
 /// \author G.Unal
 /// \date March 2010
+/// \updated Dec 2018 by P. Strizenec
 ///
 ///////////////////////////////////////////////////////////////////////////////
 
@@ -15,6 +16,9 @@
 
 // Includes for Gaudi
 #include "GaudiKernel/IAlgTool.h"
+#include "AthenaKernel/CondCont.h"
+#include "CaloConditions/CaloAffectedRegionInfoVec.h"
+
 #include <vector>
 
 namespace xAOD {
@@ -26,7 +30,7 @@ class ICaloAffectedTool: virtual public IAlgTool {
 public:
 
   static const InterfaceID& interfaceID() { 
-    static const InterfaceID IID_ICaloAffectedTool("ICaloAffectedTool", 1 , 0);
+    static const InterfaceID IID_ICaloAffectedTool("ICaloAffectedTool", 2 , 0);
     return IID_ICaloAffectedTool; 
   }
 
@@ -35,6 +39,7 @@ public:
     and with a problemType (0= deadReadout, 1 = deadHV, 2 = affectedHV,  -1= all problems)
     
     @param p  4 momentum pointer to check
+    @param vAff pointer to conditions object with affected regions
     @param deta = eta tolerance
     @param dphi = phi tolerance
     @param layer_min = min calo layer to check
@@ -42,13 +47,14 @@ public:
     @param problemType = type of problem in affacted region
   */
 
-  virtual bool isAffected(const xAOD::IParticle *p, float deta=0, float dphi=0, int layer_min=0, int layer_max=-1, int problemType=-1) const = 0;
+  virtual bool isAffected(const xAOD::IParticle *p, const CaloAffectedRegionInfoVec *vAff, float deta=0, float dphi=0, int layer_min=0, int layer_max=-1, int problemType=-1) const = 0;
 
   /*
     Return list of layers affected with their problem for a given 4 momentum
     Return true is any problem is fonund
 
     @param p 4 momentum pointer to check
+    @param vAff pointer to conditions object with affected regions
     @param deta = eta tolerance
     @param dphi = phi tolerance
     @param problemType = filters only a given type of problem (-1 : all problems)
@@ -56,7 +62,7 @@ public:
     @param problem_list = reference of vector to store list of problems
    */
 
-  virtual bool listAffected(const xAOD::IParticle* p, std::vector<int>& layer_list, std::vector<int>& problem_list, float deta=0, float dphi=0, int problemType=-1) const =0;
+  virtual bool listAffected(const xAOD::IParticle* p, const CaloAffectedRegionInfoVec *vAff, std::vector<int>& layer_list, std::vector<int>& problem_list, float deta=0, float dphi=0, int problemType=-1) const =0;
 
  
 };
diff --git a/Calorimeter/CaloRec/share/CaloRec_jobOptions.py b/Calorimeter/CaloRec/share/CaloRec_jobOptions.py
index de9da525e1346511f3fee547907118882a33ca95..1a3bdfe062df03796210ae15c65b0f4245819c39 100644
--- a/Calorimeter/CaloRec/share/CaloRec_jobOptions.py
+++ b/Calorimeter/CaloRec/share/CaloRec_jobOptions.py
@@ -291,12 +291,12 @@ if jobproperties.CaloRecFlags.doTileMuId() :
 
     
 #
-# information on Calo AffectedRegion, write metadata
+# information on Calo AffectedRegion, write conditions object
 #
 if DetFlags.dcs.LAr_on():
-    if jobproperties.CaloRecFlags.doLArAffectedRegion() and rec.doESD and (not rec.readESD):
+    if jobproperties.CaloRecFlags.doLArAffectedRegion():
         try:
-            include ("LArAffectedRegion/LArAffectedRegion_write.py")
+            include ("LArRecUtils/LArAffectedRegion.py")
         except Exception: 
             treatException("Could not setup LArAffectedRegion")
 
diff --git a/Calorimeter/CaloTools/CaloTools/CaloAffectedTool.h b/Calorimeter/CaloTools/CaloTools/CaloAffectedTool.h
index 12316e824440d719fd88bb74def7b25d8b9e0eae..3aa69b9ac50467faed070fac726f89ad0c4c7326 100644
--- a/Calorimeter/CaloTools/CaloTools/CaloAffectedTool.h
+++ b/Calorimeter/CaloTools/CaloTools/CaloAffectedTool.h
@@ -1,11 +1,12 @@
 /*
-  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
+  Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
 */
 
 /** 
     @class CaloAffectedTool
     @brief Tool to check if object is in an affected region
     @author G.Unal
+    @ changed to use conditions object by P. Strizenec
 */
 
 #ifndef CALOTOOLS_CaloAffectedTool_H
@@ -13,8 +14,6 @@
 
 
 #include "AthenaBaseComps/AthAlgTool.h"
-#include "GaudiKernel/IIncidentListener.h"
-#include "GaudiKernel/IIncidentSvc.h"
 #include "CaloInterface/ICaloAffectedTool.h"
 #include "CaloConditions/CaloAffectedRegionInfoVec.h"
 #include "AthenaKernel/IOVSvcDefs.h"
@@ -26,21 +25,8 @@ namespace xAOD {
 class StoreGateSvc;
 
 class CaloAffectedTool: public AthAlgTool,
-	             virtual public ICaloAffectedTool, virtual public IIncidentListener
+	             virtual public ICaloAffectedTool
 {
-private: 
-  
-  CaloAffectedRegionInfoVec* m_affectedRegions;
-
-  StatusCode updateAffectedRegionsFromDB(IOVSVC_CALLBACK_ARGS);
-
-  StatusCode readDB();
-
-  virtual void handle(const Incident& inc) override;
-
-  bool m_read;
-
-  bool m_readRaw;
   
 public:    
   
@@ -49,9 +35,9 @@ public:
 		const IInterface* parent); 
   virtual ~CaloAffectedTool();  
 
-  virtual bool isAffected(const xAOD::IParticle *p, float deta=0., float dphi=0., int layer_min=0, int layer_max=-1, int problemType=-1) const override;
+  virtual bool isAffected(const xAOD::IParticle *p, const CaloAffectedRegionInfoVec *vAff, float deta=0., float dphi=0., int layer_min=0, int layer_max=-1, int problemType=-1) const override;
 
-  virtual bool listAffected(const xAOD::IParticle* p, std::vector<int>& layer_list, std::vector<int>& problem_list, float deta=0, float dphi=0, int problemType=-1) const override;
+  virtual bool listAffected(const xAOD::IParticle* p, const CaloAffectedRegionInfoVec *vAff, std::vector<int>& layer_list, std::vector<int>& problem_list, float deta=0, float dphi=0, int problemType=-1) const override;
 
   virtual StatusCode initialize() override;
 
diff --git a/Calorimeter/CaloTools/python/CaloAffectedToolDefault.py b/Calorimeter/CaloTools/python/CaloAffectedToolDefault.py
deleted file mode 100644
index 5756483e242c453b08f2b5d070522a2b5288a312..0000000000000000000000000000000000000000
--- a/Calorimeter/CaloTools/python/CaloAffectedToolDefault.py
+++ /dev/null
@@ -1,28 +0,0 @@
-# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
-
-from AthenaCommon.Logging import logging
-
-def CaloAffectedToolDefault(name='CaloAffectedToolDefault'):
-
-    # check if tool already exists
-    from AthenaCommon.AppMgr import ServiceMgr as svcMgr
-    if hasattr(svcMgr.ToolSvc, name):
-        # re-use previously configured (public) tool
-        return getattr(svcMgr.ToolSvc, name)
-
-    mlog = logging.getLogger( 'CaloAffectedToolDefault' )
-
-    from CaloTools.CaloToolsConf import CaloAffectedTool
-
-
-    theTool = CaloAffectedTool(name)
-
-    from RecExConfig.RecFlags import rec
-    if rec.readRDO():
-       theTool.readRaw = True
-    else:
-       theTool.readRaw = False
-       from IOVDbSvc.CondDB import conddb
-       conddb.addFolder ('', '/LAR/LArAffectedRegionInfo<metaOnly/>')
-
-    return theTool
diff --git a/Calorimeter/CaloTools/src/CaloAffectedTool.cxx b/Calorimeter/CaloTools/src/CaloAffectedTool.cxx
index 34ea3c8b568736dfb99c48f4f3df75e0b546b1f1..1257b346f8afcba47ae35b0c339d21f550cd8c63 100644
--- a/Calorimeter/CaloTools/src/CaloAffectedTool.cxx
+++ b/Calorimeter/CaloTools/src/CaloAffectedTool.cxx
@@ -1,9 +1,8 @@
 /*
-  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
+  Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
 */
 
 #include "CaloTools/CaloAffectedTool.h" 
-//#include "EventKernel/I4Momentum.h"
 #include "xAODBase/IParticle.h"
 #include "StoreGate/StoreGateSvc.h"
 #include "CaloConditions/CaloAffectedRegionInfoVec.h"
@@ -14,145 +13,37 @@
 CaloAffectedTool::CaloAffectedTool (const std::string& type, 
 				  const std::string& name, 
 				  const IInterface* parent) :
-    AthAlgTool(type, name, parent),
-    m_read(false),
-    m_readRaw(true)
+    AthAlgTool(type, name, parent)
 { 
-  m_affectedRegions=nullptr;
   declareInterface<ICaloAffectedTool>(this);
-  declareProperty("readRaw",m_readRaw);
 }
                                                                                 
 //-----------------------------------------------------------------
 
 CaloAffectedTool::~CaloAffectedTool() {
-  if (m_affectedRegions && !m_readRaw) delete m_affectedRegions;
 }
 
 
 //-------------------------------------------------------------------
 
 StatusCode CaloAffectedTool::initialize() {
-
-  if (!m_readRaw) {
-   if (detStore()->contains<CondAttrListCollection>("/LAR/LArAffectedRegionInfo")) {
-      const DataHandle<CondAttrListCollection> affectedRegionH;
-      if (detStore()->regFcn(&CaloAffectedTool::updateAffectedRegionsFromDB,
-                          this,
-                          affectedRegionH,
-                          "/LAR/LArAffectedRegionInfo").isSuccess()) {
-        ATH_MSG_DEBUG( "Registered callback for  LArAffectedRegion "  );
-      }
-        else {
-          ATH_MSG_WARNING( "Cannot register callback for LArAffectedRegion "  );
-      }
-   }
-    else {  
-      ATH_MSG_WARNING( " no LArAffectedRegion information available from metadata "  );
-   }
-  }
-  else {
-    // register incident handler for begin event
-    IIncidentSvc* incSvc = nullptr; 
-    ATH_CHECK( service( "IncidentSvc", incSvc ) );
-    long int priority=100;
-    incSvc->addListener(this,"BeginEvent",priority);
-
-  }
-
-  m_read=false;
   return StatusCode::SUCCESS;
 }
 
 //---------------------------------------------------------
 
-void CaloAffectedTool::handle(const Incident& inc) {
-
-  if (inc.type()!="BeginEvent")
-    return; 
-
-  if (detStore()->contains<CaloAffectedRegionInfoVec>("LArAffectedRegion")) {
-     if (detStore()->retrieve(m_affectedRegions,"LArAffectedRegion").isFailure()) {
-       ATH_MSG_WARNING( " cannot read LArAffectedRegion at begin of event "  );
-       return;
-     }
-     m_read=true;
-     //std::cout << " got affected regions at beginning of event " << std::endl;
-     return;
-  }
-  return;
-
-}
-
-
-//--------------------------------------------------
-
-StatusCode CaloAffectedTool::updateAffectedRegionsFromDB(IOVSVC_CALLBACK_ARGS) {
-
-  return this->readDB();
-}
-
-StatusCode  CaloAffectedTool::readDB() {
 
-  ATH_MSG_INFO( "updateAffectedRegionsFromDB()"  );
-
-  // retrieve from detStore
-  const CondAttrListCollection* attrListColl = nullptr;
-  StatusCode sc = detStore()->retrieve(attrListColl, "/LAR/LArAffectedRegionInfo");
-  if (sc.isFailure()) {
-    ATH_MSG_WARNING( "attrrListColl not found for /LAR/CaloAffectedRegionInfo "  );
-     return StatusCode::SUCCESS;
-  }
-
-  if (m_affectedRegions) {
-     m_affectedRegions->clear();
-  }
-  else  {
-     m_affectedRegions =  new CaloAffectedRegionInfoVec();
-  }
-
-  // Loop over collection
-  CondAttrListCollection::const_iterator first = attrListColl->begin();
-  CondAttrListCollection::const_iterator last  = attrListColl->end();
-  for (; first != last; ++first) {
-      std::ostringstream attrStr1;
-      (*first).second.toOutputStream( attrStr1 );
-      ATH_MSG_DEBUG( "ChanNum " << (*first).first <<
-                     " Attribute list " << attrStr1.str()  );
-      //      const AttributeList& attrList = (*first).second;
-      const coral::AttributeList& attrList = (*first).second;
-      CaloAffectedRegionInfo info;
-      float eta_min = attrList["eta_min"].data<float>();
-      float eta_max = attrList["eta_max"].data<float>();
-      float phi_min = attrList["phi_min"].data<float>();
-      float phi_max = attrList["phi_max"].data<float>();
-      int layer_min = attrList["layer_min"].data<int>();
-      int layer_max = attrList["layer_max"].data<int>();
-      //std::cout << " affected region found " << eta_min << " " << eta_max << " " << phi_min << " " << phi_max << " " << layer_min << " " << layer_max << " " << attrList["problem"].data<int>() << std::endl;
-      CaloAffectedRegionInfo::type_problem problem = (CaloAffectedRegionInfo::type_problem)(attrList["problem"].data<int>());
-
-      info.FillCaloAffectedRegionInfo(eta_min,eta_max,phi_min,phi_max,layer_min,layer_max,problem);
-      m_affectedRegions->push_back(info);
-  }
-
-  m_read = true;
-  return StatusCode::SUCCESS;
-
-}
-
-//-------------------------------------------------
-
-bool CaloAffectedTool::isAffected(const xAOD::IParticle *p, float deta, float dphi, int layer_min, int layer_max, int problemType) const
+bool CaloAffectedTool::isAffected(const xAOD::IParticle *p, const CaloAffectedRegionInfoVec *vAff, float deta, float dphi, int layer_min, int layer_max, int problemType) const
 {
 
+   if(!vAff) return false;
+
  static float epsilon=1e-6;
 
   //std::cout << " in isAffected " << p->eta() << " " << p->phi() << std::endl;
-  if (!m_read) return false;
-  if (!m_affectedRegions) return false;
 
-  std::vector<CaloAffectedRegionInfo>::const_iterator reg1 = m_affectedRegions->begin();
-  std::vector<CaloAffectedRegionInfo>::const_iterator reg2 = m_affectedRegions->end();
+  std::vector<CaloAffectedRegionInfo>::const_iterator reg1 = vAff->begin();
+  std::vector<CaloAffectedRegionInfo>::const_iterator reg2 = vAff->end();
   for (;reg1 != reg2; ++reg1) {
     const CaloAffectedRegionInfo* region = &(*reg1);
 
@@ -194,9 +85,11 @@ bool CaloAffectedTool::isAffected(const xAOD::IParticle *p, float deta, float dp
 }
 //-------------------------------------------------
 
-bool CaloAffectedTool::listAffected(const xAOD::IParticle*p, std::vector<int>& layer_list, std::vector<int>& problem_list, float deta, float dphi, int problemType) const
+bool CaloAffectedTool::listAffected(const xAOD::IParticle*p, const CaloAffectedRegionInfoVec *vAff, std::vector<int>& layer_list, std::vector<int>& problem_list, float deta, float dphi, int problemType) const
 {
 
+  if(!vAff) return false;
+
   bool found = false;
 
   static float epsilon=1e-6;
@@ -204,11 +97,9 @@ bool CaloAffectedTool::listAffected(const xAOD::IParticle*p, std::vector<int>& l
   layer_list.clear();
   problem_list.clear();
 
-  if (!m_read) return false;
-  if (!m_affectedRegions) return false;
 
-  std::vector<CaloAffectedRegionInfo>::const_iterator reg1 = m_affectedRegions->begin();
-  std::vector<CaloAffectedRegionInfo>::const_iterator reg2 = m_affectedRegions->end();
+  std::vector<CaloAffectedRegionInfo>::const_iterator reg1 = vAff->begin();
+  std::vector<CaloAffectedRegionInfo>::const_iterator reg2 = vAff->end();
   for (;reg1 != reg2; ++reg1) {
     const CaloAffectedRegionInfo* region = &(*reg1);
 
diff --git a/LArCalorimeter/LArAffectedRegion/CMakeLists.txt b/LArCalorimeter/LArAffectedRegion/CMakeLists.txt
deleted file mode 100644
index e4fac2756cecb4c54116c4e90ee96718e58942cd..0000000000000000000000000000000000000000
--- a/LArCalorimeter/LArAffectedRegion/CMakeLists.txt
+++ /dev/null
@@ -1,41 +0,0 @@
-################################################################################
-# Package: LArAffectedRegion
-################################################################################
-
-# Declare the package name:
-atlas_subdir( LArAffectedRegion )
-
-# Declare the package's dependencies:
-atlas_depends_on_subdirs( PUBLIC
-                          Calorimeter/CaloConditions
-                          Calorimeter/CaloIdentifier
-                          Control/AthenaBaseComps
-                          Control/AthenaKernel
-                          Control/StoreGate
-                          Database/AthenaPOOL/AthenaPoolUtilities
-                          GaudiKernel
-                          LArCalorimeter/LArIdentifier
-                          PRIVATE
-                          Calorimeter/CaloDetDescr
-                          Calorimeter/CaloGeoHelpers
-                          Database/IOVDbMetaDataTools
-                          Event/EventInfo
-                          LArCalorimeter/LArElecCalib
-                          LArCalorimeter/LArGeoModel/LArHV
-                          LArCalorimeter/LArRecConditions
-                          LArCalorimeter/LArCabling )
-
-# External dependencies:
-find_package( CORAL COMPONENTS CoralBase CoralKernel RelationalAccess )
-
-# Component(s) in the package:
-atlas_add_component( LArAffectedRegion
-                     src/*.cxx
-                     src/components/*.cxx
-                     INCLUDE_DIRS ${CORAL_INCLUDE_DIRS}
-                     LINK_LIBRARIES ${CORAL_LIBRARIES} CaloConditions CaloIdentifier AthenaBaseComps AthenaKernel StoreGateLib SGtests AthenaPoolUtilities GaudiKernel LArIdentifier CaloDetDescrLib CaloGeoHelpers EventInfo LArHV LArRecConditions LArCablingLib )
-
-# Install files from the package:
-atlas_install_headers( LArAffectedRegion )
-atlas_install_joboptions( share/*.py )
-
diff --git a/LArCalorimeter/LArAffectedRegion/LArAffectedRegion/LArAffectedRegionAlg.h b/LArCalorimeter/LArAffectedRegion/LArAffectedRegion/LArAffectedRegionAlg.h
deleted file mode 100644
index fe45517e5710a3e6d69b1b03bea380fa188559f6..0000000000000000000000000000000000000000
--- a/LArCalorimeter/LArAffectedRegion/LArAffectedRegion/LArAffectedRegionAlg.h
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
-  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
-*/
-
-#ifndef LArAffectedRegionAlg_H
-#define LArAffectedRegionAlg_H
-
-#include "AthenaBaseComps/AthAlgorithm.h"
-#include "GaudiKernel/ToolHandle.h"
-#include "GaudiKernel/IIncidentListener.h"
-#include "StoreGate/DataHandle.h"
-#include "LArIdentifier/LArOnlineID.h"
-
-#include <vector>
-
-#include "CaloConditions/CaloAffectedRegionInfo.h"
-#include "CaloConditions/CaloAffectedRegionInfoVec.h"
-
-#include "AthenaKernel/IOVSvcDefs.h" // for the definition of IOVSVC_CALLBACK_ARGS
-
-#include "CaloIdentifier/CaloIdManager.h"
-
-//#include ToolHandle<ILArHVTool> m_hvtool;
-#include "AthenaPoolUtilities/CondAttrListCollection.h"
-
-#include "IOVDbMetaDataTools/IIOVDbMetaDataTool.h"
-#include "LArElecCalib/ILArHVTool.h"
-#include "CaloDetDescr/CaloDetDescrManager.h"
-#include "StoreGate/ReadCondHandleKey.h"
-#include "LArRecConditions/LArBadChannelCont.h"
-#include "LArCabling/LArOnOffIdMapping.h"
-
-class LArOnlineID;
-
-class CaloIdManager;
-
-class LArAffectedRegionAlg : public AthAlgorithm,virtual public IIncidentListener  {
-  //---
- public:
-  LArAffectedRegionAlg(const std::string& name, ISvcLocator* pSvcLocator );
-  StatusCode initialize();
-  StatusCode execute();
-  StatusCode finalize();
-
-  void handle(const Incident& inc);
-  StatusCode updateMethod();
-  StatusCode updateAffectedRegionsFromDB(IOVSVC_CALLBACK_ARGS);
-
-  void searchNonNominalHV_EMB();
-  void searchNonNominalHV_EMEC_OUTER();
-  void searchNonNominalHV_EMEC_INNER();
-  void searchNonNominalHV_HEC();
-  void searchNonNominalHV_FCAL();
-
-  float HV_nominal(const char *identification,const float eta);
-  std::vector<int> returnProblem(const float eta, const float phi, const float delta_eta, const float delta_phi);  
-  int getOccurenceProblem(const std::vector<CaloAffectedRegionInfo>& ArrayLArAffectedRegionInfo_global,float eta_min,float eta_max,float phi_min,float phi_max,int layer_min,int layer_max,int problem,float rate);
-  void debuggingSearchDoublons(const std::vector<CaloAffectedRegionInfo>& ArrayLArAffectedRegionInfo);
-  //---
- private:
-
-  SG::ReadCondHandleKey<LArBadFebCont> m_BFKey{this, "MissingFEBKey", "LArBadFeb", "SG key for missing FEB object"};
-  SG::ReadCondHandleKey<LArOnOffIdMapping> m_cablingKey{this, "OnOffMap", "LArOnOffIdMap", "SG key for mapping object"};
-
-  std::vector<CaloAffectedRegionInfo> m_ArrayLArAffectedRegionInfo_global;
-  std::vector<CaloAffectedRegionInfo> m_ArrayLArAffectedRegionInfo_current_run;
-
-  const DataHandle<CaloIdManager> m_caloIdMgr;
-  ToolHandle<ILArHVTool> m_hvtool;
-
-  const LArOnlineID* m_onlineID;
-  const DataHandle<CaloDetDescrManager> m_calodetdescrmgr;
-  
-  bool m_readingFromBytestream;
-
-  CondAttrListCollection* m_attrListColl;  // info to give to metadata  
-  ToolHandle<IIOVDbMetaDataTool> m_metaDataTool;          // Access to iov meta data tool  
-  bool m_doHV;
-  
-  void extendPhiRegion(float phi, float & phi_min, float & phi_max);
-};
-
-#endif
diff --git a/LArCalorimeter/LArAffectedRegion/share/LArAffectedRegion_read.py b/LArCalorimeter/LArAffectedRegion/share/LArAffectedRegion_read.py
deleted file mode 100644
index 352ccf81d381e9e0d590eb869e395e5991498d01..0000000000000000000000000000000000000000
--- a/LArCalorimeter/LArAffectedRegion/share/LArAffectedRegion_read.py
+++ /dev/null
@@ -1,13 +0,0 @@
-# jobOptions fragment to setup writing of LAr affected region
-
-
-if not hasattr(topSequence, 'LArAffectedRegionAlg'):
-    from LArAffectedRegion.LArAffectedRegionConf import LArAffectedRegionAlg
-    theLArAffectedRegionAlg = LArAffectedRegionAlg()
-
-    theLArAffectedRegionAlg.ReadingFromBytestream = False
-
-    topSequence+=theLArAffectedRegionAlg
-
-    from IOVDbSvc.CondDB import conddb
-    conddb.addFolder ('', '/LAR/LArAffectedRegionInfo<metaOnly/>')
diff --git a/LArCalorimeter/LArAffectedRegion/share/LArAffectedRegion_read_topExample.py b/LArCalorimeter/LArAffectedRegion/share/LArAffectedRegion_read_topExample.py
deleted file mode 100644
index 716d467a97b913941c2fe0ad0b4e612108bd8130..0000000000000000000000000000000000000000
--- a/LArCalorimeter/LArAffectedRegion/share/LArAffectedRegion_read_topExample.py
+++ /dev/null
@@ -1,87 +0,0 @@
-###############################################################
-#
-# Job options file to run Digitization
-#
-#==============================================================
-
-#these lines is to have information on what is installed
-theAuditorSvc = svcMgr.AuditorSvc
-theApp.AuditAlgorithms=True
-theApp.AuditServices=True
-theApp.AuditTools=True
-theAuditorSvc += CfgMgr.NameAuditor()
-#=================
-
-from AthenaCommon.GlobalFlags import globalflags
-globalflags.DetGeo = 'atlas'
-globalflags.DataSource = 'data'
-globalflags.InputFormat = 'pool'
-
-from AthenaCommon.DetFlags import DetFlags
-#David :
-DetFlags.detdescr.all_setOn()
-DetFlags.Muon_setOff()
-DetFlags.ID_setOff()
-# DetFlags.Tile_setOff()
-# DetFlags.readRDOBS.LAr_setOn()
-# DetFlags.makeRIO.Calo_setOn()
-
-#ADDED TO CHECK
-#David :
-#DetFlags.Calo_setOn()
-
-from RecExConfig.RecFlags import rec
-rec.doCBNT=False
-rec.doMuon = False
-rec.doInDet = False
-rec.doTrigger =False
-#rec.doTile = False
-rec.doESD = False
-rec.doWriteESD = False
-rec.doAOD = False
-rec.doWriteAOD = False
-rec.doWriteRDO = False
-
-#do the print
-rec.doDumpProperties=True
-
-include( "PartPropSvc/PartPropSvc.py" )
-
-# Get a handle to the ServiceManager
-from AthenaCommon.AppMgr import ServiceMgr as svcMgr
-
-# Get a handle to the ApplicationManager
-#from AthenaCommon.AppMgr import theApp
-
-from AthenaCommon.AthenaCommonFlags import athenaCommonFlags
-athenaCommonFlags.FilesInput = ["ESD.pool.root"]
-
-
-from LArConditionsCommon.LArCondFlags import larCondFlags
-
-from AthenaCommon.GlobalFlags import jobproperties
-jobproperties.Global.DetDescrVersion='ATLAS-GEO-00-00-00'
-#jobproperties.Global.DetDescrVersion='ATLAS-CSC-00-00-00'
-
-include("RecExCommon/RecExCommon_topOptions.py")
-
-from IOVDbSvc import IOVDb
-svcMgr.IOVDbSvc.GlobalTag = "COMCOND-ES1C-000-00"
-svcMgr.IOVDbSvc.OutputLevel      = DEBUG
-
-from LArAffectedRegion.LArAffectedRegionConf import LArAffectedRegionAlg
-theLArAffectedRegionAlg=LArAffectedRegionAlg()
-
-# if we read from ESD, AOD, etc. set the following to false
-theLArAffectedRegionAlg.ReadingFromBytestream = False
-# Need the following when reading from ESD/AOD/etc.
-#avoid searching on oracle
-svcMgr.IOVDbSvc.Folders += [ "/LAR/LArAffectedRegionInfo<metaOnly/>" ]
-
-topSequence += theLArAffectedRegionAlg
-
-#--------------------------------------------------------------
-# Event related parameters
-#--------------------------------------------------------------
-# Number of events to be processed (default is 10)
-theApp.EvtMax = 10
diff --git a/LArCalorimeter/LArAffectedRegion/share/LArAffectedRegion_write.py b/LArCalorimeter/LArAffectedRegion/share/LArAffectedRegion_write.py
deleted file mode 100644
index 188c5f438f4a40f08ef1dab1439a1124d81ddbc7..0000000000000000000000000000000000000000
--- a/LArCalorimeter/LArAffectedRegion/share/LArAffectedRegion_write.py
+++ /dev/null
@@ -1,16 +0,0 @@
-# jobOptions fragment to setup writing of LAr affected region
-
-from LArConditionsCommon import LArHVDB
-
-from LArAffectedRegion.LArAffectedRegionConf import LArAffectedRegionAlg
-theLArAffectedRegionAlg = LArAffectedRegionAlg()
-
-from AthenaCommon.GlobalFlags import globalflags
-if globalflags.DataSource()=='data':
-    theLArAffectedRegionAlg.doHV = True
-else:
-    theLArAffectedRegionAlg.doHV = False
-
-from AthenaCommon.AlgSequence import AlgSequence
-topSequence = AlgSequence()
-topSequence+=theLArAffectedRegionAlg
diff --git a/LArCalorimeter/LArAffectedRegion/share/LArAffectedRegion_write_topExample.py b/LArCalorimeter/LArAffectedRegion/share/LArAffectedRegion_write_topExample.py
deleted file mode 100644
index b6a113c550fa245ff7bb11471007f7d65201cb35..0000000000000000000000000000000000000000
--- a/LArCalorimeter/LArAffectedRegion/share/LArAffectedRegion_write_topExample.py
+++ /dev/null
@@ -1,137 +0,0 @@
-###############################################################
-#
-# Job options file to run Digitization
-#
-#==============================================================
-
-from AthenaCommon.Resilience import treatException,protectedInclude
-
-#these lines is to have information on what is installed
-theAuditorSvc = svcMgr.AuditorSvc
-theApp.AuditAlgorithms=True
-theApp.AuditServices=True
-theApp.AuditTools=True
-theAuditorSvc += CfgMgr.NameAuditor()
-#=================
-
-from AthenaCommon.GlobalFlags import globalflags
-globalflags.DetGeo = 'atlas'
-globalflags.DataSource = 'data'
-globalflags.InputFormat = 'bytestream'
-
-from AthenaCommon.DetFlags import DetFlags
-DetFlags.detdescr.all_setOn()
-DetFlags.Muon_setOff()
-DetFlags.ID_setOff()
-DetFlags.Tile_setOff()
-DetFlags.ALFA_setOff()
-DetFlags.readRDOBS.LAr_setOn()
-DetFlags.makeRIO.Calo_setOn()
-
-#ADDED TO CHECK
-DetFlags.Calo_setOn()
-
-from RecExConfig.RecFlags import rec
-rec.doMuon = False
-rec.doInDet = False
-rec.doTile = False
-rec.doESD = False
-rec.doWriteESD = False
-rec.doAOD = False
-rec.doWriteAOD = False
-rec.doWriteRDO = False
-
-include( "PartPropSvc/PartPropSvc.py" )
-
-# Get a handle to the ServiceManager
-from AthenaCommon.AppMgr import ServiceMgr as svcMgr
-
-# Get a handle to the ApplicationManager
-from AthenaCommon.AppMgr import theApp
-
-from AthenaCommon.AlgSequence import AlgSequence
-topSequence = AlgSequence()
-
-from AthenaCommon.AthenaCommonFlags  import athenaCommonFlags
-athenaCommonFlags.BSRDOInput = ["/afs/cern.ch/user/g/gencomm/w0/RTT_INPUT_DATA/CosmicATN/daq.ATLAS.0091900.physics.IDCosmic.LB0001.SFO-1._0001.10EVTS.data"]
-
-include( "ByteStreamCnvSvc/BSEventStorageEventSelector_jobOptions.py" )
-
-svcMgr.ByteStreamInputSvc.FullFileName=athenaCommonFlags.BSRDOInput()
-svcMgr.ByteStreamAddressProviderSvc.TypeNames += ["LArDigitContainer/FREE"]
-
-
-from LArConditionsCommon.LArCondFlags import larCondFlags
-
-from AthenaCommon.GlobalFlags import jobproperties
-jobproperties.Global.DetDescrVersion='ATLAS-GEO-00-00-00'
-
-from IOVDbSvc import IOVDb
-svcMgr.IOVDbSvc.GlobalTag = "COMCOND-ES1C-000-00"
-svcMgr.IOVDbSvc.OutputLevel      = DEBUG
-
-#=================For HV
-from IOVDbSvc.CondDB import conddb
-conddb.addFolder("DCS_OFL","/LAR/DCS/HV/BARREl/I16")
-conddb.addFolder("DCS_OFL","/LAR/DCS/HV/BARREL/I8")
-#to read HV mapping from database file instead of Ascii file in LArTools
-conddb.addFolder("LAR_OFL","/LAR/IdentifierOfl/HVLineToElectrodeMap")
-conddb.addOverride("/LAR/IdentifierOfl/HVLineToElectrodeMap","LARIdentifierOflHVLineToElectrodeMap-UPD4-01")
-#======================
-
-# the Tile, LAr and Calo detector description package
-include( "CaloDetMgrDetDescrCnv/CaloDetMgrDetDescrCnv_joboptions.py" )
-include( "LArDetDescr/LArDetDescr_joboptions.py" )
-include( "LArConditionsCommon/LArConditionsCommon_comm_jobOptions.py")
-
-from AtlasGeoModel import SetGeometryVersion
-from AtlasGeoModel import GeoModelInit
-
-#    ---- add algorithm
-from LArAffectedRegion.LArAffectedRegionConf import LArAffectedRegionAlg
-topSequence+=LArAffectedRegionAlg()
-
-#------------------------------------------------------
-# Set output level threshold (2=DEBUG, 3=INFO, 4=WARNING, 5=ERROR, 6=FATAL )
-#-------------------------------------------------------------
-svcMgr.MessageSvc.OutputLevel      = INFO 
-#increase the number of letter reserved to the alg/tool name from 18 to 30
-svcMgr.MessageSvc.Format = "% F%50W%S%7W%R%T %0W%M" 
-svcMgr.MessageSvc.defaultLimit = 9999999  # all messages
-svcMgr.MessageSvc.useColors = False
-svcMgr.MessageSvc.defaultLimit=1000000
-
-#---------------------------------------------------------------------
-# Perfmon
-#--------------------------------------------------------------------
-
-from PerfMonComps.PerfMonFlags import jobproperties
-jobproperties.PerfMonFlags.doMonitoring = True
-from PerfMonComps.JobOptCfg import PerfMonSvc
-svcMgr += PerfMonSvc()
-jobproperties.PerfMonFlags.doDetailedMonitoring = True
-
-
-#--------------------------------------------------------------
-# Event related parameters
-#--------------------------------------------------------------
-# Number of events to be processed (default is 10)
-theApp.EvtMax = 10
-theApp.EvtSel = "EventSelector"
-
-
-#Create output StreamESD
-from AthenaPoolCnvSvc.WriteAthenaPool import AthenaPoolOutputStream
-StreamESD=AthenaPoolOutputStream("StreamESD",athenaCommonFlags.PoolESDOutput(),True)
-StreamESD.ForceRead = True
-# Put MetaData in ESD stream
-StreamESD.MetadataItemList += [ "LumiBlockCollection#*" ]
-
-include ("EventAthenaPool/EventAthenaPoolItemList_joboptions.py")
-StreamESD.ItemList+=fullItemList
-
-     
-
-
-#David, instruction to get all the info in the DetectorStore
-ServiceMgr.DetectorStore.Dump=True 
diff --git a/LArCalorimeter/LArAffectedRegion/src/LArAffectedRegionAlg.cxx b/LArCalorimeter/LArAffectedRegion/src/LArAffectedRegionAlg.cxx
deleted file mode 100644
index 5988ac415f8ded2245e7fd955b8ece8b16008a65..0000000000000000000000000000000000000000
--- a/LArCalorimeter/LArAffectedRegion/src/LArAffectedRegionAlg.cxx
+++ /dev/null
@@ -1,1164 +0,0 @@
-/*
-  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
-*/
-
-#define HV_NON_NOMINAL_TOLERANCE 10 // tolerance : 1V for HV
-#define DEAD_HV_THRESHOLD 10 // HV <10 V="dead"
-
-//==============
-#include "EventInfo/EventIncident.h"
-#include "EventInfo/EventInfo.h"
-#include "EventInfo/EventID.h"
-//===================
-//For HV : 
-#include "GaudiKernel/IIncidentSvc.h"
-
-#include "LArAffectedRegion/LArAffectedRegionAlg.h"
-#include "CaloConditions/CaloAffectedRegionInfo.h"
-#include "CaloConditions/CaloAffectedRegionInfoVec.h"
-
-#include "GaudiKernel/MsgStream.h"
-#include "GaudiKernel/GaudiException.h"
-#include "LArRecConditions/LArBadChanBitPacking.h"
-#include "StoreGate/StoreGateSvc.h"
-
-#include "CaloDetDescr/CaloDetDescrManager.h"
-#include "CaloDetDescr/CaloDetDescrElement.h"
-#include "CaloGeoHelpers/CaloPhiRange.h"
-#include "LArCabling/LArCablingService.h"
-#include "LArIdentifier/LArOnlineID.h"
-//===========for HV
-#include "LArHV/LArHVManager.h"
-#include "LArHV/EMBHVManager.h"
-#include "LArHV/EMBHVModule.h"
-#include "LArHV/EMBHVModuleConstLink.h"
-#include "LArHV/EMBHVElectrode.h"
-#include "LArHV/EMBHVElectrodeConstLink.h"
-#include "LArHV/EMBPresamplerHVManager.h"
-#include "LArHV/EMBPresamplerHVModule.h"
-#include "LArHV/EMBPresamplerHVModuleConstLink.h"
-
-
-#include "LArHV/EMECHVManager.h"
-#include "LArHV/EMECHVModule.h"
-#include "LArHV/EMECHVModuleConstLink.h"
-#include "LArHV/EMECHVElectrode.h"
-#include "LArHV/EMECHVElectrodeConstLink.h"
-#include "LArHV/EMECPresamplerHVManager.h"
-#include "LArHV/EMECPresamplerHVModule.h"
-#include "LArHV/EMECPresamplerHVModuleConstLink.h"
-
-#include "LArHV/HECHVManager.h"
-#include "LArHV/HECHVModule.h"
-#include "LArHV/HECHVModuleConstLink.h"
-#include "LArHV/HECHVSubgap.h"
-
-#include "LArHV/FCALHVManager.h"
-#include "LArHV/FCALHVModule.h"
-#include "LArHV/FCALHVModuleConstLink.h"
-#include "LArHV/FCALHVLine.h"
-#include "LArHV/FCALHVLineConstLink.h"
-//================
-// AttributeList
-#include "CoralBase/Attribute.h"
-#include "CoralBase/Blob.h"
-#include "CoralBase/AttributeListSpecification.h"
-#include "AthenaPoolUtilities/AthenaAttributeList.h"
-#include "AthenaPoolUtilities/CondAttrListCollection.h"
-#include "IOVDbMetaDataTools/IIOVDbMetaDataTool.h"
-
-#include "LArElecCalib/ILArHVTool.h"
-
-LArAffectedRegionAlg::LArAffectedRegionAlg(const std::string& name, ISvcLocator* pSvcLocator) :
-  AthAlgorithm(name, pSvcLocator),
-  m_hvtool("LArHVToolMC"),
-  m_onlineID(NULL),
-  m_metaDataTool("IOVDbMetaDataTool"),
-  m_doHV(true)
-{
-  declareProperty("ReadingFromBytestream", m_readingFromBytestream = true);
-  declareProperty("doHV",m_doHV,"include HV non nominal regions info");
-  declareTool( m_metaDataTool, m_metaDataTool.typeAndName() );
-  m_attrListColl =0;
-}
-//=========================================================================================
-StatusCode LArAffectedRegionAlg::initialize() {
-  ATH_MSG_INFO ( "initialize()" );
-
-  ATH_CHECK( m_metaDataTool.retrieve() );
-  
-  ATH_CHECK( m_cablingKey.initialize());
-
-  ATH_CHECK( detStore()->retrieve(m_onlineID, "LArOnlineID") );
-  ATH_CHECK( detStore()->retrieve(m_caloIdMgr) );
-  ATH_CHECK( detStore()->retrieve(m_calodetdescrmgr) );
-
-  //-------------
-  // Do only when reading bytestream
-
-  if (m_readingFromBytestream) {
-    
-    ATH_CHECK( m_BFKey.initialize() );
-    
-  } else {     // Do only when reading ESD/AOD
-
-    if (detStore()->contains<CondAttrListCollection>("/LAR/LArAffectedRegionInfo")) {
-        const DataHandle<CondAttrListCollection> affectedRegionH;
-        if (detStore()->regFcn(&LArAffectedRegionAlg::updateAffectedRegionsFromDB,
-                               this,
-                               affectedRegionH,
-                               "/LAR/LArAffectedRegionInfo").isSuccess()) {
-          ATH_MSG_DEBUG ( "Registered callback for  LArAffectedRegion " );
-        }
-        else {
-          ATH_MSG_WARNING ( "Cannot register callback for LArAffectedRegion " );
-        }
-    }
-    else {
-      ATH_MSG_WARNING ( " no LArAffectedRegion information available from metadata " );
-    }
-  }
-
-  /* for the moment, we don't do the call back
-  //example : 
-   std::string folderName = "/LAR/DCS/HV/BARREl/I16";
-   if ((m_detStore->regFcn(&ILArHVTool::LoadCalibration,dynamic_cast<ILArHVTool*>(this), MyMethod,folderName)).isFailure()) {
-      log << MSG::ERROR << "cannot register callback to " << folderName << std::endl;  
-   }
-   folderName = "/LAR/DCS/HV/BARREL/I8";
-   if ((m_detStore->regFcn(&ILArHVTool::LoadCalibration,dynamic_cast<ILArHVTool*>(this), MyMethod2,folderName)).isFailure()) {
-      log << MSG::ERROR << "cannot register callback to " << folderName << std::endl;
-   }
-   log << MSG::INFO << " registered callback to /LAR/DCS/HV folders " << endmsg;
-  */
-
-  // register incident handler for begin run
-  IIncidentSvc* incSvc = nullptr;
-  ATH_CHECK( service( "IncidentSvc", incSvc ) );
-  long int priority=100;
-  /*  in case one want to launch the search only one time
-      bool rethrow = 0;
-      bool singleShot = 1; 
-      incSvc->addListener(this,"BeginRun",priority,rethrow,singleShot);
-  */
-  incSvc->addListener(this,"BeginRun",priority);
-
-//--------------------------
-
-  return StatusCode::SUCCESS;
-}
-//=========================================================================================
-void LArAffectedRegionAlg::handle(const Incident& inc) { //for non nominal HV
-
-  if (inc.type()!="BeginRun")
-    return;
-  if (!m_readingFromBytestream) // Only process if reading from bytestream
-    return;
-
-  
-  ATH_MSG_INFO ( " in LArAffectedRegionAlg  beginning of run handle " );
-  
-  long int runNumber=-1;  
-  const EventIncident* eventInc=dynamic_cast<const EventIncident*>(&inc);
-  if (eventInc) { // was a bug here in previous version : !eventInc was written
-    const EventInfo* evt = &eventInc->eventInfo();
-    runNumber=evt->event_ID()->run_number();
-  }
-   
-  //next 5 methods fill the current run info : m_ArrayLArAffectedRegionInfo_current_run
-  if (m_doHV) {
-   searchNonNominalHV_EMB();
-   searchNonNominalHV_EMEC_OUTER();
-   searchNonNominalHV_EMEC_INNER();
-   searchNonNominalHV_HEC();
-   searchNonNominalHV_FCAL();
-  }
-
-  int flag_At_Least_New_Problem_In_Current_Run=0; //flag to compare with global(=all runs) AffectedProblems. Specific case of first run (for which global run will be yet empty) is taken into consideration in the algorithm
-  
-  //next algorithm is : search for a new problem in the global (=all runs) list of AffectedRegion and update the MetaData afterwards if at least one new problem has been found 
-
-  for (unsigned int i=0;i<m_ArrayLArAffectedRegionInfo_current_run.size();++i) {     // loop over m_ArrayLArAffectedRegionInfo_current_run
-    if (getOccurenceProblem(m_ArrayLArAffectedRegionInfo_global,m_ArrayLArAffectedRegionInfo_current_run[i].get_eta_min(),m_ArrayLArAffectedRegionInfo_current_run[i].get_eta_max(),m_ArrayLArAffectedRegionInfo_current_run[i].get_phi_min(),m_ArrayLArAffectedRegionInfo_current_run[i].get_phi_max(),m_ArrayLArAffectedRegionInfo_current_run[i].get_layer_min(),m_ArrayLArAffectedRegionInfo_current_run[i].get_layer_max(),m_ArrayLArAffectedRegionInfo_current_run[i].get_problem(),m_ArrayLArAffectedRegionInfo_current_run[i].get_rate())) {
-      
-            //std::cout << "found the asked AffectedRegion in the global list of AffectedRegion" << std::endl;
-            //std::cout << "The AffectedRegion found is : " << std::endl;
-            //m_ArrayLArAffectedRegionInfo_current_run[i].PrintInfo();
-    }
-    else { // found a new problem that was no in the global list : add it and update the MetaData
-      //std::cout << "FOUND A NEW PROBLEM : " << std::endl;
-      //m_ArrayLArAffectedRegionInfo_current_run[i].PrintInfo();
-      flag_At_Least_New_Problem_In_Current_Run=1;
-      m_ArrayLArAffectedRegionInfo_global.push_back(m_ArrayLArAffectedRegionInfo_current_run[i]); //add the new problem of current run to the global list
-    }
-  } //end loop on AffectedRegion
-
-
-  // Fill AttributeListCollection and add to MetaData store
-  coral::AttributeListSpecification* attrSpec = new coral::AttributeListSpecification();
-  attrSpec->extend("eta_min", "float");
-  attrSpec->extend("eta_max", "float");
-  attrSpec->extend("phi_min", "float");
-  attrSpec->extend("phi_max", "float");
-  attrSpec->extend("layer_min", "int");
-  attrSpec->extend("layer_max", "int");
-  attrSpec->extend("problem", "int");
-  
-  if (!m_attrListColl || (m_attrListColl && flag_At_Least_New_Problem_In_Current_Run) ) { // first run or new run with new problems
-
-    m_attrListColl = new CondAttrListCollection(true);   // information that will be sent to the MetaData
-    
-    for (unsigned int i=0;i<m_ArrayLArAffectedRegionInfo_global.size();++i) {
-      CaloAffectedRegionInfo& info = m_ArrayLArAffectedRegionInfo_global[i];
-      coral::AttributeList attrList(*attrSpec,true);
-      attrList["eta_min"].setValue(info.get_eta_min());
-      attrList["eta_max"].setValue(info.get_eta_max());
-      attrList["phi_min"].setValue(info.get_phi_min());
-      attrList["phi_max"].setValue(info.get_phi_max());
-      attrList["layer_min"].setValue(info.get_layer_min());
-      attrList["layer_max"].setValue(info.get_layer_max());
-      attrList["problem"].setValue(info.get_problem());
-      m_attrListColl->add(i, attrList);  // channel number, payload
-    }
-    
-    m_attrListColl->addNewStart(IOVTime(runNumber, 0));       // start run, LB
-
-    attrSpec->release(); //Decrease ref-count, we don't need that guy any more
-
-    // Register folder in the IOV Db MetaData
-    if (StatusCode::SUCCESS != m_metaDataTool->registerFolder("/LAR/LArAffectedRegionInfo")) {      
-      ATH_MSG_ERROR ( "fillMetaData: Unable to register folder for /LAR/LArAffectedRegionInfo with meta data tool " );
-      //return StatusCode::FAILURE;
-      throw GaudiException( "Unable to get EventInfo from BeginRun incident", "TagInfoMgr::handle", StatusCode::FAILURE );
-    }
-    // Add payload
-    if (StatusCode::SUCCESS != m_metaDataTool->addPayload("/LAR/LArAffectedRegionInfo", m_attrListColl)) {      
-      ATH_MSG_ERROR ( "fillMetaData: Unable to register folder for /LAR/LArAffectedRegionInfo with meta data tool " );
-      throw GaudiException( "fillMetaData: Unable to register folder for /LAR/LArAffectedRegionInfo with meta data tool ", "TagInfoMgr::handle", StatusCode::FAILURE );
-    }
-
-    // record also in the detector store
-    CaloAffectedRegionInfoVec* affRegVec=0;
-    if (detStore()->contains<CaloAffectedRegionInfoVec>("LArAffectedRegion")) {
-      if (StatusCode::SUCCESS != detStore()->retrieve(affRegVec,"LArAffectedRegion")) {
-        ATH_MSG_ERROR ( " Cannot retrieve LArAffectedRegion " );
-        return;
-      }
-    }
-    else {
-         affRegVec = new CaloAffectedRegionInfoVec();
-         if (StatusCode::SUCCESS != detStore()->record(affRegVec,"LArAffectedRegion")) {
-           ATH_MSG_ERROR ( " Cannot record LArAffectedRegion " );
-           return;
-         }
-    }
-    affRegVec->clear();
-    affRegVec->reserve(m_ArrayLArAffectedRegionInfo_global.size());
-    for (unsigned int i=0;i<m_ArrayLArAffectedRegionInfo_global.size();++i) {
-        CaloAffectedRegionInfo& info = m_ArrayLArAffectedRegionInfo_global[i];
-        CaloAffectedRegionInfo region(info.get_eta_min(),info.get_eta_max(),info.get_phi_min(),info.get_phi_max(),info.get_layer_min(),info.get_layer_max(),(CaloAffectedRegionInfo::type_problem)(info.get_problem()));
-        affRegVec->push_back(region);
-    }
-
-  } //end first run or new run with new problems
-
-  m_attrListColl->addNewStop(IOVTime(runNumber + 1, 0));  // create (or extend) IOV to the current run
-}
-//=========================================================================================
-void LArAffectedRegionAlg::searchNonNominalHV_EMB() {  // deals with LAr HV, EMBarrel
-  const LArHVManager *manager = NULL;
-
-  //std::cout << " in HV_EMB " << std::endl;
-  if (detStore()->retrieve(manager)==StatusCode::SUCCESS) {
-    
-// accordion calorimeter
-    float HVnominal = HV_nominal("EMB",0.);
-    const EMBHVManager* hvManager_EMB=manager->getEMBHVManager();
-    
-    for (unsigned int iSide=hvManager_EMB->beginSideIndex();iSide<hvManager_EMB->endSideIndex();iSide++) { // loop over HV modules
-      for (unsigned int iPhi=hvManager_EMB->beginPhiIndex();iPhi<hvManager_EMB->endPhiIndex();iPhi++) {
-	for (unsigned int iSector=hvManager_EMB->beginSectorIndex();iSector<hvManager_EMB->endSectorIndex();iSector++) {
-	  for (unsigned int iEta=hvManager_EMB->beginEtaIndex();iEta<hvManager_EMB->endEtaIndex();iEta++) { //0 to 7
-	    EMBHVModuleConstLink hvMod = hvManager_EMB->getHVModule(iSide,iEta,iPhi,iSector);
-
-            float eta_min=hvMod->getEtaMin();
-            float eta_max=hvMod->getEtaMax();
-
-            //std::cout << "iSide,iPhi,iSector,iEta " << iSide << " " << iPhi << " " << iSector << " " << iEta << std::endl;
-            //std::cout << " eta_min , eta_max " << eta_min << " " << eta_max << std::endl;
-
-	    float phi_min=+30.,phi_max=-30.;
-	    
-	    bool are_previous_HV_affected=false;
-            bool are_previous_HV_dead=false;
-	    for (unsigned int ielec=0;ielec<32;ielec++) { //use hvMod->getNumElectrodes when bug is corrected
-	      EMBHVElectrodeConstLink electrode = hvMod->getElectrode(ielec);
-
-	      double hv[2];
-	      for (unsigned int iGap=0;iGap<2;iGap++) { // EMB : 2, TRY TO FIND AUTOMATICALLY NB OF GAPS
-		hv[iGap]=electrode->voltage(iGap);
-	      } //end for iGap
-
-              //std::cout << " electrode HV " << ielec << " " << electrode->getPhi() << " "<< hv[0] << " " << hv[1] << " ";
-
-	      //take decisions according to all the gaps HV :
-              bool isDead=false;
-              if (fabs(hv[0])<DEAD_HV_THRESHOLD && fabs(hv[1])<DEAD_HV_THRESHOLD) isDead=true;
-              bool isAffected=false;
-              if ( !isDead && ((fabs(hv[0]-HVnominal)>HV_NON_NOMINAL_TOLERANCE) || (fabs(hv[1]-HVnominal)>HV_NON_NOMINAL_TOLERANCE))) isAffected=true;
-              //std::cout << " dead/affected " << isDead << " " << isAffected << std::endl;
-          
-              // end previous dead region
-              if (are_previous_HV_dead && !isDead) {
-                 are_previous_HV_dead=false;
-                 //std::cout << " -- end dead region " << eta_min << " " << eta_max << " " <<phi_min << " " << phi_max << std::endl;
-                 CaloAffectedRegionInfo current_CaloAffectedRegionInfo(eta_min,eta_max,phi_min,phi_max,1,3,CaloAffectedRegionInfo::HVdead);
-                 m_ArrayLArAffectedRegionInfo_current_run.push_back(current_CaloAffectedRegionInfo);
-              }
-
-              // end previous affected region
-              if (are_previous_HV_affected && !isAffected) {
-                 are_previous_HV_affected=false;
-                 //std::cout << " -- end affected region " << eta_min << " " << eta_max << " " <<phi_min << " " << phi_max << std::endl;
-                 CaloAffectedRegionInfo current_CaloAffectedRegionInfo(eta_min,eta_max,phi_min,phi_max,1,3,CaloAffectedRegionInfo::HVaffected);
-                 m_ArrayLArAffectedRegionInfo_current_run.push_back(current_CaloAffectedRegionInfo);
-              }
-
-              if (isDead) {
-                 if (!are_previous_HV_dead) {
-                  phi_min=CaloPhiRange::fix(electrode->getPhi()-1e-4);
-                  phi_max=CaloPhiRange::fix(electrode->getPhi()+1e-4);
-                  //std::cout << " -- start dead region " << eta_min << " " << eta_max << " " << phi_min << " " <<phi_max << std::endl;
-                  are_previous_HV_dead = true;
-                 }
-                 else {
-                  extendPhiRegion(electrode->getPhi(),phi_min,phi_max);
-                  //std::cout << " extend dead region " << phi_min << " " << phi_max << std::endl;
-                 }
-              }
-
-              if (isAffected) {
-                 if (!are_previous_HV_affected) {
-                  phi_min=CaloPhiRange::fix(electrode->getPhi()-1e-4);
-                  phi_max=CaloPhiRange::fix(electrode->getPhi()+1e-4);
-                  //std::cout << " -- start affected region " << eta_min << " " << eta_max << " " << phi_min << " " <<phi_max << std::endl;
-                  are_previous_HV_affected = true;
-                 }
-                 else {
-                  extendPhiRegion(electrode->getPhi(),phi_min,phi_max);
-                  //std::cout << " extend affected region " << phi_min << " " << phi_max << std::endl;
-                 }
-              }
-
-	    } // end for ielec
-	    
-	    if (are_previous_HV_affected) { //in case a non nominal exists, stores it if we finish the 32 electrodes (because else the are_previous_HV_affected will be reinitialized for the next 32 electrodes serie )
-              //std::cout << "  -- finish affected region after electrode loop " << eta_min << " " << eta_max << " " << phi_min << " " <<phi_max << std::endl;
-	      CaloAffectedRegionInfo current_CaloAffectedRegionInfo(eta_min,eta_max,phi_min,phi_max,1,3,CaloAffectedRegionInfo::HVaffected);
-	      m_ArrayLArAffectedRegionInfo_current_run.push_back(current_CaloAffectedRegionInfo);	      
-	    }
-            if (are_previous_HV_dead) {
-              //std::cout << "  -- finish dead region after electrode loop " << eta_min << " " << eta_max << " " << phi_min << " " <<phi_max << std::endl;
-              CaloAffectedRegionInfo current_CaloAffectedRegionInfo(eta_min,eta_max,phi_min,phi_max,1,3,CaloAffectedRegionInfo::HVdead);
-              m_ArrayLArAffectedRegionInfo_current_run.push_back(current_CaloAffectedRegionInfo);
-            }
-	  } // end for iEta
-	} // end for iSector
-      } // end for iPhi
-    } //end for iSide
-
-// barrel presampler
-    //std::cout << " start loop over EMBPS " << std::endl;
-    const EMBPresamplerHVManager* hvManager_EMBPS=manager->getEMBPresamplerHVManager();
-    HVnominal = HV_nominal("EMBPS",0.);
-    for (unsigned int iSide=hvManager_EMBPS->beginSideIndex();iSide<hvManager_EMBPS->endSideIndex();iSide++) { // loop over HV modules
-      for (unsigned int iPhi=hvManager_EMBPS->beginPhiIndex();iPhi<hvManager_EMBPS->endPhiIndex();iPhi++) {
-          for (unsigned int iEta=hvManager_EMBPS->beginEtaIndex();iEta<hvManager_EMBPS->endEtaIndex();iEta++) { //0 to 7
-            EMBPresamplerHVModuleConstLink hvMod = hvManager_EMBPS->getHVModule(iSide,iEta,iPhi);
-            //std::cout << "iSide,iPhi,iEta " << iSide << " " << iPhi << " " << iEta << std::endl;
-            double hv[2];
-            for (int iGap=0;iGap<2;iGap++) {
-             hv[iGap] =  hvMod->voltage(iGap);
-            }
-            //std::cout << "  HV " <<  hv[0] << " " << hv[1] << " ";
-            float eta_min=hvMod->getEtaMin();
-            float eta_max=hvMod->getEtaMax();
-            float phi_min=CaloPhiRange::fix(hvMod->getPhiMin());
-            float phi_max=CaloPhiRange::fix(hvMod->getPhiMax());
-            //std::cout << "  etamin,etamax,phimin,phimax " << eta_min << " " << eta_max << " " << phi_min << " " << phi_max ;
-
-            //take decisions according to all the gaps HV :
-            bool isDead=false;
-            if (fabs(hv[0])<DEAD_HV_THRESHOLD && fabs(hv[1])<DEAD_HV_THRESHOLD) isDead=true;
-            bool isAffected=false;
-            if ( !isDead && ((fabs(hv[0]-HVnominal)>HV_NON_NOMINAL_TOLERANCE) || (fabs(hv[1]-HVnominal)>HV_NON_NOMINAL_TOLERANCE))) isAffected=true;
-            //std::cout << " dead/affected " << isDead << " " << isAffected << std::endl;
-
-            if (isDead) {
-              CaloAffectedRegionInfo current_CaloAffectedRegionInfo(eta_min,eta_max,phi_min,phi_max,0,0,CaloAffectedRegionInfo::HVdead);
-              m_ArrayLArAffectedRegionInfo_current_run.push_back(current_CaloAffectedRegionInfo);             
-            }
-            if (isAffected) {
-              CaloAffectedRegionInfo current_CaloAffectedRegionInfo(eta_min,eta_max,phi_min,phi_max,0,0,CaloAffectedRegionInfo::HVaffected);
-              m_ArrayLArAffectedRegionInfo_current_run.push_back(current_CaloAffectedRegionInfo);
-            }
-          }       // loop over iEta EMBPS
-      }        // loop over iphi EMBPS
-    }    // lop over EMBPS side
-
-
-
-
-  }
-}
-//=========================================================================================
-void LArAffectedRegionAlg::searchNonNominalHV_EMEC_OUTER() { // deals with LAr HV, EM EndCap OUTER
-  const LArHVManager *manager = NULL;
-
-  //std::cout << " start HV_EMEC_OUTER " << std::endl;
-  if (detStore()->retrieve(manager)==StatusCode::SUCCESS) {
-      
-    const EMECHVManager* hvManager_EMEC=manager->getEMECHVManager(EMECHVModule::OUTER);
-
-    for (unsigned int iSide=hvManager_EMEC->beginSideIndex();iSide<hvManager_EMEC->endSideIndex();iSide++) { // loop over HV modules
-      for (unsigned int iPhi=hvManager_EMEC->beginPhiIndex();iPhi<hvManager_EMEC->endPhiIndex();iPhi++) {
-	for (unsigned int iSector=hvManager_EMEC->beginSectorIndex();iSector<hvManager_EMEC->endSectorIndex();iSector++) {
-	  for (unsigned int iEta=hvManager_EMEC->beginEtaIndex();iEta<hvManager_EMEC->endEtaIndex();iEta++) {
-	    EMECHVModuleConstLink hvMod=hvManager_EMEC->getHVModule(iSide,iEta,iPhi,iSector);
-
-            float etaMod = 0.5*(fabs(hvMod->getEtaMin())+fabs(hvMod->getEtaMax()));
-            float HVnominal = HV_nominal("EMEC",etaMod);
-
-            float eta_min=hvMod->getEtaMin();
-            float eta_max=hvMod->getEtaMax();
-
-            //std::cout << "iSide,iPhi,iSector,iEta " << iSide << " " << iPhi << " " << iSector << " " << iEta << std::endl;
-            //std::cout << " eta_min , eta_max " << eta_min << " " << eta_max << std::endl;
-
-
-	    float phi_min=+30.,phi_max=-30.;
-
-	    bool are_previous_HV_affected=false;
-            bool are_previous_HV_dead=false;
-            //std::cout << " number of electrodes " << hvMod->getNumElectrodes() << std::endl;
-	    for (unsigned int ielec=0;ielec<hvMod->getNumElectrodes();ielec++) { //use hvMod->getNumElectrodes when bug is corrected
-	      EMECHVElectrodeConstLink electrode = hvMod->getElectrode(ielec);
-
-	      double hv[2];
-	      for (unsigned int iGap=0;iGap<2;iGap++) { //EMEC : 2 gaps, TRY TO FIND AUTOMATICALLY NB OF GAPS
-		hv[iGap]=electrode->voltage(iGap);
-	      } //end for iGap
-
-	      //------------------
-	      //take decisions according to all the gaps HV :
-              //std::cout << " electrode HV " << ielec << " " << electrode->getPhi() << " "<< hv[0] << " " << hv[1] << " " ;
-
-	      //take decisions according to all the gaps HV :
-              bool isDead=false;
-              if (fabs(hv[0])<DEAD_HV_THRESHOLD && fabs(hv[1])<DEAD_HV_THRESHOLD) isDead=true;
-              bool isAffected=false;
-              if ( !isDead && ((fabs(hv[0]-HVnominal)>HV_NON_NOMINAL_TOLERANCE) || (fabs(hv[1]-HVnominal)>HV_NON_NOMINAL_TOLERANCE))) isAffected=true;
-              //std::cout << " isDead/isAffected " << isDead << " " << isAffected << std::endl;
-          
-              // end previous dead region
-              if (are_previous_HV_dead && !isDead) {
-                 are_previous_HV_dead=false;
-                 //std::cout << " -- end dead region " << eta_min << " " << eta_max << " " <<phi_min << " " << phi_max << std::endl;
-                 CaloAffectedRegionInfo current_CaloAffectedRegionInfo(eta_min,eta_max,phi_min,phi_max,5,7,CaloAffectedRegionInfo::HVdead);
-                 m_ArrayLArAffectedRegionInfo_current_run.push_back(current_CaloAffectedRegionInfo);
-              }
-
-              // end previous affected region
-              if (are_previous_HV_affected && !isAffected) {
-                 are_previous_HV_affected=false;
-                 //std::cout << " -- end affected region " << eta_min << " " << eta_max << " " <<phi_min << " " << phi_max << std::endl;
-                 CaloAffectedRegionInfo current_CaloAffectedRegionInfo(eta_min,eta_max,phi_min,phi_max,5,7,CaloAffectedRegionInfo::HVaffected);
-                 m_ArrayLArAffectedRegionInfo_current_run.push_back(current_CaloAffectedRegionInfo);
-              }
-
-              if (isDead) {
-                 if (!are_previous_HV_dead) {
-                  phi_min=CaloPhiRange::fix(electrode->getPhi()-1e-4);
-                  phi_max=CaloPhiRange::fix(electrode->getPhi()+1e-4);
-                  are_previous_HV_dead = true;
-                  //std::cout << " -- start dead region " << eta_min << " " << eta_max << " " << phi_min << " " <<phi_max << std::endl;
-                 }
-                 else {
-                  extendPhiRegion(electrode->getPhi(),phi_min,phi_max);
-                  //std::cout << "  extend affected region " << phi_min << " " << phi_max << std::endl;
-                 }
-              }
-
-              if (isAffected) {
-                 if (!are_previous_HV_affected) {
-                  phi_min=CaloPhiRange::fix(electrode->getPhi()-1e-4);
-                  phi_max=CaloPhiRange::fix(electrode->getPhi()+1e-4);
-                  are_previous_HV_affected = true;
-                  //std::cout << " -- start affected region " << eta_min << " " << eta_max << " " << phi_min << " " <<phi_max << std::endl;
-                 }
-                 else {
-                  extendPhiRegion(electrode->getPhi(),phi_min,phi_max);
-                  //std::cout << " extend affected region " << phi_min << " " << phi_max << std::endl;
-                 }
-              }
-
-	    } // end for ielec
-	    
-	    if (are_previous_HV_affected) { //in case a non nominal exists, stores it if we finish the 32 electrodes (because else the are_previous_HV_affected will be reinitialized for the next 32 electrodes serie )
-              //std::cout << "   - finih affected region after electrode loop " << eta_min << " " << eta_max << " " << phi_max << " " <<phi_max << std::endl;
-	      CaloAffectedRegionInfo current_CaloAffectedRegionInfo(eta_min,eta_max,phi_min,phi_max,5,7,CaloAffectedRegionInfo::HVaffected);
-	      m_ArrayLArAffectedRegionInfo_current_run.push_back(current_CaloAffectedRegionInfo);	      
-	    }
-            if (are_previous_HV_dead) {
-              //std::cout << " -- finish dead region after electrode loop " << eta_min << " " << eta_max << " " << phi_max << " " <<phi_max << std::endl;
-              CaloAffectedRegionInfo current_CaloAffectedRegionInfo(eta_min,eta_max,phi_min,phi_max,5,7,CaloAffectedRegionInfo::HVdead);
-              m_ArrayLArAffectedRegionInfo_current_run.push_back(current_CaloAffectedRegionInfo);
-            }
-
-	  } // end for iEta
-	} // end for iSector
-      } // end for iPhi
-    } //end for iSide
-
-// endcap presampler
-    //std::cout << " start loop over EMECPS " << std::endl;
-    const EMECPresamplerHVManager* hvManager_EMECPS=manager->getEMECPresamplerHVManager();
-    float HVnominal = HV_nominal("EMECPS",0.);
-    for (unsigned int iSide=hvManager_EMECPS->beginSideIndex();iSide<hvManager_EMECPS->endSideIndex();iSide++) { // loop over HV modules
-      for (unsigned int iPhi=hvManager_EMECPS->beginPhiIndex();iPhi<hvManager_EMECPS->endPhiIndex();iPhi++) {
-            EMECPresamplerHVModuleConstLink hvMod = hvManager_EMECPS->getHVModule(iSide,iPhi);
-            //std::cout << "iSide,iPhi" << iSide << " " << iPhi << std::endl;
-            double hv[2];
-            for (int iGap=0;iGap<2;iGap++) {
-             hv[iGap] =  fabs(hvMod->voltage(iGap));
-            }
-            //std::cout << "  HV " <<  hv[0] << " " << hv[1] << " ";
-            float eta_min=hvMod->getEtaMin(); 
-            float eta_max=hvMod->getEtaMax();
-            float phi_min=CaloPhiRange::fix(hvMod->getPhiMin());
-            float phi_max=CaloPhiRange::fix(hvMod->getPhiMax());
-            //std::cout << "  etamin,etamax,phimin,phimax " << eta_min << " " << eta_max << " " << phi_min << " " << phi_max ;
-
-            //take decisions according to all the gaps HV :
-            bool isDead=false;
-            if (fabs(hv[0])<DEAD_HV_THRESHOLD && fabs(hv[1])<DEAD_HV_THRESHOLD) isDead=true;
-            bool isAffected=false;
-            if ( !isDead && ((fabs(hv[0]-HVnominal)>HV_NON_NOMINAL_TOLERANCE) || (fabs(hv[1]-HVnominal)>HV_NON_NOMINAL_TOLERANCE))) isAffected=true;
-            //std::cout << " dead/affected " << isDead << " " << isAffected << std::endl;
-
-            if (isDead) {
-              CaloAffectedRegionInfo current_CaloAffectedRegionInfo(eta_min,eta_max,phi_min,phi_max,4,4,CaloAffectedRegionInfo::HVdead);
-              m_ArrayLArAffectedRegionInfo_current_run.push_back(current_CaloAffectedRegionInfo);             
-            }
-            if (isAffected) {
-              CaloAffectedRegionInfo current_CaloAffectedRegionInfo(eta_min,eta_max,phi_min,phi_max,4,4,CaloAffectedRegionInfo::HVaffected);
-              m_ArrayLArAffectedRegionInfo_current_run.push_back(current_CaloAffectedRegionInfo);
-            }
-      }        // loop over iphi EMECPS
-    }    // lop over EMECPS side
-    
-
-  }
-}
-//=========================================================================================
-void LArAffectedRegionAlg::searchNonNominalHV_EMEC_INNER() { // deals with LAr HV, EM EndCap INNER
-  const LArHVManager *manager = NULL;
-
-  //std::cout << " start loop over EMEC_INNER " << std::endl;
-  if (detStore()->retrieve(manager)==StatusCode::SUCCESS) {
-
-    const EMECHVManager* hvManager_EMEC=manager->getEMECHVManager(EMECHVModule::INNER);
-
-    for (unsigned int iSide=hvManager_EMEC->beginSideIndex();iSide<hvManager_EMEC->endSideIndex();iSide++) { // loop over HV modules
-      for (unsigned int iPhi=hvManager_EMEC->beginPhiIndex();iPhi<hvManager_EMEC->endPhiIndex();iPhi++) {
-	for (unsigned int iSector=hvManager_EMEC->beginSectorIndex();iSector<hvManager_EMEC->endSectorIndex();iSector++) {
-	  for (unsigned int iEta=hvManager_EMEC->beginEtaIndex();iEta<hvManager_EMEC->endEtaIndex();iEta++) {
-	    EMECHVModuleConstLink hvMod=hvManager_EMEC->getHVModule(iSide,iEta,iPhi,iSector);
-
-            float etaMod = 0.5*(fabs(hvMod->getEtaMin())+fabs(hvMod->getEtaMax()));
-            float HVnominal = HV_nominal("EMEC",etaMod);
-
-            float eta_min = hvMod->getEtaMin();
-            float eta_max = hvMod->getEtaMax();
-
-            //std::cout << "iSide,iPhi,iSector,iEta " << iSide << " " << iPhi << " " << iSector << " " << iEta << std::endl;
-            //std::cout << " eta_min , eta_max " << eta_min << " " << eta_max << std::endl;
-
-	    float phi_min=+30.,phi_max=-30.;
-
-	    bool are_previous_HV_affected=0;
-	    bool are_previous_HV_dead=0;
-	    //	    std::cout << "There are " << hvMod->getNumElectrodes() << " electrodes" << std::endl;
-	    for (unsigned int ielec=0;ielec<hvMod->getNumElectrodes();ielec++) { //use hvMod->getNumElectrodes when bug is corrected
-	      EMECHVElectrodeConstLink electrode = hvMod->getElectrode(ielec);
-
-	      double hv[2];
-	      for (unsigned int iGap=0;iGap<2;iGap++) { //EMEC : 2 gaps, TRY TO FIND AUTOMATICALLY NB OF GAPS
-		hv[iGap]=electrode->voltage(iGap);
-	      } //end for iGap
-
-	      //------------------
-	      //------------------
-	      //take decisions according to all the gaps HV :
-              //std::cout << " electrode HV " << ielec << " " << electrode->getPhi() << " "<< hv[0] << " " << hv[1] << " ";
-
-	      //take decisions according to all the gaps HV :
-              bool isDead=false;
-              if (fabs(hv[0])<DEAD_HV_THRESHOLD && fabs(hv[1])<DEAD_HV_THRESHOLD) isDead=true;
-              bool isAffected=false;
-              if ( !isDead && ((fabs(hv[0]-HVnominal)>HV_NON_NOMINAL_TOLERANCE) || (fabs(hv[1]-HVnominal)>HV_NON_NOMINAL_TOLERANCE))) isAffected=true;
-              //std::cout << " isDead, isAffected " << isDead << " " << isAffected << std::endl;
-          
-              // end previous dead region
-              if (are_previous_HV_dead && !isDead) {
-                 are_previous_HV_dead=false;
-                 //std::cout << " -- end dead region " << eta_min << " " << eta_max << " " <<phi_min << " " << phi_max << std::endl;
-                 CaloAffectedRegionInfo current_CaloAffectedRegionInfo(eta_min,eta_max,phi_min,phi_max,5,7,CaloAffectedRegionInfo::HVdead);
-                 m_ArrayLArAffectedRegionInfo_current_run.push_back(current_CaloAffectedRegionInfo);
-              }
-
-              // end previous affected region
-              if (are_previous_HV_affected && !isAffected) {
-                 are_previous_HV_affected=false;
-                 //std::cout << " -- end affected region " << eta_min << " " << eta_max << " " <<phi_min << " " << phi_max << std::endl;
-                 CaloAffectedRegionInfo current_CaloAffectedRegionInfo(eta_min,eta_max,phi_min,phi_max,5,7,CaloAffectedRegionInfo::HVaffected);
-                 m_ArrayLArAffectedRegionInfo_current_run.push_back(current_CaloAffectedRegionInfo);
-              }
-
-              if (isDead) {
-                 if (!are_previous_HV_dead) {
-                  phi_min=CaloPhiRange::fix(electrode->getPhi()-1e-4);
-                  phi_max=CaloPhiRange::fix(electrode->getPhi()+1e-4);
-                  //std::cout << " -- start dead region " << phi_min << " " << phi_max << std::endl;
-                  are_previous_HV_dead = true;
-                 }
-                 else {
-                  extendPhiRegion(electrode->getPhi(),phi_min,phi_max);
-                  //std::cout << "  extend dead region " << phi_min << " " << phi_max << std::endl;
-                 }
-              }
-
-              if (isAffected) {
-                 if (!are_previous_HV_affected) {
-                  phi_min=CaloPhiRange::fix(electrode->getPhi()-1e-4);
-                  phi_max=CaloPhiRange::fix(electrode->getPhi()+1e-4);
-                  are_previous_HV_affected = true;
-                  //std::cout << " -- start affected region " << phi_min << " " << phi_max << std::endl;
-                 }
-                 else {
-                   extendPhiRegion(electrode->getPhi(),phi_min,phi_max);
-                   //std::cout << "  extend affected region " << phi_min << " " << phi_max << std::endl;
-                 }
-              }
-
-	    } // end for ielec
-	    
-	    if (are_previous_HV_affected) { //in case a non nominal exists, stores it if we finish the 32 electrodes (because else the are_previous_HV_affected will be reinitialized for the next 32 electrodes serie )
-              //std::cout << "   - finih affected region after electrode loop " << eta_min << " " << eta_max << " " << phi_max << " " <<phi_max << std::endl;
-	      CaloAffectedRegionInfo current_CaloAffectedRegionInfo(eta_min,eta_max,phi_min,phi_max,5,7,CaloAffectedRegionInfo::HVaffected);
-	      m_ArrayLArAffectedRegionInfo_current_run.push_back(current_CaloAffectedRegionInfo);	      
-	    }
-            if (are_previous_HV_dead) {
-              //std::cout << "    - end dead region after electrode loop " << eta_min << " " << eta_max << " " << phi_max << " " <<phi_max << std::endl;
-              CaloAffectedRegionInfo current_CaloAffectedRegionInfo(eta_min,eta_max,phi_min,phi_max,5,7,CaloAffectedRegionInfo::HVdead);
-              m_ArrayLArAffectedRegionInfo_current_run.push_back(current_CaloAffectedRegionInfo);
-            }
-	  } // end for iEta
-	} // end for iSector
-      } // end for iPhi
-    } //end for iSide
-  }
-}
-//=========================================================================================
-void LArAffectedRegionAlg::searchNonNominalHV_HEC() { // deals with LAr HV, HEC
-  
- // std::cout << " in HEC " << std::endl;
-  const LArHVManager *manager = NULL;
-  float etamax_layer[4]={3.3,3.1,3.1,3.3};
-  float etamin_layer[4]={1.5,1.5,1.6,1.7};
- 
-  float HVnominal = HV_nominal("HEC",0.);
-
-
-  if (detStore()->retrieve(manager)==StatusCode::SUCCESS) {
-    //no sector index, no eta index==>sampling index
-  
-    const HECHVManager* hvManager_HEC=manager->getHECHVManager();
-    
-    for (unsigned int iSide=hvManager_HEC->beginSideIndex();iSide<hvManager_HEC->endSideIndex();iSide++) { // loop over HV modules      
-      for (unsigned int iPhi=hvManager_HEC->beginPhiIndex();iPhi<hvManager_HEC->endPhiIndex();iPhi++) {
-	for (unsigned int iSampling=hvManager_HEC->beginSamplingIndex();iSampling<hvManager_HEC->endSamplingIndex();iSampling++) {
-          float eta_min,eta_max;
-          if (iSide==1) {
-           eta_min = etamin_layer[iSampling];
-           eta_max = etamax_layer[iSampling];
-          } else {
-           eta_min = -1.*etamax_layer[iSampling];
-           eta_max = -1.*etamin_layer[iSampling];
-         }
-
-	  HECHVModuleConstLink hvMod = hvManager_HEC->getHVModule(iSide,iPhi,iSampling);
-          //std::cout << " iSide,iPhi,iSampling " << iSide << " " << iPhi << " " << iSampling << std::endl;
-
-	  double hv[4] = {0};
-	  for (unsigned int iGap=0;iGap<hvMod->getNumSubgaps();iGap++) {//HEC : 4 gaps, TRY TO FIND AUTOMATICALLY NB OF GAPS
-	    HECHVSubgapConstLink subgap=hvMod->getSubgap(iGap);
-	    if(iGap<4) hv[iGap]=subgap->voltage();
-	  }// end for iGap
-
-	  //------------------
-          //std::cout << " HV values " << hv[0] << " " << hv[1] << " " << hv[2] << " " << hv[3] << " ";
-
-          //take decisions according to all the gaps HV :
-          bool isDead=false;
-          if (fabs(hv[0])<DEAD_HV_THRESHOLD && fabs(hv[1])<DEAD_HV_THRESHOLD  && fabs(hv[2])<DEAD_HV_THRESHOLD && fabs(hv[3])<DEAD_HV_THRESHOLD) isDead=true;
-          bool isAffected=false;
-          if ( !isDead && ((fabs(hv[0]-HVnominal)>HV_NON_NOMINAL_TOLERANCE) || (fabs(hv[1]-HVnominal)>HV_NON_NOMINAL_TOLERANCE) || 
-                           (fabs(hv[2]-HVnominal)>HV_NON_NOMINAL_TOLERANCE) || (fabs(hv[3]-HVnominal)>HV_NON_NOMINAL_TOLERANCE)) ) isAffected=true;
-          //std::cout << " isDead/isAffected " << isDead << " " << isAffected << std::endl;
-
-          float phiMin = CaloPhiRange::fix(hvMod->getPhiMin());
-          float phiMax = CaloPhiRange::fix(hvMod->getPhiMax());
-
-
-	  if (isDead) { //stores it, DEAD means all hvs < threshold
-            //std::cout << " new dead region " << eta_min << " " << eta_max << " " << phiMin << " " << phiMax << " layer " << 8+iSampling << std::endl;
-	    CaloAffectedRegionInfo current_CaloAffectedRegionInfo(eta_min,eta_max,phiMin,phiMax,8+iSampling,8+iSampling,CaloAffectedRegionInfo::HVdead);
-	    m_ArrayLArAffectedRegionInfo_current_run.push_back(current_CaloAffectedRegionInfo);
-	  }
-          if (isAffected) {
-            //std::cout << " new affected region " << eta_min << " " << eta_max << " " << phiMin << " " << phiMax << " layer " << 8+iSampling << std::endl;
-            CaloAffectedRegionInfo current_CaloAffectedRegionInfo(eta_min,eta_max,phiMin,phiMax,8+iSampling,8+iSampling,CaloAffectedRegionInfo::HVaffected);
-            m_ArrayLArAffectedRegionInfo_current_run.push_back(current_CaloAffectedRegionInfo);
-          }
-
-	} //end for iSampling
-      }//end for iPhi
-    }//end for iSide
-  }
-}
-//=========================================================================================
-void LArAffectedRegionAlg::searchNonNominalHV_FCAL() { // deals with LAr HV, FCAL
-
-  //std::cout << " inFCAL " << std::endl;
-  const LArHVManager *manager = NULL;
-  if (detStore()->retrieve(manager)==StatusCode::SUCCESS) {  
-    
-    const FCALHVManager *hvManager_FCAL=manager->getFCALHVManager();
-    
-    for (unsigned int iSide=hvManager_FCAL->beginSideIndex();iSide<hvManager_FCAL->endSideIndex();iSide++) { // loop over HV modules
-      float eta_min=3.1,eta_max=4.9;
-      if (iSide==0) {
-         eta_min=-4.9;
-         eta_max=-3.1;
-      }
-      for (unsigned int iSampling=hvManager_FCAL->beginSamplingIndex();iSampling<hvManager_FCAL->endSamplingIndex();iSampling++) {
-        float HVnominal = HV_nominal("FCAL",(float)(iSampling));
-	for (unsigned int iSector=hvManager_FCAL->beginSectorIndex(iSampling);iSector<hvManager_FCAL->endSectorIndex(iSampling);iSector++) {
-
-	  FCALHVModuleConstLink hvMod = hvManager_FCAL->getHVModule(iSide,iSector,iSampling);
-          //std::cout << " FCAL HVModule side,sampling,sector " << iSide << " " << iSampling << " " << iSector << std::endl;
-          //std::cout << "   HV nominal " << HVnominal << std::endl;
- 
-          float dphi=CaloPhiRange::twopi()/16;
-          if (iSampling==1) dphi=CaloPhiRange::twopi()/8.;
-          if (iSampling==2) dphi=CaloPhiRange::twopi()/4.;
-          float phi_min = ((float)(iSector))*dphi;
-          phi_min =   CaloPhiRange::fix(phi_min);
-          float phi_max = CaloPhiRange::fix(dphi+phi_min);
-        
-          //std::cout << " eta_min,eta_max,phi_min,phi_max " << eta_min << " " << eta_max << " " << phi_min << " " << phi_max << std::endl;
-	  
-          //std::cout << "   number of lines " << hvMod->getNumHVLines() << std::endl;
-          float hv[4] = {0};
-	  for (unsigned int iLine=0;iLine<hvMod->getNumHVLines();iLine++) {
-	    FCALHVLineConstLink hvline = hvMod->getHVLine(iLine);
-	    if (iLine<4) hv[iLine] = hvline->voltage();
-          }
-          //std::cout << " HV values " << hv[0] << " " << hv[1] << " " << hv[2] << " " << hv[3] <<  " ";
-	  //------------------
-	  //take decisions according to all the gaps HV :
-          bool isDead=false;
-          if (fabs(hv[0]) < DEAD_HV_THRESHOLD && fabs(hv[1]) < DEAD_HV_THRESHOLD && fabs(hv[2]) < DEAD_HV_THRESHOLD && fabs(hv[3]) < DEAD_HV_THRESHOLD) isDead=true;
-          bool isAffected=false;
-          if ( !isDead && ((fabs(hv[0]-HVnominal)>HV_NON_NOMINAL_TOLERANCE) || (fabs(hv[1]-HVnominal)>HV_NON_NOMINAL_TOLERANCE) ||
-                           (fabs(hv[2]-HVnominal)>HV_NON_NOMINAL_TOLERANCE) || (fabs(hv[3]-HVnominal)>HV_NON_NOMINAL_TOLERANCE)) ) isAffected=true;
-          //std::cout << " isDead/isAffected " << isDead << " " << isAffected << std::endl;
-
-	    
-	  if (isAffected) { 
-            //std::cout << " -- store affected region " << std::endl;
-	    CaloAffectedRegionInfo current_CaloAffectedRegionInfo(eta_min,eta_max,phi_min,phi_max,21+iSampling,21+iSampling,CaloAffectedRegionInfo::HVaffected);
-	    m_ArrayLArAffectedRegionInfo_current_run.push_back(current_CaloAffectedRegionInfo);	      
-	  }
-          if (isDead) { 
-            //std::cout << " -- store dead region " << std::endl;
-            CaloAffectedRegionInfo current_CaloAffectedRegionInfo(eta_min,eta_max,phi_min,phi_max,21+iSampling,21+iSampling,CaloAffectedRegionInfo::HVdead);
-            m_ArrayLArAffectedRegionInfo_current_run.push_back(current_CaloAffectedRegionInfo);
-          }
-	} //end iSector
-      } //end iSampling
-    }// end iSide
-  } //end status success
-}
-//=========================================================================================
-StatusCode LArAffectedRegionAlg::updateMethod() { //store informations on the missing Febs w/ range of eta, phi, layer
-  ATH_MSG_INFO ( "updateMethod()" );
-  
-  SG::ReadCondHandle<LArBadFebCont> bfHdl{m_BFKey};
-  const LArBadFebCont* bfCont{*bfHdl};
-  if(!bfCont) {
-      ATH_MSG_ERROR( "Do not have missing FEBs " << m_BFKey.key() );
-      return StatusCode::FAILURE;
-  }
-  SG::ReadCondHandle<LArOnOffIdMapping> cablingHdl{m_cablingKey};
-  const LArOnOffIdMapping* cabling{*cablingHdl};
-  if(!cabling) {
-      ATH_MSG_ERROR( "Do not have cabling object LArOnOffIdMapping");
-      return StatusCode::FAILURE;
-  }
-
-  std::vector<HWIdentifier>::const_iterator febid_it=m_onlineID->feb_begin();
-  std::vector<HWIdentifier>::const_iterator febid_end_it=m_onlineID->feb_end();
-
-  for (;febid_it!=febid_end_it;++febid_it) {
-      
-    bool IsMissingFeb=(bfCont->status(*febid_it).deadAll() || bfCont->status(*febid_it).deadReadout());
-    
-    if (IsMissingFeb) {       //flag for special treatment for FEB that has non contiguous eta regions, so we have to separate them
-      bool is_normal=0; //FEB without discontinuity
-      bool is_additive1=0; //FEB with a discontinuity
-      
-      int layer_min=+30,layer_max=-30;
-      float eta_min=+30,eta_max=-30;
-      float phi_min=+30,phi_max=-30;
-      
-      int layer_min_additive1=+30,layer_max_additive1=-30;
-      float eta_min_additive1=+30,eta_max_additive1=-30;
-      float phi_min_additive1=+30,phi_max_additive1=-30;
-      
-      int chans_per_feb = m_onlineID->channelInSlotMax(*febid_it);
-      
-      for (int icha=0;icha<chans_per_feb;icha++) {   //loop on each channel of the relevant FEB
-	HWIdentifier channelId=m_onlineID->channel_Id(*febid_it,icha);
-
-	if (cabling->isOnlineConnected(channelId)) {
-	  Identifier offlineId=cabling->cnvToIdentifier(channelId);
-	  const CaloDetDescrElement* caloddElement=m_calodetdescrmgr->get_element(offlineId);
-	  
-	  CaloCell_ID::CaloSample current_layer=caloddElement->getSampling(); // calo layer
-	  float current_eta=caloddElement->eta();
-	  float current_eta_low=caloddElement->eta()-0.5*caloddElement->deta();
-	  float current_eta_high=caloddElement->eta()+0.5*caloddElement->deta();
-	  float current_phi_low=caloddElement->phi()-0.5*caloddElement->dphi();
-	  float current_phi_high=caloddElement->phi()+0.5*caloddElement->dphi();
-	  
-	  if (caloddElement->is_lar_em_barrel() && caloddElement->getLayer()==3 && fabs(current_eta)>0.79 && fabs(current_eta)<1.33) { //EMB, back sampling, slot 12 : special treatment : this FEB has non contiguous eta regions, so we have to separate them
-	    is_additive1=1; //in order to add it to the summary only if it happens
-	    
-	    if (current_layer<layer_min_additive1)
-	      layer_min_additive1=current_layer;
-	    if (current_layer>layer_max_additive1)
-	      layer_max_additive1=current_layer;
-	    
-	    if (current_eta_low<eta_min_additive1)
-	      eta_min_additive1=current_eta_low;
-	    if (current_eta_high>eta_max_additive1)
-	      eta_max_additive1=current_eta_high;
-	    
-            extendPhiRegion(current_phi_low,phi_min_additive1,phi_max_additive1);
-            extendPhiRegion(current_phi_high,phi_min_additive1,phi_max_additive1);
-	    
-	    //	    std::cout << "found the special case, icha=" << icha << ", etamin=" << eta_min_additive1 << ", current layer=" << current_layer << ", current eta=" << current_eta << std::endl;
-	  }
-	  else { //normal case
-	    is_normal=1; // normal case
-	    
-	    if (current_layer<layer_min)
-	      layer_min=current_layer;
-	    if (current_layer>layer_max)
-	      layer_max=current_layer;
-	    
-	    if (current_eta_low<eta_min)
-	      eta_min=current_eta_low;
-	    if (current_eta_high>eta_max)
-	      eta_max=current_eta_high;
-	    
-            extendPhiRegion(current_phi_low,phi_min,phi_max);
-            extendPhiRegion(current_phi_high,phi_min,phi_max);
-
-	  }
-	} //end of isOnlineConnected()
-      } // end of loop on channels
-      
-      if (is_normal) {
-	CaloAffectedRegionInfo current_CaloAffectedRegionInfo(eta_min,eta_max,phi_min,phi_max,layer_min,layer_max,CaloAffectedRegionInfo::missingReadout);
-	m_ArrayLArAffectedRegionInfo_current_run.push_back(current_CaloAffectedRegionInfo);
-      }
-      
-      if (is_additive1) {
-	CaloAffectedRegionInfo current_additive1_CaloAffectedRegionInfo(eta_min_additive1,eta_max_additive1,phi_min_additive1,phi_max_additive1,layer_min_additive1,layer_max_additive1,CaloAffectedRegionInfo::missingReadout);
-	m_ArrayLArAffectedRegionInfo_current_run.push_back(current_additive1_CaloAffectedRegionInfo);
-      }
-    } // end of isMissingFeb  
-  } // end of loop on Febs  
-  return StatusCode::SUCCESS;
-}
-//================================================================
-StatusCode LArAffectedRegionAlg::updateAffectedRegionsFromDB(IOVSVC_CALLBACK_ARGS)
-{
-  // Converter attribute list collection into vector of AffectedRegionInfos
-
-  ATH_MSG_INFO ( "updateAffectedRegionsFromDB()" );
-
-  // retrieve from detStore 
-  const CondAttrListCollection* attrListColl = 0;
-  ATH_CHECK( detStore()->retrieve(attrListColl, "/LAR/LArAffectedRegionInfo") );
-
-  CaloAffectedRegionInfoVec* affRegVec = 0;
-
-  if (detStore()->contains<CaloAffectedRegionInfoVec>("LArAffectedRegion")) {
-    ATH_CHECK( detStore()->retrieve(affRegVec,"LArAffectedRegion") );
-    affRegVec->clear();
-  }
-  else {
-      affRegVec = new CaloAffectedRegionInfoVec();
-      ATH_CHECK( detStore()->record(affRegVec, "LArAffectedRegion") );
-  }
-
-  
-  // Loop over collection
-  CondAttrListCollection::const_iterator first = attrListColl->begin();
-  CondAttrListCollection::const_iterator last  = attrListColl->end();
-  for (; first != last; ++first) {
-      std::ostringstream attrStr1;
-      (*first).second.toOutputStream( attrStr1 );
-      ATH_MSG_DEBUG ( "ChanNum " << (*first).first << 
-                      " Attribute list " << attrStr1.str() );
-      //      const AttributeList& attrList = (*first).second;
-      const coral::AttributeList& attrList = (*first).second;
-      CaloAffectedRegionInfo info;
-      float eta_min = attrList["eta_min"].data<float>();
-      float eta_max = attrList["eta_max"].data<float>();
-      float phi_min = attrList["phi_min"].data<float>();
-      float phi_max = attrList["phi_max"].data<float>();
-      int layer_min = attrList["layer_min"].data<int>();
-      int layer_max = attrList["layer_max"].data<int>();
-      CaloAffectedRegionInfo::type_problem problem = (CaloAffectedRegionInfo::type_problem)(attrList["problem"].data<int>());
-
-      info.FillCaloAffectedRegionInfo(eta_min,eta_max,phi_min,phi_max,layer_min,layer_max,problem);
-      affRegVec->push_back(info);
-  }
-
-  return StatusCode::SUCCESS;
-}
-//================================================================
-StatusCode LArAffectedRegionAlg::execute() {
-  ATH_MSG_DEBUG ( "execute()" );
-  
-  if (!m_readingFromBytestream) {  //put the print to check that it is ok
-    
-    CaloAffectedRegionInfoVec* affRegVec;
-    
-    if (detStore()->contains<CaloAffectedRegionInfoVec>("LArAffectedRegion")) {
-     ATH_CHECK( detStore()->retrieve(affRegVec, "LArAffectedRegion") );
-
-     if (msgLvl(MSG::DEBUG)) {
-       ATH_MSG_DEBUG  ( " Dump of affected regions read : " );
-      for (unsigned int i=0;i<affRegVec->size();i++) {
-        ((*affRegVec)[i]).PrintInfo();
-      }
-     }
-    }
-   
-  }else{
-     ATH_CHECK(updateMethod());
-  }
-
-  return StatusCode::SUCCESS;
-}
-
-//====================================================================================
-StatusCode LArAffectedRegionAlg::finalize() {
-
-  if (msgLvl(MSG::DEBUG)) {
-    ATH_MSG_DEBUG ( "===============================" );
-    ATH_MSG_DEBUG ( "Main summary of global problems (all runs) : " << m_ArrayLArAffectedRegionInfo_global.size() << " Affected regions" );
-    for (int i=0;i<(int)m_ArrayLArAffectedRegionInfo_global.size();i++) {
-      m_ArrayLArAffectedRegionInfo_global[i].PrintInfo();
-    }
-  }
-    
-  return StatusCode::SUCCESS;
-}
-
-//====================================================================================
-float LArAffectedRegionAlg::HV_nominal(const char *identification,const float myparameter)
-{
-  if (strcmp(identification,"EMBPS")==0) 
-    return 1200.;
-  else if (strcmp(identification,"EMECPS")==0)
-    return 1600.;
-  else if (strcmp(identification,"EMB")==0)
-    return 2000.;
-  else if (strcmp(identification,"EMEC")==0) {
-    if ( fabs(myparameter)<1.5 )
-      return 2500.;
-    else if (fabs(myparameter)<1.6)
-      return 2300.;
-    else if (fabs(myparameter)<1.8 )
-      return 2100.;
-    else if ( fabs(myparameter) < 2.0 )
-      return 1700.;
-    else if ( fabs(myparameter) < 2.1 )
-      return 1500.;
-    else if ( fabs(myparameter) < 2.3 )
-      return 1250.;
-    else if ( fabs(myparameter) < 2.5 )
-      return 1000.;
-    else if ( fabs(myparameter) < 2.8 )
-      return 2300.;
-    else return 1800.;
-  }
-  else if (strcmp(identification,"HEC")==0) {
-    return 1800.;
-  }
-  else if (strcmp(identification,"FCAL")==0) {
-    if (myparameter<0.5)
-      return 250.;
-    else if (myparameter<1.5)
-      return 375.;
-    else if (myparameter<2.5)
-      return 500.;
-  }
-
-  //std::cout << "identification=" << identification << std::endl;
-  //std::cout << "myparameter=" << myparameter << std::endl;
-  //std::cout << "WARNING, HV_nominal used improperly !!!" << std::endl;
-  return -1;
-}
-//====================================================================================
-// Return the occurence of given AffectedRegion in the list of Affected Region (useful to extend the AffectedRegion in the case of a new run, and useful to update the MetaData)
-
-int LArAffectedRegionAlg::getOccurenceProblem(const std::vector<CaloAffectedRegionInfo>& ArrayLArAffectedRegionInfo_global,float eta_min,float eta_max,float phi_min,float phi_max,int layer_min,int layer_max,int problem,float rate) {
-  
-  float epsilon=1e-3;
-  int occurences=0;
-
-  for (unsigned int i = 0; i < ArrayLArAffectedRegionInfo_global.size(); ++i) {
-    
-    if (fabs(ArrayLArAffectedRegionInfo_global[i].get_eta_min()-eta_min)<epsilon &&
-	fabs(ArrayLArAffectedRegionInfo_global[i].get_eta_max()-eta_max)<epsilon &&
-	fabs(ArrayLArAffectedRegionInfo_global[i].get_phi_min()-phi_min)<epsilon &&
-	fabs(ArrayLArAffectedRegionInfo_global[i].get_phi_max()-phi_max)<epsilon &&
-	ArrayLArAffectedRegionInfo_global[i].get_layer_min()==layer_min &&
-	ArrayLArAffectedRegionInfo_global[i].get_layer_max()==layer_max &&
-	ArrayLArAffectedRegionInfo_global[i].get_problem()==problem &&
-	fabs(ArrayLArAffectedRegionInfo_global[i].get_rate()-rate)<epsilon) {
-      occurences++;
-      //      std::cout << "found the asked AffectedRegion in the global list of AffectedRegion" << std::endl;
-    }
-  }
-    
-  return occurences;
-}
-//=========================================================================================
-std::vector<int> LArAffectedRegionAlg::returnProblem(const float eta, const float phi, const float delta_eta, const float delta_phi)   // from implementation of list of Affected Region : transparent wrt discontinuity
-{
-  std::vector<int> list_problem;
-
-  if (delta_eta<0 || delta_phi<0) {
-    std::cout << "error in LArAffectedRegionAlg::returnProblem : please give positive value for delta_eta, delta_phi" << std::endl;
-    return list_problem;
-  }
-    
-  bool flag_eta; //flag if eta and delta_eta relevant for the current Affected Region
-  bool flag_phi; //flag if phi and delta_phi relevant for the current Affected Region
-
-  for (int i=0;i<(int)m_ArrayLArAffectedRegionInfo_current_run.size();i++) {
-    flag_eta=0; // not yet found
-    flag_phi=0; // not yet found
-    
-    if (eta<m_ArrayLArAffectedRegionInfo_current_run[i].get_eta_min() && eta+delta_eta>=m_ArrayLArAffectedRegionInfo_current_run[i].get_eta_min())
-      flag_eta=1;
-    else if (eta>=m_ArrayLArAffectedRegionInfo_current_run[i].get_eta_min() && eta<=m_ArrayLArAffectedRegionInfo_current_run[i].get_eta_max())
-      flag_eta=1;
-    else if (eta>=m_ArrayLArAffectedRegionInfo_current_run[i].get_eta_max() && eta-delta_eta<=m_ArrayLArAffectedRegionInfo_current_run[i].get_eta_max())
-      flag_eta=1;
-    
-    if (phi<m_ArrayLArAffectedRegionInfo_current_run[i].get_phi_min() && phi+delta_phi>=m_ArrayLArAffectedRegionInfo_current_run[i].get_phi_min())
-      flag_phi=1;
-    else if (phi>=m_ArrayLArAffectedRegionInfo_current_run[i].get_phi_min() && phi<=m_ArrayLArAffectedRegionInfo_current_run[i].get_phi_max())
-      flag_phi=1;
-    else if (phi>=m_ArrayLArAffectedRegionInfo_current_run[i].get_phi_max() && phi-delta_phi<=m_ArrayLArAffectedRegionInfo_current_run[i].get_phi_max())
-      flag_phi=1;
-    
-    if (flag_eta && flag_phi) {//found
-      m_ArrayLArAffectedRegionInfo_current_run[i].PrintInfo();
-      list_problem.push_back(m_ArrayLArAffectedRegionInfo_current_run[i].get_problem());
-    }
-  }
-  
-  return list_problem;
-}
-//=========================================================================================
-void LArAffectedRegionAlg::debuggingSearchDoublons(const std::vector<CaloAffectedRegionInfo>& ArrayLArAffectedRegionInfo) { //debugging method to check if there are doublons in the current run : for example because of lack of method for some detectors parts
-  
-  for (unsigned int i=0;i<ArrayLArAffectedRegionInfo.size();++i) {
-    int occurences=0;
-    
-    for (unsigned int j=i+1;j<ArrayLArAffectedRegionInfo.size();++j) {
-      
-      if (ArrayLArAffectedRegionInfo[i].get_eta_min()  ==ArrayLArAffectedRegionInfo[j].get_eta_min() &&
-	  ArrayLArAffectedRegionInfo[i].get_eta_max()  ==ArrayLArAffectedRegionInfo[j].get_eta_max() &&
-	  ArrayLArAffectedRegionInfo[i].get_phi_min()  ==ArrayLArAffectedRegionInfo[j].get_phi_min() &&
-	  ArrayLArAffectedRegionInfo[i].get_phi_max()  ==ArrayLArAffectedRegionInfo[j].get_phi_max() &&
-	  ArrayLArAffectedRegionInfo[i].get_layer_min()==ArrayLArAffectedRegionInfo[j].get_layer_min() &&
-	  ArrayLArAffectedRegionInfo[i].get_layer_max()==ArrayLArAffectedRegionInfo[j].get_layer_max() &&
-	  ArrayLArAffectedRegionInfo[i].get_problem()  ==ArrayLArAffectedRegionInfo[j].get_problem() &&
-	  ArrayLArAffectedRegionInfo[i].get_rate()     ==ArrayLArAffectedRegionInfo[j].get_rate()) {
-	//std::cout << "found a doublon for " << "index=" << i << ", with index=" << j << std::endl;
-	occurences++;
-      }
-    }
-    /*
-    if (occurences) {
-      std::cout << "found " << occurences << ", the asked AffectedRegion in given list of AffectedRegion : see next line" << std::endl;
-      ArrayLArAffectedRegionInfo[i].PrintInfo();      
-     }
-     */
-  }
-}
-//=========================================================================================
-
-void LArAffectedRegionAlg::extendPhiRegion(float phi, float & phi_min, float & phi_max) {
-
-  static float epsilon=1e-4;
-  
-  phi = CaloPhiRange::fix(phi);
-
-  if (phi_min>10. || phi_max<-10.) {
-     phi_min = CaloPhiRange::fix(phi-epsilon);
-     phi_max = CaloPhiRange::fix(phi+epsilon);
-     return;
-  }
-
-  bool isInRegion=false;
-  if (phi_min<phi_max) {
-     if (phi>phi_min && phi<phi_max) isInRegion=true;
-  }
-  else {
-     if (phi>phi_min || phi<phi_max) isInRegion=true;
-  }
-  if (isInRegion) return;
-
-  float dphi1 = CaloPhiRange::diff(phi,phi_min); 
-  float dphi2 = CaloPhiRange::diff(phi,phi_max); 
-  if (fabs(dphi1)<fabs(dphi2) )
-     phi_min=phi;
-  else
-     phi_max=phi;
-  
-  return;
-
-}
diff --git a/LArCalorimeter/LArAffectedRegion/src/components/LArAffectedRegionTool_entries.cxx b/LArCalorimeter/LArAffectedRegion/src/components/LArAffectedRegionTool_entries.cxx
deleted file mode 100644
index 17e4ed70bd7b38fa17c55d02e10820a0b3162161..0000000000000000000000000000000000000000
--- a/LArCalorimeter/LArAffectedRegion/src/components/LArAffectedRegionTool_entries.cxx
+++ /dev/null
@@ -1,5 +0,0 @@
-#include "LArAffectedRegion/LArAffectedRegionAlg.h"
-
-
-DECLARE_COMPONENT( LArAffectedRegionAlg )
-
diff --git a/LArCalorimeter/LArMonTools/share/LArAllMonitoring_jobOptions.py b/LArCalorimeter/LArMonTools/share/LArAllMonitoring_jobOptions.py
index 5e0d5a7a9fb1080a36f8090a93e6601d7fbd1ce6..26b4057b64c8f8ad279a7f4536b253666dda2c5f 100755
--- a/LArCalorimeter/LArMonTools/share/LArAllMonitoring_jobOptions.py
+++ b/LArCalorimeter/LArMonTools/share/LArAllMonitoring_jobOptions.py
@@ -57,7 +57,7 @@ if 'LArDigitKey'  in dir() :
 if jobproperties.Beam.beamType() == 'cosmics':
     if larESDMon and not athenaCommonFlags.isOnline():
         if LArMonFlags.doLArAffectedRegions():
-            include ("LArAffectedRegion/LArAffectedRegion_read.py")
+            include ("LArRecUtils/LArAffectedRegion.py")
             include ("LArMonTools/LArAffectedRegions_jobOptions.py")
     if larRawMon:
             if jobproperties.Global.DataSource.get_Value() == 'data':
@@ -84,7 +84,7 @@ if jobproperties.Beam.beamType() == 'cosmics':
 elif jobproperties.Beam.beamType() == 'singlebeam':
     if larESDMon and not athenaCommonFlags.isOnline():
         if LArMonFlags.doLArAffectedRegions():
-            include ("LArAffectedRegion/LArAffectedRegion_read.py")
+            include ("LArRecUtils/LArAffectedRegion.py")
             include ("LArMonTools/LArAffectedRegions_jobOptions.py")
     if larRawMon:
             if jobproperties.Global.DataSource.get_Value() == 'data':
@@ -108,7 +108,7 @@ elif jobproperties.Beam.beamType() == 'singlebeam':
 else:  # should be jobproperties.Beam.beamType() =='collisions'
     if larESDMon and not athenaCommonFlags.isOnline():
         if LArMonFlags.doLArAffectedRegions():
-            include ("LArAffectedRegion/LArAffectedRegion_read.py")
+            include ("LArRecUtils/LArAffectedRegion.py")
             include ("LArMonTools/LArAffectedRegions_jobOptions.py")
     if larRawMon:
             if jobproperties.Global.DataSource.get_Value() == 'data':
diff --git a/LArCalorimeter/LArMonTools/src/LArAffectedRegions.cxx b/LArCalorimeter/LArMonTools/src/LArAffectedRegions.cxx
index 2f4df703d971ef9a6e54ba7e693d75e9aa3a7fc0..09880c6308e9a41367f724cd76e0f0f5142b7664 100644
--- a/LArCalorimeter/LArMonTools/src/LArAffectedRegions.cxx
+++ b/LArCalorimeter/LArMonTools/src/LArAffectedRegions.cxx
@@ -88,10 +88,12 @@ LArAffectedRegions::~LArAffectedRegions()
 StatusCode 
 LArAffectedRegions::initialize()
 {
-  ATH_MSG_INFO( "Initialize LArAffectedRegions"  );
+  ATH_MSG_DEBUG( "Initialize LArAffectedRegions"  );
 
-  // End Initialize
   ManagedMonitorToolBase::initialize().ignore();
+
+  ATH_CHECK(m_affKey.initialize());
+
   ATH_MSG_DEBUG( "Successful Initialize LArAffectedRegions "  );
 
   return StatusCode::SUCCESS;
@@ -219,9 +221,10 @@ LArAffectedRegions::fillHistograms()
   
   // Retrieve CaloAffected Regions
   if(!m_isonline){
-    const CaloAffectedRegionInfoVec* affRegVec=0;
-    StatusCode sc = detStore()->retrieve(affRegVec, "LArAffectedRegion");
-    if (sc.isFailure() || !affRegVec) {
+    //Get affected info for this event
+    SG::ReadCondHandle<CaloAffectedRegionInfoVec> affHdl{m_affKey};
+    const CaloAffectedRegionInfoVec* affRegVec=*affHdl;
+    if (!affRegVec) {
       ATH_MSG_WARNING( " Cannot find LArAffectedRegion in DetectorStore "  );
       return StatusCode::SUCCESS;
     }
diff --git a/LArCalorimeter/LArMonTools/src/LArAffectedRegions.h b/LArCalorimeter/LArMonTools/src/LArAffectedRegions.h
index b309cf870147e619efdac2596dd67598408c3c4e..8d98724a5d84155c6a60662cb453e52a57cbdb40 100644
--- a/LArCalorimeter/LArMonTools/src/LArAffectedRegions.h
+++ b/LArCalorimeter/LArMonTools/src/LArAffectedRegions.h
@@ -14,6 +14,9 @@
 #include "AthenaMonitoring/ManagedMonitorToolBase.h"
 #include "StoreGate/StoreGateSvc.h"
 
+#include "StoreGate/ReadCondHandleKey.h"
+#include "CaloConditions/CaloAffectedRegionInfoVec.h"
+
 #include <string>
 #include <map>
 
@@ -57,6 +60,8 @@ class LArAffectedRegions: public ManagedMonitorToolBase
 
  private:
 
+  SG::ReadCondHandleKey<CaloAffectedRegionInfoVec> m_affKey{this,
+       "LArAffectedRegionKey", "LArAffectedRegionInfo", "SG key for affected regions cond object"};
   // Properties
   bool m_isonline;
   float m_delta_phi;
diff --git a/LArCalorimeter/LArRecUtils/CMakeLists.txt b/LArCalorimeter/LArRecUtils/CMakeLists.txt
index 84f7383c982369792f5024e790965f09312a2fe4..2078403cab1a51922d25fc79664d4e703489c0e8 100644
--- a/LArCalorimeter/LArRecUtils/CMakeLists.txt
+++ b/LArCalorimeter/LArRecUtils/CMakeLists.txt
@@ -12,6 +12,7 @@ atlas_depends_on_subdirs( PUBLIC
                           Calorimeter/CaloIdentifier
                           Calorimeter/CaloInterface
                           Calorimeter/CaloUtils
+                          Calorimeter/CaloConditions
                           Control/AthenaBaseComps
                           Control/AthenaKernel
                           Control/AthAllocators
@@ -49,18 +50,18 @@ atlas_add_library( LArRecUtilsLib
                    PRIVATE_INCLUDE_DIRS ${Boost_INCLUDE_DIRS} ${CLHEP_INCLUDE_DIRS} ${EIGEN_INCLUDE_DIRS}
                    PRIVATE_DEFINITIONS ${CLHEP_DEFINITIONS}
                    LINK_LIBRARIES ${CORAL_LIBRARIES} ${EIGEN_LIBRARIES} CaloEvent CaloIdentifier AthenaBaseComps AthenaKernel AthAllocators AthenaPoolUtilities Identifier GaudiKernel LArIdentifier LArRawEvent LArRecEvent CaloDetDescrLib CaloUtilsLib StoreGateLib SGtests LArCablingLib LArRawUtilsLib LArRecConditions LArRawConditions
-                   PRIVATE_LINK_LIBRARIES ${Boost_LIBRARIES} ${CLHEP_LIBRARIES} ${EIGEN_LIBRARIES} TestTools CaloGeoHelpers SGTools xAODEventInfo LArCOOLConditions PathResolver )
+                   PRIVATE_LINK_LIBRARIES ${Boost_LIBRARIES} ${CLHEP_LIBRARIES} ${EIGEN_LIBRARIES} TestTools CaloGeoHelpers SGTools xAODEventInfo LArCOOLConditions PathResolver CaloConditions )
 
 atlas_add_component( LArRecUtils
                      src/components/*.cxx
                      INCLUDE_DIRS ${Boost_INCLUDE_DIRS} ${CORAL_INCLUDE_DIRS} ${CLHEP_INCLUDE_DIRS} ${EIGEN_INCLUDE_DIRS}
-                     LINK_LIBRARIES ${Boost_LIBRARIES} ${CORAL_LIBRARIES} ${CLHEP_LIBRARIES} ${EIGEN_LIBRARIES} CaloDetDescrLib CaloEvent CaloIdentifier CaloUtilsLib AthenaBaseComps AthenaKernel AthAllocators StoreGateLib SGtests AthenaPoolUtilities Identifier GaudiKernel LArCablingLib LArIdentifier LArRawConditions LArRawEvent LArRecEvent TestTools CaloGeoHelpers SGTools xAODEventInfo LArCOOLConditions LArRawUtilsLib PathResolver LArRecUtilsLib LArRecConditions LArRawConditions)
+                     LINK_LIBRARIES ${Boost_LIBRARIES} ${CORAL_LIBRARIES} ${CLHEP_LIBRARIES} ${EIGEN_LIBRARIES} CaloDetDescrLib CaloEvent CaloIdentifier CaloUtilsLib AthenaBaseComps AthenaKernel AthAllocators StoreGateLib SGtests AthenaPoolUtilities Identifier GaudiKernel LArCablingLib LArIdentifier LArRawConditions LArRawEvent LArRecEvent TestTools CaloGeoHelpers SGTools xAODEventInfo LArCOOLConditions LArRawUtilsLib PathResolver LArRecUtilsLib LArRecConditions LArRawConditions CaloConditions)
 
 atlas_add_test( dummy_test
                 SOURCES
                 test/dummy_test.cxx
                 INCLUDE_DIRS ${Boost_INCLUDE_DIRS} ${CORAL_INCLUDE_DIRS} ${CLHEP_INCLUDE_DIRS} ${EIGEN_INCLUDE_DIRS}
-                LINK_LIBRARIES ${Boost_LIBRARIES} ${CORAL_LIBRARIES} ${CLHEP_LIBRARIES} ${EIGEN_LIBRARIES} CaloDetDescrLib CaloEvent CaloIdentifier CaloUtilsLib AthenaBaseComps AthenaKernel AthAllocators StoreGateLib SGtests AthenaPoolUtilities Identifier GaudiKernel LArCablingLib LArIdentifier LArRawConditions LArRawEvent LArRecEvent TestTools CaloGeoHelpers SGTools xAODEventInfo LArCOOLConditions LArRawUtilsLib PathResolver LArRecUtilsLib )
+                LINK_LIBRARIES ${Boost_LIBRARIES} ${CORAL_LIBRARIES} ${CLHEP_LIBRARIES} ${EIGEN_LIBRARIES} CaloDetDescrLib CaloEvent CaloIdentifier CaloUtilsLib AthenaBaseComps AthenaKernel AthAllocators StoreGateLib SGtests AthenaPoolUtilities Identifier GaudiKernel LArCablingLib LArIdentifier LArRawConditions LArRawEvent LArRecEvent TestTools CaloGeoHelpers SGTools xAODEventInfo LArCOOLConditions LArRawUtilsLib CaloConditions PathResolver LArRecUtilsLib )
 
 # Install files from the package:
 atlas_install_python_modules( python/*.py )
diff --git a/LArCalorimeter/LArRecUtils/share/LArAffectedRegion.py b/LArCalorimeter/LArRecUtils/share/LArAffectedRegion.py
new file mode 100644
index 0000000000000000000000000000000000000000..7b91be790dc3825950db4e34b67a45ba47065512
--- /dev/null
+++ b/LArCalorimeter/LArRecUtils/share/LArAffectedRegion.py
@@ -0,0 +1,13 @@
+# Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
+
+from IOVDbSvc.CondDB import conddb
+from AthenaCommon.AlgSequence import AthSequencer
+condseq = AthSequencer("AthCondSeq")
+
+if not hasattr (condSeq,"LArHVCondAlg"):
+   if conddb.isMC:
+      from LArRecUtils.LArRecUtilsConf import LArHVCondAlg
+      hvcond = LArHVCondAlg(doHV=False,doAffectedHV=False)
+      condSeq+=hvcond
+   else:
+      include("LArConditionsCommon/LArHVDB.py")
diff --git a/LArCalorimeter/LArRecUtils/src/LArHVCondAlg.cxx b/LArCalorimeter/LArRecUtils/src/LArHVCondAlg.cxx
index c777223afc6a0d352a80d0f80f9464a472a6eaa3..646e08e20c7c4903f1d7cdea3e0df3a6f5ec290d 100755
--- a/LArCalorimeter/LArRecUtils/src/LArHVCondAlg.cxx
+++ b/LArCalorimeter/LArRecUtils/src/LArHVCondAlg.cxx
@@ -8,25 +8,34 @@
 #include "StoreGate/ReadCondHandle.h"
 #include "LArElecCalib/ILArHVPathologyDbTool.h"
 #include "CaloDetDescr/CaloDetectorElements.h"
+#include "CaloGeoHelpers/CaloPhiRange.h"
 #include "CaloIdentifier/LArEM_ID.h"
 #include "CaloIdentifier/LArHEC_ID.h"
 #include "CaloIdentifier/LArFCAL_ID.h"
 #include "CaloIdentifier/CaloIdManager.h"
 #include "CaloDetDescr/CaloDetDescrManager.h"
 #include "LArReadoutGeometry/EMBCell.h"
+#include "LArHV/LArHVManager.h"
+#include "LArHV/EMBHVManager.h"
+#include "LArHV/EMECHVModule.h"
+#include "LArHV/EMECHVModuleConstLink.h"
 #include "LArHV/EMBHVElectrodeConstLink.h"
 #include "LArHV/EMBHVElectrode.h"
+#include "LArHV/EMBPresamplerHVManager.h"
 #include "LArHV/EMBPresamplerHVModuleConstLink.h"
 #include "LArHV/EMBPresamplerHVModule.h"
 #include "LArReadoutGeometry/EMECCell.h"
+#include "LArHV/EMECHVManager.h"
 #include "LArHV/EMECHVElectrodeConstLink.h"
 #include "LArHV/EMECHVElectrode.h"
 #include "LArHV/EMECPresamplerHVModuleConstLink.h"
 #include "LArHV/EMECPresamplerHVModule.h"
 #include "LArReadoutGeometry/HECCell.h"
+#include "LArHV/HECHVManager.h"
 #include "LArHV/HECHVSubgapConstLink.h"
 #include "LArHV/HECHVSubgap.h"
 #include "LArReadoutGeometry/FCALTile.h"
+#include "LArHV/FCALHVManager.h"
 #include "LArHV/FCALHVLineConstLink.h"
 #include "LArHV/FCALHVLine.h"
 
@@ -34,6 +43,7 @@
 
 #include "LArIdentifier/LArElectrodeID.h"
 #include "LArIdentifier/LArHVLineID.h"
+#include "LArIdentifier/LArOnlineID.h"
 
 #include "AthenaPoolUtilities/CondAttrListCollection.h"
 
@@ -45,6 +55,9 @@
 #define VDIFF_MAX 0.01 // maximum voltage difference allowed to be treated as equal
 #define WDIFF_MAX 0.0001 // maximum weight difference allowed to be treated as equal
 
+#define HV_NON_NOMINAL_TOLERANCE 10 // tolerance : 1V for HV
+#define DEAD_HV_THRESHOLD 10 // HV <10 V="dead"
+
 
 // constructor 
 LArHVCondAlg::LArHVCondAlg( const std::string& name, ISvcLocator* pSvcLocator )
@@ -56,6 +69,9 @@ LArHVCondAlg::LArHVCondAlg( const std::string& name, ISvcLocator* pSvcLocator )
     m_hvLineID(nullptr),
     m_condSvc("CondSvc",name)
  {
+  declareProperty("doHV",m_doHV=true,"create HV data");
+  declareProperty("doAffected",m_doAffected=true,"create affected region info");
+  declareProperty("doAffectedHV",m_doAffectedHV=true,"include HV non nominal regions info");
  
 }
 
@@ -77,19 +93,35 @@ StatusCode LArHVCondAlg::initialize(){
 
   ATH_CHECK(detStore()->retrieve(m_hvLineID));
 
+  ATH_CHECK( detStore()->retrieve(m_onlineID));
+
   // Read Handles
   ATH_CHECK(m_pathologiesKey.initialize());
   ATH_CHECK(m_DCSFolderKeys.initialize());
+  ATH_CHECK( m_cablingKey.initialize());
+  ATH_CHECK( m_BFKey.initialize() );
+
   // Write Handle
-  ATH_CHECK(m_hvDataKey.initialize());
   
   // Register write handle
   ATH_CHECK( m_condSvc.retrieve() );
-  if (m_condSvc->regHandle(this, m_hvDataKey).isFailure()) {
-    ATH_MSG_ERROR("unable to register WriteCondHandle " << m_hvDataKey.fullKey() << " with CondSvc");
-    return StatusCode::FAILURE;
+  ATH_CHECK(m_hvDataKey.initialize());
+  ATH_CHECK(m_outKey.initialize());
+
+  if(m_doHV || m_doAffectedHV) {
+    if (m_condSvc->regHandle(this, m_hvDataKey).isFailure()) {
+      ATH_MSG_ERROR("unable to register WriteCondHandle " << m_hvDataKey.fullKey() << " with CondSvc");
+      return StatusCode::FAILURE;
+    }
+  }
+  if(m_doAffected) {
+     if (m_condSvc->regHandle(this, m_outKey).isFailure()) {
+       ATH_MSG_ERROR("unable to register WriteCondHandle " << m_outKey.fullKey() << " with CondSvc");
+       return StatusCode::FAILURE;
+     }
   }
 
+  ATH_MSG_DEBUG("Configured with doHV " << m_doHV << " doAffected " << m_doAffected << " doAffectedHV " << m_doAffectedHV);
 
   return StatusCode::SUCCESS;
 }
@@ -98,143 +130,217 @@ StatusCode LArHVCondAlg::initialize(){
 StatusCode LArHVCondAlg::execute_r(const EventContext& ctx) const {
 
   ATH_MSG_DEBUG("executing");
+  bool doHVData=false;
+  bool doAffected=false;
 
   SG::WriteCondHandle<LArHVData> writeHandle{m_hvDataKey};
-
-  if (writeHandle.isValid()) {
-    ATH_MSG_DEBUG("Found valid write handle");
-    return StatusCode::SUCCESS;
+  if(m_doHV || m_doAffectedHV) {
+    if (writeHandle.isValid()) {
+      ATH_MSG_DEBUG("Found valid write LArHVData handle");
+    } else {
+      doHVData=true;
+    }
   } 
 
+  SG::WriteCondHandle<CaloAffectedRegionInfoVec> writeAffectedHandle{m_outKey};
+  if(m_doAffected){
+    if (writeAffectedHandle.isValid()) {
+      ATH_MSG_DEBUG("Found valid write LArAffectedRegions handle");
+    } else {
+      doAffected=true;
+    }
+  }
+
+  ATH_MSG_DEBUG("Executing with doHV " << doHVData << " doAffected " << doAffected );
+
   // Define validity of the output cond object 
   const EventIDBase start{EventIDBase::UNDEFNUM, EventIDBase::UNDEFEVT, 0, 0, EventIDBase::UNDEFNUM, EventIDBase::UNDEFNUM};
   const EventIDBase stop{EventIDBase::UNDEFNUM, EventIDBase::UNDEFEVT, EventIDBase::UNDEFNUM-1, EventIDBase::UNDEFNUM-1, EventIDBase::UNDEFNUM, EventIDBase::UNDEFNUM};
   EventIDRange rangeW{start, stop};
-  std::vector<const CondAttrListCollection*> attrvec;
-  // get handles to DCS Database folders
-  for (auto fldkey: m_DCSFolderKeys ) {
-    SG::ReadCondHandle<CondAttrListCollection> cHdl(fldkey, ctx);
-    const CondAttrListCollection* cattr = *cHdl;
-    if(cattr) {
-      ATH_MSG_DEBUG("Folder: "<<cHdl.key()<<" has size: "<<std::distance(cattr->begin(),cattr->end()));
-      attrvec.push_back(cattr);
-      EventIDRange rangeW_tmp;
-      if(!cHdl.range(rangeW_tmp)) {
-        ATH_MSG_ERROR("Failed to retrieve validity range for " << cHdl.key());
-        return StatusCode::FAILURE;
-      }
-      ATH_MSG_DEBUG("and validity range: "<<rangeW_tmp);
-      rangeW.intersect(rangeW,rangeW_tmp);
-    } else {
-       ATH_MSG_WARNING("Why do not have DCS folder " << fldkey.fullKey());
-    }
 
-  }
+  std::vector<const CondAttrListCollection*> attrvec;
 
-  // Fill pathology info
-  pathVec  hasPathologyEM;
-  pathVec  hasPathologyHEC;
-  pathVec  hasPathologyFCAL;
-  hasPathologyEM.resize(m_larem_id->channel_hash_max());
-  hasPathologyHEC.resize(m_larhec_id->channel_hash_max());
-  hasPathologyFCAL.resize(m_larfcal_id->channel_hash_max());
-
-  bool doPathology=true; 
-  SG::ReadCondHandle<LArHVPathology> pHdl(m_pathologiesKey,ctx);
-  const LArHVPathology* pathologyContainer = *pHdl;
-  if(!pathologyContainer) {
-     ATH_MSG_WARNING("Why do not have HV pathology object " << m_pathologiesKey.fullKey() << " ? Work without pathologies !!!");
-     doPathology=false;
+  if(doHVData || (doAffected && m_doAffectedHV) ) {
+    // get handles to DCS Database folders
+    for (auto fldkey: m_DCSFolderKeys ) {
+      SG::ReadCondHandle<CondAttrListCollection> cHdl(fldkey, ctx);
+      const CondAttrListCollection* cattr = *cHdl;
+      if(cattr) {
+        ATH_MSG_DEBUG("Folder: "<<cHdl.key()<<" has size: "<<std::distance(cattr->begin(),cattr->end()));
+        attrvec.push_back(cattr);
+        EventIDRange rangeW_tmp;
+        if(!cHdl.range(rangeW_tmp)) {
+          ATH_MSG_ERROR("Failed to retrieve validity range for " << cHdl.key());
+          return StatusCode::FAILURE;
+        }
+        ATH_MSG_DEBUG("and validity range: "<<rangeW_tmp);
+        rangeW.intersect(rangeW,rangeW_tmp);
+      } else {
+         ATH_MSG_WARNING("Why do not have DCS folder " << fldkey.fullKey());
+      }
+    } // over DCS folders
   }
-
-
+ 
   const LArHVManager *manager = NULL; 
   if (detStore()->retrieve(manager)==StatusCode::SUCCESS) {
-      manager->reset();
+        manager->reset();
   }
-
-  if (doPathology) {
-     const std::vector<LArHVPathologiesDb::LArHVElectPathologyDb> &pathCont = pathologyContainer->getPathology();
-     ATH_MSG_INFO( " Number of HV pathologies found " << pathCont.size());
-     for(unsigned i=0; i<pathologyContainer->getPathology().size(); ++i) {
-    
-         LArHVPathologiesDb::LArHVElectPathologyDb electPath = pathologyContainer->getPathology()[i];
-         Identifier id(electPath.cellID);
-         if (m_larem_id->is_lar_em(id)) {
-             IdentifierHash idHash = m_larem_id->channel_hash(id);
-             unsigned int index = (unsigned int)(idHash);
-             if (index<hasPathologyEM.size()) {
-                if(hasPathologyEM[index].size()) {
-                  if(hasPathologyEM[index].size()<static_cast<size_t>(abs(electPath.electInd+1)))
-                    hasPathologyEM[index].resize(electPath.electInd+1);
-                   hasPathologyEM[index][electPath.electInd]=electPath.pathologyType;
-                } else {
-                   std::vector<unsigned short> svec;
-                   svec.resize(electPath.electInd+1);
-                   svec[electPath.electInd]=electPath.pathologyType;
-                   hasPathologyEM[index]=svec;
-                }
-             }
-         }
-         if (m_larhec_id->is_lar_hec(id)) {
-             IdentifierHash idHash = m_larhec_id->channel_hash(id);
-             unsigned int index = (unsigned int)(idHash);
-             if (index<hasPathologyHEC.size()) {
-                if(hasPathologyHEC[index].size()) {
-                  if(hasPathologyHEC[index].size()<static_cast<size_t>(abs(electPath.electInd+1)))
-                    hasPathologyHEC[index].resize(electPath.electInd+1);
-                   hasPathologyHEC[index][electPath.electInd]=electPath.pathologyType;
-                } else {
-                   std::vector<unsigned short> svec;
-                   svec.resize(electPath.electInd+1);
-                   svec[electPath.electInd]=electPath.pathologyType;
-                   hasPathologyHEC[index]=svec;
-                }
-             }
-         }
-         if (m_larfcal_id->is_lar_fcal(id)) {
-             IdentifierHash idHash = m_larfcal_id->channel_hash(id);
-             unsigned int index = (unsigned int)(idHash);
-             if (index<hasPathologyFCAL.size()) {
-                if(hasPathologyFCAL[index].size()) {
-                  if(hasPathologyFCAL[index].size()<static_cast<size_t>(abs(electPath.electInd+1)))
-                    hasPathologyFCAL[index].resize(electPath.electInd+1);
-                  hasPathologyFCAL[index][electPath.electInd]=electPath.pathologyType;
-                } else {
-                   std::vector<unsigned short> svec;
-                   svec.resize(electPath.electInd+1);
-                   svec[electPath.electInd]=electPath.pathologyType;
-                   hasPathologyFCAL[index]=svec;
-                }
-
-             }
-         }
-     }
-  } //doPathology
-  // try to get old cond. object
-  const LArHVData* hvdataOld = nullptr;
- 
-  std::unique_ptr<LArHVData> hvdata = std::make_unique<LArHVData>();
-  LArHVData* p_hvdata = hvdata.get();
-
-  // and now to call filling
   std::vector<float> voltage;
   std::vector<float> current;
   std::vector<unsigned int> hvlineidx;
-  ATH_CHECK(fillUpdatedHVChannelsVec(voltage, current, hvlineidx, attrvec));
-  ATH_CHECK(fillPayload(p_hvdata, hvdataOld, voltage, current, hvlineidx, pathologyContainer, hasPathologyEM, hasPathologyHEC, hasPathologyFCAL));
+ 
+  if(doHVData) {
+    // Fill pathology info
+    pathVec  hasPathologyEM;
+    pathVec  hasPathologyHEC;
+    pathVec  hasPathologyFCAL;
+    hasPathologyEM.resize(m_larem_id->channel_hash_max());
+    hasPathologyHEC.resize(m_larhec_id->channel_hash_max());
+    hasPathologyFCAL.resize(m_larfcal_id->channel_hash_max());
+ 
+    bool doPathology=true; 
+    SG::ReadCondHandle<LArHVPathology> pHdl(m_pathologiesKey,ctx);
+    const LArHVPathology* pathologyContainer = *pHdl;
+    if(!pathologyContainer) {
+       ATH_MSG_WARNING("Why do not have HV pathology object " << m_pathologiesKey.fullKey() << " ? Work without pathologies !!!");
+       doPathology=false;
+    }
+ 
+    if(doPathology) {
+       const std::vector<LArHVPathologiesDb::LArHVElectPathologyDb> &pathCont = pathologyContainer->getPathology();
+       ATH_MSG_INFO( " Number of HV pathologies found " << pathCont.size());
+       for(unsigned i=0; i<pathologyContainer->getPathology().size(); ++i) {
+           LArHVPathologiesDb::LArHVElectPathologyDb electPath = pathologyContainer->getPathology()[i];
+           Identifier id(electPath.cellID);
+           if (m_larem_id->is_lar_em(id)) {
+               IdentifierHash idHash = m_larem_id->channel_hash(id);
+               unsigned int index = (unsigned int)(idHash);
+               if (index<hasPathologyEM.size()) {
+                  if(hasPathologyEM[index].size()) {
+                    if(hasPathologyEM[index].size()<static_cast<size_t>(abs(electPath.electInd+1)))
+                      hasPathologyEM[index].resize(electPath.electInd+1);
+                     hasPathologyEM[index][electPath.electInd]=electPath.pathologyType;
+                  } else {
+                     std::vector<unsigned short> svec;
+                     svec.resize(electPath.electInd+1);
+                     svec[electPath.electInd]=electPath.pathologyType;
+                     hasPathologyEM[index]=svec;
+                  }
+               }
+           }
+           if (m_larhec_id->is_lar_hec(id)) {
+               IdentifierHash idHash = m_larhec_id->channel_hash(id);
+               unsigned int index = (unsigned int)(idHash);
+               if (index<hasPathologyHEC.size()) {
+                  if(hasPathologyHEC[index].size()) {
+                    if(hasPathologyHEC[index].size()<static_cast<size_t>(abs(electPath.electInd+1)))
+                      hasPathologyHEC[index].resize(electPath.electInd+1);
+                     hasPathologyHEC[index][electPath.electInd]=electPath.pathologyType;
+                  } else {
+                     std::vector<unsigned short> svec;
+                     svec.resize(electPath.electInd+1);
+                     svec[electPath.electInd]=electPath.pathologyType;
+                     hasPathologyHEC[index]=svec;
+                  }
+               }
+           }
+           if (m_larfcal_id->is_lar_fcal(id)) {
+               IdentifierHash idHash = m_larfcal_id->channel_hash(id);
+               unsigned int index = (unsigned int)(idHash);
+               if (index<hasPathologyFCAL.size()) {
+                  if(hasPathologyFCAL[index].size()) {
+                    if(hasPathologyFCAL[index].size()<static_cast<size_t>(abs(electPath.electInd+1)))
+                      hasPathologyFCAL[index].resize(electPath.electInd+1);
+                    hasPathologyFCAL[index][electPath.electInd]=electPath.pathologyType;
+                  } else {
+                     std::vector<unsigned short> svec;
+                     svec.resize(electPath.electInd+1);
+                     svec[electPath.electInd]=electPath.pathologyType;
+                     hasPathologyFCAL[index]=svec;
+                  }
+ 
+               }
+           }
+       } // Pathology containers
+    }//doPathology
+    // now call filling of HV values
+    if(doHVData || (doAffected && m_doAffectedHV)) {
+      ATH_CHECK(fillUpdatedHVChannelsVec(voltage, current, hvlineidx, attrvec));
+    }
+    // try to get old cond. object
+    const LArHVData* hvdataOld = nullptr;
+    
+    std::unique_ptr<LArHVData> hvdata = std::make_unique<LArHVData>();
+    LArHVData* p_hvdata = hvdata.get();
+  
+    ATH_CHECK(fillPayload(p_hvdata, hvdataOld, voltage, current, hvlineidx, pathologyContainer, hasPathologyEM, hasPathologyHEC, hasPathologyFCAL));
+  
+  
+    const EventIDRange crangeW(rangeW);
+    if(writeHandle.record(crangeW,hvdata.release()).isFailure()) {
+        ATH_MSG_ERROR("Could not record LArHVData object with " << writeHandle.key()
+                      << " with EventRange " << crangeW << " into Conditions Store");
+        return StatusCode::FAILURE;
+    }
+  
+    ATH_MSG_INFO("recorded new " << writeHandle.key() << " with range " << crangeW << " into Conditions Store");
+  } // doHVData
 
+  if(doAffected) {
+       SG::ReadCondHandle<LArBadFebCont> readBFHandle{m_BFKey};
+       const LArBadFebCont* bfCont{*readBFHandle};
+       if(!bfCont){
+         ATH_MSG_WARNING(" Do not have Bad FEBs info, will be not filled " << m_BFKey.key() );
+       }
 
-  const EventIDRange crangeW(rangeW);
-  if(writeHandle.record(crangeW,hvdata.release()).isFailure()) {
-    ATH_MSG_ERROR("Could not record LArHVData object with " << writeHandle.key()
-                  << " with EventRange " << crangeW << " into Conditions Store");
-    return StatusCode::FAILURE;
-  }
+       SG::ReadCondHandle<LArOnOffIdMapping> cablingHdl{m_cablingKey};
+       const LArOnOffIdMapping* cabling{*cablingHdl};
+       if(!cabling) {
+         ATH_MSG_ERROR("Do not have cabling mapping from key " << m_cablingKey.key() );
+         return StatusCode::FAILURE;
+       }
 
-  ATH_MSG_INFO("recorded new " << writeHandle.key() << " with range " << crangeW << " into Conditions Store");
+       // Define validity of the output cond object
+       EventIDRange rangeW_tmp;
+       if(!readBFHandle.range(rangeW_tmp)) {
+          ATH_MSG_ERROR("Failed to retrieve validity range for " << readBFHandle.key());
+          return StatusCode::FAILURE;
+       }
+       ATH_MSG_DEBUG("and validity range: "<<rangeW_tmp);
+       rangeW.intersect(rangeW,rangeW_tmp);
+
+       if(!cablingHdl.range(rangeW_tmp)) {
+          ATH_MSG_ERROR("Failed to retrieve validity range for " << cablingHdl.key());
+          return StatusCode::FAILURE;
+       }
+       ATH_MSG_DEBUG("and validity range: "<<rangeW_tmp);
+       rangeW.intersect(rangeW,rangeW_tmp);
+   
+       CaloAffectedRegionInfoVec *vAffected = new CaloAffectedRegionInfoVec();
+   
+       if (m_doAffectedHV) {
+         ATH_CHECK(searchNonNominalHV_EMB(vAffected, voltage, hvlineidx));
+         ATH_CHECK(searchNonNominalHV_EMEC_OUTER(vAffected, voltage, hvlineidx));
+         ATH_CHECK(searchNonNominalHV_EMEC_INNER(vAffected, voltage, hvlineidx));
+         ATH_CHECK(searchNonNominalHV_HEC(vAffected, voltage, hvlineidx));
+         ATH_CHECK(searchNonNominalHV_FCAL(vAffected, voltage, hvlineidx));
+       }
+   
+   
+       ATH_CHECK(updateMethod(vAffected, bfCont, cabling));
+   
+       std::unique_ptr<CaloAffectedRegionInfoVec> affectedVec = std::make_unique<CaloAffectedRegionInfoVec>(std::move(*vAffected));
+   
+       const EventIDRange crangeW(rangeW);
+       if(writeAffectedHandle.record(crangeW,affectedVec.release()).isFailure()) {
+                ATH_MSG_ERROR("Could not record CaloAffectedRegionInfoVec object with " << writeHandle.key()
+                              << " with EventRange " << crangeW << " into Conditions Store");
+                return StatusCode::FAILURE;
+       }
+   
+       ATH_MSG_INFO("recorded new " << writeHandle.key() << " with range " << crangeW << " into Conditions Store");
+  } //doAffected
 
-  
   return StatusCode::SUCCESS;
 
 }
@@ -669,3 +775,752 @@ StatusCode LArHVCondAlg::fillUpdatedHVChannelsVec(std::vector<float> &voltageCac
   }
   return StatusCode::SUCCESS;
 }
+
+//=========================================================================================
+StatusCode LArHVCondAlg::searchNonNominalHV_EMB(CaloAffectedRegionInfoVec *vAffected, const std::vector<float> &voltage, const std::vector<unsigned int> &hvlineidx) const {  // deals with LAr HV, EMBarrel
+
+  ATH_MSG_DEBUG(" start HV_EMB ");
+  const LArHVManager *manager = nullptr;
+
+  if (detStore()->retrieve(manager)==StatusCode::SUCCESS) {
+    
+    // accordion calorimeter
+    float HVnominal = HV_nominal("EMB",0.);
+    const EMBHVManager* hvManager_EMB=manager->getEMBHVManager();
+    
+    for (unsigned int iSide=hvManager_EMB->beginSideIndex();iSide<hvManager_EMB->endSideIndex();iSide++) { // loop over HV modules
+      for (unsigned int iPhi=hvManager_EMB->beginPhiIndex();iPhi<hvManager_EMB->endPhiIndex();iPhi++) {
+	for (unsigned int iSector=hvManager_EMB->beginSectorIndex();iSector<hvManager_EMB->endSectorIndex();iSector++) {
+	  for (unsigned int iEta=hvManager_EMB->beginEtaIndex();iEta<hvManager_EMB->endEtaIndex();iEta++) { //0 to 7
+	    EMBHVModuleConstLink hvMod = hvManager_EMB->getHVModule(iSide,iEta,iPhi,iSector);
+
+            float eta_min=hvMod->getEtaMin();
+            float eta_max=hvMod->getEtaMax();
+
+            ATH_MSG_DEBUG("iSide,iPhi,iSector,iEta " << iSide << " " << iPhi << " " << iSector << " " << iEta);
+	    float phi_min=+30.,phi_max=-30.;
+	    
+	    bool are_previous_HV_affected=false;
+            bool are_previous_HV_dead=false;
+	    for (unsigned int ielec=0;ielec<32;ielec++) { //use hvMod->getNumElectrodes when bug is corrected
+	      EMBHVElectrodeConstLink electrode = hvMod->getElectrode(ielec);
+
+	      double hv[2];
+	      for (unsigned int iGap=0;iGap<2;iGap++) { // EMB : 2, TRY TO FIND AUTOMATICALLY NB OF GAPS
+                const std::vector<unsigned int>::const_iterator itrLine=std::find(hvlineidx.begin(), hvlineidx.end(), electrode->hvLineNo(iGap));
+                if(itrLine == hvlineidx.end()) { // error, could not find HVline index
+                  ATH_MSG_ERROR("Do not have hvline: "<<electrode->hvLineNo(iGap)<<" in LArHVData !!!");
+                  return StatusCode::FAILURE;
+                }
+                //unsigned idx = itrLine - hvlineidx.begin(); 
+		hv[iGap]=voltage[itrLine - hvlineidx.begin()];
+	      } //end for iGap
+
+              ATH_MSG_DEBUG(" electrode HV " << ielec << " " << electrode->getPhi() << " "<< hv[0] << " " << hv[1] );
+
+	      //take decisions according to all the gaps HV :
+              bool isDead=false;
+              if (fabs(hv[0])<DEAD_HV_THRESHOLD && fabs(hv[1])<DEAD_HV_THRESHOLD) isDead=true;
+              bool isAffected=false;
+              if ( !isDead && ((fabs(hv[0]-HVnominal)>HV_NON_NOMINAL_TOLERANCE) || (fabs(hv[1]-HVnominal)>HV_NON_NOMINAL_TOLERANCE))) isAffected=true;
+              ATH_MSG_DEBUG(" dead/affected " << isDead << " " << isAffected);
+          
+              // end previous dead region
+              if (are_previous_HV_dead && !isDead) {
+                 are_previous_HV_dead=false;
+                 ATH_MSG_DEBUG(" -- end dead region " << eta_min << " " << eta_max << " " <<phi_min << " " << phi_max);
+                 CaloAffectedRegionInfo current_CaloAffectedRegionInfo(eta_min,eta_max,phi_min,phi_max,1,3,CaloAffectedRegionInfo::HVdead);
+                 vAffected->push_back(current_CaloAffectedRegionInfo);
+              }
+
+              // end previous affected region
+              if (are_previous_HV_affected && !isAffected) {
+                 are_previous_HV_affected=false;
+                 ATH_MSG_DEBUG(" -- end affected region " << eta_min << " " << eta_max << " " <<phi_min << " " << phi_max);
+                 CaloAffectedRegionInfo current_CaloAffectedRegionInfo(eta_min,eta_max,phi_min,phi_max,1,3,CaloAffectedRegionInfo::HVaffected);
+                 vAffected->push_back(current_CaloAffectedRegionInfo);
+              }
+
+              if (isDead) {
+                 if (!are_previous_HV_dead) {
+                  phi_min=CaloPhiRange::fix(electrode->getPhi()-1e-4);
+                  phi_max=CaloPhiRange::fix(electrode->getPhi()+1e-4);
+                  ATH_MSG_DEBUG(" -- start dead region " << eta_min << " " << eta_max << " " << phi_min << " " <<phi_max);
+                  are_previous_HV_dead = true;
+                 }
+                 else {
+                  extendPhiRegion(electrode->getPhi(),phi_min,phi_max);
+                  ATH_MSG_DEBUG(" extend dead region " << phi_min << " " << phi_max);
+                 }
+              }
+
+              if (isAffected) {
+                 if (!are_previous_HV_affected) {
+                  phi_min=CaloPhiRange::fix(electrode->getPhi()-1e-4);
+                  phi_max=CaloPhiRange::fix(electrode->getPhi()+1e-4);
+                  ATH_MSG_DEBUG(" -- start affected region " << eta_min << " " << eta_max << " " << phi_min << " " <<phi_max);
+                  are_previous_HV_affected = true;
+                 }
+                 else {
+                  extendPhiRegion(electrode->getPhi(),phi_min,phi_max);
+                  ATH_MSG_DEBUG(" extend affected region " << phi_min << " " << phi_max);
+                 }
+              }
+
+	    } // end for ielec
+	    
+	    if (are_previous_HV_affected) { //in case a non nominal exists, stores it if we finish the 32 electrodes (because else the are_previous_HV_affected will be reinitialized for the next 32 electrodes serie )
+              ATH_MSG_DEBUG("  -- finish affected region after electrode loop " << eta_min << " " << eta_max << " " << phi_min << " " <<phi_max);
+	      CaloAffectedRegionInfo current_CaloAffectedRegionInfo(eta_min,eta_max,phi_min,phi_max,1,3,CaloAffectedRegionInfo::HVaffected);
+	      vAffected->push_back(current_CaloAffectedRegionInfo);	      
+	    }
+            if (are_previous_HV_dead) {
+              ATH_MSG_DEBUG("  -- finish dead region after electrode loop " << eta_min << " " << eta_max << " " << phi_min << " " <<phi_max);
+              CaloAffectedRegionInfo current_CaloAffectedRegionInfo(eta_min,eta_max,phi_min,phi_max,1,3,CaloAffectedRegionInfo::HVdead);
+              vAffected->push_back(current_CaloAffectedRegionInfo);
+            }
+	  } // end for iEta
+	} // end for iSector
+      } // end for iPhi
+    } //end for iSide
+
+    // barrel presampler
+    const EMBPresamplerHVManager* hvManager_EMBPS=manager->getEMBPresamplerHVManager();
+    HVnominal = HV_nominal("EMBPS",0.);
+    for (unsigned int iSide=hvManager_EMBPS->beginSideIndex();iSide<hvManager_EMBPS->endSideIndex();iSide++) { // loop over HV modules
+      for (unsigned int iPhi=hvManager_EMBPS->beginPhiIndex();iPhi<hvManager_EMBPS->endPhiIndex();iPhi++) {
+          for (unsigned int iEta=hvManager_EMBPS->beginEtaIndex();iEta<hvManager_EMBPS->endEtaIndex();iEta++) { //0 to 7
+            EMBPresamplerHVModuleConstLink hvMod = hvManager_EMBPS->getHVModule(iSide,iEta,iPhi);
+            ATH_MSG_DEBUG("iSide,iPhi,iEta " << iSide << " " << iPhi << " " << iEta);
+            double hv[2];
+            for (int iGap=0;iGap<2;iGap++) {
+                const std::vector<unsigned int>::const_iterator itrLine=std::find(hvlineidx.begin(), hvlineidx.end(), hvMod->hvLineNo(iGap));
+                if(itrLine == hvlineidx.end()) { // error, could not find HVline index
+                  ATH_MSG_ERROR("Do not have hvline: "<<hvMod->hvLineNo(iGap)<<" in LArHVData !!!");
+                  return StatusCode::FAILURE;
+                }
+		hv[iGap]=fabs(voltage[itrLine - hvlineidx.begin()]);
+            }
+            float eta_min=hvMod->getEtaMin();
+            float eta_max=hvMod->getEtaMax();
+            float phi_min=CaloPhiRange::fix(hvMod->getPhiMin());
+            float phi_max=CaloPhiRange::fix(hvMod->getPhiMax());
+            ATH_MSG_DEBUG("  HV " <<  hv[0] << " " << hv[1] << " " << "  etamin,etamax,phimin,phimax " << eta_min << " " << eta_max << " " << phi_min << " " << phi_max);
+
+            //take decisions according to all the gaps HV :
+            bool isDead=false;
+            if (fabs(hv[0])<DEAD_HV_THRESHOLD && fabs(hv[1])<DEAD_HV_THRESHOLD) isDead=true;
+            bool isAffected=false;
+            if ( !isDead && ((fabs(hv[0]-HVnominal)>HV_NON_NOMINAL_TOLERANCE) || (fabs(hv[1]-HVnominal)>HV_NON_NOMINAL_TOLERANCE))) isAffected=true;
+            ATH_MSG_DEBUG(" dead/affected " << isDead << " " << isAffected );
+
+            if (isDead) {
+              CaloAffectedRegionInfo current_CaloAffectedRegionInfo(eta_min,eta_max,phi_min,phi_max,0,0,CaloAffectedRegionInfo::HVdead);
+              vAffected->push_back(current_CaloAffectedRegionInfo);             
+            }
+            if (isAffected) {
+              CaloAffectedRegionInfo current_CaloAffectedRegionInfo(eta_min,eta_max,phi_min,phi_max,0,0,CaloAffectedRegionInfo::HVaffected);
+              vAffected->push_back(current_CaloAffectedRegionInfo);
+            }
+          }       // loop over iEta EMBPS
+      }        // loop over iphi EMBPS
+    }    // lop over EMBPS side
+  } else {
+     ATH_MSG_ERROR("Do not have EMB HV Manager !!! ");
+     return StatusCode::FAILURE;
+  }
+  return StatusCode::SUCCESS;
+}
+//=========================================================================================
+StatusCode LArHVCondAlg::searchNonNominalHV_EMEC_OUTER(CaloAffectedRegionInfoVec *vAffected, const std::vector<float> &voltage, const std::vector<unsigned int> &hvlineidx) const { // deals with LAr HV, EM EndCap OUTER
+
+  const LArHVManager *manager = nullptr;
+
+  ATH_MSG_DEBUG(" start HV_EMEC_OUTER ");
+
+  if (detStore()->retrieve(manager)==StatusCode::SUCCESS) {
+      
+    const EMECHVManager* hvManager_EMEC=manager->getEMECHVManager(EMECHVModule::OUTER);
+
+    for (unsigned int iSide=hvManager_EMEC->beginSideIndex();iSide<hvManager_EMEC->endSideIndex();iSide++) { // loop over HV modules
+      for (unsigned int iPhi=hvManager_EMEC->beginPhiIndex();iPhi<hvManager_EMEC->endPhiIndex();iPhi++) {
+	for (unsigned int iSector=hvManager_EMEC->beginSectorIndex();iSector<hvManager_EMEC->endSectorIndex();iSector++) {
+	  for (unsigned int iEta=hvManager_EMEC->beginEtaIndex();iEta<hvManager_EMEC->endEtaIndex();iEta++) {
+	    EMECHVModuleConstLink hvMod=hvManager_EMEC->getHVModule(iSide,iEta,iPhi,iSector);
+
+            float etaMod = 0.5*(fabs(hvMod->getEtaMin())+fabs(hvMod->getEtaMax()));
+            float HVnominal = HV_nominal("EMEC",etaMod);
+
+            float eta_min=hvMod->getEtaMin();
+            float eta_max=hvMod->getEtaMax();
+
+            ATH_MSG_DEBUG("iSide,iPhi,iSector,iEta " << iSide << " " << iPhi << " " << iSector << " " 
+                          << iEta << " eta_min , eta_max " << eta_min << " " << eta_max );
+
+
+	    float phi_min=+30.,phi_max=-30.;
+
+	    bool are_previous_HV_affected=false;
+            bool are_previous_HV_dead=false;
+	    for (unsigned int ielec=0;ielec<hvMod->getNumElectrodes();ielec++) { //use hvMod->getNumElectrodes when bug is corrected
+	      EMECHVElectrodeConstLink electrode = hvMod->getElectrode(ielec);
+
+	      double hv[2];
+	      for (unsigned int iGap=0;iGap<2;iGap++) { //EMEC : 2 gaps, TRY TO FIND AUTOMATICALLY NB OF GAPS
+                  const std::vector<unsigned int>::const_iterator itrLine=std::find(hvlineidx.begin(), hvlineidx.end(), electrode->hvLineNo(iGap));
+                  if(itrLine == hvlineidx.end()) { // error, could not find HVline index
+                     ATH_MSG_ERROR("Do not have hvline: "<<electrode->hvLineNo(iGap)<<" in LArHVData !!!");
+                     return StatusCode::FAILURE;
+                  }
+		  hv[iGap]=voltage[itrLine - hvlineidx.begin()];
+	      } //end for iGap
+
+	      //------------------
+	      //take decisions according to all the gaps HV :
+              bool isDead=false;
+              if (fabs(hv[0])<DEAD_HV_THRESHOLD && fabs(hv[1])<DEAD_HV_THRESHOLD) isDead=true;
+              bool isAffected=false;
+              if ( !isDead && ((fabs(hv[0]-HVnominal)>HV_NON_NOMINAL_TOLERANCE) || (fabs(hv[1]-HVnominal)>HV_NON_NOMINAL_TOLERANCE))) isAffected=true;
+              ATH_MSG_DEBUG(" electrode HV " << ielec << " " << electrode->getPhi() << " " << hv[0] 
+                            << " " << hv[1] << " " << " isDead/isAffected " << isDead << " " << isAffected );
+          
+              // end previous dead region
+              if (are_previous_HV_dead && !isDead) {
+                 are_previous_HV_dead=false;
+                 ATH_MSG_DEBUG(" -- end dead region " << eta_min << " " << eta_max << " " <<phi_min << " " << phi_max);
+                 CaloAffectedRegionInfo current_CaloAffectedRegionInfo(eta_min,eta_max,phi_min,phi_max,5,7,CaloAffectedRegionInfo::HVdead);
+                 vAffected->push_back(current_CaloAffectedRegionInfo);
+              }
+
+              // end previous affected region
+              if (are_previous_HV_affected && !isAffected) {
+                 are_previous_HV_affected=false;
+                 ATH_MSG_DEBUG(" -- end affected region " << eta_min << " " << eta_max << " " <<phi_min << " " << phi_max);
+                 CaloAffectedRegionInfo current_CaloAffectedRegionInfo(eta_min,eta_max,phi_min,phi_max,5,7,CaloAffectedRegionInfo::HVaffected);
+                 vAffected->push_back(current_CaloAffectedRegionInfo);
+              }
+
+              if (isDead) {
+                 if (!are_previous_HV_dead) {
+                  phi_min=CaloPhiRange::fix(electrode->getPhi()-1e-4);
+                  phi_max=CaloPhiRange::fix(electrode->getPhi()+1e-4);
+                  are_previous_HV_dead = true;
+                  ATH_MSG_DEBUG(" -- start dead region " << eta_min << " " << eta_max << " " << phi_min << " " <<phi_max);
+                 }
+                 else {
+                  extendPhiRegion(electrode->getPhi(),phi_min,phi_max);
+                  ATH_MSG_DEBUG("  extend affected region " << phi_min << " " << phi_max);
+                 }
+              }
+
+              if (isAffected) {
+                 if (!are_previous_HV_affected) {
+                  phi_min=CaloPhiRange::fix(electrode->getPhi()-1e-4);
+                  phi_max=CaloPhiRange::fix(electrode->getPhi()+1e-4);
+                  are_previous_HV_affected = true;
+                  ATH_MSG_DEBUG(" -- start affected region " << eta_min << " " << eta_max << " " << phi_min << " " <<phi_max);
+                 }
+                 else {
+                  extendPhiRegion(electrode->getPhi(),phi_min,phi_max);
+                  ATH_MSG_DEBUG(" extend affected region " << phi_min << " " << phi_max);
+                 }
+              }
+
+	    } // end for ielec
+	    
+	    if (are_previous_HV_affected) { 
+              //in case a non nominal exists, stores it if we finish the 32 electrodes 
+              //(because else the are_previous_HV_affected will be reinitialized 
+              //for the next 32 electrodes serie )
+              ATH_MSG_DEBUG("   - finih affected region after electrode loop " << eta_min << " " << eta_max 
+                            << " " << phi_max << " " <<phi_max);
+	      CaloAffectedRegionInfo current_CaloAffectedRegionInfo(eta_min,eta_max,phi_min,phi_max,5,7,CaloAffectedRegionInfo::HVaffected);
+	      vAffected->push_back(current_CaloAffectedRegionInfo);	      
+	    }
+            if (are_previous_HV_dead) {
+              ATH_MSG_DEBUG(" -- finish dead region after electrode loop " << eta_min << " " << eta_max << " " << phi_max << " " <<phi_max);
+              CaloAffectedRegionInfo current_CaloAffectedRegionInfo(eta_min,eta_max,phi_min,phi_max,5,7,CaloAffectedRegionInfo::HVdead);
+              vAffected->push_back(current_CaloAffectedRegionInfo);
+            }
+	  } // end for iEta
+	} // end for iSector
+      } // end for iPhi
+    } //end for iSide
+
+    // endcap presampler
+    const EMECPresamplerHVManager* hvManager_EMECPS=manager->getEMECPresamplerHVManager();
+    float HVnominal = HV_nominal("EMECPS",0.);
+    for (unsigned int iSide=hvManager_EMECPS->beginSideIndex();iSide<hvManager_EMECPS->endSideIndex();iSide++) { // loop over HV modules
+      for (unsigned int iPhi=hvManager_EMECPS->beginPhiIndex();iPhi<hvManager_EMECPS->endPhiIndex();iPhi++) {
+            EMECPresamplerHVModuleConstLink hvMod = hvManager_EMECPS->getHVModule(iSide,iPhi);
+            double hv[2];
+            for (int iGap=0;iGap<2;iGap++) {
+                const std::vector<unsigned int>::const_iterator itrLine=std::find(hvlineidx.begin(), hvlineidx.end(), hvMod->hvLineNo(iGap));
+                if(itrLine == hvlineidx.end()) { // error, could not find HVline index
+                  ATH_MSG_ERROR("Do not have hvline: "<<hvMod->hvLineNo(iGap)<<" in LArHVData !!!");
+                  return StatusCode::FAILURE;
+                }
+		hv[iGap]=fabs(voltage[itrLine - hvlineidx.begin()]);
+            }
+            float eta_min=hvMod->getEtaMin(); 
+            float eta_max=hvMod->getEtaMax();
+            float phi_min=CaloPhiRange::fix(hvMod->getPhiMin());
+            float phi_max=CaloPhiRange::fix(hvMod->getPhiMax());
+            ATH_MSG_DEBUG("iSide,iPhi" << iSide << " " << iPhi << "  HV " <<  hv[0] << " " << hv[1] << " "
+                          << "  etamin,etamax,phimin,phimax " << eta_min << " " << eta_max << " " 
+                          << phi_min << " " << phi_max);
+
+            //take decisions according to all the gaps HV :
+            bool isDead=false;
+            if (fabs(hv[0])<DEAD_HV_THRESHOLD && fabs(hv[1])<DEAD_HV_THRESHOLD) isDead=true;
+            bool isAffected=false;
+            if ( !isDead && ((fabs(hv[0]-HVnominal)>HV_NON_NOMINAL_TOLERANCE) || (fabs(hv[1]-HVnominal)>HV_NON_NOMINAL_TOLERANCE))) isAffected=true;
+            ATH_MSG_DEBUG(" dead/affected " << isDead << " " << isAffected);
+
+            if (isDead) {
+              CaloAffectedRegionInfo current_CaloAffectedRegionInfo(eta_min,eta_max,phi_min,phi_max,4,4,CaloAffectedRegionInfo::HVdead);
+              vAffected->push_back(current_CaloAffectedRegionInfo);             
+            }
+            if (isAffected) {
+              CaloAffectedRegionInfo current_CaloAffectedRegionInfo(eta_min,eta_max,phi_min,phi_max,4,4,CaloAffectedRegionInfo::HVaffected);
+              vAffected->push_back(current_CaloAffectedRegionInfo);
+            }
+      }        // loop over iphi EMECPS
+    }    // lop over EMECPS side
+  } else {
+     ATH_MSG_ERROR("DO not have MEC HV manager !");
+     return StatusCode::FAILURE;
+  }
+  return StatusCode::SUCCESS;
+}
+//=========================================================================================
+StatusCode LArHVCondAlg::searchNonNominalHV_EMEC_INNER(CaloAffectedRegionInfoVec *vAffected, const std::vector<float> &voltage, const std::vector<unsigned int> &hvlineidx) const { // deals with LAr HV, EM EndCap INNER
+  const LArHVManager *manager = nullptr;
+
+  ATH_MSG_DEBUG(" start loop over EMEC_INNER ");
+  if (detStore()->retrieve(manager)==StatusCode::SUCCESS) {
+
+    const EMECHVManager* hvManager_EMEC=manager->getEMECHVManager(EMECHVModule::INNER);
+
+    for (unsigned int iSide=hvManager_EMEC->beginSideIndex();iSide<hvManager_EMEC->endSideIndex();iSide++) { // loop over HV modules
+      for (unsigned int iPhi=hvManager_EMEC->beginPhiIndex();iPhi<hvManager_EMEC->endPhiIndex();iPhi++) {
+	for (unsigned int iSector=hvManager_EMEC->beginSectorIndex();iSector<hvManager_EMEC->endSectorIndex();iSector++) {
+	  for (unsigned int iEta=hvManager_EMEC->beginEtaIndex();iEta<hvManager_EMEC->endEtaIndex();iEta++) {
+	    EMECHVModuleConstLink hvMod=hvManager_EMEC->getHVModule(iSide,iEta,iPhi,iSector);
+
+            float etaMod = 0.5*(fabs(hvMod->getEtaMin())+fabs(hvMod->getEtaMax()));
+            float HVnominal = HV_nominal("EMEC",etaMod);
+
+            float eta_min = hvMod->getEtaMin();
+            float eta_max = hvMod->getEtaMax();
+
+            ATH_MSG_DEBUG("iSide,iPhi,iSector,iEta " << iSide << " " << iPhi << " " << iSector << " " 
+                          << iEta << " eta_min , eta_max " << eta_min << " " << eta_max);
+
+	    float phi_min=+30.,phi_max=-30.;
+
+	    bool are_previous_HV_affected=0;
+	    bool are_previous_HV_dead=0;
+	    for (unsigned int ielec=0;ielec<hvMod->getNumElectrodes();ielec++) { 
+	      EMECHVElectrodeConstLink electrode = hvMod->getElectrode(ielec);
+
+	      double hv[2];
+	      for (unsigned int iGap=0;iGap<2;iGap++) { 
+                  const std::vector<unsigned int>::const_iterator itrLine=std::find(hvlineidx.begin(), hvlineidx.end(), electrode->hvLineNo(iGap));
+                  if(itrLine == hvlineidx.end()) { // error, could not find HVline index
+                     ATH_MSG_ERROR("Do not have hvline: "<<electrode->hvLineNo(iGap)<<" in LArHVData !!!");
+                     return StatusCode::FAILURE;
+                  }
+		  hv[iGap]=voltage[itrLine - hvlineidx.begin()];
+	      } //end for iGap
+
+	      //------------------
+	      //take decisions according to all the gaps HV :
+              bool isDead=false;
+              if (fabs(hv[0])<DEAD_HV_THRESHOLD && fabs(hv[1])<DEAD_HV_THRESHOLD) isDead=true;
+              bool isAffected=false;
+              if ( !isDead && ((fabs(hv[0]-HVnominal)>HV_NON_NOMINAL_TOLERANCE) || (fabs(hv[1]-HVnominal)>HV_NON_NOMINAL_TOLERANCE))) isAffected=true;
+              ATH_MSG_DEBUG(" electrode HV " << ielec << " " << electrode->getPhi() << " "
+                            << hv[0] << " " << hv[1] << " " << " isDead, isAffected " 
+                            << isDead << " " << isAffected);
+          
+              // end previous dead region
+              if (are_previous_HV_dead && !isDead) {
+                 are_previous_HV_dead=false;
+                 ATH_MSG_DEBUG(" -- end dead region " << eta_min << " " << eta_max << " " <<phi_min << " " << phi_max);
+                 CaloAffectedRegionInfo current_CaloAffectedRegionInfo(eta_min,eta_max,phi_min,phi_max,5,7,CaloAffectedRegionInfo::HVdead);
+                 vAffected->push_back(current_CaloAffectedRegionInfo);
+              }
+
+              // end previous affected region
+              if (are_previous_HV_affected && !isAffected) {
+                 are_previous_HV_affected=false;
+                 ATH_MSG_DEBUG(" -- end affected region " << eta_min << " " << eta_max << " " <<phi_min << " " << phi_max);
+                 CaloAffectedRegionInfo current_CaloAffectedRegionInfo(eta_min,eta_max,phi_min,phi_max,5,7,CaloAffectedRegionInfo::HVaffected);
+                 vAffected->push_back(current_CaloAffectedRegionInfo);
+              }
+
+              if (isDead) {
+                 if (!are_previous_HV_dead) {
+                  phi_min=CaloPhiRange::fix(electrode->getPhi()-1e-4);
+                  phi_max=CaloPhiRange::fix(electrode->getPhi()+1e-4);
+                  ATH_MSG_DEBUG(" -- start dead region " << phi_min << " " << phi_max);
+                  are_previous_HV_dead = true;
+                 }
+                 else {
+                  extendPhiRegion(electrode->getPhi(),phi_min,phi_max);
+                  ATH_MSG_DEBUG("  extend dead region " << phi_min << " " << phi_max);
+                 }
+              }
+
+              if (isAffected) {
+                 if (!are_previous_HV_affected) {
+                  phi_min=CaloPhiRange::fix(electrode->getPhi()-1e-4);
+                  phi_max=CaloPhiRange::fix(electrode->getPhi()+1e-4);
+                  are_previous_HV_affected = true;
+                  ATH_MSG_DEBUG(" -- start affected region " << phi_min << " " << phi_max);
+                 }
+                 else {
+                   extendPhiRegion(electrode->getPhi(),phi_min,phi_max);
+                   ATH_MSG_DEBUG("  extend affected region " << phi_min << " " << phi_max);
+                 }
+              }
+
+	    } // end for ielec
+	    
+	    if (are_previous_HV_affected) { 
+              //in case a non nominal exists, stores it if we finish the 32 electrodes 
+              //(because else the are_previous_HV_affected will be reinitialized 
+              //for the next 32 electrodes serie )
+              ATH_MSG_DEBUG("   - finish affected region after electrode loop " << eta_min << " " 
+                            << eta_max << " " << phi_max << " " <<phi_max);
+	      CaloAffectedRegionInfo current_CaloAffectedRegionInfo(eta_min,eta_max,phi_min,phi_max,5,7,CaloAffectedRegionInfo::HVaffected);
+	      vAffected->push_back(current_CaloAffectedRegionInfo);	      
+	    }
+            if (are_previous_HV_dead) {
+              ATH_MSG_DEBUG("    - end dead region after electrode loop " << eta_min << " " << eta_max << " " << phi_max << " " <<phi_max);
+              CaloAffectedRegionInfo current_CaloAffectedRegionInfo(eta_min,eta_max,phi_min,phi_max,5,7,CaloAffectedRegionInfo::HVdead);
+              vAffected->push_back(current_CaloAffectedRegionInfo);
+            }
+	  } // end for iEta
+	} // end for iSector
+      } // end for iPhi
+    } //end for iSide
+  } else {
+     ATH_MSG_ERROR("DO not have EMEC HV manager ");
+     return StatusCode::FAILURE;
+  }
+  return StatusCode::SUCCESS;
+}
+//=========================================================================================
+StatusCode LArHVCondAlg::searchNonNominalHV_HEC(CaloAffectedRegionInfoVec *vAffected, const std::vector<float> &voltage, const std::vector<unsigned int> &hvlineidx) const { // deals with LAr HV, HEC
+  
+  ATH_MSG_DEBUG(" in HEC ");
+  const LArHVManager *manager = nullptr;
+  float etamax_layer[4]={3.3,3.1,3.1,3.3};
+  float etamin_layer[4]={1.5,1.5,1.6,1.7};
+ 
+  float HVnominal = HV_nominal("HEC",0.);
+
+
+  if (detStore()->retrieve(manager)==StatusCode::SUCCESS) {
+  
+    const HECHVManager* hvManager_HEC=manager->getHECHVManager();
+    
+    for (unsigned int iSide=hvManager_HEC->beginSideIndex();iSide<hvManager_HEC->endSideIndex();iSide++) { // loop over HV modules      
+      for (unsigned int iPhi=hvManager_HEC->beginPhiIndex();iPhi<hvManager_HEC->endPhiIndex();iPhi++) {
+	for (unsigned int iSampling=hvManager_HEC->beginSamplingIndex();iSampling<hvManager_HEC->endSamplingIndex();iSampling++) {
+          float eta_min,eta_max;
+          if (iSide==1) {
+           eta_min = etamin_layer[iSampling];
+           eta_max = etamax_layer[iSampling];
+          } else {
+           eta_min = -1.*etamax_layer[iSampling];
+           eta_max = -1.*etamin_layer[iSampling];
+         }
+
+	  HECHVModuleConstLink hvMod = hvManager_HEC->getHVModule(iSide,iPhi,iSampling);
+          ATH_MSG_DEBUG(" iSide,iPhi,iSampling " << iSide << " " << iPhi << " " << iSampling);
+
+	  double hv[4] = {0}; // 4 subgaps in HEC
+	  for (unsigned int iGap=0;iGap<hvMod->getNumSubgaps();iGap++) {
+	    HECHVSubgapConstLink subgap=hvMod->getSubgap(iGap);
+            const std::vector<unsigned int>::const_iterator itrLine=std::find(hvlineidx.begin(), hvlineidx.end(), subgap->hvLineNo());
+            if(itrLine == hvlineidx.end()) { // error, could not find HVline index
+              ATH_MSG_ERROR("Do not have hvline: "<<subgap->hvLineNo()<<" in LArHVData !!!");
+              return StatusCode::FAILURE;
+            }
+	    if(iGap<4) hv[iGap]=voltage[itrLine - hvlineidx.begin()];
+	  }// end for iGap
+
+	  //------------------
+          //take decisions according to all the gaps HV :
+          bool isDead=false;
+          if (fabs(hv[0])<DEAD_HV_THRESHOLD && fabs(hv[1])<DEAD_HV_THRESHOLD  && fabs(hv[2])<DEAD_HV_THRESHOLD && fabs(hv[3])<DEAD_HV_THRESHOLD) isDead=true;
+          bool isAffected=false;
+          if ( !isDead && ((fabs(hv[0]-HVnominal)>HV_NON_NOMINAL_TOLERANCE) || (fabs(hv[1]-HVnominal)>HV_NON_NOMINAL_TOLERANCE) || 
+                           (fabs(hv[2]-HVnominal)>HV_NON_NOMINAL_TOLERANCE) || (fabs(hv[3]-HVnominal)>HV_NON_NOMINAL_TOLERANCE)) ) isAffected=true;
+          ATH_MSG_DEBUG(" HV values " << hv[0] << " " << hv[1] << " " << hv[2] << " " << hv[3] << " " 
+                        << " isDead/isAffected " << isDead << " " << isAffected);
+
+          float phiMin = CaloPhiRange::fix(hvMod->getPhiMin());
+          float phiMax = CaloPhiRange::fix(hvMod->getPhiMax());
+
+
+	  if (isDead) { //stores it, DEAD means all hvs < threshold
+            ATH_MSG_DEBUG(" new dead region " << eta_min << " " << eta_max << " " << phiMin << " " << phiMax << " layer " << 8+iSampling);
+	    CaloAffectedRegionInfo current_CaloAffectedRegionInfo(eta_min,eta_max,phiMin,phiMax,8+iSampling,8+iSampling,CaloAffectedRegionInfo::HVdead);
+	    vAffected->push_back(current_CaloAffectedRegionInfo);
+	  }
+          if (isAffected) {
+            ATH_MSG_DEBUG(" new affected region " << eta_min << " " << eta_max << " " << phiMin << " " << phiMax << " layer " << 8+iSampling);
+            CaloAffectedRegionInfo current_CaloAffectedRegionInfo(eta_min,eta_max,phiMin,phiMax,8+iSampling,8+iSampling,CaloAffectedRegionInfo::HVaffected);
+            vAffected->push_back(current_CaloAffectedRegionInfo);
+          }
+
+	} //end for iSampling
+      }//end for iPhi
+    }//end for iSide
+  } else {
+     ATH_MSG_ERROR("Do not have HEC HV manager ");
+     return StatusCode::FAILURE;
+  }
+  return StatusCode::SUCCESS;
+}
+//=========================================================================================
+StatusCode LArHVCondAlg::searchNonNominalHV_FCAL(CaloAffectedRegionInfoVec *vAffected, const std::vector<float> &voltage, const std::vector<unsigned int> &hvlineidx) const { // deals with LAr HV, FCAL
+
+  ATH_MSG_DEBUG( " inFCAL ");
+  const LArHVManager *manager = nullptr;
+  if (detStore()->retrieve(manager)==StatusCode::SUCCESS) {  
+    
+    const FCALHVManager *hvManager_FCAL=manager->getFCALHVManager();
+    
+    for (unsigned int iSide=hvManager_FCAL->beginSideIndex();iSide<hvManager_FCAL->endSideIndex();iSide++) { // loop over HV modules
+      float eta_min=3.1,eta_max=4.9;
+      if (iSide==0) {
+         eta_min=-4.9;
+         eta_max=-3.1;
+      }
+      for (unsigned int iSampling=hvManager_FCAL->beginSamplingIndex();iSampling<hvManager_FCAL->endSamplingIndex();iSampling++) {
+        float HVnominal = HV_nominal("FCAL",(float)(iSampling));
+	for (unsigned int iSector=hvManager_FCAL->beginSectorIndex(iSampling);iSector<hvManager_FCAL->endSectorIndex(iSampling);iSector++) {
+
+	  FCALHVModuleConstLink hvMod = hvManager_FCAL->getHVModule(iSide,iSector,iSampling);
+          ATH_MSG_DEBUG(" FCAL HVModule side,sampling,sector " << iSide << " " << iSampling << " " 
+                        << iSector << "   HV nominal " << HVnominal);
+ 
+          float dphi=CaloPhiRange::twopi()/16;
+          if (iSampling==1) dphi=CaloPhiRange::twopi()/8.;
+          if (iSampling==2) dphi=CaloPhiRange::twopi()/4.;
+          float phi_min = ((float)(iSector))*dphi;
+          phi_min =   CaloPhiRange::fix(phi_min);
+          float phi_max = CaloPhiRange::fix(dphi+phi_min);
+        
+          ATH_MSG_DEBUG(" eta_min,eta_max,phi_min,phi_max " << eta_min << " " << eta_max << " " << phi_min 
+                        << " " << phi_max << "   number of lines " << hvMod->getNumHVLines());
+          float hv[4] = {0};
+	  for (unsigned int iLine=0;iLine<hvMod->getNumHVLines();iLine++) {
+	    FCALHVLineConstLink hvline = hvMod->getHVLine(iLine);
+            const std::vector<unsigned int>::const_iterator itrLine=std::find(hvlineidx.begin(), hvlineidx.end(), hvline->hvLineNo());
+            if(itrLine == hvlineidx.end()) { // error, could not find HVline index
+              ATH_MSG_ERROR("Do not have hvline: "<<hvline->hvLineNo()<<" in LArHVData !!!");
+              return StatusCode::FAILURE;
+            }
+	    if (iLine<4) hv[iLine] = voltage[itrLine - hvlineidx.begin()];
+          }
+	  //------------------
+	  //take decisions according to all the gaps HV :
+          bool isDead=false;
+          if (fabs(hv[0]) < DEAD_HV_THRESHOLD && fabs(hv[1]) < DEAD_HV_THRESHOLD && fabs(hv[2]) < DEAD_HV_THRESHOLD && fabs(hv[3]) < DEAD_HV_THRESHOLD) isDead=true;
+          bool isAffected=false;
+          if ( !isDead && ((fabs(hv[0]-HVnominal)>HV_NON_NOMINAL_TOLERANCE) || (fabs(hv[1]-HVnominal)>HV_NON_NOMINAL_TOLERANCE) ||
+                           (fabs(hv[2]-HVnominal)>HV_NON_NOMINAL_TOLERANCE) || (fabs(hv[3]-HVnominal)>HV_NON_NOMINAL_TOLERANCE)) ) isAffected=true;
+          ATH_MSG_DEBUG(" HV values " << hv[0] << " " << hv[1] << " " << hv[2] << " " << hv[3] <<  " " 
+                        << " isDead/isAffected " << isDead << " " << isAffected);
+
+	    
+	  if (isAffected) { 
+            ATH_MSG_DEBUG(" -- store affected region ");
+	    CaloAffectedRegionInfo current_CaloAffectedRegionInfo(eta_min,eta_max,phi_min,phi_max,21+iSampling,21+iSampling,CaloAffectedRegionInfo::HVaffected);
+	    vAffected->push_back(current_CaloAffectedRegionInfo);	      
+	  }
+          if (isDead) { 
+            ATH_MSG_DEBUG(" -- store dead region ");
+            CaloAffectedRegionInfo current_CaloAffectedRegionInfo(eta_min,eta_max,phi_min,phi_max,21+iSampling,21+iSampling,CaloAffectedRegionInfo::HVdead);
+            vAffected->push_back(current_CaloAffectedRegionInfo);
+          }
+	} //end iSector
+      } //end iSampling
+    }// end iSide
+  } else {
+     ATH_MSG_ERROR("Do not have FCAL HV manager");
+     return StatusCode::FAILURE;
+  }
+  return StatusCode::SUCCESS;
+}
+//=========================================================================================
+StatusCode LArHVCondAlg::updateMethod(CaloAffectedRegionInfoVec *vAffected, const LArBadFebCont* bfCont, const LArOnOffIdMapping* cabling) const { //store informations on the missing Febs w/ range of eta, phi, layer
+  ATH_MSG_INFO ( "updateMethod()" );
+  
+  std::vector<HWIdentifier>::const_iterator febid_it=m_onlineID->feb_begin();
+  std::vector<HWIdentifier>::const_iterator febid_end_it=m_onlineID->feb_end();
+
+  for (;febid_it!=febid_end_it;++febid_it) {
+      
+    bool IsMissingFeb=(bfCont->status(*febid_it).deadAll() || bfCont->status(*febid_it).deadReadout());
+    
+    if (IsMissingFeb) {       //flag for special treatment for FEB that has non contiguous eta regions, so we have to separate them
+      bool is_normal=0; //FEB without discontinuity
+      bool is_additive1=0; //FEB with a discontinuity
+      
+      int layer_min=+30,layer_max=-30;
+      float eta_min=+30,eta_max=-30;
+      float phi_min=+30,phi_max=-30;
+      
+      int layer_min_additive1=+30,layer_max_additive1=-30;
+      float eta_min_additive1=+30,eta_max_additive1=-30;
+      float phi_min_additive1=+30,phi_max_additive1=-30;
+      
+      int chans_per_feb = m_onlineID->channelInSlotMax(*febid_it);
+      
+      for (int icha=0;icha<chans_per_feb;icha++) {   //loop on each channel of the relevant FEB
+	HWIdentifier channelId=m_onlineID->channel_Id(*febid_it,icha);
+
+	if (cabling->isOnlineConnected(channelId)) {
+	  Identifier offlineId=cabling->cnvToIdentifier(channelId);
+	  const CaloDetDescrElement* caloddElement=m_calodetdescrmgr->get_element(offlineId);
+	  
+	  CaloCell_ID::CaloSample current_layer=caloddElement->getSampling(); // calo layer
+	  float current_eta=caloddElement->eta();
+	  float current_eta_low=caloddElement->eta()-0.5*caloddElement->deta();
+	  float current_eta_high=caloddElement->eta()+0.5*caloddElement->deta();
+	  float current_phi_low=caloddElement->phi()-0.5*caloddElement->dphi();
+	  float current_phi_high=caloddElement->phi()+0.5*caloddElement->dphi();
+	  
+	  if (caloddElement->is_lar_em_barrel() && caloddElement->getLayer()==3 && fabs(current_eta)>0.79 && fabs(current_eta)<1.33) { //EMB, back sampling, slot 12 : special treatment : this FEB has non contiguous eta regions, so we have to separate them
+	    is_additive1=1; //in order to add it to the summary only if it happens
+	    
+	    if (current_layer<layer_min_additive1)
+	      layer_min_additive1=current_layer;
+	    if (current_layer>layer_max_additive1)
+	      layer_max_additive1=current_layer;
+	    
+	    if (current_eta_low<eta_min_additive1)
+	      eta_min_additive1=current_eta_low;
+	    if (current_eta_high>eta_max_additive1)
+	      eta_max_additive1=current_eta_high;
+	    
+            extendPhiRegion(current_phi_low,phi_min_additive1,phi_max_additive1);
+            extendPhiRegion(current_phi_high,phi_min_additive1,phi_max_additive1);
+	    
+	    //	    std::cout << "found the special case, icha=" << icha << ", etamin=" << eta_min_additive1 << ", current layer=" << current_layer << ", current eta=" << current_eta << std::endl;
+	  }
+	  else { //normal case
+	    is_normal=1; // normal case
+	    
+	    if (current_layer<layer_min)
+	      layer_min=current_layer;
+	    if (current_layer>layer_max)
+	      layer_max=current_layer;
+	    
+	    if (current_eta_low<eta_min)
+	      eta_min=current_eta_low;
+	    if (current_eta_high>eta_max)
+	      eta_max=current_eta_high;
+	    
+            extendPhiRegion(current_phi_low,phi_min,phi_max);
+            extendPhiRegion(current_phi_high,phi_min,phi_max);
+
+	  }
+	} //end of isOnlineConnected()
+      } // end of loop on channels
+      
+      if (is_normal) {
+	CaloAffectedRegionInfo current_CaloAffectedRegionInfo(eta_min,eta_max,phi_min,phi_max,layer_min,layer_max,CaloAffectedRegionInfo::missingReadout);
+	vAffected->push_back(current_CaloAffectedRegionInfo);
+      }
+      
+      if (is_additive1) {
+	CaloAffectedRegionInfo current_additive1_CaloAffectedRegionInfo(eta_min_additive1,eta_max_additive1,phi_min_additive1,phi_max_additive1,layer_min_additive1,layer_max_additive1,CaloAffectedRegionInfo::missingReadout);
+	vAffected->push_back(current_additive1_CaloAffectedRegionInfo);
+      }
+    } // end of isMissingFeb  
+  } // end of loop on Febs  
+  return StatusCode::SUCCESS;
+}
+//====================================================================================
+float LArHVCondAlg::HV_nominal(const char *identification,const float myparameter) const
+{
+  if (strcmp(identification,"EMBPS")==0) 
+    return 1200.;
+  else if (strcmp(identification,"EMECPS")==0)
+    return 1600.;
+  else if (strcmp(identification,"EMB")==0)
+    return 2000.;
+  else if (strcmp(identification,"EMEC")==0) {
+    if ( fabs(myparameter)<1.5 )
+      return 2500.;
+    else if (fabs(myparameter)<1.6)
+      return 2300.;
+    else if (fabs(myparameter)<1.8 )
+      return 2100.;
+    else if ( fabs(myparameter) < 2.0 )
+      return 1700.;
+    else if ( fabs(myparameter) < 2.1 )
+      return 1500.;
+    else if ( fabs(myparameter) < 2.3 )
+      return 1250.;
+    else if ( fabs(myparameter) < 2.5 )
+      return 1000.;
+    else if ( fabs(myparameter) < 2.8 )
+      return 2300.;
+    else return 1800.;
+  }
+  else if (strcmp(identification,"HEC")==0) {
+    return 1800.;
+  }
+  else if (strcmp(identification,"FCAL")==0) {
+    if (myparameter<0.5)
+      return 250.;
+    else if (myparameter<1.5)
+      return 375.;
+    else if (myparameter<2.5)
+      return 500.;
+  }
+
+  return -1;
+}
+//=========================================================================================
+
+void LArHVCondAlg::extendPhiRegion(float phi, float & phi_min, float & phi_max) const {
+
+  static float epsilon=1e-4;
+  
+  phi = CaloPhiRange::fix(phi);
+
+  if (phi_min>10. || phi_max<-10.) {
+     phi_min = CaloPhiRange::fix(phi-epsilon);
+     phi_max = CaloPhiRange::fix(phi+epsilon);
+     return;
+  }
+
+  bool isInRegion=false;
+  if (phi_min<phi_max) {
+     if (phi>phi_min && phi<phi_max) isInRegion=true;
+  }
+  else {
+     if (phi>phi_min || phi<phi_max) isInRegion=true;
+  }
+  if (isInRegion) return;
+
+  float dphi1 = CaloPhiRange::diff(phi,phi_min); 
+  float dphi2 = CaloPhiRange::diff(phi,phi_max); 
+  if (fabs(dphi1)<fabs(dphi2) )
+     phi_min=phi;
+  else
+     phi_max=phi;
+  
+  return;
+
+}
diff --git a/LArCalorimeter/LArRecUtils/src/LArHVCondAlg.h b/LArCalorimeter/LArRecUtils/src/LArHVCondAlg.h
index f2505bff67012c59c3055f16e386e815773a0207..b715569aa23a2e498668697666303d7ad6b65c52 100755
--- a/LArCalorimeter/LArRecUtils/src/LArHVCondAlg.h
+++ b/LArCalorimeter/LArRecUtils/src/LArHVCondAlg.h
@@ -2,17 +2,27 @@
   Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
 */
 
+/**
+  @brief This conditions algo produces both LArHVData and LArAffectedRegions
+
+*/
+
+
 #ifndef LARHVCONDALG_H
 #define LARHVCONDALG_H
 
 
-//#include "LArElecCalib/ILArHVTool.h" 
 #include "AthenaBaseComps/AthReentrantAlgorithm.h"
 #include "StoreGate/DataHandle.h" 
 #include "Identifier/Identifier.h"
 #include "AthenaBaseComps/AthAlgTool.h"
 #include "LArRecConditions/LArHVPathology.h"
 #include "LArRecConditions/LArHVData.h"
+#include "CaloConditions/CaloAffectedRegionInfoVec.h"
+#include "LArRecConditions/LArBadChannelCont.h"
+#include "LArCabling/LArOnOffIdMapping.h"
+#include "LArRecConditions/LArHVIdMapping.h"
+
 #include "StoreGate/ReadCondHandleKey.h"
 #include "StoreGate/WriteCondHandleKey.h"
 #include "StoreGate/CondHandleKeyArray.h"
@@ -32,6 +42,7 @@ class Identifier;
 class LArElectrodeID;
 class LArHVLineID;
 class HWIdentifier;
+class LArOnlineID;
 
 class LArHVCondAlg: public AthReentrantAlgorithm
 {
@@ -49,15 +60,23 @@ class LArHVCondAlg: public AthReentrantAlgorithm
 
   private:
 
-  typedef std::vector<std::vector<unsigned short> > pathVec;
+  // Conditions keys read:
 
-  StatusCode fillPayload(LArHVData *hvdata, const LArHVData* hvdataOld, std::vector<float> &voltage, std::vector<float> &current, std::vector<unsigned int> &hvlineidx, const LArHVPathology& pathologies, pathVec& hasPathologyEM, pathVec& hasPathologyHEC, pathVec& hasPathologyFCAL) const;
-  void addHV(std::vector< LArHVData::HV_t > & v, double hv, double wt) const;
-  void addCurr(std::vector< LArHVData::CURRENT_t > & ihv, double curr, double wt) const;
-  std::vector<unsigned int> getElecList(const Identifier& id, const LArHVPathology& pathologies) const;
-  StatusCode fillUpdatedHVChannelsVec(std::vector<float> &voltage, std::vector<float> &current, std::vector<unsigned int> &hvlineidx, std::vector<const CondAttrListCollection* > fldvec) const;
+  SG::ReadCondHandleKey<LArHVPathology> m_pathologiesKey { this, "HVPathologies", "LArHVPathology", "Key for HV pathologies in Cond. store"};
 
+  SG::ReadCondHandleKeyArray<CondAttrListCollection>  m_DCSFolderKeys { this, "DCSFolderNames", {"/LAR/DCS/HV/BARREl/I16", "/LAR/DCS/HV/BARREL/I8"}, "DCS folders with HV values"};
+
+  SG::ReadCondHandleKey<LArBadFebCont> m_BFKey{this, "MissingFEBKey", "LArBadFeb", "SG key for missing FEB object"};
 
+  SG::ReadCondHandleKey<LArOnOffIdMapping> m_cablingKey{this, "OnOffMap", "LArOnOffIdMap", "SG key for mapping object"};
+
+  // Conditions keys write:
+  SG::WriteCondHandleKey<LArHVData> m_hvDataKey {this, "OutputHVData", "LArHVData", "Key for output HV data object"};
+  
+  SG::WriteCondHandleKey<CaloAffectedRegionInfoVec> m_outKey{this, "OutputKey", "LArAffectedRegionInfo", "SG key for output"};
+
+  // other members:
+  
   const DataHandle<CaloIdManager> m_caloIdMgr;
   const DataHandle<CaloDetDescrManager> m_calodetdescrmgr;
   const LArEM_ID* m_larem_id;
@@ -65,15 +84,38 @@ class LArHVCondAlg: public AthReentrantAlgorithm
   const LArFCAL_ID* m_larfcal_id;
   const LArElectrodeID* m_electrodeID;
   const LArHVLineID* m_hvLineID;
+  const LArOnlineID* m_onlineID;
+  ServiceHandle<ICondSvc> m_condSvc;
 
-  SG::ReadCondHandleKey<LArHVPathology> m_pathologiesKey { this, "HVPathologies", "LArHVPathology", "Key for HV pathologies in Cond. store"};
+  bool m_doHV;
+  bool m_doAffected;
+  bool m_doAffectedHV;
 
-  SG::ReadCondHandleKeyArray<CondAttrListCollection>  m_DCSFolderKeys { this, "DCSFolderNames", {"/LAR/DCS/HV/BARREl/I16", "/LAR/DCS/HV/BARREL/I8"}, "DCS folders with HV values"};
+  // private methods:
+  
+  // for the LArHVData construction:
 
-  SG::WriteCondHandleKey<LArHVData> m_hvDataKey {this, "OutputHVData", "LArHVData", "Key for output HV data object"};
+  typedef std::vector<std::vector<unsigned short> > pathVec;
 
-  ServiceHandle<ICondSvc> m_condSvc;
+  StatusCode fillPayload(LArHVData *hvdata, const LArHVData* hvdataOld, std::vector<float> &voltage, std::vector<float> &current, std::vector<unsigned int> &hvlineidx, const LArHVPathology& pathologies, pathVec& hasPathologyEM, pathVec& hasPathologyHEC, pathVec& hasPathologyFCAL) const;
+  void addHV(std::vector< LArHVData::HV_t > & v, double hv, double wt) const;
+  void addCurr(std::vector< LArHVData::CURRENT_t > & ihv, double curr, double wt) const;
+  std::vector<unsigned int> getElecList(const Identifier& id, const LArHVPathology& pathologies) const;
+  StatusCode fillUpdatedHVChannelsVec(std::vector<float> &voltage, std::vector<float> &current, std::vector<unsigned int> &hvlineidx, std::vector<const CondAttrListCollection* > fldvec) const;
+
+  // for the LArAffectedRegions construction
+
+  void extendPhiRegion(float phi, float & phi_min, float & phi_max) const;
+
+  StatusCode updateMethod(CaloAffectedRegionInfoVec *vAffected, const LArBadFebCont* bfCont, const LArOnOffIdMapping* cabling) const;
 
+  StatusCode searchNonNominalHV_EMB(CaloAffectedRegionInfoVec *vAffected, const std::vector<float> &voltage, const std::vector<unsigned int> &hvlineidx) const;
+  StatusCode searchNonNominalHV_EMEC_OUTER(CaloAffectedRegionInfoVec *vAffected, const std::vector<float> &voltage, const std::vector<unsigned int> &hvlineidx) const;
+  StatusCode searchNonNominalHV_EMEC_INNER(CaloAffectedRegionInfoVec *vAffected, const std::vector<float> &voltage, const std::vector<unsigned int> &hvlineidx) const;
+  StatusCode searchNonNominalHV_HEC(CaloAffectedRegionInfoVec *vAffected, const std::vector<float> &voltage, const std::vector<unsigned int> &hvlineidx) const;
+  StatusCode searchNonNominalHV_FCAL(CaloAffectedRegionInfoVec *vAffected, const std::vector<float> &voltage, const std::vector<unsigned int> &hvlineidx) const;
+  float HV_nominal(const char *identification,const float eta) const;
+  std::vector<int> returnProblem(const float eta, const float phi, const float delta_eta, const float delta_phi);
 
 };
 
diff --git a/Reconstruction/egamma/egammaTools/python/egammaOQFlagsBuilder.py b/Reconstruction/egamma/egammaTools/python/egammaOQFlagsBuilder.py
index 51d4020be5a3462a1bfc0d7135bd6366300b4be4..02437f86baa8ce805375a4f08cbdd63a8b4ef2fd 100644
--- a/Reconstruction/egamma/egammaTools/python/egammaOQFlagsBuilder.py
+++ b/Reconstruction/egamma/egammaTools/python/egammaOQFlagsBuilder.py
@@ -4,8 +4,7 @@ import egammaToolsConf
 from egammaRec.Factories import FcnWrapper, ToolFactory
 from egammaRec import egammaKeys
 
-from CaloTools import CaloAffectedToolDefault as CATD
-CaloAffectedToolDefault = ToolFactory( CATD.CaloAffectedToolDefault )
+from CaloTools.CaloToolsConf import CaloAffectedTool
 
 egammaOQFlagsBuilder = ToolFactory( egammaToolsConf.egammaOQFlagsBuilder,
   QCellCut = 4000.,
@@ -16,4 +15,4 @@ egammaOQFlagsBuilder = ToolFactory( egammaToolsConf.egammaOQFlagsBuilder,
   TCutVsE = 2.,
   RcellCut = 0.8,
   CellsName = egammaKeys.caloCellKey(),
-  affectedTool = CaloAffectedToolDefault)
+  affectedTool = CaloAffectedTool())
diff --git a/Reconstruction/egamma/egammaTools/src/egammaOQFlagsBuilder.cxx b/Reconstruction/egamma/egammaTools/src/egammaOQFlagsBuilder.cxx
index 7534043d2903ceecd6a4d5c3e3e13a7daf97645f..2217f1485555eaf597984517f748cdd29ab06bcb 100644
--- a/Reconstruction/egamma/egammaTools/src/egammaOQFlagsBuilder.cxx
+++ b/Reconstruction/egamma/egammaTools/src/egammaOQFlagsBuilder.cxx
@@ -37,7 +37,6 @@ egammaOQFlagsBuilder::egammaOQFlagsBuilder(const std::string& type,
   // declare interface
   declareInterface<IegammaBaseTool>(this);
 
-  m_affRegVec = 0;
   m_calocellId = 0;
 }
 
@@ -60,6 +59,7 @@ StatusCode egammaOQFlagsBuilder::initialize()
  
   ATH_CHECK(m_cellsKey.initialize());
   ATH_CHECK(m_bcContKey.initialize());
+  ATH_CHECK(m_affKey.initialize());
 
    //Get CaloAffectedTool
   StatusCode sc = m_affectedTool.retrieve();
@@ -342,12 +342,19 @@ StatusCode egammaOQFlagsBuilder::execute(const EventContext& ctx, xAOD::Egamma*
   dphi=0.5*0.025*phiSize;
   layer=CaloSampling::PreSamplerE;
 
-  bool checkNNHV_PSE   = m_affectedTool->isAffected(cluster ,deta , dphi ,layer,layer,1) ; //nnHVPS
-  bool checkDEADHV_PSE = m_affectedTool->isAffected(cluster ,deta , dphi ,layer,layer,2) ; //deadHVPS
+  //Get affected info for this event
+  SG::ReadCondHandle<CaloAffectedRegionInfoVec> affHdl{m_affKey,ctx};
+  const CaloAffectedRegionInfoVec* affCont=*affHdl;
+  if(!affCont) {
+     ATH_MSG_WARNING("Do not have affected regions info, is this expected ?");
+  }
+    
+  bool checkNNHV_PSE   = m_affectedTool->isAffected(cluster, affCont, deta , dphi ,layer,layer,1) ; //nnHVPS
+  bool checkDEADHV_PSE = m_affectedTool->isAffected(cluster, affCont, deta , dphi ,layer,layer,2) ; //deadHVPS
   layer=CaloSampling::PreSamplerB;
 
-  bool checkNNHV_PSB   = m_affectedTool->isAffected(cluster ,deta , dphi ,layer,layer,1) ; //nnHVPS
-  bool checkDEADHV_PSB = m_affectedTool->isAffected(cluster ,deta , dphi ,layer,layer,2) ; //deadHVPS
+  bool checkNNHV_PSB   = m_affectedTool->isAffected(cluster, affCont, deta , dphi ,layer,layer,1) ; //nnHVPS
+  bool checkDEADHV_PSB = m_affectedTool->isAffected(cluster, affCont, deta , dphi ,layer,layer,2) ; //deadHVPS
   if(checkNNHV_PSE || checkNNHV_PSB)      iflag |= ( 0x1 << xAOD::EgammaParameters::NonNominalHVPS); 
   if(checkDEADHV_PSE || checkDEADHV_PSB)  iflag |= ( 0x1 << xAOD::EgammaParameters::DeadHVPS);
 
@@ -357,9 +364,9 @@ StatusCode egammaOQFlagsBuilder::execute(const EventContext& ctx, xAOD::Egamma*
   //   dphi=0.;
   deta=0.5*0.025*3.;
   dphi=0.5*0.025*3.;
-  bool checkDEADHV_CORE_B = m_affectedTool->isAffected(cluster ,deta , dphi ,layer,layer,2) ; //deadHVPS
+  bool checkDEADHV_CORE_B = m_affectedTool->isAffected(cluster, affCont, deta , dphi ,layer,layer,2) ; //deadHVPS
   layer=CaloSampling::EME2;
-  bool checkDEADHV_CORE_E = m_affectedTool->isAffected(cluster ,deta , dphi ,layer,layer,2) ; //deadHVPS
+  bool checkDEADHV_CORE_E = m_affectedTool->isAffected(cluster, affCont, deta , dphi ,layer,layer,2) ; //deadHVPS
   if(checkDEADHV_CORE_B || checkDEADHV_CORE_E)  iflag |= ( 0x1 << xAOD::EgammaParameters::DeadHVS1S2S3Core); 
 
   //----------------> SAMPLINGS 1,2,3 : CLUSTER EDGE
@@ -367,28 +374,28 @@ StatusCode egammaOQFlagsBuilder::execute(const EventContext& ctx, xAOD::Egamma*
   dphi=0.5*0.025*phiSize;
   layer=CaloSampling::EMB1;
 
-  bool checkNNHV_EMB1   = m_affectedTool->isAffected(cluster ,deta , dphi ,layer,layer,1) ; //nnHVPS
-  bool checkDEADHV_EMB1 = m_affectedTool->isAffected(cluster ,deta , dphi ,layer,layer,2) ; //deadHVPS
+  bool checkNNHV_EMB1   = m_affectedTool->isAffected(cluster, affCont, deta , dphi ,layer,layer,1) ; //nnHVPS
+  bool checkDEADHV_EMB1 = m_affectedTool->isAffected(cluster, affCont, deta , dphi ,layer,layer,2) ; //deadHVPS
   layer=CaloSampling::EMB2;
 
-  bool checkNNHV_EMB2   = m_affectedTool->isAffected(cluster ,deta , dphi ,layer,layer,1) ; //nnHVPS
-  bool checkDEADHV_EMB2 = m_affectedTool->isAffected(cluster ,deta , dphi ,layer,layer,2) ; //deadHVPS
+  bool checkNNHV_EMB2   = m_affectedTool->isAffected(cluster, affCont, deta , dphi ,layer,layer,1) ; //nnHVPS
+  bool checkDEADHV_EMB2 = m_affectedTool->isAffected(cluster, affCont, deta , dphi ,layer,layer,2) ; //deadHVPS
   layer=CaloSampling::EMB3;
 
-  bool checkNNHV_EMB3   = m_affectedTool->isAffected(cluster ,deta , dphi ,layer,layer,1) ; //nnHVPS
-  bool checkDEADHV_EMB3 = m_affectedTool->isAffected(cluster ,deta , dphi ,layer,layer,2) ; //deadHVPS
+  bool checkNNHV_EMB3   = m_affectedTool->isAffected(cluster, affCont, deta , dphi ,layer,layer,1) ; //nnHVPS
+  bool checkDEADHV_EMB3 = m_affectedTool->isAffected(cluster, affCont, deta , dphi ,layer,layer,2) ; //deadHVPS
   layer=CaloSampling::EME1;
 
-  bool checkNNHV_EME1   = m_affectedTool->isAffected(cluster ,deta , dphi ,layer,layer,1) ; //nnHVPS
-  bool checkDEADHV_EME1 = m_affectedTool->isAffected(cluster ,deta , dphi ,layer,layer,2) ; //deadHVPS
+  bool checkNNHV_EME1   = m_affectedTool->isAffected(cluster, affCont, deta , dphi ,layer,layer,1) ; //nnHVPS
+  bool checkDEADHV_EME1 = m_affectedTool->isAffected(cluster, affCont, deta , dphi ,layer,layer,2) ; //deadHVPS
   layer=CaloSampling::EME2;
 
-  bool checkNNHV_EME2   = m_affectedTool->isAffected(cluster ,deta , dphi ,layer,layer,1) ; //nnHVPS
-  bool checkDEADHV_EME2 = m_affectedTool->isAffected(cluster ,deta , dphi ,layer,layer,2) ; //deadHVPS
+  bool checkNNHV_EME2   = m_affectedTool->isAffected(cluster, affCont, deta , dphi ,layer,layer,1) ; //nnHVPS
+  bool checkDEADHV_EME2 = m_affectedTool->isAffected(cluster, affCont, deta , dphi ,layer,layer,2) ; //deadHVPS
   layer=CaloSampling::EME3;
 
-  bool checkNNHV_EME3   = m_affectedTool->isAffected(cluster ,deta , dphi ,layer,layer,1) ; //nnHVPS
-  bool checkDEADHV_EME3 = m_affectedTool->isAffected(cluster ,deta , dphi ,layer,layer,2) ; //deadHVPS
+  bool checkNNHV_EME3   = m_affectedTool->isAffected(cluster, affCont, deta , dphi ,layer,layer,1) ; //nnHVPS
+  bool checkDEADHV_EME3 = m_affectedTool->isAffected(cluster, affCont, deta , dphi ,layer,layer,2) ; //deadHVPS
   if(checkNNHV_EMB1 || checkNNHV_EME1 || checkNNHV_EMB2 || checkNNHV_EME2 ||checkNNHV_EMB3 || checkNNHV_EME3) 
     iflag |= ( 0x1 << xAOD::EgammaParameters::NonNominalHVS1S2S3); 
   if(checkDEADHV_EMB1 || checkDEADHV_EME1 || checkDEADHV_EMB2 || checkDEADHV_EME2 ||checkDEADHV_EMB3 || checkDEADHV_EME3)  
diff --git a/Reconstruction/egamma/egammaTools/src/egammaOQFlagsBuilder.h b/Reconstruction/egamma/egammaTools/src/egammaOQFlagsBuilder.h
index 08717f5267d839a1cdf20a3ded7f1d9ffdb3d797..5b18402a53684a859c823c0b68eb22d1d81075c1 100644
--- a/Reconstruction/egamma/egammaTools/src/egammaOQFlagsBuilder.h
+++ b/Reconstruction/egamma/egammaTools/src/egammaOQFlagsBuilder.h
@@ -59,14 +59,16 @@ class egammaOQFlagsBuilder : public egammaBaseTool
  private:
   /** Handle to bad-channel CDO */
   SG::ReadCondHandleKey<LArBadChannelCont> m_bcContKey{this,
-      "LArBadChannelKey","LArBadChannel","Key of the LArBadChannelCont CDO"};
+      "LArBadChannelKey", "LArBadChannel", "Key of the LArBadChannelCont CDO"};
   
+  SG::ReadCondHandleKey<CaloAffectedRegionInfoVec> m_affKey{this,
+      "LArAffectedRegionKey", "LArAffectedRegionInfo", "SG key for affected regions cond object"};
+
   ToolHandle<ICaloAffectedTool> m_affectedTool {this,
       "affectedTool", "CaloAffectedTool", "CaloAffectedTool"};
 
   const LArEM_ID* m_emHelper;
   const CaloCell_ID* m_calocellId;
-  const CaloAffectedRegionInfoVec* m_affRegVec;
 
   SG::ReadHandleKey<CaloCellContainer> m_cellsKey {this,
       "CellsName", "AllCalo","Names of container which contain cells"};