ATLAS Offline Software
Loading...
Searching...
No Matches
IThinningHdlr.h
Go to the documentation of this file.
1
2
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
28namespace Athena {
29
35{
36public:
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
60namespace detail {
64 {
65 template <typename Element>
66 bool operator()( Element* f ) const
67 { return f != 0; }
68 };
69}
70
79template <typename Container>
81{
82 typedef typename Container::PtrVector PtrVector;
88 //
89public:
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
129template <typename Container>
131{
138 //
139public:
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
179template <typename Container>
181{
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 //
193public:
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
225template <class Container>
227{
228private:
229 typedef typename Container::value_type value_type;
230 typedef typename std::remove_pointer<value_type>::type base_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
240public:
241using type = std::conditional_t<
242 derives_from_dataobject::value,
244 std::conditional_t<
245 derives_from_std_vector::value,
248 >
249>;
250};
251
252} //> namespace Athena
253
254#endif //> ATHENAKERNEL_ITHINNINGHDLR_H
Define macros for attributes used to control the static checker.
Handle DataProxy holding DataVector.
DvThinningHdlr(const Container &c)
void rollback()
unpack the proxied DataVector ie: restore it as it was before any thinning took place
const PtrVector m_backup
Vector holding the pointers to the elements of DataVector, before any thinning took place.
void remove(const std::size_t idx)
remove an element from the proxied DataVector
Container::PtrVector PtrVector
void commit()
pack the proxied collection This is needed in order to keep element link indices consistent and T/P c...
This class defines a protocol to pack and unpack thinned collections.
virtual void rollback()=0
unpack the proxied DataVector ie: restore it as it was before any thinning took place
virtual bool isMapping() const
publish the type of underlying indexing (mapping or sequencing)
virtual ~IThinningHdlr()
virtual destructor
virtual void remove(const std::size_t idx)=0
remove an element from the proxied DataVector
virtual void commit()=0
pack the proxied collection This is needed in order to keep element link indices consistent and T/P c...
Handle DataProxy holding IdentifiableContainer This class defines a (type-safe) protocol to pack and ...
void commit()
pack the proxied collection This is needed in order to keep element link indices consistent and T/P c...
void rollback()
unpack the proxied DataVector ie: restore it as it was before any thinning took place
IdcThinningHdlr(const Container &c)
std::pair< std::size_t, Identifiable_t * > Backup_t
std::list< Backup_t > Backups_t
virtual bool isMapping() const
publish the type of underlying indexing (mapping or sequencing)
void remove(const std::size_t idx)
remove an element from the proxied DataVector
Idc_t::IDENTIFIABLE Identifiable_t
Backups_t m_backup
Vector holding the pointers to the elements of IdentifiableContainer, before any thinning took place.
Handle DataProxy holding std::vector<T> This class defines a (type-safe) protocol to pack and unpack ...
StdThinningHdlr(const Container &c)
void rollback()
unpack the proxied DataVector ie: restore it as it was before any thinning took place
void remove(const std::size_t idx)
remove an element from the proxied DataVector
void commit()
pack the proxied collection This is needed in order to keep element link indices consistent and T/P c...
const Vector_t m_backup
Vector holding the pointers to the elements of std::vector<T>, before any thinning took place.
storage of the time histories of all the cells
Some weak symbol referencing magic... These are declared in AthenaKernel/getMessageSvc....
StatusCode ROOTMessageFilterSvc::initialize ATLAS_NOT_THREAD_SAFE()
Return the file descriptor fataldump() uses for output.
DataModel_detail::iterator< DVL > stable_partition(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end, Predicate pred)
Specialization of stable_partition for DataVector/List.
Predicate to spot non NULL pointers.
bool operator()(Element *f) const
metafunction to automagically dispatch on the type of a container and fetch the right thinning handle...
std::is_base_of< std::vector< value_type >, Container > derives_from_std_vector
std::is_base_of< DataObject, Container > derives_from_dataobject
Container::value_type value_type
std::remove_pointer< value_type >::type base_value_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