ATLAS Offline Software
Loading...
Searching...
No Matches
xAODShallowAuxContainerCnv.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
10#include "GaudiKernel/ThreadLocalContext.h"
11
12
17
20 const std::string& key)
21{
22// std::cout << "Thinning shallow aux, size = " << trans->size() << std::endl;
23 if (trans->size() > 0) {
24
25
27 const xAOD::ShallowAuxContainer& orig = *trans; //need the 'const' version to ensure use the const methods!
28 size_t size = orig.size();
29 size_t nremaining = size;
30
31 std::string key2 = key;
32 if (key2.size() >= 4 && key2.substr (key2.size()-4, 4) == "Aux.")
33 {
34 key2.erase (key2.size()-4, 4);
35 }
36 const SG::ThinningInfo* info = SG::getThinningInfo (key2);
37 const SG::ThinningDecisionBase* dec = info ? info->m_decision : nullptr;
38 if (dec) {
39 nremaining = dec->thinnedSize();
40 }
41
42 //if there is no thinning to do, then just return a regular copy
43 // Be sure to also check for variable vetoes.
44 if(!dec) {
46 if (info) {
47 ids = orig.getSelectedAuxIDs();
48 ids &= info->m_vetoed;
49 }
50 if (ids.empty()) {
51 return new xAOD::ShallowAuxContainer(orig);
52 }
53 }
54 xAOD::ShallowAuxContainer* newcont = new xAOD::ShallowAuxContainer; //dont use copy constructor (like copyThinned.h), want it to have it's own internal store
55 newcont->setParent(trans->parent());
56
57 // newcont should be set for shallow IO regardless of the setting
58 // of the original container. Below we're going to copy all the
59 // variables that should be written. Any variables left in the
60 // parent that are not also in newcont are ones that were
61 // explicitly vetoed.
62 newcont->setShallowIO(true);
63
64 // Access the auxiliary type registry:
66 // The auxiliary IDs that the original container has:
67 SG::auxid_set_t auxids = orig.getDynamicAuxIDs(); //all ids of a shallow container are dynamic, don't look at the parents unless not in shallow IO mode //orig.getAuxIDs();
68 SG::auxid_set_t sel_auxids = orig.getSelectedAuxIDs();
69
70 newcont->getStore()->resize(nremaining); //had to access underlying store directly, can't call 'resize' on container
71
72 SG::AuxVectorInterface dstIface (*newcont->getStore());
73 SG::AuxVectorInterface srcIface (orig);
74
75 // Loop over all the variables of the original container:
76 for (SG::auxid_t auxid : auxids) {
77 // Skip null auxids (happens if we don't have the dictionary)
78 if(auxid == SG::null_auxid) continue;
79 // Skip non-selected dynamic variables.
80 if (info && info->vetoed (auxid)) continue;
81 if (sel_auxids.count(auxid) == 0) continue;
82 // Create the target variable:
83 (void)newcont->getStore()->getData (auxid, nremaining, nremaining); //use store's getData directly, not the container's getData ... saves on a copy!
84
85 // Access the source variable:
86 const void* src = orig.getData (auxid);
87
88 if (!src) continue;
89
90 // Copy over all elements.
91 if (nremaining == size) {
92 // No thinning.
93 r.copyForOutput (auxid, dstIface, 0, srcIface, 0, size);
94 }
95 else {
96 // Thinning
97 for (std::size_t isrc = 0, idst = 0; isrc < size; ++isrc) {
98 if ( ! (dec && dec->thinned(isrc)) ) {
99 r.copyForOutput (auxid, dstIface, idst, srcIface, isrc, 1);
100 ++idst;
101 }
102 }
103 }
104 }
106
107/* HERE is the old code which is non optimal, but functional if modification to 'resize' method of shallowauxcontainer is made
108 newcont->setShallowIO(false); //necessary so that branch selections work
109 copyAuxStoreThinned (*trans, *newcont, dec); //FIXME: In this methods call to 'getData' it ends up doing an unnecessary copy of the parent store's values!
110*/ // std::cout << " Thinned size = " << newcont->size() << std::endl;
111 return newcont;
112 }
113 return new xAOD::ShallowAuxContainer(*trans);
114}
115
117xAODShallowAuxContainerCnv::createTransientWithKey ( const Token* token, const std::string& /*key*/ ) {
119 o->toTransient (Gaudi::Hive::currentContext());
120 return o;
121}
Handle mappings between names and auxid_t.
Make an AuxVectorData object from either a raw vector or an aux store.
size_t size() const
Number of registered mappings.
Handle mappings between names and auxid_t.
static AuxTypeRegistry & instance()
Return the singleton registry instance.
Make an AuxVectorData object from either a raw array or an aux store.
virtual bool resize(size_t sz)=0
Change the size of all aux data vectors.
virtual void * getData(auxid_t auxid, size_t size, size_t capacity)=0
Return the data vector for one aux data item.
Hold thinning decisions for one container.
bool thinned(size_t ndx) const
Return true if element ndx should be thinned.
size_t thinnedSize() const
Return the size of the container being thinned after thinning.
Hold thinning/slimming information for a given object.
A set of aux data identifiers.
Definition AuxTypes.h:47
This class provides a token that identifies in a unique way objects on the persistent storage.
Definition Token.h:22
virtual xAOD::ShallowAuxContainer * createTransientWithKey(const Token *token, const std::string &key) override
Function reading in the object from the input file.
virtual xAOD::ShallowAuxContainer * createPersistentWithKey(xAOD::ShallowAuxContainer *trans, const std::string &key) override
Function preparing the container to be written out.
xAODShallowAuxContainerCnv(ISvcLocator *svcLoc)
Converter constructor.
Class creating a shallow copy of an existing auxiliary container.
virtual const void * getData(auxid_t auxid) const override
Get a pointer to a given array.
void setParent(const DataLink< SG::IConstAuxStore > &link)
Set the parent store.
virtual const auxid_set_t & getDynamicAuxIDs() const override
Get the types(names) of variables created dynamically.
virtual SG::IAuxStore * getStore() override
Get the currently used internal store object.
virtual void toTransient(const EventContext &ctx) override
Perform processing on aux variable objects just after reading to make them usable as transient object...
virtual size_t size() const override
Get the size of the container.
void setShallowIO(bool value)
Set whether only the overriden parameters should be written out.
virtual auxid_set_t getSelectedAuxIDs() const override
Get the IDs of the selected dynamic Aux variables (for writing).
const DataLink< SG::IConstAuxStore > & parent() const
Get the parent store.
Helper to copy an object while applying thinning.
Helpers to retrieve the current thinning cache from the event context.
int r
Definition globals.cxx:22
static const auxid_t null_auxid
To signal no aux data item.
Definition AuxTypes.h:30
const SG::ThinningInfo * getThinningInfo(const EventContext &ctx, const std::string &key)
Retrieve the current thinning information for key.
size_t auxid_t
Identifier for a particular aux data item.
Definition AuxTypes.h:27
T_AthenaPoolCustomCnvWithKey< xAOD::ShallowAuxContainer, xAOD::ShallowAuxContainer > xAODShallowAuxContainerCnvBase
Base class for the converter.