GGS(GenericGEANT4Simulation)Software  2.6.0
 All Data Structures Namespaces Files Functions Variables Typedefs Macros
GGSTFilesHandler.cpp
Go to the documentation of this file.
1 /*
2  * GGSTFilesHandler.cpp
3  *
4  * Created on: 31 Jul 2014
5  * Author: Nicola mori
6  */
7 
10 // C++ headers
11 #include <iostream>
12 #include <algorithm>
13 
14 // ROOT headers
15 #include "TFile.h"
16 
17 // GGS headers
18 #include "utils/GGSSmartLog.h"
20 
21 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.....
22 
24 
25 }
26 
27 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.....
28 
30  for (unsigned int iChain = 0; iChain < _chains.size(); iChain++) {
31  delete _chains[iChain];
32  }
33 }
34 
35 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.....
36 
37 const std::string& GGSTFilesHandler::GetFileName(unsigned int iFile) {
38  static const std::string nullFile("");
39  if (iFile < GetNFiles())
40  return _files[iFile];
41  else
42  return nullFile;
43 }
44 
45 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.....
46 
47 void GGSTFilesHandler::_AddFile(const std::string &fileName, bool force) {
48  static const std::string routineName("GGSTFilesHandler::_AddFile");
49 
50  _files.push_back(fileName);
51 
52  // Check if file can be opened
53  TFile *file = TFile::Open(fileName.data());
54  if (file->IsZombie()) {
55  COUT(WARNING) << "File " << fileName << " cannot be opened. File discarded." << ENDL;
56  _files.pop_back();
57  delete file;
58  return;
59  }
60 
61  // Do some consistency checks
62  if (!force) {
63  // Check if file contains GGS simulation data
64  GGSTSimInfo *simInfo = (GGSTSimInfo*) (file->Get("GGSSimInfo"));
65  if (simInfo == NULL) {
66  COUT(WARNING) << "GGS simulation info not present in file " << fileName << ". File discarded." << ENDL;
67  _files.pop_back();
68  delete file;
69  return;
70  }
71  // Retrieve Geometry parameters (if they exist)
72  GGSTGeoParams *geoParams = (GGSTGeoParams*) (file->Get("GGSGeoParams"));
73  if (_files.size() == 1) {
74  // Save simulation info
75  _simInfo = *simInfo;
76  // Save geometry parameters info object if it exists
77  if(geoParams)
78  _geoParams = *geoParams;
79  }
80  else {
81  // Check if info from current file is consistent with others
82  if (!(simInfo->IsSameSimAs(_simInfo))) {
83  COUT(WARNING) << "Simulation info in file " << fileName << " are inconsistent with those in file " << _files[0]
84  << ". File discarded." << ENDL;
85  _files.pop_back();
86  }
87  if (!(geoParams->AreSameParamsAs(_geoParams))) {
88  COUT(WARNING) << "geometry parameters in file " << fileName << " are inconsistent with those in file " << _files[0]
89  << ". File discarded." << ENDL;
90  _files.pop_back();
91  }
92 
93  }
94  }
95  delete file;
96 }
97 
98 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.....
99 
100 void GGSTFilesHandler::_SortFiles() {
101  static const std::string routineName("GGSTFilesHandler::_SortFiles");
102 
103  if (_chains.size() > 0) {
104  COUT(WARNING) << "Can't sort files after chain creation." << ENDL;
105  return;
106  }
107 
108  sort(_files.begin(), _files.end());
109  // Reset the simulation info to that of the first file
110  TFile *file0 = TFile::Open(_files[0].data());
111  _simInfo = *((GGSTSimInfo*) (file0->Get("GGSSimInfo")));
112  delete file0;
113 
114 }
115 
116 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.....
~GGSTFilesHandler()
Destructor.
bool IsSameSimAs(const GGSTSimInfo &simInfo)
Equality operator.
Definition: GGSTSimInfo.cpp:21
GGSTFilesHandler()
Constructor.
#define ENDL
Definition: GGSSmartLog.h:93
#define COUT(level)
Smart log macro. It writes on stdout only if the specified verbosity level is lesser than the maximum...
Definition: GGSSmartLog.h:66
bool AreSameParamsAs(const GGSTGeoParams &params) const
Compares two geometry parameter objects.
Class for storing the geometry parameters on Root output file.
Definition: GGSTGeoParams.h:18
unsigned int GetNFiles()
The number of files handled by this object.
A class to store simulation informations.
Definition: GGSTSimInfo.h:21
const std::string & GetFileName(unsigned int iFile)
Fetch the name of a handled file.