ATLAS Offline Software
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 <boost/mpl/if.hpp>
17 #include <type_traits>
18 #include "GaudiKernel/DataObject.h"
19 
21 
22 // FrameWork includes
23 
24 // Forward declaration
25 // class IdentifierHash;
26 // template <class T, class BASE> class DataVector;
27 // template <class T> class IdentifiableContainer;
28 
29 namespace Athena {
30 
36 {
37 public:
40  virtual ~IThinningHdlr();
41 
44  virtual void remove( const std::size_t idx ) = 0;
49  virtual void commit() = 0;
50 
54  virtual void rollback() = 0;
55 
58  virtual bool isMapping() const {return false;}
59 };
60 
61 namespace detail {
64  struct IsNonNullPtr
65  {
66  template <typename Element>
67  bool operator()( Element* f ) const
68  { return f != 0; }
69  };
70 }
71 
80 template <typename Container>
82 {
83  typedef typename Container::PtrVector PtrVector;
89  //
90 public:
91  DvThinningHdlr( const Container& c ) :
93  m_backup ( const_cast<Container&>(c).begin(),
94  const_cast<Container&>(c).end() ),
95  m_container( const_cast<PtrVector&>(const_cast<Container&>(c).stdcont()) )
96  {}
97 
98  void remove( const std::size_t idx )
99  { m_container[idx] = 0; }
100 
101  void commit()
102  {
103  typedef typename PtrVector::iterator Iter;
104  // move non NULL pointers at the begin of the vector,
105  // preserving relative order...
106  Iter itr = std::stable_partition( m_container.begin(),
107  m_container.end(),
109  // nicely truncate our container: removes the NULL elements
110  m_container.resize( std::distance( m_container.begin(), itr ) );
111  }
112 
113  void rollback()
114  {
115  const std::size_t size = m_backup.size();
116  m_container.resize( size );
117  std::copy (m_backup.begin(), m_backup.end(),
118  m_container.begin());
119  }
120 };
121 
130 template <typename Container>
132 {
139  //
140 public:
142  Athena::IThinningHdlr( ),
143  m_backup ( const_cast<Container&>(c).begin(),
144  const_cast<Container&>(c).end() ),
145  m_container( const_cast<Container&>(c) )
146  {}
147 
148  void remove( const std::size_t idx )
149  { m_container[idx] = 0; }
150 
151  void commit()
152  {
153  typedef typename Vector_t::iterator Iter;
154  // move non NULL pointers at the begin of the vector,
155  // preserving relative order...
156  Iter itr = std::stable_partition( m_container.begin(),
157  m_container.end(),
159  // nicely truncate our container: removes the NULL elements
160  m_container.resize( std::distance( m_container.begin(), itr ) );
161  }
162 
163  void rollback()
164  {
165  const std::size_t size = m_backup.size();
166  m_container.resize( size );
167  std::copy (m_backup.begin(), m_backup.end(),
168  m_container.begin());
169  }
170 };
171 
180 template <typename Container>
182 {
183  typedef Container Idc_t;
184  typedef typename Idc_t::IDENTIFIABLE Identifiable_t;
185  typedef std::pair<std::size_t, Identifiable_t*> Backup_t;
186  typedef std::list<Backup_t> Backups_t;
187 
193  //
194 public:
196  Athena::IThinningHdlr( ),
197  m_backup (),
198  m_container( const_cast<Idc_t&>(c) )
199  {}
200 
201  void remove( const std::size_t idx )
202  {
203  Identifiable_t *c = m_container.removeCollection (idx);
204  m_backup.push_back (std::make_pair(idx, c));
205  }
206 
207  void commit() {/*no-op*/}
208 
209  void rollback()
210  {
211  typedef typename Backups_t::iterator Iter;
212  Iter end = m_backup.end();
213  for ( Iter itr = m_backup.begin(); itr!=end; ++itr) {
214  m_container.addCollection (itr->second, itr->first).ignore();
215  }
216  }
217 
220  virtual bool isMapping() const {return true;}
221 };
222 
226 template <class Container>
228 {
229 private:
230  typedef typename Container::value_type value_type;
232 
233  typedef typename std::is_base_of<std::vector<value_type>, Container>
235 
236  // ASSUME a Container inheriting from DataObject means IdentifiableContainer
237  // XXX that's kind of a bold assumption...
238  typedef typename std::is_base_of<DataObject, Container>
240 
241 public:
242 #define if_c ::boost::mpl::if_c
243  typedef typename
246  typename
250  >::type
252 #undef if_c
253 };
254 
255 } //> namespace Athena
256 
257 #endif //> ATHENAKERNEL_ITHINNINGHDLR_H
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
Athena::StdThinningHdlr::m_container
Vector_t & m_container
Definition: IThinningHdlr.h:138
Athena::get_thinning_handler::base_value_type
std::remove_pointer< value_type >::type base_value_type
Definition: IThinningHdlr.h:231
python.CaloRecoConfig.f
f
Definition: CaloRecoConfig.py:127
Athena::IdcThinningHdlr::Backup_t
std::pair< std::size_t, Identifiable_t * > Backup_t
Definition: IThinningHdlr.h:185
Athena::get_thinning_handler::derives_from_std_vector
std::is_base_of< std::vector< value_type >, Container > derives_from_std_vector
Definition: IThinningHdlr.h:234
Athena::DvThinningHdlr::DvThinningHdlr
DvThinningHdlr(const Container &c)
Definition: IThinningHdlr.h:91
Athena::DvThinningHdlr::m_container
PtrVector & m_container
Definition: IThinningHdlr.h:88
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:209
Athena::DvThinningHdlr::rollback
void rollback()
unpack the proxied DataVector ie: restore it as it was before any thinning took place
Definition: IThinningHdlr.h:113
Athena::IdcThinningHdlr::Identifiable_t
Idc_t::IDENTIFIABLE Identifiable_t
Definition: IThinningHdlr.h:184
athena.value
value
Definition: athena.py:122
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:228
Athena::detail::IsNonNullPtr
Predicate to spot non NULL pointers.
Definition: IThinningHdlr.h:65
Athena::IdcThinningHdlr::isMapping
virtual bool isMapping() const
publish the type of underlying indexing (mapping or sequencing)
Definition: IThinningHdlr.h:220
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:182
Athena::StdThinningHdlr::StdThinningHdlr
StdThinningHdlr(const Container &c)
Definition: IThinningHdlr.h:141
Athena::detail::IsNonNullPtr::operator()
bool operator()(Element *f) const
Definition: IThinningHdlr.h:67
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:191
Athena::DvThinningHdlr
Handle DataProxy holding DataVector. This class defines a (type-safe) protocol to pack and unpack thi...
Definition: IThinningHdlr.h:82
Athena::IdcThinningHdlr::m_container
Idc_t & m_container
Definition: IThinningHdlr.h:192
Athena::StdThinningHdlr::Vector_t
Container Vector_t
Definition: IThinningHdlr.h:133
Athena::get_thinning_handler::derives_from_dataobject
std::is_base_of< DataObject, Container > derives_from_dataobject
Definition: IThinningHdlr.h:239
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:137
Athena::IdcThinningHdlr::IdcThinningHdlr
IdcThinningHdlr(const Container &c)
Definition: IThinningHdlr.h:195
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:163
Athena::StdThinningHdlr
Handle DataProxy holding std::vector<T> This class defines a (type-safe) protocol to pack and unpack ...
Definition: IThinningHdlr.h:132
Athena::get_thinning_handler::type
if_c< derives_from_dataobject::value, ::Athena::IdcThinningHdlr< Container >, typename if_c< derives_from_std_vector::value, ::Athena::StdThinningHdlr< Container >, ::Athena::DvThinningHdlr< Container > >::type >::type type
Definition: IThinningHdlr.h:251
Athena::get_thinning_handler::value_type
Container::value_type value_type
Definition: IThinningHdlr.h:230
Athena::IdcThinningHdlr::Backups_t
std::list< Backup_t > Backups_t
Definition: IThinningHdlr.h:186
Athena::IdcThinningHdlr::Idc_t
Container Idc_t
Definition: IThinningHdlr.h:183
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
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:87
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:207
if_c
#define if_c
Definition: IThinningHdlr.h:242
Athena::IdcThinningHdlr::remove
void remove(const std::size_t idx)
remove an element from the proxied DataVector
Definition: IThinningHdlr.h:201
Athena::IThinningHdlr::isMapping
virtual bool isMapping() const
publish the type of underlying indexing (mapping or sequencing)
Definition: IThinningHdlr.h:58
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:151
Athena::DvThinningHdlr::PtrVector
Container::PtrVector PtrVector
Definition: IThinningHdlr.h:83
calibdata.copy
bool copy
Definition: calibdata.py:27
Athena::IThinningHdlr
This class defines a protocol to pack and unpack thinned collections.
Definition: IThinningHdlr.h:36
Athena::StdThinningHdlr::remove
void remove(const std::size_t idx)
remove an element from the proxied DataVector
Definition: IThinningHdlr.h:148
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:98
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:101