Loading [MathJax]/extensions/tex2jax.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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...
 
std::string dynFieldPrefix (const std::string &key)
 This function is used to figure out what to name dynamic auxiliary field 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...
 
const std::type_info & getTypeInfo (std::string_view typeName)
 Get the type info of a primitive variable, in an RNTuple. More...
 
bool isPrimitiveType (std::string_view typeName)
 Check if the type name describes a primitive type. 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)
 This function is used to search for a branch in a TTree that contains a given substring. 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 (for TTree)

It needs to work in sync with 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  }

◆ dynFieldPrefix()

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

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

Get the dynamic auxiliary variable prefix based on a container name (for RNTuple)

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

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

170  {
171  // Make a copy of the key that we can modify:
172  std::string result = key;
173 
174  // If it ends in a colon, then let's exchange that colon for
175  // "Dyn:":
176  if( result[ result.size() - 1 ] == ':' ) {
177  result.replace( result.size() - 1, 1, "Dyn:" );
178  }
179  // If it doesn't end in a colon, then let's just add "Dyn:" at
180  // the end:
181  else {
182  result += "Dyn:";
183  }
184 
185  return result;
186  }

◆ getFirstBranchMatch()

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

This function is used to search for a branch in a TTree that contains a given substring.

Search for branches, returns search term on no result.

It returns the name of the first branch that contains the search term. If no branch is found, the function returns the search term itself.

Parameters
treeThe TTree to search in
preThe search term
Returns
The name of the first branch that contains the search term

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

393  {
394  const TObjArray * pBranches = tree->GetListOfBranches();
395  const std::regex pattern( ".*" + pre + ".*" );
396 
397  for( int i = 0, nLast = pBranches->GetLast(); i <= nLast; ++i ) {
398  const std::string name = pBranches->At(i)->GetName();
399 
400  if( std::regex_match( name, pattern ) )
401  return name;
402 
403  }
404 
405  return pre;
406  }

◆ getTypeInfo() [1/2]

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 194 of file Control/xAODRootAccess/Root/Utils.cxx.

194  {
195 
196  switch( type ) {
197 
198  case kChar_t:
199  case kchar:
200  return typeid( Char_t );
201  case kUChar_t:
202  return typeid( UChar_t );
203  case kShort_t:
204  return typeid( Short_t );
205  case kUShort_t:
206  return typeid( UShort_t );
207  case kInt_t:
208  case kCounter:
209  return typeid( Int_t );
210  case kUInt_t:
211  case kBits:
212  case kDataTypeAliasUnsigned_t:
213  return typeid( UInt_t );
214  case kLong_t:
215  return typeid( Long_t );
216  case kULong_t:
217  return typeid( ULong_t );
218  case kFloat_t:
219  return typeid( Float_t );
220  case kDouble_t:
221  return typeid( Double_t );
222  case kDouble32_t:
223  return typeid( Double32_t );
224  case kBool_t:
225  return typeid( Bool_t );
226  case kLong64_t:
227  return typeid( Long64_t );
228  case kULong64_t:
229  return typeid( ULong64_t );
230  case kFloat16_t:
231  return typeid( Float16_t );
232  case kCharStar:
233  return typeid( char* );
234  case kVoid_t:
235  return typeid( void );
236  default:
237  ::Error( "xAOD::Utils::getTypeInfo",
238  XAOD_MESSAGE( "Unknown data type (%i) received" ),
239  static_cast< int >( type ) );
240  return typeid( void );
241  }
242  }

◆ getTypeInfo() [2/2]

const std::type_info & xAOD::Utils::getTypeInfo ( std::string_view  typeName)

Get the type info of a primitive variable, in an RNTuple.

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

263  {
265  ::Error("xAOD::Utils::getTypeInfo",
266  XAOD_MESSAGE("Unknown data type (%s) received"),
267  typeName.data());
268  return typeid(void);
269  }

◆ 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 352 of file Control/xAODRootAccess/Root/Utils.cxx.

