From a3d236176435572f2c5511cb7296c2d9727e34a5 Mon Sep 17 00:00:00 2001
From: Oleg Kuprash <oleg.kuprash@cern.ch>
Date: Fri, 10 Nov 2017 14:52:38 +0100
Subject: [PATCH] Revert "Merge branch 'dynamic-alignment-folders-setup' into
 '21.1'
"

This reverts commit e224cd395dd2efc928d9dc3ace5682093566c36d [formerly 8d265faa6dd76bcd6f190b8d915fc86871f16971], reversing
changes made to 15c70bf5e4a4e2167eb9870121ad928a86b28aa5 [formerly 1d2c0dcdd566cdb4a0dbf1da1df7f79bf8e83fe5].


Former-commit-id: 198281ee7e37a0314aab8a6822c58d84f55975bd
---
 .../GeoModel/AtlasGeoModel/python/InDetGM.py  |   6 --
 .../python/InDetGMJobProperties.py            |   8 --
 .../python/InDetAlignFolders.py               |  12 ++-
 .../PixelGeoModel/PixelDetectorFactory.h      |   5 +-
 .../PixelGeoModel/PixelDetectorTool.h         |   1 -
 .../PixelGeoModel/PixelSwitches.h             |   6 --
 .../src/PixelDetectorFactory.cxx              |  41 +++++--
 .../PixelGeoModel/src/PixelDetectorTool.cxx   |   7 +-
 .../PixelGeoModel/src/PixelSwitches.cxx       |   5 +-
 .../SCT_GeoModel/SCT_DetectorFactory.h        |   4 +-
 .../SCT_GeoModel/SCT_DetectorTool.h           |   1 -
 .../SCT_GeoModel/SCT_GeoModel/SCT_Options.h   |   5 +-
 .../SCT_GeoModel/src/SCT_DetectorFactory.cxx  |  45 +++++---
 .../SCT_GeoModel/src/SCT_DetectorTool.cxx     |   8 +-
 .../SCT_GeoModel/src/SCT_Options.cxx          |  12 +--
 .../TRT_GeoModel/TRTDetectorFactory_Full.h    |   6 +-
 .../TRT_GeoModel/TRT_DetectorTool.h           |   1 -
 .../src/TRTDetectorFactory_Full.cxx           |  43 ++++++--
 .../TRT_GeoModel/src/TRT_DetectorTool.cxx     | 102 +++++++++---------
 .../python/InDetJobProperties.py              |  11 +-
 20 files changed, 181 insertions(+), 148 deletions(-)

diff --git a/DetectorDescription/GeoModel/AtlasGeoModel/python/InDetGM.py b/DetectorDescription/GeoModel/AtlasGeoModel/python/InDetGM.py
index f4a051c12f2..dbbaa823415 100755
--- a/DetectorDescription/GeoModel/AtlasGeoModel/python/InDetGM.py
+++ b/DetectorDescription/GeoModel/AtlasGeoModel/python/InDetGM.py
@@ -47,10 +47,7 @@ elif ( DetFlags.detdescr.ID_on() ):
             ToolSvc += blmTool
             GeoModelSvc.DetectorTools['PixelDetectorTool'].BLM_Tool = blmTool
 
-        GeoModelSvc.DetectorTools['PixelDetectorTool'].useDynamicAlignFolders = GeometryFlags.useDynamicAlignFolders()
-
     if ( DetFlags.detdescr.SCT_on() ):
-
         if GeometryFlags.isSLHC():
             #SLHC specific code
             if "GMX" == GeometryFlags.StripGeoType():
@@ -73,15 +70,12 @@ elif ( DetFlags.detdescr.ID_on() ):
             from AthenaCommon import CfgGetter
             GeoModelSvc.DetectorTools += [ CfgGetter.getPrivateTool("SCT_DetectorTool", checkType=True) ]
 
-        GeoModelSvc.DetectorTools['SCT_DetectorTool'].useDynamicAlignFolders = GeometryFlags.useDynamicAlignFolders()
-
     if ( DetFlags.detdescr.TRT_on() ):
         from TRT_GeoModel.TRT_GeoModelConf import TRT_DetectorTool
         trtDetectorTool = TRT_DetectorTool()
         if ( DetFlags.simulate.TRT_on() ):
             trtDetectorTool.DoXenonArgonMixture = True
             trtDetectorTool.DoKryptonMixture = True
-        trtDetectorTool.useDynamicAlignFolders = GeometryFlags.useDynamicAlignFolders()
         GeoModelSvc.DetectorTools += [ trtDetectorTool ]
 
     from InDetServMatGeoModel.InDetServMatGeoModelConf import InDetServMatTool
diff --git a/DetectorDescription/GeoModel/AtlasGeoModel/python/InDetGMJobProperties.py b/DetectorDescription/GeoModel/AtlasGeoModel/python/InDetGMJobProperties.py
index 610794a2e87..eff1ea5eecd 100755
--- a/DetectorDescription/GeoModel/AtlasGeoModel/python/InDetGMJobProperties.py
+++ b/DetectorDescription/GeoModel/AtlasGeoModel/python/InDetGMJobProperties.py
@@ -191,13 +191,6 @@ class StripGeoType(JobProperty):
      allowedTypes = ['str']
      StoredValue  = "UNDEFINED"
 
-class useDynamicAlignFolders(JobProperty):
-    """ Use to turn on dynamic alignment constants folder scheme (first deployed in 2016) """
-    statusOn     = True
-    allowedTypes = ['bool']
-    StoredValue  = False
-
-
 
 # add to jobproperties
 class GeometryFlags_JobProperties(JobPropertyContainer):
@@ -259,7 +252,6 @@ jobproperties.GeometryFlags_JobProperties.add_JobProperty(isDBM)
 jobproperties.GeometryFlags_JobProperties.add_JobProperty(Run)
 jobproperties.GeometryFlags_JobProperties.add_JobProperty(GeoType)
 jobproperties.GeometryFlags_JobProperties.add_JobProperty(StripGeoType)
