Jpp  16.0.0
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 | Protected Member Functions | Protected Attributes | List of all members
JSUPPORT::JEvtWeightFileScanner< JFileScanner_t > Struct Template Reference

Template event-weighter-associated file scanner. More...

#include <JEvtWeightFileScanner.hh>

Inheritance diagram for JSUPPORT::JEvtWeightFileScanner< JFileScanner_t >:
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 > >

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

 JEvtWeightFileScanner ()
 Default constructor. More...
 
 JEvtWeightFileScanner (const JEvtWeight &weighter)
 Constructor. More...
 
 JEvtWeightFileScanner (const JMultipleFileScanner_t &input)
 Constructor. More...
 
std::string getProgramName () const
 Get name of simulation program. More...
 
void reset (const JEvtWeight &weighter)
 Reset file scanner and event weighter. More...
 
size_t put (const JMultipleFileScanner_t &input)
 Put list of files. More...
 
bool put (const std::string &input)
 Put file. More...
 
template<class JEvtWeightFactor_t = JEvtWeightFactor>
bool setEvtWeightFactor (const int type, const JEvtWeightFactor_t &factor)
 Set event-weight factor corresponding to a given PDG code. More...
 
template<class JEvtWeightFactor_t = JEvtWeightFactor>
bool setEvtWeightFactor (const std::set< int > &types, const JEvtWeightFactor_t &factor)
 Set event-weight factor corresponding to a given set of PDG codes. More...
 
template<class JEvtWeightFactor_t = JEvtWeightFactor>
bool setEvtWeightFactor (const JEvtWeightFactorMultiParticle< JEvtWeightFactor_t > &multiParticleFactor)
 Set event-weight factor corresponding to a given multi-particle weighting factor interface. More...
 
bool setFlux (const int type, const JFlux &function)
 Set flux function corresponding to a given PDG code. More...
 
bool setFlux (const std::set< int > &types, const JFlux &function)
 Set flux function corresponding to a given set of PDG codes. More...
 
bool setFlux (const JEvtWeightFactorMultiParticle< JFlux > &multiParticleFlux)
 Set flux function corresponding to a given multi-particle flux interface. 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...
 
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...
 
template<class T >
bool is_valid (T JHead::*pd) const
 Check validity of given data member in JHead. 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...
 
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...
 
template<class T >
void erase (T JHead::*pd)
 Remove given data member from Head. More...
 
int 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, 3)
 
 ClassDef (Head, 2)
 
bool have_line (std::string key) const
 Check availability of data with the given key. More...
 
const std::string & get_line (std::string key) const
 Get data with the given key. More...
 
std::string & get_line (std::string key)
 Get data with the given key. More...
 
std::vector< std::string > matching_keys (const std::string &tag) const
 In case of duplicate keys, they are internally stored in the map with a suffix "_n". More...
 
std::vector< std::string > get_lines (const std::string &tag) const
 Get all data compatible with the given key. More...
 
std::string set_line (std::string tag, std::string line, bool ensure_unique=true)
 Set data with the given tag. More...
 
std::string get_field (std::string key, int idx) const
 Get data with the given key at given index. More...
 
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 int getMaximumNumberOfMatches ()
 Get maximum number of matching header fields. More...
 
static JLANG::JEquationParametersgetEquationParameters ()
 Get equation parameters corresponding to Monte Carlo ASCII format, i.e: More...
 
static void setEquationParameters (const JLANG::JEquationParameters &equation)
 Set equation parameters. More...
 
static std::map< std::string,
std::vector< std::string > > & 
_hdr_dict ()
 Get internal description of the known lines in header. More...
 

Public Attributes

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

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

Detailed Description

template<class JFileScanner_t = JMultipleFileScanner<Evt>>
struct JSUPPORT::JEvtWeightFileScanner< JFileScanner_t >

Template event-weighter-associated file scanner.

Note: The template class must be derived from JMultipleFileScanner<Evt>

Definition at line 53 of file JEvtWeightFileScanner.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

template<class JFileScanner_t = JMultipleFileScanner<Evt>>
JSUPPORT::JEvtWeightFileScanner< JFileScanner_t >::JEvtWeightFileScanner ( )
inline

Default constructor.

Definition at line 60 of file JEvtWeightFileScanner.hh.

61  {}
template<class JFileScanner_t = JMultipleFileScanner<Evt>>
JSUPPORT::JEvtWeightFileScanner< JFileScanner_t >::JEvtWeightFileScanner ( const JEvtWeight weighter)
inline

Constructor.

Parameters
weighterevent weighter

Definition at line 69 of file JEvtWeightFileScanner.hh.

70  {
71  reset(weighter);
72  }
virtual void reset() override
Reset pointer.
template<class JFileScanner_t = JMultipleFileScanner<Evt>>
JSUPPORT::JEvtWeightFileScanner< JFileScanner_t >::JEvtWeightFileScanner ( const JMultipleFileScanner_t input)
inline

Constructor.

Parameters
inputlist of file names

Definition at line 80 of file JEvtWeightFileScanner.hh.

81  {
82  using namespace JPP;
83 
84  const JHead& header = JSUPPORT::getHeader(input);
85  const JEvtWeight& weighter = getEventWeighter(header);
86 
87  reset(weighter);
88  put (input);
89  }
JEvtWeighter getEventWeighter
Function object for mapping header to event weighter.
Head getHeader(const JMultipleFileScanner_t &file_list)
Get Monte Carlo header.
Low-level interface for event weighing.
Definition: JEvtWeight.hh:24
Monte Carlo run header.
Definition: JHead.hh:1164
size_t put(const JMultipleFileScanner_t &input)
Put list of files.
virtual void reset() override
Reset pointer.

Member Function Documentation

template<class JFileScanner_t = JMultipleFileScanner<Evt>>
std::string JSUPPORT::JEvtWeightFileScanner< JFileScanner_t >::getProgramName ( ) const
inline

Get name of simulation program.

Returns
unique identifier

Definition at line 97 of file JEvtWeightFileScanner.hh.

98  {
99  using namespace std;
100  using namespace JPP;
101 
102  static const char SEPARATOR = '.';
103 
104  const JHead& header = this->getHeader();
105 
106  if (header.simul.size() > 0) {
107 
108  string name = header.simul.cbegin()->program;
109 
110  for (vector<JAANET::simul>::const_iterator i = next(header.simul.cbegin()); i != header.simul.cend(); ++i) {
111  name += MAKE_STRING(SEPARATOR << i->program);
112  }
113 
114  return name;
115 
116  } else {
117 
118  THROW(JNoValue, "JEvtWeightFileScanner::getProgramName(): Missing simul header-field!");
119  }
120  }
const JHead & getHeader() const
Get header.
Definition: JHead.hh:1197
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:696
then echo Enter input within $TIMEOUT_S seconds echo n User name
Definition: JCookie.sh:42
#define MAKE_STRING(A)
Make string.
Definition: JPrint.hh:142
Exception for missing value.
Definition: JException.hh:198
Monte Carlo run header.
Definition: JHead.hh:1164
template<class JFileScanner_t = JMultipleFileScanner<Evt>>
void JSUPPORT::JEvtWeightFileScanner< JFileScanner_t >::reset ( const JEvtWeight weighter)
inline

Reset file scanner and event weighter.

Parameters
weighterevent weighter

Definition at line 128 of file JEvtWeightFileScanner.hh.

129  {
130  JEvtWeightHelper::configure(weighter);
131  JFileScanner_t ::clear();
132  }
void configure(const JEvtWeight &weighter)
Configuration.
template<class JFileScanner_t = JMultipleFileScanner<Evt>>
size_t JSUPPORT::JEvtWeightFileScanner< JFileScanner_t >::put ( const JMultipleFileScanner_t input)
inline

Put list of files.

Parameters
inputfile list
Returns
number of added files

Definition at line 141 of file JEvtWeightFileScanner.hh.

142  {
143  size_t n = 0;
144 
145  for (typename JMultipleFileScanner_t::const_iterator i = input.begin(); i != input.end(); ++i) {
146  n += size_t(this->put(*i));
147  }
148 
149  return n;
150  }
const int n
Definition: JPolint.hh:676
size_t put(const JMultipleFileScanner_t &input)
Put list of files.
template<class JFileScanner_t = JMultipleFileScanner<Evt>>
bool JSUPPORT::JEvtWeightFileScanner< JFileScanner_t >::put ( const std::string &  input)
inline

Put file.

Parameters
inputfile name
Returns
true if successfully added; else false.

Definition at line 159 of file JEvtWeightFileScanner.hh.

160  {
161  using namespace JPP;
162 
163  const JHead& head = JSUPPORT::getHeader(input);
164 
165  if (this->check(head)) {
166 
167  JEvtWeightHelper::add(head);
168  JFileScanner_t ::push_back(input);
169 
170  return true;
171 
172  } else {
173 
174  return false;
175  }
176  }
bool check(const JHead &header) const
Check if a given header is consistent with this event weighter.
Head getHeader(const JMultipleFileScanner_t &file_list)
Get Monte Carlo header.
Monte Carlo run header.
Definition: JHead.hh:1164
void add(const JHead &header)
Add header.
template<class JFileScanner_t = JMultipleFileScanner<Evt>>
template<class JEvtWeightFactor_t = JEvtWeightFactor>
bool JSUPPORT::JEvtWeightFileScanner< JFileScanner_t >::setEvtWeightFactor ( const int  type,
const JEvtWeightFactor_t &  factor 
)
inline

Set event-weight factor corresponding to a given PDG code.

The template argument corresponds to the desired class of event-weight factor. This class must contain the method getFactor(const Evt&).

Note that the given event-weight factor will only be assigned if the header < b>exclusively< /b> lists the given PDG code as primary.

Parameters
typePDG code
factorevent-weight factor
Returns
true if event-weight factor set successfully; else false

