ATLAS Offline Software
Functions
xAOD::Utils Namespace Reference

Functions

SG::sgkey_t hash (const std::string &name)
 This function provides a hashed version of the key (branch) names used in the xAOD file, similar to how Athena saves hashed numbers in persistent ElementLinks. More...
 
std::string dynBranchPrefix (const std::string &key)
 This function is used to figure out what to name dynamic auxiliary branches coming from a container called key. More...
 
const std::type_info & getTypeInfo (EDataType type)
 This function is used when reading a primitive branch from an input file without the user explicitly asking for it. More...
 
char rootType (char typeidType)
 This function is used internally in the code when creating primitive dynamic auxiliary branches. More...
 
std::string getTypeName (const std::type_info &ti)
 This function is necessary in order to create type names that ROOT can understand. More...
 
std::string getFirstBranchMatch (TTree *tree, const std::string &pre)
 Search for branches, returns search term on no result. More...
 
std::string timeToString (::Double_t secs)
 Function creating a human-readable elapsed time printout. More...
 
std::string sizeToString (::Long64_t bytes)
 Function for printing data sizes in human-readable format. More...
 
std::string speedToString (::Double_t bytespersec)
 Function for printing data processing speeds in a human-readable format. More...
 

Function Documentation

◆ dynBranchPrefix()

std::string xAOD::Utils::dynBranchPrefix ( const std::string &  key)

This function is used to figure out what to name dynamic auxiliary branches coming from a container called key.

Get the dynamic auxiliary variable prefix based on a container name.

It needs to work in sync wiht how it is done in the offline code, so will eventually probably end up in another package.

Parameters
keyThe key/branch name of the auxiliary container
Returns
The prefix of the dynamic variables created based on the contents of the object

Definition at line 144 of file Control/xAODRootAccess/Root/Utils.cxx.

144  {
145 
146  // Make a copy of the key that we can modify:
147  std::string result = key;
148 
149  // If it ends in a dot, then let's exchange that dot for
150  // "Dyn.":
151  if( result[ result.size() - 1 ] == '.' ) {
152  result.replace( result.size() - 1, 1, "Dyn." );
153  }
154  // If it doesn't end in a dot, then let's just add "Dyn." at
155  // the end, and be done with it:
156  else {
157  result += "Dyn.";
158  }
159 
160  return result;
161  }

◆ getFirstBranchMatch()

std::string xAOD::Utils::getFirstBranchMatch ( TTree *  tree,
const std::string &  pre 
)

Search for branches, returns search term on no result.

Definition at line 318 of file Control/xAODRootAccess/Root/Utils.cxx.

319  {
320  const TObjArray * pBranches = tree->GetListOfBranches();
321  const std::regex pattern( ".*" + pre + ".*" );
322 
323  for( int i = 0, nLast = pBranches->GetLast(); i <= nLast; ++i ) {
324  const std::string name = pBranches->At(i)->GetName();
325 
326  if( std::regex_match( name, pattern ) )
327  return name;
328 
329  }
330 
331  return pre;
332  }

◆ getTypeInfo()

const std::type_info & xAOD::Utils::getTypeInfo ( EDataType  type)

This function is used when reading a primitive branch from an input file without the user explicitly asking for it.

Get the type info of a primitive variable, as declared by ROOT.

Parameters
typeThe type taken from ROOT
Returns
The typeid of the primitive type in question

Definition at line 169 of file Control/xAODRootAccess/Root/Utils.cxx.

169  {
170 
171  switch( type ) {
172 
173  case kChar_t:
174  case kchar:
175  return typeid( Char_t );
176  case kUChar_t:
177  return typeid( UChar_t );
178  case kShort_t:
179  return typeid( Short_t );
180  case kUShort_t:
181  return typeid( UShort_t );
182  case kInt_t:
183  case kCounter:
184  return typeid( Int_t );
185  case kUInt_t:
186  case kBits:
187  case kDataTypeAliasUnsigned_t:
188  return typeid( UInt_t );
189  case kLong_t:
190  return typeid( Long_t );
191  case kULong_t:
192  return typeid( ULong_t );
193  case kFloat_t:
194  return typeid( Float_t );
195  case kDouble_t:
196  return typeid( Double_t );
197  case kDouble32_t:
198  return typeid( Double32_t );
199  case kBool_t:
200  return typeid( Bool_t );
201  case kLong64_t:
202  return typeid( Long64_t );
203  case kULong64_t:
204  return typeid( ULong64_t );
205  case kFloat16_t:
206  return typeid( Float16_t );
207  case kCharStar:
208  return typeid( char* );
209  case kVoid_t:
210  return typeid( void );
211  default:
212  ::Error( "xAOD::Utils::getTypeInfo",
213  XAOD_MESSAGE( "Unknown data type (%i) received" ),
214  static_cast< int >( type ) );
215  return typeid( void );
216  }
217  }

◆ getTypeName()

std::string xAOD::Utils::getTypeName ( const std::type_info &  ti)

This function is necessary in order to create type names that ROOT can understand.

Get the type name as it is known to ROOT, based on std::type_info.

For instance, a type name like std::vector<ElementLink<DataVector<xAOD::IParticle, DataModel_detail::NoBase> >, std::allocator<ElementLink<DataVector<xAOD::IParticle, DataModel_detail::NoBase> > > > as seen by the compiler, needs to become std::vector<ElementLink<DataVector<xAOD::IParticle> > > for ROOT to find a dictionary for it.

This function executes the string manipulation necessary to do this.

Parameters
tiThe type for which we want to find a string type name
Returns
The type name in a format that ROOT understands

Definition at line 285 of file Control/xAODRootAccess/Root/Utils.cxx.

285  {
286 
287  // Get the "raw" type name:
288  std::string result = AthContainers_detail::typeinfoName( ti );
289 
290  // If there are no "tricky" classes in the name, then we're done
291  // already:
292  if( ( result.find( "DataVector<" ) == std::string::npos ) &&
293  ( result.find( "std::vector<" ) == std::string::npos ) &&
294  ( result.find( "std::__1::vector<") == std::string::npos ) ) {
295  return result;
296  }
297 
298  // Deal with the vector types:
299  removeDefaultTemplateParameters( result, "DataVector" );
300  removeDefaultTemplateParameters( result, "std::vector" );
301  removeDefaultTemplateParameters( result, "std::__1::vector" );
302 
303  // Make sure that no ">>" parts are left in the type name:
304  size_t pos = 0;
305  while( ( pos = result.find( ">>" ) ) != std::string::npos ) {
306  result.replace( pos, 2, "> >" );
307  }
308 
309  // Remove all "__1" namespaces from the type name:
310  while( ( pos = result.find( "__1::" ) ) != std::string::npos ) {
311  result.replace( pos, 5, "" );
312  }
313 
314  // Return the massaged name:
315  return result;
316  }

◆ hash()

SG::sgkey_t xAOD::Utils::hash ( const std::string &  name)

This function provides a hashed version of the key (branch) names used in the xAOD file, similar to how Athena saves hashed numbers in persistent ElementLinks.

Function creating a hash out of a "key name".

Since Athena uses the top 2 bits in a hashed key to save additional state information about the link, the top 2 bits of the hash are always set to 0.

Parameters
nameThe name that we want to create a unique hash for
Returns
A more or less unique hash for the string

Definition at line 125 of file Control/xAODRootAccess/Root/Utils.cxx.

125  {
126 
127  static constexpr SG::sgkey_t MASK = (~static_cast<SG::sgkey_t>(0)) >> 2;
128 
129  // The helper object:
130  static const std::hash< std::string > helper;
131  // Let the helper do the work:
132  return ( static_cast< SG::sgkey_t >( helper( name ) ) & MASK );
133  }

◆ rootType()

char xAOD::Utils::rootType ( char  typeidType)

This function is used internally in the code when creating primitive dynamic auxiliary branches.

Get the character describing a given primitive type for ROOT.

I just took the code from SFrame to be honest...

Parameters
typeidTypeThe type name coming from typeid(...).name()
Returns
The character describing this type for TTree::Branch(...)

Definition at line 226 of file Control/xAODRootAccess/Root/Utils.cxx.

226  {
227 
228  // Do the hard-coded translation:
229  switch( typeidType ) {
230 
231  case 'c':
232  return 'B';
233  break;
234  case 'h':
235  return 'b';
236  break;
237  case 's':
238  return 'S';
239  break;
240  case 't':
241  return 's';
242  break;
243  case 'i':
244  return 'I';
245  break;
246  case 'j':
247  return 'i';
248  break;
249  case 'f':
250  return 'F';
251  break;
252  case 'd':
253  return 'D';
254  break;
255  case 'x':
256  return 'L';
257  break;
258  case 'y':
259  case 'm': // Not sure how platform-independent this one is...
260  return 'l';
261  break;
262  case 'b':
263  return 'O';
264  break;
265  }
266 
267  // If we didn't find this type:
268  Error( "xAOD::Utils::rootType",
269  XAOD_MESSAGE( "Received an unknown type: %c" ), typeidType );
270  return '\0';
271  }

◆ sizeToString()

std::string xAOD::Utils::sizeToString ( ::Long64_t  bytes)

Function for printing data sizes in human-readable format.

