EVAFile.h
Go to the documentation of this file.
1 #ifndef _io_EVAFile_h_
2 #define _io_EVAFile_h_
3 
4 #include <io/EVAIOException.h>
5 #include <io/VEventFile.h>
6 #include <io/CorsikaUtilities.h>
7 #include <dirent.h>
8 #include <fstream>
9 #include <vector>
10 #include <utl/Vector.h>
11 #include <revt/Station.h>
12 
13 
14 namespace evt {
15  class Event;
16  class ShowerSimData;
17 }
18 
19 namespace io {
20 
21  // Helper struct to store the file information
22 
23  struct SubfileInfo {
24  SubfileInfo(const std::string& fstr, const utl::Vector3D& p, const double b)
25  : filestring(fstr), position(p), binning_EVA(b) { }
26  std::string filestring;
28  double binning_EVA;
29  private:
30  SubfileInfo();
31  };
32 
33 
44  class EVAFile : public VEventFile {
45 
46  public:
47  EVAFile() { }
48  EVAFile(const std::string& filename, const Mode filemode = eRead, utl::Branch* const b = nullptr);
49  virtual ~EVAFile() { }
50 
51  virtual Status Read(evt::Event& event);
52  virtual void Write(const evt::Event& event);
53  virtual Status FindEvent(const unsigned int eventId);
54  virtual int GetNEvents() { return 1; } // there is currently one event in a EVA file (hard-coded)
55  virtual void Open(const std::string& filename, const io::Mode filemode = eRead, utl::Branch* const b = nullptr);
56  virtual void Close() { file_open = false; }
57  virtual io::Status GotoPosition(const unsigned int pos);
58 
59  private:
60  // Copy-constructor are made private because they may not be used
61  EVAFile(const EVAFile&);
62 
63  bool CheckFileExtension(const std::string& filename, const std::string& extension) const;
64  void CheckFileReadability(const std::string& filename, const Mode filemode) const;
65  void OpenFile(const std::string& filename);
67  void ReadSubfileList();
70  bool ReadSubfileHeader(std::ifstream&);
71  bool ReadSubfileLine(std::ifstream&, double&, double* const);
72 
73  // Helper function for reading the data from a file
74  template<class T>
75  T
76  ReadQuantity(const std::string& var_name = "", const std::string& unit = "",
77  const bool optional = false, const bool only_if = true, const T default_value = T())
78  {
79  if (!only_if)
80  return default_value;
81 
82  if (!var_name.empty()) {
83  const std::streampos oldpos = input_file.tellg();
84  std::string input_var_name;
85  input_file >> std::ws >> input_var_name;
86  if (input_var_name != var_name) {
87  if (!optional) {
88  input_file.seekg(oldpos);
89  std::ostringstream msg;
90  msg << "Error reading variable name from " << filename << " file: expected " << var_name
91  << " got " << input_var_name << " instead.";
92  throw io::EVAIOException(msg.str());
93  } else {
94  input_file.seekg(oldpos);
95  return default_value;
96  }
97  }
98  }
99 
100  T ret_val;
101  input_file >> ret_val;
102 
103  if (unit != std::string("")) {
104  std::string input_unit;
105  input_file >> std::ws >> input_unit;
106  if (input_unit != unit) {
107  std::ostringstream msg;
108  msg << "Error reading unit for the variable '" << var_name
109  << "' from .mgmr file: expected " << unit
110  << " got " << input_unit << " instead.";
111  throw io::EVAIOException(msg.str());
112  }
113  }
114 
115  return ret_val;
116  }
117 
118  // logistics for reading the file
119  std::string filename;
120  std::string filetype;
121  std::string name;
122  std::string path_name;
123  std::string version_string;
124  std::string file_extension;
125  std::vector<SubfileInfo> sub_file_list;
126  std::ifstream input_file;
127  bool file_open = false;
128  unsigned int events_remaining = 1; // there is currently one event in a EVA file (hard-coded)
129 
130  // This is all data that is read from the .mgmr file.
133  std::string primary_particle_str;
134  double primary_energy = 0;
135  double detector_level = 0;
136  double zenith_angle = 0;
137  double azimuth_angle = 0;
138  double time_binning_MGMR = 0;
141  double magnetic_field = 0;
142  double pancake_thickness = 0;
146  int event_id = 0;
149 
150  };
151 
152 }
153 
154 
155 #endif
utl::Vector3D refcoord
Definition: EVAFile.h:132
virtual void Open(const std::string &filename, const io::Mode filemode=eRead, utl::Branch *const b=nullptr)
Definition: EVAFile.cc:207
bool file_open
Definition: EVAFile.h:127
std::string primary_particle_str
Definition: EVAFile.h:133
std::string name
Definition: EVAFile.h:121
std::vector< SubfileInfo > sub_file_list
Definition: EVAFile.h:125
virtual void Close()
Definition: EVAFile.h:56
bool ReadShowerData(evt::Event &)
Definition: EVAFile.cc:251
Mode
Available open modes.
Definition: IoCodes.h:16
virtual ~EVAFile()
Definition: EVAFile.h:49
void CheckFileReadability(const std::string &filename, const Mode filemode) const
Definition: EVAFile.cc:61
std::ifstream input_file
Definition: EVAFile.h:126
double pancake_thickness
Definition: EVAFile.h:142
double binning_EVA
Definition: EVAFile.h:28
bool ReadSubfileHeader(std::ifstream &)
Definition: EVAFile.cc:290
bool corsika_pancakefile_included
Definition: EVAFile.h:145
Class representing a document branch.
Definition: Branch.h:107
Status
Return code for seek operation.
Definition: IoCodes.h:24
utl::Vector3D position
Definition: EVAFile.h:27
bool corsika_longfile_included
Definition: EVAFile.h:144
double magnetic_field
Definition: EVAFile.h:141
int event_id
Definition: EVAFile.h:146
Base for exceptions in the EVA reader.
bool CheckFileExtension(const std::string &filename, const std::string &extension) const
Definition: EVAFile.cc:52
virtual int GetNEvents()
Definition: EVAFile.h:54
void ReadSubfileList()
Definition: EVAFile.cc:162
std::string version_string
Definition: EVAFile.h:123
double zenith_angle
Definition: EVAFile.h:136
std::string filetype
Definition: EVAFile.h:120
std::string file_extension
Definition: EVAFile.h:124
void ReadBaseFileQuantities()
Definition: EVAFile.cc:89
double primary_energy
Definition: EVAFile.h:134
int gps_time_seconds
Definition: EVAFile.h:147
double magnetic_field_zenith
Definition: EVAFile.h:139
void OpenFile(const std::string &filename)
Definition: EVAFile.cc:75
const double unit[npar]
Definition: UnivRec.h:76
Read EVA simulation output.
Definition: EVAFile.h:44
T ReadQuantity(const std::string &var_name="", const std::string &unit="", const bool optional=false, const bool only_if=true, const T default_value=T())
Definition: EVAFile.h:76
virtual Status Read(evt::Event &event)
read current event advance cursor by 1
Definition: EVAFile.cc:393
double magnetic_field_azimuth
Definition: EVAFile.h:140
double time_binning_MGMR
Definition: EVAFile.h:138
bool ReadRadioSimData(evt::Event &)
Definition: EVAFile.cc:325
virtual Status FindEvent(const unsigned int eventId)
seek Event id set cursor there
Definition: EVAFile.cc:424
std::string filestring
Definition: EVAFile.h:26
std::string path_name
Definition: EVAFile.h:122
utl::Vector3D core_position
Definition: EVAFile.h:131
SubfileInfo(const std::string &fstr, const utl::Vector3D &p, const double b)
Definition: EVAFile.h:24
double azimuth_angle
Definition: EVAFile.h:137
double detector_level
Definition: EVAFile.h:135
std::string filename
Definition: EVAFile.h:119
unsigned int events_remaining
Definition: EVAFile.h:128
virtual void Write(const evt::Event &event)
Definition: EVAFile.cc:415
bool ReadSubfileLine(std::ifstream &, double &, double *const)
Definition: EVAFile.cc:300
bool askaryan_effect_included
Definition: EVAFile.h:143
double gps_time_nanoseconds
Definition: EVAFile.h:148
virtual io::Status GotoPosition(const unsigned int pos)
goto by position in the file
Definition: EVAFile.cc:238

, generated on Tue Sep 26 2023.