ATLAS Offline Software
Loading...
Searching...
No Matches
CombinationsJetStream.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3*/
4
5#ifndef TRIGHLTJETHYPO_COMBINATIONSJETSTREAM_H
6#define TRIGHLTJETHYPO_COMBINATIONSJETSTREAM_H
7
8/*
9 * CompoundJetStream is an implementation of IJetStream.
10 * on every call to bump(), it makes available a vector of k
11 * indices chosen from a vector of n indices.
12 *
13 * The positions in the k chosen jets in the jet indices list
14 * is claculated by an instance of CombinationsGenerator, held
15 * as attribute of this class.
16 *
17 * On each call to bump(), the right neighbor is checked for
18 * having cycled. If this is rthe case, or if there is no such neighbor,
19 * the instance will bump itself by
20 * asking its CombinationsGenerator which positions to
21 * use, and makes these values availble for collection.
22 * When all combinations have been exhausted by succesive calls to
23 * bump, the bump() returns true, and the cycle is restarted.
24 *
25 */
26
27
28#include "IJetStream.h"
30#include <vector>
31#include <sstream>
32#include <memory>
33#include <string>
34
36
37 public:
38 friend std::ostream& operator << (std::ostream&,
40 friend std::stringstream& operator << (std::stringstream&,
42
43 CombinationsJetStream(const std::vector<std::size_t>& jets,
44 std::unique_ptr<IJetStream> neigh,
45 std::size_t k,
46 std::size_t id):
47 m_jets(jets),
48 m_neigh(std::move(neigh)),
49 m_id{id}
50 {
51 auto n = m_jets.size();
52
53 m_valid = k <= n and !jets.empty();
54 if (m_valid) {
55 m_combgen.reset(new CombinationsGenerator(n, k));
56 auto indices = m_combgen->get();
57 m_data.clear();
58 for (const auto i : indices) {m_data.push_back(m_jets.at(i));}
59 }
60 }
61
62 virtual std::vector<std::size_t> get() override {
63
64
65 auto result = m_neigh ? m_neigh->get() : std::vector<std::size_t>();
66 result.insert(result.end(), m_data.begin(), m_data.end());
67 return result;
68 }
69
70
71 virtual bool bump() override {
72
73 // if there is a neighor, bump it. If it returns
74 // true, it has cycled, in which case try bumping this stream
75
76 bool cycled{false};
77 if (m_neigh) {
78 bool neigh_cycled = m_neigh->bump();
79 if (!neigh_cycled) {return false;}
80
81 cycled = m_combgen->bump();
82
83 auto indices = m_combgen->get();
84 m_data.clear();
85 for (const auto i : indices) {m_data.push_back(m_jets.at(i));}
86 return cycled;
87 } else {
88 // no neighbor
89 cycled = m_combgen->bump();
90
91 auto indices = m_combgen->get();
92 m_data.clear();
93 for (const auto& i : indices) {
94 m_data.push_back(m_jets.at(i));
95 }
96 return cycled;
97 }
98 }
99
100
101 virtual bool valid() const override {
102 if (!m_valid){return false;}
103
104 if (m_neigh) {return m_neigh->valid();}
105 return true;
106 }
107
108 virtual std::string dump() const override {
109
110 auto result = m_neigh ? m_neigh->dump() : "";
111
112 std::stringstream ss;
113 ss << *this;
114 result += ss.str();
115
116 return result;
117 }
118
119private:
120 std::vector<std::size_t> m_jets;
121 std::unique_ptr<IJetStream> m_neigh{nullptr};
122 std::size_t m_id;
123 std::vector<std::size_t> m_data;
124 std::unique_ptr<CombinationsGenerator> m_combgen{nullptr};
125 bool m_valid{false};
126
127
128
129 bool empty() const {
130 return m_jets.empty();
131 }
132
133 };
134
135std::ostream& operator << (std::ostream&,
136 const CombinationsJetStream&);
137
138std::stringstream& operator << (std::stringstream&,
139 const CombinationsJetStream&);
140
141 #endif
std::ostream & operator<<(std::ostream &, const CombinationsJetStream &)
static Double_t ss
generate all possible combinations of objects
std::vector< std::size_t > m_jets
virtual bool valid() const override
virtual bool bump() override
std::vector< std::size_t > m_data
virtual std::string dump() const override
std::unique_ptr< CombinationsGenerator > m_combgen
virtual std::vector< std::size_t > get() override
friend std::ostream & operator<<(std::ostream &, const CombinationsJetStream &)
std::unique_ptr< IJetStream > m_neigh
CombinationsJetStream(const std::vector< std::size_t > &jets, std::unique_ptr< IJetStream > neigh, std::size_t k, std::size_t id)
STL namespace.