CMS 3D CMS Logo

List of all members | Classes | Public Member Functions | Private Types | Private Member Functions | Private Attributes
pat::eventhypothesis::Looper< T > Class Template Reference

#include <EventHypothesis.h>

Classes

struct  null_deleter
 

Public Member Functions

const reco::Candidatecand () const
 C++ reference to pointed particle. More...
 
const Tget () const
 Accessor as if it was a smart pointer to const T *. More...
 
size_t globalIndex ()
 Index of this item in the full EventHypothesis. More...
 
size_t index () const
 Index of this item among those in the loop. More...
 
bool isTypeOk () const
 test if the type is correct More...
 
 Looper (const EventHypothesis &eh, const ParticleFilter &filter)
 
 Looper (const EventHypothesis &eh, const ParticleFilter *filter)
 
 Looper (const EventHypothesis &eh, const ParticleFilterPtr &filter)
 
 operator bool () const
 
template<typename T2 >
bool operator!= (const Looper< T2 > &other) const
 
const Toperator* () const
 Accessor as if it was a const_iterator on a list of T. More...
 
Looperoperator++ ()
 iteration More...
 
Looperoperator-- ()
 iteration More...
 
const Toperator-> () const
 Accessor as if it was a const_iterator on a list of T. More...
 
template<typename T2 >
bool operator< (const Looper< T2 > &other) const
 
template<typename T2 >
bool operator<= (const Looper< T2 > &other) const
 
template<typename T2 >
bool operator== (const Looper< T2 > &other) const
 returns true if loopers point to the same record More...
 
template<typename T2 >
bool operator> (const Looper< T2 > &other) const
 
template<typename T2 >
bool operator>= (const Looper< T2 > &other) const
 
const CandRefTyperef () const
 EDM Ref to pointed particle. More...
 
Looperreset (int item=0)
 
const std::string & role () const
 Role of pointed item. More...
 
size_t size () const
 Number of particles in the loop. More...
 
Looperskip (int delta)
 skip (might be slow) More...
 
 ~Looper ()
 

Private Types

typedef EventHypothesis::const_iterator const_iterator
 

Private Member Functions

bool assertOk () const
 
void first ()
 
void realSize () const
 

Private Attributes

const EventHypothesiseh_
 
const ParticleFilterPtr filter_
 
const_iterator iter_
 
int num_
 
DynCastCandPtr< Tptr_
 
int total_
 

Detailed Description

template<typename T>
class pat::eventhypothesis::Looper< T >

Definition at line 17 of file EventHypothesis.h.

Member Typedef Documentation

◆ const_iterator

Definition at line 136 of file EventHypothesisLooper.h.

Constructor & Destructor Documentation

◆ Looper() [1/3]

template<typename T >
pat::eventhypothesis::Looper< T >::Looper ( const EventHypothesis eh,
const ParticleFilter filter 
)

Looper from EventHypothesis and an external, not owned, ParticleFilter. That is: MyFilter flt; Looper(eh, flt);

Definition at line 152 of file EventHypothesisLooper.h.

153  : eh_(eh), filter_(ParticleFilterPtr(&filter, typename Looper<T>::null_deleter())), total_(-1) {
154  first();
155  }

References pat::eventhypothesis::Looper< T >::first().

◆ Looper() [2/3]

template<typename T >
pat::eventhypothesis::Looper< T >::Looper ( const EventHypothesis eh,
const ParticleFilter filter 
)

Looper from EventHypothesis and an internal, owned, ParticleFilter That is: Looper(eh, new MyFilter());

Definition at line 158 of file EventHypothesisLooper.h.

158  : eh_(eh), filter_(filter), total_(-1) {
159  first();
160  }

References pat::eventhypothesis::Looper< T >::first().

◆ Looper() [3/3]

template<typename T >
pat::eventhypothesis::Looper< T >::Looper ( const EventHypothesis eh,
const ParticleFilterPtr filter 
)

Looper from EventHypothesis and a shared ParticleFilter That is: Looper(eh, ParticleFilterPtr(new MyFilter()));

Definition at line 163 of file EventHypothesisLooper.h.

164  : eh_(eh), filter_(filter), total_(-1) {
165  first();
166  }

References pat::eventhypothesis::Looper< T >::first().

◆ ~Looper()

template<typename T>
pat::eventhypothesis::Looper< T >::~Looper ( )
inline

Definition at line 62 of file EventHypothesisLooper.h.

