Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:59:12

0001 //
0002 // ********************************************************************
0003 // * License and Disclaimer                                           *
0004 // *                                                                  *
0005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
0006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
0007 // * conditions of the Geant4 Software License,  included in the file *
0008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
0009 // * include a list of copyright holders.                             *
0010 // *                                                                  *
0011 // * Neither the authors of this software system, nor their employing *
0012 // * institutes,nor the agencies providing financial support for this *
0013 // * work  make  any representation or  warranty, express or implied, *
0014 // * regarding  this  software system or assume any liability for its *
0015 // * use.  Please see the license in the file  LICENSE  and URL above *
0016 // * for the full disclaimer and the limitation of liability.         *
0017 // *                                                                  *
0018 // * This  code  implementation is the result of  the  scientific and *
0019 // * technical work of the GEANT4 collaboration.                      *
0020 // * By using,  copying,  modifying or  distributing the software (or *
0021 // * any work based  on the software)  you  agree  to acknowledge its *
0022 // * use  in  resulting  scientific  publications,  and indicate your *
0023 // * acceptance of all terms of the Geant4 Software license.          *
0024 // ********************************************************************
0025 //
0026 
0027 #include "G4HnInformation.hh"
0028 
0029 #include "G4THnToolsManager.hh"
0030 
0031 //_____________________________________________________________________________
0032 template <typename HT>
0033 inline
0034 G4bool G4ToolsAnalysisManager::WriteT(
0035   const std::vector<std::pair<HT*, G4HnInformation*>>& hnVector)
0036 {
0037   auto result = true;
0038 
0039   for ( auto& [ht, info] : hnVector) {
0040     auto activation = info->GetActivation();
0041 
0042     // skip writing if activation is enabled and H1 is inactivated
0043     // or if histogram was deleted
0044     if ( ( fState.GetIsActivation() && ( ! activation ) ) ||
0045          ( info->GetDeleted() ) ) continue;
0046 
0047     auto name = info->GetName();
0048     auto fileName = info->GetFileName();
0049     auto fileManager = GetFileManager(fileName);
0050 
0051     // skip writing if cannot get file manager (wrong file extension)
0052     if ( ! fileManager ) {
0053       G4Analysis::Warn(
0054         "Cannot get file manager for file " + fileName + ".\n" +
0055         "Writing " + G4Analysis::GetHnType<HT>() + " " +  name + " will be skipped.",
0056         fkClass, "WriteT");
0057       continue;
0058     }
0059 
0060     auto fileKind = " in file ";
0061     if ( fileName != "" ) {
0062       fileKind = " in extra file ";
0063     } else {
0064       fileName = fileManager->GetFullFileName();
0065     }
0066 
0067     // update name with a cycle number
0068     if (! fileManager->HasCycles() && fState.GetCycle() > 0) {
0069       name += "_v" + std::to_string(fState.GetCycle());
0070     }
0071 
0072     Message(G4Analysis::kVL4, "write", G4Analysis::GetHnType<HT>(),
0073       name + fileKind + fileName);
0074 
0075     if ( ! fileManager->template GetHnFileManager<HT>()->Write(ht, name, fileName) ) {
0076       G4Analysis::Warn(
0077         "Writing " + G4Analysis::GetHnType<HT>() + " " +  name +
0078         " to file " +  fileName + " failed.",
0079         fkClass, "WriteT");
0080       result = false;
0081     }
0082 
0083     if (result) {
0084       // notify that file has a written object
0085       fileManager->SetIsEmpty(fileName, false);
0086     }
0087 
0088     Message(G4Analysis::kVL3, "write", G4Analysis::GetHnType<HT>(),
0089       name + " in the " + fileKind + " file " + fileName);
0090   }
0091 
0092   return result;
0093 }
0094 
0095 //_____________________________________________________________________________
0096 inline
0097 G4bool G4ToolsAnalysisManager::IsOpenFileImpl() const
0098 {
0099   return fVFileManager->IsOpenFile();
0100 }
0101 
0102 //_____________________________________________________________________________
0103 inline
0104 tools::histo::h1d*  G4ToolsAnalysisManager::GetH1(G4int id, G4bool warn,
0105                                                  G4bool onlyIfActive) const
0106 {
0107   return fH1Manager->GetT(id, warn, onlyIfActive);
0108 }
0109 
0110 //_____________________________________________________________________________
0111 inline
0112 tools::histo::h2d*  G4ToolsAnalysisManager::GetH2(G4int id, G4bool warn,
0113                                                  G4bool onlyIfActive) const
0114 {
0115   return fH2Manager->GetT(id, warn, onlyIfActive);
0116 }
0117 
0118 //_____________________________________________________________________________
0119 inline
0120 tools::histo::h3d*  G4ToolsAnalysisManager::GetH3(G4int id, G4bool warn,
0121                                                  G4bool onlyIfActive) const
0122 {
0123   return fH3Manager->GetT(id, warn, onlyIfActive);
0124 }
0125 
0126 //_____________________________________________________________________________
0127 inline
0128 tools::histo::p1d*  G4ToolsAnalysisManager::GetP1(G4int id, G4bool warn,
0129                                                  G4bool onlyIfActive) const
0130 {
0131   return fP1Manager->GetT(id, warn, onlyIfActive);
0132 }
0133 
0134 //_____________________________________________________________________________
0135 inline
0136 tools::histo::p2d*  G4ToolsAnalysisManager::GetP2(G4int id, G4bool warn,
0137                                                  G4bool onlyIfActive) const
0138 {
0139   return fP2Manager->GetT(id, warn, onlyIfActive);
0140 }
0141 
0142 //_____________________________________________________________________________
0143 inline
0144 std::vector<tools::histo::h1d*>::iterator G4ToolsAnalysisManager::BeginH1()
0145 {
0146   return fH1Manager->BeginT();
0147 }
0148 
0149 //_____________________________________________________________________________
0150 inline
0151 std::vector<tools::histo::h1d*>::iterator G4ToolsAnalysisManager::EndH1()
0152 {
0153   return fH1Manager->EndT();
0154 }
0155 
0156 //_____________________________________________________________________________
0157 inline
0158 std::vector<tools::histo::h1d*>::const_iterator
0159 G4ToolsAnalysisManager::BeginConstH1() const
0160 {
0161   return fH1Manager->BeginConstT();
0162 }
0163 
0164 //_____________________________________________________________________________
0165 inline
0166 std::vector<tools::histo::h1d*>::const_iterator
0167 G4ToolsAnalysisManager::EndConstH1() const
0168 {
0169   return fH1Manager->EndConstT();
0170 }
0171 
0172 //_____________________________________________________________________________
0173 inline
0174 std::vector<tools::histo::h2d*>::iterator G4ToolsAnalysisManager::BeginH2()
0175 {
0176   return fH2Manager->BeginT();
0177 }
0178 
0179 //_____________________________________________________________________________
0180 inline
0181 std::vector<tools::histo::h2d*>::iterator G4ToolsAnalysisManager::EndH2()
0182 {
0183   return fH2Manager->EndT();
0184 }
0185 
0186 //_____________________________________________________________________________
0187 inline
0188 std::vector<tools::histo::h2d*>::const_iterator
0189 G4ToolsAnalysisManager::BeginConstH2() const
0190 {
0191   return fH2Manager->BeginConstT();
0192 }
0193 
0194 //_____________________________________________________________________________
0195 inline
0196 std::vector<tools::histo::h2d*>::const_iterator
0197 G4ToolsAnalysisManager::EndConstH2() const
0198 {
0199   return fH2Manager->EndConstT();
0200 }
0201 
0202 //_____________________________________________________________________________
0203 inline
0204 std::vector<tools::histo::h3d*>::iterator G4ToolsAnalysisManager::BeginH3()
0205 {
0206   return fH3Manager->BeginT();
0207 }
0208 
0209 //_____________________________________________________________________________
0210 inline
0211 std::vector<tools::histo::h3d*>::iterator G4ToolsAnalysisManager::EndH3()
0212 {
0213   return fH3Manager->EndT();
0214 }
0215 
0216 //_____________________________________________________________________________
0217 inline
0218 std::vector<tools::histo::h3d*>::const_iterator
0219 G4ToolsAnalysisManager::BeginConstH3() const
0220 {
0221   return fH3Manager->BeginConstT();
0222 }
0223 
0224 //_____________________________________________________________________________
0225 inline
0226 std::vector<tools::histo::h3d*>::const_iterator
0227 G4ToolsAnalysisManager::EndConstH3() const
0228 {
0229   return fH3Manager->EndConstT();
0230 }
0231 
0232 //_____________________________________________________________________________
0233 inline
0234 std::vector<tools::histo::p1d*>::iterator G4ToolsAnalysisManager::BeginP1()
0235 {
0236   return fP1Manager->BeginT();
0237 }
0238 
0239 //_____________________________________________________________________________
0240 inline
0241 std::vector<tools::histo::p1d*>::iterator G4ToolsAnalysisManager::EndP1()
0242 {
0243   return fP1Manager->EndT();
0244 }
0245 
0246 //_____________________________________________________________________________
0247 inline
0248 std::vector<tools::histo::p1d*>::const_iterator
0249 G4ToolsAnalysisManager::BeginConstP1() const
0250 {
0251   return fP1Manager->BeginConstT();
0252 }
0253 
0254 //_____________________________________________________________________________
0255 inline
0256 std::vector<tools::histo::p1d*>::const_iterator
0257 G4ToolsAnalysisManager::EndConstP1() const
0258 {
0259   return fP1Manager->EndConstT();
0260 }
0261 
0262 //_____________________________________________________________________________
0263 inline
0264 std::vector<tools::histo::p2d*>::iterator G4ToolsAnalysisManager::BeginP2()
0265 {
0266   return fP2Manager->BeginT();
0267 }
0268 
0269 //_____________________________________________________________________________
0270 inline
0271 std::vector<tools::histo::p2d*>::iterator G4ToolsAnalysisManager::EndP2()
0272 {
0273   return fP2Manager->EndT();
0274 }
0275 
0276 //_____________________________________________________________________________
0277 inline
0278 std::vector<tools::histo::p2d*>::const_iterator
0279 G4ToolsAnalysisManager::BeginConstP2() const
0280 {
0281   return fP2Manager->BeginConstT();
0282 }
0283 
0284 //_____________________________________________________________________________
0285 inline
0286 std::vector<tools::histo::p2d*>::const_iterator
0287 G4ToolsAnalysisManager::EndConstP2() const
0288 {
0289   return fP2Manager->EndConstT();
0290 }