1 #ifndef HEAD_HH_INCLUDED 
    2 #define HEAD_HH_INCLUDED 
   28   s.erase( s.begin(), std::find_if(s.begin(), s.end(), [](
int ch) {
 
   29     return !std::isspace(ch);
 
   33   s.erase(std::find_if(s.rbegin(), s.rend(), [](
int ch) {
 
   34     return !std::isspace(ch);
 
   54   while (
getline(ss, token, delim))
 
   57     if (token != 
"") 
r.push_back(token);
 
   78     return count( key ) != 0;
 
   88   const std::string& 
get_line( std::string key )
 const 
  102     return this->at(key);
 
  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 );
 
  175   std::string 
set_line( std::string tag, std::string line , 
bool ensure_unique = 
true )
 
  180       for (
int i = 1; find(k) != end() ; i++)
 
  203     if ( idx < 0 || idx >= 
int ( 
v.size() ) )
 
  205       THROW(
Exception, 
"Cannot find word number " << idx << 
" in line " << 
get_line(key) << 
" for key: " << key);
 
  222     auto i = std::find (
v.begin(), 
v.end(), field );
 
  223     if (i == 
v.end()) 
return -1;
 
  224     return i - 
v.begin();
 
  237   std::string 
get_field( std::string key, std::string field )
 const 
  260   void set_field( std::string key, std::string field, std::string value )
 
  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 << 
" ";
 
  295   void print ( std::ostream& out = std::cout )
 const 
  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;
 
  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" 
  364     return stod ( 
get_field(
"genvol", 
"numberOfEvents") );
 
  374     return stod ( 
get_field(
"DAQ", 
"livetime") );
 
  385     return stod ( 
get_field(
"livetime", 
"numberOfSeconds") );
 
then fatal No hydrophone data file $HYDROPHONE_TXT fi sort gr k
 
std::string & get_line(std::string key)
Get data with the given key. 
 
void set_field(std::string key, std::string field, std::string value)
Set data with the given key at given field. 
 
std::string get_field(std::string key, std::string field) const 
Get data with the given key at given field. 
 
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message. 
 
bool have_line(std::string key) const 
Check availability of data with the given key. 
 
double mc_livetime() const 
Get the Monte Carlo live time. 
 
int get_index_of_field(std::string key, std::string field) const 
Get index of data with the given key at given field. 
 
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". 
 
The Vec class is a straightforward 3-d vector, which also works in pyroot. 
 
void print(std::ostream &out=std::cout) const 
Print header. 
 
std::istream & getline(std::istream &in, JString &object)
Read string from input stream until end of line. 
 
std::string set_line(std::string tag, std::string line, bool ensure_unique=true)
Set data with the given tag. 
 
static void trimstring(std::string &s)
Trim a string in place. 
 
The Head class reflects the header of Monte-Carlo event files, which consists of keys (also referred ...
 
double ngen() const 
Get the number of generated events needed for computing event rates. 
 
std::string to_string(const T &value)
Convert value to string. 
 
const std::string & get_line(std::string key) const 
Get data with the given key. 
 
std::vector< std::string > get_lines(const std::string &tag) const 
Get all data compatible with the given key. 
 
double daq_livetime() const 
Get the the live time provided by the DAQ sytstem (=number of processed timeslices * frametime)...
 
std::string get_field(std::string key, int idx) const 
Get data with the given key at given index. 
 
Vec translate() const 
Get coordinate translation. 
 
std::vector< std::string > splitstring(const std::string &str, char delim= ' ')
Split string at delimiter. 
 
Vec coord_origin() const 
Get coordinate origin. 
 
static std::map< std::string, std::vector< std::string > > & _hdr_dict()
Get internal description of the known lines in header.