From 574b00dc2b511565bfe4f61552c99ab3debc0538 Mon Sep 17 00:00:00 2001
From: Andreas Salzburger <Andreas.Salzburger@cern.ch>
Date: Thu, 4 Jul 2019 09:26:17 +0200
Subject: [PATCH] framework-v0.09.00 with MaterialMapping

---
 Examples/MaterialMapping/CMakeLists.txt       | 72 ++++++++++---------
 .../src/GeantinoRecordingExample.cpp          | 48 +++++--------
 .../src/detail/MaterialMappingBase.hpp        | 44 +++++++-----
 external/acts-core                            |  2 +-
 4 files changed, 82 insertions(+), 84 deletions(-)

diff --git a/Examples/MaterialMapping/CMakeLists.txt b/Examples/MaterialMapping/CMakeLists.txt
index 6ca9f08f..44520405 100644
--- a/Examples/MaterialMapping/CMakeLists.txt
+++ b/Examples/MaterialMapping/CMakeLists.txt
@@ -1,37 +1,45 @@
-#file (GLOB_RECURSE src_files "src/GenericMaterialValidationExample.cpp")
+set(_common_libraries
+  ActsCore
+  ACTFramework
+  ACTFWExamplesCommon
+  ${Boost_LIBRARIES})
+
+set(_plugin_libraries
+  ACTFWRootPlugin
+  ACTFWJsonPlugin
+  ACTFWBFieldPlugin)
 
 add_executable(ACTFWGenericMaterialValidationExample src/GenericMaterialValidation.cpp)
-target_include_directories(ACTFWGenericMaterialValidationExample PRIVATE ${Boost_INCLUDE_DIRS})
-target_link_libraries(ACTFWGenericMaterialValidationExample PRIVATE ActsCore)
-target_link_libraries(ACTFWGenericMaterialValidationExample PRIVATE ACTFramework ACTFWExamplesCommon ACTFWGeometryInterfaces ACTFWPropagation ACTFWGenericDetector)
-target_link_libraries(ACTFWGenericMaterialValidationExample PRIVATE ACTFWRootPlugin ACTFWJsonPlugin ACTFWBFieldPlugin)
-target_link_libraries(ACTFWGenericMaterialValidationExample PRIVATE ${Boost_LIBRARIES})
+target_include_directories(ACTFWGenericMaterialValidationExample PRIVATE 
+  ${Boost_INCLUDE_DIRS})
+target_link_libraries(ACTFWGenericMaterialValidationExample PRIVATE 
+  ${_common_libraries} ${_plugin_libraries})
+target_link_libraries(ACTFWGenericMaterialValidationExample PRIVATE 
+  ACTFWPropagation ACTFWGenericDetector)
+install(TARGETS ACTFWGenericMaterialValidationExample RUNTIME DESTINATION 
+  ${CMAKE_INSTALL_BINDIR})
 
