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

Helper class for event weighing. More...

#include <JEvtWeightHelper.hh>

Inheritance diagram for JAANET::JEvtWeightHelper:
JLANG::JSharedPointer< JClass_t, JMemory_t > JAANET::JHead JLANG::JSharedCounter JLANG::JStorage< JClass_t, JMemory_t > Head JLANG::JPointer< JClass_t > TObject std::map< std::string, std::string > JLANG::JAbstractPointer< JClass_t > JLANG::JEquals< JAbstractPointer< JClass_t > > JSUPPORT::JEvtWeightFileScanner< JFileScanner_t >

Public Types

typedef JPointer< JClass_t > pointer_type
 
typedef JStorage< JClass_t,
JMemory_t > 
storage_type
 
typedef JMemory_t< JClass_t > memory_type
 

Public Member Functions

 JEvtWeightHelper ()
 Default constructor. More...
 
 JEvtWeightHelper (const JEvtWeight &weighter)
 Constructor. More...
 
void configure (const JEvtWeight &weighter)
 Configuration. More...
 
bool check (const JHead &header) const
 Check if a given header is consistent with this event weighter. More...
 
void add (const JHead &header)
 Add header. More...
 
double getWeight (const Evt &evt) const
 Get weight of given event. More...
 
double getNormalisation () const
 Get event-weight normalisation. More...
 
double getNormalisation (const Evt &evt) const
 Get event-weight normalisation. More...
 
const JSharedPointergetSharedPointer () const
 Get shared pointer. More...
 
JSharedPointergetSharedPointer ()
 Get shared pointer. More...
 
void setSharedPointer (const JSharedPointer &object)
 Set shared pointer. More...
 
virtual void reset () override
 Reset pointer. More...
 
template<class T >
void reset (const JPointer< T > &pointer)
 Reset pointer. More...
 
void reset (JClass_t *p)
 Reset pointer. More...
 
template<class T >
void set (const JPointer< T > &pointer)
 Set pointer. More...
 
void initialise ()
 Initialise counter. More...
 
void attach (const JSharedCounter &object)
 Attach this counter to given shared counter object. More...
 
bool detach ()
 Detach. More...
 
const int getCount ()
 Get count. More...
 
void recreate ()
 Recreate object in memory. More...
 
void create ()
 Create object in memory. More...
 
void create (const unsigned int size)
 Create array of objects in memory. More...
 
virtual JClass_t * get () const override
 Get pointer. More...
 
JClass_t *const & getReference () const
 Get rereference to internal pointer. More...
 
JClass_t *& getReference ()
 Get rereference to internal pointer. More...
 
virtual bool equals (const JAbstractPointer &object) const
 Equals. More...
 
bool is_valid () const
 Check validity of pointer. More...
 
JClass_t * operator-> () const
 Smart pointer operator. More...
 
 operator JClass_t * () const
 Type conversion operator. More...
 
Vec coord_origin () const
 Get coordinate origin. 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...
 
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)
 
 ClassDef (Head, 2)
 
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 translate () const
 Get coordinate translation. More...
 

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 const 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::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. More...
 

Protected Member Functions

void set (const JSharedPointer &object)
 Set pointer. More...
 
virtual void set (JClass_t *p) override
 Set pointer. More...
 
void release ()
 Release memory. More...
 

Protected Attributes

JClass_t * __p
 pointer to object More...
 

Private Attributes

int counter
 

Detailed Description

Helper class for event weighing.

Definition at line 28 of file JEvtWeightHelper.hh.

Member Typedef Documentation

template<class JClass_t, template< class > class JMemory_t = JNew>
typedef JPointer<JClass_t> JLANG::JSharedPointer< JClass_t, JMemory_t >::pointer_type
inherited

Definition at line 34 of file JSharedPointer.hh.

template<class JClass_t, template< class > class JMemory_t = JNew>
typedef JStorage<JClass_t, JMemory_t> JLANG::JSharedPointer< JClass_t, JMemory_t >::storage_type
inherited

Definition at line 35 of file JSharedPointer.hh.

template<class JClass_t, template< class > class JMemory_t = JNew>
typedef JMemory_t<JClass_t> JLANG::JStorage< JClass_t, JMemory_t >::memory_type
inherited

Definition at line 33 of file JStorage.hh.

Constructor & Destructor Documentation

JAANET::JEvtWeightHelper::JEvtWeightHelper ( )
inline

Default constructor.

Definition at line 37 of file JEvtWeightHelper.hh.

37  :
38  counter(0)
39  {}
JAANET::JEvtWeightHelper::JEvtWeightHelper ( const JEvtWeight weighter)
inline

