"Analysis/AnalysisPID/git@code.ihep.ac.cn:cepc/CEPCSW.git" did not exist on "835ccfdec765b39063e064464e2e284dbace9a77"
Newer
Older
Markus Frank
committed
//==========================================================================
Markus Frank
committed
//--------------------------------------------------------------------------
// Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
Markus Frank
committed
// All rights reserved.
Markus Frank
committed
//
Markus Frank
committed
// For the licensing terms see $DD4hepINSTALL/LICENSE.
// For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
Markus Frank
committed
//
Markus Frank
committed
// Author : M.Frank
//
//==========================================================================
Markus Frank
committed
Markus Frank
committed
// Framework include files
Markus Frank
committed
#include "DDG4/Geant4Mapping.h"
#include "DD4hep/Printout.h"
#include "DD4hep/VolumeManager.h"
Markus Frank
committed
#include "G4PVPlacement.hh"
#include <stdexcept>
using namespace dd4hep::sim;
using namespace dd4hep;
Markus Frank
committed
using namespace std;
/// Initializing Constructor
Geant4Mapping::Geant4Mapping(const Detector& description_ref)
Markus Frank
committed
}
/// Standard destructor
Geant4Mapping::~Geant4Mapping() {
if (m_dataPtr)
delete m_dataPtr;
Markus Frank
committed
m_dataPtr = 0;
}
/// Possibility to define a singleton instance
Geant4Mapping& Geant4Mapping::instance() {
static Geant4Mapping inst(Detector::getInstance());
Markus Frank
committed
return inst;
}
/// When resolving pointers, we must check for the validity of the data block
void Geant4Mapping::checkValidity() const {
if (m_dataPtr)
return;
Markus Frank
committed
throw runtime_error("Geant4Mapping: Attempt to access an invalid data block!");
}
/// Create new data block. Delete old data block if present.
Geant4GeometryInfo& Geant4Mapping::init() {
Geant4GeometryInfo* p = detach();
attach(new Geant4GeometryInfo());
return data();
}
Markus Frank
committed
/// Release data and pass over the ownership
Geant4GeometryInfo* Geant4Mapping::detach() {
Geant4GeometryInfo* p = m_dataPtr;
Markus Frank
committed
m_dataPtr = 0;
return p;
}
/// Set a new data block
Markus Frank
committed
void Geant4Mapping::attach(Geant4GeometryInfo* data_ptr) {
m_dataPtr = data_ptr;
Markus Frank
committed
}
/// Access the volume manager
Geant4VolumeManager Geant4Mapping::volumeManager() const {
if ( m_dataPtr ) {
if ( m_dataPtr->g4Paths.empty() ) {
return Geant4VolumeManager(m_detDesc, m_dataPtr);
return Geant4VolumeManager(Handle < Geant4GeometryInfo > (m_dataPtr));
throw runtime_error(format("Geant4Mapping", "Cannot create volume manager without Geant4 geometry info [Invalid-Info]"));
Markus Frank
committed
}
/// Accessor to resolve geometry placements
PlacedVolume Geant4Mapping::placement(const G4VPhysicalVolume* node) const {
Markus Frank
committed
checkValidity();
const Geant4GeometryMaps::PlacementMap& pm = m_dataPtr->g4Placements;
for( const auto& entry : pm ) {
if ( entry.second == node )
return PlacedVolume(entry.first);
}
Markus Frank
committed
return PlacedVolume(0);
}