DD4hep - The AIDA detector description toolkit for high energy physics experiments
DD4hep  Rev:Unversioneddirectory
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ConditionsSelectors.h
Go to the documentation of this file.
1 // $Id$
2 //==========================================================================
3 // AIDA Detector description implementation for LCD
4 //--------------------------------------------------------------------------
5 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
6 // All rights reserved.
7 //
8 // For the licensing terms see $DD4hepINSTALL/LICENSE.
9 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
10 //
11 // Author : M.Frank
12 //
13 //==========================================================================
14 #ifndef DDCOND_CONDITIONSSELECTORS_H
15 #define DDCOND_CONDITIONSSELECTORS_H
16 
17 // Framework include files
19 
21 namespace DD4hep {
22 
24  namespace Conditions {
25 
26  class Cond__Oper {
27  public:
28  typedef Condition cond_t;
30  typedef std::pair<const Condition::key_type,Condition> mapentry_t;
31  typedef std::pair<const Condition::key_type,object_t*> ptr_mapentry_t;
32  };
33 
35 
41  public:
43  void operator()(object_t* o) const { pool.insert(o); }
44  void operator()(const cond_t& o) const { pool.insert(o.ptr()); }
45  void operator()(const mapentry_t& o) const { (*this)(o.second.ptr()); }
46  void operator()(const ptr_mapentry_t& o) const { (*this)(o.second); }
47  };
48 
50 
56  public:
58  void operator()(object_t* o) const {
59  pool.onRemove(o);
60  delete o;
61  }
62  void operator()(const cond_t& o) const { (*this)(o.ptr()); }
63  void operator()(const mapentry_t& o) const { (*this)(o.second.ptr()); }
64  void operator()(const ptr_mapentry_t& o) const { (*this)(o.second); }
65  };
66 
68 
72  template<typename pool_type> class PoolInsert : public Cond__Oper {
73  pool_type& pool;
74  public:
75  PoolInsert(pool_type& p) : pool(p) { }
76  void operator()(object_t* o) const { pool.insert(o); }
77  void operator()(const cond_t& o) const { pool.insert(o.ptr()); }
78  void operator()(const mapentry_t& o) const { (*this)(o.second.ptr()); }
79  void operator()(const ptr_mapentry_t& o) const { (*this)(o.second); }
80  };
81  template <typename pool_type> PoolInsert<pool_type> poolInsert(pool_type& pool) {
82  return PoolInsert<pool_type>(pool);
83  }
84 
86 
90  template<typename collection_type> class CollectionSelect : public Cond__Oper {
91  collection_type& coll;
92  public:
93  CollectionSelect(collection_type& p) : coll(p) { }
94  void operator()(object_t* o) const { coll.insert(coll.end(),o); }
95  void operator()(const cond_t& o) const { coll.insert(coll.end(),o.ptr()); }
96  void operator()(const mapentry_t& o) const { (*this)(o.second.ptr()); }
97  void operator()(const ptr_mapentry_t& o) { (*this)(o.second); }
98  };
99  template <typename collection_type>
101  return CollectionSelect<collection_type>(collection);
102  }
103 
105 
109  template<typename collection_type> class ActiveSelect : public Cond__Oper {
110  collection_type& collection;
111  public:
112  ActiveSelect(collection_type& p) : collection(p) {}
113  void operator()(object_t* o) const {
114  if ( (o->flags & cond_t::ACTIVE) )
115  collection.insert(collection.end(),o);
116  }
117  void operator()(const cond_t& o) const { (*this)(o.ptr()); }
118  void operator()(const mapentry_t& o) const { (*this)(o.second.ptr()); }
119  void operator()(const ptr_mapentry_t& o) const { (*this)(o.second); }
120  };
121  template <typename collection_type>
122  ActiveSelect<collection_type> activeSelect(collection_type& active) {
123  return ActiveSelect<collection_type>(active);
124  }
125 
127 
131  template<typename collection_type> class KeyedSelect : public Cond__Oper {
133  collection_type& collection;
134  public:
135  KeyedSelect(cond_t::key_type k, collection_type& p) : key(k), collection(p) {}
136  void operator()(object_t* o) const {
137  if ( o->hash == key )
138  collection.insert(collection.end(),o);
139  }
140  void operator()(const cond_t& o) const { (*this)(o.ptr()); }
141  void operator()(const mapentry_t& o) const { (*this)(o.second.ptr()); }
142  void operator()(const ptr_mapentry_t& o) const { (*this)(o.second); }
143  };
144  template <typename collection_type>
146  return KeyedSelect<collection_type>(k, keyed);
147  }
148 
150 
154  class HashConditionFind : public Cond__Oper {
156  public:
158  bool operator()(const cond_t& o) const { return o->hash == hash; }
159  bool operator()(const object_t* o) const { return o->hash == hash; }
160  bool operator()(const mapentry_t& o) const { return (*this)(o.second); }
161  bool operator()(const ptr_mapentry_t& o) const { return (*this)(o.second); }
162  };
163 
164  } /* End namespace Conditions */
165 } /* End namespace DD4hep */
166 
167 #endif /* DDCOND_CONDITIONSSELECTORS_H */
KeyedSelect< collection_type > keyedSelect(Condition::key_type k, collection_type &keyed)
void operator()(const ptr_mapentry_t &o) const
void operator()(const mapentry_t &o) const
void operator()(const ptr_mapentry_t &o) const
Helper to select keyed objects from a conditions pool.
CollectionSelect< collection_type > collectionSelect(collection_type &collection)
void operator()(const cond_t &o) const
virtual void insert(Condition cond)=0
Register a new condition to this pool.
void operator()(const mapentry_t &o) const
void operator()(const cond_t &o) const
Helper to select active objects from a conditions pool.
Helper to insert objects into a conditions pool.
void operator()(const cond_t &o) const
void operator()(const cond_t &o) const
The data class behind a conditions handle.
bool operator()(const object_t *o) const
Main condition object handle.
Definition: Conditions.h:70
void operator()(const ptr_mapentry_t &o) const
void operator()(const mapentry_t &o) const
std::pair< const Condition::key_type, object_t * > ptr_mapentry_t
unsigned int key_type
Forward definition of the key type.
Definition: Conditions.h:75
bool operator()(const mapentry_t &o) const
void operator()(object_t *o) const
T * ptr() const
Access to the held object.
Definition: Handle.h:149
Helper to select condition objects by hash key from a conditions pool.
std::pair< const Condition::key_type, Condition > mapentry_t
ActiveSelect< collection_type > activeSelect(collection_type &active)
bool operator()(const cond_t &o) const
void operator()(object_t *o) const
void operator()(const mapentry_t &o) const
Class implementing the conditions collection for a given IOV type.
void operator()(object_t *o) const
bool operator()(const ptr_mapentry_t &o) const
KeyedSelect(cond_t::key_type k, collection_type &p)
void operator()(const mapentry_t &o) const
void operator()(const cond_t &o) const
void operator()(const mapentry_t &o) const
Helper to insert objects into a conditions pool.
Helper to select objects from a conditions pool.
void operator()(const cond_t &o) const
void operator()(const ptr_mapentry_t &o)
void onRemove(Condition condition)
Listener invocation when a condition is deregistered from the cache.
void operator()(const ptr_mapentry_t &o) const
PoolInsert< pool_type > poolInsert(pool_type &pool)
void operator()(const ptr_mapentry_t &o) const
key_type hash
Hash value of the name.
Helper to insert objects into a conditions pool.