Constructor.

Parameters
weighterevent weighter

Definition at line 47 of file JEvtWeightHelper.hh.

47  :
48  counter(0)
49  {
50  this->configure(weighter);
51  }
void configure(const JEvtWeight &weighter)
Configuration.

Member Function Documentation

void JAANET::JEvtWeightHelper::configure ( const JEvtWeight weighter)
inline

Configuration.

Parameters
weighterevent weighter

Definition at line 59 of file JEvtWeightHelper.hh.

60  {
61  counter = 0;
62 
63  reset(weighter.clone());
64  }
virtual clone_type clone() const override
Get clone of this object.
Definition: JClonable.hh:69
virtual void reset() override
Reset pointer.
bool JAANET::JEvtWeightHelper::check ( const JHead header) const
inline

Check if a given header is consistent with this event weighter.

Parameters
headerheader
Returns
true if header is consistent with this event weighter; else false.

Definition at line 73 of file JEvtWeightHelper.hh.

74  {
75  return (is_valid() ? get()->check(header) : false);
76  }
bool check(const JHead &header) const
Check if a given header is consistent with this event weighter.
bool is_valid() const
Check validity of pointer.
void JAANET::JEvtWeightHelper::add ( const JHead header)
inline

Add header.

Parameters
headerheader

Definition at line 84 of file JEvtWeightHelper.hh.

85  {
86  using namespace JPP;
87 
88  if (check(header)) {
89 
90  if (counter == 0) {
91  JHead::setHeader(header);
92  } else {
93  JHead::add(header);
94  }
95 
96  ++counter;
97 
98  get()->configure(getHeader());
99 
100  } else {
101 
102  THROW(JNullPointerException, "JEvtWeightHelper::add(): headers do not match.");
103  }
104  }
void configure(const JEvtWeight &weighter)
Configuration.
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:712
bool check(const JHead &header) const
Check if a given header is consistent with this event weighter.
JHead & add(const JHead &header)
Addition of headers.
Definition: JHead.hh:1529
void setHeader(const JHead &header)
Set header.
Definition: JHead.hh:1292
const JHead & getHeader() const
Get header.
Definition: JHead.hh:1270
double JAANET::JEvtWeightHelper::getWeight ( const Evt evt) const
inline

Get weight of given event.

Parameters
evtevent
Returns
weight [Hz]

Definition at line 113 of file JEvtWeightHelper.hh.

114  {
115  using namespace JPP;
116 
117  if (is_valid()) {
118  return get()->getWeight(evt);
119  } else {
120  THROW(JNullPointerException, "JEvtWeightHelper::getWeight(): Event weighter is null.");
121  }
122  }
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:712
bool is_valid() const
Check validity of pointer.
double getWeight(const Evt &evt) const
Get weight of given event.
double JAANET::JEvtWeightHelper::getNormalisation ( ) const
inline

Get event-weight normalisation.

Returns
event-weight normalisation

Definition at line 130 of file JEvtWeightHelper.hh.

131  {
132  using namespace JPP;
133 
134  if (is_valid()) {
135  return get()->getNormalisation();
136  } else {
137  THROW(JNullPointerException, "JEvtWeightHelper::getWeightNormalisation(): Event weighter is null.");
138  }
139  }
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:712
bool is_valid() const
Check validity of pointer.
double getNormalisation() const
Get event-weight normalisation.
double JAANET::JEvtWeightHelper::getNormalisation ( const Evt evt) const
inline

Get event-weight normalisation.

Parameters
evtevent
Returns
event-weight normalisation

Definition at line 148 of file JEvtWeightHelper.hh.

149  {
150  using namespace JPP;
151 
152  if (is_valid()) {
153  return get()->getNormalisation(evt);
154  } else {
155  THROW(JNullPointerException, "JEvtWeightHelper::getWeightNormalisation(): Event weighter is null.");
156  }
157  }
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:712
bool is_valid() const
Check validity of pointer.
double getNormalisation() const
Get event-weight normalisation.
template<class JClass_t, template< class > class JMemory_t = JNew>
const JSharedPointer& JLANG::JSharedPointer< JClass_t, JMemory_t >::getSharedPointer ( ) const
inlineinherited

Get shared pointer.

Returns
this shared pointer

Definition at line 95 of file JSharedPointer.hh.

96  {
97  return static_cast<const JSharedPointer&>(*this);
98  }
The template JSharedPointer class can be used to share a pointer to an object.
template<class JClass_t, template< class > class JMemory_t = JNew>
JSharedPointer& JLANG::JSharedPointer< JClass_t, JMemory_t >::getSharedPointer ( )
inlineinherited

