Jpp  18.0.0-rc.4
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | Static Private Member Functions | Friends | List of all members
JAANET::JHead Struct Reference

Monte Carlo run header. More...

#include <JHead.hh>

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

Public Member Functions

 JHead ()
 Default constructor. More...
 
 JHead (const Head &header)
 Copy constructor. More...
 
virtual ~JHead ()
 Virtual destructor. More...
 
const JHeadgetHeader () const
 Get header. More...
 
JHeadgetHeader ()
 Get header. More...
 
void setHeader (const JHead &header)
 Set header. More...
 
void createUUID ()
 Create UUID if not already set. More...
 
template<class T >
bool is_valid (T JHead::*pd) const
 Check validity of given data member in JHead. More...
 
template<class T >
const_iterator pull (T JHead::*pd) const
 Pull given data member from Head. More...
 
template<class T >
iterator pull (T JHead::*pd)
 Pull given data member from Head. More...
 
template<class T >
void push (T JHead::*pd)
 Push given data member to Head. More...
 
void push ()
 Push all data members to Head. More...
 
template<class T >
void erase (T JHead::*pd)
 Reset and remove given data member from Head. More...
 
JHead getMatch (const JHead &header) const
 Get matching fields. More...
 
size_t getNumberOfMatches (const JHead &header) const
 Get number of matching fields. More...
 
bool match (const JHead &header) const
 Test match of headers. More...
 
bool less (const JHead &header) const
 Comparison of headers. More...
 
JHeadadd (const JHead &header)
 Addition of headers. More...
 
std::istream & read (std::istream &in)
 Read header from input. More...
 
std::ostream & write (std::ostream &out) const
 Write header to output. More...
 
std::ostream & print (std::ostream &out) const
 Print header to output. More...
 
 ClassDef (JHead, 5)
 
bool have_line (std::string key) const
 Check availability of data with the given key. More...
 
const std::stringget_line (std::string key) const
 Get data with the given key. More...
 
std::stringget_line (std::string key)
 Get data with the given key. More...
 
std::vector< std::stringmatching_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::stringget_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...
 
std::string get_field (std::string key, std::string field) const
 Get data with the given key at given field. 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...
 
void set_field (std::string key, std::string field, std::string value)
 Set data with the given key at given field. 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...
 
 ClassDef (Head, 2)
 

Static Public Member Functions

template<class T >
static bool is_valid (const T &object)
 Check validity of given data member in JHead. More...
 
static const size_t getMaximumNumberOfMatches ()
 Get maximum number of matching header fields. More...
 
static JLANG::JEquationParametersgetEquationParameters ()
 Get equation parameters corresponding to Monte Carlo ASCII format, i.e: More...
 
static void setEquationParameters (const JLANG::JEquationParameters &equation)
 Set equation parameters. More...
 
static std::map< std::string,
std::vector< std::string > > & 
_hdr_dict ()
 Get internal description of the known lines in header. More...
 
static void actionAtFileOpen (int version)
 Action method at file open. More...
 

Public Attributes

JAANET::start_run start_run
 
JUUID UUID
 
JAANET::XSecFile XSecFile
 
JAANET::drawing drawing
 
std::vector< JAANET::detectordetector
 
JAANET::muon_desc_file muon_desc_file
 
JAANET::target target
 
std::vector< JAANET::physicsphysics
 
std::vector< JAANET::simulsimul
 
JAANET::cut_primary cut_primary
 
JAANET::cut_seamuon cut_seamuon
 
JAANET::cut_in cut_in
 
JAANET::cut_nu cut_nu
 
JAANET::spectrum spectrum
 
JAANET::can can
 
JAANET::fixedcan fixedcan
 
JAANET::genvol genvol
 
JAANET::coord_origin coord_origin
 
JAANET::genhencut genhencut
 
JAANET::norma norma
 
JAANET::livetime livetime
 
JAANET::seabottom seabottom
 
JAANET::depth depth
 
JAANET::DAQ DAQ
 
JAANET::K40 K40
 
JAANET::tgen tgen
 
JAANET::time_interval time_interval
 
JAANET::primary primary
 
std::vector< JAANET::fluxflux
 
JAANET::end_event end_event
 

Static Public Attributes

static int ROOT_IO_VERSION = -1
 Streamer version as obtained from ROOT file. More...
 

Static Private Member Functions

template<class T >
static bool less (const T &first, const T &second)
 Comparison. More...
 
template<class T >
static bool match (const T &first, const T &second)
 Test match. More...
 
template<class T >
static bool less (const std::vector< T > &first, const std::vector< T > &second)
 Comparison of containers. More...
 
template<class T >
static bool match (const std::vector< T > &first, const std::vector< T > &second)
 Test is containers match. More...
 
template<class T >
static bool match (const JHead &first, const JHead &second, T JHead::*pd)
 Test match of given data member of headers. More...
 

Friends

bool operator== (const JHead &first, const JHead &second)
 Equal operator. More...
 
bool operator< (const JHead &first, const JHead &second)
 Less than operator. More...
 

Detailed Description

Monte Carlo run header.

This class extends the Head class so that the data from specific tags can be promoted to concrete data types.

Note that for the copy of new JHead data (e.g. data not obtained via a previous JAANET::copy) to become effective, the key words in the corresponding map of the Head class should be set.
To this end, member method JHead::push can be used.

Definition at line 1221 of file JHead.hh.

Constructor & Destructor Documentation

JAANET::JHead::JHead ( )
inline

Default constructor.

Definition at line 1227 of file JHead.hh.

1228  {
1229  createUUID();
1230  }
void createUUID()
Create UUID if not already set.
Definition: JHead.hh:1287
JAANET::JHead::JHead ( const Head header)
inline

Copy constructor.

Parameters
headerheader

Definition at line 1238 of file JHead.hh.

1239  {
1240  copy(header, *this);
1241  }
void copy(const Head &from, JHead &to)
Copy header from from to to.
Definition: JHead.cc:162
virtual JAANET::JHead::~JHead ( )
inlinevirtual

Virtual destructor.

Definition at line 1247 of file JHead.hh.

1248  {}

Member Function Documentation

const JHead& JAANET::JHead::getHeader ( ) const
inline

Get header.

Returns
header

Definition at line 1256 of file JHead.hh.

1257  {
1258  return static_cast<const JHead&>(*this);
1259  }
Monte Carlo run header.
Definition: JHead.hh:1221
JHead& JAANET::JHead::getHeader ( )
inline

Get header.

Returns
header

Definition at line 1267 of file JHead.hh.

1268  {
1269  return static_cast<JHead&>(*this);
1270  }
Monte Carlo run header.
Definition: JHead.hh:1221
void JAANET::JHead::setHeader ( const JHead header)
inline

Set header.

Parameters
headerheader

Definition at line 1278 of file JHead.hh.

1279  {
1280  static_cast<JHead&>(*this) = header;
1281  }
Monte Carlo run header.
Definition: JHead.hh:1221
void JAANET::JHead::createUUID ( )
inline

Create UUID if not already set.

Definition at line 1287 of file JHead.hh.

1288  {
1289  if (!is_valid(&JHead::UUID)) {
1290  this->UUID = JUUID::rndm();
1291  this->push(&JHead::UUID);
1292  }
1293  }
void push()
Push all data members to Head.
Definition: JHead.cc:28
static const JUUID & rndm()
Generate random UUID.
Definition: JUUID.hh:67
JUUID UUID
Definition: JHead.hh:1567
bool is_valid(T JHead::*pd) const
Check validity of given data member in JHead.
Definition: JHead.hh:1305
template<class T >
bool JAANET::JHead::is_valid ( T JHead::*  pd) const
inline

Check validity of given data member in JHead.

The validity is defined by the presence of the name of the data member in the underlying map.

Parameters
pdpointer to data member
Returns
true if valid; else false

Definition at line 1305 of file JHead.hh.

1306  {
1307  return (this->pull(pd) != this->end());
1308  }
const_iterator pull(T JHead::*pd) const
Pull given data member from Head.
Definition: JHead.hh:1335
template<class T >
static bool JAANET::JHead::is_valid ( const T object)
inlinestatic

Check validity of given data member in JHead.

The validity is defined by difference between actual and default value.

Parameters
objectobject
Returns
true if valid; else false

Definition at line 1320 of file JHead.hh.

1321  {
1322  static const T value;
1323 
1324  return (object.less(value) || value.less(object));
1325  }
bool less(const JHead &header) const
Comparison of headers.
Definition: JHead.hh:1470
do set_variable OUTPUT_DIRECTORY $WORKDIR T
template<class T >
const_iterator JAANET::JHead::pull ( T JHead::*  pd) const
inline

Pull given data member from Head.

Parameters
pdpointer to data member
Returns
iterator of Head

Definition at line 1335 of file JHead.hh.

1336  {
1337  return this->find(JROOT::getDataMember(pd)->GetName());
1338  }
const TDataMember * getDataMember(const JRootClass &parent, const JRootClass &member)
Get ROOT data member for given parent and member class.
Definition: JRootClass.hh:641
template<class T >
iterator JAANET::JHead::pull ( T JHead::*  pd)
inline

Pull given data member from Head.

Parameters
pdpointer to data member
Returns
iterator of Head

Definition at line 1348 of file JHead.hh.

1349  {
1350  return this->find(JROOT::getDataMember(pd)->GetName());
1351  }
const TDataMember * getDataMember(const JRootClass &parent, const JRootClass &member)
Get ROOT data member for given parent and member class.
Definition: JRootClass.hh:641
template<class T >
void JAANET::JHead::push ( T JHead::*  pd)
inline

Push given data member to Head.

Parameters
pdpointer to data member

Definition at line 1360 of file JHead.hh.

1361  {
1362  (*this)[JROOT::getDataMember(pd)->GetName()] = "";
1363  }
const TDataMember * getDataMember(const JRootClass &parent, const JRootClass &member)
Get ROOT data member for given parent and member class.
Definition: JRootClass.hh:641
void JAANET::JHead::push ( )

Push all data members to Head.

Definition at line 28 of file JHead.cc.

29  {
30  using namespace std;
31  using namespace JPP;
32 
33  JRootReadableClass cls(*this);
34 
35  unique_ptr<TIterator> i(cls.getClass()->GetListOfDataMembers()->MakeIterator());
36 
37  for (const TDataMember* p; (p = (const TDataMember*) i->Next()) != NULL; ) {
38  if (!JRootClass::is_static(*p)) {
39  if (this->count(p->GetName()) == 0) {
40  (*this)[p->GetName()] = "";
41  }
42  }
43  }
44  }
template<class T >
void JAANET::JHead::erase ( T JHead::*  pd)
inline

Reset and remove given data member from Head.

Parameters
pdpointer to data member

Definition at line 1378 of file JHead.hh.

1379  {
1380  this->*pd = T();
1381 
1382  iterator p = this->pull(pd);
1383 
1384  if (p != this->end()) {
1385  static_cast<Head*>(this)->erase(p);
1386  }
1387  }
void erase(T JHead::*pd)
Reset and remove given data member from Head.
Definition: JHead.hh:1378
do set_variable OUTPUT_DIRECTORY $WORKDIR T
The Head class reflects the header of Monte-Carlo event files, which consists of keys (also referred ...
Definition: Head.hh:65
const_iterator pull(T JHead::*pd) const
Pull given data member from Head.
Definition: JHead.hh:1335
JHead JAANET::JHead::getMatch ( const JHead header) const
inline

Get matching fields.

Parameters
headerheader
Returns
header with matching fields

Definition at line 1396 of file JHead.hh.

1397  {
1398 #define IF_MATCH(A, B, C, D) \
1399  if (match(B,C,D)) { A.push(D); } \
1400  else { A.erase(D); }
1401 
1402  JHead buffer(*this);
1403 
1404  buffer.clear();
1405 
1406  buffer.createUUID();
1407 
1408  IF_MATCH(buffer, *this, header, &JHead::cut_primary);
1409  IF_MATCH(buffer, *this, header, &JHead::cut_seamuon);
1410  IF_MATCH(buffer, *this, header, &JHead::cut_in);
1411  IF_MATCH(buffer, *this, header, &JHead::cut_nu);
1412  IF_MATCH(buffer, *this, header, &JHead::simul);
1413  IF_MATCH(buffer, *this, header, &JHead::spectrum);
1414  IF_MATCH(buffer, *this, header, &JHead::can);
1415  IF_MATCH(buffer, *this, header, &JHead::fixedcan);
1416  IF_MATCH(buffer, *this, header, &JHead::genvol);
1417  IF_MATCH(buffer, *this, header, &JHead::coord_origin);
1418 
1419  IF_MATCH(buffer, *this, header, &JHead::norma);
1420  IF_MATCH(buffer, *this, header, &JHead::livetime);
1421 
1422  IF_MATCH(buffer, *this, header, &JHead::seabottom);
1423  IF_MATCH(buffer, *this, header, &JHead::depth);
1424  IF_MATCH(buffer, *this, header, &JHead::tgen);
1425  IF_MATCH(buffer, *this, header, &JHead::time_interval);
1426 
1427  IF_MATCH(buffer, *this, header, &JHead::primary);
1428  IF_MATCH(buffer, *this, header, &JHead::flux);
1429  IF_MATCH(buffer, *this, header, &JHead::DAQ);
1430  IF_MATCH(buffer, *this, header, &JHead::K40);
1431 
1432  return buffer;
1433 
1434 #undef IF_MATCH
1435  }
JAANET::depth depth
Definition: JHead.hh:1588
JAANET::genvol genvol
Definition: JHead.hh:1582
JAANET::norma norma
Definition: JHead.hh:1585
std::vector< JAANET::flux > flux
Definition: JHead.hh:1594
JAANET::cut_primary cut_primary
Definition: JHead.hh:1575
std::vector< JAANET::simul > simul
Definition: JHead.hh:1574
JAANET::fixedcan fixedcan
Definition: JHead.hh:1581
JAANET::can can
Definition: JHead.hh:1580
JAANET::cut_seamuon cut_seamuon
Definition: JHead.hh:1576
JAANET::livetime livetime
Definition: JHead.hh:1586
JAANET::seabottom seabottom
Definition: JHead.hh:1587
JAANET::spectrum spectrum
Definition: JHead.hh:1579
JAANET::K40 K40
Definition: JHead.hh:1590
JAANET::primary primary
Definition: JHead.hh:1593
Monte Carlo run header.
Definition: JHead.hh:1221
JAANET::time_interval time_interval
Definition: JHead.hh:1592
JAANET::tgen tgen
Definition: JHead.hh:1591
JAANET::cut_in cut_in
Definition: JHead.hh:1577
#define IF_MATCH(A, B, C, D)
JAANET::cut_nu cut_nu
Definition: JHead.hh:1578
JAANET::DAQ DAQ
Definition: JHead.hh:1589
Vec coord_origin() const
Get coordinate origin.
Definition: Head.hh:395
size_t JAANET::JHead::getNumberOfMatches ( const JHead header) const
inline

Get number of matching fields.

Parameters
headerheader
Returns
number of matching header fields

Definition at line 1444 of file JHead.hh.

1445  {
1446  const JHead head = getMatch(header);
1447 
1448  return head.size();
1449  }
JHead getMatch(const JHead &header) const
Get matching fields.
Definition: JHead.hh:1396
Monte Carlo run header.
Definition: JHead.hh:1221
bool JAANET::JHead::match ( const JHead header) const
inline

Test match of headers.

Parameters
headersecond header
Returns
true if all header fields match; else false

Definition at line 1458 of file JHead.hh.

1459  {
1460  return getNumberOfMatches(header) == getNumberOfMatches(*this);
1461  }
size_t getNumberOfMatches(const JHead &header) const
Get number of matching fields.
Definition: JHead.hh:1444
bool JAANET::JHead::less ( const JHead header) const
inline

Comparison of headers.

Parameters
headerheader
Returns
true if this header less than given header; else false

Definition at line 1470 of file JHead.hh.

1471  {
1472 #define RETURN_IF_DIFFERENT(A, B) \
1473  if (less(A,B)) { return true; } \
1474  if (less(B,A)) { return false; }
1475 
1476  // compare physics
1477 
1478  RETURN_IF_DIFFERENT(this->physics, header.physics);
1479 
1480  // compare simulation
1481 
1482  RETURN_IF_DIFFERENT(this->simul, header.simul);
1483 
1484  // compare generation data
1485 
1486  RETURN_IF_DIFFERENT(this->primary, header.primary);
1487  RETURN_IF_DIFFERENT(this->flux, header.flux);
1488  RETURN_IF_DIFFERENT(this->spectrum, header.spectrum);
1491  RETURN_IF_DIFFERENT(this->cut_in, header.cut_in);
1492  RETURN_IF_DIFFERENT(this->cut_nu, header.cut_nu);
1493  RETURN_IF_DIFFERENT(this->genvol, header.genvol);
1494 
1495  // compare compatibility
1496 
1497  if (is_valid(this->livetime) == is_valid(header.livetime) &&
1498  is_valid(this->DAQ) == is_valid(header.DAQ) &&
1499  is_valid(this->K40) == is_valid(header.K40)) {
1500  return false;
1501  }
1502 
1503  THROW(JException, "JHead::less() headers do not compare.");
1504 
1505 #undef RETURN_IF_DIFFERENT
1506  }
Phase space of incident neutrino.
Definition: JHead.hh:446
JAANET::genvol genvol
Definition: JHead.hh:1582
Neutrino vertex volume.
Definition: JHead.hh:636
std::vector< JAANET::flux > flux
Definition: JHead.hh:1594
Livetime of DAQ data.
Definition: JHead.hh:995
#define RETURN_IF_DIFFERENT(A, B)
Phase space of incoming particle.
Definition: JHead.hh:436
Generator for simulation.
Definition: JHead.hh:513
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:696
JAANET::cut_primary cut_primary
Definition: JHead.hh:1575
std::vector< JAANET::physics > physics
Definition: JHead.hh:1573
std::vector< JAANET::simul > simul
Definition: JHead.hh:1574
Physics information.
Definition: JHead.hh:503
JAANET::cut_seamuon cut_seamuon
Definition: JHead.hh:1576
JAANET::livetime livetime
Definition: JHead.hh:1586
Neutrino flux.
Definition: JHead.hh:893
JAANET::spectrum spectrum
Definition: JHead.hh:1579
JAANET::K40 K40
Definition: JHead.hh:1590
JAANET::primary primary
Definition: JHead.hh:1593
Normalisation of MUPAGE events.
Definition: JHead.hh:822
JAANET::cut_in cut_in
Definition: JHead.hh:1577
Primary particle.
Definition: JHead.hh:1161
JAANET::cut_nu cut_nu
Definition: JHead.hh:1578
Phase space of atmospheric muon generation.
Definition: JHead.hh:426
Phase space of primary particle.
Definition: JHead.hh:416
bool is_valid(T JHead::*pd) const
Check validity of given data member in JHead.
Definition: JHead.hh:1305
JAANET::DAQ DAQ
Definition: JHead.hh:1589
Livetime of noise data.
Definition: JHead.hh:1049
Neutrino energy spectrum.
Definition: JHead.hh:523
JHead& JAANET::JHead::add ( const JHead header)
inline

Addition of headers.

Parameters
headerheader
Returns
this header

Definition at line 1515 of file JHead.hh.

1516  {
1517  if (match(header)) {
1518 
1519  this->createUUID();
1520  this->UUID = JUUID::rndm();
1521 
1522  genvol .add(header.genvol);
1523  norma .add(header.norma);
1524  livetime.add(header.livetime);
1525  DAQ .add(header.DAQ);
1526  K40 .add(header.K40);
1527 
1528  } else {
1529 
1530  THROW(JException, "JHead::add() headers do not match.");
1531  }
1532 
1533  return *this;
1534  }
norma & add(const norma &object)
Addition.
Definition: JHead.hh:805
JAANET::genvol genvol
Definition: JHead.hh:1582
Neutrino vertex volume.
Definition: JHead.hh:636
JAANET::norma norma
Definition: JHead.hh:1585
Livetime of DAQ data.
Definition: JHead.hh:995
livetime & add(const livetime &object)
Addition.
Definition: JHead.hh:860
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:696
Normlisation of CORSIKA events.
Definition: JHead.hh:779
bool match(const JHead &header) const
Test match of headers.
Definition: JHead.hh:1458
void createUUID()
Create UUID if not already set.
Definition: JHead.hh:1287
DAQ & add(const DAQ &object)
Addition.
Definition: JHead.hh:1033
genvol & add(const genvol &object)
Addition.
Definition: JHead.hh:679
static const JUUID & rndm()
Generate random UUID.
Definition: JUUID.hh:67
JUUID UUID
Definition: JHead.hh:1567
JAANET::livetime livetime
Definition: JHead.hh:1586
JAANET::K40 K40
Definition: JHead.hh:1590
Normalisation of MUPAGE events.
Definition: JHead.hh:822
JAANET::DAQ DAQ
Definition: JHead.hh:1589
Livetime of noise data.
Definition: JHead.hh:1049
K40 & add(const K40 &object)
Addition.
Definition: JHead.hh:1087
static const size_t JAANET::JHead::getMaximumNumberOfMatches ( )
inlinestatic

Get maximum number of matching header fields.

Returns
maximum number of matching header fields

Definition at line 1603 of file JHead.hh.

1604  {
1605  static JHead header;
1606 
1607  header.push();
1608 
1609  static const size_t value = header.getNumberOfMatches(header);
1610 
1611  return value;
1612  }
void push(T JHead::*pd)
Push given data member to Head.
Definition: JHead.hh:1360
Monte Carlo run header.
Definition: JHead.hh:1221
size_t getNumberOfMatches(const JHead &header) const
Get number of matching fields.
Definition: JHead.hh:1444
static JLANG::JEquationParameters& JAANET::JHead::getEquationParameters ( )
inlinestatic

Get equation parameters corresponding to Monte Carlo ASCII format, i.e:

   <key>: <value> [<value>]*
   <key>: <value> [<value>]*
Returns
equation parameters

Definition at line 1624 of file JHead.hh.

1625  {
1626  static JLANG::JEquationParameters parameters(":", "\n", "", "");
1627 
1628  return parameters;
1629  }
*fatal Wrong number of arguments esac JCookie sh typeset Z DETECTOR typeset Z SOURCE_RUN typeset Z TARGET_RUN set_variable PARAMETERS_FILE $WORKDIR parameters
Definition: diff-Tuna.sh:38
Simple data structure to support I/O of equations (see class JLANG::JEquation).
static void JAANET::JHead::setEquationParameters ( const JLANG::JEquationParameters equation)
inlinestatic

Set equation parameters.

Parameters
equationequation parameters

Definition at line 1637 of file JHead.hh.

1638  {
1639  getEquationParameters() = equation;
1640  }
static JLANG::JEquationParameters & getEquationParameters()
Get equation parameters corresponding to Monte Carlo ASCII format, i.e:
Definition: JHead.hh:1624
std::istream & JAANET::JHead::read ( std::istream &  in)

Read header from input.

Parameters
ininput stream
Returns
input stream

Definition at line 53 of file JHead.cc.

54  {
55  using namespace std;
56  using namespace JPP;
57 
58  JStringStream is(in);
59 
60  if (getFileStatus(is.str().c_str())) {
61  is.load();
62  }
63 
65 
66  JRootReadableClass cls(*this);
67 
68  for (JEquation equation; reader >> equation && equation.getKey() != end_event::Class_Name(); ) {
69 
70  JRedirectString redirect(reader, equation.getValue());
71 
72  const JRootReadableClass abc = cls.find(equation.getKey().c_str());
73 
74  if (abc.is_valid()) {
75  reader.getObject(abc);
76  }
77 
78  (*this)[equation.getKey()] = equation.getValue();
79  }
80 
81  return in;
82  }
is
Definition: JDAQCHSM.chsm:167
T & getInstance(const T &object)
Get static instance from temporary object.
Definition: JObject.hh:75
static JLANG::JEquationParameters & getEquationParameters()
Get equation parameters corresponding to Monte Carlo ASCII format, i.e:
Definition: JHead.hh:1624
static JStat getFileStatus
Function object for file status.
Definition: JStat.hh:173
then fatal Wrong number of arguments fi set_variable DETECTOR $argv[1] set_variable INPUT_FILE $argv[2] eval JPrintDetector a $DETECTOR O IDENTIFIER eval JPrintDetector a $DETECTOR O SUMMARY JAcoustics sh $DETECTOR_ID source JAcousticsToolkit sh CHECK_EXIT_CODE typeset A EMITTERS get_tripods $WORKDIR tripod txt EMITTERS get_transmitters $WORKDIR transmitter txt EMITTERS for EMITTER in
Definition: JCanberra.sh:46
std::ostream & JAANET::JHead::write ( std::ostream &  out) const

Write header to output.

Parameters
outoutput stream
Returns
output stream

Definition at line 91 of file JHead.cc.

92  {
93  using namespace std;
94  using namespace JPP;
95 
96  JRootWriter writer(out, JHead::getEquationParameters(), JAAnetDictionary::getInstance());
97 
98  JRootWritableClass cls(*this);
99 
100  unique_ptr<TIterator> i(cls.getClass()->GetListOfDataMembers()->MakeIterator());
101 
102  for (const TDataMember* p; (p = (const TDataMember*) i->Next()) != NULL; ) {
103  if (!JRootClass::is_static(*p)) {
104  if (this->find(p->GetName()) != this->end() ||
105  cls.get(*p) == JRootClass(&JHead::start_run) ||
106  cls.get(*p) == JRootClass(&JHead::end_event)) {
107  writer.put(p->GetName(), cls.get(*p), true);
108  }
109  }
110  }
111 
112  return out << flush;
113  }
JAANET::end_event end_event
Definition: JHead.hh:1595
T & getInstance(const T &object)
Get static instance from temporary object.
Definition: JObject.hh:75
static JLANG::JEquationParameters & getEquationParameters()
Get equation parameters corresponding to Monte Carlo ASCII format, i.e:
Definition: JHead.hh:1624
JAANET::start_run start_run
Definition: JHead.hh:1566
std::ostream & JAANET::JHead::print ( std::ostream &  out) const

Print header to output.

Parameters
outoutput stream
Returns
output stream

Definition at line 122 of file JHead.cc.

123  {
124  using namespace std;
125  using namespace JPP;
126 
127  JRootWriter writer(out, JHead::getEquationParameters(), JAAnetDictionary::getInstance());
128 
129  JRootWritableClass cls(*this);
130 
131  unique_ptr<TIterator> i(cls.getClass()->GetListOfDataMembers()->MakeIterator());
132 
134 
135  for (const TDataMember* p; (p = (const TDataMember*) i->Next()) != NULL; ) {
136  if (!JRootClass::is_static(*p)) {
137  if (cls.get(*p) != JRootClass(&JHead::end_event))
138  writer.put(p->GetName(), cls.get(*p), true);
139  else
140  end_event = make_pair(p->GetName(), cls.get(*p));
141  }
142  }
143 
144  for (JHead::const_iterator i = this->begin(); i != this->end(); ++i) {
145  if (!cls.find(i->first.c_str()).is_valid()) {
146  writer.put(i->first, i->second);
147  }
148  }
149 
150  writer.put(end_event.first, end_event.second, true);
151 
152  return out << flush;
153  }
JAANET::end_event end_event
Definition: JHead.hh:1595
T & getInstance(const T &object)
Get static instance from temporary object.
Definition: JObject.hh:75
static JLANG::JEquationParameters & getEquationParameters()
Get equation parameters corresponding to Monte Carlo ASCII format, i.e:
Definition: JHead.hh:1624
bool is_valid(T JHead::*pd) const
Check validity of given data member in JHead.
Definition: JHead.hh:1305
JAANET::JHead::ClassDef ( JHead  ,
 
)
template<class T >
static bool JAANET::JHead::less ( const T first,
const T second 
)
inlinestaticprivate

Comparison.

Parameters
firstfirst object
secondsecond object
Returns
true if first less than second; else false

Definition at line 1681 of file JHead.hh.

1683  {
1684  return first.less(second);
1685  }
then echo The file $DIR KM3NeT_00000001_00000000 root already please rename or remove it first
template<class T >
static bool JAANET::JHead::match ( const T first,
const T second 
)
inlinestaticprivate

Test match.

Parameters
firstfirst object
secondsecond object
Returns
true if matches; else false

Definition at line 1696 of file JHead.hh.

1698  {
1699  return first.match(second);
1700  }
then echo The file $DIR KM3NeT_00000001_00000000 root already please rename or remove it first
template<class T >
static bool JAANET::JHead::less ( const std::vector< T > &  first,
const std::vector< T > &  second 
)
inlinestaticprivate

Comparison of containers.

It is assumed that the containers are ordered in the same way.

Parameters
firstfirst object
secondsecond object
Returns
true if first is less than second; else false

Definition at line 1712 of file JHead.hh.

1714  {
1715  if (first.size() == second.size()) {
1716 
1717  for (size_t i = 0; i != first.size(); ++i) {
1718  if (less(first[i], second[i])) {
1719  return true;
1720  }
1721  }
1722 
1723  return false;
1724 
1725  } else {
1726 
1727  return first.size() < second.size();
1728  }
1729  }
bool less(const JHead &header) const
Comparison of headers.
Definition: JHead.hh:1470
template<class T >
static bool JAANET::JHead::match ( const std::vector< T > &  first,
const std::vector< T > &  second 
)
inlinestaticprivate

Test is containers match.

It is assumed that the containers are ordered in the same way.

Parameters
firstfirst object
secondsecond object
Returns
true if matches; else false

Definition at line 1741 of file JHead.hh.

1743  {
1744  for (size_t i = 0; i != first.size() && i != second.size(); ++i) {
1745  if (!match(first[i], second[i])) {
1746  return false;
1747  }
1748  }
1749 
1750  return first.size() == second.size();
1751  }
bool match(const JHead &header) const
Test match of headers.
Definition: JHead.hh:1458
template<class T >
static bool JAANET::JHead::match ( const JHead first,
const JHead second,
T JHead::*  pd 
)
inlinestaticprivate

Test match of given data member of headers.

Parameters
firstfirst header
secondsecond header
pdpointer to data member
Returns
true if matches; else false

Definition at line 1763 of file JHead.hh.

1766  {
1767  return (first .is_valid(pd) &&
1768  second.is_valid(pd) &&
1769  match(first.*pd, second.*pd));
1770  }
bool match(const JHead &header) const
Test match of headers.
Definition: JHead.hh:1458
bool is_valid(T JHead::*pd) const
Check validity of given data member in JHead.
Definition: JHead.hh:1305
bool Head::have_line ( std::string  key) const
inlineinherited

Check availability of data with the given key.

Parameters
keykey
Returns
true if data are available; else false

Definition at line 78 of file Head.hh.

79  {
80  return count( key ) != 0;
81  }
const std::string& Head::get_line ( std::string  key) const
inlineinherited

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 90 of file Head.hh.

91  {
92  return this->at(key);
93  }
std::string& Head::get_line ( std::string  key)
inlineinherited

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 102 of file Head.hh.

103  {
104  return this->at(key);
105  }
std::vector< std::string> Head::matching_keys ( const std::string tag) const
inlineinherited

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
tagtag (without suffix)

Definition at line 116 of file Head.hh.

117  {
119 
120  auto match = [&] (const std::string & key) {
121 
122  if (key == tag) return true;
123 
124  if ( key.find( tag ) != 0 ) return false;
125 
126  // what is left should be of the form _d(ddd)
127  std::string left = key.substr( tag.length(), key.length() );
128  if (left.length() < 2 || left[0] != '_' ) return false ;
129  for ( unsigned i = 1; i < left.length(); i++ )
130  {
131  if (!std::isdigit( left[i] )) return false ;
132  }
133  return true;
134  };
135 
136  for ( auto& p : *this )
137  {
138  if ( match( p.first ) ) r.push_back( p.first );
139  }
140 
141  return r;
142  }
data_type r[M+1]
Definition: JPolint.hh:779
then awk string
std::vector< std::string > Head::get_lines ( const std::string tag) const
inlineinherited

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
tagtag (without suffix)
Returns
data

Definition at line 155 of file Head.hh.

156  {
158 
159  for ( auto& key : matching_keys( tag ) ) {
160  r.push_back( get_line( key ) );
161  }
162 
163  return r;
164  }
data_type r[M+1]
Definition: JPolint.hh:779
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 &quot;_n&quot;.
Definition: Head.hh:116
const std::string & get_line(std::string key) const
Get data with the given key.
Definition: Head.hh:90
std::string Head::set_line ( std::string  tag,
std::string  line,
bool  ensure_unique = true 
)
inlineinherited

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
tagtag
linedata
ensure_uniqueadd '_n' (with n an integer) to the tag if it would overwrite an existing key.

Definition at line 177 of file Head.hh.

178  {
179  std::string k = tag;
180 
181  if (ensure_unique)
182  for (int i = 1; find(k) != end() ; i++)
183  {
184  k = tag + "_" + std::to_string(i);
185  }
186 
188  return k;
189  }
then fatal No hydrophone data file $HYDROPHONE_TXT fi sort gr k
then awk string
std::string to_string(const T &value)
Convert value to string.
std::string Head::get_field ( std::string  key,
int  idx 
) const
inlineinherited

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 199 of file Head.hh.

200  {
201  using namespace std;
202 
204 
205  if ( idx < 0 || idx >= int ( v.size() ) )
206  {
207  THROW(Exception, "Cannot find word number " << idx << " in line " << get_line(key) << " for key: " << key);
208  }
209  return v[idx];
210  }
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:696
General exception.
Definition: Exception.hh:13
const std::string & get_line(std::string key) const
Get data with the given key.
Definition: Head.hh:90
data_type v[N+1][M+1]
Definition: JPolint.hh:777
std::vector< std::string > splitstring(const std::string &str, char delim= ' ')
Split string at delimiter.
Definition: Head.hh:44
std::string Head::get_field ( std::string  key,
std::string  field 
) const
inlineinherited

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 239 of file Head.hh.

240  {
241  int idx = get_index_of_field(key, field);
242 
243  if ( idx == -1 )
244  {
245  THROW(Exception, "Failed to find" << key << " " << field);
246  }
247 
248  return get_field( key, idx );
249  }
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:696
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:221
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:199
int Head::get_index_of_field ( std::string  key,
std::string  field 
) const
inlineinherited

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 221 of file Head.hh.

222  {
223  auto v = _hdr_dict()[key];
224  auto i = std::find (v.begin(), v.end(), field );
225  if (i == v.end()) return -1;
226  return i - v.begin();
227  }
data_type v[N+1][M+1]
Definition: JPolint.hh:777
static std::map< std::string, std::vector< std::string > > & _hdr_dict()
Get internal description of the known lines in header.
Definition: Head.hh:314
void Head::set_field ( std::string  key,
std::string  field,
std::string  value 
)
inlineinherited

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 262 of file Head.hh.

263  {
264  using namespace std;
265 
266  if ( field == "" ) get_line( key ) = value;
267 
268  int idx = get_index_of_field( key, field );
269 
270  if ( idx < 0 )
271  {
272  THROW(Exception, "GFailed to find field in header line: " << key << " " << field);
273  }
274 
275  vector<string> vals = splitstring( get_line( key ) );
276 
277  // if the fields before do not exist, add padding
278  while ( int( vals.size() ) <= idx ) vals.push_back("0");
279 
280  vals[idx] = value;
281  ostringstream ss;
282 
283  for (unsigned i = 0; i < vals.size() ; i++ )
284  {
285  ss << vals[i];
286  if ( i != vals.size() - 1) ss << " ";
287  }
288  set_line( key, ss.str() );
289 
290  }
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:696
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:221
std::string set_line(std::string tag, std::string line, bool ensure_unique=true)
Set data with the given tag.
Definition: Head.hh:177
General exception.
Definition: Exception.hh:13
const std::string & get_line(std::string key) const
Get data with the given key.
Definition: Head.hh:90
std::vector< std::string > splitstring(const std::string &str, char delim= ' ')
Split string at delimiter.
Definition: Head.hh:44
static std::map<std::string, std::vector<std::string> >& Head::_hdr_dict ( )
inlinestaticinherited

Get internal description of the known lines in header.

Returns
internal dictionary

Definition at line 314 of file Head.hh.

315  {
316  using namespace std;
317 
318  // map with, for each tag (key), a vector of field-names
319 
320  static map<string, vector<string> > r;
321  if ( r.size() > 0 ) return r;
322 
323  string desc =
324  "DAQ:livetime\n"
325  "cut_primary cut_seamuon cut_in cut_nu:Emin Emax cosTmin cosTmax\n"
326  "generator physics simul:program version date time\n"
327  "seed:program level iseed\n"
328  "PM1_type_area:type area TTS\n"
329  "PDF:i1 i2\n"
330  "model:interaction muon scattering numberOfEnergyBins\n"
331  "can:zmin zmax r\n"
332  "genvol:zmin zmax r volume numberOfEvents\n"
333  "merge:time gain\n"
334  "coord_origin:x y z\n"
335  "translate:x y z\n"
336  "genhencut:gDir Emin\n"
337  "k40:rate time\n"
338  "norma:primaryFlux numberOfPrimaries\n"
339  "livetime:numberOfSeconds errorOfSeconds\n"
340  "flux:type key file_1 file_2\n"
341  "spectrum:alpha\n"
342  "fixedcan:xcenter ycenter zmin zmax radius\n"
343  "start_run:run_id";
344 
345  for ( auto line : splitstring(desc, '\n') )
346  {
347  auto v = splitstring( line, ':');
348 
349  vector< string > fields = splitstring( v[1] );
350  for ( auto key : splitstring( v[0] ) )
351  {
352  r[key] = fields;
353  }
354  }
355  return r;
356  }
data_type r[M+1]
Definition: JPolint.hh:779
data_type v[N+1][M+1]
Definition: JPolint.hh:777
std::vector< std::string > splitstring(const std::string &str, char delim= ' ')
Split string at delimiter.
Definition: Head.hh:44
double Head::ngen ( ) const
inlineinherited

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

Returns
number of events

Definition at line 364 of file Head.hh.

365  {
366  return stod ( get_field("genvol", "numberOfEvents") );
367  }
std::string get_field(std::string key, int idx) const
Get data with the given key at given index.
Definition: Head.hh:199
double Head::daq_livetime ( ) const
inlineinherited

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

Returns
live time [s]

Definition at line 374 of file Head.hh.

375  {
376  return stod ( get_field("DAQ", "livetime") );
377  }
std::string get_field(std::string key, int idx) const
Get data with the given key at given index.
Definition: Head.hh:199
double Head::mc_livetime ( ) const
inlineinherited

Get the Monte Carlo live time.

Returns
live time [s]

Definition at line 385 of file Head.hh.

386  {
387  return stod ( get_field("livetime", "numberOfSeconds") );
388  }
std::string get_field(std::string key, int idx) const
Get data with the given key at given index.
Definition: Head.hh:199
Vec Head::coord_origin ( ) const
inlineinherited

Get coordinate origin.

Returns
position

Definition at line 395 of file Head.hh.

396  {
397  return Vec( stod( get_field("coord_origin", "x") ),
398  stod( get_field("coord_origin", "y") ),
399  stod( get_field("coord_origin", "z") ));
400  }
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:199
Vec Head::translate ( ) const
inlineinherited

Get coordinate translation.

Returns
translation

Definition at line 407 of file Head.hh.

408  {
409  return Vec( stod( get_field("translate", "x") ),
410  stod( get_field("translate", "y") ),
411  stod( get_field("translate", "z") ));
412  }
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:199
static void Head::actionAtFileOpen ( int  version)
inlinestaticinherited

Action method at file open.

Parameters
versionversion

Definition at line 421 of file Head.hh.

422  {
424  }
version
Definition: JEditTuneHV.sh:5
static int ROOT_IO_VERSION
Streamer version as obtained from ROOT file.
Definition: Head.hh:426
Head::ClassDef ( Head  ,
 
)
inherited

Friends And Related Function Documentation

bool operator== ( const JHead first,
const JHead second 
)
friend

Equal operator.

Note that this operator uses the JHead::match method.

Parameters
firstfirst header
secondsecond header
Returns
true if two headers are equal; else false

Definition at line 1546 of file JHead.hh.

1548  {
1549  return first.match(second);
1550  }
bool match(const JHead &header) const
Test match of headers.
Definition: JHead.hh:1458
bool operator< ( const JHead first,
const JHead second 
)
friend

Less than operator.

Parameters
firstfirst header
secondsecond header
Returns
true if first header is less than second header; else false

Definition at line 1560 of file JHead.hh.

1562  {
1563  return first.less(second);
1564  }
bool less(const JHead &header) const
Comparison of headers.
Definition: JHead.hh:1470

Member Data Documentation

JAANET::start_run JAANET::JHead::start_run

Definition at line 1566 of file JHead.hh.

JUUID JAANET::JHead::UUID

Definition at line 1567 of file JHead.hh.

JAANET::XSecFile JAANET::JHead::XSecFile

Definition at line 1568 of file JHead.hh.

JAANET::drawing JAANET::JHead::drawing

Definition at line 1569 of file JHead.hh.

std::vector<JAANET::detector> JAANET::JHead::detector

Definition at line 1570 of file JHead.hh.

JAANET::muon_desc_file JAANET::JHead::muon_desc_file

Definition at line 1571 of file JHead.hh.

JAANET::target JAANET::JHead::target

Definition at line 1572 of file JHead.hh.

std::vector<JAANET::physics> JAANET::JHead::physics

Definition at line 1573 of file JHead.hh.

std::vector<JAANET::simul> JAANET::JHead::simul

Definition at line 1574 of file JHead.hh.

JAANET::cut_primary JAANET::JHead::cut_primary

Definition at line 1575 of file JHead.hh.

JAANET::cut_seamuon JAANET::JHead::cut_seamuon

Definition at line 1576 of file JHead.hh.

JAANET::cut_in JAANET::JHead::cut_in

Definition at line 1577 of file JHead.hh.

JAANET::cut_nu JAANET::JHead::cut_nu

Definition at line 1578 of file JHead.hh.

JAANET::spectrum JAANET::JHead::spectrum

Definition at line 1579 of file JHead.hh.

JAANET::can JAANET::JHead::can

Definition at line 1580 of file JHead.hh.

JAANET::fixedcan JAANET::JHead::fixedcan

Definition at line 1581 of file JHead.hh.

JAANET::genvol JAANET::JHead::genvol

Definition at line 1582 of file JHead.hh.

JAANET::coord_origin JAANET::JHead::coord_origin

Definition at line 1583 of file JHead.hh.

JAANET::genhencut JAANET::JHead::genhencut

Definition at line 1584 of file JHead.hh.

JAANET::norma JAANET::JHead::norma

Definition at line 1585 of file JHead.hh.

JAANET::livetime JAANET::JHead::livetime

Definition at line 1586 of file JHead.hh.

JAANET::seabottom JAANET::JHead::seabottom

Definition at line 1587 of file JHead.hh.

JAANET::depth JAANET::JHead::depth

Definition at line 1588 of file JHead.hh.

JAANET::DAQ JAANET::JHead::DAQ

Definition at line 1589 of file JHead.hh.

JAANET::K40 JAANET::JHead::K40

Definition at line 1590 of file JHead.hh.

JAANET::tgen JAANET::JHead::tgen

Definition at line 1591 of file JHead.hh.

JAANET::time_interval JAANET::JHead::time_interval

Definition at line 1592 of file JHead.hh.

JAANET::primary JAANET::JHead::primary

Definition at line 1593 of file JHead.hh.

std::vector<JAANET::flux> JAANET::JHead::flux

Definition at line 1594 of file JHead.hh.

JAANET::end_event JAANET::JHead::end_event

Definition at line 1595 of file JHead.hh.

int Head::ROOT_IO_VERSION = -1
staticinherited

Streamer version as obtained from ROOT file.

Definition at line 426 of file Head.hh.


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