Belle II Software  release-08-00-10
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/shminput/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 
26 DQMHistAnalysisInputSrvModule::DQMHistAnalysisInputSrvModule()
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 
38 
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 
51 {
52  B2DEBUG(20, "DQMHistAnalysisInputSrv: beginRun called.");
53  clearHistList();
54 }
55 
57 {
59 
60  std::vector<TH1*> h;
61  TMemFile* file = m_memory->LoadMemFile();
62  file->cd();
63  TIter next(file->GetListOfKeys());
64  TKey* key = NULL;
65  while ((key = (TKey*)next())) {
66  h.push_back((TH1*)key->ReadObj()); // TODO should check class type before cast
67  }
68  for (size_t i = 0; i < h.size(); i++) {
69  addHist("", h[i]->GetName(), h[i]);
70  B2DEBUG(2, "Found : " << h[i]->GetName() << " : " << h[i]->GetEntries());
71  }
72  m_count++;
73  m_eventMetaDataPtr.create();
74  m_eventMetaDataPtr->setExperiment(m_expno);
75  m_eventMetaDataPtr->setRun(m_runno);
76  m_eventMetaDataPtr->setEvent(m_count);
77 
78  TTimer t(m_interval, kFALSE);// in ms
79 
80  do { // call at least once!
81  //m_serv->ProcessRequests();
82  //gSystem->Sleep(10); // 10 ms sleep
83  } while (!t.CheckTimer(gSystem->Now()));
84 
85 }
86 
88 {
89  B2DEBUG(20, "DQMHistAnalysisInputSrv: endRun called");
90 }
91 
92 
94 {
95  B2DEBUG(20, "DQMHistAnalysisInputSrv: terminate called");
96 }
97 
virtual void initialize() override
Initializer.
virtual void event() override
This method is called for each event.
virtual void endRun() override
This method is called if the current run ends.
virtual void terminate() override
This method is called at the end of the event processing.
std::string m_mempath
Path to input hist memory.
virtual void beginRun() override
Called when entering a new run.
int m_memsize
Size of the input hist memory.
int m_interval
The refresh interval in ms.
StoreObjPtr< EventMetaData > m_eventMetaDataPtr
The metadata for each event.
The base class for the histogram analysis module.
static void clearHistList(void)
Clears the list of histograms.
static bool addHist(const std::string &dirname, const std::string &histname, TH1 *h)
Add histogram.
static void initHistListBeforeEvent(void)
Reset the list of histograms.
void addParam(const std::string &name, T &paramVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
Definition: Module.h:560
#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.