62 {}

Member Function Documentation

◆ assertOk()

template<typename T >
bool pat::eventhypothesis::Looper< T >::assertOk ( ) const
private

Definition at line 169 of file EventHypothesisLooper.h.

169  {
170  assert(iter_ <= eh_.end());
171  assert((iter_ + 1) >= eh_.begin());
172  assert((iter_ < eh_.begin()) || (iter_ == eh_.end()) || ((*filter_)(*iter_)));
173  return true;
174  }

References cms::cuda::assert().

◆ cand()

template<typename T>
const reco::Candidate& pat::eventhypothesis::Looper< T >::cand ( ) const
inline

C++ reference to pointed particle.

Definition at line 79 of file EventHypothesisLooper.h.

79 { return *iter_->second; }

References pat::eventhypothesis::Looper< T >::iter_.

◆ first()

template<typename T >
void pat::eventhypothesis::Looper< T >::first ( )
private

Definition at line 241 of file EventHypothesisLooper.h.

241  {
242  num_ = 0;
243  iter_ = eh_.begin();
244  ptr_.clearCache();
245  for (; iter_ != eh_.end(); ++iter_) {
246  if ((*filter_)(*iter_))
247  break;
248  }
249  assert(assertOk());
250  }

References cms::cuda::assert(), and ptr_.

Referenced by pat::eventhypothesis::Looper< T >::Looper().

◆ get()

template<typename T>
const T* pat::eventhypothesis::Looper< T >::get ( ) const
inline

◆ globalIndex()

template<typename T>
size_t pat::eventhypothesis::Looper< T >::globalIndex ( )
inline

Index of this item in the full EventHypothesis.

Definition at line 82 of file EventHypothesisLooper.h.

82 { return iter_ - eh_.begin(); }

References pat::EventHypothesis::begin(), pat::eventhypothesis::Looper< T >::eh_, and pat::eventhypothesis::Looper< T >::iter_.

◆ index()

template<typename T>
size_t pat::eventhypothesis::Looper< T >::index ( ) const
inline

Index of this item among those in the loop.

Definition at line 84 of file EventHypothesisLooper.h.

84 { return num_; }

References pat::eventhypothesis::Looper< T >::num_.

Referenced by BeautifulSoup.PageElement::insert().

◆ isTypeOk()

template<typename T>
bool pat::eventhypothesis::Looper< T >::isTypeOk ( ) const
inline

test if the type is correct

Definition at line 72 of file EventHypothesisLooper.h.

72 { return ptr_.typeOk(iter_->second.get()); }

References pat::eventhypothesis::Looper< T >::iter_, and pat::eventhypothesis::Looper< T >::ptr_.

◆ operator bool()

template<typename T >
pat::eventhypothesis::Looper< T >::operator bool ( ) const

Returns true if you have not run out of the boundaries. It does NOT check if typeOk()

Definition at line 253 of file EventHypothesisLooper.h.

253  {
254  return (iter_ < eh_.end()) && (iter_ >= eh_.begin());
255  }

◆ operator!=()

template<typename T>
template<typename T2 >
bool pat::eventhypothesis::Looper< T >::operator!= ( const Looper< T2 > &  other) const
inline

Definition at line 112 of file EventHypothesisLooper.h.

112  {
113  return iter_ != other.iter_;
114  }

References pat::eventhypothesis::Looper< T >::iter_, and trackingPlots::other.

◆ operator*()

template<typename T>
const T& pat::eventhypothesis::Looper< T >::operator* ( void  ) const
inline

Accessor as if it was a const_iterator on a list of T.

Definition at line 65 of file EventHypothesisLooper.h.

65 { return ptr_.get(iter_->second.get()); }

References pat::eventhypothesis::Looper< T >::iter_, and pat::eventhypothesis::Looper< T >::ptr_.

◆ operator++()

template<typename T >
Looper< T > & pat::eventhypothesis::Looper< T >::operator++ ( void  )

iteration

Definition at line 177 of file EventHypothesisLooper.h.

177  {
178  ptr_.clearCache();
179  assert(assertOk());
180  if (iter_ == eh_.end())
181  return *this;
182  do {
183  ++iter_;
184  if (iter_ == eh_.end())
185  break;
186  if ((*filter_)(*iter_)) {
187  assert(assertOk());
188  ++num_;
189  return *this;
190  }
191  } while (true);
192  assert(assertOk());
193  return *this;
194  }

