Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/Geant4/G4RootHnFileManager.icc was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

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 // Author: Ivana Hrivnacova, 15/09/2020  (ivana@ipno.in2p3.fr)
0028 
0029 #include "G4AnalysisUtilities.hh"
0030 
0031 #include "tools/wroot/to"
0032 #include "tools/wroot/file"
0033 #include "toolx/zlib"
0034 
0035 //_____________________________________________________________________________
0036 template <typename HT>
0037 G4bool G4RootHnFileManager<HT>::Write(
0038   tools::wroot::directory* directory, HT* ht, const G4String& htName)
0039 {
0040   // write histogram
0041   return to(*directory, *ht, htName);
0042 }
0043 
0044 //_____________________________________________________________________________
0045 template <typename HT>
0046 G4bool G4RootHnFileManager<HT>::WriteExtra(
0047   HT* ht, const G4String& htName, const G4String& fileName)
0048 {
0049   auto result = true;
0050 
0051   // create a new file
0052   auto rfile = new tools::wroot::file(G4cout, fileName);
0053 
0054   // return if creating file failed
0055   if (rfile == nullptr) return false;
0056 
0057   // add compression
0058   rfile->add_ziper('Z', toolx::compress_buffer);
0059   rfile->set_compression(fFileManager->GetCompressionLevel());
0060 
0061   // no directory supported in this mode
0062   auto hdirectory = &(rfile->dir());
0063   if (hdirectory == nullptr) return false;
0064 
0065   // write histo
0066   result &= Write(hdirectory, ht, htName);
0067 
0068   // write file
0069   unsigned int n;
0070   result &= rfile->write(n);
0071   if ( ! result) {
0072     G4Analysis::Warn(
0073       "Saving " + G4Analysis::GetHnType<HT>() + " " + htName + " failed",
0074       fkClass, "WriteExtra");
0075     return false;
0076   }
0077 
0078   // close file
0079   rfile->close();
0080   return true;
0081 }
0082 
0083 //_____________________________________________________________________________
0084 template <typename HT>
0085 G4bool G4RootHnFileManager<HT>::Write(
0086   HT* ht, const G4String& htName, G4String& fileName)
0087 {
0088   if ( fileName.empty()) {
0089     // should not happen
0090     G4cerr << "!!! Root file name not defined." << G4endl;
0091     G4cerr << "!!! Write " << htName << " failed." << G4endl;
0092     return false;
0093   }
0094 
0095   auto hdirectory = std::get<1>(*fFileManager->GetTFile(fileName));
0096   if ( hdirectory == nullptr ) {
0097     G4Analysis::Warn(
0098       "Failed to get Root file " + fileName + " histo directory.",
0099       fkClass, "Write");
0100     return false;
0101   }
0102 
0103   auto result = Write(hdirectory, ht, htName);
0104   fFileManager->LockDirectoryNames();
0105   return result;
0106 }