Belle II Software  release-05-02-19
DelayDQMModule.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2016 - Belle II Collaboration *
4  * *
5  * Description: Create plots NOW-TriggerTime for performance monitoring *
6  * Author: The Belle II Collaboration *
7  * Contributors: Bjoern Spruck *
8  * *
9  * This software is provided "as is" without any warranty. *
10  **************************************************************************/
11 
12 #include "dqm/modules/DelayDQMModule.h"
13 #include "TMath.h"
14 #include "TDirectory.h"
15 
16 #include <chrono>
17 
18 using namespace Belle2;
19 
20 //-----------------------------------------------------------------
21 // Register the Module
22 //-----------------------------------------------------------------
23 REG_MODULE(DelayDQM)
24 
25 //-----------------------------------------------------------------
26 // Implementation
27 //-----------------------------------------------------------------
28 
30 {
31  //Set module properties
32  setDescription("Processing Delay DQM module");
33  setPropertyFlags(c_ParallelProcessingCertified); // specify this flag if you need parallel processing
34  addParam("histogramDirectoryName", m_histogramDirectoryName, "Name of the directory where histograms will be placed",
35  std::string("DAQ"));
36  addParam("title", m_title, "Prefix for Title (ERECO, HLT, ...)", std::string("Processing "));
37  addParam("useMeta", m_useMeta, "Use time from EvtMetadata or FTSW", false);
38 }
39 
41 {
42 // function copied from root-talk
43 
44  TAxis* axis = h->GetXaxis();
45  Int_t bins = axis->GetNbins();
46 
47  Axis_t from = axis->GetXmin();
48  Axis_t to = axis->GetXmax();
49  Axis_t width = (to - from) / bins;
50  Axis_t* new_bins = new Axis_t[bins + 1];
51 
52  for (Int_t i = 0; i <= bins; i++) {
53  new_bins[i] = TMath::Power(10, from + i * width);
54  }
55  axis->Set(bins, new_bins);
56  delete[] new_bins;
57 }
58 
59 //------------------------------------------------------------------
60 // Function to define histograms
61 //-----------------------------------------------------------------
62 
64 {
65  // Create a separate histogram directory and cd into it.
66  TDirectory* oldDir = gDirectory;
67  if (m_histogramDirectoryName != "") {
68  oldDir->mkdir(m_histogramDirectoryName.c_str());// do not use return value with ->cd(), it is ZERO if dir already exists
69  oldDir->cd(m_histogramDirectoryName.c_str());
70  }
71  //----------------------------------------------------------------
72 
73  m_DelayS = new TH1D("DelayS", (m_title + "Delay;time /s").c_str(), 600, 0, 600);
74  m_DelayMs = new TH1D("DelayMs", (m_title + "Delay;time /ms").c_str(), 200, 0, 2000);
75  m_DelayLog = new TH1D("DelayLog", (m_title + "Delay; time /s").c_str(), 200, -3, 6);
76  BinLogX(m_DelayLog); // set log binning, later Draw with SetLogX
77 
78  // cd back to root directory
79  oldDir->cd();
80 }
81 
82 
84 {
85  // Required input
86  if (m_useMeta) {
87  m_eventMetaData.isRequired();
88  } else {
89  m_rawFTSW.isOptional(); // actuall it would be Required(); but this prevents HLT/ERECO test from working
90  }
91 
92  // Register histograms (calls back defineHisto)
93  REG_HISTOGRAM
94 }
95 
97 {
98  // Just to make sure, reset all the histograms.
99  m_DelayMs->Reset();
100  m_DelayS->Reset();
101  m_DelayLog->Reset();
102 }
103 
104 
106 {
107  // Calculate the time difference between now and the trigger time
108  // This tells you how much delay we have summed up (it is NOT the processing time!)
110  using namespace std::chrono;
111  nanoseconds ns = duration_cast<nanoseconds> (system_clock::now().time_since_epoch());
112  nanoseconds event_time{};
113  if (m_useMeta) {
114  // We get the time from EventMetaData, which gets the time from TTD (FTSW)
115  // BUT, this time is inaccurate for longer runs, the difference is larger than teh effect we
116  // monitor in the histograms!
117  event_time = static_cast<nanoseconds>(m_eventMetaData->getTime());
118  } else {
119  // get the trigger time from the NEW member function in TDD data
120  for (auto& it : m_rawFTSW) {
121  struct timeval tv;
122  it.GetPCTimeVal(0, &tv);
123  event_time = (static_cast<seconds>(tv.tv_sec)) + (static_cast<microseconds>(tv.tv_usec));
124  break;
125  }
126  }
127  auto deltaT = (duration_cast<milliseconds> (ns - event_time)).count();
128  m_DelayMs->Fill(deltaT);
129  m_DelayLog->Fill(1e-3 * deltaT);
130  m_DelayS->Fill(1e-3 * deltaT);
131 }
132 
Belle2::DelayDQMModule::m_DelayS
TH1D * m_DelayS
Delay between trigger and end of processing in s.
Definition: DelayDQMModule.h:67
REG_MODULE
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:652
Belle2::DelayDQMModule::event
void event() override final
Function to process event record.
Definition: DelayDQMModule.cc:105
Belle2::DelayDQMModule::defineHisto
void defineHisto() override final
Function to define histograms.
Definition: DelayDQMModule.cc:63
Belle2::DelayDQMModule::m_DelayLog
TH1D * m_DelayLog
Delay between trigger and end of processing log scale.
Definition: DelayDQMModule.h:69
Belle2::DelayDQMModule::m_rawFTSW
StoreArray< RawFTSW > m_rawFTSW
Input for FTSW.
Definition: DelayDQMModule.h:65
Belle2::DelayDQMModule::BinLogX
void BinLogX(TH1 *h)
helper function to replace X axis by a log scaled axis
Definition: DelayDQMModule.cc:40
Belle2::DelayDQMModule::m_title
std::string m_title
Prefix for title (NOT histo name)
Definition: DelayDQMModule.h:58
Belle2::DelayDQMModule::m_useMeta
bool m_useMeta
use time from Meta or FTSW
Definition: DelayDQMModule.h:59
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::DelayDQMModule
Processing Delay DQM Module.
Definition: DelayDQMModule.h:40
Belle2::DelayDQMModule::initialize
void initialize() override final
Module functions.
Definition: DelayDQMModule.cc:83
Belle2::DelayDQMModule::m_eventMetaData
StoreObjPtr< EventMetaData > m_eventMetaData
Input ptr for EventMetaData.
Definition: DelayDQMModule.h:62
Belle2::DelayDQMModule::m_histogramDirectoryName
std::string m_histogramDirectoryName
Name of the histogram directory in ROOT file.
Definition: DelayDQMModule.h:57
Belle2::DelayDQMModule::beginRun
void beginRun() override final
Function to process begin_run record.
Definition: DelayDQMModule.cc:96
Belle2::DelayDQMModule::m_DelayMs
TH1D * m_DelayMs
Delay between trigger and end of processing in ms.
Definition: DelayDQMModule.h:68
Belle2::HistoModule
HistoModule.h is supposed to be used instead of Module.h for the modules with histogram definitions t...
Definition: HistoModule.h:29