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// $Id: AuxSelection.cxx 653257 2015-03-11 11:26:15Z krasznaa $
6
7
8
9// EDM include(s):
11
12// Local include(s):
15#include <mutex>
16
17// System include(s):
18#include <iostream>
19#include <map>
20
21namespace {
22
25 std::set< std::string > mentionedVariableNames ATLAS_THREAD_SAFE;
26 std::mutex mentionedMutex;
27
28} // private namespace
29
30namespace xAOD {
31
36
49 void AuxSelection::selectAux( const std::set< std::string >& attributes ) {
50
51 m_names = attributes;
52 return;
53 }
54
65 static const std::string asteriskStr{"*"}; //..or use a transparent comparitor
66 // Check for the simplest case... all variables selected:
67 if( m_names.empty() || ( m_names.find( asteriskStr ) != m_names.end() ) ) {
68 return fullset;
69 }
70
71 // Start from an empty list:
72 SG::auxid_set_t auxids;
73 static const std::string hyphenStr{"-"};
74 // Check if everything should be disregarded:
75 if( m_names.find( hyphenStr ) != m_names.end() ) {
76 return auxids;
77 }
78
79 // Check that the user only put positive or negative selections on the
80 // list. They can't be mixed.
81 bool sub = false, add = false;
82 std::set< std::string >::const_iterator name_itr = m_names.begin();
83 std::set< std::string >::const_iterator name_end = m_names.end();
84 for( ; name_itr != name_end; ++name_itr ) {
85 if( ( *name_itr )[ 0 ] == '-' ) {
86 sub = true;
87 } else {
88 add = true;
89 }
90 }
91 if( sub && add ) {
92 std::cerr << "xAOD::AuxSelection ERROR Mixing + and - options for "
93 << "dynamic attributes" << std::endl;
94 return fullset; //better safe than sorry
95 }
96
97 if( add ) {
98 // Start with an empty list, and loop over the selected names:
99 name_itr = m_names.begin();
100 name_end = m_names.end();
101 for( ; name_itr != name_end; ++name_itr ) {
102 // Get the ID of this name:
103 const SG::auxid_t auxid =
105 if( auxid != SG::null_auxid ) {
106 // Add this variable if it exists:
107 if( fullset.test( auxid ) ) {
108 auxids.insert( auxid );
109 }
110 } else {
111 // Check if a warning should be printed at this time or not:
112 std::lock_guard<std::mutex> lock (mentionedMutex);
113 if( ::mentionedVariableNames.insert( *name_itr ).second ) {
114 // Apparently we didn't complain about this name yet...
115 std::cerr << "xAOD::AuxSelection WARNING Selected dynamic "
116 << "Aux atribute \"" << *name_itr
117 << "\" not found in the registry" << std::endl;
118 }
119 }
120 }
121 } else {
122 // Start from the full list:
123 auxids = fullset;
124 // ...and check which variables should be removed:
125 for (SG::auxid_t id : fullset) {
126 // Construct the name that we need to look for:
127 const std::string attrname =
129 // Check if it is in the list to be removed:
130 if( m_names.find( attrname ) != m_names.end() ) {
131 auxids.erase( id );
132 }
133 }
134 }
135
136 // Return the list of variables to be written out:
137 return auxids;
138 }
139
140} // 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.