Get shared pointer.

Returns
this shared pointer

Definition at line 106 of file JSharedPointer.hh.

107  {
108  return static_cast<JSharedPointer&>(*this);
109  }
The template JSharedPointer class can be used to share a pointer to an object.
template<class JClass_t, template< class > class JMemory_t = JNew>
void JLANG::JSharedPointer< JClass_t, JMemory_t >::setSharedPointer ( const JSharedPointer< JClass_t, JMemory_t > &  object)
inlineinherited

Set shared pointer.

Parameters
objectshared pointer

Definition at line 117 of file JSharedPointer.hh.

118  {
119  if (this->get() != object.get()) {
120 
121  this->reset();
122 
123  if (object.is_valid()) {
124  this->set(object);
125  }
126  }
127  }
void set(const JSharedPointer &object)
Set pointer.
bool is_valid() const
Check validity of pointer.
virtual void reset() override
Reset pointer.
template<class JClass_t, template< class > class JMemory_t = JNew>
virtual void JLANG::JSharedPointer< JClass_t, JMemory_t >::reset ( )
inlineoverridevirtualinherited

Reset pointer.

The reference counter is decremented by one and the object pointed to previously is deleted when its reference counter is zero.

Reimplemented from JLANG::JStorage< JClass_t, JMemory_t >.

Definition at line 171 of file JSharedPointer.hh.

172  {
173  if (this->detach()) {
175  }
176 
178  }
virtual void reset() override
Reset pointer.
Definition: JStorage.hh:42
bool detach()
Detach.
virtual void reset() override
Reset pointer.
Definition: JPointer.hh:84
template<class JClass_t>
template<class T >
void JLANG::JPointer< JClass_t >::reset ( const JPointer< T > &  pointer)
inlineinherited

Reset pointer.

Parameters
pointerpointer to object

Definition at line 108 of file JPointer.hh.

109  {
110  this->reset(pointer.get());
111  }
virtual JClass_t * get() const override
Get pointer.
Definition: JPointer.hh:64
virtual void reset() override
Reset pointer.
Definition: JPointer.hh:84
template<class JClass_t>
void JLANG::JAbstractPointer< JClass_t >::reset ( JClass_t *  p)
inlineinherited

Reset pointer.

Parameters
ppointer to object

Definition at line 94 of file JAbstractPointer.hh.

95  {
96  if (this->get() != p) {
97 
98  this->reset();
99 
100  if (p != NULL) {
101  this->set(p);
102  }
103  }
104  }
virtual void reset()=0
Reset pointer.
virtual void set(JClass_t *p)=0
Set pointer.
template<class JClass_t, template< class > class JMemory_t = JNew>
void JLANG::JSharedPointer< JClass_t, JMemory_t >::set ( const JSharedPointer< JClass_t, JMemory_t > &  object)
inlineprotectedinherited

Set pointer.

The reference counter of the shared object pointed to is incremented by one.

Parameters
objectshared pointer

Definition at line 188 of file JSharedPointer.hh.

189  {
190  pointer_type::set(object.get());
191 
192  this->attach(object);
193  }
void attach(const JSharedCounter &object)
Attach this counter to given shared counter object.
virtual void set(JClass_t *p) override
Set pointer.
Definition: JPointer.hh:75
template<class JClass_t, template< class > class JMemory_t = JNew>
virtual void JLANG::JSharedPointer< JClass_t, JMemory_t >::set ( JClass_t *  p)
inlineoverrideprotectedvirtualinherited

Set pointer.

The reference counter of the shared object pointed to is initialised to one.

Parameters
ppointer to derived class object

Reimplemented from JLANG::JPointer< JClass_t >.

Definition at line 202 of file JSharedPointer.hh.

203  {
205 
206  this->initialise();
207  }
void initialise()
Initialise counter.
virtual void set(JClass_t *p) override
Set pointer.
Definition: JPointer.hh:75
template<class JClass_t>
template<class T >
void JLANG::JPointer< JClass_t >::set ( const JPointer< T > &  pointer)
inlineinherited

Set pointer.

Parameters
pointerpointer to object

Definition at line 96 of file JPointer.hh.

97  {
98  this->set(pointer.get());
99  }
virtual void set(JClass_t *p) override
Set pointer.
Definition: JPointer.hh:75
virtual JClass_t * get() const override
Get pointer.
Definition: JPointer.hh:64
void JLANG::JSharedCounter::initialise ( )
inlineinherited

Initialise counter.

