ATLAS Offline Software
Loading...
Searching...
No Matches
SimpleJetStream.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
5#ifndef TRIGHLTJETHYPO_SIMPLEJETSTREAM_H
6#define TRIGHLTJETHYPO_SIMPLEJETSTREAM_H
7
8
9/*
10 * SimpleJetStream is an implementation of IJetStream.
11
12 * On each call to bump(), it steps through its container of jet indices,
13 * making the current value
14 * available for collection. When it reaches the end, and moves
15 * back to the begining of its list. bump() returns the true when it has
16 * cycled, otherwise it returns false
17 *
18 */
19
20#include "IJetStream.h"
21#include <sstream>
22#include <vector>
23#include <memory>
24#include <string>
25
27
28 public:
29
30
31 friend std::ostream& operator << (std::ostream&,
32 const SimpleJetStream&);
33
34
35 SimpleJetStream(const std::vector<std::size_t>& jets,
36 std::unique_ptr<IJetStream> neigh,
37 std::size_t id):
38 m_jets(jets),
39 m_neigh(std::move(neigh)),
40 m_id{id}
41 {
42 m_valid = !jets.empty();
43 if(m_valid) {
44 m_data = m_jets.at(0);
45 m_ind = 0;
46 }
47 }
48
49
50 virtual std::vector<std::size_t> get() override {
51 auto result = m_neigh ? m_neigh->get() : std::vector<std::size_t>();
52 result.push_back(m_data);
53 return result;
54 }
55
56 virtual bool bump() override {
57 // if there is a neighbor, try bumping it.
58 bool cycled{false};
59 if (m_neigh) {
60 bool neigh_cycled = m_neigh->bump();
61
62 if (!neigh_cycled) {return false;}
63
64 // neighbor has cycled as a result of bumping.
65 ++m_ind;
66 cycled = m_ind == m_jets.size();
67
68 if (cycled) {m_ind = 0;}
69
70 m_data = m_jets.at(m_ind);
71 return cycled;
72 } else {
73
74 // no neighbor
75
76 ++m_ind;
77
78 cycled = m_ind == m_jets.size();
79
80 if(cycled) {
81 m_ind = 0;
82 }
83 m_data = m_jets.at(m_ind);
84 return cycled;
85 }
86 }
87
88
89
90 virtual bool valid() const override {
91 if (!m_valid) {return false;}
92
93 if (m_neigh) {return m_neigh->valid();}
94 return true;
95 }
96
97 virtual std::string dump() const override {
98 std::ostringstream ss;
99 auto result = m_neigh ? m_neigh->dump() : "";
100 ss<< *this << '\n';
101 result += ss.str();
102 return result;
103 }
104
105private:
106 std::vector<std::size_t> m_jets;
107 std::size_t m_ind{0};
108 std::unique_ptr<IJetStream> m_neigh{nullptr};
109 std::size_t m_id{};
110 std::size_t m_data{};
111 bool m_valid{false};
112
113};
114
115std::ostream& operator << (std::ostream& os ,
116 const SimpleJetStream& js);
117
118
119#endif
static Double_t ss
std::ostream & operator<<(std::ostream &os, const SimpleJetStream &js)
std::vector< std::size_t > m_jets
virtual std::vector< std::size_t > get() override
SimpleJetStream(const std::vector< std::size_t > &jets, std::unique_ptr< IJetStream > neigh, std::size_t id)
std::unique_ptr< IJetStream > m_neigh
virtual bool valid() const override
virtual bool bump() override
friend std::ostream & operator<<(std::ostream &, const SimpleJetStream &)
virtual std::string dump() const override
STL namespace.