Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | Static Public Member Functions | List of all members
Head Struct Reference

The Head class reflects the header of Monte-Carlo event files, which consists of keys (also referred to as "tags") and values. More...

#include <Head.hh>

Inheritance diagram for Head:
TObject std::map< std::string, std::string > JAANET::JHead JAANET::JWeightEventHelper JSUPPORT::JWeightFileScanner< JFileScanner_t >

Public Member Functions

bool have_line (std::string key) const
 Check availability of data with the given key. More...
 
const std::string & get_line (std::string key) const
 Get data with the given key. More...
 
std::string & get_line (std::string key)
 Get data with the given key. More...
 
void set_line (std::string key, std::string line)
 Set data with the given key. More...
 
std::string get_field (std::string key, int idx) const
 Get data with the given key at given index. More...
 
int get_index_of_field (std::string key, std::string field) const
 Get index of data with the given key at given field. More...
 
std::string get_field (std::string key, std::string field) const
 Get data with the given key at given field. More...
 
void set_field (std::string key, std::string field, std::string value)
 Set data with the given key at given field. More...
 
void print (std::ostream &out=std::cout) const
 Print header. More...
 
double ngen () const
 Get the number of generated events needed for computing event rates. More...
 
double daq_livetime () const
 Get the the live time provided by the DAQ sytstem (=number of processed timeslices * frametime). More...
 
double mc_livetime () const
 Get the Monte Carlo live time. More...
 
Vec coord_origin () const
 Get coordinate origin. More...
 
Vec translate () const
 Get coordinate translation. More...
 
virtual ~Head ()
 
 ClassDef (Head, 2)
 

Static Public Member Functions

static std::map< std::string,
std::vector< std::string > > & 
_hdr_dict ()
 Get internal description of the known lines in header. More...
 

Detailed Description

The Head class reflects the header of Monte-Carlo event files, which consists of keys (also referred to as "tags") and values.

Definition at line 66 of file Head.hh.

Constructor & Destructor Documentation

virtual Head::~Head ( )
inlinevirtual

Definition at line 338 of file Head.hh.

338 {}

Member Function Documentation

bool Head::have_line ( std::string  key) const
inline

Check availability of data with the given key.

Parameters
keykey
Returns
true if data are available; else false

Definition at line 75 of file Head.hh.

76  {
77  return count( key ) != 0;
78  }
std::vector< int > count
Definition: JAlgorithm.hh:184
const std::string& Head::get_line ( std::string  key) const
inline

Get data with the given key.


This method throws a run-time exception if no data are available.

Parameters
keykey
Returns
data

Definition at line 87 of file Head.hh.

88  {
89  return this->at(key);
90  }
std::string& Head::get_line ( std::string  key)
inline

Get data with the given key.


This method throws a run-time exception if no data are available.

Parameters
keykey
Returns
data

Definition at line 99 of file Head.hh.

100  {
101  return this->at(key);
102  }
void Head::set_line ( std::string  key,
std::string  line 
)
inline

Set data with the given key.

Parameters
keykey
linedata

Definition at line 110 of file Head.hh.

111  {
113  }
std::string Head::get_field ( std::string  key,
int  idx 
) const
inline

Get data with the given key at given index.


This method throws a run-time exception if no data are available.

Parameters
keykey
idxindex
Returns
data

Definition at line 123 of file Head.hh.

124  {
125  using namespace std;
126 
128 
129  if ( idx < 0 || idx >= int ( v.size() ) )
130  {
131  THROW(Exception, "Cannot find word number " << idx << " in line " << get_line(key) << " for key: " << key);
132  }
133  return v[idx];
134  }
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:670
General exception.
Definition: Exception.hh:13
const std::string & get_line(std::string key) const
Get data with the given key.
Definition: Head.hh:87
data_type v[N+1][M+1]
Definition: JPolint.hh:740
std::vector< std::string > splitstring(const std::string &str, char delim= ' ')
Split string at delimiter.
Definition: Head.hh:45
int Head::get_index_of_field ( std::string  key,
std::string  field 
) const
inline