-jobproperties.GeometryFlags_JobProperties.add_JobProperty(useDynamicAlignFolders)
 
 GeometryFlags = jobproperties.GeometryFlags_JobProperties
 GeometryFlags.setupValuesFromDB()
diff --git a/InnerDetector/InDetConditions/InDetCondFolders/python/InDetAlignFolders.py b/InnerDetector/InDetConditions/InDetCondFolders/python/InDetAlignFolders.py
index b8fd140b9a8..01056a88de0 100644
--- a/InnerDetector/InDetConditions/InDetCondFolders/python/InDetAlignFolders.py
+++ b/InnerDetector/InDetConditions/InDetCondFolders/python/InDetAlignFolders.py
@@ -17,9 +17,14 @@ conddb.addFolderSplitOnline("INDET","/Indet/Onl/IBLDist","/Indet/IBLDist")
 # Adding protection against new dynamic folder scheme;
 # In future we might want to add also to MC DB
 # Solution below is not pretty but in response to JIRA ATLASSIM-2746
-
-from AtlasGeoModel.InDetGMJobProperties import GeometryFlags as geoFlags
-if geoFlags.useDynamicAlignFolders():
+useDynamicAlignFolders = False
+try:
+    from InDetRecExample.InDetJobProperties import InDetFlags
+    if InDetFlags.useDynamicAlignFolders and conddb.dbdata == "CONDBR2":
+        useDynamicAlignFolders = True
+except ImportError:
+    pass
+if useDynamicAlignFolders:
     conddb.addFolderSplitOnline("INDET","/Indet/Onl/AlignL1/ID","/Indet/AlignL1/ID")
     conddb.addFolderSplitOnline("INDET","/Indet/Onl/AlignL2/PIX","/Indet/AlignL2/PIX")
     conddb.addFolderSplitOnline("INDET","/Indet/Onl/AlignL2/SCT","/Indet/AlignL2/SCT")
@@ -29,3 +34,4 @@ if geoFlags.useDynamicAlignFolders():
 else:
     conddb.addFolderSplitOnline("INDET","/Indet/Onl/Align","/Indet/Align")
     conddb.addFolderSplitOnline("TRT","/TRT/Onl/Align","/TRT/Align")
+del useDynamicAlignFolders #tidy up
diff --git a/InnerDetector/InDetDetDescr/PixelGeoModel/PixelGeoModel/PixelDetectorFactory.h b/InnerDetector/InDetDetDescr/PixelGeoModel/PixelGeoModel/PixelDetectorFactory.h
index cbdc029d95f..bec4be43cf1 100644
--- a/InnerDetector/InDetDetDescr/PixelGeoModel/PixelGeoModel/PixelDetectorFactory.h
+++ b/InnerDetector/InDetDetDescr/PixelGeoModel/PixelGeoModel/PixelDetectorFactory.h
@@ -32,6 +32,8 @@ class PixelDetectorFactory : public InDetDD::DetectorFactoryBase {
   // Access to the results:
   virtual const InDetDD::PixelDetectorManager * getDetectorManager() const;
 
+  // Determine which alignment folders are loaded to decide if we register old or new folders
+  virtual InDetDD::AlignFolderType getAlignFolderType() const;
 
  private:  
   
@@ -43,9 +45,6 @@ class PixelDetectorFactory : public InDetDD::DetectorFactoryBase {
   PixelGeometryManager * m_geometryManager;
 
   void doChecks();
-
-private:
-  bool m_useDynamicAlignFolders;
   
 };
 
diff --git a/InnerDetector/InDetDetDescr/PixelGeoModel/PixelGeoModel/PixelDetectorTool.h b/InnerDetector/InDetDetDescr/PixelGeoModel/PixelGeoModel/PixelDetectorTool.h
index 28e8fa98d30..ce6918b56ea 100644
--- a/InnerDetector/InDetDetDescr/PixelGeoModel/PixelGeoModel/PixelDetectorTool.h
+++ b/InnerDetector/InDetDetDescr/PixelGeoModel/PixelGeoModel/PixelDetectorTool.h
@@ -52,7 +52,6 @@ private:
   bool m_initialLayout;
   bool m_devVersion;
   bool m_buildDBM;
-  bool m_useDynamicAlignFolders;
   ToolHandle< IGeoSubDetTool > m_bcmTool;
   ToolHandle< IGeoSubDetTool > m_blmTool;
   ToolHandle< IInDetServMatBuilderTool > m_serviceBuilderTool;
diff --git a/InnerDetector/InDetDetDescr/PixelGeoModel/PixelGeoModel/PixelSwitches.h b/InnerDetector/InDetDetDescr/PixelGeoModel/PixelGeoModel/PixelSwitches.h
index 27f2119debd..68eadf25111 100644
--- a/InnerDetector/InDetDetDescr/PixelGeoModel/PixelGeoModel/PixelSwitches.h
+++ b/InnerDetector/InDetDetDescr/PixelGeoModel/PixelGeoModel/PixelSwitches.h
@@ -51,10 +51,6 @@ public:
   void setDBM(bool flag = false);
   bool dbm() const;
 
-  //dynamic alignment folders
-  void setDynamicAlignFolders(const bool useDynAlignFolders);
-  bool dynamicAlignFolders() const;
-
 private:
 
   // flag to build also the services
@@ -84,8 +80,6 @@ private:
   // DBM
   bool m_dbm;
 
-  //controls which set of alignment folders is used
-  bool m_dynAlignFolders;
 };
 
 #endif // PixelSwitches_H
diff --git a/InnerDetector/InDetDetDescr/PixelGeoModel/src/PixelDetectorFactory.cxx b/InnerDetector/InDetDetDescr/PixelGeoModel/src/PixelDetectorFactory.cxx
index ad94ef9e327..8579934f433 100644
--- a/InnerDetector/InDetDetDescr/PixelGeoModel/src/PixelDetectorFactory.cxx
+++ b/InnerDetector/InDetDetDescr/PixelGeoModel/src/PixelDetectorFactory.cxx
@@ -34,8 +34,7 @@ using InDetDD::SiCommonItems;
 PixelDetectorFactory::PixelDetectorFactory(const PixelGeoModelAthenaComps * athenaComps,
 					   const PixelSwitches & switches)
   : InDetDD::DetectorFactoryBase(athenaComps),
-    m_detectorManager(0),
-    m_useDynamicAlignFolders(false)
+    m_detectorManager(0)
 {
   // Create the detector manager
   m_detectorManager = new PixelDetectorManager(detStore());
@@ -98,8 +97,6 @@ PixelDetectorFactory::PixelDetectorFactory(const PixelGeoModelAthenaComps * athe
 			   versionPatchNumber);
   m_detectorManager->setVersion(version);
 
-  m_useDynamicAlignFolders = switches.dynamicAlignFolders();
-
 }
 
 
@@ -165,8 +162,10 @@ void PixelDetectorFactory::create(GeoPhysVol *world)
   // Register the callbacks and keys and the level corresponding to the key.
   if (m_geometryManager->Alignable()) {
 
-    if (!m_useDynamicAlignFolders){
-      m_detectorManager->addAlignFolderType(InDetDD::static_run1);
+    InDetDD::AlignFolderType AlignFolder = getAlignFolderType();
+    m_detectorManager->addAlignFolderType(AlignFolder);
+
+    if (AlignFolder==InDetDD::static_run1){
       m_detectorManager->addFolder("/Indet/Align");
       m_detectorManager->addChannel("/Indet/Align/ID",     2, InDetDD::global);
       m_detectorManager->addChannel("/Indet/Align/PIX",    1, InDetDD::global);
@@ -182,8 +181,7 @@ void PixelDetectorFactory::create(GeoPhysVol *world)
       m_detectorManager->addChannel("/Indet/Align/PIXEC3", 0, InDetDD::local);
     }
     
-    else {
-      m_detectorManager->addAlignFolderType(InDetDD::timedependent_run2);
+    if (AlignFolder==InDetDD::timedependent_run2){
       m_detectorManager->addGlobalFolder("/Indet/AlignL1/ID");
       m_detectorManager->addGlobalFolder("/Indet/AlignL2/PIX");
       m_detectorManager->addChannel("/Indet/AlignL1/ID",     2, InDetDD::global);
@@ -368,4 +366,31 @@ PixelDetectorFactory::doChecks()
 
 }
 
+// Determine which alignment folders are loaded to decide if we register old or new folders
+InDetDD::AlignFolderType PixelDetectorFactory::getAlignFolderType() const
+{
+
+  bool static_folderStruct = false;
+  bool timedep_folderStruct = false;
+  if (detStore()->contains<CondAttrListCollection>("/Indet/AlignL1/ID") &&
+      detStore()->contains<CondAttrListCollection>("/Indet/AlignL2/PIX") &&
+      detStore()->contains<AlignableTransformContainer>("/Indet/AlignL3") ) timedep_folderStruct = true;
+
+  if (detStore()->contains<AlignableTransformContainer>("/Indet/Align") ) static_folderStruct = true;
+
+  if (static_folderStruct && !timedep_folderStruct){
+    msg(MSG::INFO) << " Static run1 type alignment folder structure found" << endmsg; 
+    return InDetDD::static_run1;
+  }
+  else if (!static_folderStruct && timedep_folderStruct){
+    msg(MSG::INFO) << " Time dependent run2 type alignment folder structure found" << endmsg;
+    return InDetDD::timedependent_run2;
+  }
+  else if (static_folderStruct && timedep_folderStruct){
+    throw std::runtime_error("Old and new alignment folders are loaded at the same time! This should not happen!");    
+  }
+  else return InDetDD::none;
+
+}
+
 
diff --git a/InnerDetector/InDetDetDescr/PixelGeoModel/src/PixelDetectorTool.cxx b/InnerDetector/InDetDetDescr/PixelGeoModel/src/PixelDetectorTool.cxx
index be6a7ee9b21..3aff1ba7c39 100644
--- a/InnerDetector/InDetDetDescr/PixelGeoModel/src/PixelDetectorTool.cxx
+++ b/InnerDetector/InDetDetDescr/PixelGeoModel/src/PixelDetectorTool.cxx
@@ -42,7 +42,6 @@ PixelDetectorTool::PixelDetectorTool( const std::string& type, const std::string
     m_detectorName("PixelDetector"),
     m_IBLParameterSvc("IBLParameterSvc",name),
     m_buildDBM(0),
-    m_useDynamicAlignFolders(false),
     m_bcmTool(""),
     m_blmTool(""),
     m_serviceBuilderTool(""),
@@ -68,7 +67,6 @@ PixelDetectorTool::PixelDetectorTool( const std::string& type, const std::string
   declareProperty("GeoModelSvc", m_geoModelSvc);
   declareProperty("LorentzAngleSvc", m_lorentzAngleSvc);
   declareProperty("OverrideVersionName", m_overrideVersionName);
-  declareProperty("useDynamicAlignFolders", m_useDynamicAlignFolders);
 }
 /**
  ** Destructor
@@ -200,7 +198,6 @@ StatusCode PixelDetectorTool::create( StoreGateSvc* detStore )
     if (versionName == "SLHC") switches.setSLHC();
     if (versionName == "IBL") switches.setIBL();
     switches.setDBM(m_buildDBM); //DBM flag
-    switches.setDynamicAlignFolders(m_useDynamicAlignFolders);
 
     //JBdV
     switches.setServicesOnLadder(m_servicesOnLadder);
@@ -386,7 +383,7 @@ PixelDetectorTool::registerCallback( StoreGateSvc* detStore)
   StatusCode sc = StatusCode::FAILURE;
   if (m_alignable) {
 
-    if (m_useDynamicAlignFolders) {  
+    {  
       std::string folderName = "/Indet/AlignL1/ID";
       if (detStore->contains<CondAttrListCollection>(folderName)) {
 	msg(MSG::DEBUG) << "Registering callback on global Container with folder " << folderName << endmsg;
@@ -438,7 +435,7 @@ PixelDetectorTool::registerCallback( StoreGateSvc* detStore)
     }
 
     
-    else {
+    {
       std::string folderName = "/Indet/Align";
       if (detStore->contains<AlignableTransformContainer>(folderName)) {
 	if(msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << "Registering callback on AlignableTransformContainer with folder " << folderName << endmsg;
diff --git a/InnerDetector/InDetDetDescr/PixelGeoModel/src/PixelSwitches.cxx b/InnerDetector/InDetDetDescr/PixelGeoModel/src/PixelSwitches.cxx
index 7de1740d43e..fd244ad0111 100644
--- a/InnerDetector/InDetDetDescr/PixelGeoModel/src/PixelSwitches.cxx
+++ b/InnerDetector/InDetDetDescr/PixelGeoModel/src/PixelSwitches.cxx
@@ -13,8 +13,7 @@ PixelSwitches::PixelSwitches()
     m_alignable(true),
     m_slhc(false),
     m_ibl(false),
-    m_dbm(false),
-    m_dynAlignFolders(false)
+    m_dbm(false)
 {}
 
 void PixelSwitches::setServices(bool flag) {m_services = flag;}
@@ -47,5 +46,3 @@ bool PixelSwitches::ibl() const {return m_ibl;}
 void PixelSwitches::setDBM(bool flag) {m_dbm = flag;} //switch to build the DBM
 bool PixelSwitches::dbm() const {return m_dbm;}
 
-void PixelSwitches::setDynamicAlignFolders(const bool useDynAlignFolders){m_dynAlignFolders = useDynAlignFolders;}
-bool PixelSwitches::dynamicAlignFolders() const {  return m_dynAlignFolders;}
diff --git a/InnerDetector/InDetDetDescr/SCT_GeoModel/SCT_GeoModel/SCT_DetectorFactory.h b/InnerDetector/InDetDetDescr/SCT_GeoModel/SCT_GeoModel/SCT_DetectorFactory.h
index 822cea24a08..634c767f635 100755
--- a/InnerDetector/InDetDetDescr/SCT_GeoModel/SCT_GeoModel/SCT_DetectorFactory.h
+++ b/InnerDetector/InDetDetDescr/SCT_GeoModel/SCT_GeoModel/SCT_DetectorFactory.h
@@ -31,6 +31,9 @@ class SCT_DetectorFactory : public InDetDD::DetectorFactoryBase
   // Access to the results: 
   virtual const InDetDD::SCT_DetectorManager * getDetectorManager() const; 
 
+  // Determine which alignment folders are loaded to decide if we register old or new folders
+  virtual InDetDD::AlignFolderType getAlignFolderType() const;
+
  private: 
   // Copy and assignments operations illegal and so are made private
   SCT_DetectorFactory(const SCT_DetectorFactory &right); 
@@ -38,7 +41,6 @@ class SCT_DetectorFactory : public InDetDD::DetectorFactoryBase
 
   InDetDD::SCT_DetectorManager *m_detectorManager;
   SCT_GeometryManager *m_geometryManager;
-  bool m_useDynamicAlignFolders;
 
 }; 
  
diff --git a/InnerDetector/InDetDetDescr/SCT_GeoModel/SCT_GeoModel/SCT_DetectorTool.h b/InnerDetector/InDetDetDescr/SCT_GeoModel/SCT_GeoModel/SCT_DetectorTool.h
index 3d7db762dc4..503354587f7 100755
--- a/InnerDetector/InDetDetDescr/SCT_GeoModel/SCT_GeoModel/SCT_DetectorTool.h
+++ b/InnerDetector/InDetDetDescr/SCT_GeoModel/SCT_GeoModel/SCT_DetectorTool.h
@@ -45,7 +45,6 @@ private:
   bool m_initialLayout;
   bool m_alignable;
   bool m_cosmic;
-  bool m_useDynamicAlignFolders;
   
   const InDetDD::SCT_DetectorManager * m_manager;
   
diff --git a/InnerDetector/InDetDetDescr/SCT_GeoModel/SCT_GeoModel/SCT_Options.h b/InnerDetector/InDetDetDescr/SCT_GeoModel/SCT_GeoModel/SCT_Options.h
index fd79a564969..e20e1900bc6 100755
--- a/InnerDetector/InDetDetDescr/SCT_GeoModel/SCT_GeoModel/SCT_Options.h
+++ b/InnerDetector/InDetDetDescr/SCT_GeoModel/SCT_GeoModel/SCT_Options.h
@@ -25,9 +25,6 @@ public:
   void setAlignable(bool flag = true);
   void setAlignAtModuleLevel(bool flag = true);
 
-  //dynamic alignment folders
-  void setDynamicAlignFolders(const bool flag = true);
-  bool dynamicAlignFolders() const;
 
 private:
 
@@ -36,7 +33,7 @@ private:
   bool m_dc2Geometry;
   bool m_alignable;
   bool m_alignModule;
-  bool m_dynAlignFolders;   //controls which set of alignment folders is used
+
 
 };
 
diff --git a/InnerDetector/InDetDetDescr/SCT_GeoModel/src/SCT_DetectorFactory.cxx b/InnerDetector/InDetDetDescr/SCT_GeoModel/src/SCT_DetectorFactory.cxx
index 26b5b37ea82..226f75905bb 100755
--- a/InnerDetector/InDetDetDescr/SCT_GeoModel/src/SCT_DetectorFactory.cxx
+++ b/InnerDetector/InDetDetDescr/SCT_GeoModel/src/SCT_DetectorFactory.cxx
@@ -63,8 +63,7 @@ using InDetDD::SiCommonItems;
 
 SCT_DetectorFactory::SCT_DetectorFactory(const SCT_GeoModelAthenaComps * athenaComps,
 					 const SCT_Options & options)
-  : InDetDD::DetectorFactoryBase(athenaComps),
-    m_useDynamicAlignFolders(false)
+  : InDetDD::DetectorFactoryBase(athenaComps) 
 { 
   
   // Create the detector manager
@@ -77,8 +76,6 @@ SCT_DetectorFactory::SCT_DetectorFactory(const SCT_GeoModelAthenaComps * athenaC
   m_geometryManager = new SCT_GeometryManager();
   m_geometryManager->setOptions(options);
   m_geometryManager->setAthenaComps(athenaComps);
-
-  m_useDynamicAlignFolders = options.dynamicAlignFolders();
  
   // Pass the Athena components the data base access class
   SCT_DataBase::setAthenaComps(athenaComps);
@@ -277,15 +274,14 @@ void SCT_DetectorFactory::create(GeoPhysVol *world)
   // Register the keys and the level corresponding to the key
   // and whether it expects a global or local shift.
   // level 0: sensor, level 1: module, level 2, layer/disc, level 3: whole barrel/enccap
+  InDetDD::AlignFolderType AlignFolder = getAlignFolderType();
+  m_detectorManager->addAlignFolderType(AlignFolder);
 
-
-  if (!m_useDynamicAlignFolders){
-
-    m_detectorManager->addAlignFolderType(InDetDD::static_run1);
+  if (AlignFolder==InDetDD::static_run1){
     m_detectorManager->addFolder("/Indet/Align");
     m_detectorManager->addChannel("/Indet/Align/ID",3,InDetDD::global);
     m_detectorManager->addChannel("/Indet/Align/SCT",2,InDetDD::global);
-    
+  
     if (barrelPresent) {
       m_detectorManager->addChannel("/Indet/Align/SCTB1",1,InDetDD::local);
       m_detectorManager->addChannel("/Indet/Align/SCTB2",1,InDetDD::local);
@@ -315,9 +311,8 @@ void SCT_DetectorFactory::create(GeoPhysVol *world)
       m_detectorManager->addChannel("/Indet/Align/SCTEC9",1,InDetDD::local);
     }
   }
-  
-  else {
-    m_detectorManager->addAlignFolderType(InDetDD::timedependent_run2);
+
+  if (AlignFolder==InDetDD::timedependent_run2){
     m_detectorManager->addGlobalFolder("/Indet/AlignL1/ID");
     m_detectorManager->addGlobalFolder("/Indet/AlignL2/SCT");
     m_detectorManager->addChannel("/Indet/AlignL1/ID",3,InDetDD::global);
@@ -366,3 +361,29 @@ const SCT_DetectorManager * SCT_DetectorFactory::getDetectorManager() const
 }
  
 
+// Determine which alignment folders are loaded to decide if we register old or new folders                                         
+InDetDD::AlignFolderType SCT_DetectorFactory::getAlignFolderType() const
+{
+
+  bool static_folderStruct = false;
+  bool timedep_folderStruct = false;
+  if (detStore()->contains<CondAttrListCollection>("/Indet/AlignL1/ID") &&
+      detStore()->contains<CondAttrListCollection>("/Indet/AlignL2/SCT") &&
+      detStore()->contains<AlignableTransformContainer>("/Indet/AlignL3") ) timedep_folderStruct = true;
+
+  if (detStore()->contains<AlignableTransformContainer>("/Indet/Align") ) static_folderStruct = true;
+
+  if (static_folderStruct && !timedep_folderStruct){
+    msg(MSG::INFO) << " Static run1 type alignment folder structure found" << endreq;
+    return InDetDD::static_run1;
+  }
+  else if (!static_folderStruct && timedep_folderStruct){
+    msg(MSG::INFO) << " Time dependent run2 type alignment folder structure found" << endreq;
+    return InDetDD::timedependent_run2;
+  }
+  else if (static_folderStruct && timedep_folderStruct){
+    throw std::runtime_error("Old and new alignment folders are loaded at the same time! This should not happen!");
+  }
+  else return InDetDD::none;
+
+}
diff --git a/InnerDetector/InDetDetDescr/SCT_GeoModel/src/SCT_DetectorTool.cxx b/InnerDetector/InDetDetDescr/SCT_GeoModel/src/SCT_DetectorTool.cxx
index 8eb23959723..3153d98a206 100755
--- a/InnerDetector/InDetDetDescr/SCT_GeoModel/src/SCT_DetectorTool.cxx
+++ b/InnerDetector/InDetDetDescr/SCT_GeoModel/src/SCT_DetectorTool.cxx
@@ -42,7 +42,6 @@ SCT_DetectorTool::SCT_DetectorTool( const std::string& type,
     m_initialLayout(false),
     m_alignable(true),
     m_cosmic(false),
-    m_useDynamicAlignFolders(false),
     m_manager(0), 
     m_athenaComps(0),
     m_geoModelSvc("GeoModelSvc",name),
@@ -59,7 +58,6 @@ SCT_DetectorTool::SCT_DetectorTool( const std::string& type,
   declareProperty("GeometryDBSvc", m_geometryDBSvc);
   declareProperty("GeoModelSvc", m_geoModelSvc);
   declareProperty("LorentzAngleSvc", m_lorentzAngleSvc);
-  declareProperty("useDynamicAlignFolders", m_useDynamicAlignFolders);
 }
 
 //
@@ -173,7 +171,7 @@ SCT_DetectorTool::create( StoreGateSvc* detStore )
       SCT_Options options;
       
       options.setAlignable(m_alignable);
-      options.setDynamicAlignFolders(m_useDynamicAlignFolders);
+      
       
       m_manager = 0;
 
@@ -298,7 +296,7 @@ SCT_DetectorTool::registerCallback( StoreGateSvc* detStore)
   StatusCode sc = StatusCode::FAILURE;
   if (m_alignable) {
 
-    if (m_useDynamicAlignFolders) {
+    {
       std::string folderName = "/Indet/AlignL1/ID";
       if (detStore->contains<CondAttrListCollection>(folderName)) {
 	msg(MSG::DEBUG) << "Registering callback on global Container with folder " << folderName << endreq;
@@ -350,7 +348,7 @@ SCT_DetectorTool::registerCallback( StoreGateSvc* detStore)
     }
 
 
-    else {
+    {
       std::string folderName = "/Indet/Align";
       if (detStore->contains<AlignableTransformContainer>(folderName)) {
 	if(msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << "Registering callback on AlignableTransformContainer with folder " << folderName << endreq;
diff --git a/InnerDetector/InDetDetDescr/SCT_GeoModel/src/SCT_Options.cxx b/InnerDetector/InDetDetDescr/SCT_GeoModel/src/SCT_Options.cxx
index 6b7119b2b16..a8a7557952a 100644
--- a/InnerDetector/InDetDetDescr/SCT_GeoModel/src/SCT_Options.cxx
+++ b/InnerDetector/InDetDetDescr/SCT_GeoModel/src/SCT_Options.cxx
@@ -9,8 +9,7 @@ SCT_Options::SCT_Options()
     m_dc1Geometry(false),
     m_dc2Geometry(true),
     m_alignable(true),
-    m_alignModule(true),
-    m_dynAlignFolders(false)
+    m_alignModule(true)
 {}
 
 void 
@@ -77,12 +76,3 @@ SCT_Options::alignAtModuleLevel() const
   return m_alignModule;
 }
 
-void SCT_Options::setDynamicAlignFolders(const bool flag)
-{
-  m_dynAlignFolders = flag;
-}
-
-bool SCT_Options::dynamicAlignFolders() const 
-{  
-  return m_dynAlignFolders;
-}
diff --git a/InnerDetector/InDetDetDescr/TRT_GeoModel/TRT_GeoModel/TRTDetectorFactory_Full.h b/InnerDetector/InDetDetDescr/TRT_GeoModel/TRT_GeoModel/TRTDetectorFactory_Full.h
index dfc5d5326a4..8e3d09eadaa 100755
--- a/InnerDetector/InDetDetDescr/TRT_GeoModel/TRT_GeoModel/TRTDetectorFactory_Full.h
+++ b/InnerDetector/InDetDetDescr/TRT_GeoModel/TRT_GeoModel/TRTDetectorFactory_Full.h
@@ -44,8 +44,7 @@ class TRTDetectorFactory_Full : public InDetDD::DetectorFactoryBase  {
 			  int overridedigversion,                              //
 			  bool alignable,                                      //
 			  bool doArgon,                                        //
-			  bool doKrypton,                                      //
-			  bool useDynamicAlignmentFolders);                    //
+        bool doKrypton);                                     //
   //                                                                           //
   // Destructor:                                                               //
   ~TRTDetectorFactory_Full();                                                  //
@@ -63,6 +62,8 @@ class TRTDetectorFactory_Full : public InDetDD::DetectorFactoryBase  {
     return n;
   }
 
+  // Determine which alignment folders are loaded to decide if we register old or new folders
+  virtual InDetDD::AlignFolderType getAlignFolderType() const;
 
  private:  
 
@@ -104,7 +105,6 @@ class TRTDetectorFactory_Full : public InDetDD::DetectorFactoryBase  {
   bool m_strawsvcavailable;
   bool m_doArgon;
   bool m_doKrypton;
-  bool m_useDynamicAlignFolders;
 };
 
 #endif // TRTDetectorFactory_Full_h
diff --git a/InnerDetector/InDetDetDescr/TRT_GeoModel/TRT_GeoModel/TRT_DetectorTool.h b/InnerDetector/InDetDetDescr/TRT_GeoModel/TRT_GeoModel/TRT_DetectorTool.h
index 291ca80bcc0..658ad2cd888 100755
--- a/InnerDetector/InDetDetDescr/TRT_GeoModel/TRT_GeoModel/TRT_DetectorTool.h
+++ b/InnerDetector/InDetDetDescr/TRT_GeoModel/TRT_GeoModel/TRT_DetectorTool.h
@@ -58,7 +58,6 @@ public:
  
     bool m_doArgonMixture;
     bool m_doKryptonMixture;
-    bool m_useDynamicAlignFolders;
  
     const InDetDD::TRT_DetectorManager * m_manager;
     InDetDD::AthenaComps * m_athenaComps;
diff --git a/InnerDetector/InDetDetDescr/TRT_GeoModel/src/TRTDetectorFactory_Full.cxx b/InnerDetector/InDetDetDescr/TRT_GeoModel/src/TRTDetectorFactory_Full.cxx
index 9c00f02ef21..b0c95bf3736 100755
--- a/InnerDetector/InDetDetDescr/TRT_GeoModel/src/TRTDetectorFactory_Full.cxx
+++ b/InnerDetector/InDetDetDescr/TRT_GeoModel/src/TRTDetectorFactory_Full.cxx
@@ -69,8 +69,7 @@ TRTDetectorFactory_Full::TRTDetectorFactory_Full(const InDetDD::AthenaComps * at
 						 int overridedigversion,
 						 bool alignable,
 						 bool doArgon,
-						 bool doKrypton,
-						 bool useDynamicAlignmentFolders)
+             bool doKrypton)
   : InDetDD::DetectorFactoryBase(athenaComps), 
     m_detectorManager(0), 
     m_materialManager(0),
@@ -82,10 +81,9 @@ TRTDetectorFactory_Full::TRTDetectorFactory_Full(const InDetDD::AthenaComps * at
     m_sumSvc("TRT_StrawStatusSummarySvc","InDetTRTStrawStatusSummarySvc"),
     m_strawsvcavailable(0),
     m_doArgon(doArgon),
-    m_doKrypton(doKrypton),
-    m_useDynamicAlignFolders(useDynamicAlignmentFolders)
+    m_doKrypton(doKrypton)
 { 
-  m_sumSvc=m_summarySvc;
+m_sumSvc=m_summarySvc;
 }
 //////////////////////////////////////////////////////////////////////////////////
 
@@ -282,9 +280,10 @@ void TRTDetectorFactory_Full::create(GeoPhysVol *world)
   const int AlignmentLevelTop       = 3; // Level 1
 
   if (m_alignable) {
+    InDetDD::AlignFolderType AlignFolder = getAlignFolderType();
+    m_detectorManager->addAlignFolderType(AlignFolder);
 
-    if (!m_useDynamicAlignFolders){
-      m_detectorManager->addAlignFolderType(InDetDD::static_run1);
+    if (AlignFolder==InDetDD::static_run1){
       m_detectorManager->addFolder("/TRT/Align");
       m_detectorManager->addChannel("/TRT/Align/TRT", AlignmentLevelTop, InDetDD::global);
 
@@ -301,9 +300,7 @@ void TRTDetectorFactory_Full::create(GeoPhysVol *world)
       }
     }
 
-    else {
-      m_detectorManager->addAlignFolderType(InDetDD::timedependent_run2);
-
+    if (AlignFolder==InDetDD::timedependent_run2){
       m_detectorManager->addGlobalFolder("/TRT/AlignL1/TRT");
       m_detectorManager->addChannel("/TRT/AlignL1/TRT", AlignmentLevelTop, InDetDD::global);
       m_detectorManager->addFolder("/TRT/AlignL2");
@@ -2572,4 +2569,30 @@ TRTDetectorFactory_Full::ActiveGasMixture TRTDetectorFactory_Full::DecideGasMixt
   return return_agm; 
   }
 
+// Determine which alignment folders are loaded to decide if we register old or new folders    
+InDetDD::AlignFolderType TRTDetectorFactory_Full::getAlignFolderType() const
+{
+
+  bool static_folderStruct = false;
+  bool timedep_folderStruct = false;
+  if (detStore()->contains<CondAttrListCollection>("/TRT/AlignL1/TRT") &&
+      detStore()->contains<AlignableTransformContainer>("/TRT/AlignL2") ) timedep_folderStruct = true;
+
+  if (detStore()->contains<AlignableTransformContainer>("/TRT/Align") ) static_folderStruct = true;
+
+  if (static_folderStruct && !timedep_folderStruct){
+    msg(MSG::INFO) << " Static run1 type alignment folder structure found" << endreq;
+    return InDetDD::static_run1;
+  }
+  else if (!static_folderStruct && timedep_folderStruct){
+    msg(MSG::INFO) << " Time dependent run2 type alignment folder structure found" << endreq;
+    return InDetDD::timedependent_run2;
+  }
+  else if (static_folderStruct && timedep_folderStruct){
+    throw std::runtime_error("Old and new alignment folders are loaded at the same time! This should not happen!");
+  }
+  else return InDetDD::none;
+
+}
+
 //////////////////////////////////////////////////////////////////////////////////
diff --git a/InnerDetector/InDetDetDescr/TRT_GeoModel/src/TRT_DetectorTool.cxx b/InnerDetector/InDetDetDescr/TRT_GeoModel/src/TRT_DetectorTool.cxx
index ceeb7e22120..4aced09164c 100755
--- a/InnerDetector/InDetDetDescr/TRT_GeoModel/src/TRT_DetectorTool.cxx
+++ b/InnerDetector/InDetDetDescr/TRT_GeoModel/src/TRT_DetectorTool.cxx
@@ -38,7 +38,6 @@ TRT_DetectorTool::TRT_DetectorTool( const std::string& type, const std::string&
     m_sumSvc("TRT_StrawStatusSummarySvc", name),
     m_doArgonMixture(0),
     m_doKryptonMixture(0),
-    m_useDynamicAlignFolders(false),
     m_manager(0),
     m_athenaComps(0)
 {
@@ -52,8 +51,6 @@ TRT_DetectorTool::TRT_DetectorTool( const std::string& type, const std::string&
   declareProperty("InDetTRTStrawStatusSummarySvc", m_sumSvc);  // need for Argon
   declareProperty("DoXenonArgonMixture", m_doArgonMixture); // Set to 1 to use argon. DEFAULT VALUE is 0. Overridden by DOARGONMIXTURE switch
   declareProperty("DoKryptonMixture", m_doKryptonMixture); // Set to 1 to use krypton. DEFAULT VALUE is 0. Overridden by DOKRYPTONMIXTURE switch
-  declareProperty("useDynamicAlignFolders", m_useDynamicAlignFolders);
-
 }
 
 
@@ -212,8 +209,7 @@ StatusCode TRT_DetectorTool::create( StoreGateSvc* detStore )
 					  m_overridedigversion,
 					  m_alignable,
 					  m_doArgonMixture,
-					  m_doKryptonMixture,
-					  m_useDynamicAlignFolders
+					  m_doKryptonMixture
     );
     theTRTFactory.create(world);
     m_manager=theTRTFactory.getDetectorManager();
@@ -248,59 +244,59 @@ TRT_DetectorTool::registerCallback( StoreGateSvc* detStore)
 
   if (m_alignable) {
 
-    
+    // Regular alignment new shema   
     {
+      std::string folderName = "/TRT/AlignL1/TRT";
+      if (detStore->contains<CondAttrListCollection>(folderName)) {
+        msg(MSG::DEBUG) << "Registering callback on global Container with folder " << folderName << endreq;
+        const DataHandle<CondAttrListCollection> calc;
+        StatusCode trttmp = detStore->regFcn(&IGeoModelTool::align, dynamic_cast<IGeoModelTool*>(this), calc, folderName);
+        // We don't expect this to fail as we have already checked that the detstore contains the object. 
+        if (trttmp.isFailure()) {
+          msg(MSG::ERROR) << "Problem when register callback on global Container with folder " << folderName <<endreq;
+        } else {
+          sc =  StatusCode::SUCCESS;
+        }
+      } else {
+        msg(MSG::WARNING) << "Unable to register callback on global Container with folder " << folderName <<endreq;
+        //return StatusCode::FAILURE;
+      }
 
-      if (m_useDynamicAlignFolders){ // Regular alignment new shema   
-	std::string folderName = "/TRT/AlignL1/TRT";
-	if (detStore->contains<CondAttrListCollection>(folderName)) {
-	  msg(MSG::DEBUG) << "Registering callback on global Container with folder " << folderName << endreq;
-	  const DataHandle<CondAttrListCollection> calc;
-	  StatusCode trttmp = detStore->regFcn(&IGeoModelTool::align, dynamic_cast<IGeoModelTool*>(this), calc, folderName);
-	  // We don't expect this to fail as we have already checked that the detstore contains the object. 
-	  if (trttmp.isFailure()) {
-	    msg(MSG::ERROR) << "Problem when register callback on global Container with folder " << folderName <<endreq;
-	  } else {
-	    sc =  StatusCode::SUCCESS;
-	  }
-	} else {
-	  msg(MSG::WARNING) << "Unable to register callback on global Container with folder " << folderName <<endreq;
-	  //return StatusCode::FAILURE;
-	}
-	
-	folderName = "/TRT/AlignL2";
-	if (detStore->contains<AlignableTransformContainer>(folderName)) {
-	  if(msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << "Registering callback on AlignableTransformContainer with folder " << folderName << endreq;
-	  const DataHandle<AlignableTransformContainer> atc;
-	  StatusCode sctmp = detStore->regFcn(&IGeoModelTool::align, dynamic_cast<IGeoModelTool *>(this), atc, folderName);
-	  if(sctmp.isFailure()) {
-	    msg(MSG::ERROR) << "Problem when register callback on AlignableTransformContainer with folder " << folderName <<endreq;
-	  } else {
-	    sc =  StatusCode::SUCCESS;
-	  }
-	}
-	else {
-	  msg(MSG::WARNING) << "Unable to register callback on AlignableTransformContainer with folder "
-			    << folderName <<  endreq;
-	  //return StatusCode::FAILURE;
-	}
+      folderName = "/TRT/AlignL2";
+      if (detStore->contains<AlignableTransformContainer>(folderName)) {
+        if(msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << "Registering callback on AlignableTransformContainer with folder " << folderName << endreq;
+        const DataHandle<AlignableTransformContainer> atc;
+        StatusCode sctmp = detStore->regFcn(&IGeoModelTool::align, dynamic_cast<IGeoModelTool *>(this), atc, folderName);
+        if(sctmp.isFailure()) {
+          msg(MSG::ERROR) << "Problem when register callback on AlignableTransformContainer with folder " << folderName <<endreq;
+        } else {
+          sc =  StatusCode::SUCCESS;
+        }
+      }
+      else {
+	msg(MSG::WARNING) << "Unable to register callback on AlignableTransformContainer with folder "
+                          << folderName <<  endreq;
+        //return StatusCode::FAILURE;
       }
-      else {  // Regular alignment old schema
-	std::string folderName = "/TRT/Align";
-	if (detStore->contains<AlignableTransformContainer>(folderName)) {
-	  msg(MSG::DEBUG) << "Registering callback on AlignableTransformContainer with folder " << folderName << endreq;
-	  const DataHandle<AlignableTransformContainer> atc;
-	  StatusCode sctmp = detStore->regFcn(&IGeoModelTool::align, dynamic_cast<IGeoModelTool *>(this), atc, folderName);
-	  // We don't expect this to fail as we have already checked that the detstore contains the object.
-	  if (sctmp.isFailure()) {
-	    msg(MSG::ERROR) << "Problem when register callback on AlignableTransformContainer with folder " << folderName <<endreq;
-	  } else {
-	    sc =  StatusCode::SUCCESS;
-	  }
+    }
+
+
+    // Regular alignment
+    {
+      std::string folderName = "/TRT/Align";
+      if (detStore->contains<AlignableTransformContainer>(folderName)) {
+	msg(MSG::DEBUG) << "Registering callback on AlignableTransformContainer with folder " << folderName << endreq;
+	const DataHandle<AlignableTransformContainer> atc;
+	StatusCode sctmp = detStore->regFcn(&IGeoModelTool::align, dynamic_cast<IGeoModelTool *>(this), atc, folderName);
+	// We don't expect this to fail as we have already checked that the detstore contains the object.
+	if (sctmp.isFailure()) {
+	  msg(MSG::ERROR) << "Problem when register callback on AlignableTransformContainer with folder " << folderName <<endreq;
 	} else {
-	  msg(MSG::WARNING) << "Unable to register callback on AlignableTransformContainer with folder "
-			    << folderName << ", Alignments disabled! (Only if no Run2 schema is loaded)" << endreq;
+	  sc =  StatusCode::SUCCESS;
 	}
+      } else {
+	msg(MSG::WARNING) << "Unable to register callback on AlignableTransformContainer with folder "
+			  << folderName << ", Alignments disabled! (Only if no Run2 schema is loaded)" << endreq;
       }
     }
 
diff --git a/InnerDetector/InDetExample/InDetRecExample/python/InDetJobProperties.py b/InnerDetector/InDetExample/InDetRecExample/python/InDetJobProperties.py
index f90df27a4e9..9322b4710d7 100644
--- a/InnerDetector/InDetExample/InDetRecExample/python/InDetJobProperties.py
+++ b/InnerDetector/InDetExample/InDetRecExample/python/InDetJobProperties.py
@@ -420,6 +420,12 @@ class doMonitoringAlignment(InDetFlagsJobProperty):
     allowedTypes = ['bool']
     StoredValue  = False
 
+class useDynamicAlignFolders(InDetFlagsJobProperty):
+    """ Use to turn on dynamic alignment constants folder scheme (new development for 2016) """
+    statusOn     = True
+    allowedTypes = ['bool']
+    StoredValue  = False
+
 class doPerfMon(InDetFlagsJobProperty):
     """ Use to turn on PerfMon """
     statusOn     = True
@@ -2518,9 +2524,7 @@ class InDetJobProperties(JobPropertyContainer):
           print '* use non-standard SCT DCS based on ~20V HV cut'          
     if self.useTrtDCS():
        print '* use TRT DCS'
-
-    from AtlasGeoModel.InDetGMJobProperties import GeometryFlags as geoFlags
-    if geoFlags.useDynamicAlignFolders():
+    if self.useDynamicAlignFolders():
        print '* use of Dynamic alignment folder scheme enabled'
 
     if not self.doPRDFormation():
@@ -2660,6 +2664,7 @@ _list_InDetJobProperties = [Enabled,
                             doMonitoringSCT,
                             doMonitoringTRT,
                             doMonitoringAlignment,
+                            useDynamicAlignFolders,
                             doPerfMon,
                             AODall,
                             useBeamConstraint,
-- 
GitLab