Definition at line 33 of file JSharedCounter.hh.

34  {
35  detach();
36 
37  counter = new int(1);
38  }
bool detach()
Detach.
void JLANG::JSharedCounter::attach ( const JSharedCounter object)
inlineinherited

Attach this counter to given shared counter object.

Parameters
objectshared counter

Definition at line 46 of file JSharedCounter.hh.

47  {
48  detach();
49 
50  counter = object.counter;
51 
52  if (counter != NULL) {
53  ++(*counter);
54  }
55  }
bool detach()
Detach.
bool JLANG::JSharedCounter::detach ( )
inlineinherited

Detach.

Returns
true if counter at zero; else false

Definition at line 63 of file JSharedCounter.hh.

64  {
65  if (counter != NULL) {
66 
67  if (--(*counter) == 0) {
68 
69  delete counter;
70 
71  counter = NULL;
72 
73  return true;
74  }
75 
76  counter = NULL;
77  }
78 
79  return false;
80  }
const int JLANG::JSharedCounter::getCount ( )
inlineinherited

Get count.

Returns
count

Definition at line 88 of file JSharedCounter.hh.

89  {
90  return (counter != NULL ? *counter : 0);
91  }
template<class JClass_t, template< class > class JMemory_t = JNew>
void JLANG::JStorage< JClass_t, JMemory_t >::recreate ( )
inlineinherited

Recreate object in memory.

A new object is created if no memory is allocated yet, else the previously created object is maintained.

Definition at line 57 of file JStorage.hh.

58  {
59  if (!this->is_valid()) {
60  this->set(memory_type::create());
61  }
62  }
bool is_valid() const
Check validity of pointer.
virtual void set(JClass_t *p) override
Set pointer.
Definition: JPointer.hh:75
template<class JClass_t, template< class > class JMemory_t = JNew>
void JLANG::JStorage< JClass_t, JMemory_t >::create ( )
inlineinherited

Create object in memory.

The memory allocated by a previously created object will be released.

Definition at line 69 of file JStorage.hh.

70  {
71  this->reset(memory_type::create());
72  }
virtual void reset() override
Reset pointer.
Definition: JStorage.hh:42
template<class JClass_t, template< class > class JMemory_t = JNew>
void JLANG::JStorage< JClass_t, JMemory_t >::create ( const unsigned int  size)
inlineinherited

Create array of objects in memory.

The memory allocated by previously created objects will be released.

Parameters
sizenumber of elements

Definition at line 81 of file JStorage.hh.

82  {
83  this->reset(memory_type::create(size));
84  }
virtual void reset() override
Reset pointer.
Definition: JStorage.hh:42
template<class JClass_t, template< class > class JMemory_t = JNew>
void JLANG::JStorage< JClass_t, JMemory_t >::release ( )
inlineprotectedinherited

Release memory.

Definition at line 91 of file JStorage.hh.

92  {
93  memory_type::release(this->get());
94  }
template<class JClass_t>
virtual JClass_t* JLANG::JPointer< JClass_t >::get ( ) const
inlineoverridevirtualinherited
template<class JClass_t>
JClass_t* const& JLANG::JPointer< JClass_t >::getReference ( ) const
inlineinherited

Get rereference to internal pointer.

Returns
reference to internal pointer

Definition at line 119 of file JPointer.hh.

120  {
121  return __p;
122  }
JClass_t * __p
pointer to object
Definition: JPointer.hh:136
template<class JClass_t>
JClass_t* & JLANG::JPointer< JClass_t >::getReference ( )
inlineinherited

Get rereference to internal pointer.

Returns
reference to internal pointer

Definition at line 130 of file JPointer.hh.

131  {
132  return __p;
133  }
JClass_t * __p
pointer to object
Definition: JPointer.hh:136
template<class JClass_t>
virtual bool JLANG::JAbstractPointer< JClass_t >::equals ( const JAbstractPointer< JClass_t > &  object) const
inlinevirtualinherited

Equals.

The equality is evaluated by comparison of the internal pointers.

Parameters
objectabstract pointer
Returns
true if equals; else false

Definition at line 50 of file JAbstractPointer.hh.

51  {
52  return this->get() == object.get();
53  }
template<class JClass_t>
bool JLANG::JAbstractPointer< JClass_t >::is_valid ( ) const
inlineinherited

Check validity of pointer.

Returns
true if pointer not null; else false

Definition at line 83 of file JAbstractPointer.hh.

84  {
85  return this->get() != NULL;
86  }
template<class JClass_t>
JClass_t* JLANG::JAbstractPointer< JClass_t >::operator-> ( ) const
inlineinherited

Smart pointer operator.

Returns
pointer to object

Definition at line 112 of file JAbstractPointer.hh.

113  {
114  if (!is_valid())
115  THROW(JNullPointerException, "JAbstractPointer::operator->()");
116  else
117  return this->get();
118  }
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:712
bool is_valid() const
Check validity of pointer.
Exception for null pointer operation.
Definition: JException.hh:232
template<class JClass_t>
JLANG::JAbstractPointer< JClass_t >::operator JClass_t * ( ) const
inlineinherited

Type conversion operator.

Returns
pointer to object

Definition at line 126 of file JAbstractPointer.hh.

127  {
128  return this->get();
129  }
Vec Head::coord_origin ( ) const
inlineinherited

Get coordinate origin.

Returns
position

Definition at line 398 of file Head.hh.

399  {
400  return Vec( stod( get_field("coord_origin", "x") ),
401  stod( get_field("coord_origin", "y") ),
402  stod( get_field("coord_origin", "z") ));
403  }
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
const JHead& JAANET::JHead::getHeader ( ) const
inlineinherited

Get header.

Returns
header

Definition at line 1270 of file JHead.hh.

1271  {
1272  return static_cast<const JHead&>(*this);
1273  }
Monte Carlo run header.
Definition: JHead.hh:1234
JHead& JAANET::JHead::getHeader ( )
inlineinherited

Get header.

Returns
header

Definition at line 1281 of file JHead.hh.

1282  {
1283  return static_cast<JHead&>(*this);
1284  }
Monte Carlo run header.
Definition: JHead.hh:1234
void JAANET::JHead::setHeader ( const JHead header)
inlineinherited

Set header.

Parameters
headerheader

Definition at line 1292 of file JHead.hh.

1293  {
1294  static_cast<JHead&>(*this) = header;
1295  }
Monte Carlo run header.
Definition: JHead.hh:1234
void JAANET::JHead::createUUID ( )
inlineinherited

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  }
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
JUUID UUID
Definition: JHead.hh:1581
void push()
Push all data members to Head.
Definition: JHead.cc:28
template<class T >
bool JAANET::JHead::is_valid ( T JHead::*  pd) const
inlineinherited

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
template<class T >
static bool JAANET::JHead::is_valid ( const T object)
inlinestaticinherited

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:1484
do set_variable OUTPUT_DIRECTORY $WORKDIR T
template<class T >
const_iterator JAANET::JHead::pull ( T JHead::*  pd) const
inlineinherited

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.
Definition: JRootClass.hh:641
template<class T >
iterator JAANET::JHead::pull ( T JHead::*  pd)
inlineinherited

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  }
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)
inlineinherited

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  }
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 ( )
inherited

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)
inlineinherited

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  }
const_iterator pull(T JHead::*pd) const
Pull given data member from Head.
Definition: JHead.hh:1349
void erase(T JHead::*pd)
Reset and remove given data member from Head.
Definition: JHead.hh:1392
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
JHead JAANET::JHead::getMatch ( const JHead header) const
inlineinherited

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::spectrum);
1428  IF_MATCH(buffer, *this, header, &JHead::can);
1429  IF_MATCH(buffer, *this, header, &JHead::fixedcan);
1430  IF_MATCH(buffer, *this, header, &JHead::genvol);
1431  IF_MATCH(buffer, *this, header, &JHead::coord_origin);
1432 
1433  IF_MATCH(buffer, *this, header, &JHead::norma);
1434  IF_MATCH(buffer, *this, header, &JHead::livetime);
1435 
1436  IF_MATCH(buffer, *this, header, &JHead::seabottom);
1437  IF_MATCH(buffer, *this, header, &JHead::depth);
1438  IF_MATCH(buffer, *this, header, &JHead::tgen);
1439  IF_MATCH(buffer, *this, header, &JHead::time_interval);
1440 
1441  IF_MATCH(buffer, *this, header, &JHead::primary);
1442  IF_MATCH(buffer, *this, header, &JHead::flux);
1443  IF_MATCH(buffer, *this, header, &JHead::DAQ);
1444  IF_MATCH(buffer, *this, header, &JHead::K40);
1445 
1446  return buffer;
1447 
1448 #undef IF_MATCH
1449  }
JAANET::primary primary
Definition: JHead.hh:1608
JAANET::cut_in cut_in
Definition: JHead.hh:1592
JAANET::norma norma
Definition: JHead.hh:1600
JAANET::K40 K40
Definition: JHead.hh:1605
JAANET::time_interval time_interval
Definition: JHead.hh:1607
std::vector< JAANET::flux > flux
Definition: JHead.hh:1609
JAANET::tgen tgen
Definition: JHead.hh:1606
Monte Carlo run header.
Definition: JHead.hh:1234
JAANET::cut_nu cut_nu
Definition: JHead.hh:1593
JAANET::seabottom seabottom
Definition: JHead.hh:1602
JAANET::genvol genvol
Definition: JHead.hh:1597
JAANET::depth depth
Definition: JHead.hh:1603
std::vector< JAANET::simul > simul
Definition: JHead.hh:1588
JAANET::spectrum spectrum
Definition: JHead.hh:1594
#define IF_MATCH(A, B, C, D)
JAANET::can can
Definition: JHead.hh:1595
JAANET::cut_primary cut_primary
Definition: JHead.hh:1590
JAANET::DAQ DAQ
Definition: JHead.hh:1604
JAANET::cut_seamuon cut_seamuon
Definition: JHead.hh:1591
Vec coord_origin() const
Get coordinate origin.
Definition: Head.hh:398
JAANET::fixedcan fixedcan
Definition: JHead.hh:1596
JAANET::livetime livetime
Definition: JHead.hh:1601
size_t JAANET::JHead::getNumberOfMatches ( const JHead header) const
inlineinherited

