pxar
 All Classes Namespaces Functions Variables Typedefs Friends
PixParTab.cc
1 #include <iostream>
2 #include <cstdlib>
3 #include <bitset>
4 
5 #include <TApplication.h>
6 #include <TGButton.h>
7 #include <TGToolTip.h>
8 #include <TRandom.h>
9 #include <TSystem.h>
10 #include <TCanvas.h>
11 #include <TGTab.h>
12 #include <TGLabel.h>
13 #include <TGButtonGroup.h>
14 #include <TGTableLayout.h>
15 #include <cstdlib>
16 
17 #include "PixParTab.hh"
18 #include "log.h"
19 
20 using namespace std;
21 using namespace pxar;
22 
23 ClassImp(PixParTab)
24 
25 // ----------------------------------------------------------------------
26 PixParTab::PixParTab(PixGui *p, ConfigParameters *cfg, string tabname) {
27  init(p, cfg, tabname);
28 
29  fLockClk = true;
30 
31  fBorderR = fBorderL = fBorderT = fBorderB = 2;
32 
33  fTabFrame = fGui->getTabs()->AddTab(fTabName.c_str());
34  fTabFrame->SetLayoutManager(new TGVerticalLayout(fTabFrame));
35 
36 
37  UInt_t w = fGui->getTabs()->GetWidth();
38  UInt_t h = fGui->getTabs()->GetHeight();
39 
40  fhFrame = new TGCompositeFrame(fTabFrame, w, h, kHorizontalFrame);
41  fTabFrame->AddFrame(fhFrame, new TGLayoutHints(kLHintsRight | kLHintsExpandX | kLHintsExpandY, fBorderL, fBorderR, fBorderT, fBorderB));
42 
43  TGTabElement *tabel = fGui->getTabs()->GetTabTab(fTabName.c_str());
44  tabel->ChangeBackground(fGui->fDarkSeaGreen);
45 
46  TGTextEntry *te(0);
47  TGLabel *tl(0);
48  TGTextBuffer *tb(0);
49  TGTextButton *tset(0);
50 
51  TGCheckButton *tcb(0);
52  TGHorizontalFrame *hFrame(0);
53  TGVerticalFrame *vFrame(0);
54  TGGroupFrame *g1Frame(0), *g2Frame(0);
55 
56  // -- TB Parameters
57  vFrame = new TGVerticalFrame(fhFrame);
58  fhFrame->AddFrame(vFrame, new TGLayoutHints(kLHintsLeft, fBorderL, fBorderR, fBorderT, fBorderB));
59  g1Frame = new TGGroupFrame(vFrame, "Testboard");
60  vFrame->AddFrame(g1Frame);
61 
62  g1Frame->AddFrame(hFrame = new TGHorizontalFrame(g1Frame, 300, 30, kLHintsExpandX), new TGLayoutHints(kLHintsRight | kLHintsTop));
63  tcb = new TGCheckButton(hFrame, "lock parameters to clk");
64  tcb->Connect("Clicked()", "PixParTab", this, "lockClk()");
65  tcb->SetToolTipText("Enforce the relations ctr = clk; sda = clk+15; tin = clk+5");
66  tcb->GetToolTip()->SetDelay(2000); // add a bit of delay to ease button hitting
67  tcb->SetState(kButtonDown);
68  hFrame->AddFrame(tcb, new TGLayoutHints(kLHintsCenterY | kLHintsRight, fBorderL, fBorderR, fBorderT, fBorderB));
69 
70  vector<pair<string, uint8_t> > amap = fConfigParameters->getTbParameters();
71  for (unsigned int i = 0; i < amap.size(); ++i) {
72  hFrame = new TGHorizontalFrame(g1Frame, 300, 30, kLHintsExpandX);
73  g1Frame->AddFrame(hFrame, new TGLayoutHints(kLHintsRight | kLHintsTop));
74  tl = new TGLabel(hFrame, amap[i].first.c_str());
75  tl->SetWidth(100);
76  hFrame->AddFrame(tl, new TGLayoutHints(kLHintsCenterY | kLHintsLeft, fBorderL, fBorderR, fBorderT, 0));
77 
78  tb = new TGTextBuffer(5);
79  te = new TGTextEntry(hFrame, tb, i); te->SetWidth(100);
80  hFrame->AddFrame(te, new TGLayoutHints(kLHintsCenterY | kLHintsCenterX, fBorderL, fBorderR, fBorderT, 0));
81  fTbParIds.push_back(amap[i].first);
82  fTbTextEntries.insert(make_pair(amap[i].first, te));
83 
84  te->SetText(Form("%d", int(amap[i].second)));
85  te->Connect("ReturnPressed()", "PixParTab", this, "setTbParameter()");
86  te->Connect("TextChanged(const char *)", "PixParTab", this, "tbYellow()");
87 
88  tset = new TGTextButton(hFrame, "Set", i);
89  tset->SetToolTipText("set the parameter\nor click *return* after changing the numerical value");
90  tset->GetToolTip()->SetDelay(2000); // add a bit of delay to ease button hitting
91  tset->Connect("Clicked()", "PixParTab", this, "setTbParameter()");
92  hFrame->AddFrame(tset, new TGLayoutHints(kLHintsCenterY | kLHintsLeft, fBorderL, fBorderR, fBorderT, 0));
93  }
94 
95  vector<pair<string, double> > dmap = fConfigParameters->getTbPowerSettings();
96  for (unsigned int i = 0; i < dmap.size(); ++i) {
97  hFrame = new TGHorizontalFrame(g1Frame, 300, 30, kLHintsExpandX);
98  g1Frame->AddFrame(hFrame, new TGLayoutHints(kLHintsRight | kLHintsTop));
99  tb = new TGTextBuffer(5);
100  tl = new TGLabel(hFrame, dmap[i].first.c_str());
101  hFrame->AddFrame(tl, new TGLayoutHints(kLHintsCenterY | kLHintsLeft, fBorderL, fBorderR, fBorderT, 0));
102  tl->SetWidth(100);
103 
104  te = new TGTextEntry(hFrame, tb, i); te->SetWidth(100);
105  hFrame->AddFrame(te, new TGLayoutHints(kLHintsCenterY | kLHintsCenterX, fBorderL, fBorderR, fBorderT, 0));
106  fPowerParIds.push_back(dmap[i].first);
107  fPowerTextEntries.insert(make_pair(dmap[i].first, te));
108 
109  te->SetText(Form("%5.3f", float(dmap[i].second)));
110  te->Connect("ReturnPressed()", "PixParTab", this, "setPowerSettings()");
111  te->Connect("TextChanged(const char *)", "PixParTab", this, "powerYellow()");
112 
113  tset = new TGTextButton(hFrame, "Set", i);
114  hFrame->AddFrame(tset, new TGLayoutHints(kLHintsCenterY | kLHintsLeft, fBorderL, fBorderR, fBorderT, 0));
115  tset->SetToolTipText("set the parameter\nor click *return* after changing the numerical value");
116  tset->GetToolTip()->SetDelay(2000); // add a bit of delay to ease button hitting
117  tset->Connect("Clicked()", "PixParTab", this, "setPowerSettings()");
118  }
119 
120  tset = new TGTextButton(g1Frame, "Save Parameters");
121  g1Frame->AddFrame(tset, new TGLayoutHints(kLHintsBottom|kLHintsRight, fBorderL, fBorderR, fBorderT, 0));
122  tset->SetToolTipText(Form("Write the testboard parameters to file.\nThe output file will overwrite whatever is in the directory \"%s\"\n(change this in the top right part of the GUI)", fConfigParameters->getDirectory().c_str()));
123  tset->Connect("Clicked()", "PixParTab", this, "saveTbParameters()");
124 
125  // -- TBM Parameters
126  TGCompositeFrame *bGroup = new TGCompositeFrame(vFrame, 60, 20, kHorizontalFrame |kSunkenFrame);
127  vFrame->AddFrame(bGroup, new TGLayoutHints(kLHintsCenterX|kLHintsCenterY, fBorderL, fBorderR, fBorderT, fBorderB));
128  vector<vector<pair<string, uint8_t> > > cmap;
129  for (unsigned int i = 0; i < fGui->getApi()->_dut->getNTbms(); ++i) {
130  tcb = new TGCheckButton(bGroup, Form("%d", i), i);
131  tcb->Connect("Clicked()", "PixParTab", this, "selectTbm()");
132  bGroup->AddFrame(tcb, new TGLayoutHints(kLHintsLeft, fBorderL, fBorderR, fBorderT, 0));
133  fSelectTbm.push_back(tcb);
134  vector<pair<string, uint8_t> > smap = fGui->getApi()->_dut->getTbmDACs(i);
135  cmap.push_back(smap);
136  }
137  if (fSelectTbm.size() > 0) {
138  fSelectedTbm = 0;
139  // -- by default enable all present
140  for (unsigned itbm = 0; itbm < fSelectTbm.size(); ++itbm) {
141  fSelectTbm[itbm]->SetState(kButtonDown);
142  }
143  }
144 
145  tset = new TGTextButton(bGroup, "Save");
146  bGroup->AddFrame(tset, new TGLayoutHints(kLHintsCenterX|kLHintsCenterY, fBorderL, fBorderR, fBorderT, fBorderB));
147  tset->SetToolTipText(Form("Write the TBM parameters of all selected TBMs to file.\nThe output file will overwrite whatever is in the directory \"%s\"\n(change this in the top right part of the GUI)", fConfigParameters->getDirectory().c_str()));
148  tset->Connect("Clicked()", "PixParTab", this, "saveTbmParameters()");
149 
150  updateSelection();
151 
152  g2Frame = new TGGroupFrame(vFrame, "DAC of first selected TBM");
153  vFrame->AddFrame(g2Frame, new TGLayoutHints(kLHintsRight, fBorderL, fBorderR, fBorderT, 0));
154 
155  if (cmap.size() > 0) {
156  unsigned int firsttbm(0);
157  for (unsigned int i = 0; i < fSelectTbm.size(); ++i) {
158  if (kButtonDown == fSelectTbm[i]->GetState()) {
159  firsttbm = i;
160  break;
161  }
162  }
163 
164  for (unsigned int itbm = 0; itbm < fGui->getApi()->_dut->getNTbms(); ++itbm) {
165  map<string, uint8_t> parids;
166  amap = cmap[itbm];
167 
168  for (unsigned int i = 0; i < amap.size(); ++i) {
169  if (static_cast<unsigned int>(itbm) == firsttbm) {
170  hFrame = new TGHorizontalFrame(g2Frame, 300, 30, kLHintsExpandX);
171  g2Frame->AddFrame(hFrame, new TGLayoutHints(kLHintsRight | kLHintsTop));
172  tb = new TGTextBuffer(5);
173  tl = new TGLabel(hFrame, amap[i].first.c_str());
174  hFrame->AddFrame(tl, new TGLayoutHints(kLHintsCenterY | kLHintsLeft, fBorderL, fBorderR, fBorderT, 0));
175  tl->SetWidth(100);
176 
177  te = new TGTextEntry(hFrame, tb, i); te->SetWidth(70);
178  te->SetToolTipText("note that the numbers are in binary format (in case this is not obvious)");
179  hFrame->AddFrame(te, new TGLayoutHints(kLHintsCenterY | kLHintsCenterX, fBorderL, fBorderR, fBorderT, 0));
180  std::bitset<8> bits(amap[i].second);
181  te->SetText(Form("%s", bits.to_string().c_str()));
182  te->Connect("ReturnPressed()", "PixParTab", this, "setTbmParameter()");
183  te->Connect("TextChanged(const char *)", "PixParTab", this, "tbmYellow()");
184 
185  tset = new TGTextButton(hFrame, "Set", i);
186  tset->SetToolTipText("set the parameter\nor click *return* after changing the numerical value");
187  tset->GetToolTip()->SetDelay(2000); // add a bit of delay to ease button hitting
188  tset->Connect("Clicked()", "PixParTab", this, "setTbmParameter()");
189  hFrame->AddFrame(tset, new TGLayoutHints(kLHintsCenterY | kLHintsLeft, fBorderL, fBorderR, fBorderT, 0));
190  }
191  parids.insert(make_pair(amap[i].first, amap[i].second));
192  fTbmTextEntries.insert(make_pair(amap[i].first, te));
193  fTbmTextMap.insert(make_pair(i, amap[i].first));
194 
195  }
196  fTbmParIds.push_back(parids);
197  // vFrame->AddFrame(g2Frame);
198  g2Frame->SetWidth(g2Frame->GetDefaultWidth());
199  }
200 
201  }
202 
203  // -----------------
204  // -- DAC Parameters
205  // -----------------
206  g1Frame = new TGGroupFrame(fhFrame, "ROCs");
207  fhFrame->AddFrame(g1Frame);
208 
209  vFrame = new TGVerticalFrame(g1Frame);
210  g1Frame->AddFrame(vFrame, new TGLayoutHints(kLHintsLeft, fBorderL, fBorderR, fBorderT, fBorderB));
211 
212  TGHorizontalFrame *h1Frame = new TGHorizontalFrame(vFrame, 300, 30, kLHintsExpandX);
213  vFrame->AddFrame(h1Frame);
214 
215  h1Frame->AddFrame(tset = new TGTextButton(h1Frame, "Select all", B_SELECTALL),
216  new TGLayoutHints(kLHintsLeft, fBorderL, fBorderR, fBorderT, fBorderB));
217  tset->SetToolTipText("Select all ROCs");
218  tset->Connect("Clicked()", "PixParTab", this, "handleButtons()");
219  h1Frame->AddFrame(tset = new TGTextButton(h1Frame, "Deselect all", B_DESELECTALL),
220  new TGLayoutHints(kLHintsLeft, fBorderL, fBorderR, fBorderT, fBorderB));
221  tset->SetToolTipText("Deselect all ROCs");
222  tset->Connect("Clicked()", "PixParTab", this, "handleButtons()");
223 
224  h1Frame->AddFrame(tset = new TGTextButton(h1Frame, "Set DAC for ROC"),
225  new TGLayoutHints(kLHintsLeft, fBorderL, fBorderR, fBorderT, fBorderB));
226  tset->SetToolTipText("Change a DAC for one ROC and set this value for this ROC");
227  tset->Connect("Clicked()", "PixParTab", this, "setOneRocParameter()");
228  h1Frame->AddFrame(tset = new TGTextButton(h1Frame, "Set DAC for all ROCs"),
229  new TGLayoutHints(kLHintsLeft, fBorderL, fBorderR, fBorderT, fBorderB));
230  tset->SetToolTipText("Change a DAC for one ROC and set this value for all ROCs");
231  tset->Connect("Clicked()", "PixParTab", this, "setAllRocParameter()");
232 
233  h1Frame->AddFrame(tset = new TGTextButton(h1Frame, "Save DAC"),
234  new TGLayoutHints(kLHintsLeft, fBorderL, fBorderR, fBorderT, fBorderB));
235  tset->SetToolTipText(Form("Write the DAC parameters of all selected ROCs to file\n(also the DACs of the righthand box will be written).\nThe output file will overwrite whatever is in the directory \"%s\"\n(change this in the top right part of the GUI)", fConfigParameters->getDirectory().c_str()));
236  tset->Connect("Clicked()", "PixParTab", this, "saveDacParameters()");
237 
238 
239  h1Frame->AddFrame(tset = new TGTextButton(h1Frame, "Save Trim"),
240  new TGLayoutHints(kLHintsLeft, fBorderL, fBorderR, fBorderT, fBorderB));
241  tset->SetToolTipText(Form("Write the trim parameters of all selected ROCs to file.\nThe output file will overwrite whatever is in the directory \"%s\"\n(change this in the top right part of the GUI)", fConfigParameters->getDirectory().c_str()));
242  tset->Connect("Clicked()", "PixParTab", this, "saveTrimParameters()");
243 
244 
245  cmap.clear();
246  for (unsigned int i = 0; i < fGui->getApi()->_dut->getNRocs(); ++i) {
247  vector<pair<string, uint8_t> > smap = fGui->getApi()->_dut->getDACs(i);
248  cmap.push_back(smap);
249  }
250  updateSelection();
251 
252  if (cmap.size() > 0) {
253 
254  TGCompositeFrame *cFrame = new TGCompositeFrame(vFrame, 300, 30, kLHintsExpandX);
255  vFrame->AddFrame(cFrame);
256  cFrame->SetLayoutManager(new TGTableLayout(cFrame, cmap[0].size()+1, cmap.size()+1, 0, 0));
257 
258  // leftmost column with DAC names
259  amap = cmap[0];
260  for (unsigned int idac = 0; idac < amap.size(); ++idac) {
261  cFrame->AddFrame(tl = new TGLabel(cFrame, amap[idac].first.c_str()),
262  new TGTableLayoutHints(0, 1, idac+1, idac+2, kLHintsCenterX|kLHintsExpandX|kLHintsShrinkX|kLHintsFillX));
263  }
264 
265 
266  for (unsigned int iroc = 0; iroc < fGui->getApi()->_dut->getNRocs(); ++iroc) {
267  map<string, TGTextEntry*> rocTextEntries;
268  amap = cmap[iroc];
269  // ROC ID
270  cFrame->AddFrame(tcb = new TGCheckButton(cFrame, "XX"),
271  new TGTableLayoutHints(iroc+1, iroc+2, 0, 1, kFixedWidth));
272  tcb->SetText(Form((iroc>10?"%d":" %d"), iroc));
273  tcb->Connect("Clicked()", "PixParTab", this, "selectRoc()");
274  fSelectRoc.push_back(tcb);
275 
276 
277  // DACs
278  for (unsigned int idac = 0; idac < amap.size(); ++idac) {
279  cFrame->AddFrame(te = new TGTextEntry(cFrame, tb = new TGTextBuffer(3), idac),
280  new TGTableLayoutHints(iroc+1, iroc+2, idac+1, idac+2, kLHintsExpandX|kLHintsShrinkX|kLHintsFillX));
281  te->SetAlignment(kTextRight);
282  te->SetName(amap[idac].first.c_str());
283  te->SetWidth(30);
284  te->SetText(Form("%3d", int(amap[idac].second)));
285  te->Connect("ReturnPressed()", "PixParTab", this, "setOneRocParameter()");
286  te->Connect("TextChanged(const char *)", "PixParTab", this, "rocYellow()");
287 
288  rocTextEntries.insert(make_pair(amap[idac].first, te));
289  }
290  fRocTextEntries.push_back(rocTextEntries);
291  }
292 
293 
294  // -- by default enable all present
295  if (fSelectRoc.size() > 0) {
296  for (unsigned iroc = 0; iroc < fSelectRoc.size(); ++iroc) {
297  fSelectRoc[iroc]->SetState(kButtonDown);
298  }
299  }
300 
301 
302 
303 
304 
305  /*
306  h1Frame = new TGHorizontalFrame(vFrame, 300, 30, kLHintsExpandX);
307  vFrame->AddFrame(h1Frame, new TGLayoutHints(kLHintsBottom, fBorderL, fBorderR, fBorderT, fBorderB));
308 
309  TGVerticalFrame *v1Frame(0);
310  h1Frame->AddFrame(v1Frame = new TGVerticalFrame(h1Frame),
311  new TGLayoutHints(kLHintsLeft, fBorderL, fBorderR, fBorderT, fBorderB));
312 
313  // -- left column with DAC names
314  amap = cmap[0];
315  hFrame = new TGHorizontalFrame(v1Frame, 300, 30, kLHintsExpandX);
316  v1Frame->AddFrame(hFrame, new TGLayoutHints(kLHintsRight | kLHintsTop));
317  tl = new TGLabel(hFrame, " ");
318  hFrame->AddFrame(tl, new TGLayoutHints(kLHintsCenterY | kLHintsLeft, fBorderL, fBorderR, fBorderT, fBorderB));
319  for (unsigned int idac = 0; idac < amap.size(); ++idac) {
320  v1Frame->AddFrame(hFrame = new TGHorizontalFrame(v1Frame, 300, 25, kFixedHeight),
321  new TGLayoutHints(kLHintsRight|kLHintsCenterY));
322  hFrame->AddFrame(tl = new TGLabel(hFrame, amap[idac].first.c_str()),
323  new TGLayoutHints(kLHintsRight|kLHintsCenterY));
324  }
325 
326 
327  // -- one column per ROC
328  for (unsigned int iroc = 0; iroc < fGui->getApi()->_dut->getNRocs(); ++iroc) {
329  map<string, TGTextEntry*> rocTextEntries;
330  amap = cmap[iroc];
331  h1Frame->AddFrame(v1Frame = new TGVerticalFrame(h1Frame),
332  new TGLayoutHints(kLHintsLeft, fBorderL, fBorderR, fBorderT, fBorderB));
333  // ROC ID
334  v1Frame->AddFrame(hFrame = new TGHorizontalFrame(v1Frame, 300, 26, kLHintsExpandX),
335  new TGLayoutHints(kLHintsCenterY|kLHintsRight|kLHintsTop));
336 
337  hFrame->AddFrame(tcb = new TGCheckButton(hFrame, Form("%d", iroc)),
338  new TGLayoutHints(kLHintsCenterY|kLHintsRight, fBorderL, fBorderR, fBorderT, fBorderB));
339  tcb->Connect("Clicked()", "PixParTab", this, "selectRoc()");
340  fSelectRoc.push_back(tcb);
341 
342  // DACs
343  for (unsigned int idac = 0; idac < amap.size(); ++idac) {
344  v1Frame->AddFrame(hFrame = new TGHorizontalFrame(v1Frame, 300, 10),
345  new TGLayoutHints(kLHintsRight | kLHintsTop));
346  hFrame->AddFrame(te = new TGTextEntry(hFrame, tb = new TGTextBuffer(3), idac),
347  new TGLayoutHints(kLHintsCenterY|kLHintsRight, fBorderL, fBorderR, fBorderT, fBorderB));
348  te->SetAlignment(kTextRight);
349  te->SetName(amap[idac].first.c_str());
350  te->SetWidth(30);
351  te->SetText(Form("%3d", int(amap[idac].second)));
352  te->Connect("ReturnPressed()", "PixParTab", this, "setOneRocParameter()");
353  te->Connect("TextChanged(const char *)", "PixParTab", this, "rocYellow()");
354 
355  rocTextEntries.insert(make_pair(amap[idac].first, te));
356  }
357  fRocTextEntries.push_back(rocTextEntries);
358  }
359 
360  // -- by default enable all present
361  if (fSelectRoc.size() > 0) {
362  for (unsigned iroc = 0; iroc < fSelectRoc.size(); ++iroc) {
363  fSelectRoc[iroc]->SetState(kButtonDown);
364  }
365  }
366 
367 
368  */
369  }
370 
371 
372  fTabFrame->Layout();
373  fTabFrame->MapSubwindows();
374  fTabFrame->Resize(fTabFrame->GetDefaultSize());
375  fTabFrame->MapWindow();
376 
377 }
378 
379 
380 // ----------------------------------------------------------------------
381 PixParTab::PixParTab() {
382  init(0, 0, "nada");
383 }
384 
385 // ----------------------------------------------------------------------
386 void PixParTab::init(PixGui *p, ConfigParameters *cfg, std::string tabname) {
387  fGui = p;
388  fConfigParameters = cfg;
389  fTabName = tabname;
390 }
391 
392 // ----------------------------------------------------------------------
393 PixParTab::~PixParTab() {
394  LOG(logDEBUG) << "PixParTab destructor";
395 }
396 
397 
398 // ----------------------------------------------------------------------
399 void PixParTab::handleButtons(Int_t id) {
400 
401  if (!fGui->getTabs()) return;
402 
403  if (id == -1) {
404  TGButton *btn = (TGButton*)gTQSender;
405  id = btn->WidgetId();
406  }
407 
408  switch (id) {
409  case B_SELECTALL: {
410  LOG(logDEBUG) << "SELECT ALL";
411  for (unsigned int i = 0; i < fSelectRoc.size(); ++i) {
412  fSelectRoc[i]->SetState(kButtonDown);
413  }
414  updateSelection();
415  break;
416  }
417 
418  case B_DESELECTALL: {
419  LOG(logDEBUG) << "DESELECT ALL";
420  for (unsigned int i = 0; i < fSelectRoc.size(); ++i) {
421  fSelectRoc[i]->SetState(kButtonUp);
422  }
423  updateSelection();
424  break;
425  }
426 
427  }
428 }
429 
430 
431 // ----------------------------------------------------------------------
432 void PixParTab::setTbParameter() {
433  if (!fGui->getTabs()) return;
434 
435  TGButton *btn = (TGButton *) gTQSender;
436  int id(-1);
437  id = btn->WidgetId();
438  if (-1 == id) {
439  LOG(logDEBUG) << "ASLFDKHAPIUDF ";
440  return;
441  }
442 
443  string svalue = ((TGTextEntry*)(fTbTextEntries[fTbParIds[id]]))->GetText();
444  uint8_t udac = atoi(svalue.c_str());
445 
446  // -- enforce: ctr = clk; sda = clk + 15; tin = clk + 5;
447  if (fLockClk && (
448  (fTbParIds[id] == "clk")
449  || (fTbParIds[id] == "ctr")
450  || (fTbParIds[id] == "sda")
451  || (fTbParIds[id] == "tin")
452  )
453  ) {
454  int clk(0);
455  if (fTbParIds[id] == "clk") {
456  clk = atoi(((TGTextEntry*)(fTbTextEntries[fTbParIds[id]]))->GetText());
457  } else if (fTbParIds[id] == "ctr") {
458  clk = atoi(((TGTextEntry*)(fTbTextEntries[fTbParIds[id]]))->GetText());
459  } else if (fTbParIds[id] == "sda") {
460  clk = atoi(((TGTextEntry*)(fTbTextEntries[fTbParIds[id]]))->GetText()) - 15;
461  } else if (fTbParIds[id] == "tin") {
462  clk = atoi(((TGTextEntry*)(fTbTextEntries[fTbParIds[id]]))->GetText()) - 5;
463  }
464 
465  if (clk < 0) clk += 20;
466 
467  if (svalue != "clk") {
468  LOG(logDEBUG) << "PixParTab::setTbParameter: " << "clk" << ": " << int(clk);
469  fConfigParameters->setTbParameter("clk", clk);
470  ((TGTextEntry*)(fTbTextEntries["clk"]))->SetText(Form("%d", clk));
471  ((TGTextEntry*)(fTbTextEntries["clk"]))->SetBackgroundColor(fGui->fWhite);
472  }
473  if (svalue != "ctr") {
474  LOG(logDEBUG) << "PixParTab::setTbParameter: " << "ctr" << ": " << int(clk);
475  fConfigParameters->setTbParameter("ctr", clk);
476  ((TGTextEntry*)(fTbTextEntries["ctr"]))->SetText(Form("%d", clk));
477  ((TGTextEntry*)(fTbTextEntries["ctr"]))->SetBackgroundColor(fGui->fWhite);
478  }
479  if (svalue != "sda") {
480  LOG(logDEBUG) << "PixParTab::setTbParameter: " << "sda" << ": " << int(clk+15);
481  fConfigParameters->setTbParameter("sda", clk+15);
482  ((TGTextEntry*)(fTbTextEntries["sda"]))->SetText(Form("%d", clk+15));
483  ((TGTextEntry*)(fTbTextEntries["sda"]))->SetBackgroundColor(fGui->fWhite);
484  }
485  if (svalue != "tin") {
486  LOG(logDEBUG) << "PixParTab::setTbParameter: " << "tin" << ": " << int(clk+5);
487  fConfigParameters->setTbParameter("tin", clk+5);
488  ((TGTextEntry*)(fTbTextEntries["tin"]))->SetText(Form("%d", clk+5));
489  ((TGTextEntry*)(fTbTextEntries["tin"]))->SetBackgroundColor(fGui->fWhite);
490  }
491  } else {
492  LOG(logDEBUG) << "PixParTab::setTbParameter: " << fTbParIds[id] << ": " << int(udac);
493  fConfigParameters->setTbParameter(fTbParIds[id], udac);
494  ((TGTextEntry*)(fTbTextEntries[fTbParIds[id]]))->SetBackgroundColor(fGui->fWhite);
495  }
496 
497 
498  initTestboard();
499 }
500 
501 
502 // ----------------------------------------------------------------------
503 void PixParTab::tbYellow() {
504  if (!fGui->getTabs()) return;
505 
506  TGButton *btn = (TGButton *) gTQSender;
507  int id(-1);
508  id = btn->WidgetId();
509  if (-1 == id) {
510  LOG(logDEBUG) << "ASLFDKHAPIUDF ";
511  return;
512  }
513 
514  ((TGTextEntry*)(fTbTextEntries[fTbParIds[id]]))->SetBackgroundColor(fGui->fYellow);
515 
516 }
517 
518 
519 // ----------------------------------------------------------------------
520 void PixParTab::setPgSettings() {
521  if (!fGui->getTabs()) return;
522 
523  TGButton *btn = (TGButton *) gTQSender;
524  int id(-1);
525  id = btn->WidgetId();
526  if (-1 == id) {
527  LOG(logDEBUG) << "ASLFDKHAPIUDF ";
528  return;
529  }
530 
531  // FIXME: currently not controllable from gui
532  initTestboard();
533 
534 }
535 
536 
537 // ----------------------------------------------------------------------
538 void PixParTab::setPowerSettings() {
539  if (!fGui->getTabs()) return;
540 
541  TGButton *btn = (TGButton *) gTQSender;
542  int id(-1);
543  id = btn->WidgetId();
544  if (-1 == id) {
545  LOG(logDEBUG) << "ASLFDKHAPIUDF ";
546  return;
547  }
548 
549  string svalue = ((TGTextEntry*)(fPowerTextEntries[fPowerParIds[id]]))->GetText();
550  double udac = atof(svalue.c_str());
551 
552  LOG(logDEBUG) << "PixParTab::setPowerSettings: " << fPowerParIds[id] << ": " << udac;
553  fConfigParameters->setTbPowerSettings(fPowerParIds[id], udac);
554  ((TGTextEntry*)(fPowerTextEntries[fPowerParIds[id]]))->SetBackgroundColor(fGui->fWhite);
555  initTestboard();
556 
557 }
558 
559 
560 // ----------------------------------------------------------------------
561 void PixParTab::powerYellow() {
562  TGButton *btn = (TGButton *) gTQSender;
563  int id(-1);
564  id = btn->WidgetId();
565  if (-1 == id) {
566  LOG(logDEBUG) << "ASLFDKHAPIUDF ";
567  return;
568  }
569 
570  ((TGTextEntry*)(fPowerTextEntries[fPowerParIds[id]]))->SetBackgroundColor(fGui->fYellow);
571 }
572 
573 
574 // ----------------------------------------------------------------------
575 void PixParTab::initTestboard() {
576 
577  vector<pair<string, uint8_t> > sig_delays = fConfigParameters->getTbSigDelays();
578  vector<pair<string, double> > power_settings = fConfigParameters->getTbPowerSettings();
579  vector<pair<std::string, uint8_t> > pg_setup = fConfigParameters->getTbPgSettings();;
580 
581  fGui->getApi()->initTestboard(sig_delays, power_settings, pg_setup);
582 
583 }
584 
585 
586 // ----------------------------------------------------------------------
587 void PixParTab::setTbmParameter() {
588  if (!fGui->getTabs()) return;
589  LOG(logDEBUG) << "PixParTab::setTbmParameter: ";
590 
591  TGButton *btn = (TGButton *) gTQSender;
592  int id(-1);
593  id = btn->WidgetId();
594  if (-1 == id) {
595  LOG(logDEBUG) << "ASLFDKHAPIUDF ";
596  return;
597  }
598 
599  string sdac = fTbmTextMap[id];
600  string sval = fTbmTextEntries[sdac]->GetText();
601  // uint8_t udac = atoi(sval.c_str());
602  bitset<8> bits(sval);
603  uint8_t udac = static_cast<uint8_t>(bits.to_ulong());
604 
605  int itbm(-1);
606  for (unsigned int i = 0; i < fSelectTbm.size(); ++i) {
607  if (kButtonDown == fSelectTbm[i]->GetState()) {
608  itbm = i;
609  LOG(logDEBUG) << "TBM " << itbm << " is selected. id = " << id;
610  fTbmParIds[itbm][sdac] = udac;
611  LOG(logDEBUG)<< "xxx: ID = " << id << " TBM = " << itbm
612  << " -> " << sdac << " set to int(udac) = " << int(udac);
613  fGui->getApi()->setTbmReg(sdac, udac, itbm);
614  // if (sdac == "basee") {
615  // LOG(logDEBUG)<< "send reset to TBM because of phase adjustment";
616  // fGui->getApi()->setTbmReg("base4", 0x80, itbm);
617  // }
618  //PixTestCmd: tbmset("base4", 2, 0x80);// reset once after changing phases
619  //int CmdProc::tbmset(string name, uint8_t cores, int value, uint8_t valueMask)
620  // fApi->setTbmReg( name, update, core );
621 
622  fTbmTextEntries[sdac]->SetBackgroundColor(fGui->fWhite);
623  }
624  }
625 
626 }
627 
628 
629 // ----------------------------------------------------------------------
630 void PixParTab::tbmYellow() {
631  TGButton *btn = (TGButton *) gTQSender;
632  int id(-1);
633  id = btn->WidgetId();
634  if (-1 == id) {
635  LOG(logDEBUG) << "ASLFDKHAPIUDF ";
636  return;
637  }
638 
639  string sdac = fTbmTextMap[id];
640  ((TGTextEntry*)(fTbmTextEntries[sdac]))->SetBackgroundColor(fGui->fYellow);
641 }
642 
643 
644 // ----------------------------------------------------------------------
645 void PixParTab::updateParameters() {
646  LOG(logDEBUG) << "PixParTab::updateParameters: ";
647 
648  for (unsigned int iroc = 0; iroc < fGui->getApi()->_dut->getNRocs(); ++iroc) {
649  map<string, TGTextEntry*> amap = fRocTextEntries[iroc];
650  for (map<string, TGTextEntry*>::iterator mapit = amap.begin(); mapit != amap.end(); ++mapit) {
651  mapit->second->SetText(Form("%d", (int)(fGui->getApi()->_dut->getDAC(iroc, mapit->first))));
652  }
653  }
654 
655  vector<pair<string, uint8_t> > tbparameters = fConfigParameters->getTbParameters();
656  for (vector<pair<string, uint8_t> >::iterator itbparameters = tbparameters.begin(); itbparameters != tbparameters.end(); ++itbparameters)
657  ((TGTextEntry*)(fTbTextEntries[itbparameters->first]))->SetText(Form("%d", int(itbparameters->second)));
658 
659  for (unsigned int itbm = 0; itbm < fGui->getApi()->_dut->getNTbms(); ++itbm) {
660  vector<pair<string, uint8_t> > tbmparameters = fGui->getApi()->_dut->getTbmDACs(itbm);
661  for (vector<pair<string, uint8_t> >::iterator itbmparameters = tbmparameters.begin(); itbmparameters != tbmparameters.end(); ++itbmparameters) {
662  std::bitset<8> bits(itbmparameters->second);
663  ((TGTextEntry*)(fTbmTextEntries[itbmparameters->first]))->SetText(Form("%s", bits.to_string().c_str()));
664  fTbmParIds[itbm][itbmparameters->first]=itbmparameters->second;
665  }
666  }
667  updateSelection();
668 
669 }
670 
671 
672 // ----------------------------------------------------------------------
673 void PixParTab::selectRoc(int iroc) {
674  bool selected(false);
675  if (iroc == -1) {
676  TGButton *btn = (TGButton *) gTQSender;
677  if (kButtonDown == btn->GetState()) {
678  selected = true;
679  }
680  iroc = btn->WidgetId();
681  }
682 
683  LOG(logDEBUG) << "selectRoc: iroc = " << iroc << " selected? " << selected;
684 
685  if (false == selected) {
686  iroc = 0;
687  for (unsigned int i = 0; i < fSelectRoc.size(); ++i) {
688  if (kButtonDown == fSelectRoc[i]->GetState()) {
689  iroc = i;
690  break;
691  }
692  }
693  }
694 
695  updateSelection();
696 }
697 
698 
699 // ----------------------------------------------------------------------
700 void PixParTab::selectTbm(int id) {
701 
702  if (id == -1) {
703  TGButton *btn = (TGButton *) gTQSender;
704  id = btn->WidgetId();
705  }
706 
707  LOG(logDEBUG) << "selectTbm: id = " << id;
708  fSelectedTbm = id;
709 
710  map<string, uint8_t> amap = fTbmParIds[fSelectedTbm];
711  for (map<string, uint8_t >::iterator mapit = amap.begin(); mapit != amap.end(); ++mapit) {
712 
713  std::bitset<8> bits((*mapit).second);
714  fTbmTextEntries[(*mapit).first]->SetText(Form("%s", bits.to_string().c_str()));
715  }
716  updateSelection();
717 }
718 
719 
720 // ----------------------------------------------------------------------
721 void PixParTab::setAllRocParameter() {
722  if (!fGui->getTabs()) return;
723  set<TGTextEntry*>::iterator irc = fRocChanges.begin();
724  set<TGTextEntry*>::iterator ircE = fRocChanges.end();
725  for (; irc != ircE; ++irc) {
726  string sdac = (*irc)->GetName();
727  string sval = (*irc)->GetText();
728  uint8_t udac = atoi(sval.c_str());
729  int iroc(-1);
730  for (unsigned int i = 0; i < fGui->getApi()->_dut->getNRocs(); ++i) {
731  iroc = i;
732  LOG(logDEBUG)<< "roc = " << iroc << " -> " << sdac << " set to int(udac) = " << int(udac);
733  fGui->getApi()->setDAC(sdac, udac, iroc);
734  (*irc)->SetFocus();
735  (*irc)->SetBackgroundColor(fGui->fWhite);
736  (*irc)->SetAlignment(kTextRight);
737  }
738 
739 
740  }
741 
742  fRocChanges.clear();
743  updateParameters();
744 }
745 
746 // ----------------------------------------------------------------------
747 void PixParTab::setOneRocParameter() {
748  if (!fGui->getTabs()) return;
749  cout << "fRocChanges.size() = " << fRocChanges.size() << endl;
750  set<TGTextEntry*>::iterator irc;
751  for (irc = fRocChanges.begin(); irc != fRocChanges.end(); ++irc) {
752  string sdac = (*irc)->GetName();
753  string sval = (*irc)->GetText();
754  uint8_t udac = atoi(sval.c_str());
755  int iroc(-1);
756  for (unsigned int i = 0; i < fRocTextEntries.size(); ++i) {
757  for (map<string, TGTextEntry*>::iterator imap = fRocTextEntries[i].begin(); imap != fRocTextEntries[i].end(); ++imap) {
758  if (imap->second == *irc) {
759  iroc = i;
760  goto found;
761  }
762  }
763  }
764 
765  found:
766  if (iroc < 0) {
767  LOG(logDEBUG) << "did not find ROC for TGTextEntry";
768  continue;
769  }
770  LOG(logDEBUG)<< "roc = " << iroc << " -> " << sdac << " set to int(udac) = " << int(udac);
771  fGui->getApi()->setDAC(sdac, udac, iroc);
772  (*irc)->SetFocus();
773  (*irc)->SetBackgroundColor(fGui->fWhite);
774  (*irc)->SetAlignment(kTextRight);
775  }
776 
777  fRocChanges.clear();
778  updateParameters();
779 }
780 
781 // ----------------------------------------------------------------------
782 void PixParTab::rocYellow() {
783  TGTextEntry *f = (TGTextEntry*) gTQSender;
784  if (f) {
785  int iroc(-1);
786  for (unsigned int i = 0; i < fRocTextEntries.size(); ++i) {
787  for (map<string, TGTextEntry*>::iterator imap = fRocTextEntries[i].begin(); imap != fRocTextEntries[i].end(); ++imap) {
788  if (imap->second == f) {
789  iroc = i;
790  goto found;
791  }
792  }
793  }
794  found:
795  if (iroc < 0) {
796  LOG(logDEBUG) << "did not find ROC for TGTextEntry";
797  return;
798  }
799  string sdac = f->GetName();
800  string sval = f->GetText();
801  uint8_t udac = atoi(sval.c_str());
802 
803  if (udac != fGui->getApi()->_dut->getDAC(iroc, sdac)) {
804  f->SetBackgroundColor(fGui->fYellow);
805  f->SetAlignment(kTextRight);
806  fRocChanges.insert(f);
807  } else {
808  f->SetBackgroundColor(fGui->fWhite);
809  f->SetAlignment(kTextRight);
810  fRocChanges.erase(f);
811  }
812  }
813 
814 }
815 
816 // ----------------------------------------------------------------------
817 void PixParTab::setLemo() {
818  if (!fGui->getTabs()) return;
819  LOG(logDEBUG) << "PixParTab::setLemo: ";
820 
821  TGButton *btn = (TGButton *) gTQSender;
822  int id(-1);
823  id = btn->WidgetId();
824  if (-1 == id) {
825  LOG(logDEBUG) << "ASLFDKHAPIUDF ";
826  return;
827  }
828 
829 }
830 
831 
832 // ----------------------------------------------------------------------
833 void PixParTab::lockClk() {
834  if (fLockClk) {
835  fLockClk = false;
836  } else {
837  fLockClk = true;
838  }
839 }
840 
841 
842 // ----------------------------------------------------------------------
843 void PixParTab::saveTbParameters() {
844  LOG(logDEBUG) << "save Tb parameters";
845  fConfigParameters->writeTbParameterFile();
846 }
847 
848 // ----------------------------------------------------------------------
849 void PixParTab::saveTbmParameters() {
850  LOG(logDEBUG) << "save Tbm parameters";
851  for (unsigned int itbm = 0; itbm < fGui->getApi()->_dut->getNTbms(); itbm += 2) {
852  fConfigParameters->writeTbmParameterFile(itbm, fGui->getApi()->_dut->getTbmDACs(itbm), fGui->getApi()->_dut->getTbmDACs(itbm+1));
853  }
854 }
855 
856 // ----------------------------------------------------------------------
857 void PixParTab::saveDacParameters() {
858  LOG(logDEBUG) << "save DAC parameters";
859  vector<uint8_t> rocs = fGui->getApi()->_dut->getEnabledRocIDs();
860  LOG(logDEBUG) << " rocs.size() = " << rocs.size();
861  for (unsigned int iroc = 0; iroc < rocs.size(); ++iroc) {
862  fConfigParameters->writeDacParameterFile(rocs[iroc], fGui->getApi()->_dut->getDACs(rocs[iroc]));
863  }
864 }
865 
866 
867 // ----------------------------------------------------------------------
868 void PixParTab::saveTrimParameters() {
869  LOG(logDEBUG) << "save Trim parameters";
870  vector<uint8_t> rocs = fGui->getApi()->_dut->getEnabledRocIDs();
871  for (unsigned int iroc = 0; iroc < rocs.size(); ++iroc) {
872  fConfigParameters->writeTrimFile(rocs[iroc], fGui->getApi()->_dut->getEnabledPixels(rocs[iroc]));
873  }
874 
875 }
876 
877 
878 // ----------------------------------------------------------------------
879 vector<int> PixParTab::getSelectedTbms() {
880  vector<int> result;
881  for (unsigned int i = 0; i < fSelectTbm.size(); ++i) {
882  if (kButtonDown == fSelectTbm[i]->GetState()) {
883  result.push_back(i);
884  }
885  }
886  return result;
887 }
888 
889 // ----------------------------------------------------------------------
890 vector<int> PixParTab::getSelectedRocs() {
891  vector<int> result;
892  for (unsigned int i = 0; i < fSelectRoc.size(); ++i) {
893  if (kButtonDown == fSelectRoc[i]->GetState()) {
894  result.push_back(i);
895  }
896  }
897  return result;
898 }
899 
900 
901 // ----------------------------------------------------------------------
902 void PixParTab::updateSelection() {
903  map<int, int> id2idx;
904  vector<int> selectedRocs = getSelectedRocs();
905  for (unsigned int i = 0; i < fGui->getApi()->_dut->getNRocs(); ++i) {
906  fGui->getApi()->_dut->setROCEnable(i, false);
907  }
908  for (unsigned i = 0; i < selectedRocs.size(); ++i) {
909  fGui->getApi()->_dut->setROCEnable(selectedRocs[i], true);
910  id2idx.insert(make_pair(selectedRocs[i], i));
911  }
912 
913  fGui->updateSelectedRocs(id2idx);
914 
915  vector<int> selectedTbms = getSelectedTbms();
916  for (unsigned int i = 0; i < fGui->getApi()->_dut->getNTbms(); ++i) {
917  fGui->getApi()->_dut->setTBMEnable(i, false);
918  }
919  for (unsigned i = 0; i < selectedTbms.size(); ++i) {
920  fGui->getApi()->_dut->setTBMEnable(selectedTbms[i], true);
921  }
922 
923 }
Definition: PixGui.hh:43