ATLAS Offline Software
Loading...
Searching...
No Matches
xAODShallowAuxContainerCnv.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
10
11
16
19 const std::string& key)
20{
21// std::cout << "Thinning shallow aux, size = " << trans->size() << std::endl;
22 if (trans->size() > 0) {
23
24
26 const xAOD::ShallowAuxContainer& orig = *trans; //need the 'const' version to ensure use the const methods!
27 size_t size = orig.size();
28 size_t nremaining = size;
29
30 std::string key2 = key;
31 if (key2.size() >= 4 && key2.substr (key2.size()-4, 4) == "Aux.")
32 {
33 key2.erase (key2.size()-4, 4);
34 }
35 const SG::ThinningInfo* info = SG::getThinningInfo (key2);
36 const SG::ThinningDecisionBase* dec = info ? info->m_decision : nullptr;
37 if (dec) {
38 nremaining = dec->thinnedSize();
39 }
40
41 //if there is no thinning to do, then just return a regular copy
42 // Be sure to also check for variable vetoes.
43 if(!dec) {
45 if (info) {
46 ids = orig.getSelectedAuxIDs();
47 ids &= info->m_vetoed;
48 }
49 if (ids.empty()) {
50 return new xAOD::ShallowAuxContainer(orig);
51 }
52 }
53 xAOD::ShallowAuxContainer* newcont = new xAOD::ShallowAuxContainer; //dont use copy constructor (like copyThinned.h), want it to have it's own internal store
54 newcont->setParent(trans->parent());
55
56 // newcont should be set for shallow IO regardless of the setting
57 // of the original container. Below we're going to copy all the
58 // variables that should be written. Any variables left in the
59 // parent that are not also in newcont are ones that were
60 // explicitly vetoed.
61 newcont->setShallowIO(true);
62
63 // Access the auxiliary type registry:
65 // The auxiliary IDs that the original container has:
66 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();
67 SG::auxid_set_t sel_auxids = orig.getSelectedAuxIDs();
68
69 newcont->getStore()->resize(nremaining); //had to access underlying store directly, can't call 'resize' on container
70
71 SG::AuxVectorInterface dstIface (*newcont->getStore());
72 SG::AuxVectorInterface srcIface (orig);
73
74 // Loop over all the variables of the original container:
75 for (SG::auxid_t auxid : auxids) {
76 // Skip null auxids (happens if we don't have the dictionary)
77 if(auxid == SG::null_auxid) continue;
78 // Skip non-selected dynamic variables.
79 if (info && info->vetoed (auxid)) continue;
80 if (sel_auxids.count(auxid) == 0) continue;
81 // Create the target variable:
82 (void)newcont->getStore()->getData (auxid, nremaining, nremaining); //use store's getData directly, not the container's getData ... saves on a copy!
83
84 // Access the source variable:
85 const void* src = orig.getData (auxid);
86
87 if (!src) continue;
88
89 // Copy over all elements.
90 if (nremaining == size) {
91 // No thinning.
92 r.copyForOutput (auxid, dstIface, 0, srcIface, 0, size);
93 }
94 else {
95 // Thinning
96 for (std::size_t isrc = 0, idst = 0; isrc < size; ++isrc) {
97 if ( ! (dec && dec->thinned(isrc)) ) {
98 r.copyForOutput (auxid, dstIface, idst, srcIface, isrc, 1);
99 ++idst;
100 }
101 }
102 }
103 }
105
106/* HERE is the old code which is non optimal, but functional if modification to 'resize' method of shallowauxcontainer is made
107 newcont->setShallowIO(false); //necessary so that branch selections work
108 copyAuxStoreThinned (*trans, *newcont, dec); //FIXME: In this methods call to 'getData' it ends up doing an unnecessary copy of the parent store's values!
109*/ // std::cout << " Thinned size = " << newcont->size() << std::endl;
110 return newcont;
111 }
112 return new xAOD::ShallowAuxContainer(*trans);
113}
114
Handle mappings between names and auxid_t.
Make an AuxVectorData object from either a raw vector or an aux store.
bit_t count() const
Count the number of 1 bits in the set.
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
virtual xAOD::ShallowAuxContainer * createTransientWithKey(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 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.