ATLAS Offline Software
AuxCompression.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 // System include(s):
6 #include <iostream>
7 
8 // EDM include(s):
10 
11 // Local include(s):
13 
14 namespace xAOD {
15 
17  : m_compression_map{}
18  {
19  }
20 
35  void AuxCompression::setCompressedAuxIDs( const std::map< unsigned int, std::set< std::string > >& attributes ) {
36 
38  return;
39  }
40 
49  std::map< unsigned int, SG::auxid_set_t >
51 
52  // Create an empty result map
53  std::map< unsigned int, SG::auxid_set_t > result;
54 
55  // Loop over the internal map set by setCompressedAuxIDs
56  for(const auto& val : m_compression_map) {
57 
58  // Set helper variables
59  const unsigned int nmantissa = val.first;
60  const std::set< std::string > &names = val.second;
61 
62  // Start from an empty list
63  SG::auxid_set_t auxids;
64 
65  // Check the simplest case, nothing to be compressed
66  if( names.empty() || ( names.find("-") != names.end() ) ) {
67  continue;
68  }
69 
70  // Check that the user only put positive or negative selections on the
71  // list. They can't be mixed.
72  bool sub = false, add = false;
73  std::set< std::string >::const_iterator name_itr = names.begin();
74  std::set< std::string >::const_iterator name_end = names.end();
75  for( ; name_itr != name_end; ++name_itr ) {
76  if( ( *name_itr )[ 0 ] == '-' ) {
77  sub = true;
78  } else {
79  add = true;
80  }
81  }
82  if( sub && add ) {
83  // At this level we don't have a handle to the MsgStream,
84  // otherwise it'd be preferred!
85  std::cerr << "xAOD::AuxCompression ERROR Mixing + and - options for "
86  << "compression attributes" << std::endl;
87  continue; // Ill-defined input, not compressing anything just in case
88  }
89 
90  // Loop over the full set, find all float and std::vector<float> variables, add to the list
91  // This is our starting point as we currently compress only floats.
92  // This way we don't mistakenly float compress a random type based on wrong user input.
93  SG::auxid_set_t fauxids;
94 
95  // not using reference, because our iterator doesn't return a reference
96  for ( const SG::auxid_t auxid : fullset ) {
97  const std::string cType = SG::AuxTypeRegistry::instance().getTypeName( auxid );
98  if( cType == "float" || cType == "std::vector<float>" ) {
99  fauxids.insert( auxid );
100  }
101  }
102 
103  // Check if all floats are to be compressed
104  if( names.find("*") != names.end() ) {
105  auxids = fauxids;
106  }
107  // Here comes the parsing either + or - as in AuxSelection that we follow closely
108  else if( add ) {
109  // Build the list of variables to be compressed starting from the empty list
110  name_itr = names.begin();
111  name_end = names.end();
112  for( ; name_itr != name_end; ++name_itr ) {
113  // Get the ID of this name
114  const SG::auxid_t auxid = SG::AuxTypeRegistry::instance().findAuxID( *name_itr );
115  if( auxid != SG::null_auxid ) {
116  // Add this variable if it exists
117  if( fauxids.test( auxid ) ) {
118  auxids.insert( auxid );
119  }
120  }
121  }
122  } else {
123  // Build the list of variables to be compressed starting from the full float list
124  auxids = fauxids;
125  // Loop over all float variables and remove if matching
126  for ( SG::auxid_t auxid : fauxids ) {
127  // Construct the name of this ID
128  const std::string attrname = "-" + SG::AuxTypeRegistry::instance().getName( auxid );
129  // Check if it is in the list to be removed
130  if( names.find( attrname ) != names.end() ) {
131  auxids.erase( auxid );
132  }
133  }
134  }
135 
136  // Finally fill the result map
137  result[ nmantissa ] = auxids;
138 
139  } // End of loop over internal map
140 
141  return result; // Return the result map
142  }
143 
144 } // namespace xAOD
get_generator_info.result
result
Definition: get_generator_info.py:21
SG::AuxTypeRegistry::instance
static AuxTypeRegistry & instance()
Return the singleton registry instance.
Definition: AuxTypeRegistry.cxx:49
SG::AuxTypeRegistry::findAuxID
SG::auxid_t findAuxID(const std::string &name, const std::string &clsname="") const
Look up a name -> auxid_t mapping.
Definition: AuxTypeRegistry.cxx:159
xAOD::AuxCompression::setCompressedAuxIDs
virtual void setCompressedAuxIDs(const std::map< unsigned int, std::set< std::string > > &attributes)
Set which variables should be compressed per compression setting.
Definition: AuxCompression.cxx:35
SG::AuxTypeRegistry::getName
std::string getName(SG::auxid_t auxid) const
Return the name of an aux data item.
Definition: AuxTypeRegistry.cxx:277
xAOD
ICaloAffectedTool is abstract interface for tools checking if 4 mom is in calo affected region.
Definition: ICaloAffectedTool.h:24
SG::auxid_t
size_t auxid_t
Identifier for a particular aux data item.
Definition: AuxTypes.h:27
xAOD::AuxCompression::getCompressedAuxIDs
virtual std::map< unsigned int, SG::auxid_set_t > getCompressedAuxIDs(const SG::auxid_set_t &fullset) const
Return those variables that are selected to be compressed per compression setting.
Definition: AuxCompression.cxx:50
SG::AuxTypeRegistry::getTypeName
std::string getTypeName(SG::auxid_t auxid) const
Return the type name of an aux data item.
Definition: AuxTypeRegistry.cxx:316
CxxUtils::ConcurrentBitset::insert
ConcurrentBitset & insert(bit_t bit, bit_t new_nbits=0)
Set a bit to 1.
add
bool add(const std::string &hname, TKey *tobj)
Definition: fastadd.cxx:55
xAOD::AuxCompression::m_compression_map
std::map< unsigned int, std::set< std::string > > m_compression_map
Properties following the variable selection convention.
Definition: AuxCompression.h:36
AuxCompression.h
Pythia8_RapidityOrderMPI.val
val
Definition: Pythia8_RapidityOrderMPI.py:14
AuxTypeRegistry.h
Handle mappings between names and auxid_t.
collListGuids.attributes
attributes
Definition: collListGuids.py:46
SG::auxid_set_t
A set of aux data identifiers.
Definition: AuxTypes.h:47
xAOD::AuxCompression::AuxCompression
AuxCompression()
Default constructor.
Definition: AuxCompression.cxx:16
CxxUtils::ConcurrentBitset::erase
ConcurrentBitset & erase(bit_t bit)
Turn off one bit.
CxxUtils::ConcurrentBitset::test
bool test(bit_t bit) const
Test to see if a bit is set.