Belle II Software  release-06-00-14
DQMHistAnalysisInputSrv.cc
1 /**************************************************************************
2  * basf2 (Belle II Analysis Software Framework) *
3  * Author: The Belle II Collaboration *
4  * *
5  * See git log for contributors and copyright holders. *
6  * This file is licensed under LGPL-3.0, see LICENSE.md. *
7  **************************************************************************/
8 
9 #include <dqm/analysis/modules/DQMHistAnalysisInputSrv.h>
10 
11 #include <TKey.h>
12 #include <TSystem.h>
13 
14 using namespace std;
15 using namespace Belle2;
16 
17 //-----------------------------------------------------------------
18 // Register the Module
19 //-----------------------------------------------------------------
20 REG_MODULE(DQMHistAnalysisInputSrv)
21 
22 //-----------------------------------------------------------------
23 // Implementation
24 //-----------------------------------------------------------------
25 
28 {
29  //Parameter definition
30  addParam("HistMemoryPath", m_mempath, "Path to Input Hist memory", string(""));
31  addParam("HistMemorySize", m_memsize, "Size of Input Hist memory", 10000000);
32  addParam("RefreshInterval", m_interval, "Refresh interval of histograms in ms", 2000);
33  B2DEBUG(20, "DQMHistAnalysisInputSrv: Constructor done.");
34 }
35 
36 
37 DQMHistAnalysisInputSrvModule::~DQMHistAnalysisInputSrvModule() { }
38 
39 void DQMHistAnalysisInputSrvModule::initialize()
40 {
41  if (m_memory != nullptr) delete m_memory;
42  m_memory = new DqmMemFile(m_mempath.c_str());
43  m_eventMetaDataPtr.registerInDataStore();
44  //m_serv = new THttpServer("http:8081");
45  //m_serv->SetReadOnly(kFALSE);
46  B2DEBUG(20, "DQMHistAnalysisInputSrv: initialized.");
47 }
48 
49 
50 void DQMHistAnalysisInputSrvModule::beginRun()
51 {
52  B2DEBUG(20, "DQMHistAnalysisInputSrv: beginRun called.");
53 }
54 
55 void DQMHistAnalysisInputSrvModule::event()
56 {
57  std::vector<TH1*> h;
58  TMemFile* file = m_memory->LoadMemFile();
59  file->cd();
60  TIter next(file->GetListOfKeys());
61  TKey* key = NULL;
62  while ((key = (TKey*)next())) {
63  h.push_back((TH1*)key->ReadObj());
64  }
65  resetHist();
66  for (size_t i = 0; i < h.size(); i++) {
67  addHist("", h[i]->GetName(), h[i]);
68  B2DEBUG(2, "Found : " << h[i]->GetName() << " : " << h[i]->GetEntries());
69  std::string vname = h[i]->GetName();
70  setFloatValue(vname + ".entries", h[i]->GetEntries());
71  if (h[i]->GetDimension() == 1) {
72  setFloatValue(vname + ".rms", h[i]->GetRMS());
73  setFloatValue(vname + ".rmserr", h[i]->GetRMSError());
74  setFloatValue(vname + ".mean", h[i]->GetMean());
75  setFloatValue(vname + ".meanerr", h[i]->GetMeanError());
76  } else if (h[i]->GetDimension() == 2) {
77  setFloatValue(vname + ".xrms", h[i]->GetRMS(1));
78  setFloatValue(vname + ".xrmserr", h[i]->GetRMSError(1));
79  setFloatValue(vname + ".xmean", h[i]->GetMean(1));
80  setFloatValue(vname + ".xmeanerr", h[i]->GetMeanError(1));
81  setFloatValue(vname + ".yrms", h[i]->GetRMS(2));
82  setFloatValue(vname + ".yrmserr", h[i]->GetRMSError(2));
83  setFloatValue(vname + ".ymean", h[i]->GetMean(2));
84  setFloatValue(vname + ".ymeanerr", h[i]->GetMeanError(2));
85  }
86  }
87  m_count++;
88  m_eventMetaDataPtr.create();
89  m_eventMetaDataPtr->setExperiment(m_expno);
90  m_eventMetaDataPtr->setRun(m_runno);
91  m_eventMetaDataPtr->setEvent(m_count);
92 
93  TTimer t(m_interval, kFALSE);// in ms
94 
95  do { // call at least once!
96  //m_serv->ProcessRequests();
97  //gSystem->Sleep(10); // 10 ms sleep
98  } while (!t.CheckTimer(gSystem->Now()));
99 
100 }
101 
102 void DQMHistAnalysisInputSrvModule::endRun()
103 {
104  B2DEBUG(20, "DQMHistAnalysisInputSrv: endRun called");
105 }
106 
107 
108 void DQMHistAnalysisInputSrvModule::terminate()
109 {
110  B2DEBUG(20, "DQMHistAnalysisInputSrv: terminate called");
111 }
112 
Class definition for the output module of Sequential ROOT I/O.
The base class for the histogram analysis module.
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:650
Abstract base class for different kinds of events.