Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer 3 // * License and Disclaimer * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/ 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. 9 // * include a list of copyright holders. * 10 // * 10 // * * 11 // * Neither the authors of this software syst 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitatio 16 // * for the full disclaimer and the limitation of liability. * 17 // * 17 // * * 18 // * This code implementation is the result 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboratio 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distri 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you ag 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publicati 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Sof 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************* 24 // ******************************************************************** 25 // 25 // 26 26 27 // Author: Ivana Hrivnacova, 18/06/2013 (ivan 27 // Author: Ivana Hrivnacova, 18/06/2013 (ivana@ipno.in2p3.fr) 28 28 29 #include "G4HnManager.hh" 29 #include "G4HnManager.hh" 30 #include "G4HnMessenger.hh" 30 #include "G4HnMessenger.hh" 31 31 32 #include "G4AnalysisUtilities.hh" 32 #include "G4AnalysisUtilities.hh" 33 #include "G4VFileManager.hh" 33 #include "G4VFileManager.hh" 34 34 35 #include <utility> 35 #include <utility> 36 36 37 using namespace G4Analysis; 37 using namespace G4Analysis; 38 using std::to_string; 38 using std::to_string; 39 39 40 //____________________________________________ 40 //_____________________________________________________________________________ 41 G4HnManager::G4HnManager(G4String hnType, cons 41 G4HnManager::G4HnManager(G4String hnType, const G4AnalysisManagerState& state) 42 : G4BaseAnalysisManager(state), fHnType(std: 42 : G4BaseAnalysisManager(state), fHnType(std::move(hnType)) 43 {} << 43 { >> 44 fMessenger = std::make_unique<G4HnMessenger>(*this); >> 45 } 44 46 45 //____________________________________________ 47 //_____________________________________________________________________________ 46 G4HnManager::~G4HnManager() 48 G4HnManager::~G4HnManager() 47 { 49 { 48 for ( auto info : fHnVector ) { 50 for ( auto info : fHnVector ) { 49 delete info; 51 delete info; 50 } 52 } 51 } 53 } 52 54 53 // 55 // 54 // private methods 56 // private methods 55 // 57 // 56 58 57 //____________________________________________ 59 //_____________________________________________________________________________ 58 void G4HnManager::SetActivation(G4HnInformati 60 void G4HnManager::SetActivation(G4HnInformation* info, G4bool activation) 59 { 61 { 60 // Set activation to a given object 62 // Set activation to a given object 61 63 62 // Do nothing if activation does not change 64 // Do nothing if activation does not change 63 if ( info->GetActivation() == activation ) r 65 if ( info->GetActivation() == activation ) return; 64 66 65 // Change activation and account it in fNofA 67 // Change activation and account it in fNofActiveObjects 66 info->SetActivation(activation); 68 info->SetActivation(activation); 67 if (activation) { 69 if (activation) { 68 fNofActiveObjects++; 70 fNofActiveObjects++; 69 } 71 } 70 else { 72 else { 71 fNofActiveObjects--; 73 fNofActiveObjects--; 72 } 74 } 73 } 75 } 74 76 75 //____________________________________________ 77 //_____________________________________________________________________________ 76 void G4HnManager::SetPlotting(G4HnInformation 78 void G4HnManager::SetPlotting(G4HnInformation* info, G4bool plotting) 77 { 79 { 78 // Do nothing if ascii does not change 80 // Do nothing if ascii does not change 79 if ( info->GetPlotting() == plotting ) retur 81 if ( info->GetPlotting() == plotting ) return; 80 82 81 // Change Plotting and account it in fNofPlo 83 // Change Plotting and account it in fNofPlottingObjects 82 info->SetPlotting(plotting); 84 info->SetPlotting(plotting); 83 if (plotting) { 85 if (plotting) { 84 fNofPlottingObjects++; 86 fNofPlottingObjects++; 85 } 87 } 86 else { 88 else { 87 fNofPlottingObjects--; 89 fNofPlottingObjects--; 88 } 90 } 89 } 91 } 90 92 91 //____________________________________________ 93 //_____________________________________________________________________________ 92 void G4HnManager::SetFileName(G4HnInformation 94 void G4HnManager::SetFileName(G4HnInformation* info, const G4String& fileName) 93 { 95 { 94 // Do nothing if file name does not change 96 // Do nothing if file name does not change 95 if ( info->GetFileName() == fileName ) retur 97 if ( info->GetFileName() == fileName ) return; 96 98 97 auto hnFileName = fileName; << 98 auto extension = GetExtension(fileName); << 99 if (extension.size() != 0u) { << 100 // Check if valid extension (if present) << 101 auto output = G4Analysis::GetOutput(extens << 102 if ( output == G4AnalysisOutput::kNone ) { << 103 Warn("The file extension " + extension + << 104 fkClass, "SetFileName"); << 105 return; << 106 } << 107 } << 108 else { << 109 if (fDefaultFileType.size() != 0u) { << 110 //add extension if missing and file type << 111 hnFileName = fileName + "." + fDefaultFi << 112 } << 113 } << 114 << 115 // Save the info and account a new file name 99 // Save the info and account a new file name if file manager 116 info->SetFileName(hnFileName); << 100 info->SetFileName(fileName); 117 if (fFileManager) { 101 if (fFileManager) { 118 fFileManager->AddFileName(hnFileName); << 102 fFileManager->AddFileName(fileName); 119 } else { 103 } else { 120 Warn("Failed to set fileName " + fileName 104 Warn("Failed to set fileName " + fileName + 121 " for object " + info->GetName() + ". 105 " for object " + info->GetName() + ".\nFile manager is not set.", 122 fkClass, "SetFileName"); 106 fkClass, "SetFileName"); 123 return; 107 return; 124 } 108 } 125 109 126 if ( hnFileName != "" ) { << 110 if ( fileName != "" ) { 127 fNofFileNameObjects++; 111 fNofFileNameObjects++; 128 } else { 112 } else { 129 fNofFileNameObjects--; 113 fNofFileNameObjects--; 130 } 114 } 131 } 115 } 132 116 133 // 117 // 134 // public methods 118 // public methods 135 // 119 // 136 120 137 //____________________________________________ 121 //_____________________________________________________________________________ 138 void G4HnManager::CreateMessenger() << 122 G4HnInformation* G4HnManager::AddHnInformation(const G4String& name, G4int nofDimensions) 139 { 123 { 140 fMessenger = std::make_unique<G4HnMessenger> << 124 auto info = new G4HnInformation(name, nofDimensions); 141 } << 142 << 143 //____________________________________________ << 144 void G4HnManager::AddHnInformation(G4HnInforma << 145 { << 146 // Add new information << 147 << 148 fHnVector.push_back(info); 125 fHnVector.push_back(info); 149 ++fNofActiveObjects; 126 ++fNofActiveObjects; 150 } << 151 << 152 //____________________________________________ << 153 void G4HnManager::AddHnInformation(G4HnInforma << 154 { << 155 // Replace the information at 'index' positi << 156 // Update new information with the previous << 157 // previous histogram was deleted with 'keep << 158 << 159 auto previousInfo = fHnVector[index]; << 160 if (previousInfo->GetDeletedPair().second) { << 161 info->Update(*previousInfo); << 162 } << 163 delete previousInfo; << 164 << 165 fHnVector[index] = info; << 166 << 167 if (info->GetActivation()) { ++fNofActiveObj << 168 if (info->GetAscii()) { ++fNofAsciiObje << 169 if (info->GetPlotting()) { ++fNofPlottingO << 170 if (! info->GetFileName().empty()) { ++fNofF << 171 } << 172 << 173 //____________________________________________ << 174 void G4HnManager::SetHnDeleted(G4HnInformation << 175 { << 176 info->SetDeleted(true, keepSetting); << 177 127 178 if (info->GetActivation()) { --fNofActiveObj << 128 return info; 179 if (info->GetAscii()) { --fNofAsciiObje << 180 if (info->GetPlotting()) { --fNofPlottingO << 181 if (! info->GetFileName().empty()) { --fNofF << 182 } 129 } 183 130 184 //____________________________________________ 131 //_____________________________________________________________________________ 185 void G4HnManager::ClearData() 132 void G4HnManager::ClearData() 186 { 133 { 187 for ( auto info : fHnVector ) { 134 for ( auto info : fHnVector ) { 188 delete info; 135 delete info; 189 } 136 } 190 fHnVector.clear(); 137 fHnVector.clear(); 191 SetLockFirstId(false); 138 SetLockFirstId(false); 192 } 139 } 193 140 194 //____________________________________________ 141 //_____________________________________________________________________________ 195 G4HnInformation* G4HnManager::GetHnInformation 142 G4HnInformation* G4HnManager::GetHnInformation(G4int id, 196 std::string_v 143 std::string_view functionName, G4bool warn) const 197 { 144 { 198 G4int index = id - fFirstId; 145 G4int index = id - fFirstId; 199 if ( index < 0 || index >= G4int(fHnVector.s 146 if ( index < 0 || index >= G4int(fHnVector.size()) ) { 200 if ( warn ) { 147 if ( warn ) { 201 Warn(fHnType + " histogram " + to_string 148 Warn(fHnType + " histogram " + to_string(id) + " does not exist.", 202 fkClass, functionName); 149 fkClass, functionName); 203 } 150 } 204 return nullptr; 151 return nullptr; 205 } 152 } 206 return fHnVector[index]; 153 return fHnVector[index]; 207 } 154 } 208 155 209 //____________________________________________ 156 //_____________________________________________________________________________ 210 G4HnDimensionInformation* G4HnManager::GetHnDi 157 G4HnDimensionInformation* G4HnManager::GetHnDimensionInformation(G4int id, 211 G4int dimensio 158 G4int dimension, 212 std::string_vi 159 std::string_view functionName, G4bool warn) const 213 { 160 { 214 auto info = GetHnInformation(id, functionNam 161 auto info = GetHnInformation(id, functionName, warn); 215 if (info == nullptr) return nullptr; 162 if (info == nullptr) return nullptr; 216 163 217 return info->GetHnDimensionInformation(dimen 164 return info->GetHnDimensionInformation(dimension); 218 } 165 } 219 166 220 //____________________________________________ 167 //_____________________________________________________________________________ 221 G4bool G4HnManager::IsActive() const 168 G4bool G4HnManager::IsActive() const 222 { 169 { 223 return ( fNofActiveObjects > 0 ); 170 return ( fNofActiveObjects > 0 ); 224 } 171 } 225 172 226 //____________________________________________ 173 //_____________________________________________________________________________ 227 G4bool G4HnManager::IsAscii() const 174 G4bool G4HnManager::IsAscii() const 228 { 175 { 229 return ( fNofAsciiObjects > 0 ); 176 return ( fNofAsciiObjects > 0 ); 230 } 177 } 231 178 232 //____________________________________________ 179 //_____________________________________________________________________________ 233 G4bool G4HnManager::IsPlotting() const 180 G4bool G4HnManager::IsPlotting() const 234 { 181 { 235 return ( fNofPlottingObjects > 0 ); 182 return ( fNofPlottingObjects > 0 ); 236 } 183 } 237 184 238 //____________________________________________ 185 //_____________________________________________________________________________ 239 G4bool G4HnManager::IsFileName() const 186 G4bool G4HnManager::IsFileName() const 240 { 187 { 241 return ( fNofFileNameObjects > 0 ); 188 return ( fNofFileNameObjects > 0 ); 242 } 189 } 243 190 244 //____________________________________________ 191 //_____________________________________________________________________________ 245 void G4HnManager::SetActivation(G4int id, G4b 192 void G4HnManager::SetActivation(G4int id, G4bool activation) 246 { 193 { 247 // Set activation to a given object 194 // Set activation to a given object 248 195 249 auto info = GetHnInformation(id, "SetActivat 196 auto info = GetHnInformation(id, "SetActivation"); 250 197 251 if (info == nullptr) return; 198 if (info == nullptr) return; 252 199 253 SetActivation(info, activation); 200 SetActivation(info, activation); 254 } 201 } 255 202 256 //____________________________________________ 203 //_____________________________________________________________________________ 257 void G4HnManager::SetActivation(G4bool activa 204 void G4HnManager::SetActivation(G4bool activation) 258 { 205 { 259 // Set activation to all objects of the given 206 // Set activation to all objects of the given type 260 207 261 //std::vector<G4HnInformation*>::iterator it 208 //std::vector<G4HnInformation*>::iterator it; 262 //for ( it = fHnVector.begin(); it != fHnVec 209 //for ( it = fHnVector.begin(); it != fHnVector.end(); it++ ) { 263 // G4HnInformation* info = *it; 210 // G4HnInformation* info = *it; 264 211 265 for ( auto info : fHnVector ) { 212 for ( auto info : fHnVector ) { 266 SetActivation(info, activation); 213 SetActivation(info, activation); 267 } 214 } 268 } 215 } 269 216 270 //____________________________________________ 217 //_____________________________________________________________________________ 271 void G4HnManager::SetAscii(G4int id, G4bool a 218 void G4HnManager::SetAscii(G4int id, G4bool ascii) 272 { 219 { 273 auto info = GetHnInformation(id, "SetAscii") 220 auto info = GetHnInformation(id, "SetAscii"); 274 221 275 if (info == nullptr) return; 222 if (info == nullptr) return; 276 223 277 // Do nothing if ascii does not change 224 // Do nothing if ascii does not change 278 if ( info->GetAscii() == ascii ) return; 225 if ( info->GetAscii() == ascii ) return; 279 226 280 // Change ascii and account it in fNofAsciiO 227 // Change ascii and account it in fNofAsciiObjects 281 info->SetAscii(ascii); 228 info->SetAscii(ascii); 282 if (ascii) { 229 if (ascii) { 283 fNofAsciiObjects++; 230 fNofAsciiObjects++; 284 } 231 } 285 else { 232 else { 286 fNofAsciiObjects--; 233 fNofAsciiObjects--; 287 } 234 } 288 } 235 } 289 236 290 //____________________________________________ 237 //_____________________________________________________________________________ 291 void G4HnManager::SetPlotting(G4int id, G4boo 238 void G4HnManager::SetPlotting(G4int id, G4bool plotting) 292 { 239 { 293 auto info = GetHnInformation(id, "SetPlottin 240 auto info = GetHnInformation(id, "SetPlotting"); 294 241 295 if (info == nullptr) return; 242 if (info == nullptr) return; 296 243 297 SetPlotting(info, plotting); 244 SetPlotting(info, plotting); 298 } 245 } 299 246 300 //____________________________________________ 247 //_____________________________________________________________________________ 301 void G4HnManager::SetPlotting(G4bool plotting 248 void G4HnManager::SetPlotting(G4bool plotting) 302 { 249 { 303 // Set plotting to all objects of the given ty 250 // Set plotting to all objects of the given type 304 251 305 for ( auto info : fHnVector ) { 252 for ( auto info : fHnVector ) { 306 SetPlotting(info, plotting); 253 SetPlotting(info, plotting); 307 } 254 } 308 } 255 } 309 256 310 //____________________________________________ 257 //_____________________________________________________________________________ 311 void G4HnManager::SetFileName(G4int id, const 258 void G4HnManager::SetFileName(G4int id, const G4String& fileName) 312 { 259 { 313 auto info = GetHnInformation(id, "SetFileNam 260 auto info = GetHnInformation(id, "SetFileName"); 314 261 315 if (info == nullptr) return; 262 if (info == nullptr) return; 316 263 317 SetFileName(info, fileName); 264 SetFileName(info, fileName); 318 } 265 } 319 266 320 //____________________________________________ 267 //_____________________________________________________________________________ 321 void G4HnManager::SetFileName(const G4String& 268 void G4HnManager::SetFileName(const G4String& fileName) 322 { 269 { 323 // Set plotting to all objects of the given ty 270 // Set plotting to all objects of the given type 324 271 325 for ( auto info : fHnVector ) { 272 for ( auto info : fHnVector ) { 326 SetFileName(info, fileName); 273 SetFileName(info, fileName); 327 } 274 } 328 } 275 } 329 276 330 //____________________________________________ 277 //_____________________________________________________________________________ 331 G4bool G4HnManager::SetAxisIsLog(unsigned int 278 G4bool G4HnManager::SetAxisIsLog(unsigned int idim, G4int id, G4bool isLog) 332 { 279 { 333 auto info = GetHnInformation(id, "SetAxisIsL 280 auto info = GetHnInformation(id, "SetAxisIsLog"); 334 281 335 if (info == nullptr) return false; 282 if (info == nullptr) return false; 336 283 337 info->SetIsLogAxis(idim, isLog); 284 info->SetIsLogAxis(idim, isLog); 338 return true; 285 return true; 339 } 286 } 340 287 341 //____________________________________________ 288 //_____________________________________________________________________________ 342 G4String G4HnManager::GetName(G4int id) const 289 G4String G4HnManager::GetName(G4int id) const 343 { 290 { 344 auto info = GetHnInformation(id, "GetName"); 291 auto info = GetHnInformation(id, "GetName"); 345 292 346 if (info == nullptr) return ""; 293 if (info == nullptr) return ""; 347 294 348 return info->GetName(); 295 return info->GetName(); 349 } 296 } 350 297 351 //____________________________________________ 298 //_____________________________________________________________________________ 352 G4double G4HnManager::GetUnit(unsigned int idi 299 G4double G4HnManager::GetUnit(unsigned int idim, G4int id) const 353 { 300 { 354 auto info = GetHnDimensionInformation(id, id 301 auto info = GetHnDimensionInformation(id, idim, "GetXUnit"); 355 302 356 if (info == nullptr) return 1.0; 303 if (info == nullptr) return 1.0; 357 304 358 return info->fUnit; 305 return info->fUnit; 359 } 306 } 360 307 361 //____________________________________________ 308 //_____________________________________________________________________________ 362 G4bool G4HnManager::GetAxisIsLog(unsigned int 309 G4bool G4HnManager::GetAxisIsLog(unsigned int idim, G4int id) const 363 { 310 { 364 auto info = GetHnInformation(id, "GetXAxisIs 311 auto info = GetHnInformation(id, "GetXAxisIsLog"); 365 312 366 if (info == nullptr) return false; 313 if (info == nullptr) return false; 367 314 368 return info->GetIsLogAxis(idim); 315 return info->GetIsLogAxis(idim); 369 } 316 } 370 317 371 //____________________________________________ 318 //_____________________________________________________________________________ 372 G4bool G4HnManager::GetActivation(G4int id) co 319 G4bool G4HnManager::GetActivation(G4int id) const 373 { 320 { 374 auto info = GetHnInformation(id, "GetActivat 321 auto info = GetHnInformation(id, "GetActivation"); 375 322 376 if (info == nullptr) return true; 323 if (info == nullptr) return true; 377 324 378 return info->GetActivation(); 325 return info->GetActivation(); 379 } 326 } 380 327 381 //____________________________________________ 328 //_____________________________________________________________________________ 382 G4bool G4HnManager::GetAscii(G4int id) const 329 G4bool G4HnManager::GetAscii(G4int id) const 383 { 330 { 384 auto info = GetHnInformation(id, "GetAscii") 331 auto info = GetHnInformation(id, "GetAscii"); 385 332 386 if (info == nullptr) return false; 333 if (info == nullptr) return false; 387 334 388 return info->GetAscii(); 335 return info->GetAscii(); 389 } 336 } 390 337 391 //____________________________________________ 338 //_____________________________________________________________________________ 392 G4bool G4HnManager::GetPlotting(G4int id) cons 339 G4bool G4HnManager::GetPlotting(G4int id) const 393 { 340 { 394 auto info = GetHnInformation(id, "GetPlottin 341 auto info = GetHnInformation(id, "GetPlotting"); 395 342 396 if (info == nullptr) return false; 343 if (info == nullptr) return false; 397 344 398 return info->GetPlotting(); 345 return info->GetPlotting(); 399 } 346 } 400 347 401 //____________________________________________ 348 //_____________________________________________________________________________ 402 G4String G4HnManager::GetFileName(G4int id) co 349 G4String G4HnManager::GetFileName(G4int id) const 403 { 350 { 404 auto info = GetHnInformation(id, "GetFileNam 351 auto info = GetHnInformation(id, "GetFileName"); 405 352 406 if (info == nullptr) return ""; 353 if (info == nullptr) return ""; 407 354 408 return info->GetFileName(); 355 return info->GetFileName(); 409 } 356 } 410 357