8#include "CoralBase/AttributeListException.h"
21 return StatusCode::SUCCESS;
34 const EventContext& ctx )
36 std::scoped_lock lock (
m_mutex);
42 return StatusCode::SUCCESS;
50 return StatusCode::SUCCESS;
53 unsigned int chanNum = ctx.eventID().run_number();
56 w.m_chanNum = chanNum;
62 ATH_CHECK(
m_metaDataTool->registerFolder(
"/Generation/Parameters",
"Metadata created during Event Generation") );
65 auto cont = std::make_unique<CondAttrListCollection> (
true ) ;
71 myAttributes.extend(
"HepMCWeightNames",
"string");
72 myAttributes.extend(
"HepMCWeightSvcVersion",
"int");
73 myAttributes[
"HepMCWeightSvcVersion"].data<
int>() = 2;
75 std::string stringToStore = Gaudi::Utils::toString(
weightNames );
77 myAttributes[
"HepMCWeightNames"].data<std::string>() = stringToStore;
80 bool add_status = cont->add(chanNum, myAttributes);
82 ATH_MSG_INFO(
"Failed to add AttributeList for weight " << stringToStore);
85 ATH_MSG_INFO(
"Storing /Generation/Parameters :: WeightNames = " << stringToStore);
90 return StatusCode::SUCCESS;
97HepMCWeightSvc::WeightMap
100 std::scoped_lock lock (
m_mutex);
106 ATH_MSG_WARNING(
"Unable to load weightnames from metadata ... do not trust the weightnames!");
114std::vector<std::string>
117 std::scoped_lock lock (
m_mutex);
123 ATH_MSG_WARNING(
"Unable to load weightnames from metadata ... do not trust the weightnames!");
124 return std::vector<std::string>();
139 unsigned long chanNum = ei->mcChannelNumber();
140 if (chanNum > 0)
return chanNum;
143 return ctx.eventID().run_number();
159 std::map<std::string, int> in;
168 unsigned long chanNumRead = chanNum;
179 }
catch(
const coral::AttributeListException&) {
183 std::string
weightNames = attr.data<std::string>();
207 w.m_chanNum = chanNum;
208 w.m_weightNames.clear();
210 for(
const auto& i : in) {
211 w.m_weightNames[i.first] = i.second;
229 for (
size_t i = 0; i <
NWEIGHTS; i++) {
246 using WPair = std::pair<std::string, unsigned long int>;
247 std::vector<WPair> sorted;
249 sorted.emplace_back (i);
252 [](
const WPair&
a,
const WPair& b) {return a.second < b.second; });
253 for (
auto&
a: sorted) {
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_WARNING(x)
This file defines the class for a collection of AttributeLists where each one is associated with a ch...
Handle class for reading from StoreGate.
const AttributeList & attributeList(ChanNum chanNum) const
attribute list for a given channel number
ChanNum chanNum(unsigned int index) const
channel number for index: (index = 0 to size-1)
size_type size() const
number of Chan/AttributeList pairs
coral::AttributeList AttributeList
virtual StatusCode initialize() override
Standard Gaudi initialize.
static const unsigned int NWEIGHTS
Array of weights.
WeightInfo m_weights[NWEIGHTS]
unsigned long getChanNum(const EventContext &ctx) const
Return the ‘channel number’ for the current event.
virtual StatusCode setWeightNames(const WeightMap &weightNames, const EventContext &ctx=Gaudi::Hive::currentContext()) override
Record weight names to metadata if none have yet been set.
Gaudi::Property< bool > m_enabled
unsigned int loadWeights(unsigned long chanNum)
Try to load weight names from metadata.
size_t m_nextWeight
Index of next set of weights to overwrite.
virtual std::vector< std::string > weightNameVec(const EventContext &ctx=Gaudi::Hive::currentContext()) override
Return the current weight names.
unsigned int getWeightIndex(const EventContext &ctx)
Return the index in m_weights for the current event.
SG::ReadHandleKey< xAOD::EventInfo > m_eventInfoKey
Used to get MC channel for the current event.
virtual WeightMap weightNames(const EventContext &ctx=Gaudi::Hive::currentContext()) override
Return the current weight names.
std::mutex m_mutex
Serialize access to this service.
PublicToolHandle< IIOVDbMetaDataTool > m_metaDataTool
Handle to metadata tool.
size_type size() const
size of payload vector
CondAttrListCollection * at(unsigned int i) const
Element access.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
StatusCode parse(std::tuple< Tup... > &tup, const Gaudi::Parsers::InputData &input)
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.
WeightMap m_weightNames
Map of weight names.
void fillVec()
Initialize sorted vector from map.
std::vector< std::string > m_weightNameVec
Sorted vector of weight names.