LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
artg4tk::DetectorHolderService Class Reference

#include "DetectorHolder_service.hh"

Public Member Functions

 DetectorHolderService (fhicl::ParameterSet const &)
 
void registerDetector (DetectorBase *const db)
 
void initialize ()
 
G4VPhysicalVolume * worldPhysicalVolume ()
 
DetectorBasegetDetectorForCategory (std::string category) const
 
fhicl::ParameterSet const getParametersForCategory (std::string category)
 
void callArtProduces (art::ProducesCollector &)
 
void fillEventWithArtHits (G4HCofThisEvent *hc)
 
void setCurrArtEvent (art::Event &e)
 
art::EventgetCurrArtEvent ()
 
void constructAllLVs ()
 

Private Member Functions

void constructAllPVs ()
 
void addDBtoCategoryMap (DetectorBase *const db)
 
void placeDetector (DetectorBase *const db)
 

Private Attributes

std::map< std::string, DetectorBase * > categoryMap_
 
G4VPhysicalVolume * worldPV_
 
art::EventcurrentArtEvent_
 

Detailed Description

Definition at line 40 of file DetectorHolder_service.hh.

Constructor & Destructor Documentation

artg4tk::DetectorHolderService::DetectorHolderService ( fhicl::ParameterSet const &  )

Definition at line 25 of file DetectorHolder.cc.

26  : categoryMap_(), worldPV_(nullptr)
27 {}
std::map< std::string, DetectorBase * > categoryMap_

Member Function Documentation

void artg4tk::DetectorHolderService::addDBtoCategoryMap ( DetectorBase *const  db)
private

Definition at line 141 of file DetectorHolder.cc.

References artg4tk::DetectorBase::category(), categoryMap_, util::cend(), and msgctg.

Referenced by getCurrArtEvent(), and registerDetector().

142 {
143  if (categoryMap_.find(db->category()) != cend(categoryMap_)) {
144  // We already have one of these detectors
145  throw cet::exception("DetectorHolderService")
146  << "Duplicate detector found. "
147  << "There is already one detector with the category " << db->category() << ".\n";
148  }
149  categoryMap_.try_emplace(db->category(), db);
150  mf::LogDebug(msgctg) << "Registered detector with category: " << db->category();
151 }
decltype(auto) constexpr cend(T &&obj)
ADL-aware version of std::cend.
Definition: StdUtils.h:93
std::map< std::string, DetectorBase * > categoryMap_
static std::string msgctg
MaybeLogger_< ELseverityLevel::ELsev_success, false > LogDebug
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
void artg4tk::DetectorHolderService::callArtProduces ( art::ProducesCollector collector)

Definition at line 117 of file DetectorHolder.cc.

References categoryMap_, and msgctg.

Referenced by larg4::larg4Main::larg4Main().

118 {
119  // Let's loop over the detectors in the map
120  for (auto entry : categoryMap_) {
121  mf::LogDebug(msgctg) << "Calling art produces for category " << (entry.second)->category();
122  (entry.second)->callArtProduces(collector);
123  }
124 }
std::map< std::string, DetectorBase * > categoryMap_
static std::string msgctg
MaybeLogger_< ELseverityLevel::ELsev_success, false > LogDebug
void callArtProduces(art::ProducesCollector &)
void artg4tk::DetectorHolderService::constructAllLVs ( )

Definition at line 58 of file DetectorHolder.cc.

References categoryMap_, and msgctg.

Referenced by getCurrArtEvent(), and larg4::larg4Main::larg4Main().

59 {
60  // Let's loop over the detectors in the map
61  for (auto entry : categoryMap_) {
62  mf::LogDebug(msgctg) << "Constructing logical volumes for detector of "
63  << "category " << (entry.second)->category();
64 
65  (entry.second)->buildLVs();
66  }
67 }
std::map< std::string, DetectorBase * > categoryMap_
static std::string msgctg
MaybeLogger_< ELseverityLevel::ELsev_success, false > LogDebug
void artg4tk::DetectorHolderService::constructAllPVs ( )
private

Definition at line 82 of file DetectorHolder.cc.

References categoryMap_, msgctg, and placeDetector().

Referenced by getCurrArtEvent(), and worldPhysicalVolume().

83 {
84  // Let's loop over the detectors in the map
85  for (auto entry : categoryMap_) {
86  mf::LogDebug(msgctg) << "Constructing physical volumes for detector of "
87  << "category " << (entry.second)->category();
88 
89  placeDetector(entry.second);
90  }
91 }
std::map< std::string, DetectorBase * > categoryMap_
static std::string msgctg
void placeDetector(DetectorBase *const db)
MaybeLogger_< ELseverityLevel::ELsev_success, false > LogDebug
void artg4tk::DetectorHolderService::fillEventWithArtHits ( G4HCofThisEvent hc)

Definition at line 128 of file DetectorHolder.cc.

References categoryMap_, and msgctg.

Referenced by artg4tk::ArtG4EventAction::EndOfEventAction().

129 {
130  // Let's loop over the detectors in the map
131  for (auto entry : categoryMap_) {
132  mf::LogDebug(msgctg) << "Converting hits for category " << (entry.second)->category();
133  (entry.second)->fillEventWithArtHits(hc);
134  }
135 }
std::map< std::string, DetectorBase * > categoryMap_
static std::string msgctg
MaybeLogger_< ELseverityLevel::ELsev_success, false > LogDebug
void fillEventWithArtHits(G4HCofThisEvent *hc)
art::Event& artg4tk::DetectorHolderService::getCurrArtEvent ( )
inline
artg4tk::DetectorBase * artg4tk::DetectorHolderService::getDetectorForCategory ( std::string  category) const

