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 609 of file xAODTruthCnvAlg.cxx.

611 {
612 ATH_CHECK( metaStore.retrieve() );
613
614 auto md = std::make_unique<xAOD::TruthMetaDataContainer>();
615 m_tmd = md.get();
616
617 auto aux = std::make_unique<xAOD::TruthMetaDataAuxContainer>();
618 md->setStore( aux.get() );
619
620 // Record the trigger configuration metadata into it:
621 CHECK( metaStore->record( std::move (aux), metaName + "Aux." ) );
622 CHECK( metaStore->record( std::move (md), metaName ) );
623 return StatusCode::SUCCESS;
624 }
#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 628 of file xAODTruthCnvAlg.cxx.

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