2// ********************************************************************
 
    3// * License and Disclaimer                                           *
 
    5// * The  Geant4 software  is  copyright of the Copyright Holders  of *
 
    6// * the Geant4 Collaboration.  It is provided  under  the terms  and *
 
    7// * conditions of the Geant4 Software License,  included in the file *
 
    8// * LICENSE and available at  http://cern.ch/geant4/license .  These *
 
    9// * include a list of copyright holders.                             *
 
   11// * Neither the authors of this software system, nor their employing *
 
   12// * institutes,nor the agencies providing financial support for this *
 
   13// * work  make  any representation or  warranty, express or implied, *
 
   14// * regarding  this  software system or assume any liability for its *
 
   15// * use.  Please see the license in the file  LICENSE  and URL above *
 
   16// * for the full disclaimer and the limitation of liability.         *
 
   18// * This  code  implementation is the result of  the  scientific and *
 
   19// * technical work of the GEANT4 collaboration.                      *
 
   20// * By using,  copying,  modifying or  distributing the software (or *
 
   21// * any work based  on the software)  you  agree  to acknowledge its *
 
   22// * use  in  resulting  scientific  publications,  and indicate your *
 
   23// * acceptance of all terms of the Geant4 Software license.          *
 
   24// ********************************************************************
 
   27// Author: Ivana Hrivnacova, 15/09/2020 (ivana@ipno.in2p3.fr)
 
   29#include "G4AnalysisUtilities.hh"
 
   31#include "tools/hdf5/header"
 
   32#include "tools/hdf5/h2file"
 
   33#include "tools/histo/h1d"
 
   34#include "tools/histo/h2d"
 
   35#include "tools/histo/h3d"
 
   36#include "tools/histo/p1d"
 
   37#include "tools/histo/p2d"
 
   39#include "tools/hdf5/h2file"
 
   41//_____________________________________________________________________________
 
   44G4bool G4Hdf5HnFileManager<tools::histo::p1d>::WriteImpl(
 
   45  hid_t hdirectory, tools::histo::p1d* ht, const G4String& htName)
 
   47  return tools::hdf5::write_profile(G4cout, hdirectory, htName, *ht);
 
   50//_____________________________________________________________________________
 
   53G4bool G4Hdf5HnFileManager<tools::histo::p2d>::WriteImpl(
 
   54  hid_t hdirectory, tools::histo::p2d* ht, const G4String& htName)
 
   56  return tools::hdf5::write_profile(G4cout, hdirectory, htName, *ht);
 
   59//_____________________________________________________________________________
 
   62G4bool G4Hdf5HnFileManager<HT>::WriteImpl(
 
   63  hid_t hdirectory, HT* ht, const G4String& htName)
 
   65  return tools::hdf5::write_histo(G4cout, hdirectory, htName, *ht);
 
   68//_____________________________________________________________________________
 
   71G4bool G4Hdf5HnFileManager<HT>::WriteExtra(
 
   72  HT* ht, const G4String& htName, const G4String& fileName)
 
   76  hid_t hfile = ::H5Fcreate(fileName, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
 
   78  // Do nothing if there is no file
 
   79  // (te error should be handled by caller)
 
   81    G4cerr << "::H5Fcreate failed " << G4endl;
 
   85  // create a header with general infos :
 
   86  if(!tools::hdf5::write_header(hfile)) {
 
   87    G4cerr << "tools::hdf5::write_header() failed." << std::endl;
 
   92  hid_t hdirectory = tools_H5Gcreate(hfile, "histograms", 0);
 
   93  if ( hdirectory < 0 ) {
 
   94    G4cerr << "tools_H5Gcreate failed " << G4endl;
 
   98  auto result = tools::hdf5::write_atb(hdirectory, "type", "directory");
 
  100    G4cerr << "tools::hdf5::write_atb failed " << G4endl;
 
  104  result = WriteImpl(hdirectory, ht, htName);
 
  106    G4cerr << "Writing HT failed" << G4endl;
 
  111  ::H5Gclose(hdirectory);
 
  116//_____________________________________________________________________________
 
  117template <typename HT>
 
  119G4bool G4Hdf5HnFileManager<HT>::Write(
 
  120  HT* ht, const G4String& htName, G4String& fileName)
 
  122  if (fileName.empty()) {
 
  124    G4cerr << "!!! Hdf5 file name not defined." << G4endl;
 
  125    G4cerr << "!!! Write " << htName << " failed." << G4endl;
 
  129  auto hdirectory = std::get<1>(*fFileManager->GetTFile(fileName));
 
  130    if ( hdirectory < 0 ) {
 
  132      "Failed to get Hdf5 file " + fileName + " histo directory.",
 
  137  auto result = WriteImpl(hdirectory, ht, htName);
 
  138  fFileManager->LockDirectoryNames();