status.cxx
Go to the documentation of this file.
1 #include <gtk/gtk.h>
2 #include <string.h>
3 #include <stdint.h>
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <math.h>
7 #include <vector>
8 #include "event.h"
9 #include "status.h"
10 
11 GtkTextBuffer * stattext[NSTATBOXES];
12 GtkWidget * statbox[NSTATBOXES];
13 
14 extern bool theevents_memory_limited;
15 extern std::vector<noeevent> theevents;
16 extern int gevi;
18 
19 extern bool ghave_read_all;
20 
21 // Maximum length of any string being printed to a status bar
22 static const int MAXSTATUS = 1024;
23 
24 // This hack allows us to get proper minus signs that look a lot better
25 // than the hyphens that printf puts out. I'm sure there's a better
26 // way to do this.
27 #define BOTANY_BAY_OH_NO(x) x < 0?"−":"", fabs(x)
28 #define BOTANY_BAY_OH_INT(x) x < 0?"−":"", abs((int)x)
29 
30 void set_status(const int boxn, const char * format, ...)
31 {
32  va_list ap;
33  va_start(ap, format);
34  static char buf[MAXSTATUS];
35  vsnprintf(buf, MAXSTATUS-1, format, ap);
36 
37  gtk_text_buffer_set_text(stattext[boxn], buf, strlen(buf));
38  gtk_text_view_set_buffer(GTK_TEXT_VIEW(statbox[boxn]), stattext[boxn]);
39  gtk_widget_draw(statbox[boxn], NULL);
40 }
41 
43 {
44  if(theevents.empty()){
45  set_status(statrunevent, "No events");
46  return;
47  }
48 
49  set_status(statrunevent, "Run %'d, subrun %d, event %'d "
50  "(%'d/%'d %s, %.0f%% loaded)",
51  theevents[gevi].nrun, theevents[gevi].nsubrun,
53  (int)theevents.capacity(),
54  theevents_memory_limited?"that fit in memory":"in the file(s)",
55  100*float(theevents.size())/theevents.capacity());
56 }
57 
59 {
60  noeevent & E = theevents[gevi];
61 
62  char status1[MAXSTATUS];
63 
64  int pos = snprintf(status1, MAXSTATUS, "Ticks %s%d through %d. ",
67  pos += snprintf(status1+pos, MAXSTATUS-pos,
68  "Showing ticks %s%d through %s%d (%s%.3f through %s%.3f μs)",
73  else
74  pos += snprintf(status1+pos, MAXSTATUS-pos,
75  "Showing tick %s%d (%s%.3f μs)",
78 
79  // If there are no hits, all of the above is nonsense, so overwrite it
80  if(theevents[gevi].hits.empty())
81  snprintf(status1, MAXSTATUS, "Empty event");
82 
83  set_status(stattiming, status1);
84 }
85 
87 {
88  if(active_plane < 0 || active_cell < 0){
89  set_status(stathit, "Mouse over a cell for more information");
90  return;
91  }
92 
93  char status2[MAXSTATUS];
94  int pos = snprintf(status2, MAXSTATUS, "Plane %d, cell %d: ",
96 
97  // TODO: display calibrated energies when possible
98  std::vector<hit> & THEhits = theevents[gevi].hits;
99  bool needseparator = false;
100 
101  // TODO: make this more flexible.
102  const int maxmatches = 3;
103  int matches = 0;
104  for(unsigned int i = 0; i < THEhits.size(); i++){
105  if(THEhits[i].plane == active_plane &&
106  THEhits[i].cell == active_cell &&
107  THEhits[i].tdc >= theevents[gevi].current_mintick &&
108  THEhits[i].tdc <= theevents[gevi].current_maxtick){
109  matches++;
110  if(matches <= maxmatches){
111  pos += pos >= MAXSTATUS?0:snprintf(status2+pos, MAXSTATUS-pos,
112  "%sTDC = %s%d (%s%.3f μs), TNS = %s%.3f μs%s, ADC = %s%d",
113  needseparator?"; ":"",
114  BOTANY_BAY_OH_INT(THEhits[i].tdc),
115  BOTANY_BAY_OH_NO (THEhits[i].tdc/64.),
116  BOTANY_BAY_OH_NO (THEhits[i].tns/1000),
117  THEhits[i].good_tns?"":"(bad)",
118  BOTANY_BAY_OH_INT(THEhits[i].adc));
119  needseparator = true;
120  }
121  else if(matches == maxmatches+1){
122  pos += pos >= MAXSTATUS?0:snprintf(status2+pos, MAXSTATUS-pos,
123  "; and more...");
124  }
125  }
126  }
127  set_status(stathit, status2);
128 }
129 
131 {
132  if(active_vertex < 0){
133  if(theevents[gevi].vertices.empty())
134  set_status(statvertex, "There are no vertices");
135  else
136  set_status(statvertex, "Mouse over a vertex for information on it");
137  return;
138  }
139 
140  if(theevents[gevi].vertices.empty()) return;
141 
142  char status[MAXSTATUS];
143  int pos = snprintf(status, MAXSTATUS, "Vertex %d\n", active_vertex);
144  pos += snprintf(status+pos, MAXSTATUS-pos, "at (%.1f, %.1f, %.1f)\n",
145  theevents[gevi].vertices[active_vertex].posx/10.,
146  theevents[gevi].vertices[active_vertex].posy/10.,
147  theevents[gevi].vertices[active_vertex].posz/10.);
148  pos += snprintf(status+pos, MAXSTATUS-pos, "time %.4f %c%cs",
149  theevents[gevi].vertices[active_vertex].tns/1000, 0xce, 0xbc);
150 
151  set_status(statvertex, status);
152 }
153 
155 {
156  if(active_track < 0){
157  if(theevents[gevi].tracks.empty())
158  set_status(stattrack, "There are no tracks");
159  else
160  set_status(stattrack, "Mouse over a track for information on it");
161  return;
162  }
163 
164  if(theevents[gevi].tracks.empty()) return;
165 
166  char status[MAXSTATUS];
167  int pos = snprintf(status, MAXSTATUS, "Track %d\n", active_track);
168  pos += snprintf(status+pos, MAXSTATUS-pos, "start (%.1f, %.1f, %.1f)\n"
169  "stop (%.1f, %.1f, %.1f)\n",
170  theevents[gevi].tracks[active_track].startx/10.,
171  theevents[gevi].tracks[active_track].starty/10.,
172  theevents[gevi].tracks[active_track].startz/10.,
173  theevents[gevi].tracks[active_track].stopx/10.,
174  theevents[gevi].tracks[active_track].stopy/10.,
175  theevents[gevi].tracks[active_track].stopz/10.);
176  pos += snprintf(status+pos, MAXSTATUS-pos, "time %.4f %c%cs",
177  theevents[gevi].tracks[active_track].tns/1000, 0xce, 0xbc);
178 
179  set_status(stattrack, status);
180 }
181 
182 void set_eventn_status_progress(const int nhit, const int tothits)
183 {
184  set_status(stathit, "Processing big event, %d/%d hits", nhit, tothits);
185 }
186 
188 {
190 
191  if(theevents.empty()) return;
192 
197 }
int active_cell
Definition: main.cxx:78
int32_t current_maxtick
Definition: event.h:69
int status
Definition: fabricate.py:1613
void set_eventn_status_progress(const int nhit, const int tothits)
Definition: status.cxx:182
int active_plane
Definition: main.cxx:78
static const int MAXSTATUS
Definition: status.cxx:22
Definition: event.h:41
nhit
Definition: demo1.py:25
int32_t current_mintick
Definition: event.h:69
int active_vertex
Definition: main.cxx:78
void set_eventn_status_vertex()
Definition: status.cxx:130
void hits()
Definition: readHits.C:15
int gevi
Definition: main.cxx:76
int32_t maxtick
Definition: event.h:48
void set_status(const int boxn, const char *format,...)
Definition: status.cxx:30
std::vector< noeevent > theevents
Definition: noe_module.cc:28
Float_t E
Definition: plot.C:20
GtkTextBuffer * stattext[NSTATBOXES]
Definition: status.cxx:11
std::string format(const int32_t &value, const int &ndigits=8)
Definition: HexUtils.cpp:14
Int_t nevent
Definition: macro.C:10
void set_eventn_status_runevent()
Definition: status.cxx:42
int active_track
Definition: main.cxx:78
void set_eventn_status_timing()
Definition: status.cxx:58
bool ghave_read_all
Definition: main.cxx:101
void set_eventn_status()
Definition: status.cxx:187
int32_t mintick
Definition: event.h:48
void set_eventn_status_hit()
Definition: status.cxx:86
GtkWidget * statbox[NSTATBOXES]
Definition: status.cxx:12
#define BOTANY_BAY_OH_NO(x)
Definition: status.cxx:27
#define BOTANY_BAY_OH_INT(x)
Definition: status.cxx:28
bool theevents_memory_limited
Definition: noe_module.cc:27
void set_eventn_status_track()
Definition: status.cxx:154
Definition: status.h:4