DD4hep  1.30.0
Detector Description Toolkit for High Energy Physics
ConditionsSelectors.h
Go to the documentation of this file.
1 //==========================================================================
2 // AIDA Detector description implementation
3 //--------------------------------------------------------------------------
4 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
5 // All rights reserved.
6 //
7 // For the licensing terms see $DD4hepINSTALL/LICENSE.
8 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
9 //
10 // Author : M.Frank
11 //
12 //==========================================================================
13 #ifndef DDCOND_CONDITIONSSELECTORS_H
14 #define DDCOND_CONDITIONSSELECTORS_H
15 
16 // Framework include files
17 #include "DD4hep/Conditions.h"
19 
21 namespace dd4hep {
22 
24  namespace cond {
25 
27  namespace Operators {
28 
30 
35  class Cond__Oper {
36  public:
37  typedef Condition cond_t;
39  typedef std::pair<const Condition::key_type,Condition> mapentry_t;
40  typedef std::pair<const Condition::key_type,object_t*> ptr_mapentry_t;
41  };
42 
44 
49  template <typename T> struct SequenceSelect : public Cond__Oper {
50  T& mapping;
51  SequenceSelect(T& o) : mapping(o) { }
53  { mapping.emplace(mapping.end(), o); return true; }
54  };
55 
57 
62  template <typename T> struct MapSelect : public Cond__Oper {
63  T& mapping;
64  MapSelect(T& o) : mapping(o) { }
66  { return mapping.emplace(o->hash,o).second; }
67  };
68 
70 
75  template <typename T> struct MapConditionsSelect : public ConditionsSelect {
76  T& mapping;
78  virtual bool operator()(Condition::Object* o) const
79  { return mapping.emplace(o->hash,o).second; }
80  virtual size_t size() const { return mapping.size(); }
81  };
82 
84 
89  template <typename T> struct PoolSelect : public Cond__Oper {
90  T& pool;
91  PoolSelect(T& o) : pool(o) { }
92  bool operator()(Condition::Object* o) const { return pool.insert(o); }
93  };
94 
96 
101  template <typename T> struct PoolRemove : public Cond__Oper {
102  T& pool;
103  PoolRemove(T& o) : pool(o) { }
104  bool operator()(object_t* o) const { pool.onRemove(o); delete(o); return true; }
105  };
106 
108 
113  template <typename T> struct ActiveSelect : public Cond__Oper {
114  public:
116  ActiveSelect(T& p) : collection(p) {}
117  bool operator()(object_t* o) const {
118  if ( (o->flags & Condition::ACTIVE) ) {
119  collection.emplace(collection.end(),o);
120  return true;
121  }
122  return false;
123  }
124  };
125 
127 
132  template<typename collection_type> class KeyedSelect : public Cond__Oper {
134  collection_type& collection;
135  public:
136  KeyedSelect(cond_t::key_type k, collection_type& p) : key(k), collection(p) { }
137  bool operator()(object_t* o) const {
138  if ( o->hash == key ) {
139  collection.emplace(collection.end(),o);
140  return true;
141  }
142  return false;
143  }
144  };
145 
147 
152  class KeyFind : public Cond__Oper {
154  public:
156  bool operator()(const object_t* o) const { return o->hash == hash; }
157  };
158 
160 
165  template <typename OPER> class OperatorWrapper : public Cond__Oper {
166  public:
167  typedef OPER operator_t;
170  public:
172  bool operator()(object_t* o) const { return oper(o); }
173  bool operator()(const cond_t& o) const { return oper(o.ptr()); }
174  bool operator()(const mapentry_t& o) const { return oper(o.second.ptr()); }
175  bool operator()(const ptr_mapentry_t& o) const { return oper(o.second); }
176  };
177 
179 
184  template <typename OPER> class ConditionsOperation : public Cond__Oper {
185  public:
186  typedef OPER operator_t;
189  public:
191  bool operator()(object_t* o) const { return oper(o); }
192  bool operator()(const cond_t& o) const { return oper(o.ptr()); }
193  bool operator()(const mapentry_t& o) const { return oper(o.second.ptr()); }
194  bool operator()(const ptr_mapentry_t& o) const { return oper(o.second); }
195  };
196 
198 
203  template <typename oper_type> OperatorWrapper<oper_type> operatorWrapper(oper_type& oper) {
204  return OperatorWrapper<oper_type>(oper);
205  }
206 
208 
213  template <typename P> inline ConditionsOperation<PoolRemove<P> > poolRemove(P& pool)
214  { return ConditionsOperation<PoolRemove<P> >(PoolRemove<P>(pool)); }
215 
217 
222  template <typename P> inline ConditionsOperation<PoolSelect<P> > poolSelect(P& pool)
223  { return ConditionsOperation<PoolSelect<P> >(PoolSelect<P>(pool)); }
224 
226 
231  template <typename T> inline MapConditionsSelect<T> mapConditionsSelect(T& collection)
232  { return MapConditionsSelect<T>(collection); }
233 
235 
240  template <typename C> inline
241  ConditionsOperation<SequenceSelect<C> > sequenceSelect(C& coll) {
242  typedef SequenceSelect<C> operator_t;
243  return ConditionsOperation<operator_t>(operator_t(coll));
244  }
245 
247 
252  template <typename C> inline
253  ConditionsOperation<SequenceSelect<C> > mapSelect(C& coll) {
254  typedef MapSelect<C> operator_t;
255  return ConditionsOperation<operator_t>(operator_t(coll));
256  }
257 
259 
264  template <typename C> inline ConditionsOperation<ActiveSelect<C> > activeSelect(C& coll)
265  { return ConditionsOperation<ActiveSelect<C> >(ActiveSelect<C>(coll)); }
266 
268 
273  template <typename C> inline
274  ConditionsOperation<KeyedSelect<C> > keyedSelect(Condition::key_type key, C& coll)
275  { return ConditionsOperation<KeyedSelect<C> >(KeyedSelect<C>(key, coll)); }
276 
278 
283  ConditionsOperation<KeyFind> inline keyFind(Condition::key_type key)
284  { return ConditionsOperation<KeyFind>(KeyFind(key)); }
285 
286  } /* End namespace Operators */
287  } /* End namespace cond */
288 } /* End namespace dd4hep */
289 #endif // DDCOND_CONDITIONSSELECTORS_H
dd4hep::cond::Operators::MapSelect
Mapped container selection operator for conditions mappings.
Definition: ConditionsSelectors.h:62
dd4hep::cond::Operators::KeyedSelect::KeyedSelect
KeyedSelect(cond_t::key_type k, collection_type &p)
Definition: ConditionsSelectors.h:136
dd4hep::cond::Operators::keyedSelect
ConditionsOperation< KeyedSelect< C > > keyedSelect(Condition::key_type key, C &coll)
Helper to create functor to select keyed objects from a conditions pool.
Definition: ConditionsSelectors.h:274
dd4hep::cond::Operators::SequenceSelect::SequenceSelect
SequenceSelect(T &o)
Definition: ConditionsSelectors.h:51
cond
AlignmentCondition::Object * cond
Definition: AlignmentsCalculator.cpp:68
dd4hep::cond::Operators::OperatorWrapper::operator()
bool operator()(const mapentry_t &o) const
Definition: ConditionsSelectors.h:174
dd4hep::cond::Operators::PoolSelect::operator()
bool operator()(Condition::Object *o) const
Definition: ConditionsSelectors.h:92
dd4hep::cond::Operators::OperatorWrapper::operator()
bool operator()(const ptr_mapentry_t &o) const
Definition: ConditionsSelectors.h:175
dd4hep::cond::Operators::MapConditionsSelect::mapping
T & mapping
Definition: ConditionsSelectors.h:76
dd4hep::cond::Operators::ConditionsOperation::operator()
bool operator()(const cond_t &o) const
Definition: ConditionsSelectors.h:192
dd4hep::cond::Operators::ConditionsOperation::operator_t
OPER operator_t
Definition: ConditionsSelectors.h:186
dd4hep::cond::Operators::keyFind
ConditionsOperation< KeyFind > keyFind(Condition::key_type key)
Helper to create functor to find conditions objects by hash key.
Definition: ConditionsSelectors.h:283
dd4hep::detail::ConditionObject::hash
Condition::key_type hash
Hash value of the name.
Definition: ConditionsInterna.h:85
dd4hep::cond::Operators::operatorWrapper
OperatorWrapper< oper_type > operatorWrapper(oper_type &oper)
Helper function to create a OperatorWrapper<T> object from the argument type.
Definition: ConditionsSelectors.h:203
ConditionsInterna.h
dd4hep::cond::Operators::OperatorWrapper::oper
operator_t& oper
Definition: ConditionsSelectors.h:169
dd4hep::cond::Operators::PoolRemove::PoolRemove
PoolRemove(T &o)
Definition: ConditionsSelectors.h:103
dd4hep::cond::Operators::PoolRemove::pool
T & pool
Definition: ConditionsSelectors.h:102
dd4hep::cond::Operators::KeyFind::operator()
bool operator()(const object_t *o) const
Definition: ConditionsSelectors.h:156
dd4hep::cond::Operators::poolRemove
ConditionsOperation< PoolRemove< P > > poolRemove(P &pool)
Helper to create functor to remove objects from a conditions pool.
Definition: ConditionsSelectors.h:213
dd4hep::detail::ConditionObject::flags
Condition::mask_type flags
Flags.
Definition: ConditionsInterna.h:87
dd4hep::cond::Operators::KeyedSelect::operator()
bool operator()(object_t *o) const
Definition: ConditionsSelectors.h:137
dd4hep::cond::Operators::Cond__Oper::mapentry_t
std::pair< const Condition::key_type, Condition > mapentry_t
Definition: ConditionsSelectors.h:39
dd4hep::ConditionsSelect
Conditions selector functor. Default implementation selects everything evaluated.
Definition: Conditions.h:422
dd4hep::cond::Operators::KeyFind
Helper to select condition objects by hash key from a conditions pool.
Definition: ConditionsSelectors.h:152
dd4hep::cond::Operators::ConditionsOperation::oper
operator_t oper
Definition: ConditionsSelectors.h:188
dd4hep::cond::Operators::OperatorWrapper::operator_t
OPER operator_t
Definition: ConditionsSelectors.h:167
dd4hep::cond::Operators::KeyFind::KeyFind
KeyFind(cond_t::key_type h)
Definition: ConditionsSelectors.h:155
dd4hep::cond::Operators::PoolSelect
Helper to insert objects into a conditions pool.
Definition: ConditionsSelectors.h:89
dd4hep::Condition
Main condition object handle.
Definition: Conditions.h:51
dd4hep::cond::Operators::MapSelect::MapSelect
MapSelect(T &o)
Definition: ConditionsSelectors.h:64
dd4hep::cond::Operators::PoolRemove::operator()
bool operator()(object_t *o) const
Definition: ConditionsSelectors.h:104
dd4hep::cond::Operators::ConditionsOperation::ConditionsOperation
ConditionsOperation(const operator_t&o)
Definition: ConditionsSelectors.h:190
dd4hep::cond::Operators::sequenceSelect
ConditionsOperation< SequenceSelect< C > > sequenceSelect(C &coll)
Helper to create functor to select objects from a conditions pool into a sequential container.
Definition: ConditionsSelectors.h:241
dd4hep::cond::Operators::ConditionsOperation
Arbitrary wrapper for user defined conditions operators.
Definition: ConditionsSelectors.h:184
dd4hep::cond::Operators::OperatorWrapper
Helper to wrap another object and make it copyable.
Definition: ConditionsSelectors.h:165
dd4hep::cond::Operators::MapSelect::mapping
T & mapping
Definition: ConditionsSelectors.h:63
dd4hep::cond::Operators::PoolSelect::pool
T & pool
Definition: ConditionsSelectors.h:90
dd4hep::cond::Operators::MapConditionsSelect::operator()
virtual bool operator()(Condition::Object *o) const
Overloadable entry: Selection callback: return true if the condition should be selected.
Definition: ConditionsSelectors.h:78
dd4hep::cond::Operators::PoolSelect::PoolSelect
PoolSelect(T &o)
Definition: ConditionsSelectors.h:91
dd4hep::cond::Operators::Cond__Oper
Definition of the selector object base class to cover type definitions.
Definition: ConditionsSelectors.h:35
dd4hep::cond::Operators::SequenceSelect::operator()
bool operator()(Condition::Object *o) const
Definition: ConditionsSelectors.h:52
Conditions.h
dd4hep::cond::Operators::MapConditionsSelect::size
virtual size_t size() const
Overloadable entry: Return number of conditions selected. Default does nothing....
Definition: ConditionsSelectors.h:80
dd4hep::Condition::key_type
unsigned long long int key_type
Forward definition of the key type.
Definition: Conditions.h:54
dd4hep::detail::ConditionObject
The data class behind a conditions handle.
Definition: ConditionsInterna.h:68
dd4hep::cond::Operators::SequenceSelect
Sequential container select operator for conditions mappings.
Definition: ConditionsSelectors.h:49
dd4hep::cond::Operators::ConditionsOperation::operator()
bool operator()(const ptr_mapentry_t &o) const
Definition: ConditionsSelectors.h:194
dd4hep::cond::Operators::ActiveSelect::operator()
bool operator()(object_t *o) const
Definition: ConditionsSelectors.h:117
dd4hep::cond::Operators::mapConditionsSelect
MapConditionsSelect< T > mapConditionsSelect(T &collection)
Helper to create functor to collect conditions using a ConditionsSelect base class.
Definition: ConditionsSelectors.h:231
dd4hep::cond::Operators::MapSelect::operator()
bool operator()(Condition::Object *o) const
Definition: ConditionsSelectors.h:65
dd4hep::cond::Operators::ActiveSelect
Container select operator for conditions mappings with conditions flagged active.
Definition: ConditionsSelectors.h:113
key
unsigned char key
Definition: AlignmentsCalculator.cpp:69
dd4hep::cond::Operators::OperatorWrapper::operator()
bool operator()(const cond_t &o) const
Definition: ConditionsSelectors.h:173
dd4hep::cond::Operators::mapSelect
ConditionsOperation< SequenceSelect< C > > mapSelect(C &coll)
Helper to create functor to select objects from a conditions pool into a mapped container.
Definition: ConditionsSelectors.h:253
dd4hep::cond::Operators::ConditionsOperation::operator()
bool operator()(const mapentry_t &o) const
Definition: ConditionsSelectors.h:193
dd4hep::Handle::ptr
T * ptr() const
Access to the held object.
Definition: Handle.h:153
dd4hep::cond::Operators::PoolRemove
Helper to remove objects from a conditions pool. The removed condition is deleted.
Definition: ConditionsSelectors.h:101
dd4hep::cond::Operators::Cond__Oper::object_t
Condition::Object object_t
Definition: ConditionsSelectors.h:38
dd4hep::cond::Operators::KeyedSelect
Helper to select keyed objects from a conditions pool.
Definition: ConditionsSelectors.h:132
dd4hep::cond::Operators::OperatorWrapper::wrapper_t
OperatorWrapper< operator_t> wrapper_t
Definition: ConditionsSelectors.h:168
dd4hep
Namespace for the AIDA detector description toolkit.
Definition: AlignmentsCalib.h:28
dd4hep::cond::Operators::ConditionsOperation::operator()
bool operator()(object_t *o) const
Definition: ConditionsSelectors.h:191
dd4hep::cond::Operators
Helper class for common stuff used frequently.
Definition: ConditionsOperators.h:31
dd4hep::cond::Operators::OperatorWrapper::operator()
bool operator()(object_t *o) const
Definition: ConditionsSelectors.h:172
dd4hep::cond::Operators::poolSelect
ConditionsOperation< PoolSelect< P > > poolSelect(P &pool)
Helper to create functor to insert objects into a conditions pool.
Definition: ConditionsSelectors.h:222
dd4hep::cond::Operators::KeyedSelect::collection
collection_type & collection
Definition: ConditionsSelectors.h:134
dd4hep::Condition::ACTIVE
@ ACTIVE
Definition: Conditions.h:77
dd4hep::cond::Operators::ConditionsOperation::wrapper_t
ConditionsOperation< operator_t> wrapper_t
Definition: ConditionsSelectors.h:187
dd4hep::cond::Operators::MapConditionsSelect::MapConditionsSelect
MapConditionsSelect(T &o)
Definition: ConditionsSelectors.h:77
dd4hep::cond::Operators::activeSelect
ConditionsOperation< ActiveSelect< C > > activeSelect(C &coll)
Helper to select active objects from a conditions pool.
Definition: ConditionsSelectors.h:264
dd4hep::cond::Operators::Cond__Oper::cond_t
Condition cond_t
Definition: ConditionsSelectors.h:37
dd4hep::cond::Operators::KeyedSelect::key
cond_t::key_type key
Definition: ConditionsSelectors.h:133
dd4hep::cond::Operators::ActiveSelect::collection
T & collection
Definition: ConditionsSelectors.h:115
dd4hep::cond::Operators::Cond__Oper::ptr_mapentry_t
std::pair< const Condition::key_type, object_t * > ptr_mapentry_t
Definition: ConditionsSelectors.h:40
dd4hep::cond::Operators::ActiveSelect::ActiveSelect
ActiveSelect(T &p)
Definition: ConditionsSelectors.h:116
dd4hep::cond::Operators::KeyFind::hash
cond_t::key_type hash
Definition: ConditionsSelectors.h:153
dd4hep::cond::Operators::OperatorWrapper::OperatorWrapper
OperatorWrapper(operator_t&o)
Definition: ConditionsSelectors.h:171
dd4hep::cond::Operators::SequenceSelect::mapping
T & mapping
Definition: ConditionsSelectors.h:50
dd4hep::cond::Operators::MapConditionsSelect
Helper to collect conditions using a ConditionsSelect base class.
Definition: ConditionsSelectors.h:75