Jpp  16.0.0-rc.1
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"
16 #include "JAAnet/JFlux.hh"
21 
25 
26 
27 /**
28  * \author bjung
29  */
30 
31 namespace JSUPPORT {
32 
34 
35  using JAANET::JHead;
36 
37  using JAANET::JFlux;
38  using JAANET::JFluxHelper;
40 
44 
45 
46  /**
47  * Auxiliary class for organising Monte Carlo file scanners associated with event weighters.
48  */
49  template<class JFileScanner_t = JMultipleFileScanner<Evt>,
50  class JComparator_t = std::less<JHead> >
52  std::vector< JEvtWeightFileScanner<JFileScanner_t> >
53  {
55 
60 
63 
64 
65  /**
66  * Default constructor.
67  */
69  {}
70 
71 
72  /**
73  * Constructor.
74  *
75  * \param input file list
76  */
78  {
79  put(input);
80  }
81 
82 
83  /**
84  * Put file
85  *
86  * \param input file list
87  * \return number of added files
88  */
89  size_t put(const JMultipleFileScanner_t& input)
90  {
91  size_t n = 0;
92 
93  for (JMultipleFileScanner_t::const_iterator i = input.begin(); i != input.end(); ++i) {
94  n += size_t(this->put(*i));
95  }
96 
97  return n;
98  }
99 
100 
101  /**
102  * Put file
103  *
104  * \param input file name
105  * \return true if successfully added; else false.
106  */
107  bool put(const std::string& input)
108  {
109  using namespace std;
110  using namespace JPP;
111 
112  const JHead& head = getHeader(input);
113 
114  iterator i = lower_bound(this->begin(), this->end(), head,
116 
117  if (i == this->end() || !i->getHeader().match(head)) {
118  i = this->insert(i, value_type(getEventWeighter(head)));
119  }
120 
121  return i->put(input);
122  }
123 
124 
125  /**
126  * Get unique identifier for a file-scanner contained within this set of event-weighter-associated file-scanners.
127  *
128  * \param p iterator to contained file-scanner
129  * \return unique identifier of contained file-scanner
130  */
131  std::string getUniqueIdentifier(const_iterator p) const
132  {
133  using namespace std;
134  using namespace JPP;
135 
136  static const char SEPARATOR = '.';
137 
138  string name = p->getProgramName();
139  int index = 0;
140 
141  for (typename vector<value_type>::const_iterator i = this->cbegin(); i != this->cend() && i != p; ++i) {
142  if (i->getProgramName() == name) {
143  ++index;
144  }
145  }
146 
147  return MAKE_STRING(name << SEPARATOR << index);
148  }
149 
150 
151  /**
152  * Find file scanner compatible with a given header.
153  *
154  * \param head header
155  * \return file scanner
156  */
158  {
159  for (const_iterator i = this->begin(); i != this->end(); ++i) {
160  if (i->match(head)) {
161  return *i;
162  }
163  }
164 
165  THROW(JValueOutOfRange, "JEvtWeightFileScannerSet::get(): No corresponding scanner found for given header.");
166  }
167 
168 
169  /**
170  * Set event-weighting factor for all MC-files corresponding to a given PDG code.
171  *
172  * Note that the given event-weighting factor will only be assigned to those files\n
173  * whose header exclusively lists the given PDG code as primary.
174  *
175  * \param type PDG code
176  * \param factor event-weight factor
177  * \return number of modified event weighters
178  */
179  size_t setEvtWeightFactor(const int type,
180  const JEvtWeightFactor& factor)
181  {
182  using namespace std;
183  using namespace JPP;
184 
185  size_t n = 0;
186 
187  for (iterator i = this->begin(); i != this->end(); ++i) {
188  n += (size_t) i->setEvtWeightFactor(type, factor);
189  }
190 
191  return n;
192  }
193 
194 
195  /**
196  * Set event-weight factor of all MC-files corresponding to a given set of PDG codes.
197  *
198  * Note that the given event-weighting factor will only be assigned to those files\n
199  * whose header lists < b>all< /b> of the specified PDG codes as primaries.
200  *
201  * \param types set of PDG codes
202  * \param factor event-weight factor
203  * \return number of modified event weighters
204  */
205  size_t setEvtWeightFactor(const std::set<int>& types,
206  const JEvtWeightFactor& factor)
207  {
208  using namespace std;
209  using namespace JPP;
210 
211  size_t n = 0;
212 
213  for (iterator i = this->begin(); i != this->end(); ++i) {
214  n += (size_t) i->setEvtWeightFactor(types, factor);
215  }
216 
217  return n;
218  }
219 
220 
221  /**
222  * Set event-weight factor of all MC-files corresponding to a given multi-particle flux.
223  *
224  * Note that the given event-weighting factors will only be assigned to those files\n
225  * whose header lists < b>all< /b> of the PDG codes associated with the multi-particle event-weighting factor object as primaries.
226  *
227  * \param multiParticleFactor multi-particle event-weight factor
228  * \return number of modified event weighters
229  */
230  size_t setEvtWeightFactor(const JEvtWeightFactorMultiParticle& multiParticleFactor)
231  {
232  using namespace std;
233  using namespace JPP;
234 
235  size_t n = 0;
236 
237  for (iterator i = this->begin(); i != this->end(); ++i) {
238  n += (size_t) i->setEvtWeightFactor(multiParticleFactor);
239  }
240 
241  return n;
242  }
243 
244 
245  /**
246  * Set flux function for all MC-files corresponding to a given PDG code.
247  *
248  * Note that only the given flux function will only be assigned to those files\n
249  * whose header exclusively lists the given PDG code as primary.
250  *
251  * \param type PDG code
252  * \param function flux function
253  * \return number of modified event weighters
254  */
255  size_t setFlux(const int type,
256  const JFlux& function)
257  {
258  return setEvtWeightFactor(type, function);
259  }
260 
261 
262  /**
263  * Set flux function of all MC-files corresponding to a given set of PDG codes.
264  *
265  * Note that the given flux function will only be assigned to those files\n
266  * whose header lists < b>all< /b> of the specified PDG codes as primaries.
267  *
268  * \param types set of PDG codes
269  * \param function flux function
270  * \return number of modified event weighters
271  */
272  size_t setFlux(const std::set<int>& types,
273  const JFlux& function)
274  {
275  return setEvtWeightFactor(types, function);
276  }
277 
278 
279  /**
280  * Set flux function of all MC-files corresponding to a given multi-particle flux.
281  *
282  * Note that the given flux functions will only be assigned to those files\n
283  * whose header lists < b>all< /b> of the PDG codes associated with the multi-particle flux as primaries.
284  *
285  * \param multiParticleFlux multi-particle flux object
286  * \return number of modified event weighters
287  */
288  size_t setFlux(const JFluxMultiParticle& multiParticleFlux)
289  {
290  return setEvtWeightFactor(multiParticleFlux);
291  }
292 
293 
294  /**
295  * Function object for comparison of headers.
296  */
297  JComparator_t compare;
298  };
299 
300 
301 }
302 
303 #endif
304 
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 JFluxMultiParticle &multiParticleFlux)
Set flux function of all MC-files corresponding to a given multi-particle flux.
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.
std::vector< value_type >::reverse_iterator reverse_iterator
JEvtWeightFactorMultiParticle JFluxMultiParticle
Alias for implementation of an interface to multiple flux functions.
Definition: JFlux.hh:39
std::vector< value_type >::iterator iterator
#define MAKE_STRING(A)
Make string.
Definition: JPrint.hh:142
Head getHeader(const JMultipleFileScanner_t &file_list)
Get Monte Carlo header.
const int n
Definition: JPolint.hh:676
JEvtWeightFactor JFlux
Alias for flux function interface.
Definition: JFlux.hh:18
Implementation of event-weight factor for multiple particle types.
std::vector< value_type >::reference reference
size_t setEvtWeightFactor(const std::set< int > &types, const JEvtWeightFactor &factor)
Set event-weight factor of all MC-files corresponding to a given set of PDG codes.
Helper class for event-weight factor.
size_t setEvtWeightFactor(const JEvtWeightFactorMultiParticle &multiParticleFactor)
Set event-weight factor of all MC-files corresponding to a given multi-particle flux.
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...
size_t setFlux(const std::set< int > &types, const JFlux &function)
Set flux function of all MC-files corresponding to a given set of PDG codes.
Auxiliary base class for list of file names.
size_t setFlux(const int type, const JFlux &function)
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.
JEvtWeightFactorHelper JFluxHelper
Alias for flux function interface helper.
Definition: JFlux.hh:23
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...
size_t setEvtWeightFactor(const int type, const JEvtWeightFactor &factor)
Set event-weighting factor for all MC-files corresponding to a given PDG code.
JComparator_t compare
Function object for comparison of headers.