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" << 31 << 32 #include "G4AnalysisUtilities.hh" 30 #include "G4AnalysisUtilities.hh" 33 #include "G4VFileManager.hh" << 34 << 35 #include <utility> << 36 31 37 using namespace G4Analysis; 32 using namespace G4Analysis; 38 using std::to_string; << 39 33 40 //____________________________________________ 34 //_____________________________________________________________________________ 41 G4HnManager::G4HnManager(G4String hnType, cons << 35 G4HnManager::G4HnManager(const G4String& hnType, 42 : G4BaseAnalysisManager(state), fHnType(std: << 36 const G4AnalysisManagerState& state) 43 {} << 37 : G4BaseAnalysisManager(state), 44 << 38 fHnType(hnType), 45 //____________________________________________ << 39 fNofActiveObjects(0), 46 G4HnManager::~G4HnManager() << 40 fNofAsciiObjects(0), >> 41 fNofPlottingObjects(0), >> 42 fHnVector() 47 { 43 { 48 for ( auto info : fHnVector ) { << 49 delete info; << 50 } << 51 } << 52 << 53 // << 54 // private methods << 55 // << 56 << 57 //____________________________________________ << 58 void G4HnManager::SetActivation(G4HnInformati << 59 { << 60 // Set activation to a given object << 61 << 62 // Do nothing if activation does not change << 63 if ( info->GetActivation() == activation ) r << 64 << 65 // Change activation and account it in fNofA << 66 info->SetActivation(activation); << 67 if (activation) { << 68 fNofActiveObjects++; << 69 } << 70 else { << 71 fNofActiveObjects--; << 72 } << 73 } 44 } 74 45 75 //____________________________________________ 46 //_____________________________________________________________________________ 76 void G4HnManager::SetPlotting(G4HnInformation << 47 G4HnManager::~G4HnManager() 77 { << 78 // Do nothing if ascii does not change << 79 if ( info->GetPlotting() == plotting ) retur << 80 << 81 // Change Plotting and account it in fNofPlo << 82 info->SetPlotting(plotting); << 83 if (plotting) { << 84 fNofPlottingObjects++; << 85 } << 86 else { << 87 fNofPlottingObjects--; << 88 } << 89 } << 90 << 91 //____________________________________________ << 92 void G4HnManager::SetFileName(G4HnInformation << 93 { 48 { 94 // Do nothing if file name does not change << 49 for ( auto hnInformation : fHnVector ) { 95 if ( info->GetFileName() == fileName ) retur << 50 delete hnInformation; 96 << 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 << 116 info->SetFileName(hnFileName); << 117 if (fFileManager) { << 118 fFileManager->AddFileName(hnFileName); << 119 } else { << 120 Warn("Failed to set fileName " + fileName << 121 " for object " + info->GetName() + ". << 122 fkClass, "SetFileName"); << 123 return; << 124 } << 125 << 126 if ( hnFileName != "" ) { << 127 fNofFileNameObjects++; << 128 } else { << 129 fNofFileNameObjects--; << 130 } 51 } 131 } 52 } 132 53 133 // << 54 // 134 // public methods 55 // public methods 135 // 56 // 136 57 137 //____________________________________________ 58 //_____________________________________________________________________________ 138 void G4HnManager::CreateMessenger() << 59 G4HnInformation* G4HnManager::AddHnInformation(const G4String& name, G4int nofDimensions) 139 { 60 { 140 fMessenger = std::make_unique<G4HnMessenger> << 61 auto hnInformation = new G4HnInformation(name, nofDimensions); 141 } << 62 fHnVector.push_back(hnInformation); 142 << 143 //____________________________________________ << 144 void G4HnManager::AddHnInformation(G4HnInforma << 145 { << 146 // Add new information << 147 << 148 fHnVector.push_back(info); << 149 ++fNofActiveObjects; 63 ++fNofActiveObjects; 150 } << 151 64 152 //____________________________________________ << 65 return hnInformation; 153 void G4HnManager::AddHnInformation(G4HnInforma << 66 } 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 << 178 if (info->GetActivation()) { --fNofActiveObj << 179 if (info->GetAscii()) { --fNofAsciiObje << 180 if (info->GetPlotting()) { --fNofPlottingO << 181 if (! info->GetFileName().empty()) { --fNofF << 182 } << 183 << 184 //____________________________________________ << 185 void G4HnManager::ClearData() << 186 { << 187 for ( auto info : fHnVector ) { << 188 delete info; << 189 } << 190 fHnVector.clear(); << 191 SetLockFirstId(false); << 192 } << 193 67 194 //____________________________________________ 68 //_____________________________________________________________________________ 195 G4HnInformation* G4HnManager::GetHnInformation << 69 G4HnInformation* G4HnManager::GetHnInformation(G4int id, 196 std::string_v << 70 G4String functionName, G4bool warn) const 197 { 71 { 198 G4int index = id - fFirstId; 72 G4int index = id - fFirstId; 199 if ( index < 0 || index >= G4int(fHnVector.s 73 if ( index < 0 || index >= G4int(fHnVector.size()) ) { 200 if ( warn ) { 74 if ( warn ) { 201 Warn(fHnType + " histogram " + to_string << 75 G4String inFunction = "G4HnManager::"; 202 fkClass, functionName); << 76 if ( functionName.size() ) 203 } << 77 inFunction += functionName; 204 return nullptr; << 78 else >> 79 inFunction += "GetHnInformation"; >> 80 G4ExceptionDescription description; >> 81 description << " " << fHnType << " histogram " << id >> 82 << " does not exist."; >> 83 G4Exception(inFunction, "Analysis_W011", JustWarning, description); >> 84 } >> 85 return nullptr; 205 } 86 } 206 return fHnVector[index]; 87 return fHnVector[index]; 207 } << 88 } 208 89 209 //____________________________________________ 90 //_____________________________________________________________________________ 210 G4HnDimensionInformation* G4HnManager::GetHnDi << 91 G4HnDimensionInformation* G4HnManager::GetHnDimensionInformation(G4int id, 211 G4int dimensio 92 G4int dimension, 212 std::string_vi << 93 G4String functionName, G4bool warn) const 213 { 94 { 214 auto info = GetHnInformation(id, functionNam << 95 auto hnInformation = GetHnInformation(id, functionName, warn); 215 if (info == nullptr) return nullptr; << 96 if ( ! hnInformation ) return nullptr; 216 97 217 return info->GetHnDimensionInformation(dimen << 98 return hnInformation->GetHnDimensionInformation(dimension); 218 } << 99 } 219 100 220 //____________________________________________ 101 //_____________________________________________________________________________ 221 G4bool G4HnManager::IsActive() const 102 G4bool G4HnManager::IsActive() const 222 { 103 { 223 return ( fNofActiveObjects > 0 ); 104 return ( fNofActiveObjects > 0 ); 224 } << 105 } 225 106 226 //____________________________________________ 107 //_____________________________________________________________________________ 227 G4bool G4HnManager::IsAscii() const 108 G4bool G4HnManager::IsAscii() const 228 { 109 { 229 return ( fNofAsciiObjects > 0 ); 110 return ( fNofAsciiObjects > 0 ); 230 } << 111 } 231 112 232 //____________________________________________ 113 //_____________________________________________________________________________ 233 G4bool G4HnManager::IsPlotting() const 114 G4bool G4HnManager::IsPlotting() const 234 { 115 { 235 return ( fNofPlottingObjects > 0 ); 116 return ( fNofPlottingObjects > 0 ); 236 } << 117 } 237 << 238 //____________________________________________ << 239 G4bool G4HnManager::IsFileName() const << 240 { << 241 return ( fNofFileNameObjects > 0 ); << 242 } << 243 118 244 //____________________________________________ 119 //_____________________________________________________________________________ 245 void G4HnManager::SetActivation(G4int id, G4b 120 void G4HnManager::SetActivation(G4int id, G4bool activation) 246 { 121 { 247 // Set activation to a given object 122 // Set activation to a given object 248 123 249 auto info = GetHnInformation(id, "SetActivat 124 auto info = GetHnInformation(id, "SetActivation"); 250 125 251 if (info == nullptr) return; << 126 if ( ! info ) return; 252 127 253 SetActivation(info, activation); << 128 // Do nothing if activation does not change 254 } << 129 if ( info->GetActivation() == activation ) return; >> 130 >> 131 // Change activation and account it in fNofActiveObjects >> 132 info->SetActivation(activation); >> 133 if ( activation ) >> 134 fNofActiveObjects++; >> 135 else >> 136 fNofActiveObjects--; >> 137 } 255 138 256 //____________________________________________ 139 //_____________________________________________________________________________ 257 void G4HnManager::SetActivation(G4bool activa 140 void G4HnManager::SetActivation(G4bool activation) 258 { 141 { 259 // Set activation to all objects of the given 142 // Set activation to all objects of the given type 260 143 261 //std::vector<G4HnInformation*>::iterator it 144 //std::vector<G4HnInformation*>::iterator it; 262 //for ( it = fHnVector.begin(); it != fHnVec 145 //for ( it = fHnVector.begin(); it != fHnVector.end(); it++ ) { 263 // G4HnInformation* info = *it; 146 // G4HnInformation* info = *it; 264 147 265 for ( auto info : fHnVector ) { 148 for ( auto info : fHnVector ) { 266 SetActivation(info, activation); << 149 267 } << 150 // Do nothing if activation does not change 268 } << 151 if ( info->GetActivation() == activation ) continue; >> 152 >> 153 // Change activation and account it in fNofActiveObjects >> 154 info->SetActivation(activation); >> 155 if ( activation ) >> 156 fNofActiveObjects++; >> 157 else >> 158 fNofActiveObjects--; >> 159 } >> 160 } 269 161 270 //____________________________________________ 162 //_____________________________________________________________________________ 271 void G4HnManager::SetAscii(G4int id, G4bool a 163 void G4HnManager::SetAscii(G4int id, G4bool ascii) 272 { 164 { 273 auto info = GetHnInformation(id, "SetAscii") 165 auto info = GetHnInformation(id, "SetAscii"); 274 166 275 if (info == nullptr) return; << 167 if ( ! info ) return; 276 168 277 // Do nothing if ascii does not change 169 // Do nothing if ascii does not change 278 if ( info->GetAscii() == ascii ) return; 170 if ( info->GetAscii() == ascii ) return; 279 << 171 280 // Change ascii and account it in fNofAsciiO 172 // Change ascii and account it in fNofAsciiObjects 281 info->SetAscii(ascii); 173 info->SetAscii(ascii); 282 if (ascii) { << 174 if ( ascii ) 283 fNofAsciiObjects++; 175 fNofAsciiObjects++; 284 } << 176 else 285 else { << 177 fNofAsciiObjects--; 286 fNofAsciiObjects--; << 178 } 287 } << 288 } << 289 179 290 //____________________________________________ 180 //_____________________________________________________________________________ 291 void G4HnManager::SetPlotting(G4int id, G4boo 181 void G4HnManager::SetPlotting(G4int id, G4bool plotting) 292 { 182 { 293 auto info = GetHnInformation(id, "SetPlottin 183 auto info = GetHnInformation(id, "SetPlotting"); 294 184 295 if (info == nullptr) return; << 185 if ( ! info ) return; 296 186 297 SetPlotting(info, plotting); << 187 // Do nothing if ascii does not change 298 } << 188 if ( info->GetPlotting() == plotting ) return; >> 189 >> 190 // Change Plotting and account it in fNofPlottingObjects >> 191 info->SetPlotting(plotting); >> 192 if ( plotting ) >> 193 fNofPlottingObjects++; >> 194 else >> 195 fNofPlottingObjects--; >> 196 } 299 197 300 //____________________________________________ 198 //_____________________________________________________________________________ 301 void G4HnManager::SetPlotting(G4bool plotting 199 void G4HnManager::SetPlotting(G4bool plotting) 302 { 200 { 303 // Set plotting to all objects of the given ty 201 // Set plotting to all objects of the given type 304 202 305 for ( auto info : fHnVector ) { 203 for ( auto info : fHnVector ) { 306 SetPlotting(info, plotting); << 204 307 } << 205 // Do nothing if plotting does not change 308 } << 206 if ( info->GetPlotting() == plotting ) continue; >> 207 >> 208 // Change plotting and account it in fNofActiveObjects >> 209 info->SetPlotting(plotting); >> 210 if ( plotting ) >> 211 fNofPlottingObjects++; >> 212 else >> 213 fNofPlottingObjects--; >> 214 } >> 215 } 309 216 310 //____________________________________________ 217 //_____________________________________________________________________________ 311 void G4HnManager::SetFileName(G4int id, const << 218 G4bool G4HnManager::SetXAxisIsLog(G4int id, G4bool isLog) 312 { 219 { 313 auto info = GetHnInformation(id, "SetFileNam << 220 auto info = GetHnInformation(id, "SetXAxisIsLog"); 314 221 315 if (info == nullptr) return; << 222 if ( ! info ) return false; 316 223 317 SetFileName(info, fileName); << 224 info->SetIsLogAxis(kX, isLog); >> 225 return true; 318 } 226 } 319 227 320 //____________________________________________ 228 //_____________________________________________________________________________ 321 void G4HnManager::SetFileName(const G4String& << 229 G4bool G4HnManager::SetYAxisIsLog(G4int id, G4bool isLog) 322 { 230 { 323 // Set plotting to all objects of the given ty << 231 auto info = GetHnInformation(id, "SetYAxisIsLog"); 324 232 325 for ( auto info : fHnVector ) { << 233 if ( ! info ) return false; 326 SetFileName(info, fileName); << 234 327 } << 235 info->SetIsLogAxis(kY, isLog); >> 236 return true; 328 } 237 } 329 238 330 //____________________________________________ 239 //_____________________________________________________________________________ 331 G4bool G4HnManager::SetAxisIsLog(unsigned int << 240 G4bool G4HnManager::SetZAxisIsLog(G4int id, G4bool isLog) 332 { 241 { 333 auto info = GetHnInformation(id, "SetAxisIsL << 242 auto info = GetHnInformation(id, "SetZAxisIsLog"); 334 243 335 if (info == nullptr) return false; << 244 if ( ! info ) return false; 336 245 337 info->SetIsLogAxis(idim, isLog); << 246 info->SetIsLogAxis(kZ, isLog); 338 return true; 247 return true; 339 } 248 } 340 249 341 //____________________________________________ 250 //_____________________________________________________________________________ 342 G4String G4HnManager::GetName(G4int id) const 251 G4String G4HnManager::GetName(G4int id) const 343 { 252 { 344 auto info = GetHnInformation(id, "GetName"); 253 auto info = GetHnInformation(id, "GetName"); 345 254 346 if (info == nullptr) return ""; << 255 if ( ! info ) return ""; 347 << 256 348 return info->GetName(); 257 return info->GetName(); 349 } << 258 } 350 259 351 //____________________________________________ 260 //_____________________________________________________________________________ 352 G4double G4HnManager::GetUnit(unsigned int idi << 261 G4double G4HnManager::GetXUnit(G4int id) const 353 { 262 { 354 auto info = GetHnDimensionInformation(id, id << 263 auto info = GetHnDimensionInformation(id, kX, "GetXUnit"); 355 264 356 if (info == nullptr) return 1.0; << 265 if ( ! info ) return 1.0; >> 266 >> 267 return info->fUnit; >> 268 } 357 269 >> 270 //_____________________________________________________________________________ >> 271 G4double G4HnManager::GetYUnit(G4int id) const >> 272 { >> 273 auto info = GetHnDimensionInformation(id, kY, "GetYUnit"); >> 274 >> 275 if ( ! info ) return 1.0; >> 276 358 return info->fUnit; 277 return info->fUnit; 359 } << 278 } 360 279 361 //____________________________________________ 280 //_____________________________________________________________________________ 362 G4bool G4HnManager::GetAxisIsLog(unsigned int << 281 G4double G4HnManager::GetZUnit(G4int id) const >> 282 { >> 283 auto info = GetHnDimensionInformation(id, kZ, "GetZUnit"); >> 284 >> 285 if ( ! info ) return 1.0; >> 286 >> 287 return info->fUnit; >> 288 } >> 289 >> 290 //_____________________________________________________________________________ >> 291 G4bool G4HnManager::GetXAxisIsLog(G4int id) const 363 { 292 { 364 auto info = GetHnInformation(id, "GetXAxisIs 293 auto info = GetHnInformation(id, "GetXAxisIsLog"); 365 294 366 if (info == nullptr) return false; << 295 if ( ! info ) return false; >> 296 >> 297 return info->GetIsLogAxis(kX); >> 298 } 367 299 368 return info->GetIsLogAxis(idim); << 300 //_____________________________________________________________________________ 369 } << 301 G4bool G4HnManager::GetYAxisIsLog(G4int id) const >> 302 { >> 303 auto info = GetHnInformation(id, "GetYAxisIsLog"); >> 304 >> 305 if ( ! info ) return 1.0; >> 306 >> 307 return info->GetIsLogAxis(kY); >> 308 } >> 309 >> 310 //_____________________________________________________________________________ >> 311 G4bool G4HnManager::GetZAxisIsLog(G4int id) const >> 312 { >> 313 auto info = GetHnInformation(id, "GetZAxisIsLog"); >> 314 >> 315 if ( ! info ) return 1.0; >> 316 >> 317 return info->GetIsLogAxis(kZ); >> 318 } 370 319 371 //____________________________________________ 320 //_____________________________________________________________________________ 372 G4bool G4HnManager::GetActivation(G4int id) co 321 G4bool G4HnManager::GetActivation(G4int id) const 373 { 322 { 374 auto info = GetHnInformation(id, "GetActivat 323 auto info = GetHnInformation(id, "GetActivation"); 375 324 376 if (info == nullptr) return true; << 325 if ( ! info ) return true; 377 << 326 378 return info->GetActivation(); 327 return info->GetActivation(); 379 } << 328 } 380 329 381 //____________________________________________ 330 //_____________________________________________________________________________ 382 G4bool G4HnManager::GetAscii(G4int id) const 331 G4bool G4HnManager::GetAscii(G4int id) const 383 { 332 { 384 auto info = GetHnInformation(id, "GetAscii") 333 auto info = GetHnInformation(id, "GetAscii"); 385 334 386 if (info == nullptr) return false; << 335 if ( ! info ) return false; 387 << 336 388 return info->GetAscii(); 337 return info->GetAscii(); 389 } << 338 } 390 339 391 //____________________________________________ 340 //_____________________________________________________________________________ 392 G4bool G4HnManager::GetPlotting(G4int id) cons 341 G4bool G4HnManager::GetPlotting(G4int id) const 393 { 342 { 394 auto info = GetHnInformation(id, "GetPlottin 343 auto info = GetHnInformation(id, "GetPlotting"); 395 344 396 if (info == nullptr) return false; << 345 if ( ! info ) return false; 397 << 346 398 return info->GetPlotting(); 347 return info->GetPlotting(); 399 } << 348 } 400 << 401 //____________________________________________ << 402 G4String G4HnManager::GetFileName(G4int id) co << 403 { << 404 auto info = GetHnInformation(id, "GetFileNam << 405 << 406 if (info == nullptr) return ""; << 407 << 408 return info->GetFileName(); << 409 } << 410 349