ATLAS Offline Software
TrigCostAnalysis.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 TRIGCOSTANALYSIS_TRIGCOSTALYSIS_H
6 #define TRIGCOSTANALYSIS_TRIGCOSTALYSIS_H 1
7 
11 #include "TrigConfData/HLTMenu.h"
13 
15 
16 #include "Gaudi/Parsers/Factory.h"
17 #include "GaudiKernel/ITHistSvc.h"
18 
19 #include "MonitoredRange.h"
20 #include "CostROSData.h"
21 
22 #include <unordered_map>
23 #include <mutex>
24 
25 #include "TH1.h"
26 #include "TTree.h"
27 
37  public:
38 
44  TrigCostAnalysis( const std::string& name, ISvcLocator* pSvcLocator );
45 
49  virtual ~TrigCostAnalysis() = default;
50 
54  virtual StatusCode initialize() final;
55 
59  virtual StatusCode start();
60 
64  virtual StatusCode execute() final;
65 
69  virtual StatusCode finalize() final;
70 
77  TH1* bookGetPointer(TH1* hist, const std::string& tDir = "") const;
78 
79  ServiceHandle<ITHistSvc> m_histSvc{ this, "THistSvc", "THistSvc/THistSvc", "Histogramming svc" };
80 
81  Gaudi::Property<bool> m_singleTimeRange { this, "UseSingleTimeRange", false,
82  "Use a single time range rather than splitting by LB" };
83 
84  Gaudi::Property<std::string> m_singleTimeRangeName { this, "SingleTimeRangeName", "All",
85  "Name for single time range" };
86 
87  Gaudi::Property<std::string> m_additionalHashMap { this, "AdditionalHashMap", "TrigCostRootAnalysis/hashes2string_29042021.txt",
88  "Used to load strings corresponding to algorithms which are not explicitly scheduled by chains. To be updated periodically." };
89 
90  Gaudi::Property<std::vector<std::string>> m_additionalHashList { this, "AdditionalHashList", {},
91  "Used to load strings corresponding to algorithms which are not explicitly scheduled by chains." };
92 
93  Gaudi::Property<size_t> m_TimeRangeLengthLB { this, "TimeRangeLengthLB", 50,
94  "Length of each variable length Time Range in LB" };
95 
96  Gaudi::Property<size_t> m_maxTimeRange { this, "MaxTimeRanges", 5,
97  "Maximum number of allowed time ranges" };
98 
99  Gaudi::Property<bool> m_doMonitorAlgorithm { this, "DoMonitorAlgs", true,
100  "Monitor individual algorithms by instance name" };
101 
102  Gaudi::Property<bool> m_doMonitorAlgorithmClass { this, "DoMonitorAlgClass", true,
103  "Monitor individual algorithms by instance class type name" };
104 
105  Gaudi::Property<bool> m_doMonitorGlobal { this, "DoMonitorGlobal", true,
106  "Monitor global event properties" };
107 
108  Gaudi::Property<bool> m_doMonitorThreadOccupancy { this, "DoMonitorThreadOccupancy", true,
109  "Monitor algorithm occupancy load of individual threads in an MT execution environment" };
110 
111  Gaudi::Property<bool> m_doMonitorROS { this, "DoMonitorROS", true,
112  "Monitor Read-Out System" };
113 
114  Gaudi::Property<bool> m_doMonitorChain { this, "DoMonitorChain", true,
115  "Monitor individual chains by instance name" };
116 
117  Gaudi::Property<bool> m_doMonitorChainAlgorithm { this, "DoMonitorChainAlgorithm", false,
118  "Monitor algorithms associated with chains by instance name" };
119 
120  Gaudi::Property<bool> m_doMonitorSequence { this, "DoMonitorSequence", true,
121  "Monitor individual sequences by name" };
122 
123  Gaudi::Property<bool> m_useEBWeights { this, "UseEBWeights", true,
124  "Apply Enhanced Bias weights" };
125 
126  Gaudi::Property<size_t> m_maxFullEventDumps { this, "MaxFullEventDumps", 10,
127  "Maximum number of full event summaries which will be dumped" };
128 
129  Gaudi::Property<uint64_t> m_fullEventDumpProbability { this, "FullEventDumpProbability", 10,
130  "Save a full record of one in every N events, up to MaxFullEventDumps." };
131 
132  Gaudi::Property<float> m_baseEventWeight { this, "BaseEventWeight", true,
133  "Base events weight, other weights may be multiplied on top of this one." };
134 
135  Gaudi::Property<std::map<std::string, std::vector<uint32_t>>> m_rosToRob {
136  this, "ROSToROBMap", {}, "ROS to ROB mapping" };
137 
138  SG::ReadHandleKey<xAOD::TrigCompositeContainer> m_costDataKey { this, "CostReadHandleKey", "HLT_TrigCostContainer",
139  "Trigger cost payload container for algorithms" };
140 
141  SG::ReadHandleKey<xAOD::TrigCompositeContainer> m_rosDataKey { this, "CostROSReadHandleKey", "HLT_TrigCostROSContainer",
142  "Trigger ROS cost payload container for algorithms" };
143 
144  SG::ReadHandleKey<xAOD::TrigCompositeContainer> m_metadataDataKey { this, "CostMetadataWriteHandleKey", "HLT_RuntimeMetadata",
145  "TrigComposite collections with additional cost metadata" };
146 
147  SG::ReadHandleKey<TrigConf::HLTMenu> m_HLTMenuKey{this, "HLTTriggerMenu", "DetectorStore+HLTTriggerMenu",
148  "HLT Menu"};
149 
150  ToolHandle<IEnhancedBiasWeighter> m_enhancedBiasTool{this, "EnhancedBiasTool", "",
151  "Enhanced bias weighting tool."};
152 
153  ToolHandle<TrigCompositeUtils::AlgToChainTool> m_algToChainTool{this, "AlgToChainTool", "",
154  "Tool to retrieve chains for algorithm."};
155 
156  private:
157 
164  bool checkDoFullEventDump(const EventContext& context, const CostData& costData);
165 
173  StatusCode getRange(const EventContext& context, MonitoredRange*& range);
174 
179  StatusCode dumpEvent(const EventContext& context) const;
180 
186 
192  float getWeight(const EventContext& context);
193 
199  uint32_t getOnlineSlot(const xAOD::TrigCompositeContainer* costCollection) const;
200 
205  StatusCode checkUpdateMaxView(const size_t max);
206 
210  void writeMetadata();
211 
212  std::unordered_map<std::string, std::unique_ptr<MonitoredRange> > m_monitoredRanges;
213  std::unordered_map<uint32_t, std::string > m_algTypeMap;
214  std::set<std::string> m_storeIdentifiers;
215  TTree* m_metadataTree;
216 
217  mutable std::atomic<size_t> m_fullEventDumps;
218  mutable std::atomic<size_t> m_maxViewsNumber;
220  mutable std::set<std::string> m_hostnames ATLAS_THREAD_SAFE;
221 
223 };
224 
225 #endif // TRIGCOSTANALYSIS_TRIGCOSTALYSIS_H
ReadHandleKeyArray.h
TrigCostAnalysis::finalize
virtual StatusCode finalize() final
Currently a noop for this algorithm.
Definition: TrigCostAnalysis.cxx:459
TrigCostAnalysis::m_additionalHashMap
Gaudi::Property< std::string > m_additionalHashMap
Definition: TrigCostAnalysis.h:87
TrigCostAnalysis::m_histSvc
ServiceHandle< ITHistSvc > m_histSvc
Definition: TrigCostAnalysis.h:79
TrigCostAnalysis::execute
virtual StatusCode execute() final
Monitor event, unless max range limit reached and event outside of all ranges.
Definition: TrigCostAnalysis.cxx:184
CostROSData.h
TrigCostAnalysis::m_costDataKey
SG::ReadHandleKey< xAOD::TrigCompositeContainer > m_costDataKey
Definition: TrigCostAnalysis.h:138
TrigCostAnalysis::m_fullEventDumps
std::atomic< size_t > m_fullEventDumps
Counter to keep track of how many events have been full-dumped.
Definition: TrigCostAnalysis.h:217
TrigCostAnalysis::m_rosDataKey
SG::ReadHandleKey< xAOD::TrigCompositeContainer > m_rosDataKey
Definition: TrigCostAnalysis.h:141
TrigCostAnalysis::m_storeIdentifiers
std::set< std::string > m_storeIdentifiers
Identifiers of object stores, needed to cache STORE string-hash values.
Definition: TrigCostAnalysis.h:214
TrigCostAnalysis::m_maxViewsNumber
std::atomic< size_t > m_maxViewsNumber
What is the maximum number of View instances we've so far cached string hashes to cover?
Definition: TrigCostAnalysis.h:218
TrigCostAnalysis::writeMetadata
void writeMetadata()
Write to outpute tree (if any) the metadata needed downstream.
Definition: TrigCostAnalysis.cxx:467
TrigCostAnalysis::initialize
virtual StatusCode initialize() final
Retrieve tools and initialise read handles.
Definition: TrigCostAnalysis.cxx:34
TrigCostAnalysis::m_maxFullEventDumps
Gaudi::Property< size_t > m_maxFullEventDumps
Definition: TrigCostAnalysis.h:126
TrigCostAnalysis::getOnlineSlot
uint32_t getOnlineSlot(const xAOD::TrigCompositeContainer *costCollection) const
Return the slot used to process the event online.
Definition: TrigCostAnalysis.cxx:401
TrigCostAnalysis::m_doMonitorROS
Gaudi::Property< bool > m_doMonitorROS
Definition: TrigCostAnalysis.h:111
TrigCostAnalysis::m_doMonitorChain
Gaudi::Property< bool > m_doMonitorChain
Definition: TrigCostAnalysis.h:114
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
TrigCostAnalysis::bookGetPointer
TH1 * bookGetPointer(TH1 *hist, const std::string &tDir="") const
Public method forwarded to this class' AthHistogramAlgorithm::bookGetPointer base.
Definition: TrigCostAnalysis.cxx:171
TrigCostAnalysis::m_fullEventDumpProbability
Gaudi::Property< uint64_t > m_fullEventDumpProbability
Definition: TrigCostAnalysis.h:129
BeamSpot::mutex
std::mutex mutex
Definition: InDetBeamSpotVertex.cxx:18
max
constexpr double max()
Definition: ap_fixedTest.cxx:33
MonitoredRange.h
plotmaker.hist
hist
Definition: plotmaker.py:148
TrigCostAnalysis::m_algTypeMap
std::unordered_map< uint32_t, std::string > m_algTypeMap
Cache of algorithm's type, read from configuration data.
Definition: TrigCostAnalysis.h:213
TrigCostAnalysis::m_algToChainTool
ToolHandle< TrigCompositeUtils::AlgToChainTool > m_algToChainTool
Definition: TrigCostAnalysis.h:153
TrigCostAnalysis::TrigCostAnalysis
TrigCostAnalysis(const std::string &name, ISvcLocator *pSvcLocator)
Construct TrigCostAnalysis.
Definition: TrigCostAnalysis.cxx:26
TrigCostAnalysis::checkUpdateMaxView
StatusCode checkUpdateMaxView(const size_t max)
High watermark for pre-cached string hashes for the SLOT category.
Definition: TrigCostAnalysis.cxx:138
const
bool const RAWDATA *ch2 const
Definition: LArRodBlockPhysicsV0.cxx:560
SG::ReadHandleKey
Property holding a SG store/key/clid from which a ReadHandle is made.
Definition: StoreGate/StoreGate/ReadHandleKey.h:39
TrigCostAnalysis::m_useEBWeights
Gaudi::Property< bool > m_useEBWeights
Definition: TrigCostAnalysis.h:123
EnhancedBiasWeighter.h
TrigCostAnalysis::m_enhancedBiasTool
ToolHandle< IEnhancedBiasWeighter > m_enhancedBiasTool
Definition: TrigCostAnalysis.h:150
TrigCostAnalysis::m_baseEventWeight
Gaudi::Property< float > m_baseEventWeight
Definition: TrigCostAnalysis.h:132
AthAlgorithm.h
TrigCostAnalysis::~TrigCostAnalysis
virtual ~TrigCostAnalysis()=default
Default destructor.
TrigCostAnalysis::m_addHostnameMutex
std::mutex m_addHostnameMutex
Mutex to update set below.
Definition: TrigCostAnalysis.h:219
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
TrigCostAnalysis::m_singleTimeRange
Gaudi::Property< bool > m_singleTimeRange
Definition: TrigCostAnalysis.h:81
TrigCostAnalysis::m_costROSData
CostROSData m_costROSData
Cached CostROSData class with details needed for ROS monitoring.
Definition: TrigCostAnalysis.h:222
TrigCostAnalysis::m_metadataTree
TTree * m_metadataTree
Used to write out some metadata needed by post-processing (e.g.
Definition: TrigCostAnalysis.h:215
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
TrigCostAnalysis::m_additionalHashList
Gaudi::Property< std::vector< std::string > > m_additionalHashList
Definition: TrigCostAnalysis.h:90
TrigCostAnalysis::m_doMonitorThreadOccupancy
Gaudi::Property< bool > m_doMonitorThreadOccupancy
Definition: TrigCostAnalysis.h:108
TrigCostAnalysis::m_doMonitorGlobal
Gaudi::Property< bool > m_doMonitorGlobal
Definition: TrigCostAnalysis.h:105
DataVector
Derived DataVector<T>.
Definition: DataVector.h:794
AthAlgorithm
Definition: AthAlgorithm.h:47
TrigCompositeContainer.h
TrigCostAnalysis::registerMonitors
StatusCode registerMonitors(MonitoredRange *range)
Populate a newly minted Range object with all configured Monitors.
Definition: TrigCostAnalysis.cxx:316
TrigCostAnalysis::m_monitoredRanges
std::unordered_map< std::string, std::unique_ptr< MonitoredRange > > m_monitoredRanges
Owned storage of Ranges.
Definition: TrigCostAnalysis.h:212
CostROSData
Caches and propagates event data to be used by monitoring algorithms.
Definition: CostROSData.h:24
TrigCostAnalysis::m_doMonitorSequence
Gaudi::Property< bool > m_doMonitorSequence
Definition: TrigCostAnalysis.h:120
TrigCostAnalysis::m_doMonitorAlgorithm
Gaudi::Property< bool > m_doMonitorAlgorithm
Definition: TrigCostAnalysis.h:99
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
TrigCostAnalysis::m_metadataDataKey
SG::ReadHandleKey< xAOD::TrigCompositeContainer > m_metadataDataKey
Definition: TrigCostAnalysis.h:144
TrigCostAnalysis
Athena algorithm used to process Trigger cost monitoring data in Run 3 and above. Outputs histograms.
Definition: TrigCostAnalysis.h:36
TrigCostAnalysis::m_doMonitorChainAlgorithm
Gaudi::Property< bool > m_doMonitorChainAlgorithm
Definition: TrigCostAnalysis.h:117
TrigCostAnalysis::start
virtual StatusCode start()
Retrieve menu handle.
Definition: TrigCostAnalysis.cxx:74
TrigCostAnalysis::m_HLTMenuKey
SG::ReadHandleKey< TrigConf::HLTMenu > m_HLTMenuKey
Definition: TrigCostAnalysis.h:147
TrigCostAnalysis::m_TimeRangeLengthLB
Gaudi::Property< size_t > m_TimeRangeLengthLB
Definition: TrigCostAnalysis.h:93
MonitoredRange
Container which represents a time range and holds a collection of Monitors which monitor this range.
Definition: MonitoredRange.h:29
TrigCostAnalysis::m_singleTimeRangeName
Gaudi::Property< std::string > m_singleTimeRangeName
Definition: TrigCostAnalysis.h:84
TrigCostAnalysis::m_doMonitorAlgorithmClass
Gaudi::Property< bool > m_doMonitorAlgorithmClass
Definition: TrigCostAnalysis.h:102
HLTMenu.h
TrigCostAnalysis::getWeight
float getWeight(const EventContext &context)
Compute global event weight to correct for online prescales.
Definition: TrigCostAnalysis.cxx:160
TrigCostAnalysis::m_maxTimeRange
Gaudi::Property< size_t > m_maxTimeRange
Definition: TrigCostAnalysis.h:96
TrigCostAnalysis::m_rosToRob
Gaudi::Property< std::map< std::string, std::vector< uint32_t > > > m_rosToRob
Definition: TrigCostAnalysis.h:135
TrigCostAnalysis::getRange
StatusCode getRange(const EventContext &context, MonitoredRange *&range)
Return or construct and return a Range for the Context.
Definition: TrigCostAnalysis.cxx:361
CostData
Caches and propagates event data to be used by monitoring algorithms.
Definition: CostData.h:26
TrigCostAnalysis::ATLAS_THREAD_SAFE
std::set< std::string > m_hostnames ATLAS_THREAD_SAFE
Save unique hostnames for the run.
Definition: TrigCostAnalysis.h:220
TrigCostAnalysis::dumpEvent
StatusCode dumpEvent(const EventContext &context) const
Dump event algorithm execution data in ASCII format.
Definition: TrigCostAnalysis.cxx:421
AlgToChainTool.h
TrigCostAnalysis::checkDoFullEventDump
bool checkDoFullEventDump(const EventContext &context, const CostData &costData)
Check if event dumping should be performed for the current event.
Definition: TrigCostAnalysis.cxx:304
ServiceHandle
Definition: ClusterMakerTool.h:37