352  {
353 
354  // Get the "raw" type name:
355  std::string result = AthContainers_detail::typeinfoName( ti );
356 
357  // If there are no "tricky" classes in the name, then we're done
358  // already:
359  if( ( result.find( "DataVector<" ) == std::string::npos ) &&
360  ( result.find( "std::vector<" ) == std::string::npos ) &&
361  ( result.find( "std::__1::vector<") == std::string::npos ) ) {
362  return result;
363  }
364 
365  // Deal with the vector types:
366  removeDefaultTemplateParameters( result, "DataVector" );
367  removeDefaultTemplateParameters( result, "std::vector" );
368  removeDefaultTemplateParameters( result, "std::__1::vector" );
369 
370  // Make sure that no ">>" parts are left in the type name:
371  size_t pos = 0;
372  while( ( pos = result.find( ">>" ) ) != std::string::npos ) {
373  result.replace( pos, 2, "> >" );
374  }
375 
376  // Remove all "__1" namespaces from the type name:
377  while( ( pos = result.find( "__1::" ) ) != std::string::npos ) {
378  result.replace( pos, 5, "" );
379  }
380 
381  // Return the massaged name:
382  return result;
383  }

◆ 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  }

◆ isPrimitiveType()

bool xAOD::Utils::isPrimitiveType ( std::string_view  typeName)

Check if the type name describes a primitive type.

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

278  {
280  return false;
281  }

◆ 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 293 of file Control/xAODRootAccess/Root/Utils.cxx.

293  {
294 
295  // Do the hard-coded translation:
296  switch( typeidType ) {
297 
298  case 'c':
299  return 'B';
300  break;
301  case 'h':
302  return 'b';
303  break;
304  case 's':
305  return 'S';
306  break;
307  case 't':
308  return 's';
309  break;
310  case 'i':
311  return 'I';
312  break;
313  case 'j':
314  return 'i';
315  break;
316  case 'f':
317  return 'F';
318  break;
319  case 'd':
320  return 'D';
321  break;
322  case 'x':
323  return 'L';
324  break;
325  case 'y':
326  case 'm': // Not sure how platform-independent this one is...
327  return 'l';
328  break;
329  case 'b':
330  return 'O';
331  break;
332  }
333 
334  // If we didn't find this type:
335  Error( "xAOD::Utils::rootType",
336  XAOD_MESSAGE( "Received an unknown type: %c" ), typeidType );
337  return '\0';
338  }

◆ 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
AllowedVariables::e
e
Definition: AsgElectronSelectorTool.cxx:37
data
char data[hepevt_bytes_allocation_ATLAS]
Definition: HepEvt.cxx:11
GETTYPEINFO_SPECIALIZE
#define GETTYPEINFO_SPECIALIZE(TYPE)
Macro returning the type info for a given type name.
Definition: Control/xAODRootAccess/Root/Utils.cxx:258
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
python.CaloAddPedShiftConfig.type
type
Definition: CaloAddPedShiftConfig.py:42
runBeamSpotCalibration.helper
helper
Definition: runBeamSpotCalibration.py:112
PrepareReferenceFile.regex
regex
Definition: PrepareReferenceFile.py:43
CheckAppliedSFs.e3
e3
Definition: CheckAppliedSFs.py:264
Athena::typeinfoName
std::string typeinfoName(const std::type_info &ti)
Convert a type_info to a demangled string.
Definition: AthenaKernel/src/ClassName.cxx:23
lumiFormat.i
int i
Definition: lumiFormat.py:85
ISPRIMITIVETYPE_SPECIALIZE
#define ISPRIMITIVETYPE_SPECIALIZE(TYPE)
Definition: Control/xAODRootAccess/Root/Utils.cxx:273
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
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
TYPE_CHECK_INSTANTIATE
#define TYPE_CHECK_INSTANTIATE(MACRO)
Macro instantiating another macro for all usual "primitive" types.
Definition: Control/xAODRootAccess/Root/Utils.cxx:245
ReadCalibFromCool.typeName
typeName
Definition: ReadCalibFromCool.py:477
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:87
RoiUtil::MASK
MASK
Definition: RoiSerialise.cxx:35
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37