ATLAS Offline Software
Loading...
Searching...
No Matches
xAOD::RAuxStore Class Referenceabstract

"ROOT @c RNTuple implementation" of IAuxStore More...

#include <RAuxStore.h>

Inheritance diagram for xAOD::RAuxStore:
Collaboration diagram for xAOD::RAuxStore:

Classes

struct  impl

Public Types

enum class  EStructMode { kUndefinedStore = 0 , kContainerStore = 1 , kObjectStore = 2 }
 "Structural" modes of the object More...

Public Member Functions

 RAuxStore (std::string_view prefix="", bool topStore=true, EStructMode mode=EStructMode::kUndefinedStore)
 Constructor.
virtual ~RAuxStore ()
 Destructor.
virtual void setPrefix (std::string_view prefix) override
 Set the object name prefix.
StatusCode readFrom (ROOT::RNTupleReader &reader)
 Connect the object to an input RNTuple.
StatusCode writeTo (ROOT::RNTupleWriter &writer)
 Add the variables of the store to an output RNTuple.
StatusCode getEntry (std::int64_t entry, int getall=0)
 Get entry from the input RNTuple.
StatusCode commitTo (ROOT::REntry &entry)
 Commit a new entry to the output RNTuple.
EStructMode structMode () const
 Get what structure mode the object was constructed with.
void setStructMode (EStructMode mode)
 Set the structure mode of the object to a new value.
const std::string & prefix () const
 Get the currently configured object name prefix.
bool isTopStore () const
 Check if the object is a "top store", or not.
void setTopStore (bool value=true)
 Set whether the object should behave as a "top store" or not.
virtual void * getData (auxid_t auxid, size_t size, size_t capacity)=0
 Return the data vector for one aux data item.
virtual void * getDecoration (auxid_t auxid, size_t size, size_t capacity)=0
 Return the data vector for one aux data decoration item.
virtual bool resize (size_t sz)=0
 Change the size of all aux data vectors.
virtual void reserve (size_t sz)=0
 Change the capacity of all aux data vectors.
virtual void shift (size_t pos, ptrdiff_t offs)=0
 Shift the elements of the container.
virtual bool insertMove (size_t pos, IAuxStore &other, const SG::auxid_set_t &ignore=SG::auxid_set_t())=0
 Move all elements from other to this store.
virtual bool setOption (auxid_t, const AuxDataOption &)
 Set an option for a given auxiliary variable.
Functions implementing the @c SG::IConstAuxStore interface
virtual const void * getData (SG::auxid_t auxid) const override
 Get a pointer to a given array.
virtual const SG::IAuxTypeVectorgetVector (SG::auxid_t auxid) const override
 Return vector interface for one aux data item.
virtual const SG::auxid_set_tgetAuxIDs () const override
 Get the types(names) of variables handled by this container.
virtual const SG::auxid_set_tgetDecorIDs () const override
 Get the types(names) of decorations handled by this container.
virtual void * getDecoration (SG::auxid_t auxid, std::size_t size, std::size_t capacity) override
 Get a pointer to a given array, creating the array if necessary.
virtual bool isDecoration (SG::auxid_t auxid) const override
 Test if a variable is a decoration.
virtual void lock () override
 Lock the object, and don't let decorations be added.
virtual bool clearDecorations () override
 Remove the decorations added so far.
virtual void lockDecoration (SG::auxid_t auxid) override
 Lock a decoration.
virtual std::size_t size () const override
 Return the number of elements in the store.
virtual const SG::IAuxTypeVectorlinkedVector (SG::auxid_t auxid) const override
 Return (const) interface for a linked variable.
virtual SG::IAuxTypeVectorlinkedVector (SG::auxid_t auxid) override
 Return (non-const) interface for a linked variable.
Functions implementing the @c SG::IAuxStore interface
virtual void * getData (SG::auxid_t auxid, std::size_t size, std::size_t capacity) override
 Get a pointer to a given array, creating the array if necessary.
virtual const SG::auxid_set_tgetWritableAuxIDs () const override
 Return a set of writable data identifiers.
virtual bool resize (std::size_t size) override
 Resize the arrays to a given size.
virtual void reserve (std::size_t size) override
 Reserve a given size for the arrays.
virtual void shift (std::size_t pos, std::ptrdiff_t offs) override
 Shift the contents of the stored arrays.
virtual bool insertMove (std::size_t pos, SG::IAuxStore &other, const SG::auxid_set_t &ignore) override
 Insert contents of another store via move.
Functions implementing the SG::IAuxStoreIO interface
virtual const void * getIOData (SG::auxid_t auxid) const override
 Get a pointer to the data being stored for one aux data item.
virtual const std::type_info * getIOType (SG::auxid_t auxid) const override
 Return the type of the data to be stored for one aux data item.
virtual const SG::auxid_set_tgetDynamicAuxIDs () const override
 Get the types(names) of variables created dynamically.
virtual void selectAux (const std::set< std::string > &attributes)
 Select dynamic auxiliary attributes for writing.
virtual SG::auxid_set_t getSelectedAuxIDs () const override
 Get the IDs of the selected aux variables.

Static Public Attributes

static constexpr bool supportsThinning = true
 Mark that this type supports thinning operations.

Protected Types

using mutex_t = AthContainers_detail::mutex
 Mutex type for multithread synchronization.
using guard_t = AthContainers_detail::lock_guard<mutex_t>
 Guard type for multithreaded synchronisation.

Protected Member Functions

bool isAuxIDSelected (SG::auxid_t auxid) const
 Check if an auxiliary variable is selected for ouput writing.

Protected Attributes

Members m_data
 Member variables of the base class.

Private Attributes

std::unique_ptr< implm_impl
 Pointer to the internal object.
AuxSelection m_selection
 Object helping to select which auxiliary variables to write.
bool m_locked = false
 Is this container locked?
mutex_t m_mutex1
 Mutex objects used for multithreaded synchronisation.
mutex_t m_mutex2

Functions implementing functionality for @c AuxStoreBase

virtual void reset () override
 Tell the object that all branches will need to be re-read.
virtual bool hasEntryFor (SG::auxid_t auxid) const override
 Check if a given variable is available from the input.
virtual StatusCode getEntryFor (SG::auxid_t auxid) override
 Load a single variable from the input.
virtual bool hasOutput () const override
 Check if an output is being written by the object.
virtual StatusCode setupInputData (SG::auxid_t auxid) override
 Connect a variable to the input.
virtual StatusCode setupOutputData (SG::auxid_t auxid) override
 Connect a variable to the output.
virtual const void * getInputObject (SG::auxid_t auxid) const override
 Get a pointer to an input object, as it is in memory, for getIOData()
virtual const std::type_info * getInputType (SG::auxid_t auxid) const override
 Get the type of an input object, for getIOType()

Detailed Description

"ROOT @c RNTuple implementation" of IAuxStore

Author
Mads Lildholdt Hansen mlha2.nosp@m.0@st.nosp@m.udent.nosp@m..aau.nosp@m..dk
Nikolaj Kofod Krogh nkrog.nosp@m.h20@.nosp@m.stude.nosp@m.nt.a.nosp@m.au.dk
Attila Krasznahorkay Attil.nosp@m.a.Kr.nosp@m.aszna.nosp@m.hork.nosp@m.ay@ce.nosp@m.rn.c.nosp@m.h

Definition at line 38 of file RAuxStore.h.

Member Typedef Documentation

◆ guard_t

Guard type for multithreaded synchronisation.

Definition at line 206 of file AuxStoreBase.h.

◆ mutex_t

Mutex type for multithread synchronization.

Definition at line 204 of file AuxStoreBase.h.

Member Enumeration Documentation

◆ EStructMode

enum class xAOD::details::AuxStoreBase::EStructMode
stronginherited

"Structural" modes of the object

Enumerator
kUndefinedStore 

The structure mode is not defined.

kContainerStore 

The object describes an entire container.

kObjectStore 

The object describes a single object.

Definition at line 30 of file AuxStoreBase.h.

30 {
31 kUndefinedStore = 0,
32 kContainerStore = 1,
33 kObjectStore = 2
34 };

Constructor & Destructor Documentation

◆ RAuxStore()

xAOD::RAuxStore::RAuxStore ( std::string_view prefix = "",
bool topStore = true,
EStructMode mode = EStructMode::kUndefinedStore )

Constructor.

Definition at line 596 of file RAuxStore.cxx.

597 : details::AuxStoreBase(topStore, mode),
598 m_impl{std::make_unique<impl>(m_data)} {
599
601}
std::unique_ptr< impl > m_impl
Pointer to the internal object.
Definition RAuxStore.h:89
virtual void setPrefix(std::string_view prefix) override
Set the object name prefix.
const std::string & prefix() const
Get the currently configured object name prefix.
Members m_data
Member variables of the base class.

◆ ~RAuxStore()

xAOD::RAuxStore::~RAuxStore ( )
virtualdefault

Destructor.

Member Function Documentation

◆ clearDecorations()

bool xAOD::details::AuxStoreBase::clearDecorations ( )
overridevirtualinherited

Remove the decorations added so far.

Only works for transient decorations.

Implements SG::IConstAuxStore.

Definition at line 216 of file AuxStoreBase.cxx.

216 {
217
218 // Guard against multi-threaded execution:
219 guard_t guard(m_mutex1);
220
221 // Clear the transient decorations:
222 bool anycleared = false;
223 if (m_data.m_transientStore) {
224 SG::auxid_set_t old_id_set = m_data.m_transientStore->getAuxIDs();
225
226 // Clear the decorations from the transient store:
227 anycleared = m_data.m_transientStore->clearDecorations();
228
229 // Now remove ids that were cleared.
230 if (anycleared) {
231 old_id_set -= m_data.m_transientStore->getAuxIDs();
232 // old_id_set is now the set of ids that were cleared.
233 m_data.m_auxIDs -= old_id_set;
234 m_data.m_decorIDs.clear();
235 }
236 }
237
238 // The decorations which are going into the output file, are here to stay.
239 // Removing their IDs from the internal set would just cause more problems
240 // in my mind than just leaving them be.
241
242 return anycleared;
243}
mutex_t m_mutex1
Mutex objects used for multithreaded synchronisation.
AthContainers_detail::lock_guard< mutex_t > guard_t
Guard type for multithreaded synchronisation.

◆ commitTo()

StatusCode xAOD::RAuxStore::commitTo ( ROOT::REntry & entry)

Commit a new entry to the output RNTuple.

Definition at line 716 of file RAuxStore.cxx.

