Jpp 19.3.0-rc.3
the software that should make you happy
Loading...
Searching...
No Matches
JAANET::JHead Class 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.
 
 JHead (const Head &header)
 Copy constructor.
 
virtual ~JHead ()
 Virtual destructor.
 
const JHeadgetHeader () const
 Get header.
 
JHeadgetHeader ()
 Get header.
 
void setHeader (const JHead &header)
 Set header.
 
void createUUID ()
 Create UUID if not already set.
 
template<class T >
bool is_valid (T JHead::*pd) const
 Check validity of given data member in JHead.
 
template<class T >
const_iterator pull (T JHead::*pd) const
 Pull given data member from Head.
 
template<class T >
iterator pull (T JHead::*pd)
 Pull given data member from Head.
 
template<class T >
void push (T JHead::*pd)
 Push given data member to Head.
 
void push ()
 Push all data members to Head.
 
template<class T >
void erase (T JHead::*pd)
 Reset and remove given data member from Head.
 
JHead getMatch (const JHead &header) const
 Get matching fields.
 
size_t getNumberOfMatches (const JHead &header) const
 Get number of matching fields.
 
bool match (const JHead &header) const
 Test match of headers.
 
bool less (const JHead &header) const
 Comparison of headers.
 
JHeadadd (const JHead &header)
 Addition of headers.
 
std::istream & read (std::istream &in)
 Read header from input.
 
std::ostream & write (std::ostream &out) const
 Write header to output.
 
std::ostream & print (std::ostream &out) const
 Print header to output.
 
 ClassDef (JHead, 5)
 
bool have_line (std::string key) const
 Check availability of data with the given key.
 
const std::string & get_line (std::string key) const
 Get data with the given key.
 
std::string & get_line (std::string key)
 Get data with the given key.
 
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".
 
std::vector< std::string > get_lines (const std::string &tag) const
 Get all data compatible with the given key.
 
std::string set_line (std::string tag, std::string line, bool ensure_unique=true)
 Set data with the given tag.
 
std::string get_field (std::string key, int idx) const
 Get data with the given key at given index.
 
std::string get_field (std::string key, std::string field) const
 Get data with the given key at given field.
 
int get_index_of_field (std::string key, std::string field) const
 Get index of data with the given key at given field.
 
void set_field (std::string key, std::string field, std::string value)
 Set data with the given key at given field.
 
double ngen () const
 Get the number of generated events needed for computing event rates.
 
double daq_livetime () const
 Get the the live time provided by the DAQ sytstem (=number of processed timeslices * frametime).
 
double mc_livetime () const
 Get the Monte Carlo live time.
 
Vec coord_origin () const
 Get coordinate origin.
 
Vec translate () const
 Get coordinate translation.
 
 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.
 
static const size_t getMaximumNumberOfMatches ()
 Get maximum number of matching header fields.
 
static JLANG::JEquationParametersgetEquationParameters ()
 Get equation parameters corresponding to Monte Carlo ASCII format, i.e:
 
static void setEquationParameters (const JLANG::JEquationParameters &equation)
 Set equation parameters.
 
static const std::map< std::string, std::vector< std::string > > & _hdr_dict ()
 Get internal description of the known lines in header.
 
static void actionAtFileOpen (int version)
 Action method at file open.
 

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::calibration calibration
 
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.
 

Static Private Member Functions

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

Friends

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

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 1234 of file JHead.hh.

Constructor & Destructor Documentation

◆ JHead() [1/2]

JAANET::JHead::JHead ( )
inline

Default constructor.

Definition at line 1241 of file JHead.hh.

1242 {
1243 createUUID();
1244 }
void createUUID()
Create UUID if not already set.
Definition JHead.hh:1301

◆ JHead() [2/2]

JAANET::JHead::JHead ( const Head & header)
inline

Copy constructor.

Parameters
headerheader

Definition at line 1252 of file JHead.hh.

1253 {
1254 copy(header, *this);
1255 }
void copy(const Head &from, JHead &to)
Copy header from from to to.
Definition JHead.cc:163

◆ ~JHead()

virtual JAANET::JHead::~JHead ( )
inlinevirtual

Virtual destructor.

Definition at line 1261 of file JHead.hh.

1262 {}

Member Function Documentation

◆ getHeader() [1/2]

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

Get header.

Returns
header

Definition at line 1270 of file JHead.hh.

1271 {
1272 return static_cast<const JHead&>(*this);
1273 }
JHead()
Default constructor.
Definition JHead.hh:1241

◆ getHeader() [2/2]

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

Get header.

Returns
header

Definition at line 1281 of file JHead.hh.

1282 {
1283 return static_cast<JHead&>(*this);
1284 }

◆ setHeader()

void JAANET::JHead::setHeader ( const JHead & header)
inline

Set header.

Parameters
headerheader

Definition at line 1292 of file JHead.hh.

1293 {
1294 static_cast<JHead&>(*this) = header;
1295 }

◆ createUUID()

void JAANET::JHead::createUUID ( )
inline

Create UUID if not already set.

Definition at line 1301 of file JHead.hh.

1302 {
1303 if (!is_valid(&JHead::UUID)) {
1304 this->UUID = JUUID::rndm();
1305 this->push(&JHead::UUID);
1306 }
1307 }
void push()
Push all data members to Head.
Definition JHead.cc:29
bool is_valid(T JHead::*pd) const
Check validity of given data member in JHead.
Definition JHead.hh:1319
static const JUUID & rndm()
Generate random UUID.
Definition JUUID.hh:78

◆ is_valid() [1/2]

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 1319 of file JHead.hh.

1320 {
1321 return (this->pull(pd) != this->end());
1322 }
const_iterator pull(T JHead::*pd) const
Pull given data member from Head.
Definition JHead.hh:1349

◆ is_valid() [2/2]

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 1334 of file JHead.hh.

1335 {
1336 static const T value;
1337
1338 return (object.less(value) || value.less(object));
1339 }
bool less(const JHead &header) const
Comparison of headers.
Definition JHead.hh:1486

◆ pull() [1/2]

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 1349 of file JHead.hh.

1350 {
1351 return this->find(JROOT::getDataMember(pd)->GetName());
1352 }
const TDataMember * getDataMember(const JRootClass &parent, const JRootClass &member)
Get ROOT data member for given parent and member class.

◆ pull() [2/2]

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 1362 of file JHead.hh.

1363 {
1364 return this->find(JROOT::getDataMember(pd)->GetName());
1365 }

◆ push() [1/2]

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 1374 of file JHead.hh.

1375 {
1376 (*this)[JROOT::getDataMember(pd)->GetName()] = "";
1377 }

◆ push() [2/2]

void JAANET::JHead::push ( )

Push all data members to Head.

Definition at line 29 of file JHead.cc.

30 {
31 using namespace std;
32 using namespace JPP;
33
34 JRootReadableClass cls(*this);
35
36 unique_ptr<TIterator> i(cls.getClass()->GetListOfDataMembers()->MakeIterator());
37
38 for (const TDataMember* p; (p = (const TDataMember*) i->Next()) != NULL; ) {
39 if (!JRoot::is_static(*p)) {
40 if (this->count(p->GetName()) == 0) {
41 (*this)[p->GetName()] = "";
42 }
43 }
44 }
45 }
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
ROOT class for reading into object.

◆ erase()

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 1392 of file JHead.hh.

1393 {
1394 this->*pd = T();
1395
1396 iterator p = this->pull(pd);
1397
1398 if (p != this->end()) {
1399 static_cast<Head*>(this)->erase(p);
1400 }
1401 }
void erase(T JHead::*pd)
Reset and remove given data member from Head.
Definition JHead.hh:1392
The Head class reflects the header of Monte-Carlo event files, which consists of keys (also referred ...
Definition Head.hh:65

◆ getMatch()

JHead JAANET::JHead::getMatch ( const JHead & header) const
inline

Get matching fields.

Parameters
headerheader
Returns
header with matching fields

Definition at line 1410 of file JHead.hh.

1411 {
1412#define IF_MATCH(A, B, C, D) \
1413 if (match(B,C,D)) { A.push(D); } \
1414 else { A.erase(D); }
1415
1416 JHead buffer(*this);
1417
1418 buffer.clear();
1419
1420 buffer.createUUID();
1421
1422 IF_MATCH(buffer, *this, header, &JHead::cut_primary);
1423 IF_MATCH(buffer, *this, header, &JHead::cut_seamuon);
1424 IF_MATCH(buffer, *this, header, &JHead::cut_in);
1425 IF_MATCH(buffer, *this, header, &JHead::cut_nu);
1426 IF_MATCH(buffer, *this, header, &JHead::simul);
1427 IF_MATCH(buffer, *this, header, &JHead::physics);
1428 IF_MATCH(buffer, *this, header, &JHead::spectrum);
1429 IF_MATCH(buffer, *this, header, &JHead::can);
1430 IF_MATCH(buffer, *this, header, &JHead::fixedcan);
1431 IF_MATCH(buffer, *this, header, &JHead::genvol);
1432 IF_MATCH(buffer, *this, header, &JHead::coord_origin);
1433
1434 IF_MATCH(buffer, *this, header, &JHead::norma);
1435 IF_MATCH(buffer, *this, header, &JHead::livetime);
1436
1437 IF_MATCH(buffer, *this, header, &JHead::seabottom);
1438 IF_MATCH(buffer, *this, header, &JHead::depth);
1439 IF_MATCH(buffer, *this, header, &JHead::tgen);
1440 //IF_MATCH(buffer, *this, header, &JHead::time_interval);
1441
1442 IF_MATCH(buffer, *this, header, &JHead::primary);
1443 IF_MATCH(buffer, *this, header, &JHead::flux);
1444 IF_MATCH(buffer, *this, header, &JHead::DAQ);
1445 IF_MATCH(buffer, *this, header, &JHead::K40);
1446 IF_MATCH(buffer, *this, header, &JHead::target);
1447
1448 return buffer;
1449
1450#undef IF_MATCH
1451 }
#define IF_MATCH(A, B, C, D)
JAANET::spectrum spectrum
Definition JHead.hh:1597
std::vector< JAANET::simul > simul
Definition JHead.hh:1591
JAANET::seabottom seabottom
Definition JHead.hh:1605
JAANET::coord_origin coord_origin
Definition JHead.hh:1601
JAANET::norma norma
Definition JHead.hh:1603
JAANET::cut_in cut_in
Definition JHead.hh:1595
JAANET::livetime livetime
Definition JHead.hh:1604
JAANET::cut_nu cut_nu
Definition JHead.hh:1596
JAANET::primary primary
Definition JHead.hh:1611
JAANET::DAQ DAQ
Definition JHead.hh:1607
JAANET::tgen tgen
Definition JHead.hh:1609
JAANET::genvol genvol
Definition JHead.hh:1600
JAANET::depth depth
Definition JHead.hh:1606
std::vector< JAANET::flux > flux
Definition JHead.hh:1612
JAANET::target target
Definition JHead.hh:1589
JAANET::cut_seamuon cut_seamuon
Definition JHead.hh:1594
JAANET::can can
Definition JHead.hh:1598
JAANET::fixedcan fixedcan
Definition JHead.hh:1599
JAANET::K40 K40
Definition JHead.hh:1608
std::vector< JAANET::physics > physics
Definition JHead.hh:1590
JAANET::cut_primary cut_primary
Definition JHead.hh:1593

◆ getNumberOfMatches()

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 1460 of file JHead.hh.

1461 {
1462 const JHead head = getMatch(header);
1463
1464 return head.size();
1465 }
JHead getMatch(const JHead &header) const
Get matching fields.
Definition JHead.hh:1410

◆ match() [1/4]

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 1474 of file JHead.hh.

1475 {
1476 return getNumberOfMatches(header) == getNumberOfMatches(*this);
1477 }
size_t getNumberOfMatches(const JHead &header) const
Get number of matching fields.
Definition JHead.hh:1460

◆ less() [1/3]

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 1486 of file JHead.hh.

1487 {
1488#define RETURN_IF_DIFFERENT(A, B) \
1489 if (less(A,B)) { return true; } \
1490 if (less(B,A)) { return false; }
1491
1492 // compare physics
1493
1494 RETURN_IF_DIFFERENT(this->physics, header.physics);
1495
1496 // compare simulation
1497
1498 RETURN_IF_DIFFERENT(this->simul, header.simul);
1499
1500 // compare generation data
1501
1502 RETURN_IF_DIFFERENT(this->primary, header.primary);
1503 RETURN_IF_DIFFERENT(this->flux, header.flux);
1504 RETURN_IF_DIFFERENT(this->spectrum, header.spectrum);
1505 RETURN_IF_DIFFERENT(this->cut_primary, header.cut_primary);
1506 RETURN_IF_DIFFERENT(this->cut_seamuon, header.cut_seamuon);
1507 RETURN_IF_DIFFERENT(this->cut_in, header.cut_in);
1508 RETURN_IF_DIFFERENT(this->cut_nu, header.cut_nu);
1509 RETURN_IF_DIFFERENT(this->genvol, header.genvol);
1510 RETURN_IF_DIFFERENT(this->target, header.target);
1511
1512 // compare compatibility
1513
1514 if (is_valid(this->livetime) == is_valid(header.livetime) &&
1515 is_valid(this->DAQ) == is_valid(header.DAQ) &&
1516 is_valid(this->K40) == is_valid(header.K40)) {
1517 return false;
1518 }
1519
1520 THROW(JException, "JHead::less() headers do not compare.");
1521
1522#undef RETURN_IF_DIFFERENT
1523 }
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
#define RETURN_IF_DIFFERENT(A, B)
genvol()
Default constructor.
Definition JHead.hh:653
primary()
Default constructor.
Definition JHead.hh:1178
spectrum()
Default constructor.
Definition JHead.hh:540

◆ add()

JHead & JAANET::JHead::add ( const JHead & header)
inline

Addition of headers.

Parameters
headerheader
Returns
this header

Definition at line 1532 of file JHead.hh.

1533 {
1534 if (match(header)) {
1535
1536 this->createUUID();
1537 this->UUID = JUUID::rndm();
1538
1539 genvol .add(header.genvol);
1540 norma .add(header.norma);
1541 livetime.add(header.livetime);
1542 DAQ .add(header.DAQ);
1543 K40 .add(header.K40);
1544
1545 } else {
1546
1547 THROW(JException, "JHead::add() headers do not match.");
1548 }
1549
1550 return *this;
1551 }
bool match(const JHead &header) const
Test match of headers.
Definition JHead.hh:1474
DAQ & add(const DAQ &object)
Addition.
Definition JHead.hh:1046
K40 & add(const K40 &object)
Addition.
Definition JHead.hh:1100
genvol & add(const genvol &object)
Addition.
Definition JHead.hh:692
livetime & add(const livetime &object)
Addition.
Definition JHead.hh:873
norma & add(const norma &object)
Addition.
Definition JHead.hh:818

◆ getMaximumNumberOfMatches()

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 1621 of file JHead.hh.

1622 {
1623 static JHead header;
1624
1625 header.push();
1626
1627 static const size_t value = header.getNumberOfMatches(header);
1628
1629 return value;
1630 }

◆ getEquationParameters()

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 1642 of file JHead.hh.

1643 {
1644 static JLANG::JEquationParameters parameters(":", "\n", "", "");
1645
1646 return parameters;
1647 }
Simple data structure to support I/O of equations (see class JLANG::JEquation).

◆ setEquationParameters()

static void JAANET::JHead::setEquationParameters ( const JLANG::JEquationParameters & equation)
inlinestatic

Set equation parameters.

Parameters
equationequation parameters

Definition at line 1655 of file JHead.hh.

1656 {
1657 getEquationParameters() = equation;
1658 }
static JLANG::JEquationParameters & getEquationParameters()
Get equation parameters corresponding to Monte Carlo ASCII format, i.e:
Definition JHead.hh:1642

◆ read()

std::istream & JAANET::JHead::read ( std::istream & in)

Read header from input.

Parameters
ininput stream
Returns
input stream

Definition at line 54 of file JHead.cc.

55 {
56 using namespace std;
57 using namespace JPP;
58
59 JStringStream is(in);
60
61 if (getFileStatus(is.str().c_str())) {
62 is.load();
63 }
64
65 JRootReader reader(is, JHead::getEquationParameters(), JAAnetDictionary::getInstance());
66
67 JRootReadableClass cls(*this);
68
69 for (JEquation equation; reader >> equation && equation.getKey() != end_event::Class_Name(); ) {
70
71 JRedirectString redirect(reader, equation.getValue());
72
73 const JRootReadableClass abc = cls.find(equation.getKey().c_str());
74
75 if (abc.is_valid()) {
76 reader.getObject(abc);
77 }
78
79 (*this)[equation.getKey()] = equation.getValue();
80 }
81
82 return in;
83 }
General purpose equation class.
Definition JEquation.hh:47
const std::string & getKey() const
Get key.
Definition JEquation.hh:163
This class can be used to temporarily redirect an input stream to an input string.
Wrapper class around STL stringstream class to facilitate optional loading of data from file.
Implementation for ASCII input of objects with ROOT dictionary.
bool is_valid() const
Check validity of this addressable class.
JRootAddressableClass find(const char *const name) const
Find addressable base class or data member with given name within current class.

◆ write()

std::ostream & JAANET::JHead::write ( std::ostream & out) const

Write header to output.

Parameters
outoutput stream
Returns
output stream

Definition at line 92 of file JHead.cc.

93 {
94 using namespace std;
95 using namespace JPP;
96
97 JRootWriter writer(out, JHead::getEquationParameters(), JAAnetDictionary::getInstance());
98
99 JRootWritableClass cls(*this);
100
101 unique_ptr<TIterator> i(cls.getClass()->GetListOfDataMembers()->MakeIterator());
102
103 for (const TDataMember* p; (p = (const TDataMember*) i->Next()) != NULL; ) {
104 if (!JRoot::is_static(*p)) {
105 if (this->find(p->GetName()) != this->end() ||
106 cls.get(*p) == JRootClass(&JHead::start_run) ||
107 cls.get(*p) == JRootClass(&JHead::end_event)) {
108 writer.put(p->GetName(), cls.get(*p), true);
109 }
110 }
111 }
112
113 return out << flush;
114 }
JAANET::start_run start_run
Definition JHead.hh:1583
JAANET::end_event end_event
Definition JHead.hh:1613
Implementation for ASCII output of objects with ROOT dictionary.
Auxiliary class to manage access to base classes and data members of ROOT class.
Definition JRootClass.hh:43
JRootClass get(const TDataMember &object) const
Get ROOT class of given data member.
ROOT class for writing from object.

◆ print()

std::ostream & JAANET::JHead::print ( std::ostream & out) const

Print header to output.

Parameters
outoutput stream
Returns
output stream

Definition at line 123 of file JHead.cc.

124 {
125 using namespace std;
126 using namespace JPP;
127
128 JRootWriter writer(out, JHead::getEquationParameters(), JAAnetDictionary::getInstance());
129
130 JRootWritableClass cls(*this);
131
132 unique_ptr<TIterator> i(cls.getClass()->GetListOfDataMembers()->MakeIterator());
133
135
136 for (const TDataMember* p; (p = (const TDataMember*) i->Next()) != NULL; ) {
137 if (!JRoot::is_static(*p)) {
138 if (cls.get(*p) != JRootClass(&JHead::end_event))
139 writer.put(p->GetName(), cls.get(*p), true);
140 else
141 end_event = make_pair(p->GetName(), cls.get(*p));
142 }
143 }
144
145 for (JHead::const_iterator i = this->begin(); i != this->end(); ++i) {
146 if (!cls.find(i->first.c_str()).is_valid()) {
147 writer.put(i->first, i->second);
148 }
149 }
150
151 writer.put(end_event.first, end_event.second, true);
152
153 return out << flush;
154 }
End of event record.
Definition JHead.hh:1213

◆ ClassDef() [1/2]

JAANET::JHead::ClassDef ( JHead ,
5  )

◆ less() [2/3]

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 1699 of file JHead.hh.

1701 {
1702 return first.less(second);
1703 }

◆ match() [2/4]

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 1714 of file JHead.hh.

1716 {
1717 return first.match(second);
1718 }

◆ less() [3/3]

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 1730 of file JHead.hh.

1732 {
1733 if (first.size() == second.size()) {
1734
1735 for (size_t i = 0; i != first.size(); ++i) {
1736 if (less(first[i], second[i])) {
1737 return true;
1738 }
1739 }
1740
1741 return false;
1742
1743 } else {
1744
1745 return first.size() < second.size();
1746 }
1747 }

◆ match() [3/4]

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 1759 of file JHead.hh.

1761 {
1762 for (size_t i = 0; i != first.size() && i != second.size(); ++i) {
1763 if (!match(first[i], second[i])) {
1764 return false;
1765 }
1766 }
1767
1768 return first.size() == second.size();
1769 }

◆ match() [4/4]

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 1781 of file JHead.hh.

1784 {
1785 return (first .is_valid(pd) &&
1786 second.is_valid(pd) &&
1787 match(first.*pd, second.*pd));
1788 }

◆ have_line()

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

78 {
79 return count( key ) != 0;
80 }

◆ get_line() [1/2]

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

90 {
91 return this->at(key);
92 }

◆ get_line() [2/2]

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

102 {
103 return this->at(key);
104 }

◆ matching_keys()

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

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

◆ get_lines()

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

155 {
157
158 for ( auto& key : matching_keys( tag ) ) {
159 r.push_back( get_line( key ) );
160 }
161
162 return r;
163 }
const std::string & get_line(std::string key) const
Get data with the given key.
Definition Head.hh:89
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".
Definition Head.hh:115

◆ set_line()

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

177 {
178 std::string k = tag;
179
180 if (ensure_unique)
181 for (int i = 1; find(k) != end() ; i++)
182 {
183 k = tag + "_" + std::to_string(i);
184 }
185
187 return k;
188 }

◆ get_field() [1/2]

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

199 {
200 using namespace std;
201
203
204 if ( idx < 0 || idx >= int ( v.size() ) )
205 {
206 THROW(Exception, "Cannot find word number " << idx << " in line " << get_line(key) << " for key: " << key);
207 }
208 return v[idx];
209 }
std::vector< std::string > splitstring(const std::string &str, char delim=' ')
Split string at delimiter.
Definition Head.hh:43
General exception.
Definition Exception.hh:13

◆ get_field() [2/2]

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

241 {
242 int idx = get_index_of_field(key, field);
243
244 if ( idx == -1 )
245 {
246 THROW(Exception, "Failed to find" << key << " " << field);
247 }
248
249 return get_field( key, idx );
250 }
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:220
std::string get_field(std::string key, int idx) const
Get data with the given key at given index.
Definition Head.hh:198

◆ get_index_of_field()

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

221 {
222 auto& d = _hdr_dict();
223 if ( d.count(key) == 0 ) return -1;
224 auto v = d.at(key);
225 auto i = std::find (v.begin(), v.end(), field );
226 if (i == v.end()) return -1;
227 return i - v.begin();
228 }
static const std::map< std::string, std::vector< std::string > > & _hdr_dict()
Get internal description of the known lines in header.
Definition Head.hh:315

◆ set_field()

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

264 {
265 using namespace std;
266
267 if ( field == "" ) get_line( key ) = value;
268
269 int idx = get_index_of_field( key, field );
270
271 if ( idx < 0 )
272 {
273 THROW(Exception, "GFailed to find field in header line: " << key << " " << field);
274 }
275
276 vector<string> vals = splitstring( get_line( key ) );
277
278 // if the fields before do not exist, add padding
279 while ( int( vals.size() ) <= idx ) vals.push_back("0");
280
281 vals[idx] = value;
282 ostringstream ss;
283
284 for (unsigned i = 0; i < vals.size() ; i++ )
285 {
286 ss << vals[i];
287 if ( i != vals.size() - 1) ss << " ";
288 }
289 set_line( key, ss.str() );
290
291 }
std::string set_line(std::string tag, std::string line, bool ensure_unique=true)
Set data with the given tag.
Definition Head.hh:176

◆ _hdr_dict()

static const 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 315 of file Head.hh.

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

◆ ngen()

double Head::ngen ( ) const
inlineinherited

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

Returns
number of events

Definition at line 366 of file Head.hh.

367 {
368 return stod ( get_field("genvol", "numberOfEvents") );
369 }

◆ daq_livetime()

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

377 {
378 return stod ( get_field("DAQ", "livetime") );
379 }

◆ mc_livetime()

double Head::mc_livetime ( ) const
inlineinherited

Get the Monte Carlo live time.

Returns
live time [s]

Definition at line 387 of file Head.hh.

388 {
389 return stod ( get_field("livetime", "numberOfSeconds") );
390 }

◆ coord_origin()

Vec Head::coord_origin ( ) const
inlineinherited

Get coordinate origin.

Returns
position

Definition at line 397 of file Head.hh.

398 {
399 return Vec( stod( get_field("coord_origin", "x") ),
400 stod( get_field("coord_origin", "y") ),
401 stod( get_field("coord_origin", "z") ));
402 }
The Vec class is a straightforward 3-d vector, which also works in pyroot.
Definition Vec.hh:13

◆ translate()

Vec Head::translate ( ) const
inlineinherited

Get coordinate translation.

Returns
translation

Definition at line 409 of file Head.hh.

410 {
411 return Vec( stod( get_field("translate", "x") ),
412 stod( get_field("translate", "y") ),
413 stod( get_field("translate", "z") ));
414 }

◆ actionAtFileOpen()

static void Head::actionAtFileOpen ( int version)
inlinestaticinherited

Action method at file open.

Parameters
versionversion

Definition at line 423 of file Head.hh.

424 {
425 ROOT_IO_VERSION = version;
426 }
static int ROOT_IO_VERSION
Streamer version as obtained from ROOT file.
Definition Head.hh:428

◆ ClassDef() [2/2]

Head::ClassDef ( Head ,
2  )
inherited

Friends And Related Symbol Documentation

◆ operator==

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 1563 of file JHead.hh.

1565 {
1566 return first.match(second);
1567 }

◆ operator<

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 1577 of file JHead.hh.

1579 {
1580 return first.less(second);
1581 }

Member Data Documentation

◆ start_run

JAANET::start_run JAANET::JHead::start_run

Definition at line 1583 of file JHead.hh.

◆ UUID

JUUID JAANET::JHead::UUID

Definition at line 1584 of file JHead.hh.

◆ XSecFile

JAANET::XSecFile JAANET::JHead::XSecFile

Definition at line 1585 of file JHead.hh.

◆ drawing

JAANET::drawing JAANET::JHead::drawing

Definition at line 1586 of file JHead.hh.

◆ detector

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

Definition at line 1587 of file JHead.hh.

◆ muon_desc_file

JAANET::muon_desc_file JAANET::JHead::muon_desc_file

Definition at line 1588 of file JHead.hh.

◆ target

JAANET::target JAANET::JHead::target

Definition at line 1589 of file JHead.hh.

◆ physics

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

Definition at line 1590 of file JHead.hh.

◆ simul

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

Definition at line 1591 of file JHead.hh.

◆ calibration

JAANET::calibration JAANET::JHead::calibration

Definition at line 1592 of file JHead.hh.

◆ cut_primary

JAANET::cut_primary JAANET::JHead::cut_primary

Definition at line 1593 of file JHead.hh.

◆ cut_seamuon

JAANET::cut_seamuon JAANET::JHead::cut_seamuon

Definition at line 1594 of file JHead.hh.

◆ cut_in

JAANET::cut_in JAANET::JHead::cut_in

Definition at line 1595 of file JHead.hh.

◆ cut_nu

JAANET::cut_nu JAANET::JHead::cut_nu

Definition at line 1596 of file JHead.hh.

◆ spectrum

JAANET::spectrum JAANET::JHead::spectrum

Definition at line 1597 of file JHead.hh.

◆ can

JAANET::can JAANET::JHead::can

Definition at line 1598 of file JHead.hh.

◆ fixedcan

JAANET::fixedcan JAANET::JHead::fixedcan

Definition at line 1599 of file JHead.hh.

◆ genvol

JAANET::genvol JAANET::JHead::genvol

Definition at line 1600 of file JHead.hh.

◆ coord_origin

JAANET::coord_origin JAANET::JHead::coord_origin

Definition at line 1601 of file JHead.hh.

◆ genhencut

JAANET::genhencut JAANET::JHead::genhencut

Definition at line 1602 of file JHead.hh.

◆ norma

JAANET::norma JAANET::JHead::norma

Definition at line 1603 of file JHead.hh.

◆ livetime

JAANET::livetime JAANET::JHead::livetime

Definition at line 1604 of file JHead.hh.

◆ seabottom

JAANET::seabottom JAANET::JHead::seabottom

Definition at line 1605 of file JHead.hh.

◆ depth

JAANET::depth JAANET::JHead::depth

Definition at line 1606 of file JHead.hh.

◆ DAQ

JAANET::DAQ JAANET::JHead::DAQ

Definition at line 1607 of file JHead.hh.

◆ K40

JAANET::K40 JAANET::JHead::K40

Definition at line 1608 of file JHead.hh.

◆ tgen

JAANET::tgen JAANET::JHead::tgen

Definition at line 1609 of file JHead.hh.

◆ time_interval

JAANET::time_interval JAANET::JHead::time_interval

Definition at line 1610 of file JHead.hh.

◆ primary

JAANET::primary JAANET::JHead::primary

Definition at line 1611 of file JHead.hh.

◆ flux

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

Definition at line 1612 of file JHead.hh.

◆ end_event

JAANET::end_event JAANET::JHead::end_event

Definition at line 1613 of file JHead.hh.

◆ ROOT_IO_VERSION

int Head::ROOT_IO_VERSION = -1
staticinherited

Streamer version as obtained from ROOT file.

Definition at line 428 of file Head.hh.


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