References cms::cuda::assert(), and ptr_.

◆ operator--()

template<typename T >
Looper< T > & pat::eventhypothesis::Looper< T >::operator-- ( )

iteration

Definition at line 196 of file EventHypothesisLooper.h.

196  {
197  ptr_.clearCache();
198  assert(assertOk());
199  if (num_ < 0)
200  return *this;
201  do {
202  --iter_;
203  if (iter_ < eh_.begin()) {
204  num_ = -1;
205  break;
206  }
207  if ((*filter_)(*iter_)) {
208  assert(assertOk());
209  --num_;
210  return *this;
211  }
212  } while (true);
213  assert(assertOk());
214  return *this;
215  }

References cms::cuda::assert(), and ptr_.

◆ operator->()

template<typename T>
const T* pat::eventhypothesis::Looper< T >::operator-> ( ) const
inline

Accessor as if it was a const_iterator on a list of T.

Definition at line 67 of file EventHypothesisLooper.h.

67 { return ptr_.get(iter_->second.get()); }

References pat::eventhypothesis::Looper< T >::iter_, and pat::eventhypothesis::Looper< T >::ptr_.

◆ operator<()

template<typename T>
template<typename T2 >
bool pat::eventhypothesis::Looper< T >::operator< ( const Looper< T2 > &  other) const
inline

Definition at line 124 of file EventHypothesisLooper.h.

124  {
125  return iter_ < other.iter_;
126  }

References pat::eventhypothesis::Looper< T >::iter_, and trackingPlots::other.

◆ operator<=()

template<typename T>
template<typename T2 >
bool pat::eventhypothesis::Looper< T >::operator<= ( const Looper< T2 > &  other) const
inline

Definition at line 116 of file EventHypothesisLooper.h.

116  {
117  return iter_ <= other.iter_;
118  }

References pat::eventhypothesis::Looper< T >::iter_, and trackingPlots::other.

◆ operator==()

template<typename T>
template<typename T2 >
bool pat::eventhypothesis::Looper< T >::operator== ( const Looper< T2 > &  other) const
inline

returns true if loopers point to the same record

Definition at line 108 of file EventHypothesisLooper.h.

108  {
109  return iter_ == other.iter_;
110  }

References pat::eventhypothesis::Looper< T >::iter_, and trackingPlots::other.

◆ operator>()

template<typename T>
template<typename T2 >
bool pat::eventhypothesis::Looper< T >::operator> ( const Looper< T2 > &  other) const
inline

Definition at line 128 of file EventHypothesisLooper.h.

128  {
129  return iter_ > other.iter_;
130  }

References pat::eventhypothesis::Looper< T >::iter_, and trackingPlots::other.

◆ operator>=()

template<typename T>
template<typename T2 >
bool pat::eventhypothesis::Looper< T >::operator>= ( const Looper< T2 > &  other) const
inline

Definition at line 120 of file EventHypothesisLooper.h.

120  {
121  return iter_ >= other.iter_;
122  }

References pat::eventhypothesis::Looper< T >::iter_, and trackingPlots::other.

◆ realSize()

template<typename T >
void pat::eventhypothesis::Looper< T >::realSize ( ) const
private

Definition at line 258 of file EventHypothesisLooper.h.

258  {
260  if (it < eh_.begin()) {
261  it = eh_.begin();
262  total_ = 0;
263  } else {
264  total_ = num_;
265  }
266  for (; it != eh_.end(); ++it) {
267  if ((*filter_)(*it))
268  ++total_;
269  }
270  }

Referenced by pat::eventhypothesis::Looper< T >::size().

◆ ref()

template<typename T>
const CandRefType& pat::eventhypothesis::Looper< T >::ref ( ) const
inline

EDM Ref to pointed particle.

Definition at line 77 of file EventHypothesisLooper.h.

77 { return iter_->second; }

References pat::eventhypothesis::Looper< T >::iter_.

◆ reset()

template<typename T >
Looper< T > & pat::eventhypothesis::Looper< T >::reset ( int  item = 0)

Reset to the start or to any other specific item; negatives count from the end. might be slow, especially with negative items

Definition at line 226 of file EventHypothesisLooper.h.

226  {
227  assert(assertOk());
228  if (item >= 0) {
229  first();
230  std::advance(this, item);
231  } else {
232  num_ = item + 1;
233  iter_ = eh_.end();
234  std::advance(this, item);
235  }
236  assert(assertOk());
237  return *this;
238  }

