ATLAS Offline Software
Loading...
Searching...
No Matches
CP::TreeBranchHelpers::BranchConfig Struct Reference

the user configuration of an output branch More...

#include <TreeBranchHelpers.h>

Collaboration diagram for CP::TreeBranchHelpers::BranchConfig:

Public Member Functions

StatusCode parse (const std::string &branchDecl, MsgStream &msg)
 parse the user configuration string
StatusCode configureTypes (std::set< std::string > &decosWithoutType, MsgStream &msg)
 configure the associated decoration types
StatusCode configureSystematics (ISystematicsSvc &sysSvc, MsgStream &msg)
 configure the systematics

Public Attributes

std::string branchDecl
 the original user configuration string
std::string sgName
 the SG name of the object to read from
std::string auxName
 the aux data variable name to read from
std::string branchName
 the name of the output branch
std::string typeName
 the name of the type (or empty to read from aux-registry)
bool nominalOnly = false
 whether we only want to write out the nominal
std::optional< intbasketSize
 the basket size for this branch
std::string metTermName
 MET ONLY: the name of the MET term to write out.
SG::auxid_t nominalAuxId = SG::null_auxid
 the aux-id for the nominal decoration
const std::type_info * auxType = nullptr
 the type of the decoration we read
const std::type_info * auxVecType = nullptr
 the vector type of the decoration we read
const SG::IAuxTypeVectorFactoryauxFactory = nullptr
 pointer to the aux vector factory
CP::SystematicSet sgNameFilterSys
 the affecting systematics for the sgName
CP::SystematicSet auxNameFilterSys
 the affecting systematics for the auxName
CP::SystematicSet branchNameFilterSys
 the affecting systematics for the branchName

Detailed Description

the user configuration of an output branch

Definition at line 61 of file TreeBranchHelpers.h.

Member Function Documentation

◆ configureSystematics()

StatusCode CP::TreeBranchHelpers::BranchConfig::configureSystematics ( ISystematicsSvc & sysSvc,
MsgStream & msg )

configure the systematics

Definition at line 439 of file TreeBranchHelpers.cxx.

441 {
442 if (sgName.find ("%SYS%") == std::string::npos &&
443 auxName.find ("%SYS%") == std::string::npos &&
444 branchName.find ("%SYS%") == std::string::npos)
445 {
446 nominalOnly = true;
447 }
448 if (!nominalOnly)
449 {
450 if (branchName.find ("%SYS%") == std::string::npos)
451 {
452 msg << MSG::ERROR << "Branch with systematics without %SYS% in branch name: "
453 << branchName << endmsg;
454 return StatusCode::FAILURE;
455 }
456 if (sgName.find ("%SYS%") == std::string::npos &&
457 auxName.find ("%SYS%") == std::string::npos)
458 {
459 msg << MSG::ERROR << "Branch with systematics without %SYS% in SG or aux name: "
460 << sgName << "." << auxName << endmsg;
461 return StatusCode::FAILURE;
462 }
463 if (auxName.find ("NOSYS") != std::string::npos)
464 {
465 msg << MSG::ERROR << "Branch with systematics with NOSYS in aux name: "
466 << sgName << "." << auxName << endmsg;
467 return StatusCode::FAILURE;
468 }
469 if (sgName.find ("NOSYS") != std::string::npos && auxName.find ("%SYS%") == std::string::npos)
470 {
471 msg << MSG::ERROR << "Branch with NOSYS in SG name but without %SYS% in aux name: "
472 << sgName << "." << auxName << endmsg;
473 return StatusCode::FAILURE;
474 }
475
476 if (sgName.find ("%SYS%") != std::string::npos)
477 sgNameFilterSys = sysSvc.getObjectSystematics( sgName );
478
479 if (auxName.find ("%SYS%") != std::string::npos)
480 {
481 if (auto pos = sgName.find ("NOSYS"); pos == std::string::npos)
482 auxNameFilterSys = sysSvc.getDecorSystematics (sgName, auxName);
483 else
484 {
485 // Sometimes while object systematics were applied we are not interested in them,
486 // NOSYS will then be used on the container name.
487 // Decoration systematics however will only be aware of containers with %SYS% included.
488 // Some special handling is needed to translate from NOSYS back to %SYS%.
489 std::string sgNameSys = sgName;
490 sgNameSys.replace (pos, 5, "%SYS%");
491
492 // these will be the object systematics
493 auto objectSys = sysSvc.getObjectSystematics (sgNameSys);
494
495 // these will be all systematics (object+decor)
496 auto allSys = sysSvc.getDecorSystematics (sgNameSys, auxName);
497
498 // we now need to filter-out object systematics
499 for (auto& variation : allSys)
500 {
501 if (objectSys.find (variation) == objectSys.end())
502 auxNameFilterSys.insert (variation);
503 }
504 }
505 }
506
509 if (branchNameFilterSys.empty())
510 nominalOnly = true;
511 }
512
513 return StatusCode::SUCCESS;
514 }
#define endmsg
std::string sgName
the SG name of the object to read from
std::string auxName
the aux data variable name to read from
CP::SystematicSet auxNameFilterSys
the affecting systematics for the auxName
CP::SystematicSet sgNameFilterSys
the affecting systematics for the sgName
CP::SystematicSet branchNameFilterSys
the affecting systematics for the branchName
std::string branchName
the name of the output branch
bool nominalOnly
whether we only want to write out the nominal
MsgStream & msg
Definition testRead.cxx:32

◆ configureTypes()

StatusCode CP::TreeBranchHelpers::BranchConfig::configureTypes ( std::set< std::string > & decosWithoutType,
MsgStream & msg )

configure the associated decoration types

Definition at line 360 of file TreeBranchHelpers.cxx.

362 {
363 std::string nominalAuxName = auxName;
364 if (auto pos = nominalAuxName.find ("%SYS%"); pos != std::string::npos)
365 nominalAuxName.replace (pos, 5, "NOSYS");
366 if (!typeName.empty())
367 {
368 if (typeName == "char")
369 SG::ConstAccessor<char> {nominalAuxName};
370 else if (typeName == "float")
371 SG::ConstAccessor<float> {nominalAuxName};
372 else if (typeName == "int")
373 SG::ConstAccessor<int> {nominalAuxName};
374 else if (typeName == "unsigned")
375 SG::ConstAccessor<unsigned> {nominalAuxName};
376 else if (typeName == "uint16")
377 SG::ConstAccessor<std::uint16_t> {nominalAuxName};
378 else if (typeName == "uint32")
379 SG::ConstAccessor<std::uint32_t> {nominalAuxName};
380 else
381 {
382 unsigned line = __LINE__ - 2;
383 std::string file = __FILE__;
384 file = file.substr (file.find_last_of("/\\") + 1);
385 msg << MSG::ERROR << "Unknown type requested, please extend " << file << " near line " << line << " for type " << typeName << endmsg;
386 return StatusCode::FAILURE;
387 }
388 }
389 const SG::AuxTypeRegistry& reg = SG::AuxTypeRegistry::instance();
391 {
392 nominalAuxId = reg.findAuxID (nominalAuxName);
394 {
395 decosWithoutType.insert (nominalAuxName);
396 msg << MSG::DEBUG << "No aux ID found for auxiliary variable: " << nominalAuxName << endmsg;
397 // just returning SUCCESS here, our caller will report failure
398 return StatusCode::SUCCESS;
399 }
400 }
401 if (auxType == nullptr)
402 {
403 auxType = reg.getType (nominalAuxId);
404 if (auxType == nullptr)
405 {
406 msg << MSG::ERROR
407 << "No std::type_info available for aux-store variable: "
408 << nominalAuxName << endmsg;
409 return StatusCode::FAILURE;
410 }
411 }
412 if (auxVecType == nullptr)
413 {
414 auxVecType = reg.getVecType (nominalAuxId);
415 if (auxVecType == nullptr)
416 {
417 msg << MSG::ERROR
418 << "No std::type_info available for aux-store variable: "
419 << nominalAuxName << endmsg;
420 return StatusCode::FAILURE;
421 }
422 }
423 if (auxFactory == nullptr)
424 {
425 auxFactory = reg.getFactory (nominalAuxId);
426 if (auxFactory == nullptr)
427 {
428 msg << MSG::ERROR
429 << "No factory found for auxiliary variable: "
430 << nominalAuxName << endmsg;
431 return StatusCode::FAILURE;
432 }
433 }
434 return StatusCode::SUCCESS;
435 }
static AuxTypeRegistry & instance()
Return the singleton registry instance.
static const auxid_t null_auxid
To signal no aux data item.
Definition AuxTypes.h:30
const SG::IAuxTypeVectorFactory * auxFactory
pointer to the aux vector factory
const std::type_info * auxVecType
the vector type of the decoration we read
const std::type_info * auxType
the type of the decoration we read
SG::auxid_t nominalAuxId
the aux-id for the nominal decoration
std::string typeName
the name of the type (or empty to read from aux-registry)
TFile * file

◆ parse()

StatusCode CP::TreeBranchHelpers::BranchConfig::parse ( const std::string & branchDecl,
MsgStream & msg )

parse the user configuration string

Definition at line 320 of file TreeBranchHelpers.cxx.

322 {
323 // The regular expression used to extract the needed info. The logic
324 // is supposed to be:
325 //
326 // (match[1]).(match[2])<any whitespace>-><any whitespace>(match[3])[<any whitespace>type=(match[5])][<any whitespace>metTerm=(match[7])][<any whitespace>basketSize=(match[9])]
327 //
328 // Like:
329 // "Electrons.eta -> el_eta"
330 // "Electrons.eta -> el_eta type=float"
331 // "MissingET.px -> met_px metTerm=Final"
332 static const std::regex
333 re( "\\s*([\\w%]+)\\.([\\w%]+)\\s*->\\s*([\\w%]+)(\\s+type=([\\w%]+))?(\\s+metTerm=([\\w%]+))?(\\s+basketSize=([\\w%]+))?" );
334
335 // Interpret this branch declaration.
336 std::smatch match;
337 if( ! std::regex_match( branchDecl, match, re ) ) {
338 msg << MSG::ERROR << "Expression \"" << branchDecl << "\" doesn't match \"<object>.<variable> -> <branch>\"" << endmsg;
339 return StatusCode::FAILURE;
340 }
341 this->branchDecl = branchDecl;
342 sgName = match[ 1 ];
343 auxName = match[ 2 ];
344 branchName = match[ 3 ];
345 typeName = match[ 5 ];
346 metTermName = match[ 7 ];
347 if (match[9].matched) {
348 try {
349 basketSize = std::stoi(match[9]);
350 } catch (const std::exception& ) {
351 msg << MSG::ERROR << "Could not parse basket size value: " << match[9] << endmsg;
352 return StatusCode::FAILURE;
353 }
354 }
355 return StatusCode::SUCCESS;
356 }
const boost::regex re(r_e)
bool match(std::string s1, std::string s2)
match the individual directories of two strings
Definition hcg.cxx:357
std::string branchDecl
the original user configuration string
std::optional< int > basketSize
the basket size for this branch
std::string metTermName
MET ONLY: the name of the MET term to write out.

Member Data Documentation

◆ auxFactory

const SG::IAuxTypeVectorFactory* CP::TreeBranchHelpers::BranchConfig::auxFactory = nullptr

pointer to the aux vector factory

Definition at line 98 of file TreeBranchHelpers.h.

◆ auxName

std::string CP::TreeBranchHelpers::BranchConfig::auxName

the aux data variable name to read from

Definition at line 70 of file TreeBranchHelpers.h.

◆ auxNameFilterSys

CP::SystematicSet CP::TreeBranchHelpers::BranchConfig::auxNameFilterSys

the affecting systematics for the auxName

Definition at line 105 of file TreeBranchHelpers.h.

◆ auxType

const std::type_info* CP::TreeBranchHelpers::BranchConfig::auxType = nullptr

the type of the decoration we read

Definition at line 92 of file TreeBranchHelpers.h.

◆ auxVecType

const std::type_info* CP::TreeBranchHelpers::BranchConfig::auxVecType = nullptr

the vector type of the decoration we read

Definition at line 95 of file TreeBranchHelpers.h.

◆ basketSize

std::optional<int> CP::TreeBranchHelpers::BranchConfig::basketSize

the basket size for this branch

Definition at line 82 of file TreeBranchHelpers.h.

◆ branchDecl

std::string CP::TreeBranchHelpers::BranchConfig::branchDecl

the original user configuration string

Definition at line 64 of file TreeBranchHelpers.h.

◆ branchName

std::string CP::TreeBranchHelpers::BranchConfig::branchName

the name of the output branch

Definition at line 73 of file TreeBranchHelpers.h.

◆ branchNameFilterSys

CP::SystematicSet CP::TreeBranchHelpers::BranchConfig::branchNameFilterSys

the affecting systematics for the branchName

Definition at line 108 of file TreeBranchHelpers.h.

◆ metTermName

std::string CP::TreeBranchHelpers::BranchConfig::metTermName

MET ONLY: the name of the MET term to write out.

Definition at line 85 of file TreeBranchHelpers.h.

◆ nominalAuxId

SG::auxid_t CP::TreeBranchHelpers::BranchConfig::nominalAuxId = SG::null_auxid

the aux-id for the nominal decoration

Definition at line 89 of file TreeBranchHelpers.h.

◆ nominalOnly

bool CP::TreeBranchHelpers::BranchConfig::nominalOnly = false

whether we only want to write out the nominal

Definition at line 79 of file TreeBranchHelpers.h.

◆ sgName

std::string CP::TreeBranchHelpers::BranchConfig::sgName

the SG name of the object to read from

Definition at line 67 of file TreeBranchHelpers.h.

◆ sgNameFilterSys

CP::SystematicSet CP::TreeBranchHelpers::BranchConfig::sgNameFilterSys

the affecting systematics for the sgName

Definition at line 102 of file TreeBranchHelpers.h.

◆ typeName

std::string CP::TreeBranchHelpers::BranchConfig::typeName

the name of the type (or empty to read from aux-registry)

Definition at line 76 of file TreeBranchHelpers.h.


The documentation for this struct was generated from the following files: