ATLAS Offline Software
Classes | Public Member Functions | Private Member Functions | Private Attributes | List of all members
Monitored::OfflineHistogramProvider Class Reference

Implementation of IHistogramProvider for offline histograms. More...

#include <OfflineHistogramProvider.h>

Inheritance diagram for Monitored::OfflineHistogramProvider:
Collaboration diagram for Monitored::OfflineHistogramProvider:

Classes

struct  objcache
 

Public Member Functions

 OfflineHistogramProvider (GenericMonitoringTool *const gmTool, std::shared_ptr< HistogramFactory > factory, const HistogramDef &histDef)
 Constructor. More...
 
virtual ~OfflineHistogramProvider () override
 
TNamed * histogram () override
 Getter of ROOT object. More...
 

Private Member Functions

void storeMetadata () const
 Store metadata trees. More...
 

Private Attributes

GenericMonitoringTool *const m_gmTool
 
std::shared_ptr< HistogramFactorym_factory
 
std::shared_ptr< HistogramDefm_histDef
 
Gaudi::Hive::ContextSpecificData< objcache > m_objcache ATLAS_THREAD_SAFE
 
std::mutex m_cacheMutex
 
std::vector< std::string > m_storedPaths
 

Detailed Description

Implementation of IHistogramProvider for offline histograms.

Definition at line 29 of file OfflineHistogramProvider.h.

Constructor & Destructor Documentation

◆ OfflineHistogramProvider()

Monitored::OfflineHistogramProvider::OfflineHistogramProvider ( GenericMonitoringTool *const  gmTool,
std::shared_ptr< HistogramFactory factory,
const HistogramDef histDef 
)
inline

Constructor.

Parameters
gmToolSource of the lumi block info
factoryROOT object factory
defGeneral definition of a histogram

Definition at line 38 of file OfflineHistogramProvider.h.

41  : IHistogramProvider()
42  , m_gmTool(gmTool)
43  , m_factory(std::move(factory))
44  , m_histDef(new HistogramDef(histDef))
45  , m_objcache({0, 0, nullptr})
46  {}

◆ ~OfflineHistogramProvider()

virtual Monitored::OfflineHistogramProvider::~OfflineHistogramProvider ( )
inlineoverridevirtual

Definition at line 49 of file OfflineHistogramProvider.h.

49  {
50  try {
51  storeMetadata();
52  }
53  catch (const GaudiException&) {
54  // storeMetadata can throw due to dereferencing a Gaudi handle
55  std::abort();
56  }
57  }

Member Function Documentation

◆ histogram()

TNamed* Monitored::OfflineHistogramProvider::histogram ( )
inlineoverridevirtual

Getter of ROOT object.

Each time the method is called, factory produces ROOT object based on the current lumi block. Note: ROOT objects are cached at the factory. Nevertheless, it is recommended to call this method as rarely as possible.

Returns
ROOT object

Implements Monitored::IHistogramProvider.

Definition at line 68 of file OfflineHistogramProvider.h.

68  {
69  const unsigned runNumber = m_gmTool->runNumber();
70  const unsigned lumiBlock = m_gmTool->lumiBlock();
71 
72  // do we have the object already?
73  std::scoped_lock lock(m_cacheMutex);
74  objcache& objcacheref = m_objcache;
75  if (objcacheref.lumiBlock == lumiBlock
76  && objcacheref.runNumber == runNumber
77  && objcacheref.object) {
78  return objcacheref.object;
79  }
80 
81  std::string lbString;
84  lbString = "";
85  } else if ( period == HistogramDef::RunPeriod::LowStat ) {
86  const unsigned lbBase = lumiBlock-(((int64_t)lumiBlock-1)%20);
87  lbString = "/lowStat_LB"+std::to_string(lbBase)+"-"+std::to_string(lbBase+19);
88  } else {
89  lbString = "/lb_"+std::to_string(lumiBlock);
90  }
91  m_histDef->tld = "/run_"+std::to_string(runNumber)+lbString+"/";
92 
93  objcacheref.lumiBlock = lumiBlock;
94  objcacheref.runNumber = runNumber;
95  objcacheref.object = m_factory->create(*m_histDef);
96  const auto fullName = m_factory->getFullName(*m_histDef);
97  if (std::find(m_storedPaths.begin(), m_storedPaths.end(), fullName) == m_storedPaths.end()) {
98  m_storedPaths.push_back(fullName);
99  }
100  return objcacheref.object;
101  }

◆ storeMetadata()

void Monitored::OfflineHistogramProvider::storeMetadata ( ) const
inlineprivate

Store metadata trees.

Offline ROOT output should have "metadata" TTrees; this function makes them

Definition at line 124 of file OfflineHistogramProvider.h.

124  {
125  std::scoped_lock<std::mutex> metadataLock(s_metadataMutex);
126  for (const auto &path : m_storedPaths) {
127  //std::cout << "Path " << path << std::endl;
128  size_t pos = path.find_last_of('/');
129  auto splitPath = std::make_pair(path.substr(0, pos), path.substr(pos + 1));
130  std::string treePath = splitPath.first + "/metadata";
131  auto &histSvc = m_gmTool->histogramService();
132  std::string interval;
133  char triggerData[] = "<none>";
134  const std::string mergeDataStr = m_histDef->merge == "" ? "<default>" : m_histDef->merge;
135  std::vector<char> mergeData{mergeDataStr.begin(), mergeDataStr.end()};
136  mergeData.push_back('\0');
137 
140  interval = "run";
142  interval = "lowStat";
143  } else {
144  interval = "lumiBlock";
145  }
146  if (!histSvc->existsTree(treePath)) {
147  auto tree = std::make_unique<TTree>("metadata", "Monitoring Metadata");
148 
149  tree->Branch("Name", &(splitPath.second[0]), "Name/C");
150  tree->Branch("Interval", &(interval[0]), "Interval/C");
151  tree->Branch("TriggerChain", triggerData, "TriggerChain/C");
152  tree->Branch("MergeMethod", mergeData.data(), "MergeMethod/C");
153  tree->Fill();
154 
155  if (!histSvc->regTree(treePath, std::move(tree))) {
156  MsgStream log(Athena::getMessageSvc(), "OfflineHistogramProvider");
157  log << MSG::ERROR
158  << "Failed to register DQ metadata TTree " << treePath << endmsg;
159  }
160  } else {
161  TTree *tree{nullptr};
162  if (histSvc->getTree(treePath, tree).isSuccess()) {
163  tree->SetBranchAddress("Name", &(splitPath.second[0]));
164  tree->SetBranchAddress("Interval", &(interval[0]));
165  tree->SetBranchAddress("TriggerChain", triggerData);
166  tree->SetBranchAddress("MergeMethod", mergeData.data());
167  tree->Fill();
168  } else {
169  MsgStream log(Athena::getMessageSvc(), "OfflineHistogramProvider");
170  log << MSG::ERROR
171  << "Failed to retrieve DQ metadata TTree " << treePath << " which is reported to exist" << endmsg;
172  }
173  }
174  }
175  }

Member Data Documentation

◆ ATLAS_THREAD_SAFE

Gaudi::Hive::ContextSpecificData<objcache> m_objcache Monitored::OfflineHistogramProvider::ATLAS_THREAD_SAFE
mutableprivate

Definition at line 113 of file OfflineHistogramProvider.h.

◆ m_cacheMutex

std::mutex Monitored::OfflineHistogramProvider::m_cacheMutex
private

Definition at line 114 of file OfflineHistogramProvider.h.

◆ m_factory

std::shared_ptr<HistogramFactory> Monitored::OfflineHistogramProvider::m_factory
private

Definition at line 105 of file OfflineHistogramProvider.h.

◆ m_gmTool

GenericMonitoringTool* const Monitored::OfflineHistogramProvider::m_gmTool
private

Definition at line 104 of file OfflineHistogramProvider.h.

◆ m_histDef

std::shared_ptr<HistogramDef> Monitored::OfflineHistogramProvider::m_histDef
private

Definition at line 106 of file OfflineHistogramProvider.h.

◆ m_storedPaths

std::vector<std::string> Monitored::OfflineHistogramProvider::m_storedPaths
private

Definition at line 116 of file OfflineHistogramProvider.h.


The documentation for this class was generated from the following file:
python.AtlRunQueryAMI.period
period
Definition: AtlRunQueryAMI.py:225
Monitored::OfflineHistogramProvider::m_histDef
std::shared_ptr< HistogramDef > m_histDef
Definition: OfflineHistogramProvider.h:106
athena.path
path
python interpreter configuration --------------------------------------—
Definition: athena.py:128
find
std::string find(const std::string &s)
return a remapped string
Definition: hcg.cxx:135
Monitored::OfflineHistogramProvider::m_factory
std::shared_ptr< HistogramFactory > m_factory
Definition: OfflineHistogramProvider.h:105
Monitored::HistogramDef::RunPeriod::Run
@ Run
rebook histogram after each run
WriteCellNoiseToCool.fullName
fullName
Definition: WriteCellNoiseToCool.py:461
tree
TChain * tree
Definition: tile_monitor.h:30
GenericMonitoringTool::lumiBlock
virtual uint32_t lumiBlock()
Definition: GenericMonitoringTool.cxx:286
Athena::getMessageSvc
IMessageSvc * getMessageSvc(bool quiet=false)
Definition: getMessageSvc.cxx:20
Monitored::HistogramDef::RunPeriod
RunPeriod
Definition: HistogramDef.h:33
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
getLatestRuns.interval
interval
Definition: getLatestRuns.py:24
Monitored::OfflineHistogramProvider::m_storedPaths
std::vector< std::string > m_storedPaths
Definition: OfflineHistogramProvider.h:116
MuonSegmentReaderConfig.histSvc
histSvc
Definition: MuonSegmentReaderConfig.py:96
Monitored::OfflineHistogramProvider::m_gmTool
GenericMonitoringTool *const m_gmTool
Definition: OfflineHistogramProvider.h:104
Monitored::OfflineHistogramProvider::m_cacheMutex
std::mutex m_cacheMutex
Definition: OfflineHistogramProvider.h:114
GenericMonitoringTool::runNumber
virtual uint32_t runNumber()
Definition: GenericMonitoringTool.cxx:282
ActsTrk::to_string
std::string to_string(const DetectorType &type)
Definition: GeometryDefs.h:34
Monitored::OfflineHistogramProvider::storeMetadata
void storeMetadata() const
Store metadata trees.
Definition: OfflineHistogramProvider.h:124
GenericMonitoringTool::histogramService
virtual const ServiceHandle< ITHistSvc > & histogramService() const
Definition: GenericMonitoringTool.h:72
python.LumiBlobConversion.pos
pos
Definition: LumiBlobConversion.py:18
DeMoAtlasDataLoss.runNumber
string runNumber
Definition: DeMoAtlasDataLoss.py:64
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
Monitored::HistogramDef::RunPeriod::LowStat
@ LowStat
rebook histogram after every 20 lumiblocks
xAOD::lumiBlock
setTeId lumiBlock
Definition: L2StandAloneMuon_v1.cxx:328