Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-23 09:22:20

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 //
0027 /// \file radiobiology/src/Manager.cc
0028 /// \brief Implementation of the RadioBio::Manager class
0029 
0030 #include "Manager.hh"
0031 
0032 #include "G4AccumulableManager.hh"
0033 
0034 #include <map>
0035 #include <mutex>
0036 
0037 std::mutex init_mutex;
0038 
0039 namespace RadioBio
0040 {
0041 
0042 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0043 
0044 #define width 15L
0045 
0046 // To create the instance the DetectorConstruction must
0047 // be passed (to account for correct voxelization)
0048 Manager* Manager::CreateInstance()
0049 {
0050   if (fInstance) {
0051     G4Exception("RadioBioManager::createInstance", "RecreatingRadioBioManager", FatalException,
0052                 "Creating another, new, instance of RadioBioManager");
0053     delete fInstance;
0054   }
0055 
0056   fInstance = new Manager();
0057   return fInstance;
0058 }
0059 
0060 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0061 
0062 Manager* Manager::GetInstance()
0063 {
0064   return fInstance;
0065 }
0066 
0067 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0068 
0069 // Destructor deletes all the quantities
0070 Manager::~Manager()
0071 {
0072   for (auto q : fQuantities)
0073     delete q.second;
0074 }
0075 
0076 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0077 
0078 void Manager::InitializeAll()
0079 {
0080   std::lock_guard<std::mutex> lock(init_mutex);
0081   for (auto const& q : fQuantities)
0082     (q.second)->Initialize();
0083 }
0084 
0085 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0086 
0087 void Manager::ComputeAll()
0088 {
0089   for (auto const& q : fQuantities)
0090     (q.second)->Compute();
0091 }
0092 
0093 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0094 
0095 void Manager::ResetAll()
0096 {
0097   for (auto const& q : fQuantities)
0098     (q.second)->Reset();
0099 }
0100 
0101 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0102 
0103 void Manager::StoreAll()
0104 {
0105   for (auto const& q : fQuantities)
0106     (q.second)->Store();
0107 }
0108 
0109 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0110 
0111 VRadiobiologicalQuantity* Manager::GetQuantity(G4String str)
0112 {
0113   return fQuantities.find(str)->second;
0114 }
0115 
0116 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0117 
0118 void Manager::PrintParameters()
0119 {
0120   G4cout << "*******************************************" << G4endl
0121          << "*** right now registered quantities are ***" << G4endl;
0122   for (auto const& q : fQuantities)
0123     G4cout << "*** " << q.first;
0124   G4cout << "*** but their calculation might be not ****" << G4endl
0125          << "*** active. Ask for parameters of each ****" << G4endl
0126          << "*******************************************" << G4endl;
0127 }
0128 
0129 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0130 
0131 void Manager::DigestAccumulables()
0132 {
0133   for (auto q : fQuantities) {
0134     // Hook in the accumulable manager the one named as the quantity (eg "Dose")
0135     G4VAccumulable* GenAcc = G4AccumulableManager::Instance()->GetAccumulable(q.first);
0136 
0137     if (!GenAcc) {
0138       G4Exception("RadioBioManager::AddFromAccumulable", "NoAccumulable", FatalException, q.first);
0139     }
0140 
0141     // If calculation is not set enabled, exit
0142     if (!q.second->IsCalculationEnabled()) continue;
0143 
0144     // Add from the accumulable.
0145     q.second->AddFromAccumulable(GenAcc);
0146   }
0147 }
0148 
0149 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0150 
0151 bool Manager::Register(VRadiobiologicalQuantity* q, G4String name)
0152 {
0153   if (q == nullptr) {
0154     G4Exception("RadioBioManager::Register", "RegisteringNullptr", JustWarning,
0155                 "Asking to register a quantity with null pointer!");
0156     return false;
0157   }
0158 
0159   if (fQuantities.find(name) != fQuantities.end()) {
0160     G4Exception("RadioBioManager::Register", "RegisteringSameQuantity", FatalException,
0161                 "Registering two radiobiological quantities with the same name!");
0162     return false;
0163   }
0164   fQuantities[name] = q;
0165   return true;
0166 }
0167 
0168 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0169 
0170 }  // namespace RadioBio