ATLAS Offline Software
Public Member Functions | Private Types | Private Attributes | List of all members
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. More...
 
xAOD::TruthMetaDataContainerm_tmd = nullptr
 The meta data container to be written out. More...
 
std::unordered_set< uint32_t > m_existingMetaDataChan
 Set for tracking the mc channels for which we already added meta data. More...
 

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

564  {
565  ATH_CHECK( metaStore.retrieve() );
566 
567  auto md = std::make_unique<xAOD::TruthMetaDataContainer>();
568  m_tmd = md.get();
569 
570  auto aux = std::make_unique<xAOD::TruthMetaDataAuxContainer>();
571  md->setStore( aux.get() );
572 
573  // Record the trigger configuration metadata into it:
574  CHECK( metaStore->record( std::move (aux), metaName + "Aux." ) );
575  CHECK( metaStore->record( std::move (md), metaName ) );
576  return StatusCode::SUCCESS;
577  }

◆ maybeWrite()

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

Definition at line 581 of file xAODTruthCnvAlg.cxx.

584  {
585  // This bit needs to be serialized.
586  lock_t lock (m_mutex);
587 
588  //Inserting in a (unordered_)set returns an <iterator, boolean> pair, where the boolean
589  //is used to check if the key already exists (returns false in the case it exists)
590  if( m_existingMetaDataChan.insert(mcChannelNumber).second ) {
591  m_tmd->push_back (std::make_unique <xAOD::TruthMetaData>());
592  xAOD::TruthMetaData* md = m_tmd->back();
593 
594 #ifdef HEPMC3
597  std::vector<std::string> orderedWeightNameVec;
598  if (!genEvt.run_info()) {
599  for (size_t i=0; i<genEvt.weights().size();i++) orderedWeightNameVec.push_back(std::to_string(i));
600  } else {
601  if (!genEvt.run_info()->weight_names().empty()) {
602  orderedWeightNameVec = genEvt.weight_names();
603  } else {
604  //AV This to be decided. It is always a good idea to have a default weight 1.0.
605  //orderedWeightNameVec.push_back("0");
606  }
607  }
608  md->setWeightNames(orderedWeightNameVec);
609 #else
610  // FIXME: class member protection violation here.
611  // This appears to be because WeightContainer has no public methods
612  // to get information about the weight names.
613  const auto& weightNameMap = genEvt.weights().m_names;
614  std::vector<std::string> orderedWeightNameVec;
615  orderedWeightNameVec.reserve( weightNameMap.size() );
616  for (const auto& entry: weightNameMap) {
617  orderedWeightNameVec.push_back(entry.first);
618  }
619 
620  //The map from the HepMC record pairs the weight names with a corresponding index,
621  //it is not guaranteed that the indices are ascending when iterating over the map
622  std::sort(orderedWeightNameVec.begin(), orderedWeightNameVec.end(),
623  [&](const std::string& i, const std::string& j){return weightNameMap.at(i) < weightNameMap.at(j);});
624 
626  md->setWeightNames( orderedWeightNameVec );
627 #endif
628 
629  if(!metaFields.lhefGenerator.empty()) {
630  md->setLhefGenerator(metaFields.lhefGenerator);
631  }
632  if(!metaFields.generators.empty()) {
633  md->setGenerators(metaFields.generators);
634  }
635  if(!metaFields.evgenProcess.empty()) {
636  md->setEvgenProcess(metaFields.evgenProcess);
637  }
638  if(!metaFields.evgenTune.empty()) {
639  md->setEvgenTune(metaFields.evgenTune);
640  }
641  if(!metaFields.hardPDF.empty()) {
642  md->setHardPDF(metaFields.hardPDF);
643  }
644  if(!metaFields.softPDF.empty()) {
645  md->setSoftPDF(metaFields.softPDF);
646  }
647  }
648 
649  return StatusCode::SUCCESS;
650  }

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:
xAOD::TruthMetaData_v1::setSoftPDF
void setSoftPDF(const std::string &value)
DataVector::get
const T * get(size_type n) const
Access an element, as an rvalue.
xAODMaker::xAODTruthCnvAlg::MetaDataWriter::lock_t
std::lock_guard< std::mutex > lock_t
Definition: xAODTruthCnvAlg.h:106
xAOD::mcChannelNumber
mcChannelNumber
Definition: EventInfo_v1.cxx:197
xAOD::TruthMetaData_v1::setWeightNames
void setWeightNames(const std::vector< std::string > &value)
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
xAODMaker::xAODTruthCnvAlg::MetaDataWriter::m_mutex
std::mutex m_mutex
Mutex to control access to meta data writing.
Definition: xAODTruthCnvAlg.h:105
lumiFormat.i
int i
Definition: lumiFormat.py:92
xAOD::TruthMetaData_v1::setMcChannelNumber
void setMcChannelNumber(uint32_t value)
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
DataVector::back
const T * back() const
Access the last element in the collection as an rvalue.
xAOD::TruthMetaData_v1::setGenerators
void setGenerators(const std::string &value)
GetAllXsec.entry
list entry
Definition: GetAllXsec.py:132
xAOD::TruthMetaData_v1
Class describing meta data for truth records.
Definition: TruthMetaData_v1.h:28
ActsTrk::to_string
std::string to_string(const DetectorType &type)
Definition: GeometryDefs.h:34
DataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
xAOD::TruthMetaData_v1::setHardPDF
void setHardPDF(const std::string &value)
std::sort
void sort(typename std::reverse_iterator< DataModel_detail::iterator< DVL > > beg, typename std::reverse_iterator< DataModel_detail::iterator< DVL > > end, const Compare &comp)
Specialization of sort for DataVector/List.
Definition: DVL_algorithms.h:623
xAOD::TruthMetaData_v1::setLhefGenerator
void setLhefGenerator(const std::string &value)
xAOD::TruthMetaData_v1::setEvgenTune
void setEvgenTune(const std::string &value)
xAODMaker::xAODTruthCnvAlg::MetaDataWriter::m_tmd
xAOD::TruthMetaDataContainer * m_tmd
The meta data container to be written out.
Definition: xAODTruthCnvAlg.h:109
xAODMaker::xAODTruthCnvAlg::MetaDataWriter::m_existingMetaDataChan
std::unordered_set< uint32_t > m_existingMetaDataChan
Set for tracking the mc channels for which we already added meta data.
Definition: xAODTruthCnvAlg.h:112
xAOD::TruthMetaData_v1::setEvgenProcess
void setEvgenProcess(const std::string &value)