Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-05 07:50:37

0001 //
0002 // ********************************************************************
0003 // * License and Disclaimer                                           *
0004 // *                                                                  *
0005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
0006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
0007 // * conditions of the Geant4 Software License,  included in the file *
0008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
0009 // * include a list of copyright holders.                             *
0010 // *                                                                  *
0011 // * Neither the authors of this software system, nor their employing *
0012 // * institutes,nor the agencies providing financial support for this *
0013 // * work  make  any representation or  warranty, express or implied, *
0014 // * regarding  this  software system or assume any liability for its *
0015 // * use.  Please see the license in the file  LICENSE  and URL above *
0016 // * for the full disclaimer and the limitation of liability.         *
0017 // *                                                                  *
0018 // * This  code  implementation is the result of  the  scientific and *
0019 // * technical work of the GEANT4 collaboration.                      *
0020 // * By using,  copying,  modifying or  distributing the software (or *
0021 // * any work based  on the software)  you  agree  to acknowledge its *
0022 // * use  in  resulting  scientific  publications,  and indicate your *
0023 // * acceptance of all terms of the Geant4 Software license.          *
0024 // ********************************************************************
0025 //
0026 /// \file Manager.cc
0027 /// \brief Implementation of the RadioBio::Manager class
0028 
0029 #include "Manager.hh"
0030 
0031 #include "G4AccumulableManager.hh"
0032 
0033 #include <map>
0034 #include <mutex>
0035 
0036 std::mutex init_mutex;
0037 
0038 namespace RadioBio
0039 {
0040 
0041 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0042 
0043 #define width 15L
0044 
0045 // To create the instance the DetectorConstruction must
0046 // be passed (to account for correct voxelization)
0047 Manager* Manager::CreateInstance()
0048 {
0049   if (fInstance) {
0050     G4Exception("RadioBioManager::createInstance", "RecreatingRadioBioManager", FatalException,
0051                 "Creating another, new, instance of RadioBioManager");
0052     delete fInstance;
0053   }
0054 
0055   fInstance = new Manager();
0056   return fInstance;
0057 }
0058 
0059 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0060 
0061 Manager* Manager::GetInstance()
0062 {
0063   return fInstance;
0064 }
0065 
0066 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0067 
0068 // Destructor deletes all the quantities
0069 Manager::~Manager()
0070 {
0071   for (auto q : fQuantities)
0072     delete q.second;
0073 }
0074 
0075 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0076 
0077 void Manager::InitializeAll()
0078 {
0079   std::lock_guard<std::mutex> lock(init_mutex);
0080   for (auto const& q : fQuantities)
0081     (q.second)->Initialize();
0082 }
0083 
0084 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0085 
0086 void Manager::ComputeAll()
0087 {
0088   for (auto const& q : fQuantities)
0089     (q.second)->Compute();
0090 }
0091 
0092 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0093 
0094 void Manager::ResetAll()
0095 {
0096   for (auto const& q : fQuantities)
0097     (q.second)->Reset();
0098 }
0099 
0100 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0101 
0102 void Manager::StoreAll()
0103 {
0104   for (auto const& q : fQuantities)
0105     (q.second)->Store();
0106 }
0107 
0108 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0109 
0110 VRadiobiologicalQuantity* Manager::GetQuantity(G4String str)
0111 {
0112   return fQuantities.find(str)->second;
0113 }
0114 
0115 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0116 
0117 void Manager::PrintParameters()
0118 {
0119   G4cout << "*******************************************" << G4endl
0120          << "*** right now registered quantities are ***" << G4endl;
0121   for (auto const& q : fQuantities)
0122     G4cout << "*** " << q.first;
0123   G4cout << "*** but their calculation might be not ****" << G4endl
0124          << "*** active. Ask for parameters of each ****" << G4endl
0125          << "*******************************************" << G4endl;
0126 }
0127 
0128 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0129 
0130 void Manager::DigestAccumulables()
0131 {
0132   for (auto q : fQuantities) {
0133     // Hook in the accumulable manager the one named as the quantity (eg "Dose")
0134     G4VAccumulable* GenAcc = G4AccumulableManager::Instance()->GetAccumulable(q.first);
0135 
0136     if (!GenAcc) {
0137       G4Exception("RadioBioManager::AddFromAccumulable", "NoAccumulable", FatalException, q.first);
0138     }
0139 
0140     // If calculation is not set enabled, exit
0141     if (!q.second->IsCalculationEnabled()) continue;
0142 
0143     // Add from the accumulable.
0144     q.second->AddFromAccumulable(GenAcc);
0145   }
0146 }
0147 
0148 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0149 
0150 bool Manager::Register(VRadiobiologicalQuantity* q, G4String name)
0151 {
0152   if (q == nullptr) {
0153     G4Exception("RadioBioManager::Register", "RegisteringNullptr", JustWarning,
0154                 "Asking to register a quantity with null pointer!");
0155     return false;
0156   }
0157 
0158   if (fQuantities.find(name) != fQuantities.end()) {
0159     G4Exception("RadioBioManager::Register", "RegisteringSameQuantity", FatalException,
0160                 "Registering two radiobiological quantities with the same name!");
0161     return false;
0162   }
0163   fQuantities[name] = q;
0164   return true;
0165 }
0166 
0167 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0168 
0169 }  // namespace RadioBio