24#include <TVirtualCollectionProxy.h>
43 TempInterface (
size_t size) : m_size (size) {}
44 TempInterface (
size_t size,
SG::auxid_t auxid,
void* ptr) :
47 setCache (auxid, ptr);
50 using AuxVectorData::setStore;
52 virtual size_t size_v()
const {
return m_size; }
53 virtual size_t capacity_v()
const {
return m_size; }
89 if( ! evtStore.
retrieve( c, key ).isSuccess() ) {
90 msg << MSG::ERROR <<
"Couldn't retrieve container with key \"" <<
key
95 if( holder !=
nullptr ) {
100 cl = TClass::GetClass( *ti );
104 cl = TClass::GetClass(
typeid( *c ) );
106 if( ( allowMissing ==
false ) && ( cl ==
nullptr ) ) {
108 <<
"Couldn't find TClass dictionary for container \"" <<
key
137 if( ! evtStore.
retrieve( e, key ).isSuccess() ) {
138 msg << MSG::ERROR <<
"Couldn't retrieve object with key \"" <<
key
148 class ProxyWithName {
151 typedef const SG::DataProxy* argument_type;
153 ProxyWithName(
const std::string& name ) : m_name(
name ) {}
155 bool operator()( argument_type proxy )
const {
156 return (
proxy->name() == m_name );
181 auto proxies = evtStore.
proxies();
183 std::not_fn( ProxyWithName( key ) ) ),
195 <<
"Couldn't access data object as a data bucket?!?" <<
endmsg;
199 cl = TClass::GetClass( bucket->
tinfo() );
201 if(
msg.level() <= MSG::VERBOSE ) {
202 msg << MSG::VERBOSE <<
"No dictionary found for: "
208 if( !
cl->InheritsFrom(
"SG::AuxVectorBase" ) ) {
209 if(
msg.level() <= MSG::VERBOSE ) {
210 msg << MSG::VERBOSE <<
"Object \"" <<
key <<
"/" <<
cl->GetName()
211 <<
"\" does not inherit from SG::AuxVectorBase" <<
endmsg;
222 if( ! allowMissing ) {
223 msg << MSG::ERROR <<
"Couldn't retrieve object \"" <<
key
224 <<
"\" as SG::AuxVectorBase" <<
endmsg;
247 if( !evtStore.
retrieve( e, key ).isSuccess() ) {
249 msg << MSG::ERROR <<
"Couldn't retrieve object with key \"" <<
key
270 switch( typeidType ) {
308 msg << MSG::ERROR <<
"Received an unknown type: " << typeidType
320 StatusCode BranchConfig ::
332 static const std::regex
333 re(
"\\s*([\\w%]+)\\.([\\w%]+)\\s*->\\s*([\\w%]+)(\\s+type=([\\w%]+))?(\\s+metTerm=([\\w%]+))?" );
338 msg << MSG::ERROR <<
"Expression \"" <<
branchDecl <<
"\" doesn't match \"<object>.<variable> -> <branch>\"" <<
endmsg;
339 return StatusCode::FAILURE;
347 return StatusCode::SUCCESS;
352 StatusCode BranchConfig ::
353 configureTypes (std::set<std::string>& decosWithoutType, MsgStream&
msg)
355 std::string nominalAuxName =
auxName;
356 if (
auto pos = nominalAuxName.find (
"%SYS%"); pos != std::string::npos)
357 nominalAuxName.replace (pos, 5,
"NOSYS");
374 unsigned line = __LINE__ - 2;
375 std::string
file = __FILE__;
377 msg << MSG::ERROR <<
"Unknown type requested, please extend " <<
file <<
" near line " << line <<
" for type " <<
typeName <<
endmsg;
378 return StatusCode::FAILURE;
387 decosWithoutType.insert (nominalAuxName);
388 msg << MSG::DEBUG <<
"No aux ID found for auxiliary variable: " << nominalAuxName <<
endmsg;
390 return StatusCode::SUCCESS;
399 <<
"No std::type_info available for aux-store variable: "
400 << nominalAuxName <<
endmsg;
401 return StatusCode::FAILURE;
410 <<
"No std::type_info available for aux-store variable: "
411 << nominalAuxName <<
endmsg;
412 return StatusCode::FAILURE;
421 <<
"No factory found for auxiliary variable: "
422 << nominalAuxName <<
endmsg;
423 return StatusCode::FAILURE;
426 return StatusCode::SUCCESS;
431 StatusCode BranchConfig ::
434 if (
sgName.find (
"%SYS%") == std::string::npos &&
435 auxName.find (
"%SYS%") == std::string::npos &&
436 branchName.find (
"%SYS%") == std::string::npos)
442 if (
branchName.find (
"%SYS%") == std::string::npos)
444 msg << MSG::ERROR <<
"Branch with systematics without %SYS% in branch name: "
446 return StatusCode::FAILURE;
448 if (
sgName.find (
"%SYS%") == std::string::npos &&
449 auxName.find (
"%SYS%") == std::string::npos)
451 msg << MSG::ERROR <<
"Branch with systematics without %SYS% in SG or aux name: "
453 return StatusCode::FAILURE;
455 if (
auxName.find (
"NOSYS") != std::string::npos)
457 msg << MSG::ERROR <<
"Branch with systematics with NOSYS in aux name: "
459 return StatusCode::FAILURE;
461 if (
sgName.find (
"NOSYS") != std::string::npos &&
auxName.find (
"%SYS%") == std::string::npos)
463 msg << MSG::ERROR <<
"Branch with NOSYS in SG name but without %SYS% in aux name: "
465 return StatusCode::FAILURE;
468 if (
sgName.find (
"%SYS%") != std::string::npos)
471 if (
auxName.find (
"%SYS%") != std::string::npos)
473 if (
auto pos =
sgName.find (
"NOSYS"); pos == std::string::npos)
481 std::string sgNameSys =
sgName;
482 sgNameSys.replace (pos, 5,
"%SYS%");
491 for (
auto& variation : allSys)
493 if (objectSys.find (variation) == objectSys.end())
505 return StatusCode::SUCCESS;
510 StatusCode OutputBranchData ::
515 if (
branchConfig.sgName.find (
"%SYS%") != std::string::npos)
519 return StatusCode::FAILURE;
521 return StatusCode::FAILURE;
522 if (!matching.
empty())
527 if (
branchConfig.auxName.find (
"%SYS%") != std::string::npos)
531 return StatusCode::FAILURE;
533 return StatusCode::FAILURE;
534 if (!matching.
empty())
539 if (
branchConfig.branchName.find (
"%SYS%") != std::string::npos)
543 return StatusCode::FAILURE;
545 return StatusCode::FAILURE;
548 msg << MSG::FATAL <<
"Branch \"" <<
branchName <<
"\" is not affected by any of the requested systematics but is not nominal." <<
endmsg;
549 return StatusCode::FAILURE;
556 msg << MSG::FATAL <<
"Branch \"" <<
branchName <<
"\" without systematics is evaluated in a non-nominal context." <<
endmsg;
557 return StatusCode::FAILURE;
561 return StatusCode::SUCCESS;
583 TBranch* br =
nullptr;
586 if( strlen( branchConfig.
auxType->name() ) == 1 ) {
591 const char rType = rootType( branchConfig.
auxType->name()[ 0 ],
msg );
592 if( rType ==
'\0' ) {
593 msg << MSG::ERROR <<
"Type not recognised for variable: "
595 return StatusCode::FAILURE;
599 std::ostringstream typeDesc;
600 typeDesc << outputData.
branchName <<
"/" << rType;
604 typeDesc.str().c_str() );
614 TClass* cl = TClass::GetClass( *branchConfig.
auxType );
616 cl = TClass::GetClass( typeName.c_str() );
619 msg << MSG::ERROR <<
"Couldn't find dictionary for type: "
621 return StatusCode::FAILURE;
623 if( ! cl->GetStreamerInfo() ) {
624 msg << MSG::ERROR <<
"No streamer info available for type: "
625 << cl->GetName() <<
endmsg;
626 return StatusCode::FAILURE;
637 msg << MSG::ERROR <<
"Failed to create branch: " << outputData.
branchName
639 return StatusCode::FAILURE;
643 return StatusCode::SUCCESS;
652 msg << MSG::FATAL <<
"Internal logic error detected" <<
endmsg;
653 return StatusCode::FAILURE;
665 return StatusCode::SUCCESS;
687 TClass* cl = TClass::GetClass( *branchConfig.
auxVecType );
689 cl = TClass::GetClass( typeName.c_str() );
692 msg << MSG::ERROR <<
"Couldn't find dictionary for type: "
694 return StatusCode::FAILURE;
696 if( ! cl->GetStreamerInfo() ) {
697 msg << MSG::ERROR <<
"No streamer info available for type: "
698 << cl->GetName() <<
endmsg;
699 return StatusCode::FAILURE;
704 TBranch* br =
tree.Branch( outputData.
branchName.c_str(), cl->GetName(),
707 msg << MSG::ERROR <<
"Failed to create branch: " << outputData.
branchName
709 return StatusCode::FAILURE;
713 return StatusCode::SUCCESS;
721 msg << MSG::FATAL <<
"Internal logic error detected" <<
endmsg;
722 return StatusCode::FAILURE;
730 return StatusCode::SUCCESS;
738 msg << MSG::FATAL <<
"Internal logic error detected" <<
endmsg;
739 return StatusCode::FAILURE;
751 return StatusCode::SUCCESS;
759 :
asg::
AsgMessaging( (
"CP::TreeBranchHelpers::ElementProcessorRegular/" + sgName).c_str() ),
768 static const bool ALLOW_MISSING =
false;
771 ALLOW_MISSING,
msg() );
775 return StatusCode::FAILURE;
785 return StatusCode::SUCCESS;
792 m_branches.emplace_back(std::make_unique<ElementBranchProcessor>());
796 return StatusCode::SUCCESS;
800 :
asg::
AsgMessaging( (
"CP::TreeBranchHelpers::ContainerProcessorRegular/" + sgName).c_str() ),
809 static const bool ALLOW_MISSING =
false;
810 const TClass* cl =
nullptr;
813 ALLOW_MISSING, cl,
msg() );
817 return StatusCode::FAILURE;
829 return StatusCode::FAILURE;
834 static const TClass*
const auxElementClass =
837 m_collProxy->GetValueClass()->GetBaseClassOffset( auxElementClass );
841 <<
"\" doesn't seem to inherit from \""
842 << auxElementClass->GetName() <<
"\"" );
843 return StatusCode::FAILURE;
850 const_cast< void*
>(
static_cast< const void*
>( &
container ) );
851 TVirtualCollectionProxy::TPushPop helper(
m_collProxy, cPtr );
860 for( UInt_t i = 0; i < cSize; ++i ) {
863 char* elPtr =
static_cast< char*
>(
m_collProxy->At( i ) );
865 ATH_MSG_ERROR(
"Failed to get element " << i <<
" from container" );
866 return StatusCode::FAILURE;
879 return StatusCode::SUCCESS;
886 m_branches.emplace_back(std::make_unique<ContainerBranchProcessor>());
890 return StatusCode::SUCCESS;
894 :
asg::
AsgMessaging( (
"CP::TreeBranchHelpers::ElementProcessorMet/" + sgName).c_str() ),
912 return StatusCode::SUCCESS;
919 m_branches.emplace_back(std::make_unique<ElementBranchProcessor>());
923 return StatusCode::SUCCESS;
928 StatusCode ProcessorList ::
929 setupTree(
const std::vector<std::string>& branches, std::unordered_set<std::string> nonContainers,
ISystematicsSvc& sysSvc, TTree&
tree) {
933 std::vector<BranchConfig> branchConfigs;
934 branchConfigs.reserve( branches.size() );
935 for (
const std::string& branchDecl : branches ) {
936 branchConfigs.emplace_back();
937 ATH_CHECK( branchConfigs.back().parse( branchDecl,
msg() ) );
945 std::set<std::string> decosWithoutType;
946 for (
auto& branchConfig : branchConfigs) {
947 ATH_CHECK ( branchConfig.configureTypes (decosWithoutType,
msg()) );
949 if (!decosWithoutType.empty()) {
950 msg() << MSG::ERROR <<
"The following decorations have no type information:";
951 for (
const auto& deco : decosWithoutType) {
952 msg() <<
" " << deco;
955 return StatusCode::FAILURE;
959 for (
auto& branchConfig : branchConfigs) {
960 ATH_CHECK ( branchConfig.configureSystematics (sysSvc,
msg()) );
965 if (!sysVector.at(0).empty()) {
966 ATH_MSG_ERROR (
"The first systematic in the list is not nominal!");
967 return StatusCode::FAILURE;
971 std::vector<OutputBranchData> outputBranches;
974 std::unordered_set<std::string> allBranches;
977 for(
const auto& branchConfig : branchConfigs ) {
980 std::unordered_set<std::string> branchesForRule;
983 for(
const auto& sys : sysVector ) {
985 if (branchConfig.nominalOnly && !sys.empty())
continue;
988 outputData.
sysIndex = &sys - &sysVector.front();
994 if (branchesForRule.contains(outputData.
branchName))
996 ANA_MSG_VERBOSE (
"Branch \"" << outputData.
branchName <<
"\" for rule \"" << branchConfig.branchDecl <<
"\" and systematic \"" << sys.name() <<
"\" already exists, skipping." );
999 branchesForRule.insert(outputData.
branchName);
1003 if (allBranches.contains(outputData.
branchName))
1006 return StatusCode::FAILURE;
1009 outputBranches.push_back(outputData);
1018 return a.sysIndex < b.sysIndex; });
1020 for (
auto &outputData : outputBranches)
1024 return StatusCode::SUCCESS;
1030 branchConfig, outputData ) );
1032 <<
"\" from container/variable \"" << outputData.
sgName
1033 <<
"." << outputData.
auxName <<
"\"" );
1036 return StatusCode::SUCCESS;
1039 StatusCode ProcessorList ::
1048 return StatusCode::SUCCESS;
1054 getObjectProcessor(
const BranchConfig& branchConfig,
const std::string& sgName )
1056 std::string processorName = sgName;
1058 processorName +=
":metTerm=" + branchConfig.
metTermName;
1061 return *iter->second;
1064 return *
m_processors.emplace (processorName, std::make_unique<ElementProcessorMet>(sgName, branchConfig.
metTermName)).first->second;
1067 return *
m_processors.emplace (processorName, std::make_unique<ElementProcessorRegular>(sgName)).first->second;
1069 return *
m_processors.emplace (processorName, std::make_unique<ContainerProcessorRegular>(sgName)).first->second;
const boost::regex re(r_e)
#define ATH_CHECK
Evaluate an expression and check for errors.
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.
static HEPVis_BooleanProcessor processor
#define ATLAS_NOT_CONST_THREAD_SAFE
the interface for the central systematics service
virtual CP::SystematicSet getObjectSystematics(const std::string &name) const =0
get the systematics for the given object in the event store
virtual std::vector< CP::SystematicSet > makeSystematicsVector() const =0
get the list of systematics
virtual CP::SystematicSet getDecorSystematics(const std::string &objectName, const std::string &decorName) const =0
get the systematics for the given object in the event store
virtual StatusCode makeSystematicsName(std::string &result, const std::string &name, const CP::SystematicSet &sys) const =0
make the name for the given systematics
Class to wrap a set of SystematicVariations.
bool empty() const
returns: whether the set is empty
static StatusCode filterForAffectingSystematics(const SystematicSet &systConfig, const SystematicSet &affectingSystematics, SystematicSet &filteredSystematics)
description: filter the systematics for the affected systematics returns: success guarantee: strong f...
std::string m_branchName
Name of the branch being written.
StatusCode resize(size_t size, MsgStream &msg)
Function (re)sizing the variable for a new event.
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::unique_ptr< SG::TypelessConstAccessor > m_acc
Object accessing the variable in question.
StatusCode setup(TTree &tree, const BranchConfig &branchConfig, OutputBranchData &outputData, MsgStream &msg)
Function setting up the object, and the branch.
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.
TVirtualCollectionProxy * m_collProxy
Collection proxy used for iterating over the container.
std::string m_sgName
Name of the object in the event store.
int m_auxElementOffset
Offset of the element type to SG::AuxElement.
StatusCode retrieveProcess(StoreType &evtStore) override
retrieve and process the object
StatusCode addBranch(TTree &tree, const BranchConfig &branchConfig, OutputBranchData &outputData) override
Add one branch to the output tree.
std::vector< std::unique_ptr< ContainerBranchProcessor > > m_branches
List of branch processors set up for this xAOD object.
ContainerProcessorRegular(const std::string &sgName)
Default constructor.
std::unique_ptr< SG::IAuxTypeVector > m_data
The object managing the memory of the written variable.
void * m_dataPtr
Helper variable, pointing at the object to be written.
const SG::IAuxTypeVectorFactory * m_factory
Pointer to the helper object that handles this variable.
std::string m_branchName
Name of the branch being written.
StatusCode setup(TTree &tree, const BranchConfig &branchConfig, OutputBranchData &outputData, MsgStream &msg)
Function setting up the object, and the branch.
std::unique_ptr< SG::TypelessConstAccessor > m_acc
Object accessing the variable in question.
StatusCode process(const SG::AuxElement &element, MsgStream &msg)
Function processing the object, filling the variable.
std::vector< std::unique_ptr< ElementBranchProcessor > > m_branches
List of branch processors set up for this xAOD object.
std::string m_termName
Name of the MET term to retrieve.
StatusCode addBranch(TTree &tree, const BranchConfig &branchConfig, OutputBranchData &outputData) override
Add one branch to the output tree.
ElementProcessorMet(const std::string &sgName, const std::string &termName)
Default constructor.
StatusCode retrieveProcess(StoreType &evtStore) override
retrieve and process the object
std::string m_sgName
Name of the object in the event store.
StatusCode retrieveProcess(StoreType &evtStore) override
retrieve and process the object
StatusCode addBranch(TTree &tree, const BranchConfig &branchConfig, OutputBranchData &outputData) override
Add one branch to the output tree.
std::string m_sgName
Name of the object in the event store.
ElementProcessorRegular(const std::string &sgName)
Default constructor.
std::vector< std::unique_ptr< ElementBranchProcessor > > m_branches
List of branch processors set up for this xAOD object.
the interface class for classes reading an object from the event store and processing it
virtual StatusCode addBranch(TTree &tree, const BranchConfig &branchConfig, OutputBranchData &outputData)=0
Add one branch to the output tree.
StatusCode setupBranch(const BranchConfig &branchConfig, OutputBranchData &outputData, TTree &tree)
Function setting up an individual branch on the first event.
std::unordered_set< std::string > m_nonContainers
the non-containers
IObjectProcessor & getObjectProcessor(const BranchConfig &branchConfig, const std::string &sgName)
std::unordered_map< std::string, std::unique_ptr< IObjectProcessor > > m_processors
object processors
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.
Helper class to provide constant type-safe access to aux data.
DataObject * accessData()
Access DataObject on-demand using conversion service.
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.
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
a namespace for helper functions and objects for filling tree branches
StoreGateSvc StoreType
the type of the event store in the current environment
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()) ]
void stable_sort(DataModel_detail::iterator< DVL > beg, DataModel_detail::iterator< DVL > end)
Specialization of stable_sort for DataVector/List.
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.
MissingETContainer_v1 MissingETContainer
Convert a type_info to a normalized string representation (matching the names used in the root dictio...
the user configuration of an output branch
std::string branchDecl
the original user configuration string
std::string sgName
the SG name of the object to read from
const SG::IAuxTypeVectorFactory * auxFactory
pointer to the aux vector factory
std::string auxName
the aux data variable name to read from
const std::type_info * auxVecType
the vector type of the decoration we read
CP::SystematicSet auxNameFilterSys
the affecting systematics for the auxName
CP::SystematicSet sgNameFilterSys
the affecting systematics for the sgName
CP::SystematicSet branchNameFilterSys
the affecting systematics for the branchName
const std::type_info * auxType
the type of the decoration we read
SG::auxid_t nominalAuxId
the aux-id for the nominal decoration
std::string branchName
the name of the output branch
std::string metTermName
MET ONLY: the name of the MET term to write out.
bool nominalOnly
whether we only want to write out the nominal
std::string typeName
the name of the type (or empty to read from aux-registry)
the data for a single output branch
bool isNominal
whether this is unaffected by systematics (i.e. nominal)
const BranchConfig * branchConfig
the BranchConfig we are based on
std::size_t sysIndex
the index in the systematics list
StatusCode configureNames(const BranchConfig &branchConfig, const CP::SystematicSet &sys, ISystematicsSvc &sysSvc, MsgStream &msg)
configure names for systematics
std::string auxName
the name of the decoration in the aux-store
std::string sgName
the SG name of the object to read from
std::string branchName
the name of the output branch