ATLAS Offline Software
HepMCWeightSvc.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #ifndef EVGENPRODTOOLS_HEPMCWEIGHTSVC_H
6 #define EVGENPRODTOOLS_HEPMCWEIGHTSVC_H
7 
12 #include <string>
13 
15 
16 #include "GaudiKernel/ToolHandle.h"
17 #include <vector>
18 #include <mutex>
19 
24 class HepMCWeightSvc : public extends<AthService, IHepMCWeightSvc>
25 {
26 public:
27  using base_class::base_class;
28 
29 
33  virtual StatusCode initialize() override;
34 
35 
43  virtual StatusCode
44  setWeightNames (const WeightMap& weightNames,
45  const EventContext& ctx = Gaudi::Hive::currentContext()) override;
46 
47 
51  virtual WeightMap
52  weightNames (const EventContext& ctx = Gaudi::Hive::currentContext()) override;
53 
54 
58  virtual std::vector<std::string>
59  weightNameVec (const EventContext& ctx = Gaudi::Hive::currentContext()) override;
60 
61 
62 private:
69  unsigned long getChanNum (const EventContext& ctx) const;
70 
71 
78  unsigned int loadWeights (unsigned long chanNum);
79 
80 
87  unsigned int getWeightIndex (const EventContext& ctx);
88 
89 
91  PublicToolHandle<IIOVDbMetaDataTool> m_metaDataTool
92  { this, "IOVDbMetaDataTool", "IOVDbMetaDataTool" };
93 
94 
95  // Property: Allow disabling reading from metadata.
96  Gaudi::Property<bool> m_enabled
97  { this, "Enable", true, "If false, will return failure on loadWeights" };
98 
99 
103  struct WeightInfo
104  {
106  unsigned long m_chanNum = 0;
107 
109  WeightMap m_weightNames;
110 
112  std::vector<std::string> m_weightNameVec;
113 
115  void fillVec();
116  };
117 
119  static const unsigned int NWEIGHTS = 8;
121 
123  size_t m_nextWeight = 0;
124 
127  { this, "EventInfoKey", "EventInfo", "SG key for EventInfo object." };
128 
131 };
132 
133 #endif
ReadHandleKey.h
Property holding a SG store/key/clid from which a ReadHandle is made.
IHepMCWeightSvc.h
HepMCWeightSvc::m_nextWeight
size_t m_nextWeight
Index of next set of weights to overwrite.
Definition: HepMCWeightSvc.h:123
HepMCWeightSvc::WeightInfo
Cached sets of weights.
Definition: HepMCWeightSvc.h:104
HepMCWeightSvc::NWEIGHTS
static const unsigned int NWEIGHTS
Array of weights.
Definition: HepMCWeightSvc.h:119
BeamSpot::mutex
std::mutex mutex
Definition: InDetBeamSpotVertex.cxx:18
HepMCWeightSvc::m_enabled
Gaudi::Property< bool > m_enabled
Definition: HepMCWeightSvc.h:97
HepMCWeightSvc::m_metaDataTool
PublicToolHandle< IIOVDbMetaDataTool > m_metaDataTool
Handle to metadata tool.
Definition: HepMCWeightSvc.h:92
HepMCWeightSvc::m_eventInfoKey
SG::ReadHandleKey< xAOD::EventInfo > m_eventInfoKey
Used to get MC channel for the current event.
Definition: HepMCWeightSvc.h:127
HepMCWeightSvc
Service to read/write HepMC's WeightContainer key names from/to IOVMetaDataContainers author: will bu...
Definition: HepMCWeightSvc.h:25
SG::ReadHandleKey< xAOD::EventInfo >
HepMCWeightSvc::initialize
virtual StatusCode initialize() override
Standard Gaudi initialize.
Definition: HepMCWeightSvc.cxx:18
HepMCWeightSvc::loadWeights
unsigned int loadWeights(unsigned long chanNum)
Try to load weight names from metadata.
Definition: HepMCWeightSvc.cxx:153
checkCoolLatestUpdate.chanNum
chanNum
Definition: checkCoolLatestUpdate.py:27
HepMCWeightSvc::m_weights
WeightInfo m_weights[NWEIGHTS]
Definition: HepMCWeightSvc.h:120
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
HepMCWeightSvc::WeightInfo::m_weightNameVec
std::vector< std::string > m_weightNameVec
Sorted vector of weight names.
Definition: HepMCWeightSvc.h:112
HepMCWeightSvc::getWeightIndex
unsigned int getWeightIndex(const EventContext &ctx)
Return the index in m_weights for the current event.
Definition: HepMCWeightSvc.cxx:225
HepMCWeightSvc::WeightInfo::m_weightNames
WeightMap m_weightNames
Map of weight names.
Definition: HepMCWeightSvc.h:109
HepMCWeightSvc::setWeightNames
virtual StatusCode setWeightNames(const WeightMap &weightNames, const EventContext &ctx=Gaudi::Hive::currentContext()) override
Record weight names to metadata if none have yet been set.
Definition: HepMCWeightSvc.cxx:33
EventInfo.h
HepMCWeightSvc::getChanNum
unsigned long getChanNum(const EventContext &ctx) const
Return the ‘channel number’ for the current event.
Definition: HepMCWeightSvc.cxx:134
HepMCWeightSvc::weightNames
virtual WeightMap weightNames(const EventContext &ctx=Gaudi::Hive::currentContext()) override
Return the current weight names.
Definition: HepMCWeightSvc.cxx:98
AthService.h
HepMCWeightSvc::weightNameVec
virtual std::vector< std::string > weightNameVec(const EventContext &ctx=Gaudi::Hive::currentContext()) override
Return the current weight names.
Definition: HepMCWeightSvc.cxx:115
HepMCWeightSvc::WeightInfo::m_chanNum
unsigned long m_chanNum
Channel number for this set of weights.
Definition: HepMCWeightSvc.h:106
IIOVDbMetaDataTool.h
This is an interface to a tool used to manage the IOV Meta Data for a given object in the MetaData St...
HepMCWeightSvc::m_mutex
std::mutex m_mutex
Serialize access to this service.
Definition: HepMCWeightSvc.h:130
HepMCWeightSvc::WeightInfo::fillVec
void fillVec()
Initialize sorted vector from map.
Definition: HepMCWeightSvc.cxx:243