Loading [MathJax]/extensions/tex2jax.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
IThinningHdlr.h
Go to the documentation of this file.
1 
3 /*
4  Copyright (C) 2002-2017, 2019 CERN for the benefit of the ATLAS collaboration
5 */
6 
7 #ifndef ATHENAKERNEL_ITHINNINGHDLR_H
8 #define ATHENAKERNEL_ITHINNINGHDLR_H 1
9 
10 // STL includes
11 #include <algorithm>
12 #include <vector>
13 #include <list>
14 #include <utility> // for std::pair
15 
16 #include <type_traits>
17 #include "GaudiKernel/DataObject.h"
18 
20 
21 // FrameWork includes
22 
23 // Forward declaration
24 // class IdentifierHash;
25 // template <class T, class BASE> class DataVector;
26 // template <class T> class IdentifiableContainer;
27 
28 namespace Athena {
29 
35 {
36 public:
39  virtual ~IThinningHdlr();
40 
43  virtual void remove( const std::size_t idx ) = 0;
48  virtual void commit() = 0;
49 
53  virtual void rollback() = 0;
54 
57  virtual bool isMapping() const {return false;}
58 };
59 
60 namespace detail {
63  struct IsNonNullPtr
64  {
65  template <typename Element>
66  bool operator()( Element* f ) const
67  { return f != 0; }
68  };
69 }
70 
79 template <typename Container>
81 {
82  typedef typename Container::PtrVector PtrVector;
88  //
89 public:
90  DvThinningHdlr( const Container& c ) :
92  m_backup ( const_cast<Container&>(c).begin(),
93  const_cast<Container&>(c).end() ),
94  m_container( const_cast<PtrVector&>(const_cast<Container&>(c).stdcont()) )
95  {}
96 
97  void remove( const std::size_t idx )
98  { m_container[idx] = 0; }
99 
100  void commit()
101  {
102  typedef typename PtrVector::iterator Iter;
103  // move non NULL pointers at the begin of the vector,
104  // preserving relative order...
105  Iter itr = std::stable_partition( m_container.begin(),
106  m_container.end(),
108  // nicely truncate our container: removes the NULL elements
109  m_container.resize( std::distance( m_container.begin(), itr ) );
110  }
111 
112  void rollback()
113  {
114  const std::size_t size = m_backup.size();
115  m_container.resize( size );
116  std::copy (m_backup.begin(), m_backup.end(),
117  m_container.begin());
118  }
119 };
120 
129 template <typename Container>
131 {
138  //
139 public:
141  Athena::IThinningHdlr( ),
142  m_backup ( const_cast<Container&>(c).begin(),
143  const_cast<Container&>(c).end() ),
144  m_container( const_cast<Container&>(c) )
145  {}
146 
147  void remove( const std::size_t idx )
148  { m_container[idx] = 0; }
149 
150  void commit()
151  {
152  typedef typename Vector_t::iterator Iter;
153  // move non NULL pointers at the begin of the vector,
154  // preserving relative order...
155  Iter itr = std::stable_partition( m_container.begin(),
156  m_container.end(),
158  // nicely truncate our container: removes the NULL elements
159  m_container.resize( std::distance( m_container.begin(), itr ) );
160  }
161 
162  void rollback()
163  {
164  const std::size_t size = m_backup.size();
165  m_container.resize( size );
166  std::copy (m_backup.begin(), m_backup.end(),
167  m_container.begin());
168  }
169 };
170 
179 template <typename Container>
181 {
182  typedef Container Idc_t;
183  typedef typename Idc_t::IDENTIFIABLE Identifiable_t;
184  typedef std::pair<std::size_t, Identifiable_t*> Backup_t;
185  typedef std::list<Backup_t> Backups_t;
186 
192  //
193 public:
195  Athena::IThinningHdlr( ),
196  m_backup (),
197  m_container( const_cast<Idc_t&>(c) )
198  {}
199 
200  void remove( const std::size_t idx )
201  {
202  Identifiable_t *c = m_container.removeCollection (idx);
203  m_backup.push_back (std::make_pair(idx, c));
204  }
205 
206  void commit() {/*no-op*/}
207 
208  void rollback()
209  {
210  typedef typename Backups_t::iterator Iter;
211  Iter end = m_backup.end();
212  for ( Iter itr = m_backup.begin(); itr!=end; ++itr) {
213  m_container.addCollection (itr->second, itr->first).ignore();
214  }
215  }
216 
219  virtual bool isMapping() const {return true;}
220 };
221 
225 template <class Container>
227 {
228 private:
229  typedef typename Container::value_type value_type;
231 
232  typedef typename std::is_base_of<std::vector<value_type>, Container>
234 
235  // ASSUME a Container inheriting from DataObject means IdentifiableContainer
236  // XXX that's kind of a bold assumption...
237  typedef typename std::is_base_of<DataObject, Container>
239 
240 public:
241 using type = std::conditional_t<
244  std::conditional_t<
248  >
249 >;
250 };
251 
252 } //> namespace Athena
253 
254 #endif //> ATHENAKERNEL_ITHINNINGHDLR_H
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
Athena::StdThinningHdlr::m_container
Vector_t & m_container
Definition: IThinningHdlr.h:137
Athena::get_thinning_handler::base_value_type
std::remove_pointer< value_type >::type base_value_type
Definition: IThinningHdlr.h:230
Athena::IdcThinningHdlr::Backup_t
std::pair< std::size_t, Identifiable_t * > Backup_t
Definition: IThinningHdlr.h:184
Athena::get_thinning_handler::derives_from_std_vector
std::is_base_of< std::vector< value_type >, Container > derives_from_std_vector
Definition: IThinningHdlr.h:233
Athena::DvThinningHdlr::DvThinningHdlr
DvThinningHdlr(const Container &c)
Definition: IThinningHdlr.h:90
Athena::DvThinningHdlr::m_container
PtrVector & m_container
Definition: IThinningHdlr.h:87
PlotCalibFromCool.begin
begin
Definition: PlotCalibFromCool.py:94
Athena::IdcThinningHdlr::rollback
void rollback()
unpack the proxied DataVector ie: restore it as it was before any thinning took place
Definition: IThinningHdlr.h:208
Athena::DvThinningHdlr::rollback
void rollback()
unpack the proxied DataVector ie: restore it as it was before any thinning took place
Definition: IThinningHdlr.h:112
Athena::IdcThinningHdlr::Identifiable_t
Idc_t::IDENTIFIABLE Identifiable_t
Definition: IThinningHdlr.h:183
athena.value
value
Definition: athena.py:124
detail
Definition: extract_histogram_tag.cxx:14
Athena::get_thinning_handler
metafunction to automagically dispatch on the type of a container and fetch the right thinning handle...
Definition: IThinningHdlr.h:227
Athena::detail::IsNonNullPtr
Predicate to spot non NULL pointers.
Definition: IThinningHdlr.h:64
Athena::IdcThinningHdlr::isMapping
virtual bool isMapping() const
publish the type of underlying indexing (mapping or sequencing)
Definition: IThinningHdlr.h:219
python.CaloAddPedShiftConfig.type
type
Definition: CaloAddPedShiftConfig.py:42
Athena::IThinningHdlr::rollback
virtual void rollback()=0
unpack the proxied DataVector ie: restore it as it was before any thinning took place
mergePhysValFiles.end
end
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:93
Container
storage of the time histories of all the cells
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
Athena
Some weak symbol referencing magic...
Definition: AthLegacySequence.h:21
Athena::IdcThinningHdlr
Handle DataProxy holding IdentifiableContainer This class defines a (type-safe) protocol to pack and ...
Definition: IThinningHdlr.h:181
Athena::StdThinningHdlr::StdThinningHdlr
StdThinningHdlr(const Container &c)
Definition: IThinningHdlr.h:140
Athena::detail::IsNonNullPtr::operator()
bool operator()(Element *f) const
Definition: IThinningHdlr.h:66
Athena::IdcThinningHdlr::m_backup
Backups_t m_backup
Vector holding the pointers to the elements of IdentifiableContainer, before any thinning took place.
Definition: IThinningHdlr.h:190
Athena::DvThinningHdlr
Handle DataProxy holding DataVector. This class defines a (type-safe) protocol to pack and unpack thi...
Definition: IThinningHdlr.h:81
hist_file_dump.f
f
Definition: hist_file_dump.py:141
Athena::IdcThinningHdlr::m_container
Idc_t & m_container
Definition: IThinningHdlr.h:191
Athena::StdThinningHdlr::Vector_t
Container Vector_t
Definition: IThinningHdlr.h:132
Athena::get_thinning_handler::derives_from_dataobject
std::is_base_of< DataObject, Container > derives_from_dataobject
Definition: IThinningHdlr.h:238
Athena::IThinningHdlr::~IThinningHdlr
virtual ~IThinningHdlr()
virtual destructor
Definition: IThinningHdlr.cxx:21
Athena::StdThinningHdlr::m_backup
const Vector_t m_backup
Vector holding the pointers to the elements of std::vector<T>, before any thinning took place.
Definition: IThinningHdlr.h:136
Athena::IdcThinningHdlr::IdcThinningHdlr
IdcThinningHdlr(const Container &c)
Definition: IThinningHdlr.h:194
Athena::IThinningHdlr::commit
virtual void commit()=0
pack the proxied collection This is needed in order to keep element link indices consistent and T/P c...
Athena::StdThinningHdlr::rollback
void rollback()
unpack the proxied DataVector ie: restore it as it was before any thinning took place
Definition: IThinningHdlr.h:162
Athena::StdThinningHdlr
Handle DataProxy holding std::vector<T> This class defines a (type-safe) protocol to pack and unpack ...
Definition: IThinningHdlr.h:131
Athena::get_thinning_handler::value_type
Container::value_type value_type
Definition: IThinningHdlr.h:229
Athena::IdcThinningHdlr::Backups_t
std::list< Backup_t > Backups_t
Definition: IThinningHdlr.h:185
Athena::IdcThinningHdlr::Idc_t
Container Idc_t
Definition: IThinningHdlr.h:182
Athena::DvThinningHdlr::m_backup
const PtrVector m_backup
Vector holding the pointers to the elements of DataVector, before any thinning took place.
Definition: IThinningHdlr.h:86
LArNewCalib_DelayDump_OFC_Cali.idx
idx
Definition: LArNewCalib_DelayDump_OFC_Cali.py:69
Athena::IdcThinningHdlr::commit
void commit()
pack the proxied collection This is needed in order to keep element link indices consistent and T/P c...
Definition: IThinningHdlr.h:206
Athena::IdcThinningHdlr::remove
void remove(const std::size_t idx)
remove an element from the proxied DataVector
Definition: IThinningHdlr.h:200
Athena::IThinningHdlr::isMapping
virtual bool isMapping() const
publish the type of underlying indexing (mapping or sequencing)
Definition: IThinningHdlr.h:57
Athena::StdThinningHdlr::commit
void commit()
pack the proxied collection This is needed in order to keep element link indices consistent and T/P c...
Definition: IThinningHdlr.h:150
Athena::DvThinningHdlr::PtrVector
Container::PtrVector PtrVector
Definition: IThinningHdlr.h:82
calibdata.copy
bool copy
Definition: calibdata.py:27
Athena::IThinningHdlr
This class defines a protocol to pack and unpack thinned collections.
Definition: IThinningHdlr.h:35
Athena::StdThinningHdlr::remove
void remove(const std::size_t idx)
remove an element from the proxied DataVector
Definition: IThinningHdlr.h:147
checker_macros.h
Define macros for attributes used to control the static checker.
Athena::DvThinningHdlr::remove
void remove(const std::size_t idx)
remove an element from the proxied DataVector
Definition: IThinningHdlr.h:97
Athena::get_thinning_handler::type
std::conditional_t< derives_from_dataobject::value, ::Athena::IdcThinningHdlr< Container >, std::conditional_t< derives_from_std_vector::value, ::Athena::StdThinningHdlr< Container >, ::Athena::DvThinningHdlr< Container > > > type
Definition: IThinningHdlr.h:249
Amg::distance
float distance(const Amg::Vector3D &p1, const Amg::Vector3D &p2)
calculates the distance between two point in 3D space
Definition: GeoPrimitivesHelpers.h:54
python.compressB64.c
def c
Definition: compressB64.py:93
Athena::ATLAS_NOT_THREAD_SAFE
void DebugAids::stacktraceLine ATLAS_NOT_THREAD_SAFE(IOFD fd, unsigned long addr)
Write out stack trace line to FD.
Definition: SealDebug.cxx:328
Athena::IThinningHdlr::remove
virtual void remove(const std::size_t idx)=0
remove an element from the proxied DataVector
Athena::DvThinningHdlr::commit
void commit()
pack the proxied collection This is needed in order to keep element link indices consistent and T/P c...
Definition: IThinningHdlr.h:100