Get number of matching fields.

Parameters
headerheader
Returns
number of matching header fields

Definition at line 1458 of file JHead.hh.

1459  {
1460  const JHead head = getMatch(header);
1461 
1462  return head.size();
1463  }
Monte Carlo run header.
Definition: JHead.hh:1234
JHead getMatch(const JHead &header) const
Get matching fields.
Definition: JHead.hh:1410
bool JAANET::JHead::match ( const JHead header) const
inlineinherited

Test match of headers.

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

Definition at line 1472 of file JHead.hh.

1473  {
1474  return getNumberOfMatches(header) == getNumberOfMatches(*this);
1475  }
size_t getNumberOfMatches(const JHead &header) const
Get number of matching fields.
Definition: JHead.hh:1458
bool JAANET::JHead::less ( const JHead header) const
inlineinherited

Comparison of headers.

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

Definition at line 1484 of file JHead.hh.

1485  {
1486 #define RETURN_IF_DIFFERENT(A, B) \
1487  if (less(A,B)) { return true; } \
1488  if (less(B,A)) { return false; }
1489 
1490  // compare physics
1491 
1492  RETURN_IF_DIFFERENT(this->physics, header.physics);
1493 
1494  // compare simulation
1495 
1496  RETURN_IF_DIFFERENT(this->simul, header.simul);
1497 
1498  // compare generation data
1499 
1500  RETURN_IF_DIFFERENT(this->primary, header.primary);
1501  RETURN_IF_DIFFERENT(this->flux, header.flux);
1502  RETURN_IF_DIFFERENT(this->spectrum, header.spectrum);
1505  RETURN_IF_DIFFERENT(this->cut_in, header.cut_in);
1506  RETURN_IF_DIFFERENT(this->cut_nu, header.cut_nu);
1507  RETURN_IF_DIFFERENT(this->genvol, header.genvol);
1508 
1509  // compare compatibility
1510 
1511  if (is_valid(this->livetime) == is_valid(header.livetime) &&
1512  is_valid(this->DAQ) == is_valid(header.DAQ) &&
1513  is_valid(this->K40) == is_valid(header.K40)) {
1514  return false;
1515  }
1516 
1517  THROW(JException, "JHead::less() headers do not compare.");
1518 
1519 #undef RETURN_IF_DIFFERENT
1520  }
Phase space of incident neutrino.
Definition: JHead.hh:459
bool is_valid(T JHead::*pd) const
Check validity of given data member in JHead.
Definition: JHead.hh:1319
Neutrino vertex volume.
Definition: JHead.hh:649
JAANET::primary primary
Definition: JHead.hh:1608
Livetime of DAQ data.
Definition: JHead.hh:1008
#define RETURN_IF_DIFFERENT(A, B)
Phase space of incoming particle.
Definition: JHead.hh:449
Generator for simulation.
Definition: JHead.hh:526
JAANET::cut_in cut_in
Definition: JHead.hh:1592
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:712
JAANET::K40 K40
Definition: JHead.hh:1605
Physics information.
Definition: JHead.hh:516
std::vector< JAANET::flux > flux
Definition: JHead.hh:1609
Neutrino flux.
Definition: JHead.hh:906
JAANET::cut_nu cut_nu
Definition: JHead.hh:1593
JAANET::genvol genvol
Definition: JHead.hh:1597
Normalisation of MUPAGE events.
Definition: JHead.hh:835
std::vector< JAANET::simul > simul
Definition: JHead.hh:1588
JAANET::spectrum spectrum
Definition: JHead.hh:1594
Primary particle.
Definition: JHead.hh:1174
JAANET::cut_primary cut_primary
Definition: JHead.hh:1590
Phase space of atmospheric muon generation.
Definition: JHead.hh:439
Phase space of primary particle.
Definition: JHead.hh:429
JAANET::DAQ DAQ
Definition: JHead.hh:1604
std::vector< JAANET::physics > physics
Definition: JHead.hh:1587
JAANET::cut_seamuon cut_seamuon
Definition: JHead.hh:1591
Livetime of noise data.
Definition: JHead.hh:1062
Neutrino energy spectrum.
Definition: JHead.hh:536
JAANET::livetime livetime
Definition: JHead.hh:1601
static const size_t JAANET::JHead::getMaximumNumberOfMatches ( )
inlinestaticinherited

