ATLAS Offline Software
Public Types | Static Public Member Functions | List of all members
CP::detail::ShallowCopy< T, 1 > Struct Template Reference

#include <CopyHelpers.h>

Collaboration diagram for CP::detail::ShallowCopy< T, 1 >:

Public Types

typedef std::decay< decltype(*(std::declval< EL::AnaAlgorithm >).evtStore()))>::type StoreType
 the type of the event store we use More...
 

Static Public Member Functions

static StatusCode getCopy (MsgStream &msgStream, StoreType &store, T *&object, const T *inputObject, const std::string &outputName, const std::string &auxName)
 

Detailed Description

template<typename T>
struct CP::detail::ShallowCopy< T, 1 >

Definition at line 67 of file SystematicsHandles/SystematicsHandles/CopyHelpers.h.

Member Typedef Documentation

◆ StoreType

template<typename T >
typedef std::decay<decltype( *(std::declval<EL::AnaAlgorithm>).evtStore()))>::type CP::detail::ShallowCopy< T, 1 >::StoreType

the type of the event store we use

Definition at line 72 of file SystematicsHandles/SystematicsHandles/CopyHelpers.h.

Member Function Documentation

◆ getCopy()

template<typename T >
static StatusCode CP::detail::ShallowCopy< T, 1 >::getCopy ( MsgStream &  msgStream,
StoreType store,
T *&  object,
const T *  inputObject,
const std::string &  outputName,
const std::string &  auxName 
)
inlinestatic

Definition at line 75 of file SystematicsHandles/SystematicsHandles/CopyHelpers.h.

78  {
79  // Define the msg(...) function as a lambda.
80  // Suppress thread-checker warning because this provides just a wrapper to MsgStream.
81  const auto msg = [&] ATLAS_NOT_THREAD_SAFE (MSG::Level lvl) -> MsgStream& {
82  msgStream << lvl;
83  return msgStream;
84  };
85 
86  // Make sure that we get a valid pointer.
87  assert (inputObject != nullptr);
88 
89  // Handle the case when the input object is a view container.
90  if( ! inputObject->getConstStore() ) {
91 
92  // Decide how to handle the container.
93  if( inputObject->size() ) {
94  // Get the pointer to the "owning container" from the first
95  // element.
96  const T* originContainer =
97  dynamic_cast< const T* >( ( *inputObject )[ 0 ]->container() );
98  // Make sure that every element in the view container has the same
99  // parent.
100  for( size_t i = 1; i < inputObject->size(); ++i ) {
101  if( ( *inputObject )[ i ]->container() != originContainer ) {
102  ANA_MSG_ERROR( "Not all elements of the received view "
103  "container come from the same container!" );
104  return StatusCode::FAILURE;
105  }
106  }
107  // Postfix for the shallow-copy container of the origin container.
108  static const char* const ORIGIN_POSTFIX = "_ShallowCopyOrigin";
109  // Make a shallow copy of the origin container.
110  auto originCopy = xAOD::shallowCopyContainer( *originContainer );
111  if( ( ! originCopy.first ) || ( ! originCopy.second ) ) {
112  ANA_MSG_ERROR( "Failed to shallow copy the origin of a view "
113  << "container, meant for: " << outputName );
114  return StatusCode::FAILURE;
115  }
116  // ...and record it.
117  ANA_CHECK( store.record( originCopy.first,
118  outputName + ORIGIN_POSTFIX ) );
119  ANA_CHECK( store.record( originCopy.second,
120  outputName + ORIGIN_POSTFIX + "Aux." ) );
121  // Make a view copy on top of it.
122  auto viewCopy = std::make_unique< T >( SG::VIEW_ELEMENTS );
123  auto viewCopyPtr = viewCopy.get();
124  for( const auto* element : *inputObject ) {
125  viewCopy->push_back( originCopy.first->at( element->index() ) );
126  }
127  // Set the origin links on it. Note that
128  // xAOD::setOriginalObjectLink's "container version" doesn't work
129  // with view containers, we have to call this function one-by-one
130  // on the elements.
131  for( size_t i = 0; i < inputObject->size(); ++i ) {
132  if( ! xAOD::setOriginalObjectLink( *( ( *inputObject )[ i ] ),
133  *( ( *viewCopy )[ i ] ) ) ) {
134  return StatusCode::FAILURE;
135  }
136  }
137  // Finally, record the view container with the requested name.
138  ANA_CHECK( store.record( viewCopy.release(), outputName ) );
139  // The copy is done.
140  object = viewCopyPtr;
141  return StatusCode::SUCCESS;
142  } else {
143  // If the container was empty, then let's just make a new empty
144  // container, and that's that...
145  auto viewCopy = std::make_unique< T >( SG::VIEW_ELEMENTS );
146  auto viewCopyPtr = viewCopy.get();
147  ANA_CHECK( store.record( viewCopy.release(), outputName ) );
148  // The copy is done.
149  object = viewCopyPtr;
150  return StatusCode::SUCCESS;
151  }
152 
153  } else {
154 
155  // We can just copy the container as is.
156  auto copy = xAOD::shallowCopyContainer( *inputObject );
157  if (!copy.first || !copy.second)
158  {
159  ANA_MSG_ERROR ("failed to shallow copy object: " << outputName);
160  ANA_MSG_ERROR ("likely shallow copying a view container");
161  return StatusCode::FAILURE;
162  }
163 
164  if (!xAOD::setOriginalObjectLink (*inputObject, *copy.first)) {
165  return StatusCode::FAILURE;
166  }
167 
168  ANA_CHECK (store.record (copy.second, auxName));
169  ANA_CHECK (store.record (copy.first, outputName));
170  object = copy.first;
171  return StatusCode::SUCCESS;
172  }
173  }

The documentation for this struct was generated from the following file:
StoreGateSvc::record
StatusCode record(T *p2BRegistered, const TKEY &key)
Record an object with a key.
store
StoreGateSvc * store
Definition: fbtTestBasics.cxx:69
ATLAS_NOT_THREAD_SAFE
#define ATLAS_NOT_THREAD_SAFE
getNoisyStrip() Find noisy strips from hitmaps and write out into xml/db formats
Definition: checker_macros.h:212
SG::VIEW_ELEMENTS
@ VIEW_ELEMENTS
this data object is a view, it does not own its elmts
Definition: OwnershipPolicy.h:18
ANA_MSG_ERROR
#define ANA_MSG_ERROR(xmsg)
Macro printing error messages.
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:294
ANA_CHECK
#define ANA_CHECK(EXP)
check whether the given expression was successful
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:324
TrigConf::MSGTC::Level
Level
Definition: Trigger/TrigConfiguration/TrigConfBase/TrigConfBase/MsgStream.h:21
lumiFormat.i
int i
Definition: lumiFormat.py:92
lumiFormat.outputName
string outputName
Definition: lumiFormat.py:71
xAOD::shallowCopyContainer
std::pair< std::unique_ptr< T >, std::unique_ptr< ShallowAuxContainer > > shallowCopyContainer(const T &cont, [[maybe_unused]] const EventContext &ctx)
Function making a shallow copy of a constant container.
Definition: ShallowCopy.h:110
xAOD::setOriginalObjectLink
bool setOriginalObjectLink(const IParticle &original, IParticle &copy)
This function should be used by CP tools when they make a deep copy of an object in their correctedCo...
Definition: IParticleHelpers.cxx:30
calibdata.copy
bool copy
Definition: calibdata.py:27
python.AutoConfigFlags.msg
msg
Definition: AutoConfigFlags.py:7
TSU::T
unsigned long long T
Definition: L1TopoDataTypes.h:35