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

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