Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: convert several DDRec constructors to use const Detector& #1148

Merged
merged 4 commits into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DDCore/include/DD4hep/Detector.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ namespace dd4hep {
is not present. Otherwise an empty detector container is returned.
*/
virtual const std::vector<DetElement>& detectors(const std::string& type,
bool throw_exc=false) = 0;
bool throw_exc=false) const = 0;

/// Access a set of subdetectors according to several sensitive types.
virtual std::vector<DetElement> detectors(const std::string& type1,
Expand Down
2 changes: 1 addition & 1 deletion DDCore/include/DD4hep/DetectorImp.h
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ namespace dd4hep {
- If throw_exc is set to true, an exception is thrown if the type
is not present. Otherwise an empty detector container is returned.
*/
virtual const std::vector<DetElement>& detectors(const std::string& type, bool throw_exc) override;
virtual const std::vector<DetElement>& detectors(const std::string& type, bool throw_exc) const override;

/// Access a set of subdetectors according to several sensitive types.
virtual std::vector<DetElement> detectors(const std::string& type1,
Expand Down
9 changes: 5 additions & 4 deletions DDCore/src/DetectorImp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,7 @@ Material DetectorImp::material(const string& name) const {

/// Internal helper to map detector types once the geometry is closed
void DetectorImp::mapDetectorTypes() {
m_detectorTypes[""] = {};
for( const auto& i : m_detectors ) {
DetElement det(i.second);
if ( det.parent().isValid() ) { // Exclude 'world'
Expand Down Expand Up @@ -571,15 +572,15 @@ vector<string> DetectorImp::detectorTypes() const {
}

/// Access a set of subdetectors according to the sensitive type.
const vector<DetElement>& DetectorImp::detectors(const string& type, bool throw_exc) {
const vector<DetElement>& DetectorImp::detectors(const string& type, bool throw_exc) const {
if ( m_manager->IsClosed() ) {
DetectorTypeMap::const_iterator i=m_detectorTypes.find(type);
if ( i != m_detectorTypes.end() ) return (*i).second;
if ( throw_exc ) {
DetectorTypeMap::const_iterator i=m_detectorTypes.find(type);
if ( i != m_detectorTypes.end() ) return (*i).second;
throw runtime_error("detectors("+type+"): Detectors of this type do not exist in the current setup!");
}
// return empty vector instead of exception
return m_detectorTypes[ type ] ;
return m_detectorTypes.at("") ;
andresailer marked this conversation as resolved.
Show resolved Hide resolved
}
throw runtime_error("detectors("+type+"): Detectors can only selected by type once the geometry is closed!");
}
Expand Down
2 changes: 1 addition & 1 deletion DDRec/include/DDRec/CellIDPositionConverter.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ namespace dd4hep {
public:

/// The constructor - takes the main description object.
CellIDPositionConverter( Detector& description ) : _description( &description ) {
CellIDPositionConverter(const Detector& description ) : _description( &description ) {
_volumeManager = VolumeManager::getVolumeManager(description);
}

Expand Down
4 changes: 2 additions & 2 deletions DDRec/include/DDRec/MaterialScan.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ namespace dd4hep {
private:

/// Reference to detector setup
Detector& m_detector;
const Detector& m_detector;
/// Material manager
std::unique_ptr<MaterialManager> m_materialMgr; //!
/// Local cache: subdetector placements
Expand All @@ -64,7 +64,7 @@ namespace dd4hep {
public:

/// Standard constructor for the master instance
MaterialScan(Detector& description);
MaterialScan(const Detector& description);

/// Default destructor
virtual ~MaterialScan();
Expand Down
4 changes: 2 additions & 2 deletions DDRec/include/DDRec/SurfaceManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ namespace dd4hep {

public:
/// The constructor
SurfaceManager(Detector& theDetector);
SurfaceManager(const Detector& theDetector);

/// No default constructor
#if defined(G__ROOT)
Expand Down Expand Up @@ -69,7 +69,7 @@ namespace dd4hep {


/// initialize all known surface maps
void initialize(Detector& theDetector) ;
void initialize(const Detector& theDetector) ;

SurfaceMapsMap _map ;
};
Expand Down
2 changes: 1 addition & 1 deletion DDRec/src/MaterialScan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ MaterialScan::MaterialScan()
}

/// Default constructor
MaterialScan::MaterialScan(Detector& description)
MaterialScan::MaterialScan(const Detector& description)
: m_detector(description)
{
m_materialMgr.reset(new MaterialManager(m_detector.world().volume()));
Expand Down
4 changes: 2 additions & 2 deletions DDRec/src/SurfaceManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace dd4hep {
namespace rec {


SurfaceManager::SurfaceManager(Detector& theDetector){
SurfaceManager::SurfaceManager(const Detector& theDetector){

// have to make sure the volume manager is populated once in order to have
// the volumeIDs attached to the DetElements
Expand All @@ -52,7 +52,7 @@ namespace dd4hep {
return 0 ;
}

void SurfaceManager::initialize(Detector& description) {
void SurfaceManager::initialize(const Detector& description) {

const std::vector<std::string>& types = description.detectorTypes() ;

Expand Down
Loading