Get index of data with the given key at given field.


Note that this method uses the dictionary define in method Head::_hdr_dict.

Parameters
keykey
fieldfield
Returns
index (-1 if not present)

Definition at line 145 of file Head.hh.

146  {
147  auto v = _hdr_dict()[key];
148  auto i = std::find (v.begin(), v.end(), field );
149  if (i == v.end()) return -1;
150  return i - v.begin();
151  }
data_type v[N+1][M+1]
Definition: JPolint.hh:740
static std::map< std::string, std::vector< std::string > > & _hdr_dict()
Get internal description of the known lines in header.
Definition: Head.hh:238
std::string Head::get_field ( std::string  key,
std::string  field 
) const
inline

Get data with the given key at given field.


This method throws a run-time exception if no field is available.

Note that this method uses the dictionary define in method Head::_hdr_dict.

Parameters
keykey
fieldfield
Returns
data

Definition at line 163 of file Head.hh.

164  {
165  int idx = get_index_of_field(key, field);
166 
167  if ( idx == -1 )
168  {
169  THROW(Exception, "Failed to find" << key << " " << field);
170  }
171 
172  return get_field( key, idx );
173  }
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:670
int get_index_of_field(std::string key, std::string field) const
Get index of data with the given key at given field.
Definition: Head.hh:145
General exception.
Definition: Exception.hh:13
std::string get_field(std::string key, int idx) const
Get data with the given key at given index.
Definition: Head.hh:123
void Head::set_field ( std::string  key,
std::string  field,
std::string  value 
)
inline

Set data with the given key at given field.


This method throws a run-time exception if no field available.

Note that this method uses the dictionary define in method Head::_hdr_dict.

Parameters
keykey
fieldfield
valuevakue

Definition at line 186 of file Head.hh.

187  {
188  using namespace std;
189 
190  if ( field == "" ) get_line( key ) = value;
191 
192  int idx = get_index_of_field( key, field );
193 
194  if ( idx < 0 )
195  {
196  THROW(Exception, "GFailed to find field in header line: " << key << " " << field);
197  }
198 
199  vector<string> vals = splitstring( get_line( key ) );
200 
201  // if the fields before do not exist, add padding
202  while ( int( vals.size() ) <= idx ) vals.push_back("0");
203 
204  vals[idx] = value;
205  ostringstream ss;
206 
207  for (unsigned i = 0; i < vals.size() ; i++ )
208  {
209  ss << vals[i];
210  if ( i != vals.size() - 1) ss << " ";
211  }
212  set_line( key, ss.str() );
213 
214  }
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:670
int get_index_of_field(std::string key, std::string field) const
Get index of data with the given key at given field.
Definition: Head.hh:145
General exception.
Definition: Exception.hh:13
void set_line(std::string key, std::string line)
Set data with the given key.
Definition: Head.hh:110
const std::string & get_line(std::string key) const
Get data with the given key.
Definition: Head.hh:87
std::vector< std::string > splitstring(const std::string &str, char delim= ' ')
Split string at delimiter.
Definition: Head.hh:45
void Head::print ( std::ostream &  out = std::cout) const
inline

Print header.

Parameters
outoutput stream

Definition at line 221 of file Head.hh.

222  {
223  if (count("start_run")) out << "start_run: " << at("start_run") << std::endl;
224 
225  for ( auto& p : *this )
226  {
227  if ( p.first == "start_run" || p.first == "end_event" ) continue;
228  out << p.first << ": " << p.second << std::endl ;
229  }
230  out << "end_event:" << std::endl;
231  }
std::vector< int > count
Definition: JAlgorithm.hh:184
static std::map<std::string, std::vector<std::string> >& Head::_hdr_dict ( )
inlinestatic

Get internal description of the known lines in header.

Returns
internal dictionary

Definition at line 238 of file Head.hh.

239  {
240  using namespace std;
241 
242  // map with, for each tag (key), a vector of field-names
243 
244  static map<string, vector<string> > r;
245  if ( r.size() > 0 ) return r;
246 
247  string desc =
248  "DAQ:livetime\n"
249  "cut_primary cut_seamuon cut_in cut_nu:Emin Emax cosTmin cosTmax\n"
250  "generator physics simul:program version date time\n"
251  "seed:program level iseed\n"
252  "PM1_type_area:type area TTS\n"
253  "PDF:i1 i2\n"
254  "model:interaction muon scattering numberOfEnergyBins\n"
255  "can:zmin zmax r\n"
256  "genvol:zmin zmax r volume numberOfEvents\n"
257  "merge:time gain\n"
258  "coord_origin:x y z\n"
259  "translate:x y z\n"
260  "genhencut:gDir Emin\n"
261  "k40:rate time\n"
262  "norma:primaryFlux numberOfPrimaries\n"
263  "livetime:numberOfSeconds errorOfSeconds\n"
264  "flux:type key file_1 file_2\n"
265  "spectrum:alpha\n"
266  "fixedcan:xcenter ycenter zmin zmax radius\n"
267  "start_run:run_id";
268 
269  for ( auto line : splitstring(desc, '\n') )
270  {
271  auto v = splitstring( line, ':');
272 
273  vector< string > fields = splitstring( v[1] );
274  for ( auto key : splitstring( v[0] ) )
275  {
276  r[key] = fields;
277  }
278  }
279  return r;
280  }
data_type r[M+1]
Definition: JPolint.hh:742
data_type v[N+1][M+1]
Definition: JPolint.hh:740
std::vector< std::string > splitstring(const std::string &str, char delim= ' ')
Split string at delimiter.
Definition: Head.hh:45
double Head::ngen ( ) const
inline

Get the number of generated events needed for computing event rates.

Returns
number of events

Definition at line 288 of file Head.hh.

289  {
290  return stod ( get_field("genvol", "numberOfEvents") );
291  }
std::string get_field(std::string key, int idx) const
Get data with the given key at given index.
Definition: Head.hh:123
double Head::daq_livetime ( ) const
inline

Get the the live time provided by the DAQ sytstem (=number of processed timeslices * frametime).

Returns
live time [s]

Definition at line 298 of file Head.hh.

299  {
300  return stod ( get_field("DAQ", "livetime") );
301  }
std::string get_field(std::string key, int idx) const
Get data with the given key at given index.
Definition: Head.hh:123
double Head::mc_livetime ( ) const
inline

Get the Monte Carlo live time.

Returns
live time [s]

Definition at line 309 of file Head.hh.

310  {
311  return stod ( get_field("livetime", "numberOfSeconds") );
312  }
std::string get_field(std::string key, int idx) const
Get data with the given key at given index.
Definition: Head.hh:123
Vec Head::coord_origin ( ) const
inline

Get coordinate origin.

Returns
position

Definition at line 319 of file Head.hh.

320  {
321  return Vec( stod( get_field("coord_origin", "x") ),
322  stod( get_field("coord_origin", "y") ),
323  stod( get_field("coord_origin", "z") ));
324  }
The Vec class is a straightforward 3-d vector, which also works in pyroot.
Definition: Vec.hh:12
std::string get_field(std::string key, int idx) const
Get data with the given key at given index.
Definition: Head.hh:123
Vec Head::translate ( ) const
inline

Get coordinate translation.

Returns
translation

Definition at line 331 of file Head.hh.

332  {
333  return Vec( stod( get_field("translate", "x") ),
334  stod( get_field("translate", "y") ),
335  stod( get_field("translate", "z") ));
336  }
The Vec class is a straightforward 3-d vector, which also works in pyroot.
Definition: Vec.hh:12
std::string get_field(std::string key, int idx) const
Get data with the given key at given index.
Definition: Head.hh:123
Head::ClassDef ( Head  ,
 
)

The documentation for this struct was generated from the following file: