Belle II Software development
EclDisplayModule.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//This module
10#include <ecl/modules/eclDisplay/EclDisplayModule.h>
11
12//Root
13#include <TApplication.h>
14#include <TSystem.h>
15#include <TFile.h>
16
17//Framework
18#include <framework/utilities/EnvironmentVariables.h>
19
20//ECL
21#include <ecl/dataobjects/ECLCalDigit.h>
22#include <ecl/modules/eclDisplay/EclFrame.h>
23#include <ecl/modules/eclDisplay/EclData.h>
24#include <ecl/modules/eclDisplay/geometry.h>
25
26using namespace Belle2;
27using namespace ECLDisplayUtility;
28
29//-----------------------------------------------------------------
30// Register the Module
31//-----------------------------------------------------------------
32REG_MODULE(EclDisplay);
33
34//-----------------------------------------------------------------
35// Implementation
36//-----------------------------------------------------------------
37
38EclDisplayModule::EclDisplayModule() : Module()
39{
40 // Set module properties
41 setDescription("Event display module for ECL.");
42
43 // Parameter definitions
44 addParam("showDisplay", m_showDisplay,
45 "Show GUI. Off by default because GUI crashes automatic tests.", false);
46 addParam("keepOpen", m_keepOpen,
47 "Keep window open after all events have been processed", false);
48 addParam("displayEnergy", m_displayEnergy,
49 "If true, energy distribution per channel (shaper, crate) is displayed. Otherwise, number of counts is displayed", false);
50 addParam("displayMode", m_displayMode,
51 "Default display mode. Can be later changed in GUI.", 9);
52 addParam("autoDisplay", m_autoDisplay,
53 "If true, events are displayed as soon as they are loaded.", true);
54 addParam("InitFileName", m_eclMapperInitFileName,
55 "Initialization file for eclMapper", std::string("ecl/data/ecl_channels_map.txt"));
56
57 m_evtNum = 0;
58}
59
61{
62}
63
65{
66 m_eclarray.isRequired();
67
68 if (!m_showDisplay) {
69 m_frame_closed = true;
70 } else {
71 // Check if X display is available.
72 std::string display = EnvironmentVariables::get("DISPLAY", "");
73 if (display == "") {
74 B2WARNING("Environment variable DISPLAY is not set, event display won't be opened");
75 m_frame_closed = true;
76 }
77 }
78
79 if (!m_frame_closed)
80 initFrame();
81}
82
84{
85 //== Init temporary file so TTree is not kept in memory.
86 m_tempname = "ecldisplay_tmp";
87
88 if (gSystem->TempFileName(m_tempname) == 0) {
89 throw std::runtime_error("ECLDisplay: failed to create temp file.");
90 } else {
91 m_tempfile = new TFile(m_tempname, "recreate");
92 gSystem->Unlink(m_tempname);
93 }
94
96 m_app = new TApplication("ECLDisplay App", 0, 0);
97 m_data = new EclData();
99
100 m_frame->Connect("CloseWindow()", "Belle2::EclDisplayModule", this, "handleClosedFrame()");
101
102 B2DEBUG(100, "EclDisplayModule::create ECLFrame");
103}
104
106{
107 m_frame_closed = true;
108}
109
111{
112 // Initialize channel mapper at run start to account for possible
113 // changes in ECL mapping between runs.
114 if (!m_mapper.initFromDB()) {
115 B2FATAL("ECL Display:: Can't initialize eclChannelMapper");
116 }
117}
118
120{
121 // EclFrame is closed, skipping data reading.
122 if (m_frame_closed) return;
123
124 int added_entries = 0;
125
126 for (int i = 0; i < m_eclarray.getEntries(); i++) {
127 ECLCalDigit* record = m_eclarray[i];
128 if (record->getEnergy() >= 1e-4) { //TODO: Move to constant ENERGY_THRESHOLD.
129 if (m_data->addEvent(record, m_evtNum) == 0) {
130 added_entries++;
131 }
132 }
133 }
134
135 if (m_autoDisplay) {
136 m_data->update(true);
137 gSystem->ProcessEvents();
138 if (!m_frame_closed)
140 }
141 if (added_entries > 0)
142 m_evtNum++;
143}
144
146{
147}
148
150{
151 if (m_keepOpen) {
152 if (!m_frame_closed) {
153 m_data->update(false);
155 }
156
157 while (!m_frame_closed) {
158 gSystem->ProcessEvents();
159 gSystem->Sleep(0);
160 }
161 }
162
163 if (m_frame) delete m_frame;
164 if (m_data) delete m_data;
165}
166
Class to store calibrated ECLDigits: ECLCalDigits.
Definition: ECLCalDigit.h:23
bool initFromDB()
Initialize channel mapper from the conditions database.
This class contains data for ECLSimHit's and provides several relevant conversion functions for bette...
Definition: EclData.h:31
int addEvent(ECLCalDigit *event, int evtn)
Add ECLDigit event to inner TTree (m_tree).
Definition: EclData.cc:428
void update(bool reset_event_ranges=false)
Update time_min, time_max, event_counts and energy_sums.
Definition: EclData.cc:368
bool m_frame_closed
Flag to check if EclFrame is closed;.
int m_evtNum
Counter of added events.
bool m_autoDisplay
If true, events are displayed as soon as they are loaded.
ECL::ECLChannelMapper m_mapper
Channel mapper to show channel <-> (crate, shaper) distributions.
bool m_keepOpen
Keep window open after all events have been processed.
virtual void initialize() override
Initialize EclChannelMapper.
TFile * m_tempfile
Temporary file to store TTree.
virtual void event() override
Handle event.
void initFrame()
Initialize EclFrame.
virtual void endRun() override
Empty method.
virtual void terminate() override
Wait till EclFrame is closed then free allocated resources.
EclFrame * m_frame
Root GUI to display ECL data.
virtual void beginRun() override
Empty method.
bool m_displayEnergy
If true, energy distribution in ECL is displayed.
int m_displayMode
Default display mode.
TApplication * m_app
Application to contain EclFrame.
StoreArray< ECLCalDigit > m_eclarray
Displayed ECL events.
TString m_tempname
Name of temporary file.
virtual ~EclDisplayModule()
Module destructor.
void handleClosedFrame()
This method is called when EclFrame is closed.
EclData * m_data
Class that provides interface for quick and comprehensive analysis of large number of events.
Root TGMainFrame that contains multiple widgets that display the ECLSimHit's w.r.t.
Definition: EclFrame.h:41
void loadNewData()
Update view of the data.
Definition: EclFrame.cc:377
Base class for Modules.
Definition: Module.h:72
void SetMode(int i)
Changes between display of events (0) and energy (1).
Definition: geometry.cc:15
static std::string get(const std::string &name, const std::string &fallback="")
Get the value of an environment variable or the given fallback value if the variable is not set.
#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.