WatchListBox.cxx
Go to the documentation of this file.
2 #include <iostream>
3 #include "TGButton.h"
4 #include "TGListBox.h"
5 #include "TGText.h"
6 #include "TGFrame.h"
7 #include "TGComboBox.h"
8 #include "TGLabel.h"
9 #include "TGString.h"
10 #include "TList.h"
17 
18 using namespace om;
19 
20 WatchListBox::WatchListBox(const TGWindow* win,
21  unsigned int w,
22  unsigned int h,
23  unsigned int opt) :
24  TGCompositeFrame(win, w, h, opt),
26 {
27 
28  TGLayoutHints* xx = new TGLayoutHints(kLHintsExpandX);
29 
30  fHardwareFrame = new TGGroupFrame(this, "Choose Hardware");
31  this->LayoutHardwareFrame();
32  this->AddFrame(fHardwareFrame, xx);
33 
34  fCurrentListFrame = new TGGroupFrame(this, "Current WatchList:");
35  this->LayoutCurrentListFrame();
36  this->AddFrame(fCurrentListFrame, xx);
37 
38  fRemoveFromList = new TGTextButton(this, "Remove from WatchList");
39  fRemoveFromList->SetToolTipText("Remove the selected item from the WatchList");
40  fRemoveFromList->Connect("Clicked()",
41  "om::WatchListBox",
42  this,
43  "HandleRemoveFromList()");
44  this->AddFrame(fRemoveFromList, xx);
45 
46 }
47 
48 
49 
50 //......................................................................
51 
53 {
54 
55  ///\todo: add detectorID republish into everything that would change
56  // when the detector changes...
57 
58  TGCompositeFrame* fHWboxes = new TGCompositeFrame(fHardwareFrame,
59  300, 20,
60  kHorizontalFrame);
61  fDB = new TGComboBox(fHWboxes);
62  fDCM = new TGComboBox(fHWboxes);
63  fFEB = new TGComboBox(fHWboxes);
64  fPIX = new TGComboBox(fHWboxes);
65 
66  TGLayoutHints* yy = new TGLayoutHints(kLHintsNormal, 10, 0, 0, 0);
67  TGLayoutHints* zz = new TGLayoutHints(kLHintsNormal, 2, 0, 0, 0);
68 
69 
70 
71  // These numbers will be properly set in the GUIModelDataIssue function
72  // after the GUIModelData is properly initialized.
73  int numDB = 0;
74  int numDCM = 0;
75 
76  if(om::GUIModel::Instance().Data().fDetector == kNDOS) {
77  numDB = 1;
78  numDCM = 1;
79  }
80  else if(om::GUIModel::Instance().Data().fDetector == kNEARDET) {
81  numDB = 1;
82  numDCM = 1;
83  }
84  else if(om::GUIModel::Instance().Data().fDetector == kFARDET) {
85  numDB = 1;
86  numDCM = 1;
87  }
88  else if(om::GUIModel::Instance().Data().fDetector == kTESTBEAM) {
89  numDB = 1;
90  numDCM = 1;
91  }
92 
93  fDB->RemoveAll();
94  fHWboxes->AddFrame(fDB, zz);
95  fDB->AddEntry("ALL", 1);
96  for(int i = 1; i <= numDB; ++i) {
97  char entry[64];
98  sprintf(entry, "%.2u", i);
99  fDB->AddEntry(entry, i+1);
100  }
101  fDB->Resize(50, 20);
102 
103  fDCM->RemoveAll();
104  fHWboxes->AddFrame(fDCM, zz);
105  fDCM->AddEntry("ALL", 1);
106  for(int i = 1; i <= numDCM; ++i) {
107  char entry[64];
108  sprintf(entry, "%.2u", i);
109  fDCM->AddEntry(entry, i+1);
110  }
111  fDCM->Resize(50, 20);
112 
113  fFEB->RemoveAll();
114  fHWboxes->AddFrame(fFEB, zz);
115  fFEB->AddEntry("ALL", 1);
116  for(int i = 0; i < 64; ++i) {
117  char entry[64];
118  sprintf(entry, "%.2u", i);
119  fFEB->AddEntry(entry, i+2);
120  }
121  fFEB->Resize(50, 20);
122 
123  fPIX->RemoveAll();
124  fHWboxes->AddFrame(fPIX, zz);
125  fPIX->AddEntry("ALL", 1);
126  for(int i = 0; i < 32; ++i) {
127  char entry[64];
128  sprintf(entry, "%.2u", i);
129  fPIX->AddEntry(entry, i+2);
130  }
131  fPIX->Resize(50, 20);
132 
133  fAddToList = new TGTextButton(fHWboxes, "ADD");
134  fAddToList->SetToolTipText("Add the chosen hardware to the WatchList");
135  fAddToList->Connect("Clicked()",
136  "om::WatchListBox",
137  this,
138  "HandleAddToList()");
139  fHWboxes->AddFrame(fAddToList, yy);
140 
141  fHWlabel = new TGLabel(fHardwareFrame,
142  "Diblock - DCM - FEB - Pixel");
143  fHardwareFrame->AddFrame(fHWlabel, zz);
144  fHardwareFrame->AddFrame(fHWboxes, zz);
145 
146 }
147 
148 
149 
150 //......................................................................
151 
153 {
154 
155  TGLayoutHints* zz = new TGLayoutHints(kLHintsExpandX);
156 
157  fCurrentList = new TGListBox(fCurrentListFrame, kSunkenFrame);
158  fCurrentListFrame->AddFrame(fCurrentList, zz);
159  fCurrentList->Resize(100,300);
160 
161  fCurrentList->SetMultipleSelections();
162 
163 }
164 
165 
166 
167 //......................................................................
168 
170 {
171 
172  // GetSelected() returns:
173  //
174  // -1 = nothing selected
175  // 1 = first selection (for me this is ALL)
176  // 2 = second selection (etc...)
177 
178  // check for legit entries & pass info to GUIModelData
179  if(fDB ->GetSelected() < 1 || fDCM->GetSelected() < 1 ||
180  fFEB->GetSelected() < 1 || fPIX->GetSelected() < 1) {
181  om::cout << "You must make a selection in every hardware field!"
182  << "";
183  return;
184  }
185 
186  // We have good values to pass to GUIModel. Note: the first item in the ComboBox is
187  // "ALL" which is translated to -1 and the second item is 00, so we will subtract 2
188  // from the ComboBox value to get the number right. Diblocks and DCMs are different
189  // since they start at 01 (honestly, who came up with this numbering system???)
190  int DB = fDB->GetSelected();
191  if(fDB->GetSelected() == 1) DB = -1;
192  else DB = DB - 1;
193 
194  int DCM = fDCM->GetSelected();
195  if(fDCM->GetSelected() == 1) DCM = -1;
196  else DCM = DCM - 1;
197 
198  int FEB = fFEB->GetSelected()-2;
199  int PIX = fPIX->GetSelected()-2;
200 
201  // check to see that histo source is SHM
202  // if source is a root file, do nothing and return
203  std::string s(GUIModel::Instance().Data().fHistogramSource.c_str());
204  bool is_root = s.find(".root")<s.length();
205  bool is_shm = s.find(".shm")< s.length();
206 
207  if (is_root && is_shm) abort();
208  if (is_root) {
209  om::cout << "WatchList disabled (input source is not SHM.)";
210  this->UpdateHWboxes();
211  return;
212  }
213 
214  IPC ipc(kIPC_CLIENT, GUIModel::Instance().Data().fHistogramSource.c_str());
215 
216  ipc.RequestAddToWatchList(DB, DCM, FEB, PIX);
217 
219 
220  return;
221 }
222 
223 
224 
225 //......................................................................
226 
228 {
229 
230  // check to see that histo source is SHM
231  // if source is a root file, do nothing and return
232  std::string s(GUIModel::Instance().Data().fHistogramSource.c_str());
233  bool is_root = s.find(".root")<s.length();
234  bool is_shm = s.find(".shm")< s.length();
235 
236  if (is_root && is_shm) abort();
237  if (is_root) return;
238 
239  IPC ipc(kIPC_CLIENT, GUIModel::Instance().Data().fHistogramSource.c_str());
240 
241  TList* selected = new TList();
242  fCurrentList->GetSelectedEntries(selected);
243 
244  std::vector<unsigned int> rlist;
245 
246  for(int i = 0; i < selected->GetSize(); ++i) {
247  for(int j = 0; j < fCurrentList->GetNumberOfEntries(); ++j) {
248  if(fCurrentList->GetEntry(j) == selected->At(i)) rlist.push_back(j);
249  }
250  }
251 
252  for(unsigned int k = 0; k < rlist.size(); ++k) {
253  ipc.RequestRemoveFromWatchList(fCWLdb [rlist[k]], fCWLdcm[rlist[k]],
254  fCWLfeb[rlist[k]], fCWLpix[rlist[k]]);
255  }
256 
258 
259  return;
260 }
261 
262 
263 
264 //......................................................................
265 
267 {
268 
269  // check to see that histo source is SHM
270  // if source is a root file, do nothing and return
271  std::string s(GUIModel::Instance().Data().fHistogramSource.c_str());
272  bool is_root = s.find(".root")<s.length();
273  bool is_shm = s.find(".shm")< s.length();
274 
275  if (is_root && is_shm) abort();
276  if (is_root) return;
277 
278  IPC ipc(kIPC_CLIENT, GUIModel::Instance().Data().fHistogramSource.c_str());
279 
280  std::vector<int> db;
281  std::vector<int> dcm;
282  std::vector<int> feb;
283  std::vector<int> pix;
284 
285  ipc.RequestCurrentWatchList(db, dcm, feb, pix);
286 
287  fCWLdb .clear();
288  fCWLdcm.clear();
289  fCWLfeb.clear();
290  fCWLpix.clear();
291 
292  fCWLdb = db;
293  fCWLdcm = dcm;
294  fCWLfeb = feb;
295  fCWLpix = pix;
296 
297  // make the list of strings for displaying the current watchlist
298  fCurrentList->RemoveAll();
299  for(unsigned int i = 0; i < db.size(); ++i) {
300 
301  TGString label;
302 
303  if(db[i] < 0) label += "XX";
304  else {
305  char temp[64];
306  sprintf(temp, "%.2u", db[i]);
307  label += temp;
308  }
309  label += " - ";
310 
311  if(dcm[i] < 0) label += "XX";
312  else {
313  char temp[64];
314  sprintf(temp, "%.2u", dcm[i]);
315  label += temp;
316  }
317  label += " - ";
318 
319  if(feb[i] < 0) label += "XX";
320  else {
321  char temp[64];
322  sprintf(temp, "%.2u", feb[i]);
323  label += temp;
324  }
325  label += " - ";
326 
327  if(pix[i] < 0) label += "XX";
328  else {
329  char temp[64];
330  sprintf(temp, "%.2u", pix[i]);
331  label += temp;
332  }
333 
334  fCurrentList->AddEntry(label, i);
335  }
336 
337  fCurrentList->Layout();
338 
339 }
340 
341 
342 
343 //......................................................................
344 
346 {
347  int numDB = 0;
348  int numDCM = 0;
349 
350  if(om::GUIModel::Instance().Data().fDetector == kNDOS) {
351  numDB = 4;
352  numDCM = 3;
353  }
354  else if(om::GUIModel::Instance().Data().fDetector == kNEARDET) {
355  numDB = 4;
356  numDCM = 3;
357  }
358  else if(om::GUIModel::Instance().Data().fDetector == kFARDET) {
359  numDB = 14;
360  numDCM = 12;
361  }
362 
363  fDB->RemoveAll();
364  fDB->AddEntry("ALL", 1);
365  for(int i = 1; i <= numDB; ++i) {
366  char entry[64];
367  sprintf(entry, "%.2u", i);
368  fDB->AddEntry(entry, i+1);
369  }
370 
371  fDCM->RemoveAll();
372  fDCM->AddEntry("ALL", 1);
373  for(int i = 1; i <= numDCM; ++i) {
374  char entry[64];
375  sprintf(entry, "%.2u", i);
376  fDCM->AddEntry(entry, i+1);
377  }
378 
379  fFEB->RemoveAll();
380  fFEB->AddEntry("ALL", 1);
381  for(int i = 0; i < 64; ++i) {
382  char entry[64];
383  sprintf(entry, "%.2u", i);
384  fFEB->AddEntry(entry, i+2);
385  }
386 
387  fPIX->RemoveAll();
388  fPIX->AddEntry("ALL", 1);
389  for(int i = 0; i < 32; ++i) {
390  char entry[64];
391  sprintf(entry, "%.2u", i);
392  fPIX->AddEntry(entry, i+2);
393  }
394 }
395 
396 
397 
398 //......................................................................
399 
401  unsigned int which)
402 {
403  if (this->GetLock()==false) return;
404 
405  if((which&kDetectorID) != 0 || (which&kWatchListUpdateID) != 0) {
406  this->UpdateHWboxes();
407  } // end if (kGUIModelDataUpdateID or kWatchListUpdateID)
408 
409  if((which&kWatchListUpdateID) != 0 ||
410  (which&kHistogramSourceID) != 0) {
411  this->UpdateCurrentList();
412  } // end if (kWatchListUpdateID or kHistogramSourceID)
413 
414  this->ReleaseLock();
415 }
416 
417 //......................................................................
418 
419 
420 
422 {
423  if (fHardwareFrame) { delete fHardwareFrame; fHardwareFrame = 0; }
424  if (fHWlabel) { delete fHWlabel; fHWlabel = 0; }
425  if (fHWboxes) { delete fHWboxes; fHWboxes = 0; }
426  if (fDB) { delete fDB; fDB = 0; }
427  if (fDCM) { delete fDCM; fDCM = 0; }
428  if (fFEB) { delete fFEB; fFEB = 0; }
429  if (fPIX) { delete fPIX; fPIX = 0; }
430  if (fAddToList) { delete fAddToList; fAddToList = 0; }
432  if (fCurrentList) { delete fCurrentList; fCurrentList = 0; }
433  if (fRemoveFromList) { delete fRemoveFromList; fRemoveFromList = 0; }
434 }
435 
436 ////////////////////////////////////////////////////////////////////////
TGLabel * fHWlabel
Definition: WatchListBox.h:47
TGTextButton * fAddToList
Definition: WatchListBox.h:54
TGComboBox * fDCM
Definition: WatchListBox.h:51
Double_t xx
Definition: macro.C:12
void GUIModelDataIssue(const GUIModelData &m, unsigned int which)
int RequestAddToWatchList(int db, int dcm, int feb, int pix)
Definition: IPC.cxx:346
TGComboBox * fDB
Definition: WatchListBox.h:50
static const unsigned int kWatchListUpdateID
Definition: GUIModelData.h:26
Class to manage the shared memory segment.
WatchListBox(const TGWindow *win, unsigned int w, unsigned int h, unsigned int opt)
std::vector< int > fCWLfeb
Definition: WatchListBox.h:64
Double_t zz
Definition: plot.C:277
TGListBox * fCurrentList
Definition: WatchListBox.h:57
TGCompositeFrame * fHWboxes
Definition: WatchListBox.h:48
static const int kIPC_CLIENT
Definition: IPC.h:24
std::vector< int > fCWLdcm
Definition: WatchListBox.h:63
void LayoutHardwareFrame()
const char * label
TGGroupFrame * fCurrentListFrame
Definition: WatchListBox.h:56
Class to read, hold, and deliver histogram data.
const XML_Char * s
Definition: expat.h:262
static const unsigned int numDB
TGTextButton * fRemoveFromList
Definition: WatchListBox.h:59
static GUIModel & Instance()
Definition: GUIModel.cxx:11
const double j
Definition: BetheBloch.cxx:29
void LayoutCurrentListFrame()
TGComboBox * fPIX
Definition: WatchListBox.h:53
OStream cout
Definition: OStream.cxx:6
std::vector< int > fCWLdb
Definition: WatchListBox.h:62
static const unsigned int kHistogramSourceID
Definition: GUIModelData.h:22
::xsd::cxx::tree::string< char, simple_type > string
Definition: Database.h:154
Definition: IPC.h:29
TGGroupFrame * fHardwareFrame
Definition: WatchListBox.h:46
void HandleRemoveFromList()
void SendWatchListUpdate()
Definition: GUIModel.cxx:189
std::vector< int > fCWLpix
Definition: WatchListBox.h:65
Float_t w
Definition: plot.C:20
def entry(str)
Definition: HTMLTools.py:26
static const unsigned int kDetectorID
Definition: GUIModelData.h:25
TGComboBox * fFEB
Definition: WatchListBox.h:52
Online Monitoring package header.