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

#include <CopyHelpers.h>

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

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, 2 >

Definition at line 177 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, 2 >::StoreType

the type of the event store we use

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

Member Function Documentation

◆ getCopy()

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

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

188  {
189  // Define the msg(...) function as a lambda.
190  // Suppress thread-checker warning because this provides just a wrapper to MsgStream.
191  const auto msg = [&] ATLAS_NOT_THREAD_SAFE (MSG::Level lvl) -> MsgStream& {
192  msgStream << lvl;
193  return msgStream;
194  };
195 
196  // Make sure that we get a valid pointer.
197  assert (inputObject != nullptr);
198 
199  // Handle the case when the input object is a view container.
200  if( ! inputObject->getConstStore() ) {
201 
202  // Decide how to handle the container.
203  if( inputObject->size() ) {
204  // Get the pointer to the "owning container" from the first
205  // element.
206  const T* originContainer =
207  dynamic_cast< const T* >( ( *inputObject )[ 0 ]->container() );
208  // Make sure that every element in the view container has the same
209  // parent.
210  for( size_t i = 1; i < inputObject->size(); ++i ) {
211  if( ( *inputObject )[ i ]->container() != originContainer ) {
212  ANA_MSG_ERROR( "Not all elements of the received view "
213  "container come from the same container!" );
214  return StatusCode::FAILURE;
215  }
216  }
217  // Postfix for the shallow-copy container of the origin container.
218  static const char* const ORIGIN_POSTFIX = "_ShallowCopyOrigin";
219  // Make a shallow copy of the origin container.
220  auto originCopy = xAOD::shallowCopyContainer( *originContainer );
221  if( ( ! originCopy.first ) || ( ! originCopy.second ) ) {
222  ANA_MSG_ERROR( "Failed to shallow copy the origin of a view "
223  << "container, meant for: " << outputName );
224  return StatusCode::FAILURE;
225  }
226  // ...and record it.
227  ANA_CHECK( store.record( originCopy.first,
228  outputName + ORIGIN_POSTFIX ) );
229  ANA_CHECK( store.record( originCopy.second,
230  outputName + ORIGIN_POSTFIX +
231  "Aux." ) );
232  // Make a view copy on top of it.
233  auto viewCopy = std::make_unique< T >( SG::VIEW_ELEMENTS );
234  auto viewCopyPtr = viewCopy.get();
235  for( const auto* element : *inputObject ) {
236  viewCopy->push_back( originCopy.first->at( element->index() ) );
237  }
238  // Finally, record the view container with the requested name.
239  ANA_CHECK( store.record( viewCopy.release(), outputName ) );
240  // The copy is done.
241  object = viewCopyPtr;
242  return StatusCode::SUCCESS;
243  } else {
244  // If the container was empty, then let's just make a new empty
245  // container, and that's that...
246  auto viewCopy = std::make_unique< T >( SG::VIEW_ELEMENTS );
247  auto viewCopyPtr = viewCopy.get();
248  ANA_CHECK( store.record( viewCopy.release(), outputName ) );
249  // The copy is done.
250  object = viewCopyPtr;
251  return StatusCode::SUCCESS;
252  }
253 
254  } else {
255 
256  // We can just copy the container as is.
257  auto copy = xAOD::shallowCopyContainer( *inputObject );
258  if (!copy.first || !copy.second)
259  {
260  ANA_MSG_ERROR ("failed to shallow copy object: " << outputName);
261  ANA_MSG_ERROR ("likely shallow copying a view container");
262  return StatusCode::FAILURE;
263  }
264 
265  ANA_CHECK (store.record (copy.second, auxName));
266  ANA_CHECK (store.record (copy.first, outputName));
267  object = copy.first;
268  return StatusCode::SUCCESS;
269  }
270  }

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
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