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] [ 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/root/src/G4RootRNtupleManager.cc (Version 11.3.0) and /analysis/root/src/G4RootRNtupleManager.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: G4RootRNtupleManager.cc 70604 2013-06-03 11:27:06Z ihrivnac $
 26                                                    27 
 27 // Author: Ivana Hrivnacova, 09/04/2014 (ivana     28 // Author: Ivana Hrivnacova, 09/04/2014 (ivana@ipno.in2p3.fr)
 28                                                    29 
 29 #include "G4RootRNtupleManager.hh"                 30 #include "G4RootRNtupleManager.hh"
 30 #include "G4RootRFileManager.hh"               << 
 31 #include "G4AnalysisManagerState.hh"               31 #include "G4AnalysisManagerState.hh"
 32 #include "G4AnalysisUtilities.hh"              << 
 33                                                << 
 34 #include "tools/rroot/file"                    << 
 35 #include "tools/rroot/rall"                    << 
 36 #include "tools/rroot/streamers"               << 
 37 #include "tools/rroot/fac"                     << 
 38 #include "tools/rroot/tree"                    << 
 39                                                << 
 40 using namespace G4Analysis;                    << 
 41                                                    32 
 42 //____________________________________________     33 //_____________________________________________________________________________
 43 G4RootRNtupleManager::G4RootRNtupleManager(con     34 G4RootRNtupleManager::G4RootRNtupleManager(const G4AnalysisManagerState& state)
 44  : G4TRNtupleManager<tools::rroot::ntuple>(sta     35  : G4TRNtupleManager<tools::rroot::ntuple>(state)
 45 {}                                                 36 {}
 46                                                    37 
 47 //                                             << 
 48 // private methods                             << 
 49 //                                             << 
 50                                                << 
 51 //____________________________________________     38 //_____________________________________________________________________________
 52 G4int G4RootRNtupleManager::ReadNtupleImpl(con <<  39 G4RootRNtupleManager::~G4RootRNtupleManager()
 53                                            con <<  40 {}
 54                                            con << 
 55                                            G4b << 
 56 {                                              << 
 57   Message(kVL4, "read", "ntuple", ntupleName); << 
 58                                                << 
 59   // Ntuples are saved per thread              << 
 60   // but do not apply the thread suffix if fil << 
 61   auto isPerThread = true;                     << 
 62   if ( isUserFileName ) isPerThread = false;   << 
 63                                                << 
 64   // Get or open a file                        << 
 65   auto rfileTuple = fFileManager->GetRFile(fil << 
 66   if (rfileTuple == nullptr) {                 << 
 67     if ( ! fFileManager->OpenRFile(fileName, i << 
 68     rfileTuple = fFileManager->GetRFile(fileNa << 
 69   }                                            << 
 70   auto rfile = std::get<0>(*rfileTuple);       << 
 71                                                << 
 72   // Get or open a directory if dirName is def << 
 73   tools::rroot::TDirectory* ntupleDirectory =  << 
 74   if ( ntupleDirectory == nullptr ) {          << 
 75     // Retrieve directory only once as analysi << 
 76     // 1 ntuple directory par file)            << 
 77     if ( ! dirName.empty() ) {                 << 
 78       ntupleDirectory = tools::rroot::find_dir << 
 79       if ( ntupleDirectory != nullptr ) {      << 
 80         std::get<2>(*rfileTuple) = ntupleDirec << 
 81       }                                        << 
 82       else {                                   << 
 83         G4Analysis::Warn(                      << 
 84           "Directory " + dirName + " not found << 
 85           fkClass, "ReadNtupleImpl");          << 
 86         return kInvalidId;                     << 
 87       }                                        << 
 88     }                                          << 
 89   }                                            << 
 90                                                << 
 91   // Get key                                   << 
 92   tools::rroot::key* key = nullptr;            << 
 93   if ( ntupleDirectory != nullptr ) {          << 
 94     key = ntupleDirectory->find_key(ntupleName << 
 95   }                                            << 
 96   else {                                       << 
 97     key = rfile->dir().find_key(ntupleName);   << 
 98   }                                            << 
 99   if (key == nullptr) {                        << 
100     Warn("Key " + ntupleName + " for Ntuple no << 
101       ", directory " + dirName, fkClass, "Read << 
102     return kInvalidId;                         << 
103   }                                            << 
104                                                << 
105   unsigned int size;                           << 
106   char* charBuffer = key->get_object_buffer(*r << 
107   if (charBuffer == nullptr) {                 << 
108     Warn("Cannot get data buffer for Ntuple "  << 
109          " in file " + fileName, fkClass, "Rea << 
110     return kInvalidId;                         << 
111   }                                            << 
112                                                << 
113   auto verbose = false;                        << 
114   auto buffer                                  << 
115     = new tools::rroot::buffer(G4cout, rfile-> << 
116                                key->key_length << 
117   buffer->set_map_objs(true);                  << 
118                                                << 
119   auto fac = new tools::rroot::fac(G4cout);    << 
120                                                << 
121   auto tree = new tools::rroot::tree(*rfile, * << 
122   if ( ! tree->stream(*buffer) ) {             << 
123     Warn("TTree streaming failed for Ntuple "  << 
124          " in file " + fileName,               << 
125          fkClass, "ReadNtupleImpl");           << 
126                                                << 
127     delete buffer;                             << 
128     delete tree;                               << 
129     return kInvalidId;                         << 
130   }                                            << 
131                                                << 
132   auto rntuple  = new tools::rroot::ntuple(*tr << 
133   auto rntupleDescription = new G4TRNtupleDesc << 
134                                                << 
135   auto id = SetNtuple(rntupleDescription);     << 
136                                                << 
137                                                << 
138   Message(kVL2, "read", "ntuple", ntupleName,  << 
139                                                    41 
140   return id;                                   <<  42 // 
141 }                                              <<  43 // private methods
                                                   >>  44 //
142                                                    45 
143 //____________________________________________     46 //_____________________________________________________________________________
144 G4bool G4RootRNtupleManager::GetTNtupleRow(        47 G4bool G4RootRNtupleManager::GetTNtupleRow(
145   G4TRNtupleDescription<tools::rroot::ntuple>*     48   G4TRNtupleDescription<tools::rroot::ntuple>* ntupleDescription)
146 {                                                  49 {
147   auto ntuple = ntupleDescription->fNtuple;        50   auto ntuple = ntupleDescription->fNtuple;
148   auto ntupleBinding = ntupleDescription->fNtu     51   auto ntupleBinding = ntupleDescription->fNtupleBinding;
149                                                    52 
150   G4bool isInitialized = ntupleDescription->fI     53   G4bool isInitialized = ntupleDescription->fIsInitialized;
151   if ( ! isInitialized ) {                         54   if ( ! isInitialized ) {
152                                                    55 
153     if ( ! ntuple->initialize(G4cout, *ntupleB     56     if ( ! ntuple->initialize(G4cout, *ntupleBinding) ) {
154       Warn("Ntuple initialization failed !!",  <<  57       G4ExceptionDescription description;
                                                   >>  58       description 
                                                   >>  59         << "      " 
                                                   >>  60         << "Ntuple initialization failed !!"; 
                                                   >>  61       G4Exception("G4RootRNtuple::GetTNtupleRow()",
                                                   >>  62                   "Analysis_WR021", JustWarning, description);
155       return false;                                63       return false;
156     }                                              64     }
157     ntupleDescription->fIsInitialized = true;      65     ntupleDescription->fIsInitialized = true;
158     ntuple->start();                               66     ntuple->start();
159   }                                                67   }
160                                                    68 
161   auto next = ntuple->next();                      69   auto next = ntuple->next();
162   if ( next ) {                                    70   if ( next ) {
163     if ( ! ntuple->get_row() ) {                   71     if ( ! ntuple->get_row() ) {
164       Warn("Ntuple get_row() failed !!", fkCla <<  72       G4ExceptionDescription description;
                                                   >>  73       description 
                                                   >>  74         << "      " 
                                                   >>  75         << "Ntuple get_row() failed !!"; 
                                                   >>  76       G4Exception("G4RootRNtuple::GetTNtupleRow()",
                                                   >>  77                   "Analysis_WR021", JustWarning, description);
165       return false;                                78       return false;
166     }                                              79     }
167   }                                            <<  80   }  
168                                                    81 
169   return next;                                     82   return next;
170 }                                              <<  83 }   
171                                                    84