Definition at line 95 of file DetectorHolder.cc.

References categoryMap_.

Referenced by getParametersForCategory().

96 {
97 
98  auto categoryDB = categoryMap_.find(category);
99 
100  if (categoryDB != categoryMap_.end()) {
101  // We have a detector of that category
102  return categoryDB->second;
103  }
104  throw cet::exception("DetectorHolderService")
105  << "No detector found for category " << category << ".LO";
106 }
std::map< std::string, DetectorBase * > categoryMap_
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
fhicl::ParameterSet const artg4tk::DetectorHolderService::getParametersForCategory ( std::string  category)

Definition at line 110 of file DetectorHolder.cc.

References getDetectorForCategory(), and artg4tk::DetectorBase::parameters().

111 {
112  return getDetectorForCategory(category)->parameters();
113 }
fhicl::ParameterSet const & parameters() const
DetectorBase * getDetectorForCategory(std::string category) const
void artg4tk::DetectorHolderService::initialize ( )

Definition at line 71 of file DetectorHolder.cc.

References categoryMap_, and msgctg.

Referenced by larg4::larg4Main::larg4Main().

72 {
73  for (auto entry : categoryMap_) {
74  mf::LogDebug(msgctg) << "Initializing detector with category " << (entry.second)->category();
75 
76  (entry.second)->initialize();
77  }
78 }
std::map< std::string, DetectorBase * > categoryMap_
static std::string msgctg
MaybeLogger_< ELseverityLevel::ELsev_success, false > LogDebug
void artg4tk::DetectorHolderService::placeDetector ( DetectorBase *const  db)
private

Definition at line 156 of file DetectorHolder.cc.

References artg4tk::DetectorBase::category(), categoryMap_, artg4tk::DetectorBase::motherCategory(), msgctg, artg4tk::DetectorBase::placeToPVs(), and worldPV_.

Referenced by constructAllPVs(), and getCurrArtEvent().

157 {
158  // Check if we're dealing with the world volume first.
159  if (db->category() == "world") {
160  // The world's mother 'logical volume' is an empty vector.
161  worldPV_ = (db->placeToPVs(std::vector<G4LogicalVolume*>()))[0];
162  mf::LogDebug(msgctg) << "Just placed detector with category: " << db->category();
163  return;
164  }
165 
166  // Deal with non-world detectors
167  auto motherCategoryDB = categoryMap_.find(db->motherCategory());
168  if (motherCategoryDB == categoryMap_.end()) {
169  throw cet::exception("DetectorHolderService")
170  << "No mother volume found for detector with category " << db->category()
171  << ", which wanted a mother of category " << db->motherCategory()
172  << ". This probably means you are missing a "
173  << "detector class (derived from DetectorBase).\n";
174  }
175 
176  // We have a parent volume - pass the DB its mother volume and call place.
177  db->placeToPVs(motherCategoryDB->second->lvs());
178  mf::LogDebug(msgctg) << "Just placed detector with category: " << db->category();
179 }
std::map< std::string, DetectorBase * > categoryMap_
static std::string msgctg
MaybeLogger_< ELseverityLevel::ELsev_success, false > LogDebug
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
void artg4tk::DetectorHolderService::registerDetector ( DetectorBase *const  db)

Definition at line 31 of file DetectorHolder.cc.

References addDBtoCategoryMap(), msgctg, and artg4tk::DetectorBase::myName().

32 {
33  mf::LogDebug(msgctg) << "Registering detector named " << db->myName();
35 }
static std::string msgctg
void addDBtoCategoryMap(DetectorBase *const db)
MaybeLogger_< ELseverityLevel::ELsev_success, false > LogDebug
void artg4tk::DetectorHolderService::setCurrArtEvent ( art::Event e)
inline

Definition at line 78 of file DetectorHolder_service.hh.

References currentArtEvent_, and e.

79  {
81  }
Float_t e
Definition: plot.C:35
G4VPhysicalVolume * artg4tk::DetectorHolderService::worldPhysicalVolume ( )

Definition at line 39 of file DetectorHolder.cc.

References constructAllPVs(), and worldPV_.

40 {
41  // Check if we have a world yet.
42  if (0 == worldPV_) {
43  // We don't - let's construct all the physical volumes.
45 
46  // Check whether we have a world at this point. If not, we have a problem.
47  if (0 == worldPV_) {
48  throw cet::exception("DetectorHolderService") << "No world volume "
49  << "constructed!\n";
50  }
51  }
52  // If we reach this point, the world volume exists, so let's return it!
53  return worldPV_;
54 }
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33

Member Data Documentation

std::map<std::string, DetectorBase*> artg4tk::DetectorHolderService::categoryMap_
private
art::Event* artg4tk::DetectorHolderService::currentArtEvent_
private

Definition at line 115 of file DetectorHolder_service.hh.

Referenced by getCurrArtEvent(), and setCurrArtEvent().

G4VPhysicalVolume* artg4tk::DetectorHolderService::worldPV_
private

Definition at line 112 of file DetectorHolder_service.hh.

Referenced by placeDetector(), and worldPhysicalVolume().


The documentation for this class was generated from the following files: