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 65 of file TreeBranchHelpers.h.

Member Function Documentation

◆ configureSystematics()

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

configure the systematics

Definition at line 500 of file TreeBranchHelpers.cxx.

502 {
503 if (sgName.find ("%SYS%") == std::string::npos &&
504 auxName.find ("%SYS%") == std::string::npos &&
505 branchName.find ("%SYS%") == std::string::npos)
506 {
507 nominalOnly = true;
508 }
509 if (!nominalOnly)
510 {
511 if (branchName.find ("%SYS%") == std::string::npos)
512 {
513 msg << MSG::ERROR << "Branch with systematics without %SYS% in branch name: "
514 << branchName << endmsg;
515 return StatusCode::FAILURE;
516 }
517 if (sgName.find ("%SYS%") == std::string::npos &&
518 auxName.find ("%SYS%") == std::string::npos)
519 {
520 msg << MSG::ERROR << "Branch with systematics without %SYS% in SG or aux name: "
521 << sgName << "." << auxName << endmsg;
522 return StatusCode::FAILURE;
523 }
524 if (auxName.find ("NOSYS") != std::string::npos)
525 {
526 msg << MSG::ERROR << "Branch with systematics with NOSYS in aux name: "
527 << sgName << "." << auxName << endmsg;
528 return StatusCode::FAILURE;
529 }
530 if (sgName.find ("NOSYS") != std::string::npos && auxName.find ("%SYS%") == std::string::npos)
531 {
532 msg << MSG::ERROR << "Branch with NOSYS in SG name but without %SYS% in aux name: "
533 << sgName << "." << auxName << endmsg;
534 return StatusCode::FAILURE;
535 }
536
537 if (sgName.find ("%SYS%") != std::string::npos)
538 sgNameFilterSys = sysSvc.getObjectSystematics( sgName );
539
540 if (auxName.find ("%SYS%") != std::string::npos)
541 {
542 if (auto pos = sgName.find ("NOSYS"); pos == std::string::npos)
543 auxNameFilterSys = sysSvc.getDecorSystematics (sgName, auxName);
544 else
545 {
546 // Sometimes while object systematics were applied we are not interested in them,
547 // NOSYS will then be used on the container name.
548 // Decoration systematics however will only be aware of containers with %SYS% included.
549 // Some special handling is needed to translate from NOSYS back to %SYS%.
550 std::string sgNameSys = sgName;
551 sgNameSys.replace (pos, 5, "%SYS%");
552
553 // these will be the object systematics
554 auto objectSys = sysSvc.getObjectSystematics (sgNameSys);
555
556 // these will be all systematics (object+decor)
557 auto allSys = sysSvc.getDecorSystematics (sgNameSys, auxName);
558
559 // we now need to filter-out object systematics
560 for (auto& variation : allSys)
561 {
562 if (objectSys.find (variation) == objectSys.end())
563 auxNameFilterSys.insert (variation);
564 }
565 }
566 }
567
570 if (branchNameFilterSys.empty())
571 nominalOnly = true;
572 }
573
574 return StatusCode::SUCCESS;
575 }
#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 367 of file TreeBranchHelpers.cxx.

369 {
370 std::string nominalAuxName = auxName;
371 if (auto pos = nominalAuxName.find ("%SYS%"); pos != std::string::npos)
372 nominalAuxName.replace (pos, 5, "NOSYS");
373 if (!typeName.empty())
374 {
375 if (typeName == "char")
376 SG::ConstAccessor<char> {nominalAuxName};
377 else if (typeName == "float")
378 SG::ConstAccessor<float> {nominalAuxName};
379 else if (typeName == "double")
380 SG::ConstAccessor<double> {nominalAuxName};
381 else if (typeName == "int")
382 SG::ConstAccessor<int> {nominalAuxName};
383 else if (typeName == "unsigned" || typeName == "unsigned_int")
384 SG::ConstAccessor<unsigned> {nominalAuxName};
385 else if (typeName == "unsigned_char")
386 SG::ConstAccessor<unsigned char> {nominalAuxName};
387 else if (typeName == "unsigned_long")
388 SG::ConstAccessor<unsigned long> {nominalAuxName};
389 else if (typeName == "unsigned_long_long")
391 else if (typeName == "int8")
392 SG::ConstAccessor<std::int8_t> {nominalAuxName};
393 else if (typeName == "int16")
394 SG::ConstAccessor<std::int16_t> {nominalAuxName};
395 else if (typeName == "int32")
396 SG::ConstAccessor<std::int32_t> {nominalAuxName};
397 else if (typeName == "int64")
398 SG::ConstAccessor<std::int64_t> {nominalAuxName};
399 else if (typeName == "uint8")
400 SG::ConstAccessor<std::uint8_t> {nominalAuxName};
401 else if (typeName == "uint16")
402 SG::ConstAccessor<std::uint16_t> {nominalAuxName};
403 else if (typeName == "uint32")
404 SG::ConstAccessor<std::uint32_t> {nominalAuxName};
405 else if (typeName == "uint64")
406 SG::ConstAccessor<std::uint64_t> {nominalAuxName};
407 else if (typeName == "vector_float")
408 SG::ConstAccessor<std::vector<float>> {nominalAuxName};
409 else if (typeName == "vector_int")
410 SG::ConstAccessor<std::vector<int>> {nominalAuxName};
411 else if (typeName == "vector_string")
413 else if (typeName == "vector_vector_float")
415 else if (typeName == "vector_vector_int")
417 else if (typeName == "PtEtaPhiEVector")
418 SG::ConstAccessor<PtEtaPhiEVector> {nominalAuxName};
419 else if (typeName == "PtEtaPhiMVector")
420 SG::ConstAccessor<PtEtaPhiMVector> {nominalAuxName};
421 else if (typeName == "PxPyPzEVector")
422 SG::ConstAccessor<PxPyPzEVector> {nominalAuxName};
423 else if (typeName == "PxPyPzMVector")
424 SG::ConstAccessor<PxPyPzMVector> {nominalAuxName};
425 else if (typeName == "vector_PtEtaPhiEVector")
427 else if (typeName == "vector_PtEtaPhiMVector")
429 else if (typeName == "vector_PxPyPzEVector")
431 else if (typeName == "vector_PxPyPzMVector")
433 else if (typeName == "vector_vector_PtEtaPhiEVector")
435 else if (typeName == "vector_vector_PtEtaPhiMVector")
437 else if (typeName == "vector_vector_PxPyPzEVector")
439 else if (typeName == "vector_vector_PxPyPzMVector")
441 else
442 {
443 unsigned line = __LINE__ - 2;
444 std::string file = __FILE__;
445 file = file.substr (file.find_last_of("/\\") + 1);
446 msg << MSG::ERROR << "Unknown type requested, please extend " << file << " near line " << line << " for type " << typeName << endmsg;
447 return StatusCode::FAILURE;
448 }
449 }
450 const SG::AuxTypeRegistry& reg = SG::AuxTypeRegistry::instance();
452 {
453 nominalAuxId = reg.findAuxID (nominalAuxName);
455 {
456 decosWithoutType.insert (nominalAuxName);
457 msg << MSG::DEBUG << "No aux ID found for auxiliary variable: " << nominalAuxName << endmsg;
458 // just returning SUCCESS here, our caller will report failure
459 return StatusCode::SUCCESS;
460 }
461 }
462 if (auxType == nullptr)
463 {
464 auxType = reg.getType (nominalAuxId);
465 if (auxType == nullptr)
466 {
467 msg << MSG::ERROR
468 << "No std::type_info available for aux-store variable: "
469 << nominalAuxName << endmsg;
470 return StatusCode::FAILURE;
471 }
472 }
473 if (auxVecType == nullptr)
474 {
475 auxVecType = reg.getVecType (nominalAuxId);
476 if (auxVecType == nullptr)
477 {
478 msg << MSG::ERROR
479 << "No std::type_info available for aux-store variable: "
480 << nominalAuxName << endmsg;
481 return StatusCode::FAILURE;
482 }
483 }
484 if (auxFactory == nullptr)
485 {
486 auxFactory = reg.getFactory (nominalAuxId);
487 if (auxFactory == nullptr)
488 {
489 msg << MSG::ERROR
490 << "No factory found for auxiliary variable: "
491 << nominalAuxName << endmsg;
492 return StatusCode::FAILURE;
493 }
494 }
495 return StatusCode::SUCCESS;
496 }
static AuxTypeRegistry & instance()
Return the singleton registry instance.
SG::ConstAccessor< T, ALLOC > ConstAccessor
Definition AuxElement.h:570
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 327 of file TreeBranchHelpers.cxx.

329 {
330 // The regular expression used to extract the needed info. The logic
331 // is supposed to be:
332 //
333 // (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])]
334 //
335 // Like:
336 // "Electrons.eta -> el_eta"
337 // "Electrons.eta -> el_eta type=float"
338 // "MissingET.px -> met_px metTerm=Final"
339 static const std::regex
340 re( "\\s*([\\w%]+)\\.([\\w%]+)\\s*->\\s*([\\w%]+)(\\s+type=([\\w%]+))?(\\s+metTerm=([\\w%]+))?(\\s+basketSize=([\\w%]+))?" );
341
342 // Interpret this branch declaration.
343 std::smatch match;
344 if( ! std::regex_match( branchDecl, match, re ) ) {
345 msg << MSG::ERROR << "Expression \"" << branchDecl << "\" doesn't match \"<object>.<variable> -> <branch>\"" << endmsg;
346 return StatusCode::FAILURE;
347 }
348 this->branchDecl = branchDecl;
349 sgName = match[ 1 ];
350 auxName = match[ 2 ];
351 branchName = match[ 3 ];
352 typeName = match[ 5 ];
353 metTermName = match[ 7 ];
354 if (match[9].matched) {
355 try {
356 basketSize = std::stoi(match[9]);
357 } catch (const std::exception& ) {
358 msg << MSG::ERROR << "Could not parse basket size value: " << match[9] << endmsg;
359 return StatusCode::FAILURE;
360 }
361 }
362 return StatusCode::SUCCESS;
363 }
const std::regex re(r_e)
bool match(std::string s1, std::string s2)
match the individual directories of two strings
Definition hcg.cxx:359
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 102 of file TreeBranchHelpers.h.

◆ auxName

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

the aux data variable name to read from

Definition at line 74 of file TreeBranchHelpers.h.

◆ auxNameFilterSys

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

the affecting systematics for the auxName

Definition at line 109 of file TreeBranchHelpers.h.

◆ auxType

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

the type of the decoration we read

Definition at line 96 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 99 of file TreeBranchHelpers.h.

◆ basketSize

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

the basket size for this branch

Definition at line 86 of file TreeBranchHelpers.h.

◆ branchDecl

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

the original user configuration string

Definition at line 68 of file TreeBranchHelpers.h.

◆ branchName

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

the name of the output branch

Definition at line 77 of file TreeBranchHelpers.h.

◆ branchNameFilterSys

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

the affecting systematics for the branchName

Definition at line 112 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 89 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 93 of file TreeBranchHelpers.h.

◆ nominalOnly

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

whether we only want to write out the nominal

Definition at line 83 of file TreeBranchHelpers.h.

◆ sgName

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

the SG name of the object to read from

Definition at line 71 of file TreeBranchHelpers.h.

◆ sgNameFilterSys

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

the affecting systematics for the sgName

Definition at line 106 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 80 of file TreeBranchHelpers.h.


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