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(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 { storeMetadata(); }

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 60 of file OfflineHistogramProvider.h.

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

◆ storeMetadata()

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

Store metadata trees.

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

Definition at line 116 of file OfflineHistogramProvider.h.

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

Member Data Documentation

◆ ATLAS_THREAD_SAFE

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

Definition at line 105 of file OfflineHistogramProvider.h.

◆ m_cacheMutex

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

Definition at line 106 of file OfflineHistogramProvider.h.

◆ m_factory

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

Definition at line 97 of file OfflineHistogramProvider.h.

◆ m_gmTool

GenericMonitoringTool* const Monitored::OfflineHistogramProvider::m_gmTool
private

Definition at line 96 of file OfflineHistogramProvider.h.

◆ m_histDef

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

Definition at line 98 of file OfflineHistogramProvider.h.

◆ m_storedPaths

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

Definition at line 108 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:98
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:97
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:108
MuonSegmentReaderConfig.histSvc
histSvc
Definition: MuonSegmentReaderConfig.py:96
Monitored::OfflineHistogramProvider::m_gmTool
GenericMonitoringTool *const m_gmTool
Definition: OfflineHistogramProvider.h:96
Monitored::OfflineHistogramProvider::m_cacheMutex
std::mutex m_cacheMutex
Definition: OfflineHistogramProvider.h:106
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:116
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:327