pxar
 All Classes Namespaces Functions Variables Typedefs Friends
PixMonitorFrame.cc
1 #include "PixMonitorFrame.hh"
2 #include "log.h"
3 
4 #include "PixGui.hh"
5 #include "PixTab.hh"
6 #include "PixSetup.hh"
7 #include "PixMonitor.hh"
8 
9 using namespace std;
10 using namespace pxar;
11 
12 // ----------------------------------------------------------------------
13 PixMonitorFrame::PixMonitorFrame(TGVerticalFrame *f, PixGui *pixGui) {
14  fGui = pixGui;
15  fMonitorFrame = new TGVerticalFrame(f);
16  fHFrame1 = new TGHorizontalFrame(fMonitorFrame);
17  fHFrame2 = new TGHorizontalFrame(fMonitorFrame);
18 
19  TGString *a = new TGString("I(ana) ");
20  TGString *d = new TGString("I(digi) ");
21 
22  fAna = new TGLabel(fHFrame1, a);
23  fDigi = new TGLabel(fHFrame2, d);
24 
25  fNmrAna = new TGTextEntry(fHFrame1, fAnaFileBuffer = new TGTextBuffer(50));
26  fNmrAna->SetWidth(50);
27  fNmrAna->SetToolTipText(Form("Total analog current drawn by %s", (fGui->getPixSetup()->getConfigParameters()->getNrocs()>1?"module":"ROC")));
28  fNmrDigi = new TGTextEntry(fHFrame2, fDigiFileBuffer = new TGTextBuffer(50));
29  fNmrDigi->SetWidth(50);
30  fNmrDigi->SetToolTipText(Form("Total digital current drawn by %s", (fGui->getPixSetup()->getConfigParameters()->getNrocs()>1?"module":"ROC")));
31 
32  fAnaButton = new TGTextButton(fHFrame1," Draw ", B_DRAWANA);
33  fAnaButton->SetToolTipText("draw analog current measurements vs time");
34  fAnaButton->ChangeOptions(fAnaButton->GetOptions() | kFixedWidth);
35  fAnaButton->Connect("Clicked()", "PixMonitorFrame", this, "handleButtons()");
36 
37  fDigiButton = new TGTextButton(fHFrame2," Draw ", B_DRAWDIGI);
38  fDigiButton->SetToolTipText("draw digital current measurements vs time");
39  fDigiButton->ChangeOptions(fDigiButton->GetOptions() | kFixedWidth);
40  fDigiButton->Connect("Clicked()", "PixMonitorFrame", this, "handleButtons()");
41 
42  if ("fpix" == fGui->getHdiType()) {
43  TGString *temperature_degree = new TGString("T (deg C) ");
44  fHFrame_TDegree = new TGHorizontalFrame(fMonitorFrame);
45  fTemperatureDegree = new TGLabel(fHFrame_TDegree, temperature_degree);
46  fNmrTDegree = new TGTextEntry(fHFrame_TDegree, fTDegreeFileBuffer = new TGTextBuffer(40));
47  fNmrTDegree->SetWidth(40);
48  fHFrame_TDegree->AddFrame(fTemperatureDegree, new TGLayoutHints(kLHintsTop | kLHintsLeft,2,2,2,2));
49  fHFrame_TDegree->AddFrame(fNmrTDegree, new TGLayoutHints(kLHintsTop | kLHintsLeft,2,2,2,2));
50  }
51 
52  fActTime = time(NULL);
53  fTimeinfo = localtime(&fActTime);
54 
55  fHFrame1->AddFrame(fAna, new TGLayoutHints(kLHintsTop | kLHintsLeft,2,2,2,2));
56  fHFrame1->AddFrame(fNmrAna, new TGLayoutHints(kLHintsTop | kLHintsLeft,2,2,2,2));
57  fHFrame1->AddFrame(fAnaButton, new TGLayoutHints(kLHintsTop | kLHintsLeft,2,2,2,2));
58  fHFrame2->AddFrame(fDigi, new TGLayoutHints(kLHintsTop | kLHintsLeft,2,2,2));
59  fHFrame2->AddFrame(fNmrDigi, new TGLayoutHints(kLHintsTop | kLHintsLeft,2,2,2));
60  fHFrame2->AddFrame(fDigiButton, new TGLayoutHints(kLHintsTop | kLHintsLeft,2,2,2));
61 
62  fMonitorFrame->AddFrame(fHFrame1, new TGLayoutHints(kLHintsTop | kLHintsExpandX,1,1,1,1));
63  fMonitorFrame->AddFrame(fHFrame2, new TGLayoutHints(kLHintsTop | kLHintsExpandX,1,1,1,1));
64 
65 
66  if ("fpix" == fGui->getHdiType()) {
67  fMonitorFrame->AddFrame(fHFrame_TDegree, new TGLayoutHints(kLHintsTop | kLHintsExpandX,1,1,1,1));
68  }
69 
70  f->AddFrame(fMonitorFrame, new TGLayoutHints(kLHintsTop,2,2,2,2));
71 
72 }
73 
74 
75 // ----------------------------------------------------------------------
76 PixMonitorFrame::~PixMonitorFrame() {
77 }
78 
79 
80 // ----------------------------------------------------------------------
81 void PixMonitorFrame::handleButtons(Int_t id) {
82  if(id == -1) {
83  TGButton *btn = (TGButton *) gTQSender;
84  id = btn->WidgetId();
85  }
86 
87  // timer initializing
88  fActTime = time(NULL);
89  fTimeinfo = gmtime (&fActTime);
90 
91  PixMonitor *a = fGui->getPixSetup()->getPixMonitor();
92  switch(id) {
93  case B_DRAWANA:
94  a->drawHist("iana");
95  if (fGui->getPixTab()) fGui->getPixTab()->update();
96  // fGui->getTabs()->SetTab(fGui->getSelectedTab());
97 
98  break;
99  case B_DRAWDIGI:
100  a->drawHist("idig");
101  if (fGui->getPixTab()) fGui->getPixTab()->update();
102  break;
103  default:
104  LOG(logINFO) << "Something went wrong in the PixMonitorFrame::handleButons method!";
105  break;
106  }
107 }
108 
109 // ----------------------------------------------------------------------
110 void PixMonitorFrame::Update() {
111  static float ia(0.), id(0.);
112  PixMonitor *a = fGui->getPixSetup()->getPixMonitor();
113  if (fGui->getApi()) {
114  a->update();
115 // ia = static_cast<float>(fGui->getApi()->getTBia());
116 // id = static_cast<float>(fGui->getApi()->getTBid());
117  ia = static_cast<float>(a->getIana());
118  id = static_cast<float>(a->getIdig());
119  if (!fGui->isPowerOff()) {
120  if (ia < 1e-4) {
121  LOG(logERROR) << "analog current reading unphysical";
122  }
123  if (id < 1e-4) {
124  LOG(logERROR) << "digital current reading unphysical";
125  }
126  }
127  } else {
128  ia += 1.0;
129  id += 1.0;
130  }
131 
132  fNmrAna->SetText(Form("%4.3f", ia));
133  fNmrDigi->SetText(Form("%4.3f", id));
134 
135  if ("fpix" == fGui->getHdiType()) {
136  if (fGui->getApi()) {
137  uint16_t v_ref = fGui->getApi()->GetADC(5);
138  uint16_t v_val = fGui->getApi()->GetADC(4);
139  fNmrTDegree->SetText(Form("%3.1f", (-(v_val - v_ref) - 0.92) / 6.55));
140  } else {
141  fNmrTDegree->SetText(Form("---"));
142  }
143  }
144 
145 }
146 
147 
148 // // ----------------------------------------------------------------------
149 // string PixMonitorFrame::stringify(int x) {
150 // ostringstream o;
151 // o << x;
152 // return o.str();
153 
154 // }
Definition: PixGui.hh:43