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 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  }

◆ 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.
634  lock_t lock (m_mutex);
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
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 
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  }

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:85
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)