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>
|
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...
|
|
std::vector< std::string > | matching_keys (const std::string &tag) const |
| In case of duplicate keys, they are internally stored in the map with a suffix "_n". More...
|
|
std::vector< std::string > | get_lines (const std::string &tag) const |
| Get all data compatible with the given key. More...
|
|
std::string | set_line (std::string tag, std::string line, bool ensure_unique=true) |
| Set data with the given tag. 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) |
|
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 67 of file Head.hh.
bool Head::have_line |
( |
std::string |
key | ) |
const |
|
inline |
Check availability of data with the given key.
- Parameters
-
- Returns
- true if data are available; else false
Definition at line 76 of file Head.hh.
78 return count( key ) != 0;
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
-
- Returns
- data
Definition at line 88 of file Head.hh.
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
-
- Returns
- data
Definition at line 100 of file Head.hh.
102 return this->at(key);
std::vector< std::string> Head::matching_keys |
( |
const std::string & |
tag | ) |
const |
|
inline |
In case of duplicate keys, they are internally stored in the map with a suffix "_n".
This function returns all the keys that start with 'key' and end in "_n", with n an integer
- Parameters
-
Definition at line 114 of file Head.hh.
118 auto match = [&] (
const std::string & key) {
120 if (key == tag)
return true;
122 if ( key.find( tag ) != 0 )
return false;
125 std::string left = key.substr( tag.length(), key.length() );
126 if (left.length() < 2 || left[0] !=
'_' )
return false ;
127 for (
unsigned i = 1; i < left.length(); i++ )
129 if (!std::isdigit( left[i] ))
return false ;
134 for (
auto& p : *
this )
136 if ( match( p.first ) ) r.push_back( p.first );
std::vector< std::string > Head::get_lines |
( |
const std::string & |
tag | ) |
const |
|
inline |
Get all data compatible with the given key.
This means all data that is internally stored with "key_n", with n an integer
This method throws a run-time exception if no data are available.
- Parameters
-
- Returns
- data
Definition at line 153 of file Head.hh.
std::vector< std::string > matching_keys(const std::string &tag) const
In case of duplicate keys, they are internally stored in the map with a suffix "_n".
const std::string & get_line(std::string key) const
Get data with the given key.
std::string Head::set_line |
( |
std::string |
tag, |
|
|
std::string |
line, |
|
|
bool |
ensure_unique = true |
|
) |
| |
|
inline |
Set data with the given tag.
The function will return the actual key that is used internally to store the result, which is equal to the tag with an optional "_n" added to ensure uniqueness.
- Parameters
-
tag | tag |
line | data |
ensure_unique | add '_n' (with n an integer) to the tag if it would overwrite an existing key. |
Definition at line 175 of file Head.hh.
180 for (
int i = 1; find(k) != end() ; i++)
then fatal No sound hydrophone file $HYDROPHONE_TXT fi JGraph f $HYDROPHONE_TXT o $HYDROPHONE_ROOT sort gr k
std::string to_string(const T &value)
Convert value to string.
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
-
- Returns
- data
Definition at line 197 of file Head.hh.
203 if ( idx < 0 || idx >=
int (
v.size() ) )
205 THROW(
Exception,
"Cannot find word number " << idx <<
" in line " <<
get_line(key) <<
" for key: " << key);
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
const std::string & get_line(std::string key) const
Get data with the given key.
std::vector< std::string > splitstring(const std::string &str, char delim= ' ')
Split string at delimiter.
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
-
- Returns
- index (-1 if not present)
Definition at line 219 of file Head.hh.
222 auto i = std::find (
v.begin(),
v.end(), field );
223 if (i ==
v.end())
return -1;
224 return i -
v.begin();
static std::map< std::string, std::vector< std::string > > & _hdr_dict()
Get internal description of the known lines in header.
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
-
- Returns
- data
Definition at line 237 of file Head.hh.
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
int get_index_of_field(std::string key, std::string field) const
Get index of data with the given key at given field.
std::string get_field(std::string key, int idx) const
Get data with the given key at given index.
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
-
key | key |
field | field |
value | vakue |
Definition at line 260 of file Head.hh.
264 if ( field ==
"" )
get_line( key ) = value;
270 THROW(
Exception,
"GFailed to find field in header line: " << key <<
" " << field);
276 while (
int( vals.size() ) <= idx ) vals.push_back(
"0");
281 for (
unsigned i = 0; i < vals.size() ; i++ )
284 if ( i != vals.size() - 1) ss <<
" ";
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
int get_index_of_field(std::string key, std::string field) const
Get index of data with the given key at given field.
std::string set_line(std::string tag, std::string line, bool ensure_unique=true)
Set data with the given tag.
const std::string & get_line(std::string key) const
Get data with the given key.
std::vector< std::string > splitstring(const std::string &str, char delim= ' ')
Split string at delimiter.
void Head::print |
( |
std::ostream & |
out = std::cout | ) |
const |
|
inline |
Print header.
- Parameters
-
Definition at line 295 of file Head.hh.
297 if (
count(
"start_run")) out <<
"start_run: " << at(
"start_run") << std::endl;
299 for (
auto& p : *
this )
301 if ( p.first ==
"start_run" || p.first ==
"end_event" )
continue;
302 out << p.first <<
": " << p.second << std::endl ;
304 out <<
"end_event:" << std::endl;
Get internal description of the known lines in header.
- Returns
- internal dictionary
Definition at line 312 of file Head.hh.
319 if (
r.size() > 0 )
return r;
323 "cut_primary cut_seamuon cut_in cut_nu:Emin Emax cosTmin cosTmax\n"
324 "generator physics simul:program version date time\n"
325 "seed:program level iseed\n"
326 "PM1_type_area:type area TTS\n"
328 "model:interaction muon scattering numberOfEnergyBins\n"
330 "genvol:zmin zmax r volume numberOfEvents\n"
332 "coord_origin:x y z\n"
334 "genhencut:gDir Emin\n"
336 "norma:primaryFlux numberOfPrimaries\n"
337 "livetime:numberOfSeconds errorOfSeconds\n"
338 "flux:type key file_1 file_2\n"
340 "fixedcan:xcenter ycenter zmin zmax radius\n"
std::vector< std::string > splitstring(const std::string &str, char delim= ' ')
Split string at delimiter.
double Head::ngen |
( |
| ) |
const |
|
inline |
Get the number of generated events needed for computing event rates.
- Returns
- number of events
Definition at line 362 of file Head.hh.
364 return stod (
get_field(
"genvol",
"numberOfEvents") );
std::string get_field(std::string key, int idx) const
Get data with the given key at given index.
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 372 of file Head.hh.
374 return stod (
get_field(
"DAQ",
"livetime") );
std::string get_field(std::string key, int idx) const
Get data with the given key at given index.
double Head::mc_livetime |
( |
| ) |
const |
|
inline |
Get the Monte Carlo live time.
- Returns
- live time [s]
Definition at line 383 of file Head.hh.
385 return stod (
get_field(
"livetime",
"numberOfSeconds") );
std::string get_field(std::string key, int idx) const
Get data with the given key at given index.
Vec Head::coord_origin |
( |
| ) |
const |
|
inline |
Get coordinate origin.
- Returns
- position
Definition at line 393 of file Head.hh.
The Vec class is a straightforward 3-d vector, which also works in pyroot.
std::string get_field(std::string key, int idx) const
Get data with the given key at given index.
Vec Head::translate |
( |
| ) |
const |
|
inline |
Get coordinate translation.
- Returns
- translation
Definition at line 405 of file Head.hh.
The Vec class is a straightforward 3-d vector, which also works in pyroot.
std::string get_field(std::string key, int idx) const
Get data with the given key at given index.
Head::ClassDef |
( |
Head |
, |
|
|
2 |
|
|
) |
| |
The documentation for this struct was generated from the following file: