Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JWeightFileScannerSet.hh
Go to the documentation of this file.
1 #ifndef __JSUPPORT_JWEIGHTFILESCANNERSET__
2 #define __JSUPPORT_JWEIGHTFILESCANNERSET__
3 
4 #include <vector>
5 #include <functional>
6 
9 
10 #include "JLang/JException.hh"
11 #include "JLang/JComparator.hh"
12 
15 
16 #include "JAAnet/JHead.hh"
18 
19 /**
20  * \author bjung
21  */
22 
23 namespace JSUPPORT {
24 
25  using JAANET::JHead;
27 
28 
29  /**
30  * Auxiliary class for organising Monte Carlo file scanners.
31  */
32  template<class JFileScanner_t = JMultipleFileScanner<Evt>,
33  class JComparator_t = std::less<JHead> >
35  std::vector< JWeightFileScanner<JFileScanner_t> >
36  {
38 
43 
44 
45  /**
46  * Default constructor.
47  */
49  {}
50 
51 
52  /**
53  * Constructor.
54  *
55  * \param input file list
56  * \param limit limit
57  */
59  JLimit& limit = JLimit())
60  {
61  put (input);
62  setLimit(limit);
63  }
64 
65 
66  /**
67  * Put file
68  *
69  * \param input file list
70  */
72  {
73  for (JMultipleFileScanner_t::const_iterator i = input.begin(); i != input.end(); ++i) {
74  this->put(*i);
75  }
76  }
77 
78 
79  /**
80  * Put file
81  *
82  * \param input file name
83  */
84  void put(const std::string& input)
85  {
86  using namespace std;
87  using namespace JPP;
88 
89  const JHead head = getHeader(input);
90 
91  iterator p = lower_bound(this->begin(), this->end(), head,
93 
94  if (p == this->end()) {
95  p = this->insert(p, value_type(getEventWeighter(head)));
96  }
97 
98  p->put(input);
99  }
100 
101 
102  /**
103  * Get file scanner for given header
104  *
105  * \param head header
106  * \return file scanner
107  */
108  const value_type& get(const JHead& head) const
109  {
110  for (const_iterator p = this->begin(); p != this->end(); ++p) {
111  if (p->match(head, false)) {
112  return *p;
113  }
114  }
115 
116  THROW(JValueOutOfRange, "JWeightFileScannerSet::get(): No corresponding scanner found for given header.");
117  }
118 
119 
120  /**
121  * Set limit.
122  *
123  * \param limit limit
124  */
125  void setLimit(const JLimit& limit)
126  {
127  for (iterator p = this->begin(); p != this->end(); ++p) {
128  p->setLimit(limit);
129  }
130  }
131 
132 
133  /**
134  * Function object for comparison of headers.
135  */
136  JComparator_t compare;
137  };
138 }
139 
140 #endif
141 
Exceptions.
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
JWeightFileScanner< JFileScanner_t > value_type
const JHead & getHeader() const
Get header.
Definition: JHead.hh:1083
JWeightFileScannerSet(JMultipleFileScanner_t &input, JLimit &limit=JLimit())
Constructor.
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:670
std::vector< value_type >::const_iterator const_iterator
Auxiliary class for organising Monte Carlo file scanners.
std::vector< value_type >::iterator iterator
Head getHeader(const JMultipleFileScanner_t &file_list)
Get Monte Carlo header.
Auxiliary class for defining the range of iterations of objects.
Definition: JLimit.hh:41
Template file scanner with event weight.
std::vector< value_type >::reverse_iterator reverse_iterator
JEventWeighter getEventWeighter
Function object for mapping header to event weighter.
Monte Carlo run header.
Definition: JHead.hh:1050
JComparator_t compare
Function object for comparison of headers.
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.
Exception for accessing a value in a collection that is outside of its range.
Definition: JException.hh:162
JWeightFileScannerSet()
Default constructor.
void setLimit(const JLimit &limit)
Set limit.
std::vector< value_type >::const_reverse_iterator const_reverse_iterator
void put(const std::string &input)
Put file.
void put(JMultipleFileScanner_t &input)
Put file.