References cms::cuda::assert(), dqmdumpme::first, and B2GTnPMonitor_cfi::item.

◆ role()

template<typename T>
const std::string& pat::eventhypothesis::Looper< T >::role ( ) const
inline

Role of pointed item.

Definition at line 75 of file EventHypothesisLooper.h.

75 { return iter_->first; }

References pat::eventhypothesis::Looper< T >::iter_.

◆ size()

template<typename T>
size_t pat::eventhypothesis::Looper< T >::size ( void  ) const
inline

Number of particles in the loop.

Definition at line 86 of file EventHypothesisLooper.h.

86  {
87  if (total_ < 0)
88  realSize();
89  return total_;
90  }

References pat::eventhypothesis::Looper< T >::realSize(), and pat::eventhypothesis::Looper< T >::total_.

Referenced by ntupleDataFormat._Collection::__iter__(), and ntupleDataFormat._Collection::__len__().

◆ skip()

template<typename T >
Looper< T > & pat::eventhypothesis::Looper< T >::skip ( int  delta)

skip (might be slow)

Definition at line 218 of file EventHypothesisLooper.h.

218  {
219  assert(assertOk());
220  std::advance(this, delta);
221  assert(assertOk());
222  return *this;
223  }

References cms::cuda::assert(), and dumpMFGeometry_cfg::delta.

Member Data Documentation

◆ eh_

template<typename T>
const EventHypothesis& pat::eventhypothesis::Looper< T >::eh_
private

◆ filter_

template<typename T>
const ParticleFilterPtr pat::eventhypothesis::Looper< T >::filter_
private

Definition at line 143 of file EventHypothesisLooper.h.

◆ iter_

template<typename T>
const_iterator pat::eventhypothesis::Looper< T >::iter_
private

◆ num_

template<typename T>
int pat::eventhypothesis::Looper< T >::num_
private

Definition at line 145 of file EventHypothesisLooper.h.

Referenced by pat::eventhypothesis::Looper< T >::index().

◆ ptr_

template<typename T>
DynCastCandPtr<T> pat::eventhypothesis::Looper< T >::ptr_
mutableprivate

◆ total_

template<typename T>
int pat::eventhypothesis::Looper< T >::total_
mutableprivate

Definition at line 146 of file EventHypothesisLooper.h.

Referenced by pat::eventhypothesis::Looper< T >::size().

pat::EventHypothesis::const_iterator
vector_type::const_iterator const_iterator
Definition: EventHypothesis.h:38
pat::EventHypothesis::begin
const_iterator begin() const
Definition: EventHypothesis.h:44
cms::cuda::assert
assert(be >=bs)
pat::eventhypothesis::Looper::realSize
void realSize() const
Definition: EventHypothesisLooper.h:258
pat::eventhypothesis::Looper::ptr_
DynCastCandPtr< T > ptr_
Definition: EventHypothesisLooper.h:147
trackingPlots.other
other
Definition: trackingPlots.py:1465
ALCARECOTkAlBeamHalo_cff.filter
filter
Definition: ALCARECOTkAlBeamHalo_cff.py:27
pat::eventhypothesis::ParticleFilterPtr
std::shared_ptr< const ParticleFilter > ParticleFilterPtr
Definition: EventHypothesis.h:30
dumpMFGeometry_cfg.delta
delta
Definition: dumpMFGeometry_cfg.py:25
pat::eventhypothesis::Looper::total_
int total_
Definition: EventHypothesisLooper.h:146
B2GTnPMonitor_cfi.item
item
Definition: B2GTnPMonitor_cfi.py:147
pat::eventhypothesis::Looper::first
void first()
Definition: EventHypothesisLooper.h:241
pat::eventhypothesis::Looper::filter_
const ParticleFilterPtr filter_
Definition: EventHypothesisLooper.h:143
pat::EventHypothesis::end
const_iterator end() const
Definition: EventHypothesis.h:45
pat::eventhypothesis::Looper::iter_
const_iterator iter_
Definition: EventHypothesisLooper.h:144
pat::eventhypothesis::Looper::assertOk
bool assertOk() const
Definition: EventHypothesisLooper.h:169
pat::eventhypothesis::Looper::eh_
const EventHypothesis & eh_
Definition: EventHypothesisLooper.h:142
pat::eventhypothesis::Looper::num_
int num_
Definition: EventHypothesisLooper.h:145