Skip to content
Snippets Groups Projects
Commit 7f17489a authored by Frank Winklmeier's avatar Frank Winklmeier
Browse files

Merge branch 'monopole' into 'master'

Monopole: thread-checker fixes

See merge request atlas/athena!58728
parents f5857b53 023ef382
No related branches found
No related tags found
No related merge requests found
Simulation/G4Extensions/Monopole
################################################################################
# Package: Monopole
################################################################################
# Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
# Declare the package name:
atlas_subdir( Monopole )
......@@ -8,7 +6,6 @@ atlas_subdir( Monopole )
# External dependencies:
find_package( CLHEP )
find_package( Geant4 )
find_package( XercesC )
# Component(s) in the package:
atlas_add_library( Monopole
......@@ -16,8 +13,8 @@ atlas_add_library( Monopole
src/components/*.cxx
OBJECT
NO_PUBLIC_HEADERS
PRIVATE_INCLUDE_DIRS ${GEANT4_INCLUDE_DIRS} ${XERCESC_INCLUDE_DIRS} ${CLHEP_INCLUDE_DIRS}
PRIVATE_LINK_LIBRARIES ${GEANT4_LIBRARIES} ${XERCESC_LIBRARIES} ${CLHEP_LIBRARIES} GaudiKernel AthenaBaseComps G4AtlasInterfaces )
PRIVATE_INCLUDE_DIRS ${GEANT4_INCLUDE_DIRS} ${CLHEP_INCLUDE_DIRS}
PRIVATE_LINK_LIBRARIES ${GEANT4_LIBRARIES} ${CLHEP_LIBRARIES} AthenaBaseComps CxxUtils G4AtlasInterfaces )
# Install files from the package:
atlas_install_python_modules( python/*.py POST_BUILD_CMD ${ATLAS_FLAKE8} )
......
/*
Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
*/
// class header
......@@ -16,28 +16,27 @@
#include <stdexcept>
#include <sstream>
#include <iterator>
#include <map>
#include <set>
bool CustomMonopoleFactory::loaded = false;
//std::set<G4ParticleDefinition *> CustomMonopoleFactory::m_particles;
std::set<CustomMonopole *> CustomMonopoleFactory::m_particles;
//bool CustomMonopoleFactory::isCustomMonopole(G4ParticleDefinition *particle)
bool CustomMonopoleFactory::isCustomMonopole(CustomMonopole *particle)
const CustomMonopoleFactory& CustomMonopoleFactory::instance()
{
static const CustomMonopoleFactory factory;
return factory;
}
bool CustomMonopoleFactory::isCustomMonopole(CustomMonopole *particle) const
{
return (particle && m_particles.find(particle)!=m_particles.end());
}
// CustomMonopole* CustomMonopoleFactory::getCustomMonopole(G4ParticleDefinition *particle)
// {
// return (m_particles.find(particle)!=m_particles.end());
// }
CustomMonopoleFactory::CustomMonopoleFactory()
{
loadCustomMonopoles();
}
void CustomMonopoleFactory::loadCustomMonopoles()
{
if(loaded) return;
loaded = true;
std::ifstream configFile("particles.txt");
// std::ifstream configFile("stophadrons.txt");
G4String pType="custom";
......
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
*/
#ifndef MONOPOLE_CustomMonopoleFactory_h
......@@ -17,15 +17,14 @@
class CustomMonopoleFactory
{
private:
static bool loaded;
// static std::set<G4ParticleDefinition *> m_particles;
static std::set<CustomMonopole *> m_particles;
public:
static void loadCustomMonopoles();
// static bool isCustomMonopole(G4ParticleDefinition *particle);
static bool isCustomMonopole(CustomMonopole *particle);
static const CustomMonopoleFactory& instance();
void loadCustomMonopoles();
bool isCustomMonopole(CustomMonopole *particle) const;
private:
CustomMonopoleFactory();
std::set<CustomMonopole *> m_particles;
};
......
......@@ -24,7 +24,6 @@
// ********************************************************************
//
//
// $Id: G4mplAtlasTransportation.cxx 729653 2016-03-14 15:55:47Z jchapman $
// GEANT4 tag $Name: geant4-09-03-patch-01 $
//
// ------------------------------------------------------------
......@@ -93,6 +92,7 @@ G4mplAtlasTransportation::G4mplAtlasTransportation( const CustomMonopole* mpl, G
fMomentumChanged( false ),
//fEnergyChanged( false ), // Not used?
fParticleIsLooping( false ),
fCurrentTouchableHandle(), // Points to (G4VTouchable*) 0
fGeometryLimitedStep( false ),
fPreviousSftOrigin (0.,0.,0.),
fPreviousSafety ( 0.0 ),
......@@ -133,9 +133,6 @@ G4mplAtlasTransportation::G4mplAtlasTransportation( const CustomMonopole* mpl, G
// or usual matter
fEquationSetup= G4mplEquationSetup::GetInstance();
static G4TouchableHandle nullTouchableHandle; // Points to (G4VTouchable*) 0
fCurrentTouchableHandle = nullTouchableHandle;
fEndGlobalTimeComputed = false;
fCandidateEndGlobalTime = 0;
}
......@@ -408,7 +405,7 @@ AlongStepGetPhysicalInteractionLength( const G4Track& track,
G4double startEnergy= track.GetKineticEnergy();
G4double endEnergy= fTransportEndKineticEnergy;
static G4int no_inexact_steps=0, no_large_ediff;
static std::atomic<G4int> no_inexact_steps=0, no_large_ediff;
G4double absEdiff = std::fabs(startEnergy- endEnergy);
if( absEdiff > CLHEP::perMillion * endEnergy )
{
......@@ -419,7 +416,7 @@ AlongStepGetPhysicalInteractionLength( const G4Track& track,
{
if( std::fabs(startEnergy- endEnergy) > CLHEP::perThousand * endEnergy )
{
static G4int no_warnings= 0, warnModulo=1, moduloFactor= 10;
static std::atomic<G4int> no_warnings= 0, warnModulo=1, moduloFactor= 10;
no_large_ediff ++;
if( (no_large_ediff% warnModulo) == 0 )
{
......@@ -445,7 +442,7 @@ AlongStepGetPhysicalInteractionLength( const G4Track& track,
<< no_large_ediff << " times." << G4endl;
if( no_large_ediff == warnModulo * moduloFactor )
{
warnModulo *= moduloFactor;
warnModulo = warnModulo * moduloFactor;
}
}
}
......@@ -541,14 +538,16 @@ AlongStepGetPhysicalInteractionLength( const G4Track& track,
G4VParticleChange* G4mplAtlasTransportation::AlongStepDoIt( const G4Track& track,
const G4Step& stepData )
{
static G4int noCalls=0;
static const G4ParticleDefinition* fOpticalPhoton =
#ifdef G4VERBOSE
static std::atomic<G4int> noCalls=0;
noCalls++;
#endif
static const G4ParticleDefinition* const fOpticalPhoton =
G4ParticleTable::GetParticleTable()->FindParticle("opticalphoton");
// G4cout << "SB: G4mplAtlasTransportation: AlongStepDoIt" << G4endl;
noCalls++;
fParticleChange.Initialize(track) ;
// Code for specific process
......@@ -756,8 +755,8 @@ G4VParticleChange* G4mplAtlasTransportation::PostStepDoIt( const G4Track& track,
} // endif ( fGeometryLimitedStep )
const G4VPhysicalVolume* pNewVol = retCurrentTouchable->GetVolume() ;
const G4Material* pNewMaterial = 0 ;
const G4VSensitiveDetector* pNewSensitiveDetector = 0 ;
G4Material* pNewMaterial = 0 ;
G4VSensitiveDetector* pNewSensitiveDetector = 0 ;
if( pNewVol != 0 )
{
......@@ -768,8 +767,8 @@ G4VParticleChange* G4mplAtlasTransportation::PostStepDoIt( const G4Track& track,
// ( <const_cast> pNewMaterial ) ;
// ( <const_cast> pNewSensitiveDetector) ;
fParticleChange.SetMaterialInTouchable( (G4Material *) pNewMaterial ) ;
fParticleChange.SetSensitiveDetectorInTouchable( (G4VSensitiveDetector *) pNewSensitiveDetector ) ;
fParticleChange.SetMaterialInTouchable( pNewMaterial ) ;
fParticleChange.SetSensitiveDetectorInTouchable( pNewSensitiveDetector ) ;
const G4MaterialCutsCouple* pNewMaterialCutsCouple = 0;
if( pNewVol != 0 )
......@@ -836,8 +835,7 @@ G4mplAtlasTransportation::StartTracking(G4Track* aTrack)
}
// Make sure to clear the chord finders of all fields (ie managers)
static G4FieldManagerStore* fieldMgrStore= G4FieldManagerStore::GetInstance();
fieldMgrStore->ClearAllChordFindersState();
G4FieldManagerStore::GetInstance()->ClearAllChordFindersState();
// Set up the Field Propagation to integrate time in case of magnetic charge
G4double particleMagCharge = mplParticle->MagneticCharge();
......
......@@ -26,7 +26,6 @@
/// \file Derived from example exoticphysics G4MonopolFieldSetup.cc
/// \brief Implementation of the G4mplEquationSetup class
//
// $Id: G4mplEquationSetup.cxx 684372 2015-07-20 15:34:53Z jchapman $
//
//
// G4mplEquationSetup is responsible for switching between two different
......@@ -154,7 +153,7 @@ G4mplEquationSetup::InitialiseForField(G4FieldManager* fieldManager )
const G4MagneticField* magField = dynamic_cast<const G4MagneticField*>(fieldManager->GetDetectorField());
G4MagneticField* magFieldNC = const_cast<G4MagneticField*>(magField);
G4MagneticField* magFieldNC ATLAS_THREAD_SAFE = const_cast<G4MagneticField*>(magField); // fieldManager only allow const access despite being non-const
delete fEquation;
fEquation = new G4Mag_UsualEqRhs(magFieldNC);
......@@ -189,7 +188,7 @@ void G4mplEquationSetup::SwitchStepperAndChordFinder(G4bool useMonopoleEq,
// - potentially after a change of 'field' object in this field manager (tbc)
const G4MagneticField* magField = dynamic_cast<const G4MagneticField*>(fieldManager->GetDetectorField());
G4MagneticField* magFieldNC= const_cast<G4MagneticField*>(magField);
G4MagneticField* magFieldNC ATLAS_THREAD_SAFE = const_cast<G4MagneticField*>(magField); // fieldManager only allow const access despite being non-const
if ( magField )
{
......
......@@ -23,8 +23,6 @@
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
// $Id: $
//
// G4mplEquationSetup is responsible for switching between two different
// equation of motions, one for monopoles and another for the rest of the
// particles.
......@@ -54,6 +52,8 @@
// Geant4 headers
#include "G4MagneticField.hh"
#include "CxxUtils/checker_macros.h"
class G4FieldManager;
class G4ChordFinder;
class G4Mag_UsualEqRhs;
......@@ -82,7 +82,7 @@ private:
// Thread-to-EquationSetup concurrent map type
using ESThreadMap_t = tbb::concurrent_unordered_map< std::thread::id, G4mplEquationSetup*, std::hash<std::thread::id> >;
// Concurrent map of EquationsSetup, one for each thread
static ESThreadMap_t m_ESThreadMap;
static ESThreadMap_t m_ESThreadMap ATLAS_THREAD_SAFE;
//@brief Search inside m_ESThreadMap the element with the current threadID
// and return it or return a null pointer if the element is not found
static G4mplEquationSetup* getES();
......
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
*/
// class header
......@@ -67,7 +67,7 @@ MonopolePhysicsTool* MonopolePhysicsTool::GetPhysicsOption()
void MonopolePhysicsTool::ConstructParticle()
{
ATH_MSG_DEBUG(" ConstructParticle for the Monopole being run");
CustomMonopoleFactory::loadCustomMonopoles();
CustomMonopoleFactory::instance();
}
void MonopolePhysicsTool::ConstructProcess()
......@@ -79,7 +79,7 @@ void MonopolePhysicsTool::ConstructProcess()
{
CustomMonopole* particle = dynamic_cast<CustomMonopole*>(PARTICLEITERATOR->value());
if(CustomMonopoleFactory::isCustomMonopole(particle))
if(CustomMonopoleFactory::instance().isCustomMonopole(particle))
{
ATH_MSG_DEBUG( particle->GetParticleName() << " is Custom" );
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment