Jpp 19.3.0-rc.1
the software that should make you happy
Loading...
Searching...
No Matches
JHeadSet.hh
Go to the documentation of this file.
1#ifndef __JSUPPORT_JHEADSET__
2#define __JSUPPORT_JHEADSET__
3
4#include <vector>
5#include <algorithm>
6#include <functional>
7
9
10#include "JLang/JException.hh"
11
12#include "JAAnet/JHead.hh"
14
16
17
18namespace JSUPPORT {}
19namespace JPP { using namespace JSUPPORT; }
20
21namespace JSUPPORT {
22
24
25 /**
26 * Auxiliary class for organising Monte Carlo run headers.
27 */
28 template<class JComparator_t = std::less<JHead> >
29 struct JHeadSet :
30 std::vector<JHead>
31 {
32 /**
33 * Default constructor.
34 */
36 {}
37
38
39 /**
40 * Constructor.
41 *
42 * \param input file list
43 */
45 {
46 put(input);
47 }
48
49
50 /**
51 * Put headers from given list of files.
52 *
53 * \param input file list
54 */
56 {
57 for (JMultipleFileScanner_t::const_iterator i = input.begin(); i != input.end(); ++i) {
58 this->put(*i);
59 }
60 }
61
62
63 /**
64 * Put header from given file.
65 *
66 * \param input file name
67 */
68 void put(const std::string& input)
69 {
70 using namespace std;
71 using namespace JPP;
72
73 const JHead head = getHeader(input);
74
75 iterator p = lower_bound(this->begin(), this->end(), head, compare);
76
77 if (p != this->end() && *p == head)
78 p->add(head);
79 else
80 this->insert(p, head);
81 }
82
83
84 /**
85 * Get header for given file.
86 *
87 * \param input file name
88 */
89 const JHead& get(const std::string& input) const
90 {
91 const JHead head = getHeader(input);
92
93 const_iterator p = lower_bound(this->begin(), this->end(), head, compare);
94
95 if (p != this->end())
96 return *p;
97 else
98 THROW(JValueOutOfRange, "No corresponding header for file " << input);
99 }
100
101
102 /**
103 * Function object for comparison of headers.
104 */
105 JComparator_t compare;
106 };
107}
108
109#endif
110
Exceptions.
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Monte Carlo run header.
Definition JHead.hh:1236
Exception for accessing a value in a collection that is outside of its range.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Support classes and methods for experiment specific I/O.
Head getHeader(const JMultipleFileScanner_t &file_list)
Get Monte Carlo header.
Auxiliary class for organising Monte Carlo run headers.
Definition JHeadSet.hh:31
JHeadSet()
Default constructor.
Definition JHeadSet.hh:35
JHeadSet(JMultipleFileScanner_t &input)
Constructor.
Definition JHeadSet.hh:44
JComparator_t compare
Function object for comparison of headers.
Definition JHeadSet.hh:105
void put(const std::string &input)
Put header from given file.
Definition JHeadSet.hh:68
void put(JMultipleFileScanner_t &input)
Put headers from given list of files.
Definition JHeadSet.hh:55
const JHead & get(const std::string &input) const
Get header for given file.
Definition JHeadSet.hh:89
Auxiliary base class for list of file names.