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/wcsv_histo"
32#include "tools/histo/h1d"
33#include "tools/histo/h2d"
34#include "tools/histo/h3d"
35#include "tools/histo/p1d"
36#include "tools/histo/p2d"
38//_____________________________________________________________________________
41G4bool G4CsvHnFileManager<tools::histo::p1d>::Write(
42 std::ofstream& hnfile, tools::histo::p1d* ht)
44 return tools::wcsv::pto(hnfile, ht->s_cls(), *ht);
47//_____________________________________________________________________________
50G4bool G4CsvHnFileManager<tools::histo::p2d>::Write(
51 std::ofstream& hnfile, tools::histo::p2d* ht)
53 return tools::wcsv::pto(hnfile, ht->s_cls(), *ht);
56//_____________________________________________________________________________
59G4bool G4CsvHnFileManager<HT>::Write(
60 std::ofstream& hnfile, HT* ht)
62 return tools::wcsv::hto(hnfile, ht->s_cls(), *ht);
65//_____________________________________________________________________________
68G4bool G4CsvHnFileManager<HT>::WriteExtra(
69 HT* ht, const G4String& htName, const G4String& fileName)
72 std::ofstream hnFile(fileName);
74 // Do nothing if there is no file
75 if ( ! hnFile.is_open() ) return false;
77 auto result = Write(hnFile, ht);
81 "Saving " + G4Analysis::GetHnType<HT>() + " " + htName + " failed",
82 fkClass, "WriteExtra");
89//_____________________________________________________________________________
92G4bool G4CsvHnFileManager<HT>::Write(
93 HT* ht, const G4String& htName, G4String& fileName)
95 if ( fileName.empty() ) {
97 G4cerr << "!!! Csv file name not defined." << G4endl;
98 G4cerr << "!!! Write " << htName << " failed." << G4endl;
102 auto hnFile = fFileManager->GetTFile(fileName, false);
104 // If histogram file name was not defined per object
105 // a file should be created from the provided default file name
106 auto hnFileName = fFileManager->GetHnFileName(G4Analysis::GetHnType<HT>(), htName);
108 // If histo directory name is set and if this directory exists
109 // add directory path to hnFileName
110 if ( fFileManager->IsHistoDirectory() ) {
111 hnFileName = "./" + fFileManager->GetHistoDirectoryName() + "/" + hnFileName;
114 if ( ! hnFileName.empty() ) {
115 hnFile = fFileManager->CreateTFile(hnFileName);
119 G4Analysis::Warn("Failed to get Csv file " + fileName, fkClass, "Write");
122 fileName = hnFileName;
126 return Write(*hnFile, ht);