BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
Loading...
Searching...
No Matches
FileMapper.hh
1/*
2Beam Delivery Simulation (BDSIM) Copyright (C) Royal Holloway,
3University of London 2001 - 2023.
4
5This file is part of BDSIM.
6
7BDSIM is free software: you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published
9by the Free Software Foundation version 3 of the License.
10
11BDSIM is distributed in the hope that it will be useful, but
12WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with BDSIM. If not, see <http://www.gnu.org/licenses/>.
18*/
19#ifndef FILEMAPPER_H
20#define FILEMAPPER_H
21
22#include <string>
23#include <vector>
24
26class TDirectory;
27class TFile;
28class TH1;
29
30namespace RBDS
31{
37 bool GetFileType(TFile* file,
38 std::string& fileType,
39 int* dataVersion = nullptr);
40
43 bool IsBDSIMOutputFile(TFile* file,
44 int* dataVersion = nullptr);
45
47 bool IsBDSIMOutputFile(const std::string& filePath,
48 int* dataVersion = nullptr);
49
52 bool IsREBDSIMOutputFile(TFile* file);
53
55 bool IsREBDSIMOutputFile(const std::string& filePath);
56
59 bool IsREBDSIMOrCombineOutputFile(TFile* file);
60
62 bool IsREBDSIMOrCombineOutputFile(const std::string& filePath);
63
65 int DetermineDimensionality(TH1* h);
66
68 void WarningMissingHistogram(const std::string& histName,
69 const std::string& fileName);
70
73 {
74 std::string path;
75 std::string name;
76 HistogramAccumulator* accumulator;
77 TDirectory* outputDir;
78 bool BDSBH4Dtype;
79 };
80
82 enum class MergeType {none, meanmerge, sum};
83
85 MergeType DetermineMergeType(const std::string& parentDir);
86}
87
95{
96public:
97 HistogramMap() = delete;
98 HistogramMap(TFile* file,
99 TFile* output,
100 bool debugIn = false);
101 ~HistogramMap(){;}
102
105 void MapDirectory(TDirectory* dir,
106 TFile* output,
107 const std::string& parentDir);
108
110 inline const std::vector<RBDS::HistogramPath>& Histograms() const {return histograms;}
111
112private:
113 bool debug;
114 std::vector<RBDS::HistogramPath> histograms;
115};
116
117#endif
Class to accumulate and merge histograms in different ways.
Class to map a rebdsim file structure and create duplicate in output.
Definition: FileMapper.hh:95
bool debug
Debug flag.
Definition: FileMapper.hh:113
HistogramMap()=delete
No need for default constructor.
std::vector< RBDS::HistogramPath > histograms
Storage of all objects.
Definition: FileMapper.hh:114
const std::vector< RBDS::HistogramPath > & Histograms() const
Access full vector of histograms.
Definition: FileMapper.hh:110
void MapDirectory(TDirectory *dir, TFile *output, const std::string &parentDir)
Definition: FileMapper.cc:164
Utility functions for data files.
bool IsBDSIMOutputFile(TFile *file, int *dataVersion=nullptr)
Definition: FileMapper.cc:66
bool IsREBDSIMOutputFile(TFile *file)
Definition: FileMapper.cc:93
bool GetFileType(TFile *file, std::string &fileType, int *dataVersion=nullptr)
Definition: FileMapper.cc:44
MergeType DetermineMergeType(const std::string &parentDir)
Determine merge type from parent directory name.
Definition: FileMapper.cc:258
bool IsREBDSIMOrCombineOutputFile(TFile *file)
Definition: FileMapper.cc:116
int DetermineDimensionality(TH1 *h)
Determine the number of dimensions of a histogram by dynamically casting.
Definition: FileMapper.cc:142
MergeType
Types of merging.
Definition: FileMapper.hh:82
void WarningMissingHistogram(const std::string &histName, const std::string &fileName)
Common print out method.
Definition: FileMapper.cc:147
Basic structure for accumulating histogram from rebdsim output files.
Definition: FileMapper.hh:73
std::string path
Without histogram name.
Definition: FileMapper.hh:74
std::string name
Name of histogram.
Definition: FileMapper.hh:75