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 498 of file TreeBranchHelpers.cxx.

500 {
501 if (sgName.find ("%SYS%") == std::string::npos &&
502 auxName.find ("%SYS%") == std::string::npos &&
503 branchName.find ("%SYS%") == std::string::npos)
504 {
505 nominalOnly = true;
506 }
507 if (!nominalOnly)
508 {
509 if (branchName.find ("%SYS%") == std::string::npos)
510 {
511 msg << MSG::ERROR << "Branch with systematics without %SYS% in branch name: "
512 << branchName << endmsg;
513 return StatusCode::FAILURE;
514 }
515 if (sgName.find ("%SYS%") == std::string::npos &&
516 auxName.find ("%SYS%") == std::string::npos)
517 {
518 msg << MSG::ERROR << "Branch with systematics without %SYS% in SG or aux name: "
519 << sgName << "." << auxName << endmsg;
520 return StatusCode::FAILURE;
521 }
522 if (auxName.find ("NOSYS") != std::string::npos)
523 {
524 msg << MSG::ERROR << "Branch with systematics with NOSYS in aux name: "
525 << sgName << "." << auxName << endmsg;
526 return StatusCode::FAILURE;
527 }
528 if (sgName.find ("NOSYS") != std::string::npos && auxName.find ("%SYS%") == std::string::npos)
529 {
530 msg << MSG::ERROR << "Branch with NOSYS in SG name but without %SYS% in aux name: "
531 << sgName << "." << auxName << endmsg;
532 return StatusCode::FAILURE;
533 }
534
535 if (sgName.find ("%SYS%") != std::string::npos)
536 sgNameFilterSys = sysSvc.getObjectSystematics( sgName );
537
538 if (auxName.find ("%SYS%") != std::string::npos)
539 {
540 if (auto pos = sgName.find ("NOSYS"); pos == std::string::npos)
541 auxNameFilterSys = sysSvc.getDecorSystematics (sgName, auxName);
542 else
543 {
544 // Sometimes while object systematics were applied we are not interested in them,
545 // NOSYS will then be used on the container name.
546 // Decoration systematics however will only be aware of containers with %SYS% included.
547 // Some special handling is needed to translate from NOSYS back to %SYS%.
548 std::string sgNameSys = sgName;
549 sgNameSys.replace (pos, 5, "%SYS%");
550
551 // these will be the object systematics
552 auto objectSys = sysSvc.getObjectSystematics (sgNameSys);
553
554 // these will be all systematics (object+decor)
555 auto allSys = sysSvc.getDecorSystematics (sgNameSys, auxName);
556
557 // we now need to filter-out object systematics
558 for (auto& variation : allSys)
559 {
560 if (objectSys.find (variation) == objectSys.end())
561 auxNameFilterSys.insert (variation);
562 }
563 }
564 }
565
568 if (branchNameFilterSys.empty())
569 nominalOnly = true;
570 }
571
572 return StatusCode::SUCCESS;
573 }
#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")
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_vector_float")
413 else if (typeName == "vector_vector_int")
415 else if (typeName == "PtEtaPhiEVector")
416 SG::ConstAccessor<PtEtaPhiEVector> {nominalAuxName};
417 else if (typeName == "PtEtaPhiMVector")
418 SG::ConstAccessor<PtEtaPhiMVector> {nominalAuxName};
419 else if (typeName == "PxPyPzEVector")
420 SG::ConstAccessor<PxPyPzEVector> {nominalAuxName};
421 else if (typeName == "PxPyPzMVector")
422 SG::ConstAccessor<PxPyPzMVector> {nominalAuxName};
423 else if (typeName == "vector_PtEtaPhiEVector")
425 else if (typeName == "vector_PtEtaPhiMVector")
427 else if (typeName == "vector_PxPyPzEVector")
429 else if (typeName == "vector_PxPyPzMVector")
431 else if (typeName == "vector_vector_PtEtaPhiEVector")
433 else if (typeName == "vector_vector_PtEtaPhiMVector")
435 else if (typeName == "vector_vector_PxPyPzEVector")
437 else if (typeName == "vector_vector_PxPyPzMVector")
439 else
440 {
441 unsigned line = __LINE__ - 2;
442 std::string file = __FILE__;
443 file = file.substr (file.find_last_of("/\\") + 1);
444 msg << MSG::ERROR << "Unknown type requested, please extend " << file << " near line " << line << " for type " << typeName << endmsg;
445 return StatusCode::FAILURE;
446 }
447 }
448 const SG::AuxTypeRegistry& reg = SG::AuxTypeRegistry::instance();
450 {
451 nominalAuxId = reg.findAuxID (nominalAuxName);
453 {
454 decosWithoutType.insert (nominalAuxName);
455 msg << MSG::DEBUG << "No aux ID found for auxiliary variable: " << nominalAuxName << endmsg;
456 // just returning SUCCESS here, our caller will report failure
457 return StatusCode::SUCCESS;
458 }
459 }
460 if (auxType == nullptr)
461 {
462 auxType = reg.getType (nominalAuxId);
463 if (auxType == nullptr)
464 {
465 msg << MSG::ERROR
466 << "No std::type_info available for aux-store variable: "
467 << nominalAuxName << endmsg;
468 return StatusCode::FAILURE;
469 }
470 }
471 if (auxVecType == nullptr)
472 {
473 auxVecType = reg.getVecType (nominalAuxId);
474 if (auxVecType == nullptr)
475 {
476 msg << MSG::ERROR
477 << "No std::type_info available for aux-store variable: "
478 << nominalAuxName << endmsg;
479 return StatusCode::FAILURE;
480 }
481 }
482 if (auxFactory == nullptr)
483 {
484 auxFactory = reg.getFactory (nominalAuxId);
485 if (auxFactory == nullptr)
486 {
487 msg << MSG::ERROR
488 << "No factory found for auxiliary variable: "
489 << nominalAuxName << endmsg;
490 return StatusCode::FAILURE;
491 }
492 }
493 return StatusCode::SUCCESS;
494 }
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: