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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/xml/src/G4XmlAnalysisReader.cc (Version 11.3.0) and /analysis/xml/src/G4XmlAnalysisReader.cc (Version 10.2.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: G4XmlAnalysisReader.cc 74257 2013-10-02 14:24:55Z gcosmo $
 26                                                    27 
 27 // Author: Ivana Hrivnacova, 25/07/2014 (ivana     28 // Author: Ivana Hrivnacova, 25/07/2014 (ivana@ipno.in2p3.fr)
 28                                                    29 
 29 #include "G4XmlAnalysisReader.hh"                  30 #include "G4XmlAnalysisReader.hh"
 30 #include "G4XmlRFileManager.hh"                    31 #include "G4XmlRFileManager.hh"
                                                   >>  32 #include "G4H1ToolsManager.hh"
                                                   >>  33 #include "G4H2ToolsManager.hh"
                                                   >>  34 #include "G4H3ToolsManager.hh"
                                                   >>  35 #include "G4P1ToolsManager.hh"
                                                   >>  36 #include "G4P2ToolsManager.hh"
 31 #include "G4XmlRNtupleManager.hh"                  37 #include "G4XmlRNtupleManager.hh"
                                                   >>  38 #include "G4XmlRNtupleDescription.hh"
                                                   >>  39 #include "G4AnalysisVerbose.hh"
 32 #include "G4AnalysisUtilities.hh"                  40 #include "G4AnalysisUtilities.hh"
 33 #include "G4ThreadLocalSingleton.hh"           << 
 34 #include "G4Threading.hh"                          41 #include "G4Threading.hh"
 35                                                    42 
                                                   >>  43 #include <iostream>
                                                   >>  44 #include <cstdio>
                                                   >>  45 
 36 using namespace G4Analysis;                        46 using namespace G4Analysis;
 37                                                    47 
                                                   >>  48 G4XmlAnalysisReader* G4XmlAnalysisReader::fgMasterInstance = nullptr;
                                                   >>  49 G4ThreadLocal G4XmlAnalysisReader* G4XmlAnalysisReader::fgInstance = 0;
                                                   >>  50 
 38 //____________________________________________     51 //_____________________________________________________________________________
 39 G4XmlAnalysisReader* G4XmlAnalysisReader::Inst     52 G4XmlAnalysisReader* G4XmlAnalysisReader::Instance()
 40 {                                                  53 {
 41   static G4ThreadLocalSingleton<G4XmlAnalysisR <<  54   if ( fgInstance == nullptr ) {
 42   return instance.Instance();                  <<  55     G4bool isMaster = ! G4Threading::IsWorkerThread();
 43 }                                              <<  56     fgInstance = new G4XmlAnalysisReader(isMaster);
                                                   >>  57   }
                                                   >>  58   
                                                   >>  59   return fgInstance;
                                                   >>  60 }    
 44                                                    61 
 45 //____________________________________________     62 //_____________________________________________________________________________
 46 G4XmlAnalysisReader::G4XmlAnalysisReader()     <<  63 G4XmlAnalysisReader::G4XmlAnalysisReader(G4bool isMaster)
 47  : G4ToolsAnalysisReader("Xml")                <<  64  : G4ToolsAnalysisReader("Xml", isMaster),
                                                   >>  65    fNtupleManager(nullptr),
                                                   >>  66    fFileManager(nullptr)
 48 {                                                  67 {
 49   if ( ! G4Threading::IsWorkerThread() ) fgMas <<  68   if ( ( isMaster && fgMasterInstance ) || ( fgInstance ) ) {
                                                   >>  69     G4ExceptionDescription description;
                                                   >>  70     description 
                                                   >>  71       << "      " 
                                                   >>  72       << "G4XmlAnalysisReader already exists." 
                                                   >>  73       << "Cannot create another instance.";
                                                   >>  74     G4Exception("G4XmlAnalysisReader::G4XmlAnalysisReader()",
                                                   >>  75                 "Analysis_F001", FatalException, description);
                                                   >>  76   }
                                                   >>  77   if ( isMaster ) fgMasterInstance = this;
                                                   >>  78   fgInstance = this;
 50                                                    79 
 51   // Create managers                               80   // Create managers
 52   fNtupleManager = std::make_shared<G4XmlRNtup <<  81   fNtupleManager = new G4XmlRNtupleManager(fState);
 53   fFileManager = std::make_shared<G4XmlRFileMa <<  82   fFileManager = new G4XmlRFileManager(fState);
 54   fNtupleManager->SetFileManager(fFileManager) <<  83       // The managers will be deleted by the base class
 55                                                <<  84   
 56   // Set managers to base class                    85   // Set managers to base class
 57   SetNtupleManager(fNtupleManager);                86   SetNtupleManager(fNtupleManager);
 58   SetFileManager(fFileManager);                    87   SetFileManager(fFileManager);
 59 }                                                  88 }
 60                                                    89 
 61 //____________________________________________     90 //_____________________________________________________________________________
 62 G4XmlAnalysisReader::~G4XmlAnalysisReader()        91 G4XmlAnalysisReader::~G4XmlAnalysisReader()
 63 {                                                  92 {
 64   if ( fState.GetIsMaster() ) fgMasterInstance     93   if ( fState.GetIsMaster() ) fgMasterInstance = nullptr;
                                                   >>  94   fgInstance = nullptr;
 65 }                                                  95 }
 66                                                    96 
 67 //                                             <<  97 // 
 68 // private methods                                 98 // private methods
 69 //                                                 99 //
 70                                                   100 
 71 //____________________________________________    101 //_____________________________________________________________________________
 72 G4bool G4XmlAnalysisReader::Reset()            << 102 tools::raxml_out* G4XmlAnalysisReader::GetHandler(
                                                   >> 103                              const G4String& fileName, 
                                                   >> 104                              const G4String& objectName,
                                                   >> 105                              const G4String& objectType,
                                                   >> 106                              const G4String& inFunction)
 73 {                                                 107 {
 74 // Reset histograms and ntuple                 << 108 // Get buffer for reading object specified by objectName and objectType
 75                                                << 109 // for a file specified by fileName; 
 76   auto result = true;                          << 110 // open the file if it was not yet open 
                                                   >> 111 
                                                   >> 112   // Histograms and profiles are not saved per thread
                                                   >> 113   // and ntuple file name is already updated
                                                   >> 114   auto rfile = fFileManager->GetRFile(fileName);
                                                   >> 115   if ( ! rfile ) {
                                                   >> 116     if ( ! fFileManager->OpenRFile(fileName) ) return nullptr;
                                                   >> 117     rfile = fFileManager->GetRFile(fileName);
                                                   >> 118   }
 77                                                   119 
 78   result &= G4ToolsAnalysisReader::Reset();    << 120   tools::raxml_out* handler = nullptr;
 79   result &= fNtupleManager->Reset();           << 121   if ( rfile ) {
                                                   >> 122     std::vector<tools::raxml_out>& objects = rfile->objects();
                                                   >> 123     std::vector<tools::raxml_out>::iterator it;
                                                   >> 124     for (it = objects.begin(); it!=objects.end(); ++it) {
                                                   >> 125       tools::raxml_out& object = *it;
                                                   >> 126       if ( object.cls() == objectType && object.name() == objectName ) {
                                                   >> 127         handler = &object;
                                                   >> 128         break;
                                                   >> 129       }  
                                                   >> 130     }
                                                   >> 131   }  
                                                   >> 132   
                                                   >> 133   if ( ! handler ) {
                                                   >> 134     G4ExceptionDescription description;
                                                   >> 135     description 
                                                   >> 136       << "      " 
                                                   >> 137       << "Cannot get "<< objectName << " in file " << fileName; 
                                                   >> 138     G4String inFunctionFull = "G4XmlAnalysisReader::";
                                                   >> 139     inFunctionFull.append(inFunction);
                                                   >> 140     G4Exception(inFunctionFull, "Analysis_WR011", JustWarning, description);
                                                   >> 141     return nullptr;
                                                   >> 142   }
                                                   >> 143   
                                                   >> 144   return handler;  
                                                   >> 145 }                             
 80                                                   146 
 81   return result;                               << 147 //_____________________________________________________________________________
 82 }                                              << 148 G4bool G4XmlAnalysisReader::Reset()
                                                   >> 149 {
                                                   >> 150 // Reset histograms and ntuple
 83                                                   151 
 84 //                                             << 152   auto finalResult = true;
                                                   >> 153   
                                                   >> 154   auto result = G4ToolsAnalysisReader::Reset();
                                                   >> 155   finalResult = finalResult && result;
                                                   >> 156   
                                                   >> 157   result = fNtupleManager->Reset();
                                                   >> 158   finalResult = finalResult && result;
                                                   >> 159   
                                                   >> 160   return finalResult;
                                                   >> 161 }  
                                                   >> 162  
                                                   >> 163 // 
 85 // protected methods                              164 // protected methods
 86 //                                                165 //
 87                                                   166 
 88 //____________________________________________    167 //_____________________________________________________________________________
 89 G4bool  G4XmlAnalysisReader::CloseFilesImpl(G4 << 168 G4int G4XmlAnalysisReader::ReadH1Impl(const G4String& h1Name, 
                                                   >> 169                                       const G4String& fileName,
                                                   >> 170                                       G4bool /*isUserFileName*/)
 90 {                                                 171 {
 91   Message(kVL4, "close", "files");             << 172 #ifdef G4VERBOSE
                                                   >> 173   if ( fState.GetVerboseL4() ) 
                                                   >> 174     fState.GetVerboseL4()->Message("read", "h1", h1Name);
                                                   >> 175 #endif
                                                   >> 176 
                                                   >> 177   tools::raxml_out* handler
                                                   >> 178     = GetHandler(fileName, h1Name, tools::histo::h1d::s_class(), "ReadH1Impl");
                                                   >> 179   if ( ! handler ) return kInvalidId;
                                                   >> 180 
                                                   >> 181   auto h1 = static_cast<tools::histo::h1d*>(handler->object());
                                                   >> 182   auto id = fH1Manager->AddH1(h1Name, h1);
                                                   >> 183 
                                                   >> 184 #ifdef G4VERBOSE
                                                   >> 185   if ( fState.GetVerboseL2() ) 
                                                   >> 186     fState.GetVerboseL2()->Message("read", "h1", h1Name, id > kInvalidId);
                                                   >> 187 #endif
                                                   >> 188   
                                                   >> 189   return id;  
                                                   >> 190 }  
 92                                                   191 
 93   auto result = true;                          << 192 //_____________________________________________________________________________
                                                   >> 193 G4int G4XmlAnalysisReader::ReadH2Impl(const G4String& h2Name, 
                                                   >> 194                                       const G4String& fileName,
                                                   >> 195                                       G4bool /*isUserFileName*/)
                                                   >> 196 {
                                                   >> 197 #ifdef G4VERBOSE
                                                   >> 198   if ( fState.GetVerboseL4() ) 
                                                   >> 199     fState.GetVerboseL4()->Message("read", "h2", h2Name);
                                                   >> 200 #endif
                                                   >> 201 
                                                   >> 202   auto handler
                                                   >> 203     = GetHandler(fileName, h2Name, tools::histo::h2d::s_class(), "ReadH2Impl");
                                                   >> 204   if ( ! handler ) return kInvalidId;
                                                   >> 205 
                                                   >> 206   auto h2 = static_cast<tools::histo::h2d*>(handler->object());
                                                   >> 207   auto id = fH2Manager->AddH2(h2Name, h2);
                                                   >> 208 
                                                   >> 209 #ifdef G4VERBOSE
                                                   >> 210   if ( fState.GetVerboseL2() ) 
                                                   >> 211     fState.GetVerboseL2()->Message("read", "h2", h2Name, id > kInvalidId);
                                                   >> 212 #endif
                                                   >> 213   
                                                   >> 214   return id;  
                                                   >> 215 }  
 94                                                   216 
 95   if (reset) {                                 << 217 //_____________________________________________________________________________
 96     result &= Reset();                         << 218 G4int G4XmlAnalysisReader::ReadH3Impl(const G4String& h3Name, 
 97   }                                            << 219                                       const G4String& fileName,
                                                   >> 220                                       G4bool /*isUserFileName*/)
                                                   >> 221 {
                                                   >> 222 #ifdef G4VERBOSE
                                                   >> 223   if ( fState.GetVerboseL4() ) 
                                                   >> 224     fState.GetVerboseL4()->Message("read", "h3", h3Name);
                                                   >> 225 #endif
                                                   >> 226 
                                                   >> 227   auto handler
                                                   >> 228     = GetHandler(fileName, h3Name, tools::histo::h3d::s_class(), "ReadH3Impl");
                                                   >> 229   if ( ! handler ) return kInvalidId;
                                                   >> 230 
                                                   >> 231   auto h3 = static_cast<tools::histo::h3d*>(handler->object());
                                                   >> 232   auto id = fH3Manager->AddH3(h3Name, h3);
                                                   >> 233 
                                                   >> 234 #ifdef G4VERBOSE
                                                   >> 235   if ( fState.GetVerboseL2() ) 
                                                   >> 236     fState.GetVerboseL2()->Message("read", "h3", h3Name, id > kInvalidId);
                                                   >> 237 #endif
                                                   >> 238   
                                                   >> 239   return id;  
                                                   >> 240 }  
 98                                                   241 
 99   fFileManager->CloseFiles();                  << 242 //_____________________________________________________________________________
                                                   >> 243 G4int G4XmlAnalysisReader::ReadP1Impl(const G4String& p1Name, 
                                                   >> 244                                       const G4String& fileName,
                                                   >> 245                                       G4bool /*isUserFileName*/)
                                                   >> 246 {
                                                   >> 247 #ifdef G4VERBOSE
                                                   >> 248   if ( fState.GetVerboseL4() ) 
                                                   >> 249     fState.GetVerboseL4()->Message("read", "p1", p1Name);
                                                   >> 250 #endif
                                                   >> 251 
                                                   >> 252   auto handler
                                                   >> 253     = GetHandler(fileName, p1Name, tools::histo::p1d::s_class(), "ReadP1Impl");
                                                   >> 254   if ( ! handler ) return kInvalidId;
                                                   >> 255 
                                                   >> 256   auto p1 = static_cast<tools::histo::p1d*>(handler->object());
                                                   >> 257   auto id = fP1Manager->AddP1(p1Name, p1);
                                                   >> 258 
                                                   >> 259 #ifdef G4VERBOSE
                                                   >> 260   if ( fState.GetVerboseL2() ) 
                                                   >> 261     fState.GetVerboseL2()->Message("read", "p1", p1Name, id > kInvalidId);
                                                   >> 262 #endif
                                                   >> 263   
                                                   >> 264   return id;  
                                                   >> 265 }  
100                                                   266 
101   Message(kVL2, "close", "files", "", result); << 267 //_____________________________________________________________________________
                                                   >> 268 G4int G4XmlAnalysisReader::ReadP2Impl(const G4String& p2Name, 
                                                   >> 269                                       const G4String& fileName,
                                                   >> 270                                       G4bool /*isUserFileName*/)
                                                   >> 271 {
                                                   >> 272 #ifdef G4VERBOSE
                                                   >> 273   if ( fState.GetVerboseL4() ) 
                                                   >> 274     fState.GetVerboseL4()->Message("read", "p2", p2Name);
                                                   >> 275 #endif
                                                   >> 276 
                                                   >> 277   auto handler
                                                   >> 278     = GetHandler(fileName, p2Name, tools::histo::p2d::s_class(), "ReadP2Impl");
                                                   >> 279   if ( ! handler ) return kInvalidId;
                                                   >> 280 
                                                   >> 281   auto p2 = static_cast<tools::histo::p2d*>(handler->object());
                                                   >> 282   auto id = fP2Manager->AddP2(p2Name, p2);
                                                   >> 283 
                                                   >> 284 #ifdef G4VERBOSE
                                                   >> 285   if ( fState.GetVerboseL2() ) 
                                                   >> 286     fState.GetVerboseL2()->Message("read", "p2", p2Name, id > kInvalidId);
                                                   >> 287 #endif
                                                   >> 288   
                                                   >> 289   return id;  
                                                   >> 290 }  
102                                                   291 
103   return result;                               << 292 //_____________________________________________________________________________
104 }                                              << 293 G4int G4XmlAnalysisReader::ReadNtupleImpl(const G4String& ntupleName, 
                                                   >> 294                                           const G4String& fileName,
                                                   >> 295                                           G4bool isUserFileName)
                                                   >> 296 {
                                                   >> 297 #ifdef G4VERBOSE
                                                   >> 298   if ( fState.GetVerboseL4() ) 
                                                   >> 299     fState.GetVerboseL4()->Message("read", "ntuple", ntupleName);
                                                   >> 300 #endif
                                                   >> 301 
                                                   >> 302   // Ntuples are saved per object and per thread
                                                   >> 303   // but apply the ntuple name and the thread suffixes
                                                   >> 304   // only if fileName is not provided explicitly
                                                   >> 305   auto fullFileName = fileName;
                                                   >> 306   if ( ! isUserFileName ) {
                                                   >> 307     fullFileName = fFileManager->GetNtupleFileName(ntupleName);
                                                   >> 308   }  
                                                   >> 309 
                                                   >> 310   auto handler
                                                   >> 311     = GetHandler(fullFileName, ntupleName, tools::aida::ntuple::s_class(), 
                                                   >> 312                  "ReadNtupleImpl");
                                                   >> 313   if ( ! handler ) return kInvalidId;
                                                   >> 314 
                                                   >> 315   auto rntuple = static_cast<tools::aida::ntuple*>(handler->object());
                                                   >> 316   auto id = fNtupleManager->SetNtuple(new G4XmlRNtupleDescription(rntuple));
                                                   >> 317   
                                                   >> 318 #ifdef G4VERBOSE
                                                   >> 319   if ( fState.GetVerboseL2() ) 
                                                   >> 320     fState.GetVerboseL2()->Message("read", "ntuple", ntupleName, id > kInvalidId);
                                                   >> 321 #endif
                                                   >> 322   
                                                   >> 323   return id;
                                                   >> 324 }  
105                                                   325