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 10.5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /analysis/hdf5/src/G4Hdf5AnalysisReader.cc (Version 11.3.0) and /analysis/hdf5/src/G4Hdf5AnalysisReader.cc (Version 10.4.p1)


  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$
 26                                                    27 
 27 // Author: Ivana Hrivnacova, 20/07/2017 (ivana     28 // Author: Ivana Hrivnacova, 20/07/2017 (ivana@ipno.in2p3.fr)
 28                                                    29 
 29 #include "G4Hdf5AnalysisReader.hh"                 30 #include "G4Hdf5AnalysisReader.hh"
 30 #include "G4Hdf5RFileManager.hh"               << 
 31 #include "G4Hdf5RNtupleManager.hh"                 31 #include "G4Hdf5RNtupleManager.hh"
 32 #include "G4ThreadLocalSingleton.hh"           <<  32 #include "G4AnalysisVerbose.hh"
                                                   >>  33 #include "G4AnalysisUtilities.hh"
 33 #include "G4Threading.hh"                          34 #include "G4Threading.hh"
 34                                                    35 
                                                   >>  36 #include <iostream>
                                                   >>  37 #include <cstdio>
                                                   >>  38 
 35 using namespace G4Analysis;                        39 using namespace G4Analysis;
 36                                                    40 
                                                   >>  41 G4Hdf5AnalysisReader* G4Hdf5AnalysisReader::fgMasterInstance = nullptr;
                                                   >>  42 G4ThreadLocal G4Hdf5AnalysisReader* G4Hdf5AnalysisReader::fgInstance = nullptr;
                                                   >>  43 
 37 //____________________________________________     44 //_____________________________________________________________________________
 38 G4Hdf5AnalysisReader* G4Hdf5AnalysisReader::In     45 G4Hdf5AnalysisReader* G4Hdf5AnalysisReader::Instance()
 39 {                                                  46 {
 40   static G4ThreadLocalSingleton<G4Hdf5Analysis <<  47   if ( fgInstance == nullptr ) {
 41   return instance.Instance();                  <<  48     G4bool isMaster = ! G4Threading::IsWorkerThread();
 42 }                                              <<  49     fgInstance = new G4Hdf5AnalysisReader(isMaster);
                                                   >>  50   }
                                                   >>  51   
                                                   >>  52   return fgInstance;
                                                   >>  53 }    
 43                                                    54 
 44 //____________________________________________     55 //_____________________________________________________________________________
 45 G4Hdf5AnalysisReader::G4Hdf5AnalysisReader()   <<  56 G4Hdf5AnalysisReader::G4Hdf5AnalysisReader(G4bool isMaster)
 46  : G4ToolsAnalysisReader("Hdf5")               <<  57  : G4ToolsAnalysisReader("Hdf5", isMaster),
                                                   >>  58    fNtupleManager(nullptr),
                                                   >>  59    fFileManager(nullptr)
 47 {                                                  60 {
 48   if ( ! G4Threading::IsWorkerThread() ) fgMas <<  61   if ( ( isMaster && fgMasterInstance ) || ( fgInstance ) ) {
                                                   >>  62     G4ExceptionDescription description;
                                                   >>  63     description 
                                                   >>  64       << "      " 
                                                   >>  65       << "G4Hdf5AnalysisReader already exists." 
                                                   >>  66       << "Cannot create another instance.";
                                                   >>  67     G4Exception("G4Hdf5AnalysisReader::G4Hdf5AnalysisReader()",
                                                   >>  68                 "Analysis_F001", FatalException, description);
                                                   >>  69   }
                                                   >>  70   if ( isMaster ) fgMasterInstance = this;
                                                   >>  71   fgInstance = this;
 49                                                    72 
 50   // Create managers                               73   // Create managers
 51   fNtupleManager = std::make_shared<G4Hdf5RNtu <<  74   fNtupleManager = new G4Hdf5RNtupleManager(fState);
 52   fFileManager = std::make_shared<G4Hdf5RFileM <<  75   fFileManager = new G4Hdf5RFileManager(fState);
 53   fNtupleManager->SetFileManager(fFileManager) <<  76   
 54                                                << 
 55   // Set managers to base class                    77   // Set managers to base class
 56   SetNtupleManager(fNtupleManager);                78   SetNtupleManager(fNtupleManager);
 57   SetFileManager(fFileManager);                    79   SetFileManager(fFileManager);
 58 }                                                  80 }
 59                                                    81 
 60 //____________________________________________     82 //_____________________________________________________________________________
 61 G4Hdf5AnalysisReader::~G4Hdf5AnalysisReader()      83 G4Hdf5AnalysisReader::~G4Hdf5AnalysisReader()
 62 {                                                  84 {
 63   if ( fState.GetIsMaster() ) fgMasterInstance     85   if ( fState.GetIsMaster() ) fgMasterInstance = nullptr;
                                                   >>  86   fgInstance = nullptr;
 64 }                                                  87 }
 65                                                    88 
 66 //                                             <<  89 // 
 67 // private methods                                 90 // private methods
 68 //                                                 91 //
 69                                                    92 
 70 //____________________________________________     93 //_____________________________________________________________________________
 71 G4bool G4Hdf5AnalysisReader::Reset()               94 G4bool G4Hdf5AnalysisReader::Reset()
 72 {                                                  95 {
 73 // Reset histograms and ntuple                     96 // Reset histograms and ntuple
 74                                                    97 
 75   auto result = true;                          <<  98   auto finalResult = true;
 76                                                <<  99   
 77   result &= G4ToolsAnalysisReader::Reset();    << 100   auto result = G4ToolsAnalysisReader::Reset();
 78   result &= fNtupleManager->Reset();           << 101   finalResult = finalResult && result;
 79                                                << 102 
 80   return result;                               << 103   result = fNtupleManager->Reset();
 81 }                                              << 104   finalResult = finalResult && result;
 82                                                << 105   
 83 //                                             << 106   return finalResult;
                                                   >> 107 }  
                                                   >> 108  
                                                   >> 109 // 
 84 // protected methods                              110 // protected methods
 85 //                                                111 //
 86                                                   112 
 87 //____________________________________________    113 //_____________________________________________________________________________
 88 G4bool  G4Hdf5AnalysisReader::CloseFilesImpl(G << 114 G4int G4Hdf5AnalysisReader::ReadH1Impl(const G4String& h1Name, 
                                                   >> 115                                        const G4String& fileName,
                                                   >> 116                                        const G4String& dirName,
                                                   >> 117                                        G4bool /*isUserFileName*/)
 89 {                                                 118 {
 90   Message(kVL4, "close", "files");             << 119 #ifdef G4VERBOSE
                                                   >> 120   if ( fState.GetVerboseL4() ) 
                                                   >> 121     fState.GetVerboseL4()->Message("read", "h1", h1Name);
                                                   >> 122 #endif
                                                   >> 123 
                                                   >> 124   auto h1 = ReadHnImpl<tools::histo::h1d>(h1Name, fileName, dirName);
                                                   >> 125  
                                                   >> 126   if ( ! h1 ) return kInvalidId;
                                                   >> 127   
                                                   >> 128   auto id = fH1Manager->AddH1(h1Name, h1);
                                                   >> 129 
                                                   >> 130 #ifdef G4VERBOSE
                                                   >> 131   if ( fState.GetVerboseL2() ) 
                                                   >> 132     fState.GetVerboseL2()->Message("read", "h1", h1Name, id > kInvalidId);
                                                   >> 133 #endif
                                                   >> 134   
                                                   >> 135   return id;
                                                   >> 136 }  
 91                                                   137 
 92   auto result = true;                          << 138 //_____________________________________________________________________________
                                                   >> 139 G4int G4Hdf5AnalysisReader::ReadH2Impl(const G4String& h2Name, 
                                                   >> 140                                        const G4String& fileName,
                                                   >> 141                                        const G4String& dirName,
                                                   >> 142                                        G4bool /*isUserFileName*/)
                                                   >> 143 {
                                                   >> 144 #ifdef G4VERBOSE
                                                   >> 145   if ( fState.GetVerboseL4() ) 
                                                   >> 146     fState.GetVerboseL4()->Message("read", "h2", h2Name);
                                                   >> 147 #endif
                                                   >> 148 
                                                   >> 149   auto h2 = ReadHnImpl<tools::histo::h2d>(h2Name, fileName, dirName);
                                                   >> 150  
                                                   >> 151   if ( ! h2 ) return kInvalidId;
                                                   >> 152   
                                                   >> 153   auto id = fH2Manager->AddH2(h2Name, h2);
                                                   >> 154   
                                                   >> 155 #ifdef G4VERBOSE
                                                   >> 156   if ( fState.GetVerboseL2() ) 
                                                   >> 157     fState.GetVerboseL2()->Message("read", "h2", h2Name, id > kInvalidId);
                                                   >> 158 #endif
                                                   >> 159   
                                                   >> 160   return id;  
                                                   >> 161 }  
 93                                                   162 
 94   if (reset) {                                 << 163 //_____________________________________________________________________________
 95     result &= Reset();                         << 164 G4int G4Hdf5AnalysisReader::ReadH3Impl(const G4String& h3Name, 
 96   }                                            << 165                                        const G4String& fileName,
                                                   >> 166                                        const G4String& dirName,
                                                   >> 167                                        G4bool /*isUserFileName*/)
                                                   >> 168 {
 97                                                   169 
 98   fFileManager->CloseFiles();                  << 170 #ifdef G4VERBOSE
                                                   >> 171   if ( fState.GetVerboseL4() ) 
                                                   >> 172     fState.GetVerboseL4()->Message("read", "h3", h3Name);
                                                   >> 173 #endif
                                                   >> 174 
                                                   >> 175   auto h3 = ReadHnImpl<tools::histo::h3d>(h3Name, fileName, dirName);
                                                   >> 176  
                                                   >> 177   if ( ! h3 ) return kInvalidId;
                                                   >> 178     
                                                   >> 179   auto id = fH3Manager->AddH3(h3Name, h3);
                                                   >> 180   
                                                   >> 181 #ifdef G4VERBOSE
                                                   >> 182   if ( fState.GetVerboseL2() ) 
                                                   >> 183     fState.GetVerboseL2()->Message("read", "h3", h3Name, id > kInvalidId);
                                                   >> 184 #endif
                                                   >> 185   
                                                   >> 186   return id;  
                                                   >> 187 }  
 99                                                   188 
100   Message(kVL2, "close", "files", "", result); << 189 //_____________________________________________________________________________
                                                   >> 190 G4int G4Hdf5AnalysisReader::ReadP1Impl(const G4String& p1Name, 
                                                   >> 191                                        const G4String& fileName,
                                                   >> 192                                        const G4String& dirName,
                                                   >> 193                                        G4bool /*isUserFileName*/)
                                                   >> 194 {
                                                   >> 195 #ifdef G4VERBOSE
                                                   >> 196   if ( fState.GetVerboseL4() ) 
                                                   >> 197     fState.GetVerboseL4()->Message("read", "p1", p1Name);
                                                   >> 198 #endif
                                                   >> 199 
                                                   >> 200   auto p1 = ReadPnImpl<tools::histo::p1d>(p1Name, fileName, dirName);
                                                   >> 201  
                                                   >> 202   if ( ! p1 ) return kInvalidId;
                                                   >> 203   
                                                   >> 204   auto id = fP1Manager->AddP1(p1Name, p1);
                                                   >> 205 
                                                   >> 206 #ifdef G4VERBOSE
                                                   >> 207   if ( fState.GetVerboseL2() ) 
                                                   >> 208     fState.GetVerboseL2()->Message("read", "p1", p1Name, id > kInvalidId);
                                                   >> 209 #endif
                                                   >> 210   
                                                   >> 211   return id;  
                                                   >> 212 }  
101                                                   213 
102   return result;                               << 214 //_____________________________________________________________________________
103 }                                              << 215 G4int G4Hdf5AnalysisReader::ReadP2Impl(const G4String& p2Name, 
                                                   >> 216                                        const G4String& fileName,
                                                   >> 217                                        const G4String& dirName,
                                                   >> 218                                        G4bool /*isUserFileName*/)
                                                   >> 219 {
                                                   >> 220 
                                                   >> 221 #ifdef G4VERBOSE
                                                   >> 222   if ( fState.GetVerboseL4() ) 
                                                   >> 223     fState.GetVerboseL4()->Message("read", "p2", p2Name);
                                                   >> 224 #endif
                                                   >> 225 
                                                   >> 226   auto p2 = ReadPnImpl<tools::histo::p2d>(p2Name, fileName, dirName);
                                                   >> 227  
                                                   >> 228   if ( ! p2 ) return kInvalidId;
                                                   >> 229   
                                                   >> 230   auto id = fP2Manager->AddP2(p2Name, p2);
                                                   >> 231   
                                                   >> 232 #ifdef G4VERBOSE
                                                   >> 233   if ( fState.GetVerboseL2() ) 
                                                   >> 234     fState.GetVerboseL2()->Message("read", "p2", p2Name, id > kInvalidId);
                                                   >> 235 #endif
                                                   >> 236   
                                                   >> 237   return id;  
                                                   >> 238 }  
                                                   >> 239 
                                                   >> 240 //_____________________________________________________________________________
                                                   >> 241 G4int G4Hdf5AnalysisReader::ReadNtupleImpl(const G4String& ntupleName, 
                                                   >> 242                                            const G4String& fileName,
                                                   >> 243                                            const G4String& dirName,
                                                   >> 244                                            G4bool isUserFileName)
                                                   >> 245 {
                                                   >> 246 #ifdef G4VERBOSE
                                                   >> 247   if ( fState.GetVerboseL4() ) 
                                                   >> 248     fState.GetVerboseL4()->Message("read", "ntuple", ntupleName);
                                                   >> 249 #endif
                                                   >> 250 
                                                   >> 251   // Ntuples are saved in files per thread
                                                   >> 252   // but apply thethe thread suffix only if fileName is not provided explicitly
                                                   >> 253   G4String fullFileName = fileName;
                                                   >> 254   if ( ! isUserFileName ) {
                                                   >> 255     fullFileName = fFileManager->GetFullFileName();
                                                   >> 256   }  
                                                   >> 257 
                                                   >> 258   // Get directory
                                                   >> 259   auto directory = fFileManager->GetNtupleRDirectory(fullFileName, dirName, false);
                                                   >> 260   if ( directory < 0 ) return kInvalidId;
                                                   >> 261 
                                                   >> 262   // Create ntuple 
                                                   >> 263   auto rntuple = new tools::hdf5::ntuple(G4cout, directory, ntupleName);
                                                   >> 264   auto rntupleDescription = new G4TRNtupleDescription<tools::hdf5::ntuple>(rntuple);
                                                   >> 265   auto id = fNtupleManager->SetNtuple(rntupleDescription);
                                                   >> 266   
                                                   >> 267 #ifdef G4VERBOSE
                                                   >> 268   if ( fState.GetVerboseL2() ) 
                                                   >> 269     fState.GetVerboseL2()->Message("read", "ntuple", ntupleName, id > kInvalidId);
                                                   >> 270 #endif
                                                   >> 271 
                                                   >> 272   return id;
                                                   >> 273 }  
104                                                   274