Geant4 Cross Reference |
1 // 2 // ******************************************************************** 3 // * License and Disclaimer * 4 // * * 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. * 10 // * * 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitation of liability. * 17 // * * 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************************************** 25 // 26 27 // Author: Ivana Hrivnacova, 09/07/2013 (ivana@ipno.in2p3.fr) 28 29 #include "G4VAnalysisReader.hh" 30 #include "G4AnalysisUtilities.hh" 31 #include "G4HnManager.hh" 32 #include "G4VRNtupleManager.hh" 33 #include "G4VRFileManager.hh" 34 #include "G4Threading.hh" 35 36 using namespace G4Analysis; 37 38 //_____________________________________________________________________________ 39 G4VAnalysisReader::G4VAnalysisReader(const G4String& type) 40 : fState(type, ! G4Threading::IsWorkerThread()) 41 {} 42 43 //_____________________________________________________________________________ 44 G4VAnalysisReader::~G4VAnalysisReader() = default; 45 46 // 47 // protected methods 48 // 49 50 //_____________________________________________________________________________ 51 void G4VAnalysisReader::SetH1Manager(G4VTBaseHnManager<kDim1>* h1Manager) 52 { 53 fVH1Manager.reset(h1Manager); 54 } 55 56 //_____________________________________________________________________________ 57 void G4VAnalysisReader::SetH2Manager(G4VTBaseHnManager<kDim2>* h2Manager) 58 { 59 fVH2Manager.reset(h2Manager); 60 } 61 62 //_____________________________________________________________________________ 63 void G4VAnalysisReader::SetH3Manager(G4VTBaseHnManager<kDim3>* h3Manager) 64 { 65 fVH3Manager.reset(h3Manager); 66 } 67 68 //_____________________________________________________________________________ 69 void G4VAnalysisReader::SetP1Manager(G4VTBaseHnManager<kDim2>* p1Manager) 70 { 71 fVP1Manager.reset(p1Manager); 72 } 73 74 //_____________________________________________________________________________ 75 void G4VAnalysisReader::SetP2Manager(G4VTBaseHnManager<kDim3>* p2Manager) 76 { 77 fVP2Manager.reset(p2Manager); 78 } 79 80 //_____________________________________________________________________________ 81 void G4VAnalysisReader::SetNtupleManager(std::shared_ptr<G4VRNtupleManager> ntupleManager) 82 { 83 fVNtupleManager = std::move(ntupleManager); 84 } 85 86 //_____________________________________________________________________________ 87 void G4VAnalysisReader::SetFileManager(std::shared_ptr<G4VRFileManager> fileManager) 88 { 89 fVFileManager = std::move(fileManager); 90 } 91 92 // 93 // public methods 94 // 95 96 //_____________________________________________________________________________ 97 G4bool G4VAnalysisReader::CloseFiles(G4bool reset) 98 { 99 return CloseFilesImpl(reset); 100 } 101 102 //_____________________________________________________________________________ 103 void G4VAnalysisReader::SetFileName(const G4String& fileName) 104 { 105 fVFileManager->SetFileName(fileName); 106 } 107 108 //_____________________________________________________________________________ 109 G4String G4VAnalysisReader::GetFileName() const 110 { 111 return fVFileManager->GetFileName(); 112 } 113 114 //_____________________________________________________________________________ 115 G4int G4VAnalysisReader::ReadH1(const G4String& h1Name, 116 const G4String& fileName, 117 const G4String& dirName) 118 { 119 if ( fileName != "" ) { 120 return ReadH1Impl(h1Name, fileName, dirName, true); 121 } 122 if (fVFileManager->GetFileName() == "") { 123 Warn("Cannot get H1 " + h1Name + ". File name has to be set first.", fkClass, "ReadH1"); 124 return kInvalidId; 125 } 126 return ReadH1Impl(h1Name, fVFileManager->GetFileName(), dirName, false); 127 } 128 129 //_____________________________________________________________________________ 130 G4int G4VAnalysisReader::ReadH2(const G4String& h2Name, 131 const G4String& fileName, 132 const G4String& dirName) 133 { 134 if ( fileName != "" ) { 135 return ReadH2Impl(h2Name, fileName, dirName, true); 136 } 137 if (fVFileManager->GetFileName() == "") { 138 Warn("Cannot get H2 " + h2Name + ". File name has to be set first.", fkClass, "ReadH2"); 139 return kInvalidId; 140 } 141 return ReadH2Impl(h2Name, fVFileManager->GetFileName(), dirName, false); 142 } 143 144 //_____________________________________________________________________________ 145 G4int G4VAnalysisReader::ReadH3(const G4String& h3Name, 146 const G4String& fileName, 147 const G4String& dirName) 148 { 149 if ( fileName != "" ) { 150 return ReadH3Impl(h3Name, fileName, dirName, true); 151 } 152 if (fVFileManager->GetFileName() == "") { 153 Warn("Cannot get H3 " + h3Name + ". File name has to be set first.", fkClass, "ReadH3"); 154 return kInvalidId; 155 } 156 return ReadH3Impl(h3Name, fVFileManager->GetFileName(), dirName, false); 157 } 158 159 //_____________________________________________________________________________ 160 G4int G4VAnalysisReader::ReadP1(const G4String& p1Name, 161 const G4String& fileName, 162 const G4String& dirName) 163 { 164 if ( fileName != "" ) { 165 return ReadP1Impl(p1Name, fileName, dirName, true); 166 } 167 if (fVFileManager->GetFileName() == "") { 168 Warn("Cannot get P1 " + p1Name + ". File name has to be set first.", fkClass, "ReadP1"); 169 return kInvalidId; 170 } 171 return ReadP1Impl(p1Name, fVFileManager->GetFileName(), dirName, false); 172 } 173 174 //_____________________________________________________________________________ 175 G4int G4VAnalysisReader::ReadP2(const G4String& p2Name, 176 const G4String& fileName, 177 const G4String& dirName) 178 { 179 if ( fileName != "" ) { 180 return ReadP2Impl(p2Name, fileName, dirName, true); 181 } 182 if (fVFileManager->GetFileName() == "") { 183 Warn("Cannot get P2 " + p2Name + ". File name has to be set first.", fkClass, "ReadP2"); 184 return kInvalidId; 185 } 186 return ReadP2Impl(p2Name, fVFileManager->GetFileName(), dirName, false); 187 } 188 189 //_____________________________________________________________________________ 190 G4bool G4VAnalysisReader::SetFirstHistoId(G4int firstId) 191 { 192 auto result = true; 193 194 result &= SetFirstH1Id(firstId); 195 result &= SetFirstH2Id(firstId); 196 result &= SetFirstH3Id(firstId); 197 198 return result; 199 } 200 201 //_____________________________________________________________________________ 202 G4bool G4VAnalysisReader::SetFirstH1Id(G4int firstId) 203 { 204 return fVH1Manager->GetHnManager()->SetFirstId(firstId); 205 } 206 207 //_____________________________________________________________________________ 208 G4bool G4VAnalysisReader::SetFirstH2Id(G4int firstId) 209 { 210 return fVH2Manager->GetHnManager()->SetFirstId(firstId); 211 } 212 213 //_____________________________________________________________________________ 214 G4bool G4VAnalysisReader::SetFirstH3Id(G4int firstId) 215 { 216 return fVH3Manager->GetHnManager()->SetFirstId(firstId); 217 } 218 219 //_____________________________________________________________________________ 220 G4bool G4VAnalysisReader::SetFirstProfileId(G4int firstId) 221 { 222 auto result = true; 223 224 result &= SetFirstP1Id(firstId); 225 result &= SetFirstP2Id(firstId); 226 227 return result; 228 } 229 230 //_____________________________________________________________________________ 231 G4bool G4VAnalysisReader::SetFirstP1Id(G4int firstId) 232 { 233 return fVP1Manager->GetHnManager()->SetFirstId(firstId); 234 } 235 236 //_____________________________________________________________________________ 237 G4bool G4VAnalysisReader::SetFirstP2Id(G4int firstId) 238 { 239 return fVP2Manager->GetHnManager()->SetFirstId(firstId); 240 } 241 242 //_____________________________________________________________________________ 243 G4bool G4VAnalysisReader::SetFirstNtupleId(G4int firstId) 244 { 245 return fVNtupleManager->SetFirstId(firstId); 246 } 247 248 //_____________________________________________________________________________ 249 G4int G4VAnalysisReader::GetNtuple(const G4String& ntupleName, 250 const G4String& fileName, 251 const G4String& dirName) 252 { 253 if ( fileName != "" ) { 254 return fVNtupleManager->ReadNtupleImpl(ntupleName, fileName, dirName, true); 255 } 256 // Check if fileName was set 257 if (fVFileManager->GetFileName() == "") { 258 Warn("Cannot read Ntuple " + ntupleName += ". File name has to be set first.", fkClass, 259 "ReadNtuple"); 260 return kInvalidId; 261 } 262 return fVNtupleManager->ReadNtupleImpl(ntupleName, fVFileManager->GetFileName(), dirName, false); 263 } 264 265 //_____________________________________________________________________________ 266 G4bool G4VAnalysisReader::SetNtupleIColumn(const G4String& columnName, 267 G4int& value) 268 { 269 return fVNtupleManager->SetNtupleIColumn(columnName, value); 270 } 271 272 //_____________________________________________________________________________ 273 G4bool G4VAnalysisReader::SetNtupleFColumn(const G4String& columnName, 274 G4float& value) 275 { 276 return fVNtupleManager->SetNtupleFColumn(columnName, value); 277 } 278 279 //_____________________________________________________________________________ 280 G4bool G4VAnalysisReader::SetNtupleDColumn(const G4String& columnName, 281 G4double& value) 282 { 283 return fVNtupleManager->SetNtupleDColumn(columnName, value); 284 } 285 286 //_____________________________________________________________________________ 287 G4bool G4VAnalysisReader::SetNtupleSColumn(const G4String& columnName, 288 G4String& value) 289 { 290 return fVNtupleManager->SetNtupleSColumn(columnName, value); 291 } 292 293 //_____________________________________________________________________________ 294 G4bool G4VAnalysisReader::SetNtupleIColumn(const G4String& columnName, 295 std::vector<int>& vector) 296 { 297 return fVNtupleManager->SetNtupleIColumn(columnName, vector); 298 } 299 300 //_____________________________________________________________________________ 301 G4bool G4VAnalysisReader::SetNtupleFColumn(const G4String& columnName, 302 std::vector<float>& vector) 303 { 304 return fVNtupleManager->SetNtupleFColumn(columnName, vector); 305 } 306 307 //_____________________________________________________________________________ 308 G4bool G4VAnalysisReader::SetNtupleDColumn(const G4String& columnName, 309 std::vector<double>& vector) 310 { 311 return fVNtupleManager->SetNtupleDColumn(columnName, vector); 312 } 313 314 //_____________________________________________________________________________ 315 G4bool G4VAnalysisReader::SetNtupleSColumn(const G4String& columnName, 316 std::vector<std::string>& vector) 317 { 318 return fVNtupleManager->SetNtupleSColumn(columnName, vector); 319 } 320 321 //_____________________________________________________________________________ 322 G4bool G4VAnalysisReader::SetNtupleIColumn(G4int ntupleId, 323 const G4String& columnName, 324 G4int& value) 325 { 326 return fVNtupleManager->SetNtupleIColumn(ntupleId, columnName, value); 327 } 328 329 //_____________________________________________________________________________ 330 G4bool G4VAnalysisReader::SetNtupleFColumn(G4int ntupleId, 331 const G4String& columnName, 332 G4float& value) 333 { 334 return fVNtupleManager->SetNtupleFColumn(ntupleId, columnName, value); 335 } 336 337 //_____________________________________________________________________________ 338 G4bool G4VAnalysisReader::SetNtupleDColumn(G4int ntupleId, 339 const G4String& columnName, 340 G4double& value) 341 { 342 return fVNtupleManager->SetNtupleDColumn(ntupleId, columnName, value); 343 } 344 345 //_____________________________________________________________________________ 346 G4bool G4VAnalysisReader::SetNtupleSColumn(G4int ntupleId, 347 const G4String& columnName, 348 G4String& value) 349 { 350 return fVNtupleManager->SetNtupleSColumn(ntupleId, columnName, value); 351 } 352 353 //_____________________________________________________________________________ 354 G4bool G4VAnalysisReader::SetNtupleIColumn(G4int ntupleId, 355 const G4String& columnName, 356 std::vector<int>& vector) 357 { 358 return fVNtupleManager->SetNtupleIColumn(ntupleId, columnName, vector); 359 } 360 361 //_____________________________________________________________________________ 362 G4bool G4VAnalysisReader::SetNtupleFColumn(G4int ntupleId, 363 const G4String& columnName, 364 std::vector<float>& vector) 365 { 366 return fVNtupleManager->SetNtupleFColumn(ntupleId, columnName, vector); 367 } 368 369 //_____________________________________________________________________________ 370 G4bool G4VAnalysisReader::SetNtupleDColumn(G4int ntupleId, 371 const G4String& columnName, 372 std::vector<double>& vector) 373 { 374 return fVNtupleManager->SetNtupleDColumn(ntupleId, columnName, vector); 375 } 376 377 //_____________________________________________________________________________ 378 G4bool G4VAnalysisReader::SetNtupleSColumn(G4int ntupleId, 379 const G4String& columnName, 380 std::vector<std::string>& vector) 381 { 382 return fVNtupleManager->SetNtupleSColumn(ntupleId, columnName, vector); 383 } 384 385 //_____________________________________________________________________________ 386 G4bool G4VAnalysisReader::GetNtupleRow() 387 { 388 return fVNtupleManager->GetNtupleRow(); 389 } 390 391 392 //_____________________________________________________________________________ 393 G4bool G4VAnalysisReader::GetNtupleRow(G4int ntupleId) 394 { 395 return fVNtupleManager->GetNtupleRow(ntupleId); 396 } 397 398 //_____________________________________________________________________________ 399 G4int G4VAnalysisReader::GetNofH1s(G4bool onlyIfExist) const 400 { 401 return fVH1Manager->GetNofHns(onlyIfExist); 402 } 403 404 //_____________________________________________________________________________ 405 G4int G4VAnalysisReader::GetNofH2s(G4bool onlyIfExist) const 406 { 407 return fVH2Manager->GetNofHns(onlyIfExist); 408 } 409 410 //_____________________________________________________________________________ 411 G4int G4VAnalysisReader::GetNofH3s(G4bool onlyIfExist) const 412 { 413 return fVH3Manager->GetNofHns(onlyIfExist); 414 } 415 416 //_____________________________________________________________________________ 417 G4int G4VAnalysisReader::GetNofP1s(G4bool onlyIfExist) const 418 { 419 return fVP1Manager->GetNofHns(onlyIfExist); 420 } 421 422 //_____________________________________________________________________________ 423 G4int G4VAnalysisReader::GetNofP2s(G4bool onlyIfExist) const 424 { 425 return fVP2Manager->GetNofHns(onlyIfExist); 426 } 427 428 //_____________________________________________________________________________ 429 G4int G4VAnalysisReader::GetNofNtuples() const 430 { 431 return fVNtupleManager->GetNofNtuples(); 432 } 433 434 // GetH1Id(), GetH2Id in .icc 435 436 // Access methods in .icc 437 438 //_____________________________________________________________________________ 439 void G4VAnalysisReader::SetVerboseLevel(G4int verboseLevel) 440 { 441 fState.SetVerboseLevel(verboseLevel); 442 } 443 444 // GetVerboseLevel() in .icc 445