8#ifndef SYSTEMATICS_HANDLES__COPY_HELPERS_H
9#define SYSTEMATICS_HANDLES__COPY_HELPERS_H
52 static const int value = ( std::is_same< std::true_type, decltype( test_iparticle< T >(
nullptr ) ) >
::value ?
64 template<typename T, int type = ContainerType<T>::value>
68 "Type can not be shallow copied");
75 getCopy (MsgStream& msgStream,
const EventContext& ctx,
76 T*&
object,
const T *inputObject,
77 const std::string& outputName)
87 assert (inputObject !=
nullptr);
90 if( ! inputObject->getConstStore() ) {
93 if( inputObject->size() ) {
96 const T* originContainer =
97 dynamic_cast< const T*
>( ( *inputObject )[ 0 ]->container() );
98 if (!originContainer){
100 return StatusCode::FAILURE;
104 for(
size_t i = 1; i < inputObject->size(); ++i ) {
105 if( ( *inputObject )[ i ]->container() != originContainer ) {
107 "container come from the same container!" );
108 return StatusCode::FAILURE;
112 static const char*
const ORIGIN_POSTFIX =
"_ShallowCopyOrigin";
115 if( ( ! originCopy.first ) || ( ! originCopy.second ) ) {
116 ANA_MSG_ERROR(
"Failed to shallow copy the origin of a view "
117 <<
"container, meant for: " << outputName );
118 return StatusCode::FAILURE;
122 auto viewCopyPtr = viewCopy.get();
123 for(
const auto* element : *inputObject ) {
124 viewCopy->push_back( originCopy.first->at( element->index() ) );
131 std::move(originCopy.second) ) );
137 for(
size_t i = 0; i < inputObject->size(); ++i ) {
139 *( ( *viewCopy )[ i ] ) ) ) {
140 return StatusCode::FAILURE;
147 object = viewCopyPtr;
148 return StatusCode::SUCCESS;
153 auto viewCopyPtr = viewCopy.get();
157 object = viewCopyPtr;
158 return StatusCode::SUCCESS;
165 if (!copy.first || !copy.second)
167 ANA_MSG_ERROR (
"failed to shallow copy object: " << outputName);
169 return StatusCode::FAILURE;
173 return StatusCode::FAILURE;
176 object = copy.first.get();
180 ANA_CHECK (handle.recordNonConst (std::move(copy.first), std::move(copy.second)));
181 return StatusCode::SUCCESS;
190 getCopy (MsgStream& msgStream,
const EventContext& ctx,
191 T*&
object,
const T *inputObject,
192 const std::string& outputName)
202 assert (inputObject !=
nullptr);
205 if( ! inputObject->getConstStore() ) {
208 if( inputObject->size() ) {
211 const T* originContainer =
dynamic_cast< const T*
>( ( *inputObject )[ 0 ]->container() );
212 if (!originContainer){
214 return StatusCode::FAILURE;
218 for(
size_t i = 1; i < inputObject->size(); ++i ) {
219 if( ( *inputObject )[ i ]->container() != originContainer ) {
221 "container come from the same container!" );
222 return StatusCode::FAILURE;
226 static const char*
const ORIGIN_POSTFIX =
"_ShallowCopyOrigin";
229 if( ( ! originCopy.first ) || ( ! originCopy.second ) ) {
230 ANA_MSG_ERROR(
"Failed to shallow copy the origin of a view "
231 <<
"container, meant for: " << outputName );
232 return StatusCode::FAILURE;
237 auto viewCopyPtr = viewCopy.get();
238 for(
const auto* element : *inputObject ) {
239 viewCopy->push_back( originCopy.first->at( element->index() ) );
246 std::move(originCopy.second) ) );
252 object = viewCopyPtr;
253 return StatusCode::SUCCESS;
258 auto viewCopyPtr = viewCopy.get();
262 object = viewCopyPtr;
263 return StatusCode::SUCCESS;
270 if (!copy.first || !copy.second)
272 ANA_MSG_ERROR (
"failed to shallow copy object: " << outputName);
274 return StatusCode::FAILURE;
278 object = copy.first.get();
282 ANA_CHECK (handle.recordNonConst (std::move(copy.first), std::move(copy.second)));
283 return StatusCode::SUCCESS;
292 getCopy (MsgStream& msgStream,
const EventContext& ctx,
293 T*&
object,
const T *inputObject,
294 const std::string& outputName)
305 if (!copy.first || !copy.second)
307 ANA_MSG_ERROR (
"failed to shallow copy object: " << outputName);
309 return StatusCode::FAILURE;
312 object = copy.first.get();
316 ANA_CHECK (handle.recordNonConst (std::move(copy.first), std::move(copy.second)));
317 return StatusCode::SUCCESS;
325 getCopy (MsgStream& msgStream,
const EventContext& ctx,
328 const std::string& outputName);
Define macros for attributes used to control the static checker.
Manage index tracking and synchronization of auxiliary data.
StatusCode recordNonConst(std::unique_ptr< T > data)
Record a non-const object to the store.
Class providing the definition of the 4-vector interface.
Select isolated Photons, Electrons and Muons.
@ VIEW_ELEMENTS
this data object is a view, it does not own its elmts
ICaloAffectedTool is abstract interface for tools checking if 4 mom is in calo affected region.
ShallowCopyResult_t< T > shallowCopy(const T &cont, const EventContext &ctx)
Create a shallow copy of an existing container.
bool setOriginalObjectLink(const IParticle &original, IParticle ©)
This function should be used by CP tools when they make a deep copy of an object in their correctedCo...
void ClearTransientTrees ATLAS_NOT_THREAD_SAFE()
Function cleaning up the managed memory.
DataVector< IParticle > IParticleContainer
Simple convenience declaration of IParticleContainer.
check what kind of object/container the argument is
static std::true_type test_container(checker< C, decltype((*(const SG::AuxVectorBase **) nullptr)=((C *) nullptr))> *)
static const int value
Value evaluating to:
static std::false_type test_iparticle(...)
static std::false_type test_container(...)
static std::true_type test_iparticle(checker< C, decltype((*(const xAOD::IParticle **) nullptr)=((C *) nullptr) ->at(0))> *)
static StatusCode getCopy(MsgStream &msgStream, const EventContext &ctx, T *&object, const T *inputObject, const std::string &outputName)
static StatusCode getCopy(MsgStream &msgStream, const EventContext &ctx, T *&object, const T *inputObject, const std::string &outputName)
static StatusCode getCopy(MsgStream &msgStream, const EventContext &ctx, T *&object, const T *inputObject, const std::string &outputName)
static StatusCode getCopy(MsgStream &msgStream, const EventContext &ctx, xAOD::IParticleContainer *&object, const xAOD::IParticleContainer *inputObject, const std::string &outputName)
a helper class to create shallow copies and register them in the event store