716 {
717
718 assert(m_impl);
719
720 // Loop through all of the output variables.
721 for (SG::auxid_t id : getSelectedAuxIDs()) {
722 // Now connect the output entry to the variable.
723 const std::string fieldName =
724 std::format("{}{}", m_data.m_dynPrefix,
726 void* fieldPtr = const_cast<void*>(getIOData(id));
727 if (fieldPtr) {
728 entry.BindRawPtr(fieldName, fieldPtr);
729 } else {
730 entry.EmplaceNewValue(fieldName);
731 }
732 }
733
734 // Return gracefully.
735 return StatusCode::SUCCESS;
736}
std::string getName(SG::auxid_t auxid) const
Return the name of an aux data item.
static AuxTypeRegistry & instance()
Return the singleton registry instance.
virtual const void * getIOData(SG::auxid_t auxid) const override
Get a pointer to the data being stored for one aux data item.
virtual SG::auxid_set_t getSelectedAuxIDs() const override
Get the IDs of the selected aux variables.
size_t auxid_t
Identifier for a particular aux data item.
Definition AuxTypes.h:27

◆ getAuxIDs()

const SG::auxid_set_t & xAOD::details::AuxStoreBase::getAuxIDs ( ) const
overridevirtualinherited

Get the types(names) of variables handled by this container.

Implements SG::IConstAuxStore.

Definition at line 106 of file AuxStoreBase.cxx.

106 {
107
108 return m_data.m_auxIDs;
109}

◆ getData() [1/3]

virtual void * SG::IAuxStore::getData ( auxid_t auxid,
size_t size,
size_t capacity )
pure virtualinherited

Return the data vector for one aux data item.

Parameters
auxidThe identifier of the desired aux data item.
sizeThe current size of the container (in case the data item does not already exist).
capacityThe current capacity of the container (in case the data item does not already exist).

Each aux data item is stored as a vector, with one entry per entry in the owning container. This returns a pointer to the start of the vector.

If the data item does not exist, it should be created and initialized to default values. size and capacity give the size for the new aux data item vector.

If the container is locked, throw an exception.

Implemented in APRTest::AuxStore, RootAuxDynStore, SG::AuxStoreInternal, xAOD::AuxContainerBase, xAOD::AuxInfoBase, xAOD::ByteStreamAuxContainer_v1, and xAOD::ShallowAuxContainer.

◆ getData() [2/3]

const void * xAOD::details::AuxStoreBase::getData ( SG::auxid_t auxid) const
overridevirtualinherited

Get a pointer to a given array.

Implements SG::IConstAuxStore.

Definition at line 56 of file AuxStoreBase.cxx.

56 {
57
58 const SG::IAuxTypeVector* v = getVector(auxid);
59 if (v) {
60 return v->toPtr();
61 }
62 return nullptr;
63}
virtual const SG::IAuxTypeVector * getVector(SG::auxid_t auxid) const override
Return vector interface for one aux data item.

◆ getData() [3/3]

void * xAOD::details::AuxStoreBase::getData ( SG::auxid_t auxid,
std::size_t size,
std::size_t capacity )
overridevirtualinherited

Get a pointer to a given array, creating the array if necessary.

Definition at line 308 of file AuxStoreBase.cxx.

309 {
310
311 // Guard against multi-threaded execution:
312 guard_t guard(m_mutex2);
313
314 // Remember the size:
315 m_data.m_size = size;
316
317 // Check if we want to write this variable to the output:
318 if (!(isAuxIDSelected(auxid) && hasOutput())) {
319 // Create the store only when necessary:
320 if (!m_data.m_transientStore) {
321 m_data.m_transientStore = std::make_unique<SG::AuxStoreInternal>(
322 m_data.m_structMode == EStructMode::kObjectStore);
323 if (m_locked) {
324 m_data.m_transientStore->lock();
325 }
326 }
327 // Let the transient store create the variable:
328 std::size_t nids = m_data.m_transientStore->getAuxIDs().size();
329 void* result = m_data.m_transientStore->getData(auxid, size, capacity);
330 if (result && (nids != m_data.m_transientStore->getAuxIDs().size())) {
331 m_data.m_auxIDs.insert(auxid);
332 }
333 // Return the address in the transient memory:
334 return result;
335 }
336
337 // If the variable exists already, and this is a locked store, then
338 // we are in trouble.
339 if (m_locked && (auxid < m_data.m_vecs.size()) && m_data.m_vecs[auxid]) {
340 if (!((auxid < m_data.m_isDecoration.size()) &&
341 m_data.m_isDecoration[auxid])) {
342 throw SG::ExcStoreLocked(auxid);
343 }
344 }
345
346 // Connect this auxiliary variable just to the output:
347 if (setupOutputData(auxid).isFailure()) {
348 ::Error("xAOD::AuxStoreBase::getData",
349 XAOD_MESSAGE("Failed to set up variable %s"),
350 SG::AuxTypeRegistry::instance().getName(auxid).c_str());
351 return nullptr;
352 }
353
354 // Check whether things make sense:
355 if ((m_data.m_structMode == EStructMode::kObjectStore) && (size != 1)) {
356 ::Error("xAOD::AuxStoreBase::getData",
357 XAOD_MESSAGE("Branch creation requested with:"));
358 ::Error("xAOD::AuxStoreBase::getData", XAOD_MESSAGE(" name = %s"),
359 SG::AuxTypeRegistry::instance().getName(auxid).c_str());
360 ::Error("xAOD::AuxStoreBase::getData", XAOD_MESSAGE(" size = %i"),
361 static_cast<int>(size));
362 ::Error("xAOD::AuxStoreBase::getData",
363 XAOD_MESSAGE(" m_structMode = EStructMode::kObjectStore"));
364 return nullptr;
365 }
366
367 // Make sure the variable is of the right size:
368 m_data.m_vecs[auxid]->reserve(capacity);
369 m_data.m_vecs[auxid]->resize(size);
370
371 // Return the object:
372 return m_data.m_vecs[auxid]->toPtr();
373}
#define XAOD_MESSAGE(MESSAGE)
Simple macro for printing error/verbose messages.
virtual StatusCode setupOutputData(SG::auxid_t auxid)=0
Connect a variable to the output.
virtual bool hasOutput() const =0
Check if an output is being written by the object.
bool isAuxIDSelected(SG::auxid_t auxid) const
Check if an auxiliary variable is selected for ouput writing.
@ kObjectStore
The object describes a single object.
bool m_locked
Is this container locked?
virtual std::size_t size() const override
Return the number of elements in the store.

◆ getDecoration() [1/2]

virtual void * SG::IConstAuxStore::getDecoration ( auxid_t auxid,
size_t size,
size_t capacity )
pure virtualinherited

Return the data vector for one aux data decoration item.

Parameters
auxidThe identifier of the desired aux data item.
sizeThe current size of the container (in case the data item does not already exist).
capacityThe current capacity of the container (in case the data item does not already exist).

Each aux data item is stored as a vector, with one entry per entry in the owning container. This returns a pointer to the start of the vector.

If the data item does not exist, it then it will be created and initialized with default values. If the container is locked, then the new item will be marked as a decoration. size and capacity give the size for the new aux data item vector.

If the data item already exists, then we return it if either the container is not locked or the item is marked as a decoration. Otherwise we throw an exception.

Implemented in RootAuxDynStore, SG::AuxStoreConstMem, SG::AuxStoreInternal, xAOD::AuxContainerBase, xAOD::AuxInfoBase, xAOD::ByteStreamAuxContainer_v1, xAOD::EventAuxInfo_v1, xAOD::EventAuxInfo_v2, xAOD::EventAuxInfo_v3, xAOD::EventInfoAuxContainer_v1, and xAOD::ShallowAuxContainer.

◆ getDecoration() [2/2]

void * xAOD::details::AuxStoreBase::getDecoration ( SG::auxid_t auxid,
std::size_t size,
std::size_t capacity )
overridevirtualinherited

Get a pointer to a given array, creating the array if necessary.

Definition at line 116 of file AuxStoreBase.cxx.

117 {
118
119 // Guard against multi-threaded execution:
120 guard_t guard(m_mutex1);
121
122 // Remember the requested size:
123 m_data.m_size = size;
124
125 // If this is a locked object, deal with it correctly:
126 if (m_locked) {
127 // If the variable exists already and it's a decoration, then let's
128 // give it back.
129 if ((auxid < m_data.m_vecs.size()) && m_data.m_vecs[auxid] &&
130 (auxid < m_data.m_isDecoration.size() &&
131 m_data.m_isDecoration[auxid])) {
132 // Things look okay...
133 m_data.m_vecs[auxid]->reserve(capacity);
134 m_data.m_vecs[auxid]->resize(size);
135 return m_data.m_vecs[auxid]->toPtr();
136 }
137 // If it's in the transient store already, return it from there.
138 // Since in a locked store *everything* is a decoration in the
139 // transient store.
140 if (m_data.m_transientStore &&
141 m_data.m_transientStore->getAuxIDs().test(auxid)) {
142 return m_data.m_transientStore->getDecoration(auxid, size, capacity);
143 }
144 // If we know this auxiliary ID, but it was not found as a decoration
145 // by the previous checks, then we're in trouble.
146 if (m_data.m_auxIDs.test(auxid)) {
147 throw SG::ExcStoreLocked(auxid);
148 }
149 }
150
151 // Check if we want to write this variable to the output:
152 if (!(isAuxIDSelected(auxid) && hasOutput())) {
153
154 // Create the store only when necessary:
155 if (!m_data.m_transientStore) {
156 m_data.m_transientStore = std::make_unique<SG::AuxStoreInternal>(
157 m_data.m_structMode == EStructMode::kObjectStore);
158 if (m_locked) {
159 m_data.m_transientStore->lock();
160 }
161 }
162 // Let the transient store create the decoration:
163 const std::size_t nids = m_data.m_transientStore->getAuxIDs().size();
164 void* result =
165 m_data.m_transientStore->getDecoration(auxid, size, capacity);
166 if (result && (nids != m_data.m_transientStore->getAuxIDs().size())) {
167 if (m_data.m_transientStore->isDecoration(auxid)) {
168 m_data.m_decorIDs.insert(auxid);
169 }
170 std::atomic_thread_fence( std::memory_order_seq_cst );
171 m_data.m_auxIDs.insert(auxid);
172 }
173 // Return the memory address from the transient store:
174 return result;
175 }
176
177 // Doesn't exist yet. So let's make it:
178 if (m_locked) {
179 // If the container is locked, remember that this is a decoration:
180 if (m_data.m_isDecoration.size() <= auxid) {
181 m_data.m_isDecoration.resize(auxid + 1);
182 }
183 m_data.m_isDecoration[auxid] = true;
184 m_data.m_decorIDs.insert(auxid);
185 std::atomic_thread_fence( std::memory_order_seq_cst );
186 }
187 void* result = getData(auxid, size, capacity);
188
189 // Return the pointer made by getData(...):
190 return result;
191}
virtual const void * getData(SG::auxid_t auxid) const override
Get a pointer to a given array.

◆ getDecorIDs()

const SG::auxid_set_t & xAOD::details::AuxStoreBase::getDecorIDs ( ) const
overridevirtualinherited

Get the types(names) of decorations handled by this container.

Implements SG::IConstAuxStore.

Definition at line 111 of file AuxStoreBase.cxx.

111 {
112
113 return m_data.m_decorIDs;
114}

◆ getDynamicAuxIDs()

const SG::auxid_set_t & xAOD::details::AuxStoreBase::getDynamicAuxIDs ( ) const
overridevirtualinherited

Get the types(names) of variables created dynamically.

Implements SG::IAuxStoreIO.

Definition at line 617 of file AuxStoreBase.cxx.

617 {
618
619 // All the auxiliary decorations handled by this object are considered
620 // dynamic:
621 return getAuxIDs();
622}
virtual const SG::auxid_set_t & getAuxIDs() const override
Get the types(names) of variables handled by this container.

◆ getEntry()

StatusCode xAOD::RAuxStore::getEntry ( std::int64_t entry,
int getall = 0 )

Get entry from the input RNTuple.

Definition at line 667 of file RAuxStore.cxx.

667 {
668
669 assert(m_impl);
670
671 // Guard against multi-threaded execution:
672 guard_t guard(m_impl->m_mutex);
673
674 m_impl->m_entry = entry;
675
676 // Reset the transient store. TEvent::fill() calls this function with
677 // getall==99. When that is happening, we need to keep the transient
678 // store still around. Since the user may want to interact with the
679 // object after it was written out. (And since TEvent::fill() asks for
680 // the transient decorations after calling getEntry(...).)
681 if (m_data.m_transientStore && (getall != 99)) {
682 // Remove the transient auxiliary IDs from the internal list:
683 m_data.m_auxIDs -= m_data.m_transientStore->getAuxIDs();
684 m_data.m_decorIDs -= m_data.m_transientStore->getDecorIDs();
685 // Delete the object:
686 m_data.m_transientStore.reset();
687 }
688
689 // Now remove the IDs of the decorations that are getting persistified:
690 if (getall != 99) {
691 for (SG::auxid_t auxid = 0; auxid < m_data.m_isDecoration.size(); ++auxid) {
692 if (!m_data.m_isDecoration[auxid]) {
693 continue;
694 }
695 m_data.m_auxIDs.erase(auxid);
696 m_data.m_decorIDs.erase(auxid);
697 }
698 }
699
700 // If we don't need everything loaded, return now:
701 if (!getall) {
702 return StatusCode::SUCCESS;
703 }
704
705 // Get all the variables at once:
706 for (auto& field : m_impl->m_fields) {
707 if (field) {
708 RETURN_CHECK("xAOD::RAuxStore::getEntry", field->getEntry(entry));
709 }
710 }
711
712 // Return gracefully.
713 return StatusCode::SUCCESS;
714}
#define RETURN_CHECK(CONTEXT, EXP)
Helper macro for checking return codes in a compact form in the code.
Definition ReturnCheck.h:26

◆ getEntryFor()

StatusCode xAOD::RAuxStore::getEntryFor ( SG::auxid_t auxid)
overrideprivatevirtual

Load a single variable from the input.

Implements xAOD::details::AuxStoreBase.

Definition at line 756 of file RAuxStore.cxx.

756 {
757
758 // Guard against multi-threaded execution:
759 guard_t guard(m_impl->m_mutex);
760
761 assert(m_impl);
762 assert(m_impl->m_fields.size() > auxid);
763 assert(m_impl->m_fields[auxid]);
764 RETURN_CHECK("xAOD::RAuxStore::getEntryFor",
765 m_impl->m_fields[auxid]->getEntry(m_impl->m_entry));
766 return StatusCode::SUCCESS;
767}

◆ getInputObject()

const void * xAOD::RAuxStore::getInputObject ( SG::auxid_t auxid) const
overrideprivatevirtual

Get a pointer to an input object, as it is in memory, for getIOData()

Implements xAOD::details::AuxStoreBase.

Definition at line 1126 of file RAuxStore.cxx.

1126 {
1127
1128 assert(m_impl);
1129 assert(m_impl->m_fields.size() > auxid);
1130 assert(m_impl->m_fields[auxid]);
1131 return m_impl->m_fields[auxid]->objectPtr();
1132}

◆ getInputType()

const std::type_info * xAOD::RAuxStore::getInputType ( SG::auxid_t auxid) const
overrideprivatevirtual

Get the type of an input object, for getIOType()

Implements xAOD::details::AuxStoreBase.

Definition at line 1134 of file RAuxStore.cxx.

1134 {
1135
1136 assert(m_impl);
1137 assert(m_impl->m_fields.size() > auxid);
1138 assert(m_impl->m_fields[auxid]);
1139 return m_impl->m_fields[auxid]->typeInfo();
1140}

◆ getIOData()

const void * xAOD::details::AuxStoreBase::getIOData ( SG::auxid_t auxid) const
overridevirtualinherited

Get a pointer to the data being stored for one aux data item.

Implements SG::IAuxStoreIO.

Definition at line 519 of file AuxStoreBase.cxx.

519 {
520
521 // Guard against multi-threaded execution:
522 guard_t guard(m_mutex1);
523
524 auto this_nc ATLAS_THREAD_SAFE =
525 const_cast<AuxStoreBase*>(this); // locked above
526
527 // If the variable is coming from the input, and is connected to already.
528 if (hasEntryFor(auxid)) {
529 if (!this_nc->getEntryFor(auxid).isSuccess()) {
530 ::Error("xAOD::AuxStoreBase::getIOData",
531 XAOD_MESSAGE("Couldn't read in variable %s"),
532 SG::AuxTypeRegistry::instance().getName(auxid).c_str());
533 return nullptr;
534 }
535 return getInputObject(auxid);
536 }
537
538 // Check if it's in the transient store:
539 if (m_data.m_transientStore &&
540 m_data.m_transientStore->getAuxIDs().test(auxid)) {
541 return m_data.m_transientStore->getIOData(auxid);
542 }
543
544 // If not, try connecting to it now:
545 if (!this_nc->setupInputData(auxid).isSuccess()) {
546 // This is not actually an error condition anymore. We can end up here
547 // when we decorate constant objects coming from the input file, but
548 // on one event we can't set any decorations. For instance when the
549 // input container is empty. In that case the object will still list
550 // the auxiliary ID belonging to that decoration as being available,
551 // but it really isn't.
552 //
553 // Later on it might be needed to tweak the logic of all of this, but
554 // for now just silently returning 0 seems to do the right thing.
555 return nullptr;
556 }
557
558 // Now we should know this variable:
559 if (!hasEntryFor(auxid)) {
560 ::Fatal("xAOD::AuxStoreBase::getIOData",
561 XAOD_MESSAGE("Internal logic error detected"));
562 return nullptr;
563 }
564
565 // Make sure that the right payload is in memory:
566 if (!this_nc->getEntryFor(auxid).isSuccess()) {
567 ::Error("xAOD::AuxStoreBase::getIOData",
568 XAOD_MESSAGE("Couldn't read in variable %s"),
569 SG::AuxTypeRegistry::instance().getName(auxid).c_str());
570 return nullptr;
571 }
572
573 // Return the pointer.
574 return getInputObject(auxid);
575}
#define ATLAS_THREAD_SAFE
virtual bool hasEntryFor(SG::auxid_t auxid) const =0
Check if a given variable is available from the input.
AuxStoreBase(bool topStore=true, EStructMode mode=EStructMode::kUndefinedStore)
Constructor.
virtual const void * getInputObject(SG::auxid_t auxid) const =0
Get a pointer to an input object, as it is in memory, for getIOData()

◆ getIOType()

const std::type_info * xAOD::details::AuxStoreBase::getIOType ( SG::auxid_t auxid) const
overridevirtualinherited

Return the type of the data to be stored for one aux data item.

Implements SG::IAuxStoreIO.

Definition at line 578 of file AuxStoreBase.cxx.

578 {
579
580 // Guard against multi-threaded execution:
581 guard_t guard(m_mutex1);
582
583 // If the variable is connected to already:
584 if (hasEntryFor(auxid)) {
585 return getInputType(auxid);
586 }
587
588 // Check if it's in the transient store:
589 if (m_data.m_transientStore &&
590 m_data.m_transientStore->getAuxIDs().test(auxid)) {
591 return m_data.m_transientStore->getIOType(auxid);
592 }
593
594 // If not, try connecting to it now:
595 auto this_nc ATLAS_THREAD_SAFE =
596 const_cast<AuxStoreBase*>(this); // locked above
597 if (!this_nc->setupInputData(auxid).isSuccess()) {
598 ::Error("xAOD::AuxStoreBase::getIOType",
599 XAOD_MESSAGE("Couldn't connect to auxiliary variable "
600 "%i %s"),
601 static_cast<int>(auxid),
602 SG::AuxTypeRegistry::instance().getName(auxid).c_str());
603 return nullptr;
604 }
605
606 // Now we should know this variable:
607 if (!hasEntryFor(auxid)) {
608 ::Fatal("xAOD::AuxStoreBase::getIOType",
609 XAOD_MESSAGE("Internal logic error detected"));
610 return nullptr;
611 }
612
613 // Return the type info:
614 return getInputType(auxid);
615}
virtual const std::type_info * getInputType(SG::auxid_t auxid) const =0
Get the type of an input object, for getIOType()

◆ getSelectedAuxIDs()

SG::auxid_set_t xAOD::details::AuxStoreBase::getSelectedAuxIDs ( ) const
overridevirtualinherited

Get the IDs of the selected aux variables.

Reimplemented from SG::IAuxStoreIO.

Definition at line 632 of file AuxStoreBase.cxx.

632 {
633
634 // Guard against multi-threaded execution:
635 guard_t guard(m_mutex1);
636 // Leave the calculation up to the internal object:
637 return m_selection.getSelectedAuxIDs(m_data.m_auxIDs);
638}
AuxSelection m_selection
Object helping to select which auxiliary variables to write.

◆ getVector()

const SG::IAuxTypeVector * xAOD::details::AuxStoreBase::getVector ( SG::auxid_t auxid) const
overridevirtualinherited

Return vector interface for one aux data item.

Implements SG::IConstAuxStore.

Definition at line 65 of file AuxStoreBase.cxx.

65 {
66
67 // Guard against multi-threaded execution:
68 guard_t guard(m_mutex1);
69
70 // Check if the transient store already handles this variable:
71 if (m_data.m_transientStore &&
72 (m_data.m_transientStore->getAuxIDs().test(auxid))) {
73 return m_data.m_transientStore->getVector(auxid);
74 }
75
76 // Access the object through a non-const pointer. This is "safe" because
77 // of the mutex lock above.
78 auto this_nc ATLAS_THREAD_SAFE = const_cast<AuxStoreBase*>(this);
79
80 // Connect this auxiliary variable both to the input and output
81 // if needed:
82 if ((auxid >= m_data.m_vecs.size()) || (!m_data.m_vecs[auxid])) {
83 if ((!this_nc->setupInputData(auxid).isSuccess()) ||
84 (!this_nc->setupOutputData(auxid).isSuccess())) {
85 return nullptr;
86 }
87 }
88
89 // Make sure the variable is up to date:
90 if (this_nc->getEntryFor(auxid).isSuccess() == false) {
91 ::Error("xAOD::AuxStoreBase::getVector",
92 XAOD_MESSAGE("Couldn't read in variable %s"),
93 SG::AuxTypeRegistry::instance().getName(auxid).c_str());
94 return nullptr;
95 }
96
97 // Let the AuxTypeVector object know that the std::vector that it manages
98 // has changed. (This updates the cached span.)
99 SG::IAuxTypeVector* vec = m_data.m_vecs[auxid].get();
100 vec->resize (vec->size());
101
102 // Return the pointer to the object:
103 return vec;
104}
std::vector< size_t > vec

◆ getWritableAuxIDs()

const SG::auxid_set_t & xAOD::details::AuxStoreBase::getWritableAuxIDs ( ) const
overridevirtualinherited

Return a set of writable data identifiers.

Implements SG::IAuxStore.

Definition at line 375 of file AuxStoreBase.cxx.

375 {
376
377 return getAuxIDs();
378}

◆ hasEntryFor()

bool xAOD::RAuxStore::hasEntryFor ( SG::auxid_t auxid) const
overrideprivatevirtual

Check if a given variable is available from the input.

Implements xAOD::details::AuxStoreBase.

Definition at line 750 of file RAuxStore.cxx.

750 {
751
752 assert(m_impl);
753 return ((m_impl->m_fields.size() > auxid) && m_impl->m_fields[auxid]);
754}

◆ hasOutput()

bool xAOD::RAuxStore::hasOutput ( ) const
overrideprivatevirtual

Check if an output is being written by the object.

Implements xAOD::details::AuxStoreBase.

Definition at line 769 of file RAuxStore.cxx.

769 {
770
771 assert(m_impl);
772 return (m_impl->m_outTuple != nullptr);
773}

◆ insertMove() [1/2]

virtual bool SG::IAuxStore::insertMove ( size_t pos,
IAuxStore & other,
const SG::auxid_set_t & ignore = SG::auxid_set_t() )
pure virtualinherited

Move all elements from other to this store.

Parameters
posThe starting index of the insertion.
otherStore from which to do the move.
ignoreSet of variables that should not be added to the store.

Let len be the size of other. The store will be increased in size by len elements, with the elements at pos being copied to pos+len. Then, for each auxiliary variable, the entire contents of that variable for other will be moved to this store at index pos. This will be done via move semantics if possible; otherwise, it will be done with a copy. Variables present in this store but not in other will have the corresponding elements default-initialized. Variables in other but not in this store will be added unless they are in ignore.

Returns true if it is known that none of the vectors' memory moved, false otherwise.

Implemented in SG::AuxStoreInternal.

◆ insertMove() [2/2]

bool xAOD::details::AuxStoreBase::insertMove ( std::size_t pos,
SG::IAuxStore & other,
const SG::auxid_set_t & ignore )
overridevirtualinherited

Insert contents of another store via move.

Definition at line 469 of file AuxStoreBase.cxx.

470 {
471 // Guard against multi-threaded execution:
472 guard_t guard(m_mutex1);
473
474 // A sanity check:
475 if (m_data.m_structMode == EStructMode::kObjectStore) {
476 ::Error("xAOD::AuxStoreBase::insertMove",
477 XAOD_MESSAGE("Should not have been called for single-object "
478 "store"));
479 return false;
480 }
481
482 bool nomove = true;
483 std::size_t other_size = other.size();
484
485 SG::auxid_set_t ignore = ignore_in;
486
487 for (SG::auxid_t id : m_data.m_auxIDs) {
488 SG::IAuxTypeVector* v_dst = nullptr;
489 if (id < m_data.m_vecs.size()) {
490 v_dst = m_data.m_vecs[id].get();
491 }
492 if (v_dst && !v_dst->isLinked()) {
493 ignore.insert(id);
494 if (other.getData(id)) {
495 void* src_ptr = other.getData(id, other_size, other_size);
496 if (src_ptr) {
497 if (!v_dst->insertMove(pos, src_ptr, 0, other_size, other)) {
498 nomove = false;
499 }
500 }
501 } else {
502 const void* orig = v_dst->toPtr();
503 v_dst->shift(pos, other_size);
504 if (orig != v_dst->toPtr()) {
505 nomove = false;
506 }
507 }
508 }
509 }
510
511 if (m_data.m_transientStore) {
512 if (!m_data.m_transientStore->insertMove(pos, other, ignore))
513 nomove = false;
514 }
515
516 return nomove;
517}
bool isLinked() const
Return true if this variable is linked from another one.
virtual void * toPtr()=0
Return a pointer to the start of the vector's data.
virtual bool insertMove(size_t pos, void *src, size_t src_pos, size_t src_n, IAuxStore &srcStore)=0
Insert elements into the vector via move semantics.
virtual bool shift(size_t pos, ptrdiff_t offs)=0
Shift the elements of the vector.

◆ isAuxIDSelected()

bool xAOD::details::AuxStoreBase::isAuxIDSelected ( SG::auxid_t auxid) const
protectedinherited

Check if an auxiliary variable is selected for ouput writing.

This is a tricky one.

The function can't just rely on getSelectedAuxIDs, as the aux ID received here may be a new ID that the object doesn't yet know about. So we have no other choice but to check this ID explicitly.

@apram auxid The auxiliary ID that should be checked

Returns
true if the variable needs to be written out, false if not

Definition at line 648 of file AuxStoreBase.cxx.

648 {
649
650 // A temporary object:
651 SG::auxid_set_t auxids;
652 auxids.insert(auxid);
653
654 // Check if the auxid is returned as a selected ID:
655 return m_selection.getSelectedAuxIDs(auxids).size();
656}
ConcurrentBitset & insert(bit_t bit, bit_t new_nbits=0)
Set a bit to 1.

◆ isDecoration()

bool xAOD::details::AuxStoreBase::isDecoration ( SG::auxid_t auxid) const
overridevirtualinherited

Test if a variable is a decoration.

Implements SG::IConstAuxStore.

Definition at line 193 of file AuxStoreBase.cxx.

193 {
194 if (m_locked) {
195 if (auxid < m_data.m_isDecoration.size() && m_data.m_isDecoration[auxid]) {
196 return true;
197 }
198 if (m_data.m_transientStore) {
199 return m_data.m_transientStore->isDecoration(auxid);
200 }
201 }
202 return false;
203}

◆ isTopStore()

bool xAOD::details::AuxStoreBase::isTopStore ( ) const
inherited

Check if the object is a "top store", or not.

Definition at line 45 of file AuxStoreBase.cxx.

45 {
46
47 return m_data.m_topStore;
48}

◆ linkedVector() [1/2]

const SG::IAuxTypeVector * xAOD::details::AuxStoreBase::linkedVector ( SG::auxid_t auxid) const
overridevirtualinherited

Return (const) interface for a linked variable.

Reimplemented from SG::IConstAuxStore.

Definition at line 281 of file AuxStoreBase.cxx.

281 {
282 const SG::AuxTypeRegistry& r = SG::AuxTypeRegistry::instance();
283 SG::auxid_t linked_id = r.linkedVariable(auxid);
284 guard_t guard(m_mutex1);
285 if (linked_id < m_data.m_vecs.size()) {
286 return m_data.m_vecs[linked_id].get();
287 }
288 if (m_data.m_transientStore) {
289 return CxxUtils::as_const_ptr(m_data.m_transientStore.get())
290 ->linkedVector(auxid);
291 }
292 return nullptr;
293}
int r
Definition globals.cxx:22
const T * as_const_ptr(const T *p)
Helper for getting a const version of a pointer.

◆ linkedVector() [2/2]

SG::IAuxTypeVector * xAOD::details::AuxStoreBase::linkedVector ( SG::auxid_t auxid)
overridevirtualinherited

Return (non-const) interface for a linked variable.

Reimplemented from SG::IAuxStore.

Definition at line 295 of file AuxStoreBase.cxx.

295 {
296 const SG::AuxTypeRegistry& r = SG::AuxTypeRegistry::instance();
297 SG::auxid_t linked_id = r.linkedVariable(auxid);
298 guard_t guard(m_mutex1);
299 if (linked_id < m_data.m_vecs.size()) {
300 return m_data.m_vecs[linked_id].get();
301 }
302 if (m_data.m_transientStore) {
303 return m_data.m_transientStore->linkedVector(auxid);
304 }
305 return nullptr;
306}

◆ lock()

void xAOD::details::AuxStoreBase::lock ( )
overridevirtualinherited

Lock the object, and don't let decorations be added.

Implements SG::IConstAuxStore.

Definition at line 205 of file AuxStoreBase.cxx.

205 {
206
207 // Guard against multi-threaded execution:
208 guard_t guard(m_mutex1);
209
210 m_locked = true;
211 if (m_data.m_transientStore) {
212 m_data.m_transientStore->lock();
213 }
214}

◆ lockDecoration()

void xAOD::details::AuxStoreBase::lockDecoration ( SG::auxid_t auxid)
overridevirtualinherited

Lock a decoration.

Implements SG::IConstAuxStore.

Definition at line 246 of file AuxStoreBase.cxx.

246 {
247 if (m_data.m_transientStore) {
248 m_data.m_transientStore->lockDecoration(auxid);
249 }
250 m_data.m_decorIDs.erase(auxid);
251}

◆ prefix()

const std::string & xAOD::details::AuxStoreBase::prefix ( ) const
inherited

Get the currently configured object name prefix.

Definition at line 40 of file AuxStoreBase.cxx.

40 {
41
42 return m_data.m_prefix;
43}

◆ readFrom()

StatusCode xAOD::RAuxStore::readFrom ( ROOT::RNTupleReader & reader)

Connect the object to an input RNTuple.

This function is called by the infrastructure to connect the object to an input RNTuple whenever a new input file is opened.

Parameters
readerThe reader object set up by a parent object
Returns
StatusCode::SUCCESS if the function was successful, something else otherwise

Definition at line 619 of file RAuxStore.cxx.

619 {
620
621 assert(m_impl);
622
623 // Make sure that everything will be re-read after this:
624 reset();
625
626 // We will need to check again which branches are available:
627 m_impl->m_missingFields.clear();
628
629 // Remember the tree:
630 m_impl->m_inTuple = &reader;
631
632 // Catalogue all the branches:
633 RETURN_CHECK("xAOD::RAuxStore::readFrom", m_impl->scanInputTuple());
634
635 // Return gracefully.
636 return StatusCode::SUCCESS;
637}
virtual void reset() override
Tell the object that all branches will need to be re-read.
reader
read the goodrunslist xml file(s)
Definition collisions.py:22

◆ reserve() [1/2]

virtual void SG::IAuxStore::reserve ( size_t sz)
pure virtualinherited

Change the capacity of all aux data vectors.

Parameters
szThe new capacity.

This should be called when the capacity of the container changes (by reserve). This should change the capacity for the vectors for all aux data items.

Implemented in SG::AuxStoreInternal, xAOD::AuxContainerBase, xAOD::AuxInfoBase, xAOD::ByteStreamAuxContainer_v1, and xAOD::ShallowAuxContainer.

◆ reserve() [2/2]

void xAOD::details::AuxStoreBase::reserve ( std::size_t size)
overridevirtualinherited

Reserve a given size for the arrays.

Definition at line 413 of file AuxStoreBase.cxx.

413 {
414
415 // Guard against multi-threaded execution:
416 guard_t guard(m_mutex1);
417
418 // A sanity check:
419 if ((m_data.m_structMode == EStructMode::kObjectStore) && (size != 1)) {
420 ::Error("xAOD::AuxStoreBase::reserve",
421 XAOD_MESSAGE("size = %i for single-object store"),
422 static_cast<int>(size));
423 return;
424 }
425
426 for (auto& v : m_data.m_vecs) {
427 if (v && !v->isLinked()) {
428 v->reserve(size);
429 }
430 }
431
432 if (m_data.m_transientStore) {
433 m_data.m_transientStore->reserve(size);
434 }
435}

◆ reset()

void xAOD::RAuxStore::reset ( )
overridevirtual

Tell the object that all branches will need to be re-read.

Implements xAOD::details::AuxStoreBase.

Definition at line 738 of file RAuxStore.cxx.

738 {
739
740 assert(m_impl);
741
742 for (auto& field : m_impl->m_fields) {
743 if (field) {
744 field->reset();
745 }
746 }
747 m_impl->m_inputScanned = false;
748}

◆ resize() [1/2]

virtual bool SG::IAuxStore::resize ( size_t sz)
pure virtualinherited

Change the size of all aux data vectors.

Parameters
szThe new size.

This should be called when the size of the container changes. This should resize the vectors for all aux data items.

If the size of the container grows, the new elements should be default-initialized; if it shrinks, destructors should be run as appropriate.

Should return true if it is known that none of the data pointers changed (and thus the cache does not need to be cleared), false otherwise.

Implemented in SG::AuxStoreInternal, xAOD::AuxContainerBase, xAOD::AuxInfoBase, xAOD::ByteStreamAuxContainer_v1, and xAOD::ShallowAuxContainer.

◆ resize() [2/2]

bool xAOD::details::AuxStoreBase::resize ( std::size_t size)
overridevirtualinherited

Resize the arrays to a given size.

Definition at line 380 of file AuxStoreBase.cxx.

380 {
381
382 // Guard against multi-threaded execution:
383 guard_t guard(m_mutex1);
384
385 // A sanity check:
386 if ((m_data.m_structMode == EStructMode::kObjectStore) && (size != 1)) {
387 ::Error("xAOD::AuxStoreBase::resize",
388 XAOD_MESSAGE("size = %i for single-object store"),
389 static_cast<int>(size));
390 return false;
391 }
392
393 // Remember the new size:
394 m_data.m_size = size;
395
396 bool nomoves = true;
397 for (auto& v : m_data.m_vecs) {
398 if (v && !v->isLinked()) {
399 if (!v->resize(size)) {
400 nomoves = false;
401 }
402 }
403 }
404 if (m_data.m_transientStore) {
405 if (!m_data.m_transientStore->resize(size)) {
406 nomoves = false;
407 }
408 }
409
410 return nomoves;
411}

◆ selectAux()

void xAOD::details::AuxStoreBase::selectAux ( const std::set< std::string > & attributes)
virtualinherited

Select dynamic auxiliary attributes for writing.

Definition at line 625 of file AuxStoreBase.cxx.

625 {
626
627 guard_t guard(m_mutex1);
628 m_selection.selectAux(attributes);
629}

◆ setOption()

virtual bool SG::IAuxStore::setOption ( auxid_t ,
const AuxDataOption &  )
inlinevirtualinherited

Set an option for a given auxiliary variable.

Parameters
auxidThe identifier of the desired aux data item.
optionThe option to set.

The interpretation of the option depends on the particular representation of the variable.

Returns true if the option setting was successful; false otherwise.

Reimplemented in SG::AuxStoreInternal, xAOD::AuxContainerBase, and xAOD::AuxInfoBase.

Definition at line 173 of file IAuxStore.h.

174 { return false; }

◆ setPrefix()

void xAOD::RAuxStore::setPrefix ( std::string_view prefix)
overridevirtual

Set the object name prefix.

Implements xAOD::details::AuxStoreBase.

Definition at line 605 of file RAuxStore.cxx.

605 {
606
607 m_data.m_prefix = prefix;
608 m_data.m_dynPrefix = Utils::dynFieldPrefix(m_data.m_prefix);
609 reset();
610}
std::string dynFieldPrefix(const std::string &key)
This function is used to figure out what to name dynamic auxiliary field coming from a container call...

◆ setStructMode()

void xAOD::details::AuxStoreBase::setStructMode ( EStructMode mode)
inherited

Set the structure mode of the object to a new value.

Definition at line 34 of file AuxStoreBase.cxx.

34 {
35
36 m_data.m_structMode = mode;
37 reset();
38}
virtual void reset()=0
Reset all (transient) information in the object.

◆ setTopStore()

void xAOD::details::AuxStoreBase::setTopStore ( bool value = true)
inherited

Set whether the object should behave as a "top store" or not.

Definition at line 50 of file AuxStoreBase.cxx.

50 {
51
52 m_data.m_topStore = value;
53 reset();
54}

◆ setupInputData()

StatusCode xAOD::RAuxStore::setupInputData ( SG::auxid_t auxid)
overrideprivatevirtual

Connect a variable to the input.

This internal function takes care of connecting to an individual (sub-)field in the input file for a given auxiliary variable.

Parameters
auxidThe ID of the variable to connect to
Returns
StatusCode::SUCCESS if the function was successful, something else otherwise

Implements xAOD::details::AuxStoreBase.

Definition at line 782 of file RAuxStore.cxx.

782 {
783
784 // Return right away if we already know that the field is missing.
785 if ((auxid < m_impl->m_missingFields.size()) &&
786 m_impl->m_missingFields[auxid]) {
787 return StatusCode::RECOVERABLE;
788 }
789
790 // We may call this function without an input being used. That's not an
791 // error either.
792 if (m_impl->m_inTuple == nullptr) {
793 return StatusCode::RECOVERABLE;
794 }
795
796 // Make sure the internal storage is large enough:
797 if (m_data.m_vecs.size() <= auxid) {
798 m_data.m_vecs.resize(auxid + 1);
799 }
800 if (m_impl->m_fields.size() <= auxid) {
801 m_impl->m_fields.resize(auxid + 1);
802 }
803
804 // Check if we need to do anything. Remember, output-only variables don't
805 // have an associated RFieldHandle. To tell the caller that no input is
806 // actually available for the variable (only an output), use a different
807 // return value.
808 if (m_data.m_vecs[auxid]) {
809 return (m_impl->m_fields[auxid] ? StatusCode::SUCCESS
810 : StatusCode::RECOVERABLE);
811 }
812
813 // Convenience access to the registry.
814 const SG::AuxTypeRegistry& r = SG::AuxTypeRegistry::instance();
815
816 // Get the property name:
817 const std::string statFieldName =
818 std::format("{}{}", m_data.m_prefix, r.getName(auxid));
819 const std::string dynFieldName =
820 std::format("{}{}", m_data.m_dynPrefix, r.getName(auxid));
821
822 // Check if the field exists:
823 std::string fieldName = statFieldName;
824 ROOT::DescriptorId_t fieldId;
825 if ((fieldId = m_impl->m_inTuple->GetDescriptor().FindFieldId(
826 statFieldName)) == std::numeric_limits<unsigned long>::max()) {
827 if ((fieldId = m_impl->m_inTuple->GetDescriptor().FindFieldId(
828 dynFieldName)) == std::numeric_limits<unsigned long>::max()) {
829 // Remember that the field is missing.
830 if (m_impl->m_missingFields.size() <= auxid) {
831 m_impl->m_missingFields.resize(auxid + 1);
832 }
833 m_impl->m_missingFields[auxid] = true;
834 // The field doesn't exist, but this is not an error per se.
835 // The user may just be calling isAvailable(...) on the variable.
836 return StatusCode::RECOVERABLE;
837 }
838 // We have a dynamic field:
839 fieldName = std::move(dynFieldName);
840 }
841
842 // Get the object describing this field.
843 const ROOT::RFieldDescriptor& fieldDesc =
844 m_impl->m_inTuple->GetDescriptor().GetFieldDescriptor(fieldId);
845
846 // Check if it's a "primitive field":
847 const bool primitiveField = Utils::isPrimitiveType(fieldDesc.GetTypeName());
848 // Check if it's a "container field":
849 const bool containerField =
850 (primitiveField ? false : isContainerField(fieldDesc, auxid));
851
852 // Set the structure mode if it has not been defined externally:
853 if (m_data.m_structMode == EStructMode::kUndefinedStore) {
854 m_data.m_structMode = (containerField ? EStructMode::kContainerStore
856 }
857
858 // Check that the branch type makes sense:
859 if ((containerField &&
860 (m_data.m_structMode != EStructMode::kContainerStore) &&
861 !r.isLinked(auxid)) ||
862 ((!containerField) &&
863 (m_data.m_structMode != EStructMode::kObjectStore))) {
864 ::Error("xAOD::RAuxStore::setupInputData",
865 XAOD_MESSAGE("Field type and requested structure mode "
866 "differ for field: %s"),
867 fieldName.c_str());
868 return StatusCode::FAILURE;
869 }
870
871 // Get the property type:
872 const std::type_info* fieldType = nullptr;
873 if (details::isRegisteredType(auxid)) {
874 // Get the type from the auxiliary type registry:
875 fieldType = (containerField ? r.getVecType(auxid) : r.getType(auxid));
876 } else {
877 // Get the type from the input field itself:
878 TClass* clDummy = ::TClass::GetClass(fieldDesc.GetTypeName().c_str());
879 fieldType = (clDummy ? clDummy->GetTypeInfo()
880 : &(Utils::getTypeInfo(fieldDesc.GetTypeName())));
881 }
882 if (!fieldType) {
883 ::Error("xAOD::RAuxStore::setupInputData",
884 XAOD_MESSAGE("Can't read/copy variable %s (%s)"), fieldName.c_str(),
885 fieldDesc.GetTypeName().c_str());
886 return StatusCode::RECOVERABLE;
887 }
888 const TString fieldTypeName = Utils::getTypeName(*fieldType).c_str();
889
890 // Check if we have the needed dictionary for an object field:
891 ::TClass* fieldClass = nullptr;
892 if (!primitiveField) {
893 // Get the property's class:
894 fieldClass = ::TClass::GetClass(*fieldType, true, true);
895 if (!fieldClass) {
896 fieldClass = ::TClass::GetClass(fieldTypeName);
897 }
898 if (!fieldClass) {
899 ::Error("xAOD::RAuxStore::setupInputData",
900 XAOD_MESSAGE("No dictionary available for class \"%s\""),
901 fieldTypeName.Data());
902 return StatusCode::FAILURE;
903 }
904 }
905
906 // Create the smart object holding this vector:
907 if (details::isRegisteredType(auxid)) {
908 m_data.m_vecs[auxid] = r.makeVector(auxid, (size_t)0, (size_t)0);
909 if (!containerField) {
910 m_data.m_vecs[auxid]->resize(1);
911 }
912 if (fieldClass &&
913 strncmp(fieldClass->GetName(), "SG::PackedContainer<", 20) == 0) {
914 std::unique_ptr<SG::IAuxTypeVector> packed =
915 m_data.m_vecs[auxid]->toPacked();
916 std::swap(m_data.m_vecs[auxid], packed);
917 }
918 } else {
919 ::Error("xAOD::RAuxStore::setupInputData",
920 XAOD_MESSAGE("Couldn't create in-memory vector for "
921 "variable %s (%i)"),
922 fieldName.c_str(), static_cast<int>(auxid));
923 return StatusCode::FAILURE;
924 }
925
926 // Access/create the field, and create a field handle object.
927 void* objectPtr = (containerField ? m_data.m_vecs[auxid]->toVector()
928 : m_data.m_vecs[auxid]->toPtr());
929 m_impl->m_fields[auxid] = std::make_unique<RFieldHandle>(
930 m_impl->m_inTuple->GetView<void>(fieldName.c_str(), objectPtr), auxid,
931 m_data.m_prefix, objectPtr, fieldType);
932
933 // Get the current entry.
934 RETURN_CHECK("xAOD::RAuxStore::setupInputData",
935 m_impl->m_fields[auxid]->getEntry(m_impl->m_entry));
936
937 // Remember which variable got created:
938 m_data.m_auxIDs.insert(auxid);
939
940 // Check if we just replaced a generic object:
941 if (details::isRegisteredType(auxid)) {
942 // The name of the variable we just created:
943 const std::string auxname = r.getName(auxid);
944 // Check if there's another variable with this name already:
945 for (SG::auxid_t i = 0; i < m_data.m_vecs.size(); ++i) {
946 // Check if we have this aux ID:
947 if (!m_data.m_vecs[i]) {
948 continue;
949 }
950 // Ingore the object that we *just* created:
951 if (i == auxid) {
952 continue;
953 }
954 // The name of the variable:
955 const std::string testname = r.getName(i);
956 // Check if it has the same name:
957 if (testname != auxname) {
958 continue;
959 }
960 // Check that the other one is a non-registered type:
962 ::Error("xAOD::RAuxStore::setupInputData",
963 XAOD_MESSAGE("Internal logic error!"));
964 continue;
965 }
966 // Okay, we do need to remove this object:
967 m_data.m_vecs[i].reset();
968 m_impl->m_fields[i].reset();
969 m_data.m_auxIDs.erase(i);
970 }
971 }
972
973 SG::auxid_t linked_auxid = r.linkedVariable(auxid);
974 if (linked_auxid != SG::null_auxid) {
975 return setupInputData(linked_auxid);
976 }
977
978 // Return gracefully:
979 return StatusCode::SUCCESS;
980}
virtual StatusCode setupInputData(SG::auxid_t auxid) override
Connect a variable to the input.
@ kUndefinedStore
The structure mode is not defined.
@ kContainerStore
The object describes an entire container.
H5::CompType packed(H5::CompType in)
Definition common.cxx:16
static const auxid_t null_auxid
To signal no aux data item.
Definition AuxTypes.h:30
void swap(ElementLinkVector< DOBJ > &lhs, ElementLinkVector< DOBJ > &rhs)
const std::type_info & getTypeInfo(EDataType type)
This function is used when reading a primitive branch from an input file without the user explicitly ...
bool isPrimitiveType(std::string_view typeName)
Check if the type name describes a primitive type.
std::string getTypeName(const std::type_info &ti)
This function is necessary in order to create type names that ROOT can understand.
bool isRegisteredType(SG::auxid_t auxid)
Check if the auxiliary variable has a registered type.

◆ setupOutputData()

StatusCode xAOD::RAuxStore::setupOutputData ( SG::auxid_t auxid)
overrideprivatevirtual

Connect a variable to the output.

This function is used internally to create an output field with the contents of a single auxiliary variable.

Parameters
auxidThe ID of the variable to create an output field for
Returns
StatusCode::SUCCESS if the function was successful, something else otherwise

Implements xAOD::details::AuxStoreBase.

Definition at line 989 of file RAuxStore.cxx.

989 {
990
991 assert(m_impl);
992
993 // Check whether we need to do anything.
994 if (!m_impl->m_outTuple) {
995 return StatusCode::SUCCESS;
996 }
997
998 // Check if the variable needs to be written out.
999 if (!isAuxIDSelected(auxid)) {
1000 return StatusCode::SUCCESS;
1001 }
1002
1003 // Make sure that containers are large enough:
1004 if (m_data.m_vecs.size() <= auxid) {
1005 m_data.m_vecs.resize(auxid + 1);
1006 }
1007 if (m_impl->m_fieldsWritten.size() <= auxid) {
1008 m_impl->m_fieldsWritten.resize(auxid + 1);
1009 }
1010
1011 // Check if this auxiliary variable is already in the output:
1012 if (m_impl->m_fieldsWritten[auxid]) {
1013 return StatusCode::SUCCESS;
1014 }
1015
1016 // After this point, we either succeed with setting up the writing of this
1017 // variable, or the code fails completely. So let's set this flag already,
1018 // as unfortunately we can recursively end up here using the code below.
1019 m_impl->m_fieldsWritten[auxid] = true;
1020
1021 // The registry:
1022 SG::AuxTypeRegistry& reg = SG::AuxTypeRegistry::instance();
1023
1024 // Check if the variable was put into the transient store as a
1025 // decoration, and now needs to be put into the output file:
1026 if ((!m_data.m_vecs[auxid]) && m_data.m_transientStore &&
1027 (m_data.m_transientStore->getAuxIDs().test(auxid))) {
1028
1029 // Get the variable from the transient store:
1030 const void* pptr = m_data.m_transientStore->getData(auxid);
1031 if (!pptr) {
1032 ::Fatal("xAOD::RAuxStore::setupOutputData",
1033 XAOD_MESSAGE("Internal logic error detected"));
1034 return StatusCode::FAILURE;
1035 }
1036
1037 // Create the new object:
1038 m_data.m_vecs[auxid] = reg.makeVector(auxid, m_data.m_size, m_data.m_size);
1039 void* ptr = m_data.m_vecs[auxid]->toPtr();
1040 if (!ptr) {
1041 ::Error("xAOD::RAuxStore::setupOutputData",
1042 XAOD_MESSAGE("Couldn't create decoration in memory "
1043 "for writing"));
1044 return StatusCode::FAILURE;
1045 }
1046
1047 // Get the type of this variable:
1048 const std::type_info* type = reg.getType(auxid);
1049 if (!type) {
1050 ::Error("xAOD::RAuxStore::setupOutputData",
1051 XAOD_MESSAGE("Couldn't get the type of transient "
1052 "variable %i"),
1053 static_cast<int>(auxid));
1054 return StatusCode::FAILURE;
1055 }
1056 // Now get the factory for this variable:
1057 const SG::IAuxTypeVectorFactory* factory = reg.getFactory(auxid);
1058 if (!factory) {
1059 ::Error("xAOD::RAuxStore::setupOutputData",
1060 XAOD_MESSAGE("No factory found for transient variable "
1061 "%i"),
1062 static_cast<int>(auxid));
1063 return StatusCode::FAILURE;
1064 }
1065
1066 // Mark it as a decoration already, otherwise the copy may fail.
1067 if (m_data.m_isDecoration.size() <= auxid) {
1068 m_data.m_isDecoration.resize(auxid + 1);
1069 }
1070 m_data.m_isDecoration[auxid] = true;
1071
1072 // Finally, do the copy, and remove the variable from the transient store.
1073 factory->copy(auxid, SG::AuxVectorInterface(*this), 0,
1074 SG::AuxVectorInterface(*m_data.m_transientStore), 0,
1075 m_data.m_size);
1076 }
1077
1078 // Check if we know about this variable to be on the input,
1079 // but haven't connected to it yet:
1080 if ((m_data.m_auxIDs.test(auxid)) && (!m_data.m_vecs[auxid]) &&
1081 (!m_impl->m_fields[auxid])) {
1082 RETURN_CHECK("xAOD::RAuxStore::setupOutputData", setupInputData(auxid));
1083 }
1084
1085 // Check that we know the store's type:
1086 if ((m_data.m_structMode != EStructMode::kContainerStore) &&
1087 (m_data.m_structMode != EStructMode::kObjectStore)) {
1088 ::Error("xAOD::RAuxStore::setupOutputData",
1089 XAOD_MESSAGE("Structure mode unknown for variable %s"),
1090 reg.getName(auxid).c_str());
1091 return StatusCode::FAILURE;
1092 }
1093
1094 // Check if the variable exists already in memory:
1095 if (!m_data.m_vecs[auxid]) {
1096 m_data.m_vecs[auxid] = reg.makeVector(auxid, (size_t)0, (size_t)0);
1097 if (m_data.m_structMode == EStructMode::kObjectStore) {
1098 m_data.m_vecs[auxid]->resize(1);
1099 }
1100 }
1101
1102 // Figure out the type and name of the output field.
1103 const std::string fieldName =
1104 std::format("{}{}", m_data.m_dynPrefix, reg.getName(auxid));
1105 const std::string typeName = SG::normalizedTypeinfoName(
1106 *(m_data.m_structMode == EStructMode::kContainerStore
1107 ? reg.getVecType(auxid)
1108 : reg.getType(auxid)));
1109
1110 // Update the output ntuple's model.
1111 {
1112 auto field = ROOT::RFieldBase::Create(fieldName, typeName).Unwrap();
1113 auto updater = m_impl->m_outTuple->CreateModelUpdater();
1114 updater->BeginUpdate();
1115 updater->AddField(std::move(field));
1116 updater->CommitUpdate();
1117 }
1118
1119 // Remember that we now handle this variable.
1120 m_data.m_auxIDs.insert(auxid);
1121
1122 // We were successful:
1123 return StatusCode::SUCCESS;
1124}
virtual void copy(SG::auxid_t auxid, AuxVectorData &dst, size_t dst_index, const AuxVectorData &src, size_t src_index, size_t n) const =0
Copy elements between vectors.
std::string normalizedTypeinfoName(const std::type_info &info)
Convert a type_info to a normalized string representation (matching the names used in the root dictio...
void * ptr(T *p)
Definition SGImplSvc.cxx:74

◆ shift() [1/2]

virtual void SG::IAuxStore::shift ( size_t pos,
ptrdiff_t offs )
pure virtualinherited

Shift the elements of the container.

Parameters
posThe starting index for the shift.
offsThe (signed) amount of the shift.

This operation shifts the elements in the vectors for all aux data items, to implement an insertion or deletion. offs may be either positive or negative.

If offs is positive, then the container is growing. The container size should be increased by offs, the element at pos moved to pos + offs, and similarly for following elements. The elements between pos and pos + offs should be default-initialized.

If offs is negative, then the container is shrinking. The element at pos should be moved to pos + offs, and similarly for following elements. The container should then be shrunk by -offs elements (running destructors as appropriate).

Implemented in SG::AuxStoreInternal, xAOD::AuxContainerBase, xAOD::AuxInfoBase, xAOD::ByteStreamAuxContainer_v1, and xAOD::ShallowAuxContainer.

◆ shift() [2/2]

void xAOD::details::AuxStoreBase::shift ( std::size_t pos,
std::ptrdiff_t offs )
overridevirtualinherited

Shift the contents of the stored arrays.

Definition at line 437 of file AuxStoreBase.cxx.

437 {
438
439 // Guard against multi-threaded execution:
440 guard_t guard(m_mutex1);
441
442 // A sanity check:
443 if (m_data.m_structMode == EStructMode::kObjectStore) {
444 ::Error("xAOD::AuxStoreBase::shift",
445 XAOD_MESSAGE("Should not have been called for single-object "
446 "store"));
447 return;
448 }
449
450 // Adjust the size of the container:
451 if ((static_cast<std::size_t>(std::abs(offs)) > m_data.m_size) &&
452 (offs < 0)) {
453 m_data.m_size = 0;
454 } else {
455 m_data.m_size += offs;
456 }
457
458 for (auto& v : m_data.m_vecs) {
459 if (v && !v->isLinked()) {
460 v->shift(pos, offs);
461 }
462 }
463
464 if (m_data.m_transientStore) {
465 m_data.m_transientStore->shift(pos, offs);
466 }
467}

◆ size()

std::size_t xAOD::details::AuxStoreBase::size ( ) const
overridevirtualinherited

Return the number of elements in the store.

Implements SG::IConstAuxStore.

Definition at line 253 of file AuxStoreBase.cxx.

253 {
254
255 // First, try to find a managed vector in the store:
256 for (SG::auxid_t id : m_data.m_auxIDs) {
257 // Make sure that we are still within the bounds of our vector:
258 if (id >= m_data.m_vecs.size())
259 break;
260 // Skip non-existent or linked objects:
261 if (!m_data.m_vecs[id] || m_data.m_vecs[id]->isLinked()) {
262 continue;
263 }
264 // Ask the vector for its size:
265 const std::size_t size = m_data.m_vecs[id]->size();
266 // Only accept a non-zero size. Not sure why...
267 if (size > 0) {
268 return size;
269 }
270 }
271
272 // Check if we have a transient store, and get the size from that:
273 if (m_data.m_transientStore) {
274 return m_data.m_transientStore->size();
275 }
276
277 // Apparently the store is empty:
278 return 0;
279}

◆ structMode()

auto xAOD::details::AuxStoreBase::structMode ( ) const
inherited

Get what structure mode the object was constructed with.

Definition at line 29 of file AuxStoreBase.cxx.

29 {
30
31 return m_data.m_structMode;
32}

◆ writeTo()

StatusCode xAOD::RAuxStore::writeTo ( ROOT::RNTupleWriter & writer)

Add the variables of the store to an output RNTuple.

This function is called by the infrastructure to connect the object to an output RNTuple.

Parameters
writerThe writer object used for creating an output ntuple
Returns
kTRUE if successful, kFALSE otherwise

Definition at line 645 of file RAuxStore.cxx.

645 {
646
647 assert(m_impl);
648
649 // Look for any auxiliary fields that have not been connected to yet.
650 RETURN_CHECK("xAOD::RAuxStore::writeTo", m_impl->scanInputTuple());
651
652 // Put the object into "output writing" mode.
653 m_impl->m_outTuple = &writer;
654
655 // Create all the variables that we already know about. Notice that the
656 // code makes a copy of the auxid set on purpose. Because the underlying
657 // AuxSelection object gets modified while doing the for loop.
658 const SG::auxid_set_t selAuxIDs = getSelectedAuxIDs();
659 for (SG::auxid_t id : selAuxIDs) {
660 RETURN_CHECK("xAOD::RAuxStore::writeTo", setupOutputData(id));
661 }
662
663 // Return gracefully.
664 return StatusCode::SUCCESS;
665}
virtual StatusCode setupOutputData(SG::auxid_t auxid) override
Connect a variable to the output.
writer
show summary of content
Definition example.py:36

Member Data Documentation

◆ m_data

Members xAOD::details::AuxStoreBase::m_data
protectedinherited

Member variables of the base class.

Definition at line 201 of file AuxStoreBase.h.

◆ m_impl

std::unique_ptr<impl> xAOD::RAuxStore::m_impl
private

Pointer to the internal object.

Definition at line 89 of file RAuxStore.h.

◆ m_locked

bool xAOD::details::AuxStoreBase::m_locked = false
privateinherited

Is this container locked?

Definition at line 212 of file AuxStoreBase.h.

◆ m_mutex1

mutex_t xAOD::details::AuxStoreBase::m_mutex1
mutableprivateinherited

Mutex objects used for multithreaded synchronisation.

Definition at line 214 of file AuxStoreBase.h.

◆ m_mutex2

mutex_t xAOD::details::AuxStoreBase::m_mutex2
privateinherited

Definition at line 214 of file AuxStoreBase.h.

◆ m_selection

AuxSelection xAOD::details::AuxStoreBase::m_selection
privateinherited

Object helping to select which auxiliary variables to write.

Definition at line 210 of file AuxStoreBase.h.

◆ supportsThinning

bool SG::IAuxStore::supportsThinning = true
staticconstexprinherited

Mark that this type supports thinning operations.

See AthContainers/supportsThinning.h and AthenaPoolCnvSvc/T_AthenaPoolCnv.h. Helps guide which pool converter template will be used. If false, the default pool converter will be used rather than the aux store-specific one. Ordinary xAOD type should not touch this, but may be overridden in a derived class to handle certain special cases.

Definition at line 199 of file IAuxStore.h.


The documentation for this class was generated from the following files: