ATLAS Offline Software
Loading...
Searching...
No Matches
AuxSelection.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
5// EDM include(s):
7
8// Local include(s):
11#include <mutex>
12
13// System include(s):
14#include <iostream>
15#include <map>
16#include <print>
17
18namespace {
19
22 std::set< std::string > mentionedVariableNames ATLAS_THREAD_SAFE;
23 std::mutex mentionedMutex;
24
25} // private namespace
26
27namespace xAOD {
28
33
46 void AuxSelection::selectAux( const std::set< std::string >& attributes ) {
47
48 m_names = attributes;
49 return;
50 }
51
62 static const std::string asteriskStr{"*"}; //..or use a transparent comparitor
63 // Check for the simplest case... all variables selected:
64 if( m_names.empty() || ( m_names.find( asteriskStr ) != m_names.end() ) ) {
65 return fullset;
66 }
67
68 // Start from an empty list:
69 SG::auxid_set_t auxids;
70 static const std::string hyphenStr{"-"};
71 // Check if everything should be disregarded:
72 if( m_names.find( hyphenStr ) != m_names.end() ) {
73 return auxids;
74 }
75
76 // Check that the user only put positive or negative selections on the
77 // list. They can't be mixed.
78 bool sub = false, add = false;
79 std::set< std::string >::const_iterator name_itr = m_names.begin();
80 std::set< std::string >::const_iterator name_end = m_names.end();
81 for( ; name_itr != name_end; ++name_itr ) {
82 if( ( *name_itr )[ 0 ] == '-' ) {
83 sub = true;
84 } else {
85 add = true;
86 }
87 }
88 if( sub && add ) {
89 std::println( std::cerr, "xAOD::AuxSelection ERROR Mixing + and - options for "
90 "dynamic attributes" );
91 return fullset; //better safe than sorry
92 }
93
94 if( add ) {
95 // Start with an empty list, and loop over the selected names:
96 name_itr = m_names.begin();
97 name_end = m_names.end();
98 for( ; name_itr != name_end; ++name_itr ) {
99 // Get the ID of this name:
100 const SG::auxid_t auxid =
102 if( auxid != SG::null_auxid ) {
103 // Add this variable if it exists:
104 if( fullset.test( auxid ) ) {
105 auxids.insert( auxid );
106 }
107 } else {
108 // Check if a warning should be printed at this time or not:
109 std::lock_guard<std::mutex> lock (mentionedMutex);
110 if( ::mentionedVariableNames.insert( *name_itr ).second ) {
111 // Apparently we didn't complain about this name yet...
112 std::println( std::cerr, "xAOD::AuxSelection WARNING Selected dynamic "
113 "Aux atribute \"{}\" not found in the registry",
114 *name_itr );
115 }
116 }
117 }
118 } else {
119 // Start from the full list:
120 auxids = fullset;
121 // ...and check which variables should be removed:
122 for (SG::auxid_t id : fullset) {
123 // Construct the name that we need to look for:
124 const std::string attrname =
126 // Check if it is in the list to be removed:
127 if( m_names.find( attrname ) != m_names.end() ) {
128 auxids.erase( id );
129 }
130 }
131 }
132
133 // Return the list of variables to be written out:
134 return auxids;
135 }
136
137} // namespace xAOD
Handle mappings between names and auxid_t.
virtual void lock()=0
Interface to allow an object to lock itself when made const in SG.
Define macros for attributes used to control the static checker.
#define ATLAS_THREAD_SAFE
SG::auxid_t findAuxID(const std::string &name, const std::string &clsname="") const
Look up a name -> auxid_t mapping.
std::string getName(SG::auxid_t auxid) const
Return the name of an aux data item.
static AuxTypeRegistry & instance()
Return the singleton registry instance.
A set of aux data identifiers.
Definition AuxTypes.h:47
std::set< std::string > m_names
Properties following the variable selection convention.
virtual void selectAux(const std::set< std::string > &attributes)
Select which variables should be written out.
virtual SG::auxid_set_t getSelectedAuxIDs(const SG::auxid_set_t &fullset) const
Return which variables were selected to be written out.
AuxSelection()
Default constructor.
bool add(const std::string &hname, TKey *tobj)
Definition fastadd.cxx:55
static const auxid_t null_auxid
To signal no aux data item.
Definition AuxTypes.h:30
size_t auxid_t
Identifier for a particular aux data item.
Definition AuxTypes.h:27
ICaloAffectedTool is abstract interface for tools checking if 4 mom is in calo affected region.