|
ATLAS Offline Software
|
Go to the documentation of this file.
18 #include <TVirtualCollectionProxy.h>
34 TempInterface (
size_t size) : m_size (
size) {}
43 virtual size_t size_v()
const {
return m_size; }
44 virtual size_t capacity_v()
const {
return m_size; }
56 #ifdef XAOD_STANDALONE
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
129 msg << MSG::ERROR <<
"Couldn't retrieve object with key \"" <<
key
139 class ProxyWithName {
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();
173 proxies.erase( std::remove_if( proxies.begin(), proxies.end(),
174 std::not_fn( ProxyWithName(
key ) ) ),
186 <<
"Couldn't access data object as a data bucket?!?" <<
endmsg;
190 cl = TClass::GetClass( bucket->
tinfo() );
199 if( !
cl->InheritsFrom(
"SG::AuxVectorBase" ) ) {
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;
240 msg << MSG::ERROR <<
"Couldn't retrieve object with key \"" <<
key
248 #endif // XAOD_STANDALONE
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;
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;
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};
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;
524 if(
brName.find(
"%SYS%" ) != std::string::npos )
532 return StatusCode::SUCCESS;
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() ) ) {
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;
615 :
asg::AsgMessaging(
"CP::AsgxAODNTupleMakerAlg::ElementProcessor" ) {
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 ) {
694 m_branchName = branchName;
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;
716 m_data = m_factory->create( m_acc->auxid(), 1, 1,
false );
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;
740 typeDesc.str().c_str() );
750 TClass*
cl = TClass::GetClass( *ti );
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: "
762 return StatusCode::FAILURE;
766 m_dataPtr =
m_data->toPtr();
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;
787 if( ( ! m_acc ) || ( ! m_factory ) || ( !
m_data ) ) {
789 return StatusCode::FAILURE;
796 TempInterface dstiface (
m_data->size(), m_acc->auxid(),
m_data->toPtr());
797 m_factory->copy( m_acc->auxid(), dstiface, 0,
801 return StatusCode::SUCCESS;
805 :
asg::AsgMessaging(
"CP::AsgxAODNTupleMakerAlg::ContainerProcessor" ) {
813 if( ! m_collProxy ) {
816 m_collProxy =
cl.GetCollectionProxy();
817 if( ! m_collProxy ) {
820 return StatusCode::FAILURE;
825 static const TClass*
const auxElementClass =
828 m_collProxy->GetValueClass()->GetBaseClassOffset( auxElementClass );
829 if( m_auxElementOffset < 0 ) {
831 << m_collProxy->GetValueClass()->GetName()
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 );
843 const UInt_t cSize = m_collProxy->Size();
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;
861 m_auxElementOffset );
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 ) {
935 m_branchName = branchName;
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;
958 m_data = m_factory->create( m_acc->auxid(), 0, 0,
false );
964 TClass*
cl = TClass::GetClass( *vecTi );
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: "
976 return StatusCode::FAILURE;
980 m_dataPtr =
m_data->toVector();
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;
999 return StatusCode::FAILURE;
1007 return StatusCode::SUCCESS;
1014 if( ( ! m_acc ) || ( ! m_factory ) || ( !
m_data ) ) {
1016 return StatusCode::FAILURE;
1023 TempInterface dstiface (
m_data->size(), m_acc->auxid(),
m_data->toPtr());
1024 m_factory->copy( m_acc->auxid(), dstiface,
index,
1028 return StatusCode::SUCCESS;
const IAuxTypeVectorFactory * getFactory(const std::type_info &ti, const std::type_info &ti_alloc)
Return the vector factory for a given vector element type.
TTree * m_tree
The tree being written.
StatusCode process(const SG::AuxVectorBase &container, const TClass &cl)
Process the container.
StatusCode setupBranch(const std::string &branchDecl, const CP::SystematicSet &sys)
Function setting up an individual branch on the first event.
const THolder * holder(const std::string &key) const
return holder for key
bool contains(const std::string &name) const
Check if an object is available for constant access.
StatusCode setup(TTree &tree, const std::string &auxName, const std::string &branchName, MsgStream &msg)
Function setting up the object, and the branch.
StatusCode process(const SG::AuxElement &element)
Process the object.
Gaudi::Property< std::string > m_treeName
The name of the output tree to write.
A non-templated base class for DataBucket, allows to access the transient object address as a void*.
static AuxTypeRegistry & instance()
Return the singleton registry instance.
StatusCode setup(TTree &tree, const std::string &auxName, const std::string &branchName, MsgStream &msg)
Function setting up the object, and the branch.
SG::auxid_t findAuxID(const std::string &name, const std::string &clsname="") const
Look up a name -> auxid_t mapping.
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...
Base class for elements of a container that can have aux data.
This class takes care of holding EDM objects in memory.
virtual void * object()=0
#define ATLAS_NOT_CONST_THREAD_SAFE
bool empty() const
returns: whether the set is empty
xAOD::TStore * tds() const
Return the underlying transient data store.
Class to wrap a set of SystematicVariations.
DataObject * accessData()
Access DataObject on-demand using conversion service.
Helper class to provide const generic access to aux data.
Class writing one variable from an xAOD object into a branch.
std::vector< size_t > vec
#define ATH_MSG_VERBOSE(x)
Select isolated Photons, Electrons and Muons.
Manage index tracking and synchronization of auxiliary data.
Manage index tracking and synchronization of auxiliary data.
Class writing one variable from an xAOD object into a branch.
Interface providing I/O for a generic auxiliary store.
ContainerProcessor()
Default constructor.
StatusCode execute() override
Function executed once per event.
StatusCode retrieve(const T *&ptr) const
Retrieve the default object into a const T*.
Handle mappings between names and auxid_t.
StatusCode process(const SG::AuxElement &element, size_t index, MsgStream &msg)
Function processing the object, filling the variable.
void setStore(SG::IAuxStore *store)
Set the store associated with this object.
ServiceHandle< StoreGateSvc > & evtStore()
The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
T * retrieve(const std::string &name) const
Function retrieving a constant or non-constant object.
size_t auxid_t
Identifier for a particular aux data item.
const std::type_info * getType(SG::auxid_t auxid) const
Return the type of an aux data item.
The Athena Transient Store API.
void setCache(SG::auxid_t auxid, void *ptr)
Explicitly set a cache pointer.
StatusCode resize(size_t size, MsgStream &msg)
Function (re)sizing the variable for a new event.
virtual std::vector< const SG::DataProxy * > proxies() const =0
Return the list of all current proxies in store.
Interface providing I/O for a generic auxiliary store.
::StatusCode StatusCode
StatusCode definition for legacy code.
bool m_isInitialized
Internal status flag, showing whether the algorithm is initialised.
std::unordered_map< std::string, ContainerProcessor > m_containers
Containers to write branches from.
const_iterator end() const
description: const iterator to the end of the set
ServiceHandle< ISystematicsSvc > m_systematicsService
the handle for the systematics service
const std::type_info * getVecType(SG::auxid_t auxid) const
Return the type of the STL vector used to hold an aux data item.
size_t index() const
Return the index of this element within its container.
Convert a type_info to a normalized string representation (matching the names used in the root dictio...
void insert(const SystematicVariation &systematic)
description: insert a systematic into the set
StatusCode addBranch(TTree &tree, const std::string &auxName, const std::string &branchName, bool allowMissing, bool &created)
Add one branch to the output tree.
StatusCode process(const SG::AuxElement &element, MsgStream &msg)
Function processing the object, filling the variable.
Wrapper for TEvent to make it look like StoreGate.
iterator find(const SystematicVariation &sys) const
description: find an element in the set
StatusCode finalize() override
Function executed as part of the job finalisation.
StatusCode addBranch(TTree &tree, const std::string &auxName, const std::string &branchName, bool allowMissing, bool &created)
Add one branch to the output tree.
const std::type_info * getTypeInfo() const
#define ATH_MSG_WARNING(x)
Interface for factory objects that create vectors.
const boost::regex re(r_e)
StatusCode initialize() override
Function executed as part of the job initialisation.
virtual const std::type_info & tinfo() const =0
Return the type_info for the stored object.
StatusCode setupTree()
Function setting up the internal data structures on the first event.
Manage lookup of vectors of auxiliary data.
const SG::AuxVectorData * container() const
Return the container holding this element.
Gaudi::Property< std::vector< std::string > > m_branches
The branches to write into this output tree.
std::string m_name
Instance name.
cl
print [x.__class__ for x in toList(dqregion.getSubRegions()) ]
std::unordered_map< std::string, ElementProcessor > m_elements
Objects to write branches from.
char rootType(char typeidType)
This function is used internally in the code when creating primitive dynamic auxiliary branches.
virtual size_t capacity_v() const =0
Return the capacity of the container.
virtual size_t size_v() const =0
Return the size of the container.
static StatusCode filterForAffectingSystematics(const SystematicSet &systConfig, const SystematicSet &affectingSystematics, SystematicSet &filteredSystematics)
description: filter the systematics for the affected systematics returns: success guarantee: strong f...
bool match(std::string s1, std::string s2)
match the individual directories of two strings
Base class for elements of a container that can have aux data.
TTree * tree(const std::string &treeName, const std::string &tDir="", const std::string &stream="")
Simplify the retrieval of registered TTrees.
ElementProcessor()
Default constructor.