ATLAS Offline Software
SimpleJetStream.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_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 <vector>
22 #include <sstream>
23 #include <memory>
24 #include <string>
25 
26 class SimpleJetStream: public IJetStream {
27 
28  public:
29 
30 
31  friend std::ostream& operator << (std::ostream&,
32  const SimpleJetStream&);
33  friend std::stringstream& operator << (std::stringstream&,
34  const SimpleJetStream&);
35 
36  SimpleJetStream(const std::vector<std::size_t>& jets,
37  std::unique_ptr<IJetStream> neigh,
38  std::size_t id):
39  m_jets(jets),
40  m_neigh(std::move(neigh)),
41  m_id{id}
42  {
43  m_valid = !jets.empty();
44  if(m_valid) {
45  m_data = m_jets.at(0);
46  m_ind = 0;
47  }
48  }
49 
50 
51  virtual std::vector<std::size_t> get() override {
52 
53  auto result = m_neigh ? m_neigh->get() : std::vector<std::size_t>();
54  result.push_back(m_data);
55 
56  return result;
57  }
58 
59  virtual bool bump() override {
60  // if there is a neighbor, try bumping it.
61  bool cycled{false};
62  if (m_neigh) {
63  bool neigh_cycled = m_neigh->bump();
64 
65  if (!neigh_cycled) {return false;}
66 
67  // neighbor has cycled as a result of bumping.
68  ++m_ind;
69  cycled = m_ind == m_jets.size();
70 
71  if (cycled) {m_ind = 0;}
72 
73  m_data = m_jets.at(m_ind);
74  return cycled;
75  } else {
76 
77  // no neighbor
78 
79  ++m_ind;
80 
81  cycled = m_ind == m_jets.size();
82 
83  if(cycled) {
84  m_ind = 0;
85  }
86  m_data = m_jets.at(m_ind);
87  return cycled;
88  }
89  }
90 
91 
92 
93  virtual bool valid() const override {
94  if (!m_valid) {return false;}
95 
96  if (m_neigh) {return m_neigh->valid();}
97  return true;
98  }
99 
100  virtual std::string dump() const override {
101  std::stringstream ss;
102 
103  auto result = m_neigh ? m_neigh->dump() : "";
104 
105  ss<< *this << '\n';
106  result += ss.str();
107 
108  return result;
109  }
110 
111 private:
112  std::vector<std::size_t> m_jets;
113  std::size_t m_ind{0};
114  std::unique_ptr<IJetStream> m_neigh{nullptr};
115  std::size_t m_id;
116  std::size_t m_data;
117  bool m_valid{false};
118 
119 };
120 
121 std::ostream& operator << (std::ostream& os ,
122  const SimpleJetStream& js);
123 std::stringstream& operator << (std::stringstream& os ,
124  const SimpleJetStream& js);
125 
126 #endif
get_generator_info.result
result
Definition: get_generator_info.py:21
PowhegControl_ttHplus_NLO.ss
ss
Definition: PowhegControl_ttHplus_NLO.py:83
SimpleJetStream::m_jets
std::vector< std::size_t > m_jets
Definition: SimpleJetStream.h:112
operator<<
std::ostream & operator<<(std::ostream &os, const SimpleJetStream &js)
Definition: SimpleJetStream.cxx:7
SimpleJetStream::m_id
std::size_t m_id
Definition: SimpleJetStream.h:115
SimpleJetStream::m_data
std::size_t m_data
Definition: SimpleJetStream.h:116
SimpleJetStream::m_valid
bool m_valid
Definition: SimpleJetStream.h:117
IJetStream.h
ReadFromCoolCompare.os
os
Definition: ReadFromCoolCompare.py:231
IJetStream
Definition: IJetStream.h:31
SimpleJetStream::get
virtual std::vector< std::size_t > get() override
Definition: SimpleJetStream.h:51
SimpleJetStream::m_neigh
std::unique_ptr< IJetStream > m_neigh
Definition: SimpleJetStream.h:114
SimpleJetStream::SimpleJetStream
SimpleJetStream(const std::vector< std::size_t > &jets, std::unique_ptr< IJetStream > neigh, std::size_t id)
Definition: SimpleJetStream.h:36
SimpleJetStream::m_ind
std::size_t m_ind
Definition: SimpleJetStream.h:113
SimpleJetStream::operator<<
friend std::ostream & operator<<(std::ostream &, const SimpleJetStream &)
Definition: SimpleJetStream.cxx:7
SimpleJetStream
Definition: SimpleJetStream.h:26
SimpleJetStream::valid
virtual bool valid() const override
Definition: SimpleJetStream.h:93
defineDB.jets
list jets
Definition: JetTagCalibration/share/defineDB.py:24
SimpleJetStream::dump
virtual std::string dump() const override
Definition: SimpleJetStream.h:100
SimpleJetStream::bump
virtual bool bump() override
Definition: SimpleJetStream.h:59