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