Definition at line 192 of file JEvtWeightFileScanner.hh.

194  {
195  using namespace std;
196  using namespace JPP;
197 
198  typedef JEvtWeightFactorHelper<JEvtWeightFactor_t> JEvtWeightFactorHelper_t;
199 
200  const JHead& header = this->getHeader();
201 
202  vector<JAANET::flux>::const_iterator i = find_if(header.flux.cbegin(),
203  header.flux.cend(),
204  make_predicate(&flux::type, type));
205 
206  if ((header.primary.type == type) ||
207  (abs(type) == TRACK_TYPE_MUON && is_mupage(header)) ||
208  (header.flux.size() == 1 && i != header.flux.end())) {
209 
210  JEvtWeightFactorHelper_t* helper = dynamic_cast<JEvtWeightFactorHelper_t*>(this->get());
211 
212  if (helper != NULL) {
213 
214  helper->configure(factor);
215 
216  return true;
217  }
218  }
219 
220  return false;
221  }
bool is_mupage(const JHead &header)
Check for generator.
Definition: JHeadToolkit.hh:84
JPredicate< JResult_t T::*, JComparison::eq > make_predicate(JResult_t T::*member, const JResult_t value)
Helper method to create predicate for data member.
Definition: JPredicate.hh:128
const JHead & getHeader() const
Get header.
Definition: JHead.hh:1197
Helper class for event-weight factor.
Monte Carlo run header.
Definition: JHead.hh:1164
template<class JFileScanner_t = JMultipleFileScanner<Evt>>
template<class JEvtWeightFactor_t = JEvtWeightFactor>
bool JSUPPORT::JEvtWeightFileScanner< JFileScanner_t >::setEvtWeightFactor ( const std::set< int > &  types,
const JEvtWeightFactor_t &  factor 
)
inline

Set event-weight factor corresponding to a given set of PDG codes.

The template argument corresponds to the desired class of event-weight factor. This class must contain the method getFactor(const Evt&).

Note that the given event-weight factor will only be assigned
if the header lists < b>all< /b> of the specified PDG codes as primaries.

Parameters
typesset of PDG codes
factorevent-weight factor
Returns
true if event-weight factor set successfully; else false

Definition at line 238 of file JEvtWeightFileScanner.hh.

240  {
241  using namespace std;
242  using namespace JPP;
243 
244  typedef JEvtWeightFactorHelper<JEvtWeightFactor_t> JEvtWeightFactorHelper_t;
245 
246  bool matching = (!types.empty());
247 
248  const JHead& header = this->getHeader();
249 
250  for (std::set<int>::const_iterator i = types.cbegin(); i != types.cend() && matching; ++i) {
251 
252  vector<JAANET::flux>::const_iterator flux = find_if(header.flux.cbegin(),
253  header.flux.cend(),
254  make_predicate(&flux::type, *i));
255 
256  matching = (flux != header.flux.cend());
257  }
258 
259  if (matching) {
260 
261  JEvtWeightFactorHelper_t* helper = dynamic_cast<JEvtWeightFactorHelper_t*>(this->get());
262 
263  if (helper != NULL) {
264 
265  helper->configure(factor);
266  return true;
267  }
268  }
269 
270  return false;
271  }
JPredicate< JResult_t T::*, JComparison::eq > make_predicate(JResult_t T::*member, const JResult_t value)
Helper method to create predicate for data member.
Definition: JPredicate.hh:128
const JHead & getHeader() const
Get header.
Definition: JHead.hh:1197
Neutrino flux.
Definition: JHead.hh:890
Helper class for event-weight factor.
Monte Carlo run header.
Definition: JHead.hh:1164
template<class JFileScanner_t = JMultipleFileScanner<Evt>>
template<class JEvtWeightFactor_t = JEvtWeightFactor>
bool JSUPPORT::JEvtWeightFileScanner< JFileScanner_t >::setEvtWeightFactor ( const JEvtWeightFactorMultiParticle< JEvtWeightFactor_t > &  multiParticleFactor)
inline

Set event-weight factor corresponding to a given multi-particle weighting factor interface.

The template argument corresponds to the desired class of event-weight factor. This class must contain the method getFactor(const Evt&).

Note that the given event-weight factors will only be assigned
if the header lists < b>all< /b> of the PDG codes associated with the multi-particle event-weight factor interface as primaries.

Parameters
multiParticleFactormulti-particle event-weight factor
Returns
true if multi-particle event-weight factor set successfully; else false

Definition at line 287 of file JEvtWeightFileScanner.hh.

288  {
289  using namespace std;
290  using namespace JPP;
291 
292  typedef JEvtWeightFactorHelper<JEvtWeightFactor_t> JEvtWeightFactorHelper_t;
293  typedef JEvtWeightFactorMultiParticle<JEvtWeightFactor_t> JEvtWeightFactorMultiParticle_t;
294  typedef typename JEvtWeightFactorMultiParticle_t::const_iterator const_iterator;
295 
296  bool matching = (!multiParticleFactor.empty());
297 
298  const JHead& header = this->getHeader();
299 
300  for (const_iterator i = multiParticleFactor.cbegin(); i != multiParticleFactor.cend() && matching; ++i) {
301 
302  vector<JAANET::flux>::const_iterator flux = find_if(header.flux.cbegin(),
303  header.flux.cend(),
304  make_predicate(&flux::type, i->first));
305 
306  matching = (flux != header.flux.cend());
307  }
308 
309  if (matching) {
310 
311  JEvtWeightFactorHelper_t* helper = dynamic_cast<JEvtWeightFactorHelper_t*>(this->get());
312 
313  if (helper != NULL) {
314 
315  helper->configure(multiParticleFactor);
316  return true;
317  }
318  }
319 
320  return false;
321  }
JPredicate< JResult_t T::*, JComparison::eq > make_predicate(JResult_t T::*member, const JResult_t value)
Helper method to create predicate for data member.
Definition: JPredicate.hh:128
const JHead & getHeader() const
Get header.
Definition: JHead.hh:1197
Implementation of event-weight factor for multiple particle types.
Neutrino flux.
Definition: JHead.hh:890
Helper class for event-weight factor.
Monte Carlo run header.
Definition: JHead.hh:1164
template<class JFileScanner_t = JMultipleFileScanner<Evt>>
bool JSUPPORT::JEvtWeightFileScanner< JFileScanner_t >::setFlux ( const int  type,
const JFlux function 
)
inline

Set flux function corresponding to a given PDG code.

Note that only the given flux function will only be assigned
if the header exclusively lists the given PDG code as primary.

Parameters
typePDG code
functionflux function
Returns
true if event-weight factor set successfully; else false

Definition at line 334 of file JEvtWeightFileScanner.hh.

336  {
337  return setEvtWeightFactor<JFlux>(type, function);
338  }
template<class JFileScanner_t = JMultipleFileScanner<Evt>>
bool JSUPPORT::JEvtWeightFileScanner< JFileScanner_t >::setFlux ( const std::set< int > &  types,
const JFlux function 
)
inline

Set flux function corresponding to a given set of PDG codes.

Note that the given flux function will only be assigned
if the header lists < b>all< /b> of the specified PDG codes as primaries.

Parameters
typesset of PDG codes
functionflux function
Returns
true if event-weight factor set successfully; else false

Definition at line 351 of file JEvtWeightFileScanner.hh.

353  {
354  return setEvtWeightFactor<JFlux>(types, function);
355  }
template<class JFileScanner_t = JMultipleFileScanner<Evt>>
bool JSUPPORT::JEvtWeightFileScanner< JFileScanner_t >::setFlux ( const JEvtWeightFactorMultiParticle< JFlux > &  multiParticleFlux)
inline

Set flux function corresponding to a given multi-particle flux interface.

Note that the given flux functions will only be assigned
if the lists < b>all< /b> of the PDG codes associated with the multi-particle flux object as primaries.

Parameters
multiParticleFluxmulti-particle flux object
Returns
true if multi-particle event-weight factor set successfully; else false

Definition at line 367 of file JEvtWeightFileScanner.hh.

368  {
369  return setEvtWeightFactor<JFlux>(multiParticleFlux);
370  }
void JAANET::JEvtWeightHelper::configure ( const JEvtWeight weighter)
inlineinherited

Configuration.

Parameters
weighterevent weighter

Definition at line 58 of file JEvtWeightHelper.hh.

59  {
60  counter = 0;
61 
62  reset(weighter.clone());
63  }
virtual void reset() override
Reset pointer.
bool JAANET::JEvtWeightHelper::check ( const JHead header) const
inlineinherited

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 72 of file JEvtWeightHelper.hh.

73  {
74  return (is_valid() ? get()->check(header) : false);
75  }
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)
inlineinherited

Add header.

Parameters
headerheader

Definition at line 83 of file JEvtWeightHelper.hh.

84  {
85  if (check(header)) {
86 
87  if (counter == 0) {
88  JHead::setHeader(header);
89  } else {
90  JHead::add(header);
91  }
92 
93  ++counter;
94 
95  get()->configure(getHeader());
96 
97  } else {
98 
99  THROW(JNullPointerException, "JEvtWeightHelper::add(): headers do not match.");
100  }
101  }
void configure(const JEvtWeight &weighter)
Configuration.
void setHeader(const JHead &header)
Set header.
Definition: JHead.hh:1219
const JHead & getHeader() const
Get header.
Definition: JHead.hh:1197
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:696
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:1406
double JAANET::JEvtWeightHelper::getWeight ( const Evt evt) const
inlineinherited

Get weight of given event.

Parameters
evtevent
Returns
weight [Hz]

Definition at line 110 of file JEvtWeightHelper.hh.

111  {
112  if (is_valid()) {
113  return get()->getWeight(evt);
114  } else {
115  THROW(JNullPointerException, "JEvtWeightHelper::getWeight(): Event weighter is null.");
116  }
117  }
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:696
bool is_valid() const
Check validity of pointer.
double getWeight(const Evt &evt) const
Get weight of given event.
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 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 1234 of file JHead.hh.

1235  {
1236  return (this->pull(pd) != this->end());
1237  }
const_iterator pull(T JHead::*pd) const
Pull given data member from Head.
Definition: JHead.hh:1264
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 1249 of file JHead.hh.

1250  {
1251  static const T value;
1252 
1253  return (object.less(value) || value.less(object));
1254  }
bool less(const JHead &header) const
Comparison of headers.
Definition: JHead.hh:1362
do set_variable OUTPUT_DIRECTORY $WORKDIR T
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  }
bool is_valid() const
Check validity of pointer.
Exception for null pointer operation.
Definition: JException.hh:216
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 393 of file Head.hh.

394  {
395  return Vec( stod( get_field("coord_origin", "x") ),
396  stod( get_field("coord_origin", "y") ),
397  stod( get_field("coord_origin", "z") ));
398  }
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:197
const JHead& JAANET::JHead::getHeader ( ) const
inlineinherited

Get header.

Returns
header

Definition at line 1197 of file JHead.hh.

1198  {
1199  return static_cast<const JHead&>(*this);
1200  }
Monte Carlo run header.
Definition: JHead.hh:1164
JHead& JAANET::JHead::getHeader ( )
inlineinherited

Get header.

Returns
header

Definition at line 1208 of file JHead.hh.

1209  {
1210  return static_cast<JHead&>(*this);
1211  }
Monte Carlo run header.
Definition: JHead.hh:1164
void JAANET::JHead::setHeader ( const JHead header)
inlineinherited

Set header.

Parameters
headerheader

Definition at line 1219 of file JHead.hh.

1220  {
1221  static_cast<JHead&>(*this) = header;
1222  }
Monte Carlo run header.
Definition: JHead.hh:1164
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 1264 of file JHead.hh.

1265  {
1266  return this->find(JROOT::getDataMember(pd)->GetName());
1267  }
const TDataMember * getDataMember(const JRootClass &parent, const JRootClass &member)
Get ROOT data member for given parent and member class.
Definition: JRootClass.hh:637
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 1277 of file JHead.hh.

1278  {
1279  return this->find(JROOT::getDataMember(pd)->GetName());
1280  }
const TDataMember * getDataMember(const JRootClass &parent, const JRootClass &member)
Get ROOT data member for given parent and member class.
Definition: JRootClass.hh:637
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 1289 of file JHead.hh.

1290  {
1291  (*this)[JROOT::getDataMember(pd)->GetName()] = "";
1292  }
const TDataMember * getDataMember(const JRootClass &parent, const JRootClass &member)
Get ROOT data member for given parent and member class.
Definition: JRootClass.hh:637
template<class T >
void JAANET::JHead::erase ( T JHead::*  pd)
inlineinherited

Remove given data member from Head.

Parameters
pdpointer to data member

Definition at line 1301 of file JHead.hh.

1302  {
1303  iterator p = this->pull(pd);
1304 
1305  if (p != this->end()) {
1306 
1307  this->*pd = T();
1308 
1309  static_cast<Head*>(this)->erase(p);
1310  }
1311  }
void erase(T JHead::*pd)
Remove given data member from Head.
Definition: JHead.hh:1301
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:67
const_iterator pull(T JHead::*pd) const
Pull given data member from Head.
Definition: JHead.hh:1264
int JAANET::JHead::getNumberOfMatches ( const JHead header) const
inlineinherited

Get number of matching fields.

Parameters
headersecond header
Returns
number of matching header fields

Definition at line 1320 of file JHead.hh.

1321  {
1322  return ((int) match(*this, header, &JHead::cut_primary) +
1323  (int) match(*this, header, &JHead::cut_seamuon) +
1324  (int) match(*this, header, &JHead::cut_in) +
1325  (int) match(*this, header, &JHead::cut_nu) +
1326  (int) match(*this, header, &JHead::simul) +
1327  (int) match(*this, header, &JHead::spectrum) +
1328  (int) match(*this, header, &JHead::can) +
1329  (int) match(*this, header, &JHead::fixedcan) +
1330  (int) match(*this, header, &JHead::genvol) +
1331  (int) match(*this, header, &JHead::coord_origin) +
1332  (int) match(*this, header, &JHead::norma) +
1333  (int) match(*this, header, &JHead::livetime) +
1334  (int) match(*this, header, &JHead::seabottom) +
1335  (int) match(*this, header, &JHead::depth) +
1336  (int) match(*this, header, &JHead::tgen) +
1337  (int) match(*this, header, &JHead::time_interval) +
1338  (int) match(*this, header, &JHead::primary) +
1339  (int) match(*this, header, &JHead::flux) +
1340  (int) match(*this, header, &JHead::DAQ));
1341  }
JAANET::depth depth
Definition: JHead.hh:1475
JAANET::genvol genvol
Definition: JHead.hh:1469
JAANET::norma norma
Definition: JHead.hh:1472
std::vector< JAANET::flux > flux
Definition: JHead.hh:1480
JAANET::cut_primary cut_primary
Definition: JHead.hh:1462
bool match(const JHead &header) const
Test match of headers.
Definition: JHead.hh:1350
std::vector< JAANET::simul > simul
Definition: JHead.hh:1461
JAANET::fixedcan fixedcan
Definition: JHead.hh:1468
JAANET::can can
Definition: JHead.hh:1467
JAANET::cut_seamuon cut_seamuon
Definition: JHead.hh:1463
JAANET::livetime livetime
Definition: JHead.hh:1473
JAANET::seabottom seabottom
Definition: JHead.hh:1474
JAANET::spectrum spectrum
Definition: JHead.hh:1466
JAANET::primary primary
Definition: JHead.hh:1479
JAANET::time_interval time_interval
Definition: JHead.hh:1478
JAANET::tgen tgen
Definition: JHead.hh:1477
JAANET::cut_in cut_in
Definition: JHead.hh:1464
JAANET::cut_nu cut_nu
Definition: JHead.hh:1465
JAANET::DAQ DAQ
Definition: JHead.hh:1476
Vec coord_origin() const
Get coordinate origin.
Definition: Head.hh:393
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 1350 of file JHead.hh.

1351  {
1352  return getNumberOfMatches(header) == getMaximumNumberOfMatches();
1353  }
static const int getMaximumNumberOfMatches()
Get maximum number of matching header fields.
Definition: JHead.hh:1489
int getNumberOfMatches(const JHead &header) const
Get number of matching fields.
Definition: JHead.hh:1320
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 1362 of file JHead.hh.

1363  {
1364 #define RETURN_IF_DIFFERENT(A, B) \
1365  if (less(A,B)) { return true; } \
1366  if (less(B,A)) { return false; }
1367 
1368  // compare physics
1369 
1370  RETURN_IF_DIFFERENT(this->physics, header.physics);
1371 
1372  // compare simulation
1373 
1374  RETURN_IF_DIFFERENT(this->simul, header.simul);
1375 
1376  // compare generation data
1377 
1378  RETURN_IF_DIFFERENT(this->primary, header.primary);
1379  RETURN_IF_DIFFERENT(this->flux, header.flux);
1380  RETURN_IF_DIFFERENT(this->spectrum, header.spectrum);
1383  RETURN_IF_DIFFERENT(this->cut_in, header.cut_in);
1384  RETURN_IF_DIFFERENT(this->cut_nu, header.cut_nu);
1385  RETURN_IF_DIFFERENT(this->genvol, header.genvol);
1386 
1387  // compare compatibility
1388 
1389  if (is_valid(this->livetime) == is_valid(header.livetime) &&
1390  is_valid(this->DAQ) == is_valid(header.DAQ)) {
1391  return false;
1392  }
1393 
1394  THROW(JException, "JHead::less() headers do not compare.");
1395 
1396 #undef RETURN_IF_DIFFERENT
1397  }
Phase space of incident neutrino.
Definition: JHead.hh:444
JAANET::genvol genvol
Definition: JHead.hh:1469
Neutrino vertex volume.
Definition: JHead.hh:634
std::vector< JAANET::flux > flux
Definition: JHead.hh:1480
Livetime of DAQ data.
Definition: JHead.hh:992
#define RETURN_IF_DIFFERENT(A, B)
Phase space of incoming particle.
Definition: JHead.hh:434
Generator for simulation.
Definition: JHead.hh:511
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:696
JAANET::cut_primary cut_primary
Definition: JHead.hh:1462
std::vector< JAANET::physics > physics
Definition: JHead.hh:1460
std::vector< JAANET::simul > simul
Definition: JHead.hh:1461
Physics information.
Definition: JHead.hh:501
JAANET::cut_seamuon cut_seamuon
Definition: JHead.hh:1463
JAANET::livetime livetime
Definition: JHead.hh:1473
Neutrino flux.
Definition: JHead.hh:890
JAANET::spectrum spectrum
Definition: JHead.hh:1466
JAANET::primary primary
Definition: JHead.hh:1479
Normalisation of MUPAGE events.
Definition: JHead.hh:819
JAANET::cut_in cut_in
Definition: JHead.hh:1464
Primary particle.
Definition: JHead.hh:1104
JAANET::cut_nu cut_nu
Definition: JHead.hh:1465
Phase space of atmospheric muon generation.
Definition: JHead.hh:424
Phase space of primary particle.
Definition: JHead.hh:414
bool is_valid(T JHead::*pd) const
Check validity of given data member in JHead.
Definition: JHead.hh:1234
JAANET::DAQ DAQ
Definition: JHead.hh:1476
Neutrino energy spectrum.
Definition: JHead.hh:521
static const int JAANET::JHead::getMaximumNumberOfMatches ( )
inlinestaticinherited

Get maximum number of matching header fields.

Returns
maximum number of matching header fields

Definition at line 1489 of file JHead.hh.

1490  {
1491  static const JHead header;
1492  static const int value = header.getNumberOfMatches(header);
1493 
1494  return value;
1495  }
Monte Carlo run header.
Definition: JHead.hh:1164
int getNumberOfMatches(const JHead &header) const
Get number of matching fields.
Definition: JHead.hh:1320
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 1507 of file JHead.hh.

1508  {
1509  static JLANG::JEquationParameters parameters(":", "\n", "", "");
1510 
1511  return parameters;
1512  }
*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 1520 of file JHead.hh.

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

Read header from input.

Parameters
ininput stream
Returns
input stream

Definition at line 30 of file JHead.cc.

31  {
32  using namespace std;
33  using namespace JPP;
34 
35  JStringStream is(in);
36 
37  if (getFileStatus(is.str().c_str())) {
38  is.load();
39  }
40 
42 
43  JRootReadableClass cls(*this);
44 
45  for (JEquation equation; reader >> equation && equation.getKey() != end_event::Class_Name(); ) {
46 
47  JRedirectString redirect(reader, equation.getValue());
48 
49  const JRootReadableClass abc = cls.find(equation.getKey().c_str());
50 
51  if (abc.is_valid()) {
52  reader.getObject(abc);
53  }
54 
55  (*this)[equation.getKey()] = equation.getValue();
56  }
57 
58  return in;
59  }
is
Definition: JDAQCHSM.chsm:167
T & getInstance(const T &object)
Get static instance from temporary object.
Definition: JObject.hh:75
static JLANG::JEquationParameters & getEquationParameters()
Get equation parameters corresponding to Monte Carlo ASCII format, i.e:
Definition: JHead.hh:1507
static JStat getFileStatus
Function object for file status.
Definition: JStat.hh:173
then fatal Wrong number of arguments fi set_variable DETECTOR $argv[1] set_variable INPUT_FILE $argv[2] eval JPrintDetector a $DETECTOR O IDENTIFIER eval JPrintDetector a $DETECTOR O SUMMARY source JAcoustics sh $DETECTOR_ID CHECK_EXIT_CODE typeset A TRIPODS get_tripods $WORKDIR tripod txt TRIPODS for EMITTER in
Definition: JCanberra.sh:42
std::ostream & JAANET::JHead::write ( std::ostream &  out) const
inherited

Write header to output.

Parameters
outoutput stream
Returns
output stream

Definition at line 68 of file JHead.cc.

69  {
70  using namespace std;
71  using namespace JPP;
72 
73  JRootWriter writer(out, JHead::getEquationParameters(), JAAnetDictionary::getInstance());
74 
75  JRootWritableClass cls(*this);
76 
77  TIterator* i = cls.getClass()->GetListOfDataMembers()->MakeIterator();
78 
79  for (const TDataMember* p; (p = (const TDataMember*) i->Next()) != NULL; ) {
80  if (!JRootClass::is_static(*p)) {
81  if (this->find(p->GetName()) != this->end() ||
82  cls.get(*p) == JRootClass(&JHead::start_run) ||
83  cls.get(*p) == JRootClass(&JHead::end_event)) {
84  writer.put(p->GetName(), cls.get(*p), true);
85  }
86  }
87  }
88 
89  return out << flush;
90  }
JAANET::end_event end_event
Definition: JHead.hh:1481
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:1507
JAANET::start_run start_run
Definition: JHead.hh:1454
std::ostream & JAANET::JHead::print ( std::ostream &  out) const
inherited

Print header to output.

Parameters
outoutput stream
Returns
output stream

Definition at line 99 of file JHead.cc.

100  {
101  using namespace std;
102  using namespace JPP;
103 
104  JRootWriter writer(out, JHead::getEquationParameters(), JAAnetDictionary::getInstance());
105 
106  JRootWritableClass cls(*this);
107 
108  TIterator* i = cls.getClass()->GetListOfDataMembers()->MakeIterator();
109 
111 
112  for (const TDataMember* p; (p = (const TDataMember*) i->Next()) != NULL; ) {
113  if (!JRootClass::is_static(*p)) {
114  if (cls.get(*p) != JRootClass(&JHead::end_event))
115  writer.put(p->GetName(), cls.get(*p), true);
116  else
117  end_event = make_pair(p->GetName(), cls.get(*p));
118  }
119  }
120 
121  for (JHead::const_iterator i = this->begin(); i != this->end(); ++i) {
122  if (!cls.find(i->first.c_str()).is_valid()) {
123  writer.put(i->first, i->second);
124  }
125  }
126 
127  writer.put(end_event.first, end_event.second, true);
128 
129  return out << flush;
130  }
JAANET::end_event end_event
Definition: JHead.hh:1481
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:1507
bool is_valid(T JHead::*pd) const
Check validity of given data member in JHead.
Definition: JHead.hh:1234
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 76 of file Head.hh.

77  {
78  return count( key ) != 0;
79  }
std::vector< int > count
Definition: JAlgorithm.hh:180
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 88 of file Head.hh.

89  {
90  return this->at(key);
91  }
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 100 of file Head.hh.

101  {
102  return this->at(key);
103  }
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 114 of file Head.hh.

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

154  {
156 
157  for ( auto& key : matching_keys( tag ) ) {
158  r.push_back( get_line( key ) );
159  }
160 
161  return r;
162  }
data_type r[M+1]
Definition: JPolint.hh:758
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:114
const std::string & get_line(std::string key) const
Get data with the given key.
Definition: Head.hh:88
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 175 of file Head.hh.

176  {
177  std::string k = tag;
178 
179  if (ensure_unique)
180  for (int i = 1; find(k) != end() ; i++)
181  {
182  k = tag + "_" + std::to_string(i);
183  }
184 
186  return k;
187  }
then fatal No hydrophone data file $HYDROPHONE_TXT fi sort gr k
std::string to_string(const T &value)
Convert value to string.
std::string Head::get_field ( std::string  key,
int  idx 
) const
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 197 of file Head.hh.

198  {
199  using namespace std;
200 
202 
203  if ( idx < 0 || idx >= int ( v.size() ) )
204  {
205  THROW(Exception, "Cannot find word number " << idx << " in line " << get_line(key) << " for key: " << key);
206  }
207  return v[idx];
208  }
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:696
General exception.
Definition: Exception.hh:13
const std::string & get_line(std::string key) const
Get data with the given key.
Definition: Head.hh:88
data_type v[N+1][M+1]
Definition: JPolint.hh:756
std::vector< std::string > splitstring(const std::string &str, char delim= ' ')
Split string at delimiter.
Definition: Head.hh:46
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 237 of file Head.hh.

238  {
239  int idx = get_index_of_field(key, field);
240 
241  if ( idx == -1 )
242  {
243  THROW(Exception, "Failed to find" << key << " " << field);
244  }
245 
246  return get_field( key, idx );
247  }
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:696
int get_index_of_field(std::string key, std::string field) const
Get index of data with the given key at given field.
Definition: Head.hh:219
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:197
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 219 of file Head.hh.

220  {
221  auto v = _hdr_dict()[key];
222  auto i = std::find (v.begin(), v.end(), field );
223  if (i == v.end()) return -1;
224  return i - v.begin();
225  }
data_type v[N+1][M+1]
Definition: JPolint.hh:756
static std::map< std::string, std::vector< std::string > > & _hdr_dict()
Get internal description of the known lines in header.
Definition: Head.hh:312
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 260 of file Head.hh.

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

Get internal description of the known lines in header.

Returns
internal dictionary

Definition at line 312 of file Head.hh.

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

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

Returns
number of events

Definition at line 362 of file Head.hh.

363  {
364  return stod ( get_field("genvol", "numberOfEvents") );
365  }
std::string get_field(std::string key, int idx) const
Get data with the given key at given index.
Definition: Head.hh:197
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 372 of file Head.hh.

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

Get the Monte Carlo live time.

Returns
live time [s]

Definition at line 383 of file Head.hh.

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

Get coordinate translation.

Returns
translation

Definition at line 405 of file Head.hh.

406  {
407  return Vec( stod( get_field("translate", "x") ),
408  stod( get_field("translate", "y") ),
409  stod( get_field("translate", "z") ));
410  }
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:197

Member Data Documentation

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

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

Definition at line 1455 of file JHead.hh.

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

Definition at line 1456 of file JHead.hh.

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

Definition at line 1457 of file JHead.hh.

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

Definition at line 1458 of file JHead.hh.

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

Definition at line 1459 of file JHead.hh.

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

Definition at line 1460 of file JHead.hh.

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

Definition at line 1461 of file JHead.hh.

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

Definition at line 1462 of file JHead.hh.

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

Definition at line 1463 of file JHead.hh.

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

Definition at line 1464 of file JHead.hh.

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

Definition at line 1465 of file JHead.hh.

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

Definition at line 1466 of file JHead.hh.

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

Definition at line 1467 of file JHead.hh.

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

Definition at line 1468 of file JHead.hh.

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

Definition at line 1469 of file JHead.hh.

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

Definition at line 1470 of file JHead.hh.

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

Definition at line 1471 of file JHead.hh.

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

Definition at line 1472 of file JHead.hh.

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

Definition at line 1473 of file JHead.hh.

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

Definition at line 1474 of file JHead.hh.

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

Definition at line 1475 of file JHead.hh.

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

Definition at line 1476 of file JHead.hh.

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

Definition at line 1477 of file JHead.hh.

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

Definition at line 1478 of file JHead.hh.

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

Definition at line 1479 of file JHead.hh.

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

Definition at line 1480 of file JHead.hh.

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

Definition at line 1481 of file JHead.hh.


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