Loading [MathJax]/extensions/tex2jax.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
Typedefs | Functions
xAOD::Utils Namespace Reference

Typedefs

using RNTupleReader = ROOT::Experimental::RNTupleReader
 

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...
 
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 getFirstFieldMatch (RNTupleReader &ntupleReader, const std::string &pre)
 This function is used to search for a field in an RNTupleReader that contains a given substring. More...
 
::Bool_t fieldExists (std::string fieldName, RNTupleReader &ntupleReader)
 This function is used to check if a field exists in an RNTupleReader. 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...
 

Typedef Documentation

◆ RNTupleReader

using xAOD::Utils::RNTupleReader = typedef ROOT::Experimental::RNTupleReader

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  }

◆ fieldExists()

Bool_t xAOD::Utils::fieldExists ( std::string  fieldName,
RNTupleReader ntupleReader 
)

This function is used to check if a field exists in an RNTupleReader.

Checks if a given field exists in the ntuple.

Parameters
fieldNameThe name of the field to check
ntupleReaderThe RNTupleReader to check in
Returns
True if the field exists, false otherwise

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

405  {
406  // If it cannot find a field id it will give the maximum value of
407  // unsigned long
408  if( ntupleReader.GetDescriptor().FindFieldId( fieldName ) ==
410  return kFALSE;
411  }
412  return kTRUE;
413  }

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

351  {
352  const TObjArray * pBranches = tree->GetListOfBranches();
353  const std::regex pattern( ".*" + pre + ".*" );
354 
355  for( int i = 0, nLast = pBranches->GetLast(); i <= nLast; ++i ) {
356  const std::string name = pBranches->At(i)->GetName();
357 
358  if( std::regex_match( name, pattern ) )
359  return name;
360 
361  }
362 
363  return pre;
364  }

◆ getFirstFieldMatch()

std::string xAOD::Utils::getFirstFieldMatch ( RNTupleReader ntupleReader,
const std::string &  pre 
)

This function is used to search for a field in an RNTupleReader that contains a given substring.

Search for fields, returns search term on no result.

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

Parameters
ntupleReaderThe RNTupleReader to search in
preThe search term
Returns
The name of the first field that contains the search term

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

377  {
378  const std::regex pattern( ".*" + pre + ".*" );
379  ntupleReader.LoadEntry( 0 );
380  for( const auto& field :
381 #if ROOT_VERSION_CODE >= ROOT_VERSION( 6, 33, 0 )
382  ntupleReader.GetModel().GetConstFieldZero()
383  ) {
384  auto name = field.GetQualifiedFieldName();
385 #else
386  ntupleReader.GetModel().GetFieldZero().GetSubFields()
387  ) {
388  auto name = field->GetQualifiedFieldName();
389 #endif
390  if( std::regex_match( name, pattern ) ) {
391  return name;
392  }
393  }
394  return pre;
395  }

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

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

310  {
311 
312  // Get the "raw" type name:
313  std::string result = AthContainers_detail::typeinfoName( ti );
314 
315  // If there are no "tricky" classes in the name, then we're done
316  // already:
317  if( ( result.find( "DataVector<" ) == std::string::npos ) &&
318  ( result.find( "std::vector<" ) == std::string::npos ) &&
319  ( result.find( "std::__1::vector<") == std::string::npos ) ) {
320  return result;
321  }
322 
323  // Deal with the vector types:
324  removeDefaultTemplateParameters( result, "DataVector" );
325  removeDefaultTemplateParameters( result, "std::vector" );
326  removeDefaultTemplateParameters( result, "std::__1::vector" );
327 
328  // Make sure that no ">>" parts are left in the type name:
329  size_t pos = 0;
330  while( ( pos = result.find( ">>" ) ) != std::string::npos ) {
331  result.replace( pos, 2, "> >" );
332  }
333 
334  // Remove all "__1" namespaces from the type name:
335  while( ( pos = result.find( "__1::" ) ) != std::string::npos ) {
336  result.replace( pos, 5, "" );
337  }
338 
339  // Return the massaged name:
340  return result;
341  }

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

251  {
252 
253  // Do the hard-coded translation:
254  switch( typeidType ) {
255 
256  case 'c':
257  return 'B';
258  break;
259  case 'h':
260  return 'b';
261  break;
262  case 's':
263  return 'S';
264  break;
265  case 't':
266  return 's';
267  break;
268  case 'i':
269  return 'I';
270  break;
271  case 'j':
272  return 'i';
273  break;
274  case 'f':
275  return 'F';
276  break;
277  case 'd':
278  return 'D';
279  break;
280  case 'x':
281  return 'L';
282  break;
283  case 'y':
284  case 'm': // Not sure how platform-independent this one is...
285  return 'l';
286  break;
287  case 'b':
288  return 'O';
289  break;
290  }
291 
292  // If we didn't find this type:
293  Error( "xAOD::Utils::rootType",
294  XAOD_MESSAGE( "Received an unknown type: %c" ), typeidType );
295  return '\0';
296  }

◆ 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
get_generator_info.result
result
Definition: get_generator_info.py:21
max
constexpr double max()
Definition: ap_fixedTest.cxx:33
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
ReadOfcFromCool.field
field
Definition: ReadOfcFromCool.py:48
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
taskman.fieldName
fieldName
Definition: taskman.py:492
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
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
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