ATLAS Offline Software
SDWrapper.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include "SDWrapper.h"
6 
7 // Geant4 includes
8 #include "G4SDManager.hh"
9 
10 // Framework utilities
11 
12 // Project includes
14 
15 // Local includes
16 #include "FCS_StepInfoSD.h"
17 
18 namespace FCS_Param
19 {
20 
21  namespace detail
22  {
23 
24  //-------------------------------------------------------------------------
25  // Construct with a hit collection name
26  //-------------------------------------------------------------------------
27  template<class SDType, class HitContainerType>
29  SDWrapper(const std::string& name, const std::string& hitCollectionName)
30  : G4VSensitiveDetector(name),
31  m_hitCollName(hitCollectionName),
32  m_hitColl(hitCollectionName)
33  {}
34 
35  //-------------------------------------------------------------------------
36  // Add a unique SD to the list
37  //-------------------------------------------------------------------------
38  template<class SDType, class HitContainerType>
40  addSD(std::unique_ptr<SDType> sd)
41  {
42  m_sdList.push_back( std::move(sd) );
43  }
44 
45  //-------------------------------------------------------------------------
46  // Initialize the hit collection at the beginning of the G4 event
47  //-------------------------------------------------------------------------
48  template<class SDType, class HitContainerType>
50  Initialize(G4HCofThisEvent*)
51  {
52  if(!m_hitColl.isValid()) {
53  if(verboseLevel >= 5) {
54  G4cout << GetName() << " \tDEBUG\t" << "Initializing hit container: "
55  << m_hitCollName << G4endl;
56  }
57  m_hitColl = std::make_unique<HitContainerType>();
58  }
59  }
60 
61  //-------------------------------------------------------------------------
62  // This should not be called
63  //-------------------------------------------------------------------------
64  template<class SDType, class HitContainerType>
66  ProcessHits(G4Step*, G4TouchableHistory*)
67  {
68  G4ExceptionDescription description;
69  description << "ProcessHits: this SD shouldn't be assigned to volumes!";
70  G4Exception(GetName(), "SDError", FatalException, description);
71  return false;
72  }
73 
74  //-------------------------------------------------------------------------
75  // Gather the hits into the WriteHandle from all the SDs
76  //-------------------------------------------------------------------------
77  template<class SDType, class HitContainerType>
80  {
81  if(!m_hitColl.isValid()) {
82  G4cerr << GetName() << " \tERROR\t" << "Hit collection WriteHandle is "
83  << "invalid!" << G4endl;
84  throw std::runtime_error("Invalid hit container WriteHandle: " +
85  m_hitColl.name());
86  }
87  // Loop over each SD and fill the container
88  for(auto& sd : m_sdList) {
89  sd->EndOfAthenaEvent( &*m_hitColl );
90  }
91  }
92 
93  //-------------------------------------------------------------------------
94  // Explit template instantiations
95  //-------------------------------------------------------------------------
97 
98  } // namespace detail
99 
100 } // namespace FCS_Param
FCS_StepInfoCollection.h
FCS_StepInfoSD.h
detail
Definition: extract_histogram_tag.cxx:14
python.selector.AtlRunQuerySelectorLhcOlc.sd
sd
Definition: AtlRunQuerySelectorLhcOlc.py:612
FCS_Param
Definition: FCS_StepInfoSD.h:39
SDWrapper.h
FCS_Param::detail::SDWrapper::SDWrapper
SDWrapper(const std::string &name, const std::string &hitCollectionName)
Construct the wrapper from the output collection name.
Definition: SDWrapper.cxx:29
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
FCS_Param::detail::SDWrapper::EndOfAthenaEvent
void EndOfAthenaEvent()
Gather the hits into the WriteHandle from all the SDs.
Definition: SDWrapper.cxx:79
FCS_Param::detail::SDWrapper::Initialize
virtual void Initialize(G4HCofThisEvent *) override final
Beginning of G4 event; initialize the hit collection.
Definition: SDWrapper.cxx:50
FCS_Param::detail::SDWrapper
A template class which wraps multiple sensitive detectors.
Definition: Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimSD/src/SDWrapper.h:51
FCS_Param::detail::SDWrapper::addSD
void addSD(std::unique_ptr< SDType > sd)
Add an SD to this wrapper.
Definition: SDWrapper.cxx:40
FCS_Param::detail::SDWrapper::ProcessHits
virtual bool ProcessHits(G4Step *, G4TouchableHistory *) override final
This method should not be called. It will throw.
Definition: SDWrapper.cxx:66
description
std::string description
glabal timer - how long have I taken so far?
Definition: hcg.cxx:88