ATLAS Offline Software
Loading...
Searching...
No Matches
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.
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.
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.
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.
const std::type_info & getTypeInfo (std::string_view typeName)
 Get the type info of a primitive variable, in an RNTuple.
bool isPrimitiveType (std::string_view typeName)
 Check if the type name describes a primitive type.
char rootType (char typeidType)
 This function is used internally in the code when creating primitive dynamic auxiliary branches.
std::string getTypeName (const std::type_info &ti)
 This function is necessary in order to create type names that ROOT can understand.
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.
std::string timeToString (::Double_t secs)
 Function creating a human-readable elapsed time printout.
std::string sizeToString (::Long64_t bytes)
 Function for printing data sizes in human-readable format.
std::string speedToString (::Double_t bytespersec)
 Function for printing data processing speeds in a human-readable format.

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

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

◆ 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 }
#define XAOD_MESSAGE(MESSAGE)
Simple macro for printing error/verbose messages.

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

265 {
267 ::Error("xAOD::Utils::getTypeInfo",
268 XAOD_MESSAGE("Unknown data type (%s) received"),
269 typeName.data());
270 return typeid(void);
271 }
#define TYPE_CHECK_INSTANTIATE(MACRO)
Macro instantiating another macro for all usual "primitive" types.
#define GETTYPEINFO_SPECIALIZE(TYPE)
Macro returning the type info for a given type name.
char data[hepevt_bytes_allocation_ATLAS]
Definition HepEvt.cxx:11

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

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

◆ 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 }
uint32_t sgkey_t
Type used for hashed StoreGate key+CLID pairs.
Definition sgkey_t.h:32

◆ isPrimitiveType()

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

Check if the type name describes a primitive type.

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

280 {
282 return false;
283 }
#define ISPRIMITIVETYPE_SPECIALIZE(TYPE)

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

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

◆ 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 }
int ts
Definition globals.cxx:24