File indexing completed on 2025-02-23 09:22:20
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
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
0043
0044 #define width 15L
0045
0046
0047
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
0061
0062 Manager* Manager::GetInstance()
0063 {
0064 return fInstance;
0065 }
0066
0067
0068
0069
0070 Manager::~Manager()
0071 {
0072 for (auto q : fQuantities)
0073 delete q.second;
0074 }
0075
0076
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
0086
0087 void Manager::ComputeAll()
0088 {
0089 for (auto const& q : fQuantities)
0090 (q.second)->Compute();
0091 }
0092
0093
0094
0095 void Manager::ResetAll()
0096 {
0097 for (auto const& q : fQuantities)
0098 (q.second)->Reset();
0099 }
0100
0101
0102
0103 void Manager::StoreAll()
0104 {
0105 for (auto const& q : fQuantities)
0106 (q.second)->Store();
0107 }
0108
0109
0110
0111 VRadiobiologicalQuantity* Manager::GetQuantity(G4String str)
0112 {
0113 return fQuantities.find(str)->second;
0114 }
0115
0116
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
0130
0131 void Manager::DigestAccumulables()
0132 {
0133 for (auto q : fQuantities) {
0134
0135 G4VAccumulable* GenAcc = G4AccumulableManager::Instance()->GetAccumulable(q.first);
0136
0137 if (!GenAcc) {
0138 G4Exception("RadioBioManager::AddFromAccumulable", "NoAccumulable", FatalException, q.first);
0139 }
0140
0141
0142 if (!q.second->IsCalculationEnabled()) continue;
0143
0144
0145 q.second->AddFromAccumulable(GenAcc);
0146 }
0147 }
0148
0149
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
0169
0170 }