Get maximum number of matching header fields.

Returns
maximum number of matching header fields

Definition at line 1618 of file JHead.hh.

1619  {
1620  static JHead header;
1621 
1622  header.push();
1623 
1624  static const size_t value = header.getNumberOfMatches(header);
1625 
1626  return value;
1627  }
size_t getNumberOfMatches(const JHead &header) const
Get number of matching fields.
Definition: JHead.hh:1458
Monte Carlo run header.
Definition: JHead.hh:1234
void push(T JHead::*pd)
Push given data member to Head.
Definition: JHead.hh:1374
static JLANG::JEquationParameters& JAANET::JHead::getEquationParameters ( )
inlinestaticinherited

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

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

Definition at line 1639 of file JHead.hh.

1640  {
1641  static JLANG::JEquationParameters parameters(":", "\n", "", "");
1642 
1643  return parameters;
1644  }
*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)
inlinestaticinherited

Set equation parameters.

Parameters
equationequation parameters

Definition at line 1652 of file JHead.hh.

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

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 JStat getFileStatus
Function object for file status.
Definition: JStat.hh:173
static JLANG::JEquationParameters & getEquationParameters()
Get equation parameters corresponding to Monte Carlo ASCII format, i.e:
Definition: JHead.hh:1639
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
inherited

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::start_run start_run
Definition: JHead.hh:1580
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:1639
JAANET::end_event end_event
Definition: JHead.hh:1610
std::ostream & JAANET::JHead::print ( std::ostream &  out) const
inherited

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  }
bool is_valid(T JHead::*pd) const
Check validity of given data member in JHead.
Definition: JHead.hh:1319
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:1639
JAANET::end_event end_event
Definition: JHead.hh:1610
JAANET::JHead::ClassDef ( JHead  ,
 
)
inherited
Head::ClassDef ( Head  ,
 
)
inherited
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:712
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 241 of file Head.hh.

242  {
243  int idx = get_index_of_field(key, field);
244 
245  if ( idx == -1 )
246  {
247  THROW(Exception, "Failed to find" << key << " " << field);
248  }
249 
250  return get_field( key, idx );
251  }
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:712
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& d = _hdr_dict();
224  if ( d.count(key) == 0 ) return -1;
225  auto v = d.at(key);
226  auto i = std::find (v.begin(), v.end(), field );
227  if (i == v.end()) return -1;
228  return i - v.begin();
229  }
then JMuonMCEvt f $INPUT_FILE o $INTERMEDIATE_FILE d
Definition: JMuonPath.sh:47
static const std::map< std::string, std::vector< std::string > > & _hdr_dict()
Get internal description of the known lines in header.
Definition: Head.hh:316
data_type v[N+1][M+1]
Definition: JPolint.hh:777
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 264 of file Head.hh.

265  {
266  using namespace std;
267 
268  if ( field == "" ) get_line( key ) = value;
269 
270  int idx = get_index_of_field( key, field );
271 
272  if ( idx < 0 )
273  {
274  THROW(Exception, "GFailed to find field in header line: " << key << " " << field);
275  }
276 
277  vector<string> vals = splitstring( get_line( key ) );
278 
279  // if the fields before do not exist, add padding
280  while ( int( vals.size() ) <= idx ) vals.push_back("0");
281 
282  vals[idx] = value;
283  ostringstream ss;
284 
285  for (unsigned i = 0; i < vals.size() ; i++ )
286  {
287  ss << vals[i];
288  if ( i != vals.size() - 1) ss << " ";
289  }
290  set_line( key, ss.str() );
291 
292  }
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:712
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 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 316 of file Head.hh.

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

