GGS(GenericGEANT4Simulation)Software  2.7.0
 All Data Structures Namespaces Files Functions Variables Typedefs Macros
Public Member Functions | Static Public Member Functions
GGSScoringManager Class Reference

Singleton for handling plugin scoring classes. More...

#include <GGSScoringManager.h>

Public Member Functions

 ~GGSScoringManager ()
 Destructor.
 
void RegisterSDClass (const G4String &className, G4VSensitiveDetector *(*sdBuilder)(G4String))
 Class registration method (class factory approach). More...
 
void AddSDToLogVol (const G4String &sdClassName, const G4String &logVolNameAndParams)
 Adds a sensitive detector to a logical volume (class factory approach). More...
 
void AddSDToLogVol (G4VSensitiveDetector *sd, G4LogicalVolume *logVol)
 Adds a sensitive detector to a logical volume (user build approach). More...
 
GGSScoringManagerMessengerGetMessenger ()
 Getter for messenger.
 

Static Public Member Functions

static GGSScoringManagerGetInstance ()
 Singleton getter. More...
 

Detailed Description

Singleton for handling plugin scoring classes.

This singleton manages the assignment of multiple sensitive detectors to a logical volume. The sensitive detectors can be provided by the user (user build approach) or be built by the singleton itself (class factory approach) in a messenger-driven way.

Definition at line 26 of file GGSScoringManager.h.

Member Function Documentation

void GGSScoringManager::AddSDToLogVol ( const G4String &  sdClassName,
const G4String &  logVolNameAndParams 
)

Adds a sensitive detector to a logical volume (class factory approach).

This method adds a new sensitive detector to a logical volume. It can be called multiple times for each logical volume to add more sd to the same volume. The logical volume is specified by a string containing its name plus an eventual additional trailing string separated by a space and containing the parameters to initialize the sensitive detector. The format and the handling of the parameters are defined by the given sensitive detector.

Parameters
sdClassNameThe name of the sd class.
logVolNameAndParamsThe name of the logical volume, eventually followed by parameters.
See Also
GGSScorer

Definition at line 48 of file GGSScoringManager.cpp.

48  {
49  static const std::string routineName("GGSScoringManager::AddSDToLogVol");
50 
51  G4VSensitiveDetector *sd = nullptr;
52 
53  // Attach the sensitive detector to all the logical volumes
54  G4String logVolName = logVolNameAndParams.substr(0, logVolNameAndParams.find_first_of(' '));
55  auto separatorPos = logVolNameAndParams.find_first_of(' ');
56  G4String params;
57  if (separatorPos != std::string::npos) {
58  params = logVolNameAndParams.substr(logVolNameAndParams.find_first_of(' ') + 1);
59  }
60  for (G4LogicalVolumeStore::const_iterator logVol = G4LogicalVolumeStore::GetInstance()->begin();
61  logVol != G4LogicalVolumeStore::GetInstance()->end(); logVol++) {
62  if ((*logVol)->GetName() == logVolName) {
63  // Retrieve the sd builder
64  if (!sd) {
65  SDBuildersMap::iterator builder = _buildersMap.find(sdClassName);
66  if (builder == _buildersMap.end()) {
67  throw std::runtime_error(routineName + ": builder for sensitive detector class " + sdClassName +
68  " is not present.");
69  }
70  // Build the sd
71  G4String sdName = sdClassName;
72  if (params != "") {
73  sdName.append('.').append(params);
74  }
75  sd = builder->second(logVolName + "." + sdName);
76  }
77  // Add sd to logvol
78  AddSDToLogVol(sd, *logVol);
79  }
80  }
81 
82  if (!sd) {
83  throw std::runtime_error(routineName + ": logical volume " + logVolName + " not present. Sensitive detector " +
84  sdClassName + " not added.");
85  }
86 }
void AddSDToLogVol(const G4String &sdClassName, const G4String &logVolNameAndParams)
Adds a sensitive detector to a logical volume (class factory approach).
void GGSScoringManager::AddSDToLogVol ( G4VSensitiveDetector *  sd,
G4LogicalVolume *  logVol 
)

Adds a sensitive detector to a logical volume (user build approach).

This method adds a new sensitive detector to a logical volume. It can be called multiple times for each logical volume to add more sd to the same volume.

Parameters
sdPointer to the sensitive detector.
logVolPointer to the logical volume.

Definition at line 90 of file GGSScoringManager.cpp.

90  {
91 
92  // Add sd to logical volume
93  if (logVol->GetSensitiveDetector() == NULL) {
94  // Case 1: logical has not a sd. Add the newly built sd to it
95  logVol->SetSensitiveDetector(sd);
96  } else {
97  GGSMultiSensitiveDetector *multiSD = dynamic_cast<GGSMultiSensitiveDetector *>(logVol->GetSensitiveDetector());
98  if (multiSD) {
99  // Case 2: the current sd is a multisd. Add the newly built sd to it
100  multiSD->AddSensitiveDetector(sd);
101  } else {
102  // Case 3: the current sd is a standard sd. Replace it with a multisd and add it and the newly built sd to the
103  // multisd
104  multiSD = new GGSMultiSensitiveDetector(G4String(logVol->GetName()).append(".GGSMultiSD"));
105  multiSD->AddSensitiveDetector(logVol->GetSensitiveDetector());
106  multiSD->AddSensitiveDetector(sd);
107  G4SDManager::GetSDMpointer()->AddNewDetector(multiSD);
108  logVol->SetSensitiveDetector(multiSD);
109  }
110  }
111 
112  // Add the sd to the sdmanager if it has not already been added
113  GGSSmartLog::MuteOutput();
114  if (G4SDManager::GetSDMpointer()->GetCollectionID(sd->GetName()) == -1) {
115  G4SDManager::GetSDMpointer()->AddNewDetector(sd);
116  }
117  GGSSmartLog::UnmuteOutput();
118 }
A multiple sensitive detector.
void AddSensitiveDetector(G4VSensitiveDetector *sd)
Adds a new sensitive detector to the multidetector.
GGSScoringManager & GGSScoringManager::GetInstance ( )
static

Singleton getter.

Returns
Reference to the scoring manager.

Definition at line 22 of file GGSScoringManager.cpp.

22  {
23  static GGSScoringManager instance;
24  return instance;
25 }
Singleton for handling plugin scoring classes.
void GGSScoringManager::RegisterSDClass ( const G4String &  className,
G4VSensitiveDetector *(*)(G4String)  sdBuilder 
)

Class registration method (class factory approach).

Parameters
classNameThe name of the sd class to be registered.
sdBuilderBuilder function for sd class.

Definition at line 37 of file GGSScoringManager.cpp.

37  {
38  static const std::string routineName("GGSScoringManager::RegisterSDClass");
39  std::pair<SDBuildersMap::iterator, bool> insertResult =
40  _buildersMap.insert(std::pair<G4String, G4VSensitiveDetector *(*)(G4String)>(className, sdBuilder));
41  if (!insertResult.second) {
42  COUT(WARNING) << "Sensitive detector class " << className << " is already present." << ENDL;
43  }
44 }
#define ENDL
Definition: GGSSmartLog.h:105
#define COUT(level)
Smart log macro. It writes on stdout only if the specified verbosity level is lesser than the maximum...
Definition: GGSSmartLog.h:76

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