ATLAS Offline Software
MaterialManipulation.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 // MaterialManipulation.cxx, (c) ATLAS Detector software
8 
9 // Gaudi Units
10 #include "GaudiKernel/SystemOfUnits.h"
11 //TrkDetDescr Algs, Interfaces, Utils
12 #include "MaterialManipulation.h"
18 
19 
20 Trk::MaterialManipulation::MaterialManipulation(const std::string& name, ISvcLocator* pSvcLocator)
21 : AthAlgorithm(name,pSvcLocator),
22  m_inputLayerMaterialMapName("/GLOBAL/TrackingGeo/Input"),
23  m_inputLayerMaterialMap(nullptr),
24  m_outputLayerMaterialMapName("/GLOBAL/TrackingGeo/Output"),
25  m_layerMaterialManipulator("")
26 {
27  declareProperty("LayerMaterialManipulator", m_layerMaterialManipulator);
28  // input - output definition
29  declareProperty("LayerMaterialMapNameInput", m_inputLayerMaterialMapName);
30  declareProperty("LayerMaterialMapNameOutput", m_outputLayerMaterialMapName);
31 
32 }
33 
35 = default;
36 
38 {
39  ATH_MSG_INFO("initialize()");
40 
41  if (!m_layerMaterialManipulator.empty() && m_layerMaterialManipulator.retrieve().isFailure()){
42  ATH_MSG_FATAL("Could not retrieve LayerMaterial manipulator - although configured. Aborting.");
43  return StatusCode::FAILURE;
44  }
45  return StatusCode::SUCCESS;
46 }
47 
48 
50 {
51  ATH_MSG_VERBOSE("MaterialManipulation execute() start");
52 
53  Trk::LayerMaterialMap* outputLayerMaterialMap = nullptr;
54 
55  // make sure this is only done once
56  if (!m_inputLayerMaterialMap){
57 
58  // -------------------------------------------------------------------------------
59  if (detStore()->retrieve(m_inputLayerMaterialMap, m_inputLayerMaterialMapName).isFailure()){
60  ATH_MSG_FATAL( "Could not retrieve LayerMaterialMap wiht name '" << m_inputLayerMaterialMapName << "'. Aborting.");
61  return StatusCode::FAILURE;
62  } else
63  ATH_MSG_DEBUG( "Retrieved LayerMaterialMap wiht name '" << m_inputLayerMaterialMapName << "' for " << m_inputLayerMaterialMap->size() << " layers.");
64 
65  // create the output material map
66  outputLayerMaterialMap = new Trk::LayerMaterialMap();
67  // now create the new one and manipulate
68  for ( const auto & lmIter : (*m_inputLayerMaterialMap) ){
69  // copy the layer material
70  ATH_MSG_VERBOSE(" -> Found map for layer with index " << lmIter.first);
71  // use the virtual constructor
72  const Trk::LayerMaterialProperties* lmp = nullptr;
73  // manipulate it if needed
74  if (!m_layerMaterialManipulator.empty())
75  lmp = m_layerMaterialManipulator->processLayerMaterial(lmIter.first,*(lmIter.second));
76  else
77  lmp = lmIter.second->clone();
78  // and insert into the map
79  (*outputLayerMaterialMap)[lmIter.first] = lmp;
80  }
81 
82  // get the element table - and copy it over if there's none
83  const ElementTable* eTable = m_inputLayerMaterialMap->elementTable();
84  if (eTable){
86  outputLayerMaterialMap->updateElementTable(tElementTable);
87  }
88  // finally write it to StoreGate
89  if ( (detStore()->record(outputLayerMaterialMap, m_outputLayerMaterialMapName, false)).isFailure()){
90  ATH_MSG_ERROR("Writing of LayerMaterialMap with name '" << m_outputLayerMaterialMapName << "' was not successful." );
91  delete outputLayerMaterialMap;
92  } else
93  ATH_MSG_INFO("Successfully wrote LayerMaterialMap with name '" << m_outputLayerMaterialMapName << "' to the detector store.");
94 
95  }
96  return StatusCode::SUCCESS;
97 
98 }
99 
100 
102 {
103 
104  ATH_MSG_INFO("========================================================================================= ");
105  ATH_MSG_INFO("finalize() starts ...");
106  return StatusCode::SUCCESS;
107 }
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
ElementTable.h
Trk::MaterialManipulation::m_outputLayerMaterialMapName
std::string m_outputLayerMaterialMapName
Definition: MaterialManipulation.h:61
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
Trk::MaterialManipulation::initialize
virtual StatusCode initialize() override
standard Athena-Algorithm method
Definition: MaterialManipulation.cxx:37
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
Trk::LayerMaterialMap::updateElementTable
void updateElementTable(const SharedObject< const ElementTable > &eTable)
update method
Definition: LayerMaterialMap.h:66
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
Trk::MaterialManipulation::m_inputLayerMaterialMapName
std::string m_inputLayerMaterialMapName
< input material properties
Definition: MaterialManipulation.h:57
Trk::LayerMaterialMap
Definition: LayerMaterialMap.h:32
Trk::MaterialManipulation::MaterialManipulation
MaterialManipulation(const std::string &name, ISvcLocator *pSvcLocator)
Standard Athena-Algorithm Constructor.
Definition: MaterialManipulation.cxx:20
Trk::MaterialManipulation::finalize
virtual StatusCode finalize() override
standard Athena-Algorithm method
Definition: MaterialManipulation.cxx:101
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
Trk::LayerMaterialProperties
Definition: LayerMaterialProperties.h:62
Trk::MaterialManipulation::execute
virtual StatusCode execute() override
standard Athena-Algorithm method
Definition: MaterialManipulation.cxx:49
LayerIndex.h
AthAlgorithm
Definition: AthAlgorithm.h:47
Trk::MaterialManipulation::m_layerMaterialManipulator
ToolHandle< ILayerMaterialManipulator > m_layerMaterialManipulator
Definition: MaterialManipulation.h:63
python.PyKernel.detStore
detStore
Definition: PyKernel.py:41
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
LayerMaterialMap.h
Trk::SharedObject
std::shared_ptr< T > SharedObject
Definition: SharedObject.h:24
Trk::ElementTable
Definition: ElementTable.h:24
Trk::MaterialManipulation::~MaterialManipulation
~MaterialManipulation()
Default Destructor.
Trk::LayerMaterialProperties::clone
virtual LayerMaterialProperties * clone() const =0
Pseudo-Constructor clone()
ILayerMaterialManipulator.h
MaterialManipulation.h
LayerMaterialProperties.h