368  {
369  return stod ( get_field("genvol", "numberOfEvents") );
370  }
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 377 of file Head.hh.

378  {
379  return stod ( get_field("DAQ", "livetime") );
380  }
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 388 of file Head.hh.

389  {
390  return stod ( get_field("livetime", "numberOfSeconds") );
391  }
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 410 of file Head.hh.

411  {
412  return Vec( stod( get_field("translate", "x") ),
413  stod( get_field("translate", "y") ),
414  stod( get_field("translate", "z") ));
415  }
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 424 of file Head.hh.

425  {
427  }
version
Definition: JEditTuneHV.sh:5
static int ROOT_IO_VERSION
Streamer version as obtained from ROOT file.
Definition: Head.hh:429

Member Data Documentation

int JAANET::JEvtWeightHelper::counter
private

Definition at line 161 of file JEvtWeightHelper.hh.

template<class JClass_t>
JClass_t* JLANG::JPointer< JClass_t >::__p
protectedinherited

pointer to object

Definition at line 136 of file JPointer.hh.

JAANET::start_run JAANET::JHead::start_run
inherited

Definition at line 1580 of file JHead.hh.

JUUID JAANET::JHead::UUID
inherited

Definition at line 1581 of file JHead.hh.

JAANET::XSecFile JAANET::JHead::XSecFile
inherited

Definition at line 1582 of file JHead.hh.

JAANET::drawing JAANET::JHead::drawing
inherited

Definition at line 1583 of file JHead.hh.

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

Definition at line 1584 of file JHead.hh.

JAANET::muon_desc_file JAANET::JHead::muon_desc_file
inherited

Definition at line 1585 of file JHead.hh.

JAANET::target JAANET::JHead::target
inherited

Definition at line 1586 of file JHead.hh.

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

Definition at line 1587 of file JHead.hh.

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

Definition at line 1588 of file JHead.hh.

JAANET::calibration JAANET::JHead::calibration
inherited

Definition at line 1589 of file JHead.hh.

JAANET::cut_primary JAANET::JHead::cut_primary
inherited

Definition at line 1590 of file JHead.hh.

JAANET::cut_seamuon JAANET::JHead::cut_seamuon
inherited

Definition at line 1591 of file JHead.hh.

JAANET::cut_in JAANET::JHead::cut_in
inherited

Definition at line 1592 of file JHead.hh.

JAANET::cut_nu JAANET::JHead::cut_nu
inherited

Definition at line 1593 of file JHead.hh.

JAANET::spectrum JAANET::JHead::spectrum
inherited

Definition at line 1594 of file JHead.hh.

JAANET::can JAANET::JHead::can
inherited

Definition at line 1595 of file JHead.hh.

JAANET::fixedcan JAANET::JHead::fixedcan
inherited

Definition at line 1596 of file JHead.hh.

JAANET::genvol JAANET::JHead::genvol
inherited

Definition at line 1597 of file JHead.hh.

JAANET::coord_origin JAANET::JHead::coord_origin
inherited

Definition at line 1598 of file JHead.hh.

JAANET::genhencut JAANET::JHead::genhencut
inherited

Definition at line 1599 of file JHead.hh.

JAANET::norma JAANET::JHead::norma
inherited

Definition at line 1600 of file JHead.hh.

JAANET::livetime JAANET::JHead::livetime
inherited

Definition at line 1601 of file JHead.hh.

JAANET::seabottom JAANET::JHead::seabottom
inherited

Definition at line 1602 of file JHead.hh.

JAANET::depth JAANET::JHead::depth
inherited

Definition at line 1603 of file JHead.hh.

JAANET::DAQ JAANET::JHead::DAQ
inherited

Definition at line 1604 of file JHead.hh.

JAANET::K40 JAANET::JHead::K40
inherited

Definition at line 1605 of file JHead.hh.

JAANET::tgen JAANET::JHead::tgen
inherited

Definition at line 1606 of file JHead.hh.

JAANET::time_interval JAANET::JHead::time_interval
inherited

Definition at line 1607 of file JHead.hh.

JAANET::primary JAANET::JHead::primary
inherited

Definition at line 1608 of file JHead.hh.

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

Definition at line 1609 of file JHead.hh.

JAANET::end_event JAANET::JHead::end_event
inherited

Definition at line 1610 of file JHead.hh.

int Head::ROOT_IO_VERSION = -1
staticinherited

Streamer version as obtained from ROOT file.

Definition at line 429 of file Head.hh.


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