Service to read/write HepMC's WeightContainer key names from/to IOVMetaDataContainers author: will buttinger , NLAA.
More...
#include <HepMCWeightSvc.h>
|
| virtual StatusCode | initialize () override |
| | Standard Gaudi initialize.
|
| virtual StatusCode | setWeightNames (const WeightMap &weightNames, const EventContext &ctx=Gaudi::Hive::currentContext()) override |
| | Record weight names to metadata if none have yet been set.
|
| virtual WeightMap | weightNames (const EventContext &ctx=Gaudi::Hive::currentContext()) override |
| | Return the current weight names.
|
| virtual std::vector< std::string > | weightNameVec (const EventContext &ctx=Gaudi::Hive::currentContext()) override |
| | Return the current weight names.
|
|
| unsigned long | getChanNum (const EventContext &ctx) const |
| | Return the ‘channel number’ for the current event.
|
| unsigned int | loadWeights (unsigned long chanNum) |
| | Try to load weight names from metadata.
|
| unsigned int | getWeightIndex (const EventContext &ctx) |
| | Return the index in m_weights for the current event.
|
|
| static const unsigned int | NWEIGHTS = 8 |
| | Array of weights.
|
Service to read/write HepMC's WeightContainer key names from/to IOVMetaDataContainers author: will buttinger , NLAA.
Definition at line 24 of file HepMCWeightSvc.h.
◆ getChanNum()
| unsigned long HepMCWeightSvc::getChanNum |
( |
const EventContext & | ctx | ) |
const |
|
private |
Return the ‘channel number’ for the current event.
- Parameters
-
| ctx | Current event context. |
Either the MC channel number or the run number if that hasn't been set.
Definition at line 134 of file HepMCWeightSvc.cxx.
135{
136
138 if (ei.isValid()) {
139 unsigned long chanNum = ei->mcChannelNumber();
140 if (chanNum > 0)
return chanNum;
141 }
142
143 return ctx.eventID().run_number();
144}
SG::ReadHandleKey< xAOD::EventInfo > m_eventInfoKey
Used to get MC channel for the current event.
◆ getWeightIndex()
| unsigned int HepMCWeightSvc::getWeightIndex |
( |
const EventContext & | ctx | ) |
|
|
private |
Return the index in m_weights for the current event.
- Parameters
-
| ctx | The current event context. |
Returns NWEIGHTS on failure.
Definition at line 225 of file HepMCWeightSvc.cxx.
226{
228 if (chanNum != 0) {
232 }
233 }
235 }
237}
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.
unsigned int loadWeights(unsigned long chanNum)
Try to load weight names from metadata.
◆ initialize()
| StatusCode HepMCWeightSvc::initialize |
( |
| ) |
|
|
overridevirtual |
Standard Gaudi initialize.
Definition at line 18 of file HepMCWeightSvc.cxx.
19{
21 return StatusCode::SUCCESS;
22}
#define ATH_CHECK
Evaluate an expression and check for errors.
◆ loadWeights()
| unsigned int HepMCWeightSvc::loadWeights |
( |
unsigned long | chanNum | ) |
|
|
private |
Try to load weight names from metadata.
- Parameters
-
| chanNum | Channel number for which to load weights. |
Returns the index in m_weights of the loaded weights.
Definition at line 153 of file HepMCWeightSvc.cxx.
154{
155
156
158
159 std::map<std::string, int> in;
160
162 const IOVMetaDataContainer* cont =
m_metaDataTool->findMetaDataContainer (
"/Generation/Parameters");
163
164
165 if (cont) {
167
168 unsigned long chanNumRead =
chanNum;
169
172 }
173
175
177 try {
179 } catch(const coral::AttributeListException&) {
181 }
182
183 std::string
weightNames = attr.data<std::string>();
184
185
186
187
188
189
190 if(version==1) {
194 }
195
197
199 }
200
204 }
205
208 w.m_weightNames.clear();
209
210 for(const auto& i : in) {
211 w.m_weightNames[
i.first] =
i.second;
212 }
214
215 return iweight;
216}
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
Gaudi::Property< bool > m_enabled
size_t m_nextWeight
Index of next set of weights to overwrite.
virtual WeightMap weightNames(const EventContext &ctx=Gaudi::Hive::currentContext()) override
Return the current weight names.
PublicToolHandle< IIOVDbMetaDataTool > m_metaDataTool
Handle to metadata tool.
size_type size() const
size of payload vector
CondAttrListCollection * at(unsigned int i) const
Element access.
StatusCode parse(std::tuple< Tup... > &tup, const Gaudi::Parsers::InputData &input)
◆ setWeightNames()
| StatusCode HepMCWeightSvc::setWeightNames |
( |
const WeightMap & | weightNames, |
|
|
const EventContext & | ctx = Gaudi::Hive::currentContext() ) |
|
overridevirtual |
Record weight names to metadata if none have yet been set.
- Parameters
-
| weightNames | Map of names to record. |
| ctx | Current event context. |
Does nothing if weight names have already been set or read.
Definition at line 33 of file HepMCWeightSvc.cxx.
35{
36 std::scoped_lock lock (
m_mutex);
37
38
41 {
42 return StatusCode::SUCCESS;
43 }
44
46
47
48
49
50 return StatusCode::SUCCESS;
51 }
52
53 unsigned int chanNum = ctx.eventID().run_number();
54
59
60
61
62 ATH_CHECK(
m_metaDataTool->registerFolder(
"/Generation/Parameters",
"Metadata created during Event Generation") );
63
64
65 auto cont = std::make_unique<CondAttrListCollection> (true ) ;
66
67
69
70
71 myAttributes.extend("HepMCWeightNames","string");
72 myAttributes.extend("HepMCWeightSvcVersion","int");
73 myAttributes["HepMCWeightSvcVersion"].data<int>() = 2;
74
75 std::string stringToStore = Gaudi::Utils::toString(
weightNames );
76
77 myAttributes["HepMCWeightNames"].data<std::string>() = stringToStore;
78
79
80 bool add_status = cont->add(chanNum, myAttributes);
81 if (!add_status) {
82 ATH_MSG_INFO(
"Failed to add AttributeList for weight " << stringToStore);
83 }
84
85 ATH_MSG_INFO(
"Storing /Generation/Parameters :: WeightNames = " << stringToStore);
86
87
89
90 return StatusCode::SUCCESS;
91}
coral::AttributeList AttributeList
std::mutex m_mutex
Serialize access to this service.
◆ weightNames()
| HepMCWeightSvc::WeightMap HepMCWeightSvc::weightNames |
( |
const EventContext & | ctx = Gaudi::Hive::currentContext() | ) |
|
|
overridevirtual |
Return the current weight names.
Definition at line 98 of file HepMCWeightSvc.cxx.
99{
100 std::scoped_lock lock (
m_mutex);
104 }
105
106 ATH_MSG_WARNING(
"Unable to load weightnames from metadata ... do not trust the weightnames!");
107 return WeightMap();
108}
#define ATH_MSG_WARNING(x)
unsigned int getWeightIndex(const EventContext &ctx)
Return the index in m_weights for the current event.
◆ weightNameVec()
| std::vector< std::string > HepMCWeightSvc::weightNameVec |
( |
const EventContext & | ctx = Gaudi::Hive::currentContext() | ) |
|
|
overridevirtual |
Return the current weight names.
Definition at line 115 of file HepMCWeightSvc.cxx.
116{
117 std::scoped_lock lock (
m_mutex);
121 }
122
123 ATH_MSG_WARNING(
"Unable to load weightnames from metadata ... do not trust the weightnames!");
124 return std::vector<std::string>();
125}
◆ m_enabled
| Gaudi::Property<bool> HepMCWeightSvc::m_enabled { this, "Enable", true, "If false, will return failure on loadWeights" } |
|
private |
Definition at line 96 of file HepMCWeightSvc.h.
97{ this, "Enable", true, "If false, will return failure on loadWeights" };
◆ m_eventInfoKey
Used to get MC channel for the current event.
Definition at line 126 of file HepMCWeightSvc.h.
127{ this, "EventInfoKey", "EventInfo", "SG key for EventInfo object." };
◆ m_metaDataTool
| PublicToolHandle<IIOVDbMetaDataTool> HepMCWeightSvc::m_metaDataTool { this, "IOVDbMetaDataTool", "IOVDbMetaDataTool" } |
|
private |
Handle to metadata tool.
Definition at line 91 of file HepMCWeightSvc.h.
92{ this, "IOVDbMetaDataTool", "IOVDbMetaDataTool" };
◆ m_mutex
| std::mutex HepMCWeightSvc::m_mutex |
|
private |
◆ m_nextWeight
| size_t HepMCWeightSvc::m_nextWeight = 0 |
|
private |
◆ m_weights
◆ NWEIGHTS
| const unsigned int HepMCWeightSvc::NWEIGHTS = 8 |
|
staticprivate |
The documentation for this class was generated from the following files: