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

465 {
466 if (sgName.find ("%SYS%") == std::string::npos &&
467 auxName.find ("%SYS%") == std::string::npos &&
468 branchName.find ("%SYS%") == std::string::npos)
469 {
470 nominalOnly = true;
471 }
472 if (!nominalOnly)
473 {
474 if (branchName.find ("%SYS%") == std::string::npos)
475 {
476 msg << MSG::ERROR << "Branch with systematics without %SYS% in branch name: "
477 << branchName << endmsg;
478 return StatusCode::FAILURE;
479 }
480 if (sgName.find ("%SYS%") == std::string::npos &&
481 auxName.find ("%SYS%") == std::string::npos)
482 {
483 msg << MSG::ERROR << "Branch with systematics without %SYS% in SG or aux name: "
484 << sgName << "." << auxName << endmsg;
485 return StatusCode::FAILURE;
486 }
487 if (auxName.find ("NOSYS") != std::string::npos)
488 {
489 msg << MSG::ERROR << "Branch with systematics with NOSYS in aux name: "
490 << sgName << "." << auxName << endmsg;
491 return StatusCode::FAILURE;
492 }
493 if (sgName.find ("NOSYS") != std::string::npos && auxName.find ("%SYS%") == std::string::npos)
494 {
495 msg << MSG::ERROR << "Branch with NOSYS in SG name but without %SYS% in aux name: "
496 << sgName << "." << auxName << endmsg;
497 return StatusCode::FAILURE;
498 }
499
500 if (sgName.find ("%SYS%") != std::string::npos)
501 sgNameFilterSys = sysSvc.getObjectSystematics( sgName );
502
503 if (auxName.find ("%SYS%") != std::string::npos)
504 {
505 if (auto pos = sgName.find ("NOSYS"); pos == std::string::npos)
506 auxNameFilterSys = sysSvc.getDecorSystematics (sgName, auxName);
507 else
508 {
509 // Sometimes while object systematics were applied we are not interested in them,
510 // NOSYS will then be used on the container name.
511 // Decoration systematics however will only be aware of containers with %SYS% included.
512 // Some special handling is needed to translate from NOSYS back to %SYS%.
513 std::string sgNameSys = sgName;
514 sgNameSys.replace (pos, 5, "%SYS%");
515
516 // these will be the object systematics
517 auto objectSys = sysSvc.getObjectSystematics (sgNameSys);
518
519 // these will be all systematics (object+decor)
520 auto allSys = sysSvc.getDecorSystematics (sgNameSys, auxName);
521
522 // we now need to filter-out object systematics
523 for (auto& variation : allSys)
524 {
525 if (objectSys.find (variation) == objectSys.end())
526 auxNameFilterSys.insert (variation);
527 }
528 }
529 }
530
533 if (branchNameFilterSys.empty())
534 nominalOnly = true;
535 }
536
537 return StatusCode::SUCCESS;
538 }
#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 == "unsigned_char")
377 SG::ConstAccessor<unsigned char> {nominalAuxName};
378 else if (typeName == "unsigned_long_long")
379 SG::ConstAccessor<unsigned long long> {nominalAuxName};
380 else if (typeName == "int8")
381 SG::ConstAccessor<std::int8_t> {nominalAuxName};
382 else if (typeName == "int16")
383 SG::ConstAccessor<std::int16_t> {nominalAuxName};
384 else if (typeName == "int32")
385 SG::ConstAccessor<std::int32_t> {nominalAuxName};
386 else if (typeName == "int64")
387 SG::ConstAccessor<std::int64_t> {nominalAuxName};
388 else if (typeName == "uint8")
389 SG::ConstAccessor<std::uint8_t> {nominalAuxName};
390 else if (typeName == "uint16")
391 SG::ConstAccessor<std::uint16_t> {nominalAuxName};
392 else if (typeName == "uint32")
393 SG::ConstAccessor<std::uint32_t> {nominalAuxName};
394 else if (typeName == "uint64")
395 SG::ConstAccessor<std::uint64_t> {nominalAuxName};
396 else if (typeName == "vector_float")
397 SG::ConstAccessor<std::vector<float>> {nominalAuxName};
398 else if (typeName == "vector_int")
399 SG::ConstAccessor<std::vector<int>> {nominalAuxName};
400 else if (typeName == "vector_vector_float")
401 SG::ConstAccessor<std::vector<std::vector<float>>> {nominalAuxName};
402 else if (typeName == "vector_vector_int")
403 SG::ConstAccessor<std::vector<std::vector<int>>> {nominalAuxName};
404 else
405 {
406 unsigned line = __LINE__ - 2;
407 std::string file = __FILE__;
408 file = file.substr (file.find_last_of("/\\") + 1);
409 msg << MSG::ERROR << "Unknown type requested, please extend " << file << " near line " << line << " for type " << typeName << endmsg;
410 return StatusCode::FAILURE;
411 }
412 }
413 const SG::AuxTypeRegistry& reg = SG::AuxTypeRegistry::instance();
415 {
416 nominalAuxId = reg.findAuxID (nominalAuxName);
418 {
419 decosWithoutType.insert (nominalAuxName);
420 msg << MSG::DEBUG << "No aux ID found for auxiliary variable: " << nominalAuxName << endmsg;
421 // just returning SUCCESS here, our caller will report failure
422 return StatusCode::SUCCESS;
423 }
424 }
425 if (auxType == nullptr)
426 {
427 auxType = reg.getType (nominalAuxId);
428 if (auxType == nullptr)
429 {
430 msg << MSG::ERROR
431 << "No std::type_info available for aux-store variable: "
432 << nominalAuxName << endmsg;
433 return StatusCode::FAILURE;
434 }
435 }
436 if (auxVecType == nullptr)
437 {
438 auxVecType = reg.getVecType (nominalAuxId);
439 if (auxVecType == nullptr)
440 {
441 msg << MSG::ERROR
442 << "No std::type_info available for aux-store variable: "
443 << nominalAuxName << endmsg;
444 return StatusCode::FAILURE;
445 }
446 }
447 if (auxFactory == nullptr)
448 {
449 auxFactory = reg.getFactory (nominalAuxId);
450 if (auxFactory == nullptr)
451 {
452 msg << MSG::ERROR
453 << "No factory found for auxiliary variable: "
454 << nominalAuxName << endmsg;
455 return StatusCode::FAILURE;
456 }
457 }
458 return StatusCode::SUCCESS;
459 }
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: