Jpp  16.0.0
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JEvtWeightFileScannerSet.hh
Go to the documentation of this file.
1 #ifndef __JSUPPORT_JEVTWEIGHTFILESCANNERSET__
2 #define __JSUPPORT_JEVTWEIGHTFILESCANNERSET__
3 
4 #include <set>
5 #include <vector>
6 #include <string>
7 
10 
11 #include "JLang/JException.hh"
12 #include "JLang/JPredicate.hh"
13 #include "JLang/JComparator.hh"
14 
15 #include "JAAnet/JHead.hh"
20 #include "JAAnet/JFlux.hh"
21 
25 
26 
27 /**
28  * \author bjung
29  */
30 
31 namespace JSUPPORT {
32 
34 
35  using JAANET::JHead;
36 
40 
41  using JAANET::JFlux;
42 
43 
44  /**
45  * Auxiliary class for organising Monte Carlo file scanners associated with event weighters.
46  */
47  template<class JFileScanner_t = JMultipleFileScanner<Evt>,
48  class JComparator_t = std::less<JHead> >
50  std::vector< JEvtWeightFileScanner<JFileScanner_t> >
51  {
53 
58 
61 
62 
63  /**
64  * Default constructor.
65  */
67  {}
68 
69 
70  /**
71  * Constructor.
72  *
73  * \param input file list
74  */
76  {
77  put(input);
78  }
79 
80 
81  /**
82  * Put file
83  *
84  * \param input file list
85  * \return number of added files
86  */
87  size_t put(const JMultipleFileScanner_t& input)
88  {
89  size_t n = 0;
90 
91  for (JMultipleFileScanner_t::const_iterator i = input.begin(); i != input.end(); ++i) {
92  n += size_t(this->put(*i));
93  }
94 
95  return n;
96  }
97 
98 
99  /**
100  * Put file
101  *
102  * \param input file name
103  * \return true if successfully added; else false.
104  */
105  bool put(const std::string& input)
106  {
107  using namespace std;
108  using namespace JPP;
109 
110  const JHead& head = getHeader(input);
111 
112  iterator i = lower_bound(this->begin(), this->end(), head,
114 
115  if (i == this->end() || !i->getHeader().match(head)) {
116  i = this->insert(i, value_type(getEventWeighter(head)));
117  }
118 
119  return i->put(input);
120  }
121 
122 
123  /**
124  * Get unique identifier for a file-scanner contained within this set of event-weighter-associated file-scanners.
125  *
126  * \param p iterator to contained file-scanner
127  * \return unique identifier of contained file-scanner
128  */
129  std::string getUniqueIdentifier(const_iterator p) const
130  {
131  using namespace std;
132  using namespace JPP;
133 
134  static const char SEPARATOR = '.';
135 
136  string name = p->getProgramName();
137  int index = 0;
138 
139  for (typename vector<value_type>::const_iterator i = this->cbegin(); i != this->cend() && i != p; ++i) {
140  if (i->getProgramName() == name) {
141  ++index;
142  }
143  }
144 
145  return MAKE_STRING(name << SEPARATOR << index);
146  }
147 
148 
149  /**
150  * Find file scanner compatible with a given header.
151  *
152  * \param head header
153  * \return file scanner
154  */
156  {
157  for (const_iterator i = this->begin(); i != this->end(); ++i) {
158  if (i->match(head)) {
159  return *i;
160  }
161  }
162 
163  THROW(JValueOutOfRange, "JEvtWeightFileScannerSet::get(): No corresponding scanner found for given header.");
164  }
165 
166 
167  /**
168  * Set event-weighting factor for all MC-files corresponding to a given PDG code.
169  *
170  * The template argument corresponds to the desired class of event-weight factor.
171  * This class must contain the method `getFactor(const Evt&)`.
172  *
173  * Note that the given event-weighting factor will only be assigned to those files\n
174  * whose header exclusively lists the given PDG code as primary.
175  *
176  * \param type PDG code
177  * \param factor event-weight factor
178  * \return number of modified event weighters
179  */
180  template<class JEvtWeightFactor_t = JEvtWeightFactor>
181  size_t setEvtWeightFactor(const int type,
182  const JEvtWeightFactor_t& factor)
183  {
184  using namespace std;
185  using namespace JPP;
186 
187  size_t n = 0;
188 
189  for (iterator i = this->begin(); i != this->end(); ++i) {
190  n += (size_t) i->template setEvtWeightFactor<JEvtWeightFactor_t>(type, factor);
191  }
192 
193  return n;
194  }
195 
196 
197  /**
198  * Set event-weight factor of all MC-files corresponding to a given set of PDG codes.
199  *
200  * The template argument corresponds to the desired class of event-weight factor.
201  * This class must contain the method `getFactor(const Evt&)`.
202  *
203  * Note that the given event-weighting factor will only be assigned to those files\n
204  * whose header lists < b>all< /b> of the specified PDG codes as primaries.
205  *
206  * \param types set of PDG codes
207  * \param factor event-weight factor
208  * \return number of modified event weighters
209  */
210  template<class JEvtWeightFactor_t = JEvtWeightFactor>
211  size_t setEvtWeightFactor(const std::set<int>& types,
212  const JEvtWeightFactor_t& factor)
213  {
214  using namespace std;
215  using namespace JPP;
216 
217  size_t n = 0;
218 
219  for (iterator i = this->begin(); i != this->end(); ++i) {
220  n += (size_t) i->template setEvtWeightFactor<JEvtWeightFactor_t>(types, factor);
221  }
222 
223  return n;
224  }
225 
226 
227  /**
228  * Set event-weight factor of all MC-files corresponding to a given multi-particle flux.
229  *
230  * The template argument corresponds to the desired class of event-weight factor.
231  * This class must contain the method `getFactor(const Evt&)`.
232  *
233  * Note that the given event-weighting factors will only be assigned to those files\n
234  * whose header lists < b>all< /b> of the PDG codes associated with the multi-particle event-weighting factor object as primaries.
235  *
236  * \param multiParticleFactor multi-particle event-weight factor
237  * \return number of modified event weighters
238  */
239  template<class JEvtWeightFactor_t = JEvtWeightFactor>
241  {
242  using namespace std;
243  using namespace JPP;
244 
245  size_t n = 0;
246 
247  for (iterator i = this->begin(); i != this->end(); ++i) {
248  n += (size_t) i->template setEvtWeightFactor<JEvtWeightFactor_t>(multiParticleFactor);
249  }
250 
251  return n;
252  }
253 
254 
255  /**
256  * Set flux function for all MC-files corresponding to a given PDG code.
257  *
258  * Note that only the given flux function will only be assigned to those files\n
259  * whose header exclusively lists the given PDG code as primary.
260  *
261  * \param type PDG code
262  * \param flux flux function
263  * \return number of modified event weighters
264  */
265  size_t setFlux(const int type,
266  const JFlux& flux)
267  {
268  return setEvtWeightFactor<JFlux>(type, flux);
269  }
270 
271 
272  /**
273  * Set flux function of all MC-files corresponding to a given set of PDG codes.
274  *
275  * Note that the given flux function will only be assigned to those files\n
276  * whose header lists < b>all< /b> of the specified PDG codes as primaries.
277  *
278  * \param types set of PDG codes
279  * \param flux flux function
280  * \return number of modified event weighters
281  */
282  size_t setFlux(const std::set<int>& types,
283  const JFlux& flux)
284  {
285  return setEvtWeightFactor<JFlux>(types, flux);
286  }
287 
288 
289  /**
290  * Set flux function of all MC-files corresponding to a given multi-particle flux interface.
291  *
292  * Note that the given flux functions will only be assigned to those files\n
293  * whose header lists < b>all< /b> of the PDG codes associated with the multi-particle flux interface as primaries.
294  *
295  * \param multiParticleFlux multi-particle flux object
296  * \return number of modified event weighters
297  */
298  size_t setFlux(const JEvtWeightFactorMultiParticle<JFlux>& multiParticleFlux)
299  {
300  return setEvtWeightFactor<JFlux>(multiParticleFlux);
301  }
302 
303 
304  /**
305  * Function object for comparison of headers.
306  */
307  JComparator_t compare;
308  };
309 
310 
311 }
312 
313 #endif
314 
JEvtWeighter getEventWeighter
Function object for mapping header to event weighter.
Exceptions.
bool put(const std::string &input)
Put file.
std::vector< value_type >::const_reverse_iterator const_reverse_iterator
JComparator< JResult_t T::*, JComparison::lt > make_comparator(JResult_t T::*member)
Helper method to create comparator between values of data member.
Definition: JComparator.hh:185
std::string getUniqueIdentifier(const_iterator p) const
Get unique identifier for a file-scanner contained within this set of event-weighter-associated file-...
size_t setFlux(const std::set< int > &types, const JFlux &flux)
Set flux function of all MC-files corresponding to a given set of PDG codes.
size_t setEvtWeightFactor(const std::set< int > &types, const JEvtWeightFactor_t &factor)
Set event-weight factor of all MC-files corresponding to a given set of PDG codes.
const JEvtWeightFileScanner< JFileScanner_t > & find(const JHead &head) const
Find file scanner compatible with a given header.
const JHead & getHeader() const
Get header.
Definition: JHead.hh:1197
JEvtWeightFileScanner< JFileScanner_t > value_type
JEvtWeightFileScannerSet(const JMultipleFileScanner_t &input)
Constructor.
#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
size_t put(const JMultipleFileScanner_t &input)
Put file.
size_t setEvtWeightFactor(const int type, const JEvtWeightFactor_t &factor)
Set event-weighting factor for all MC-files corresponding to a given PDG code.
std::vector< value_type >::reverse_iterator reverse_iterator
std::vector< value_type >::iterator iterator
#define MAKE_STRING(A)
Make string.
Definition: JPrint.hh:142
size_t setEvtWeightFactor(const JEvtWeightFactorMultiParticle< JEvtWeightFactor_t > &multiParticleFactor)
Set event-weight factor of all MC-files corresponding to a given multi-particle flux.
Head getHeader(const JMultipleFileScanner_t &file_list)
Get Monte Carlo header.
const int n
Definition: JPolint.hh:676
Implementation of event-weight factor for multiple particle types.
std::vector< value_type >::reference reference
Neutrino flux.
Definition: JHead.hh:890
Helper class for event-weight factor.
Low-level interface for retrieving the flux corresponding to a given event.
Definition: JFlux.hh:18
Monte Carlo run header.
Definition: JHead.hh:1164
std::vector< value_type >::const_reference const_reference
Scanning of objects from multiple files according a format that follows from the extension of each fi...
Auxiliary base class for list of file names.
size_t setFlux(const JEvtWeightFactorMultiParticle< JFlux > &multiParticleFlux)
Set flux function of all MC-files corresponding to a given multi-particle flux interface.
size_t setFlux(const int type, const JFlux &flux)
Set flux function for all MC-files corresponding to a given PDG code.
Auxiliary class for organising Monte Carlo file scanners associated with event weighters.
Exception for accessing a value in a collection that is outside of its range.
Definition: JException.hh:162
Template event-weighter-associated file scanner.
std::vector< value_type >::const_iterator const_iterator
Low-level interface for retrieving a specifiable multiplication factor corresponding to a given event...
JComparator_t compare
Function object for comparison of headers.