This function is used to produce nicely readable printouts for amounts of data.

Parameters
bytesThe amount of data expressed in bytes
Returns
A human-readable printout of the data size

Definition at line 129 of file Event/xAOD/xAODCore/Root/Utils.cxx.

129  {
130 
131  std::ostringstream result;
132 
133  if( std::abs( bytes ) > 1e12 ) {
134  result << ( bytes * 1e-12 ) << " TB";
135  } else if( std::abs( bytes ) > 1e9 ) {
136  result << ( bytes * 1e-9 ) << " GB";
137  } else if( std::abs( bytes ) > 1e6 ) {
138  result << ( bytes * 1e-6 ) << " MB";
139  } else if( std::abs( bytes ) > 1e3 ) {
140  result << ( bytes * 1e-3 ) << " kB";
141  } else {
142  result << bytes << " bytes";
143  }
144 
145  return result.str();
146  }

◆ speedToString()

std::string xAOD::Utils::speedToString ( ::Double_t  bytespersec)

Function for printing data processing speeds in a human-readable format.

Parameters
bytespersecThe speed expressed in bytes / seconds
Returns
A human-readable printout of the data processing speed

Definition at line 151 of file Event/xAOD/xAODCore/Root/Utils.cxx.

151  {
152 
153  std::ostringstream result;
154 
155  if( ::fabs( bytespersec ) > 1e12 ) {
156  result << ( bytespersec * 1e-12 ) << " TB/s";
157  } else if( ::fabs( bytespersec ) > 1e9 ) {
158  result << ( bytespersec * 1e-9 ) << " GB/s";
159  } else if( ::fabs( bytespersec ) > 1e6 ) {
160  result << ( bytespersec * 1e-6 ) << " MB/s";
161  } else if( ::fabs( bytespersec ) > 1e3 ) {
162  result << ( bytespersec * 1e-3 ) << " kB/s";
163  } else {
164  result << bytespersec << " B/s";
165  }
166 
167  return result.str();
168  }

◆ timeToString()

std::string xAOD::Utils::timeToString ( ::Double_t  secs)

Function creating a human-readable elapsed time printout.

Since I wasn't able to find a nice function printing elapsed times in a human-readable format, I ended up writing one.

This function is used in printing the statistics about an analysis.

Parameters
secsAn amount of time passed, expressed in seconds
Returns
A formatted, human-readable version of the amount of time passed

Definition at line 99 of file Event/xAOD/xAODCore/Root/Utils.cxx.

99  {
100 
101  // Do meat of the calculation:
102  const TimeStruct ts = timeToStruct( secs );
103 
104  // Construct the string:
105  std::ostringstream result;
106  if( ts.days ) {
107  result << ts.days << "d ";
108  }
109  if( ts.hours || ts.days ) {
110  result << ts.hours << "h ";
111  }
112  if( ts.minutes || ts.hours || ts.days ) {
113  result << ts.minutes << "m ";
114  }
115  if( ts.seconds || ts.minutes || ts.hours || ts.days ) {
116  result << ts.seconds << "s ";
117  }
118  result << ts.miliseconds << "ms";
119 
120  return result.str();
121  }
mergePhysValFiles.pattern
pattern
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:26
get_generator_info.result
result
Definition: get_generator_info.py:21
tree
TChain * tree
Definition: tile_monitor.h:30
XAOD_MESSAGE
#define XAOD_MESSAGE(MESSAGE)
Simple macro for printing error/verbose messages.
Definition: Control/xAODRootAccess/xAODRootAccess/tools/Message.h:19
runBeamSpotCalibration.helper
helper
Definition: runBeamSpotCalibration.py:112
PrepareReferenceFile.regex
regex
Definition: PrepareReferenceFile.py:43
CheckAppliedSFs.e3
e3
Definition: CheckAppliedSFs.py:264
lumiFormat.i
int i
Definition: lumiFormat.py:92
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:192
SG::sgkey_t
uint32_t sgkey_t
Type used for hashed StoreGate key+CLID pairs.
Definition: CxxUtils/CxxUtils/sgkey_t.h:32
python.LumiBlobConversion.pos
pos
Definition: LumiBlobConversion.py:18
DiTauMassTools::MaxHistStrategyV2::e
e
Definition: PhysicsAnalysis/TauID/DiTauMassTools/DiTauMassTools/HelperFunctions.h:26
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
L1Topo::Error
Error
The different types of error that can be flagged in the L1TopoRDO.
Definition: Error.h:16
python.CaloScaleNoiseConfig.ts
ts
Definition: CaloScaleNoiseConfig.py:86
RoiUtil::MASK
MASK
Definition: RoiSerialise.cxx:35
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37