-install(TARGETS ACTFWGenericMaterialValidationExample RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
+add_executable(ACTFWGenericMaterialMappingExample src/GenericMaterialMapping.cpp)
+target_include_directories(ACTFWGenericMaterialMappingExample PRIVATE 
+  ${Boost_INCLUDE_DIRS})
+target_link_libraries(ACTFWGenericMaterialMappingExample PRIVATE 
+  ${_common_libraries} ${_plugin_libraries})
+target_link_libraries(ACTFWGenericMaterialMappingExample PRIVATE 
+  ACTFWMaterialMapping ACTFWGenericDetector)
+install(TARGETS ACTFWGenericMaterialMappingExample RUNTIME DESTINATION 
+  ${CMAKE_INSTALL_BINDIR})
 
-#add_executable(ACTFWGenericMaterialMappingExample src/GenericMaterialMapping.cpp)
-#target_include_directories(ACTFWGenericMaterialMappingExample PRIVATE ${Boost_INCLUDE_DIRS})
-#target_link_libraries(ACTFWGenericMaterialMappingExample PRIVATE ActsCore ActsMaterialMappingPlugin)
-#target_link_libraries(ACTFWGenericMaterialMappingExample PRIVATE ACTFramework ACTFWExamplesCommon ACTFWMaterialMapping ACTFWGenericDetector)
-#target_link_libraries(ACTFWGenericMaterialMappingExample PRIVATE ACTFWRootPlugin ACTFWJsonPlugin)
-#target_link_libraries(ACTFWGenericMaterialMappingExample PRIVATE ${Boost_LIBRARIES})
-#
-#install(TARGETS ACTFWGenericMaterialMappingExample RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
 
-#if (USE_GEANT4 AND USE_DD4HEP)  
-#  include(${Geant4_USE_FILE})
-#  
-#  add_executable(ACTFWGeantinoRecordingExample src/GeantinoRecordingExample.cpp)
-#  target_include_directories(ACTFWGeantinoRecordingExample PRIVATE ${Boost_INCLUDE_DIRS})
-#  target_include_directories(ACTFWGeantinoRecordingExample PRIVATE ${DD4hep_INCLUDE_DIRS})
-#  target_link_libraries(ACTFWGeantinoRecordingExample PRIVATE ACTFWDD4hepG4Plugin)
-#  target_link_libraries(ACTFWGeantinoRecordingExample PRIVATE ACTFWExamplesCommon)
-#  target_link_libraries(ACTFWGeantinoRecordingExample PRIVATE ACTFWDD4hepDetector)
-#  target_link_libraries(ACTFWGeantinoRecordingExample PRIVATE ACTFWMaterialMapping)
-#  target_link_libraries(ACTFWGeantinoRecordingExample PRIVATE ACTFWRootPlugin)
-#  target_link_libraries(ACTFWGeantinoRecordingExample PRIVATE ${DD4hep_LIBRARIES})
-#  target_link_libraries(ACTFWGeantinoRecordingExample PRIVATE ${Geant4_LIBRARIES})
-#  target_link_libraries(ACTFWGeantinoRecordingExample PRIVATE ${Boost_LIBRARIES})
-#  
-#  install(TARGETS ACTFWGeantinoRecordingExample RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
-#endif()
+if (USE_GEANT4 AND USE_DD4HEP)
+  include(${Geant4_USE_FILE})
+  
+  add_executable(ACTFWGeantinoRecordingExample src/GeantinoRecordingExample.cpp)
+  target_include_directories(ACTFWGeantinoRecordingExample PRIVATE 
+    ${Boost_INCLUDE_DIRS} ${DD4hep_INCLUDE_DIRS})
+  target_link_libraries(ACTFWGeantinoRecordingExample PRIVATE 
+   ACTFWExamplesCommon ACTFWMaterialMapping ACTFWDD4hepG4Plugin ACTFWRootPlugin)
+  target_link_libraries(ACTFWGeantinoRecordingExample PRIVATE 
+   ACTFWDD4hepDetector ${DD4hep_LIBRARIES} ${Geant4_LIBRARIES} ${Boost_LIBRARIES})
+   
+  install(TARGETS ACTFWGeantinoRecordingExample RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
+endif()
diff --git a/Examples/MaterialMapping/src/GeantinoRecordingExample.cpp b/Examples/MaterialMapping/src/GeantinoRecordingExample.cpp
index bff12179..ea33e52e 100644
--- a/Examples/MaterialMapping/src/GeantinoRecordingExample.cpp
+++ b/Examples/MaterialMapping/src/GeantinoRecordingExample.cpp
@@ -7,17 +7,15 @@
 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 #include <boost/program_options.hpp>
-#include "ACTFW/Common/CommonOptions.hpp"
-#include "ACTFW/Common/OutputOptions.hpp"
 #include "ACTFW/DD4hepDetector/DD4hepDetectorOptions.hpp"
 #include "ACTFW/DD4hepDetector/DD4hepGeometryService.hpp"
 #include "ACTFW/Framework/Sequencer.hpp"
 #include "ACTFW/MaterialMapping/GeantinoRecording.hpp"
+#include "ACTFW/Options/CommonOptions.hpp"
 #include "ACTFW/Plugins/DD4hepG4/DD4hepToG4Svc.hpp"
 #include "ACTFW/Plugins/Root/RootMaterialTrackWriter.hpp"
 #include "ACTFW/Random/RandomNumbersSvc.hpp"
 #include "ACTFW/Utilities/Paths.hpp"
-#include "ACTFW/Writers/IWriterT.hpp"
 #include "Acts/Detector/TrackingGeometry.hpp"
 #include "Acts/Utilities/GeometryContext.hpp"
 
@@ -27,24 +25,19 @@ int
 main(int argc, char* argv[])
 {
   // Declare the supported program options.
-  po::options_description desc("Allowed options");
-  // Add the standard/common options
-  FW::Options::addCommonOptions<po::options_description>(desc);
-  // Add the output options
-  FW::Options::addOutputOptions<po::options_description>(desc);
-  // Add the detector options
-  FW::Options::addDD4hepOptions<po::options_description>(desc);
-  po::variables_map vm;
-  // Get all options from contain line and store it into the map
-  po::store(po::parse_command_line(argc, argv, desc), vm);
-  po::notify(vm);
-  // print help if requested
-  if (vm.count("help")) {
-    std::cout << desc << std::endl;
-    return 1;
+  // Setup and parse options
+  auto desc = FW::Options::makeDefaultOptions();
+  FW::Options::addSequencerOptions(desc);
+  FW::Options::addOutputOptions(desc);
+  FW::Options::addDD4hepOptions(desc);
+
+  // Parse the options
+  auto vm = FW::Options::parse(desc, argc, argv);
+  if (vm.empty()) {
+    return EXIT_FAILURE;
   }
-  // Now read the standard options
-  auto nEvents = FW::Options::readNumberOfEvents<po::variables_map>(vm);
+
+  FW::Sequencer g4sequencer(FW::Options::readSequencerConfig(vm));
 
   size_t nTracks     = 100;
   int    randomSeed1 = 536235167;
@@ -87,13 +80,6 @@ main(int argc, char* argv[])
   auto g4rAlgorithm
       = std::make_shared<FW::GeantinoRecording>(g4rConfig, Acts::Logging::INFO);
 
-  // Geant4 job - these can be many Geant4 jobs, indeed
-  //
-  // create the config object for the sequencer
-  FW::Sequencer::Config g4SeqConfig;
-  // now create the sequencer
-  FW::Sequencer g4Sequencer(g4SeqConfig);
-
   // Output directory
   std::string outputDir     = vm["output-dir"].template as<std::string>();
   std::string matCollection = g4rConfig.geantMaterialCollection;
@@ -107,12 +93,10 @@ main(int argc, char* argv[])
     auto matTrackWriterRoot
         = std::make_shared<FW::Root::RootMaterialTrackWriter>(
             matTrackWriterRootConfig);
-    if (g4Sequencer.addWriters({matTrackWriterRoot})
-        != FW::ProcessCode::SUCCESS)
-      return -1;
+    g4sequencer.addWriter(matTrackWriterRoot);
   }
 
   // Append the algorithm and run
-  g4Sequencer.appendEventAlgorithms({g4rAlgorithm});
-  g4Sequencer.run(nEvents);
+  g4sequencer.addAlgorithm(g4rAlgorithm);
+  g4sequencer.run();
 }
diff --git a/Examples/MaterialMapping/src/detail/MaterialMappingBase.hpp b/Examples/MaterialMapping/src/detail/MaterialMappingBase.hpp
index 47df0e1f..1b66f3a0 100644
--- a/Examples/MaterialMapping/src/detail/MaterialMappingBase.hpp
+++ b/Examples/MaterialMapping/src/detail/MaterialMappingBase.hpp
@@ -13,17 +13,20 @@
 #include "ACTFW/Framework/Sequencer.hpp"
 #include "ACTFW/Geometry/CommonGeometry.hpp"
 #include "ACTFW/MaterialMapping/MaterialMapping.hpp"
+#include "ACTFW/Options/CommonOptions.hpp"
 #include "ACTFW/Plugins/Json/JsonGeometryConverter.hpp"
 #include "ACTFW/Plugins/Json/JsonMaterialWriter.hpp"
 #include "ACTFW/Plugins/Root/RootMaterialTrackReader.hpp"
 #include "ACTFW/Plugins/Root/RootMaterialWriter.hpp"
+#include "ACTFW/Propagation/PropagationOptions.hpp"
 #include "ACTFW/Utilities/Paths.hpp"
-#include "ACTFW/options/CommonOptions.hpp"
 #include "Acts/Detector/TrackingGeometry.hpp"
 #include "Acts/Extrapolator/Navigator.hpp"
 #include "Acts/Plugins/MaterialMapping/SurfaceMaterialMapper.hpp"
 #include "Acts/Propagator/Propagator.hpp"
 #include "Acts/Propagator/StraightLineStepper.hpp"
+#include "Acts/Utilities/GeometryContext.hpp"
+#include "Acts/Utilities/MagneticFieldContext.hpp"
 
 namespace po = boost::program_options;
 
@@ -51,8 +54,6 @@ materialMappingExample(int              argc,
   FW::Options::addSequencerOptions(desc);
   FW::Options::addGeometryOptions(desc);
   FW::Options::addMaterialOptions(desc);
-  FW::Options::addBFieldOptions(desc);
-  FW::Options::addRandomNumbersOptions(desc);
   FW::Options::addPropagationOptions(desc);
   FW::Options::addOutputOptions(desc);
 
@@ -72,6 +73,10 @@ materialMappingExample(int              argc,
   auto geometry  = FW::Geometry::build(vm, geometrySetup);
   auto tGeometry = geometry.first;
 
+  /// Default contexts
+  Acts::GeometryContext      geoContext;
+  Acts::MagneticFieldContext mfContext;
+
   // Get a Navigator
   Acts::Navigator navigator(tGeometry);
 
@@ -99,8 +104,7 @@ materialMappingExample(int              argc,
     auto matTrackReaderRoot
         = std::make_shared<FW::Root::RootMaterialTrackReader>(
             matTrackReaderRootConfig);
-    if (sequencer.addReaders({matTrackReaderRoot}) != FW::ProcessCode::SUCCESS)
-      return -1;
+    sequencer.addReader(matTrackReaderRoot);
   }
 
   /// The material mapper
@@ -120,17 +124,17 @@ materialMappingExample(int              argc,
 
   if (vm["output-root"].template as<bool>()) {
 
-    /// The writer of the indexed material
-    FW::Root::RootMaterialWriter::Config rimConfig("MaterialWriter");
-    rimConfig.fileName = materialFileName + ".root";
-    auto rimRootWriter
-        = std::make_shared<FW::Root::RootMaterialWriter>(rimConfig);
-
-    mmAlgConfig.materialWriters.push_back(rimRootWriter);
+    // The writer of the indexed material
+    FW::Root::RootMaterialWriter::Config rmwConfig("MaterialWriter");
+    rmwConfig.fileName = materialFileName + ".root";
+    FW::Root::RootMaterialWriter rmwImpl(rmwConfig);
+    // Fullfill the IMaterialWriter interface
+    using RootWriter = FW::MaterialWriterT<FW::Root::RootMaterialWriter>;
+    mmAlgConfig.materialWriters.push_back(
+        std::make_shared<RootWriter>(std::move(rmwImpl)));
   }
 
   if (vm["output-json"].template as<bool>()) {
-
     /// The name of the output file
     std::string fileName = vm["mat-output-file"].template as<std::string>();
     // the material writer
@@ -147,17 +151,19 @@ materialMappingExample(int              argc,
     jmConverterCfg.processVolumes = vm["mat-output-volume"].template as<bool>();
     jmConverterCfg.writeData      = vm["mat-output-data"].template as<bool>();
     // The writer
-    auto jimJsonWriter = std::make_shared<FW::Json::JsonMaterialWriter>(
-        jmConverterCfg, materialFileName + ".json";);
-
-    mmAlgConfig.materialWriters.push_back(jimJsonWriter);
+    FW::Json::JsonMaterialWriter jmwImpl(jmConverterCfg,
+                                         materialFileName + ".json");
+    // Fullfill the IMaterialWriter interface
+    using JsonWriter = FW::MaterialWriterT<FW::Json::JsonMaterialWriter>;
+    mmAlgConfig.materialWriters.push_back(
+        std::make_shared<JsonWriter>(std::move(jmwImpl)));
   }
 
   // Create the material mapping
   auto mmAlg = std::make_shared<FW::MaterialMapping>(mmAlgConfig);
 
-  // Apend the Algorithm
-  sequencer.appendAlgorithm(mmAlg);
+  // Append the Algorithm
+  sequencer.addAlgorithm(mmAlg);
 
   // Initiate the run
   sequencer.run();
diff --git a/external/acts-core b/external/acts-core
index 8626adb8..a8f31303 160000
--- a/external/acts-core
+++ b/external/acts-core
@@ -1 +1 @@
-Subproject commit 8626adb803ee140810198595f7d731bf8b7e03c5
+Subproject commit a8f31303ee8720ed2946bfe2d59e81d0f70e307e
-- 
GitLab