18#include <TVirtualCollectionProxy.h>
34 TempInterface (
size_t size) : m_size (size) {}
35 TempInterface (
size_t size,
SG::auxid_t auxid,
void* ptr) :
38 setCache (auxid, ptr);
41 using AuxVectorData::setStore;
43 virtual size_t size_v()
const {
return m_size; }
44 virtual size_t capacity_v()
const {
return m_size; }
80 if( ! evtStore.
retrieve( c, key ).isSuccess() ) {
81 msg << MSG::ERROR <<
"Couldn't retrieve container with key \"" <<
key
86 if( holder !=
nullptr ) {
91 cl = TClass::GetClass( *ti );
95 cl = TClass::GetClass(
typeid( *c ) );
97 if( ( allowMissing ==
false ) && ( cl ==
nullptr ) ) {
99 <<
"Couldn't find TClass dictionary for container \"" <<
key
128 if( ! evtStore.
retrieve( e, key ).isSuccess() ) {
129 msg << MSG::ERROR <<
"Couldn't retrieve object with key \"" <<
key
139 class ProxyWithName {
142 typedef const SG::DataProxy* argument_type;
144 ProxyWithName(
const std::string& name ) : m_name(
name ) {}
146 bool operator()( argument_type proxy )
const {
147 return (
proxy->name() == m_name );
172 auto proxies = evtStore.
proxies();
174 std::not_fn( ProxyWithName( key ) ) ),
186 <<
"Couldn't access data object as a data bucket?!?" <<
endmsg;
190 cl = TClass::GetClass( bucket->
tinfo() );
192 if(
msg.level() <= MSG::VERBOSE ) {
193 msg << MSG::VERBOSE <<
"No dictionary found for: "
199 if( !
cl->InheritsFrom(
"SG::AuxVectorBase" ) ) {
200 if(
msg.level() <= MSG::VERBOSE ) {
201 msg << MSG::VERBOSE <<
"Object \"" <<
key <<
"/" <<
cl->GetName()
202 <<
"\" does not inherit from SG::AuxVectorBase" <<
endmsg;
213 if( ! allowMissing ) {
214 msg << MSG::ERROR <<
"Couldn't retrieve object \"" <<
key
215 <<
"\" as SG::AuxVectorBase" <<
endmsg;
238 if( !evtStore.
retrieve( e, key ).isSuccess() ) {
240 msg << MSG::ERROR <<
"Couldn't retrieve object with key \"" <<
key
261 switch( typeidType ) {
299 msg << MSG::ERROR <<
"Received an unknown type: " << typeidType
311 bool auxItemExists(
const std::string& key ) {
327 return StatusCode::FAILURE;
337 return StatusCode::SUCCESS;
349 return StatusCode::FAILURE;
360 static const bool ALLOW_MISSING =
false;
363 ALLOW_MISSING,
msg() );
365 ATH_MSG_ERROR(
"Failed to retrieve object \"" << element_itr.first
367 return StatusCode::FAILURE;
370 ATH_CHECK( element_itr.second.process( *el ) );
376 static const bool ALLOW_MISSING =
false;
377 const TClass* cl =
nullptr;
380 ALLOW_MISSING, cl,
msg() );
383 << container_itr.first <<
"\"" );
384 return StatusCode::FAILURE;
391 return StatusCode::SUCCESS;
397 return StatusCode::SUCCESS;
404 for(
const std::string& branchDecl :
m_branches ) {
416 for(
const std::string& branchDecl :
m_branches ) {
422 return StatusCode::SUCCESS;
438 static const std::regex
439 re(
"\\s*([\\w%]+)\\.([\\w%]+)\\s*->\\s*([\\w%]+)" );
443 if( ! std::regex_match( branchDecl,
match,
re ) ) {
445 <<
"\" doesn't match \"<object>.<variable> ->"
447 return StatusCode::FAILURE;
451 bool nominal = sys.empty();
453 bool systematicsContainer{
false};
454 bool systematicsDecoration{
false};
455 bool affectedContainer{
true};
456 bool affectedDecoration{
true};
459 std::string key =
match[ 1 ];
460 if( key.find(
"%SYS%" ) != std::string::npos )
462 systematicsContainer =
true;
466 if( !nominal && matching.
empty() ) {
467 ATH_MSG_VERBOSE(
"Container \"" << key <<
"\" is not affected by systematics \"" << sys.name() <<
"\"" );
468 affectedContainer =
false;
473 std::string auxName =
match[ 2 ];
474 if( auxName.find(
"%SYS%" ) != std::string::npos )
476 systematicsDecoration =
true;
478 if( affecting.
empty() )
484 const auto nosysInKey = key.find(
"NOSYS" );
485 if( nosysInKey != std::string::npos )
487 std::string sysKey = key;
488 sysKey.replace (nosysInKey, 5,
"%SYS%");
495 if( affectingObject.
find( variation ) == affectingObject.
end() )
497 affecting.
insert( variation );
504 if( !nominal && matching.
empty() ) {
505 ATH_MSG_VERBOSE(
"Decoration \"" << auxName <<
"\" is not affected by systematics \"" << sys.name() <<
"\"" );
506 affectedDecoration =
false;
513 && ( ( systematicsContainer && systematicsDecoration && !affectedContainer && !affectedDecoration )
514 || ( !systematicsContainer && systematicsDecoration && !affectedDecoration )
515 || ( systematicsContainer && !systematicsDecoration && !affectedContainer ) ) )
517 ANA_MSG_VERBOSE(
"Neither container nor decoration are affected by systematics \"" << sys.name() <<
"\""
518 <<
" for branch rule \"" << branchDecl <<
"\"" );
519 return StatusCode::SUCCESS;
523 std::string brName =
match[ 3 ];
524 if( brName.find(
"%SYS%" ) != std::string::npos )
530 ( key ==
match[ 1 ] ) && ( auxName ==
match[ 2 ] ) &&
531 ( brName ==
match[ 3 ] ) ) {
532 return StatusCode::SUCCESS;
536 if( ( ( key ==
match[ 1 ] ) && ( auxName ==
match[ 2 ] ) &&
537 ( brName !=
match[ 3 ] ) ) ||
538 ( ( ( key !=
match[ 1 ] ) || ( auxName !=
match[ 2 ] ) ) &&
539 ( brName ==
match[ 3 ] ) ) ) {
541 "inconsistently in: \"" << branchDecl
543 return StatusCode::FAILURE;
547 bool branchCreated =
false;
551 static const bool ALLOW_MISSING =
true;
552 const TClass* cl =
nullptr;
557 store->getDynamicAuxIDs();
558 bool created =
false;
566 <<
"\" from container/variable \"" << key
567 <<
"." << auxName <<
"\"" );
568 branchCreated =
true;
571 <<
"\" from container/variable \"" << key
572 <<
"." << auxName <<
"\"" );
575 ALLOW_MISSING,
msg() ) ) {
577 if (
const auto *store =
dynamic_cast<const SG::IAuxStoreIO *
>(ele->getConstStore()))
578 store->getDynamicAuxIDs();
579 bool created =
false;
587 <<
"\" from object/variable \"" << key
588 <<
"." << auxName <<
"\"" );
589 branchCreated =
true;
592 <<
"\" from object/variable \"" << key
593 <<
"." << auxName <<
"\"" );
597 <<
"\" not readable for expression: \""
598 << branchDecl <<
"\"" );
602 if( ! branchCreated ) {
604 << branchDecl <<
"\""
605 <<
" and systematics: \""
606 << sys.name() <<
"\"" );
607 return StatusCode::FAILURE;
611 return StatusCode::SUCCESS;
628 return StatusCode::SUCCESS;
633 const std::string& branchName,
643 BranchFinder(
const std::string& branchName ) :
m_name( branchName ) {}
645 bool operator()( argument_type bp )
const {
646 return ( bp.m_branchName ==
m_name );
653 bool validAuxItem = auxItemExists( auxName );
654 if( ! validAuxItem ) {
658 <<
"\" not readable for branch \""
659 << branchName <<
"\"" );
660 return StatusCode::SUCCESS;
664 <<
"\" not readable for branch \""
665 << branchName <<
"\"" );
666 return StatusCode::FAILURE;
672 BranchFinder( branchName ) );
674 ATH_MSG_WARNING(
"Duplicate setup received for branch: " << branchName );
675 return StatusCode::SUCCESS;
685 return StatusCode::SUCCESS;
690 setup( TTree&
tree,
const std::string& auxName,
691 const std::string& branchName, MsgStream&
msg ) {
701 const std::type_info* ti = reg.getType(
m_acc->auxid() );
704 <<
"No std::type_info available for auxiliary variable: "
706 return StatusCode::FAILURE;
710 msg << MSG::ERROR <<
"No factory found for auxiliary variable: "
712 return StatusCode::FAILURE;
719 TBranch* br =
nullptr;
722 if( strlen( ti->name() ) == 1 ) {
727 const char rType = rootType( ti->name()[ 0 ],
msg );
728 if( rType ==
'\0' ) {
729 msg << MSG::ERROR <<
"Type not recognised for variable: "
731 return StatusCode::FAILURE;
735 std::ostringstream typeDesc;
736 typeDesc << branchName <<
"/" << rType;
739 br =
tree.Branch( branchName.c_str(),
m_data->toPtr(),
740 typeDesc.str().c_str() );
750 TClass* cl = TClass::GetClass( *ti );
752 cl = TClass::GetClass( typeName.c_str() );
755 msg << MSG::ERROR <<
"Couldn't find dictionary for type: "
757 return StatusCode::FAILURE;
759 if( ! cl->GetStreamerInfo() ) {
760 msg << MSG::ERROR <<
"No streamer info available for type: "
761 << cl->GetName() <<
endmsg;
762 return StatusCode::FAILURE;
767 br =
tree.Branch( branchName.c_str(), cl->GetName(), &
m_dataPtr );
773 msg << MSG::ERROR <<
"Failed to create branch: " << branchName
775 return StatusCode::FAILURE;
779 return StatusCode::SUCCESS;
788 msg << MSG::FATAL <<
"Internal logic error detected" <<
endmsg;
789 return StatusCode::FAILURE;
801 return StatusCode::SUCCESS;
805 :
asg::
AsgMessaging(
"CP::AsgxAODNTupleMakerAlg::ContainerProcessor" ) {
820 return StatusCode::FAILURE;
825 static const TClass*
const auxElementClass =
828 m_collProxy->GetValueClass()->GetBaseClassOffset( auxElementClass );
832 <<
"\" doesn't seem to inherit from \""
833 << auxElementClass->GetName() <<
"\"" );
834 return StatusCode::FAILURE;
841 const_cast< void*
>(
static_cast< const void*
>( &
container ) );
842 TVirtualCollectionProxy::TPushPop helper(
m_collProxy, cPtr );
851 for( UInt_t i = 0; i < cSize; ++i ) {
854 char* elPtr =
static_cast< char*
>(
m_collProxy->At( i ) );
856 ATH_MSG_ERROR(
"Failed to get element " << i <<
" from container" );
857 return StatusCode::FAILURE;
870 return StatusCode::SUCCESS;
875 const std::string& branchName,
885 BranchFinder(
const std::string& branchName ) :
m_name( branchName ) {}
887 bool operator()( argument_type bp )
const {
888 return ( bp.m_branchName ==
m_name );
895 bool validAuxItem = auxItemExists( auxName );
896 if( ! validAuxItem ) {
900 <<
"\" not readable for branch \""
901 << branchName <<
"\"" );
902 return StatusCode::SUCCESS;
906 <<
"\" not readable for branch \""
907 << branchName <<
"\"" );
908 return StatusCode::FAILURE;
914 BranchFinder( branchName ) );
916 ATH_MSG_WARNING(
"Duplicate setup received for branch: " << branchName );
917 return StatusCode::SUCCESS;
927 return StatusCode::SUCCESS;
931 setup( TTree&
tree,
const std::string& auxName,
932 const std::string& branchName, MsgStream&
msg ) {
942 const std::type_info* ti = reg.getType(
m_acc->auxid() );
943 const std::type_info* vecTi = reg.getVecType(
m_acc->auxid() );
944 if( ( ! ti ) || ( ! vecTi ) ) {
946 <<
"No std::type_info available for auxiliary variable: "
948 return StatusCode::FAILURE;
952 msg << MSG::ERROR <<
"No factory found for auxiliary variable: "
954 return StatusCode::FAILURE;
964 TClass* cl = TClass::GetClass( *vecTi );
966 cl = TClass::GetClass( typeName.c_str() );
969 msg << MSG::ERROR <<
"Couldn't find dictionary for type: "
971 return StatusCode::FAILURE;
973 if( ! cl->GetStreamerInfo() ) {
974 msg << MSG::ERROR <<
"No streamer info available for type: "
975 << cl->GetName() <<
endmsg;
976 return StatusCode::FAILURE;
981 TBranch* br =
tree.Branch( branchName.c_str(), cl->GetName(),
984 msg << MSG::ERROR <<
"Failed to create branch: " << branchName
986 return StatusCode::FAILURE;
990 return StatusCode::SUCCESS;
998 msg << MSG::FATAL <<
"Internal logic error detected" <<
endmsg;
999 return StatusCode::FAILURE;
1007 return StatusCode::SUCCESS;
1015 msg << MSG::FATAL <<
"Internal logic error detected" <<
endmsg;
1016 return StatusCode::FAILURE;
1028 return StatusCode::SUCCESS;
const boost::regex re(r_e)
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
Base class for elements of a container that can have aux data.
Manage index tracking and synchronization of auxiliary data.
std::vector< size_t > vec
Interface providing I/O for a generic auxiliary store.
Interface for factory objects that create vectors.
#define ATLAS_NOT_CONST_THREAD_SAFE
ServiceHandle< StoreGateSvc > & evtStore()
TTree * tree(const std::string &treeName, const std::string &tDir="", const std::string &stream="")
Simplify the retrieval of registered TTrees.
std::string m_name
Instance name.
Class writing one variable from an xAOD object into a branch.
std::unique_ptr< SG::IAuxTypeVector > m_data
The object managing the memory of the written variable.
StatusCode process(const SG::AuxElement &element, size_t index, MsgStream &msg)
Function processing the object, filling the variable.
std::string m_branchName
Name of the branch being written.
const SG::IAuxTypeVectorFactory * m_factory
Pointer to the helper object that handles this variable.
void * m_dataPtr
Helper variable, pointing at the object to be written.
StatusCode setup(TTree &tree, const std::string &auxName, const std::string &branchName, MsgStream &msg)
Function setting up the object, and the branch.
std::unique_ptr< SG::TypelessConstAccessor > m_acc
Object accessing the variable in question.
StatusCode resize(size_t size, MsgStream &msg)
Function (re)sizing the variable for a new event.
StatusCode process(const SG::AuxVectorBase &container, const TClass &cl)
Process the container.
std::list< BranchProcessor > m_branches
List of branch processors set up for this xAOD object.
ContainerProcessor()
Default constructor.
StatusCode addBranch(TTree &tree, const std::string &auxName, const std::string &branchName, bool allowMissing, bool &created)
Add one branch to the output tree.
TVirtualCollectionProxy * m_collProxy
Collection proxy used for iterating over the container.
int m_auxElementOffset
Offset of the element type to SG::AuxElement.
Class writing one variable from an xAOD object into a branch.
std::unique_ptr< SG::TypelessConstAccessor > m_acc
Object accessing the variable in question.
const SG::IAuxTypeVectorFactory * m_factory
Pointer to the helper object that handles this variable.
StatusCode setup(TTree &tree, const std::string &auxName, const std::string &branchName, MsgStream &msg)
Function setting up the object, and the branch.
void * m_dataPtr
Helper variable, pointing at the object to be written.
std::string m_branchName
Name of the branch being written.
std::unique_ptr< SG::IAuxTypeVector > m_data
The object managing the memory of the written variable.
StatusCode process(const SG::AuxElement &element, MsgStream &msg)
Function processing the object, filling the variable.
StatusCode process(const SG::AuxElement &element)
Process the object.
StatusCode addBranch(TTree &tree, const std::string &auxName, const std::string &branchName, bool allowMissing, bool &created)
Add one branch to the output tree.
std::list< BranchProcessor > m_branches
List of branch processors set up for this xAOD object.
ElementProcessor()
Default constructor.
ServiceHandle< ISystematicsSvc > m_systematicsService
the handle for the systematics service
StatusCode execute() override
Function executed once per event.
StatusCode setupBranch(const std::string &branchDecl, const CP::SystematicSet &sys)
Function setting up an individual branch on the first event.
std::unordered_map< std::string, ElementProcessor > m_elements
Objects to write branches from.
StatusCode finalize() override
Function executed as part of the job finalisation.
bool m_isInitialized
Internal status flag, showing whether the algorithm is initialised.
Gaudi::Property< std::string > m_treeName
The name of the output tree to write.
StatusCode setupTree()
Function setting up the internal data structures on the first event.
TTree * m_tree
The tree being written.
Gaudi::Property< std::vector< std::string > > m_branches
The branches to write into this output tree.
std::unordered_map< std::string, ContainerProcessor > m_containers
Containers to write branches from.
StatusCode initialize() override
Function executed as part of the job initialisation.
Class to wrap a set of SystematicVariations.
bool empty() const
returns: whether the set is empty
const_iterator end() const
description: const iterator to the end of the set
void insert(const SystematicVariation &systematic)
description: insert a systematic into the set
iterator find(const SystematicVariation &sys) const
description: find an element in the set
static StatusCode filterForAffectingSystematics(const SystematicSet &systConfig, const SystematicSet &affectingSystematics, SystematicSet &filteredSystematics)
description: filter the systematics for the affected systematics returns: success guarantee: strong f...
A non-templated base class for DataBucket, allows to access the transient object address as a void*.
virtual void * object()=0
virtual const std::type_info & tinfo() const =0
Return the type_info for the stored object.
virtual std::vector< const SG::DataProxy * > proxies() const =0
Return the list of all current proxies in store.
Base class for elements of a container that can have aux data.
const SG::AuxVectorData * container() const
Return the container holding this element.
size_t index() const
Return the index of this element within its container.
Handle mappings between names and auxid_t.
static AuxTypeRegistry & instance()
Return the singleton registry instance.
Manage index tracking and synchronization of auxiliary data.
Manage lookup of vectors of auxiliary data.
DataObject * accessData()
Access DataObject on-demand using conversion service.
Interface providing I/O for a generic auxiliary store.
Helper class to provide const generic access to aux data.
The Athena Transient Store API.
StatusCode retrieve(const T *&ptr) const
Retrieve the default object into a const T*.
MsgStream & msg() const
The standard message stream.
AsgMessaging(const std::string &name)
Constructor with a name.
Wrapper for TEvent to make it look like StoreGate.
bool contains(const std::string &name) const
Check if an object is available for constant access.
T * retrieve(const std::string &name) const
Function retrieving a constant or non-constant object.
xAOD::TStore * tds() const
Return the underlying transient data store.
This class takes care of holding EDM objects in memory.
const std::type_info * getTypeInfo() const
const THolder * holder(const std::string &key) const
return holder for key
bool match(std::string s1, std::string s2)
match the individual directories of two strings
Select isolated Photons, Electrons and Muons.
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...
static const auxid_t null_auxid
To signal no aux data item.
size_t auxid_t
Identifier for a particular aux data item.
cl
print [x.__class__ for x in toList(dqregion.getSubRegions()) ]
DataModel_detail::iterator< DVL > remove_if(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end, Predicate pred)
Specialization of remove_if for DataVector/List.
char rootType(char typeidType)
This function is used internally in the code when creating primitive dynamic auxiliary branches.
Convert a type_info to a normalized string representation (matching the names used in the root dictio...