ATLAS Offline Software
Loading...
Searching...
No Matches
xAODMaker::xAODTruthCnvAlg::MetaDataWriter Class Reference

Factor out the pieces dealing with writing to meta data. More...

Collaboration diagram for xAODMaker::xAODTruthCnvAlg::MetaDataWriter:

Public Member Functions

StatusCode initialize (ServiceHandle< StoreGateSvc > &metaStore, const std::string &metaName)
StatusCode maybeWrite (uint32_t mcChannelNumber, const HepMC::GenEvent &genEvt, const MetadataFields &metaFields)

Private Types

typedef std::lock_guard< std::mutex > lock_t

Private Attributes

std::mutex m_mutex
 Mutex to control access to meta data writing.
xAOD::TruthMetaDataContainerm_tmd = nullptr
 The meta data container to be written out.
std::unordered_set< uint32_t > m_existingMetaDataChan
 Set for tracking the mc channels for which we already added meta data.

Detailed Description

Factor out the pieces dealing with writing to meta data.

This will be non-const, so need to protect with a mutex.

Definition at line 94 of file xAODTruthCnvAlg.h.

Member Typedef Documentation

◆ lock_t

typedef std::lock_guard<std::mutex> xAODMaker::xAODTruthCnvAlg::MetaDataWriter::lock_t
private

Definition at line 106 of file xAODTruthCnvAlg.h.

Member Function Documentation

◆ initialize()

StatusCode xAODMaker::xAODTruthCnvAlg::MetaDataWriter::initialize ( ServiceHandle< StoreGateSvc > & metaStore,
const std::string & metaName )

Definition at line 610 of file xAODTruthCnvAlg.cxx.

612 {
613 ATH_CHECK( metaStore.retrieve() );
614
615 auto md = std::make_unique<xAOD::TruthMetaDataContainer>();
616 m_tmd = md.get();
617
618 auto aux = std::make_unique<xAOD::TruthMetaDataAuxContainer>();
619 md->setStore( aux.get() );
620
621 // Record the trigger configuration metadata into it:
622 CHECK( metaStore->record( std::move (aux), metaName + "Aux." ) );
623 CHECK( metaStore->record( std::move (md), metaName ) );
624 return StatusCode::SUCCESS;
625 }
#define ATH_CHECK
Evaluate an expression and check for errors.
#define CHECK(...)
Evaluate an expression and check for errors.
xAOD::TruthMetaDataContainer * m_tmd
The meta data container to be written out.

◆ maybeWrite()

StatusCode xAODMaker::xAODTruthCnvAlg::MetaDataWriter::maybeWrite ( uint32_t mcChannelNumber,
const HepMC::GenEvent & genEvt,
const MetadataFields & metaFields )

Definition at line 629 of file xAODTruthCnvAlg.cxx.

632 {
633 // This bit needs to be serialized.
635
636 //Inserting in a (unordered_)set returns an <iterator, boolean> pair, where the boolean
637 //is used to check if the key already exists (returns false in the case it exists)
638 if( m_existingMetaDataChan.insert(mcChannelNumber).second ) {
639 m_tmd->push_back (std::make_unique <xAOD::TruthMetaData>());
640 xAOD::TruthMetaData* md = m_tmd->back();
641
642#ifdef HEPMC3
644 md->setMcChannelNumber(mcChannelNumber);
645 std::vector<std::string> orderedWeightNameVec;
646 if (!genEvt.run_info()) {
647 for (size_t i=0; i<genEvt.weights().size();i++) orderedWeightNameVec.push_back(std::to_string(i));
648 } else {
649 if (!genEvt.run_info()->weight_names().empty()) {
650 orderedWeightNameVec = genEvt.weight_names();
651 } else {
652 //AV This to be decided. It is always a good idea to have a default weight 1.0.
653 //orderedWeightNameVec.push_back("0");
654 }
655 }
656 md->setWeightNames(orderedWeightNameVec);
657#else
658 // FIXME: class member protection violation here.
659 // This appears to be because WeightContainer has no public methods
660 // to get information about the weight names.
661 const auto& weightNameMap = genEvt.weights().m_names;
662 std::vector<std::string> orderedWeightNameVec;
663 orderedWeightNameVec.reserve( weightNameMap.size() );
664 for (const auto& entry: weightNameMap) {
665 orderedWeightNameVec.push_back(entry.first);
666 }
667
668 //The map from the HepMC record pairs the weight names with a corresponding index,
669 //it is not guaranteed that the indices are ascending when iterating over the map
670 std::sort(orderedWeightNameVec.begin(), orderedWeightNameVec.end(),
671 [&](const std::string& i, const std::string& j){return weightNameMap.at(i) < weightNameMap.at(j);});
672
673 md->setMcChannelNumber(mcChannelNumber);
674 md->setWeightNames( orderedWeightNameVec );
675#endif
676
677 if(!metaFields.lhefGenerator.empty()) {
678 md->setLhefGenerator(metaFields.lhefGenerator);
679 }
680 if(!metaFields.generators.empty()) {
681 md->setGenerators(metaFields.generators);
682 }
683 if(!metaFields.evgenProcess.empty()) {
684 md->setEvgenProcess(metaFields.evgenProcess);
685 }
686 if(!metaFields.evgenTune.empty()) {
687 md->setEvgenTune(metaFields.evgenTune);
688 }
689 if(!metaFields.hardPDF.empty()) {
690 md->setHardPDF(metaFields.hardPDF);
691 }
692 if(!metaFields.softPDF.empty()) {
693 md->setSoftPDF(metaFields.softPDF);
694 }
695 }
696
697 return StatusCode::SUCCESS;
698 }
virtual void lock()=0
Interface to allow an object to lock itself when made const in SG.
size_t size() const
Number of registered mappings.
std::mutex m_mutex
Mutex to control access to meta data writing.
std::unordered_set< uint32_t > m_existingMetaDataChan
Set for tracking the mc channels for which we already added meta data.
void setGenerators(const std::string &value)
void setLhefGenerator(const std::string &value)
void setEvgenTune(const std::string &value)
void setHardPDF(const std::string &value)
void setMcChannelNumber(uint32_t value)
void setSoftPDF(const std::string &value)
void setWeightNames(const std::vector< std::string > &value)
void setEvgenProcess(const std::string &value)
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.
TruthMetaData_v1 TruthMetaData
Typedef to implementation.

Member Data Documentation

◆ m_existingMetaDataChan

std::unordered_set<uint32_t> xAODMaker::xAODTruthCnvAlg::MetaDataWriter::m_existingMetaDataChan
private

Set for tracking the mc channels for which we already added meta data.

Definition at line 112 of file xAODTruthCnvAlg.h.

◆ m_mutex

std::mutex xAODMaker::xAODTruthCnvAlg::MetaDataWriter::m_mutex
private

Mutex to control access to meta data writing.

Definition at line 105 of file xAODTruthCnvAlg.h.

◆ m_tmd

xAOD::TruthMetaDataContainer* xAODMaker::xAODTruthCnvAlg::MetaDataWriter::m_tmd = nullptr
private

The meta data container to be written out.

Definition at line 109 of file xAODTruthCnvAlg.h.


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