| 1 | #ifndef FACT_FactGui
|
|---|
| 2 | #define FACT_FactGui
|
|---|
| 3 |
|
|---|
| 4 | #include "MainWindow.h"
|
|---|
| 5 |
|
|---|
| 6 | #include <iomanip>
|
|---|
| 7 | #include <valarray>
|
|---|
| 8 |
|
|---|
| 9 | #include <boost/bind.hpp>
|
|---|
| 10 |
|
|---|
| 11 | #include <QTimer>
|
|---|
| 12 | #include <QStandardItemModel>
|
|---|
| 13 |
|
|---|
| 14 | #include "CheckBoxDelegate.h"
|
|---|
| 15 |
|
|---|
| 16 | #include "src/Converter.h"
|
|---|
| 17 | #include "src/HeadersFTM.h"
|
|---|
| 18 | #include "src/DimNetwork.h"
|
|---|
| 19 | #include "src/tools.h"
|
|---|
| 20 |
|
|---|
| 21 | #include "TROOT.h"
|
|---|
| 22 | #include "TSystem.h"
|
|---|
| 23 | #include "TGraph.h"
|
|---|
| 24 | #include "TH1.h"
|
|---|
| 25 | #include "TStyle.h"
|
|---|
| 26 | #include "TMarker.h"
|
|---|
| 27 | #include "TColor.h"
|
|---|
| 28 | #include "TQtTimer.h"
|
|---|
| 29 |
|
|---|
| 30 | #define HAS_ROOT
|
|---|
| 31 |
|
|---|
| 32 | using namespace std;
|
|---|
| 33 |
|
|---|
| 34 | // #########################################################################
|
|---|
| 35 |
|
|---|
| 36 | class Camera : public TObject
|
|---|
| 37 | {
|
|---|
| 38 | typedef pair<double,double> Position;
|
|---|
| 39 | typedef vector<Position> Positions;
|
|---|
| 40 |
|
|---|
| 41 | Positions fGeom;
|
|---|
| 42 |
|
|---|
| 43 | void CreatePalette()
|
|---|
| 44 | {
|
|---|
| 45 | /*
|
|---|
| 46 | double ss[5] = {0., 0.10, 0.45, 0.75, 1.00};
|
|---|
| 47 | double rr[5] = {0., 0.35, 0.85, 1.00, 1.00};
|
|---|
| 48 | double gg[5] = {0., 0.10, 0.20, 0.73, 1.00};
|
|---|
| 49 | double bb[5] = {0., 0.03, 0.06, 0.00, 1.00};
|
|---|
| 50 | */
|
|---|
| 51 | double ss[5] = {0., 0.25, 0.50, 0.75, 1.00};
|
|---|
| 52 | double rr[5] = {0., 0.00, 0.00, 1.00, 1.00};
|
|---|
| 53 | double gg[5] = {0., 0.00, 1.00, 0.00, 1.00};
|
|---|
| 54 | double bb[5] = {0., 1.00, 0.00, 0.00, 1.00};
|
|---|
| 55 |
|
|---|
| 56 | const Int_t nn = 1438;
|
|---|
| 57 |
|
|---|
| 58 | Int_t idx = TColor::CreateGradientColorTable(5, ss, rr, gg, bb, nn);
|
|---|
| 59 | for (int i=0; i<nn; i++)
|
|---|
| 60 | fPalette.push_back(idx++);
|
|---|
| 61 | }
|
|---|
| 62 |
|
|---|
| 63 | void CreateGeometry()
|
|---|
| 64 | {
|
|---|
| 65 | const double gsSin60 = sqrt(3.)/2;
|
|---|
| 66 |
|
|---|
| 67 | const int rings = 23;
|
|---|
| 68 |
|
|---|
| 69 | // add the first pixel to the list
|
|---|
| 70 |
|
|---|
| 71 | fGeom.push_back(make_pair(0, -0.5));
|
|---|
| 72 |
|
|---|
| 73 | for (int ring=1; ring<=rings; ring++)
|
|---|
| 74 | {
|
|---|
| 75 | for (int s=0; s<6; s++)
|
|---|
| 76 | {
|
|---|
| 77 | for (int i=1; i<=ring; i++)
|
|---|
| 78 | {
|
|---|
| 79 | double xx, yy;
|
|---|
| 80 | switch (s)
|
|---|
| 81 | {
|
|---|
| 82 | case 0: // Direction South East
|
|---|
| 83 | xx = (ring+i)*0.5;
|
|---|
| 84 | yy = (-ring+i)*gsSin60;
|
|---|
| 85 | break;
|
|---|
| 86 |
|
|---|
| 87 | case 1: // Direction North East
|
|---|
| 88 | xx = ring-i*0.5;
|
|---|
| 89 | yy = i*gsSin60;
|
|---|
| 90 | break;
|
|---|
| 91 |
|
|---|
| 92 | case 2: // Direction North
|
|---|
| 93 | xx = ring*0.5-i;
|
|---|
| 94 | yy = ring*gsSin60;
|
|---|
| 95 | break;
|
|---|
| 96 |
|
|---|
| 97 | case 3: // Direction North West
|
|---|
| 98 | xx = -(ring+i)*0.5;
|
|---|
| 99 | yy = (ring-i)*gsSin60;
|
|---|
| 100 | break;
|
|---|
| 101 |
|
|---|
| 102 | case 4: // Direction South West
|
|---|
| 103 | xx = 0.5*i-ring;
|
|---|
| 104 | yy = -i*gsSin60;
|
|---|
| 105 | break;
|
|---|
| 106 |
|
|---|
| 107 | case 5: // Direction South
|
|---|
| 108 | xx = i-ring*0.5;
|
|---|
| 109 | yy = -ring*gsSin60;
|
|---|
| 110 | break;
|
|---|
| 111 | }
|
|---|
| 112 |
|
|---|
| 113 | if (xx*xx + yy*yy - xx > 395.75)
|
|---|
| 114 | continue;
|
|---|
| 115 |
|
|---|
| 116 | fGeom.push_back(make_pair(yy, xx-0.5));
|
|---|
| 117 | }
|
|---|
| 118 | }
|
|---|
| 119 | }
|
|---|
| 120 | }
|
|---|
| 121 |
|
|---|
| 122 | valarray<double> fData;
|
|---|
| 123 | map<int, bool> fBold;
|
|---|
| 124 | map<int, bool> fEnable;
|
|---|
| 125 |
|
|---|
| 126 | int fWhite;
|
|---|
| 127 |
|
|---|
| 128 | public:
|
|---|
| 129 | Camera() : fData(0., 1438), fWhite(-1)
|
|---|
| 130 | {
|
|---|
| 131 | CreatePalette();
|
|---|
| 132 | CreateGeometry();
|
|---|
| 133 |
|
|---|
| 134 | for (int i=0; i<1438; i++)
|
|---|
| 135 | fData[i] = i;
|
|---|
| 136 | }
|
|---|
| 137 |
|
|---|
| 138 | void Reset() { fBold.clear(); }
|
|---|
| 139 |
|
|---|
| 140 | void SetBold(int idx) { fBold[idx]=true; }
|
|---|
| 141 | void SetWhite(int idx) { fWhite=idx; }
|
|---|
| 142 | void SetEnable(int idx, bool b) { fEnable[idx]=b; }
|
|---|
| 143 | void Toggle(int idx) { fEnable[idx]=!fEnable[idx]; }
|
|---|
| 144 |
|
|---|
| 145 | const char *GetName() const { return "Camera"; }
|
|---|
| 146 |
|
|---|
| 147 | vector<Int_t> fPalette;
|
|---|
| 148 |
|
|---|
| 149 | void Paint(const Position &p)
|
|---|
| 150 | {
|
|---|
| 151 | static const Double_t fgCos60 = 0.5; // TMath::Cos(60/TMath::RadToDeg());
|
|---|
| 152 | static const Double_t fgSin60 = sqrt(3.)/2; // TMath::Sin(60/TMath::RadToDeg());
|
|---|
| 153 |
|
|---|
| 154 | static const Double_t fgDy[6] = { fgCos60, 0., -fgCos60, -fgCos60, 0., fgCos60 };
|
|---|
| 155 | static const Double_t fgDx[6] = { fgSin60/3, fgSin60*2/3, fgSin60/3, -fgSin60/3, -fgSin60*2/3, -fgSin60/3 };
|
|---|
| 156 |
|
|---|
| 157 | //
|
|---|
| 158 | // calculate the positions of the pixel corners
|
|---|
| 159 | //
|
|---|
| 160 | Double_t x[7], y[7];
|
|---|
| 161 | for (Int_t i=0; i<7; i++)
|
|---|
| 162 | {
|
|---|
| 163 | x[i] = p.first + fgDx[i%6];
|
|---|
| 164 | y[i] = p.second + fgDy[i%6];
|
|---|
| 165 | }
|
|---|
| 166 |
|
|---|
| 167 | gPad->PaintFillArea(6, x, y);
|
|---|
| 168 | gPad->PaintPolyLine(7, x, y);
|
|---|
| 169 |
|
|---|
| 170 | }
|
|---|
| 171 |
|
|---|
| 172 | void Paint(Option_t *)
|
|---|
| 173 | {
|
|---|
| 174 | gStyle->SetPalette(fPalette.size(), fPalette.data());
|
|---|
| 175 |
|
|---|
| 176 |
|
|---|
| 177 | const double r = double(gPad->GetWw())/gPad->GetWh();
|
|---|
| 178 | const double max = 20.5; // 20.5 rings in x and y
|
|---|
| 179 |
|
|---|
| 180 | if (r>1)
|
|---|
| 181 | gPad->Range(-r*max, -max, r*max, max);
|
|---|
| 182 | else
|
|---|
| 183 | gPad->Range(-max, -max/r, max, max/r);
|
|---|
| 184 |
|
|---|
| 185 |
|
|---|
| 186 | const double min = fData.min();
|
|---|
| 187 | const double scale = fData.max()-fData.min();
|
|---|
| 188 |
|
|---|
| 189 | TAttFill fill(0, 1001);
|
|---|
| 190 | TAttLine line;
|
|---|
| 191 |
|
|---|
| 192 | int cnt=0;
|
|---|
| 193 | for (Positions::iterator p=fGeom.begin(); p!=fGeom.end(); p++, cnt++)
|
|---|
| 194 | {
|
|---|
| 195 | if (fBold[cnt])
|
|---|
| 196 | continue;
|
|---|
| 197 |
|
|---|
| 198 |
|
|---|
| 199 | const int col = (fData[cnt]-min)/scale*(fPalette.size()-1);
|
|---|
| 200 |
|
|---|
| 201 | if (fEnable[cnt])
|
|---|
| 202 | fill.SetFillColor(gStyle->GetColorPalette(col));
|
|---|
| 203 | else
|
|---|
| 204 | fill.SetFillColor(kWhite);
|
|---|
| 205 |
|
|---|
| 206 | fill.Modify();
|
|---|
| 207 |
|
|---|
| 208 | Paint(*p);
|
|---|
| 209 | }
|
|---|
| 210 |
|
|---|
| 211 | line.SetLineWidth(2);
|
|---|
| 212 | line.Modify();
|
|---|
| 213 |
|
|---|
| 214 | cnt = 0;
|
|---|
| 215 | for (Positions::iterator p=fGeom.begin(); p!=fGeom.end(); p++, cnt++)
|
|---|
| 216 | {
|
|---|
| 217 | if (!fBold[cnt])
|
|---|
| 218 | continue;
|
|---|
| 219 |
|
|---|
| 220 | const int col = (fData[cnt]-min)/scale*(fPalette.size()-1);
|
|---|
| 221 |
|
|---|
| 222 | if (fEnable[cnt])
|
|---|
| 223 | fill.SetFillColor(gStyle->GetColorPalette(col));
|
|---|
| 224 | else
|
|---|
| 225 | fill.SetFillColor(kWhite);
|
|---|
| 226 | fill.Modify();
|
|---|
| 227 |
|
|---|
| 228 | Paint(*p);
|
|---|
| 229 | }
|
|---|
| 230 |
|
|---|
| 231 | TMarker m(0,0,kStar);
|
|---|
| 232 | m.DrawMarker(0, 0);
|
|---|
| 233 |
|
|---|
| 234 | if (fWhite<0)
|
|---|
| 235 | return;
|
|---|
| 236 |
|
|---|
| 237 | const Position &p = fGeom[fWhite];
|
|---|
| 238 |
|
|---|
| 239 | line.SetLineColor(kWhite);
|
|---|
| 240 | line.Modify();
|
|---|
| 241 |
|
|---|
| 242 | const int col = (fData[fWhite]-min)/scale*(fPalette.size()-1);
|
|---|
| 243 |
|
|---|
| 244 | if (fEnable[fWhite])
|
|---|
| 245 | fill.SetFillColor(gStyle->GetColorPalette(col));
|
|---|
| 246 | else
|
|---|
| 247 | fill.SetFillColor(kWhite);
|
|---|
| 248 | fill.Modify();
|
|---|
| 249 |
|
|---|
| 250 | Paint(p);
|
|---|
| 251 | }
|
|---|
| 252 |
|
|---|
| 253 | int GetIdx(float px, float py) const
|
|---|
| 254 | {
|
|---|
| 255 | static const double sqrt3 = sqrt(3);
|
|---|
| 256 |
|
|---|
| 257 | int idx = 0;
|
|---|
| 258 | for (Positions::const_iterator p=fGeom.begin(); p!=fGeom.end(); p++, idx++)
|
|---|
| 259 | {
|
|---|
| 260 | const Double_t dy = py - p->second;
|
|---|
| 261 | if (fabs(dy)>0.5)
|
|---|
| 262 | continue;
|
|---|
| 263 |
|
|---|
| 264 | const Double_t dx = px - p->first;
|
|---|
| 265 |
|
|---|
| 266 | if (TMath::Abs(dy + dx*sqrt3) > 1)
|
|---|
| 267 | continue;
|
|---|
| 268 |
|
|---|
| 269 | if (TMath::Abs(dy - dx*sqrt3) > 1)
|
|---|
| 270 | continue;
|
|---|
| 271 |
|
|---|
| 272 | return idx;
|
|---|
| 273 | }
|
|---|
| 274 | return -1;
|
|---|
| 275 | }
|
|---|
| 276 |
|
|---|
| 277 | char* GetObjectInfo(Int_t px, Int_t py) const
|
|---|
| 278 | {
|
|---|
| 279 | static stringstream stream;
|
|---|
| 280 | static string str;
|
|---|
| 281 |
|
|---|
| 282 | const float x = gPad->PadtoX(gPad->AbsPixeltoX(px));
|
|---|
| 283 | const float y = gPad->PadtoY(gPad->AbsPixeltoY(py));
|
|---|
| 284 |
|
|---|
| 285 | const int idx = GetIdx(x, y);
|
|---|
| 286 |
|
|---|
| 287 | stream.seekp(0);
|
|---|
| 288 | if (idx>=0)
|
|---|
| 289 | stream << "Pixel=" << idx << " Data=" << fData[idx] << '\0';
|
|---|
| 290 |
|
|---|
| 291 | str = stream.str();
|
|---|
| 292 | return const_cast<char*>(str.c_str());
|
|---|
| 293 | }
|
|---|
| 294 |
|
|---|
| 295 | Int_t DistancetoPrimitive(Int_t px, Int_t py)
|
|---|
| 296 | {
|
|---|
| 297 | const float x = gPad->PadtoX(gPad->AbsPixeltoX(px));
|
|---|
| 298 | const float y = gPad->PadtoY(gPad->AbsPixeltoY(py));
|
|---|
| 299 |
|
|---|
| 300 | return GetIdx(x, y)>=0 ? 0 : 99999;
|
|---|
| 301 | }
|
|---|
| 302 |
|
|---|
| 303 | void SetData(const valarray<double> &data)
|
|---|
| 304 | {
|
|---|
| 305 | fData = data;
|
|---|
| 306 | }
|
|---|
| 307 | };
|
|---|
| 308 |
|
|---|
| 309 | // #########################################################################
|
|---|
| 310 |
|
|---|
| 311 |
|
|---|
| 312 | class FactGui : public MainWindow, public DimNetwork
|
|---|
| 313 | {
|
|---|
| 314 | private:
|
|---|
| 315 | class FunctionEvent : public QEvent
|
|---|
| 316 | {
|
|---|
| 317 | public:
|
|---|
| 318 | boost::function<void(const QEvent &)> fFunction;
|
|---|
| 319 |
|
|---|
| 320 | FunctionEvent(const boost::function<void(const QEvent &)> &f)
|
|---|
| 321 | : QEvent((QEvent::Type)QEvent::registerEventType()),
|
|---|
| 322 | fFunction(f) { }
|
|---|
| 323 |
|
|---|
| 324 | bool Exec() { fFunction(*this); return true; }
|
|---|
| 325 | };
|
|---|
| 326 |
|
|---|
| 327 | vector<bool> fFtuDisabled;
|
|---|
| 328 |
|
|---|
| 329 | DimStampedInfo fDimDNS;
|
|---|
| 330 |
|
|---|
| 331 | DimStampedInfo fDimLoggerStats;
|
|---|
| 332 | DimStampedInfo fDimLoggerFilenameNight;
|
|---|
| 333 | DimStampedInfo fDimLoggerFilenameRun;
|
|---|
| 334 | DimStampedInfo fDimLoggerNumSubs;
|
|---|
| 335 |
|
|---|
| 336 | DimStampedInfo fDimFtmPassport;
|
|---|
| 337 | DimStampedInfo fDimFtmTriggerCounter;
|
|---|
| 338 | DimStampedInfo fDimFtmError;
|
|---|
| 339 | DimStampedInfo fDimFtmFtuList;
|
|---|
| 340 | DimStampedInfo fDimFtmStaticData;
|
|---|
| 341 | DimStampedInfo fDimFtmDynamicData;
|
|---|
| 342 |
|
|---|
| 343 | vector<DimInfo*> fDim;
|
|---|
| 344 | map<string, DimInfo*> fServices;
|
|---|
| 345 |
|
|---|
| 346 | // ===================== Services and Commands ==========================
|
|---|
| 347 |
|
|---|
| 348 | QStandardItem *AddServiceItem(const std::string &server, const std::string &service, bool iscmd)
|
|---|
| 349 | {
|
|---|
| 350 | QListView *servers = iscmd ? fDimCmdServers : fDimSvcServers;
|
|---|
| 351 | QListView *services = iscmd ? fDimCmdCommands : fDimSvcServices;
|
|---|
| 352 | QListView *description = iscmd ? fDimCmdDescription : fDimSvcDescription;
|
|---|
| 353 |
|
|---|
| 354 | QStandardItemModel *m = dynamic_cast<QStandardItemModel*>(servers->model());
|
|---|
| 355 | if (!m)
|
|---|
| 356 | {
|
|---|
| 357 | m = new QStandardItemModel(this);
|
|---|
| 358 | servers->setModel(m);
|
|---|
| 359 | services->setModel(m);
|
|---|
| 360 | description->setModel(m);
|
|---|
| 361 | }
|
|---|
| 362 |
|
|---|
| 363 | QList<QStandardItem*> l = m->findItems(server.c_str());
|
|---|
| 364 |
|
|---|
| 365 | if (l.size()>1)
|
|---|
| 366 | {
|
|---|
| 367 | cout << "hae" << endl;
|
|---|
| 368 | return 0;
|
|---|
| 369 | }
|
|---|
| 370 |
|
|---|
| 371 | QStandardItem *col = l.size()==0 ? NULL : l[0];
|
|---|
| 372 |
|
|---|
| 373 | if (!col)
|
|---|
| 374 | {
|
|---|
| 375 | col = new QStandardItem(server.c_str());
|
|---|
| 376 | m->appendRow(col);
|
|---|
| 377 |
|
|---|
| 378 | if (!services->rootIndex().isValid())
|
|---|
| 379 | {
|
|---|
| 380 | services->setRootIndex(col->index());
|
|---|
| 381 | servers->setCurrentIndex(col->index());
|
|---|
| 382 | }
|
|---|
| 383 | }
|
|---|
| 384 |
|
|---|
| 385 | QStandardItem *item = 0;
|
|---|
| 386 | for (int i=0; i<col->rowCount(); i++)
|
|---|
| 387 | {
|
|---|
| 388 | QStandardItem *coli = col->child(i);
|
|---|
| 389 | if (coli->text().toStdString()==service)
|
|---|
| 390 | return coli;
|
|---|
| 391 | }
|
|---|
| 392 |
|
|---|
| 393 | item = new QStandardItem(service.c_str());
|
|---|
| 394 | col->appendRow(item);
|
|---|
| 395 |
|
|---|
| 396 | if (!description->rootIndex().isValid())
|
|---|
| 397 | {
|
|---|
| 398 | description->setRootIndex(item->index());
|
|---|
| 399 | services->setCurrentIndex(item->index());
|
|---|
| 400 | }
|
|---|
| 401 |
|
|---|
| 402 | if (!iscmd)
|
|---|
| 403 | item->setCheckable(true);
|
|---|
| 404 |
|
|---|
| 405 | return item;
|
|---|
| 406 | }
|
|---|
| 407 |
|
|---|
| 408 | void AddDescription(QStandardItem *item, const vector<Description> &vec)
|
|---|
| 409 | {
|
|---|
| 410 | if (!item)
|
|---|
| 411 | return;
|
|---|
| 412 | if (vec.size()==0)
|
|---|
| 413 | return;
|
|---|
| 414 |
|
|---|
| 415 | item->setToolTip(vec[0].comment.c_str());
|
|---|
| 416 |
|
|---|
| 417 | const string str = Description::GetHtmlDescription(vec);
|
|---|
| 418 |
|
|---|
| 419 | QStandardItem *desc = new QStandardItem(str.c_str());
|
|---|
| 420 | desc->setSelectable(false);
|
|---|
| 421 | item->setChild(0, 0, desc);
|
|---|
| 422 | }
|
|---|
| 423 |
|
|---|
| 424 | void AddServer(const std::string &s)
|
|---|
| 425 | {
|
|---|
| 426 | DimNetwork::AddServer(s);
|
|---|
| 427 |
|
|---|
| 428 | QApplication::postEvent(this,
|
|---|
| 429 | new FunctionEvent(boost::bind(&FactGui::handleAddServer, this, s)));
|
|---|
| 430 | }
|
|---|
| 431 |
|
|---|
| 432 | void RemoveServer(const std::string &s)
|
|---|
| 433 | {
|
|---|
| 434 | UnsubscribeServer(s);
|
|---|
| 435 |
|
|---|
| 436 | DimNetwork::RemoveServer(s);
|
|---|
| 437 |
|
|---|
| 438 | QApplication::postEvent(this,
|
|---|
| 439 | new FunctionEvent(boost::bind(&FactGui::handleRemoveServer, this, s)));
|
|---|
| 440 | }
|
|---|
| 441 |
|
|---|
| 442 | void RemoveAllServers()
|
|---|
| 443 | {
|
|---|
| 444 | UnsubscribeAllServers();
|
|---|
| 445 |
|
|---|
| 446 | vector<string> v = GetServerList();
|
|---|
| 447 | for (vector<string>::iterator i=v.begin(); i<v.end(); i++)
|
|---|
| 448 | QApplication::postEvent(this,
|
|---|
| 449 | new FunctionEvent(boost::bind(&FactGui::handleStateOffline, this, *i)));
|
|---|
| 450 |
|
|---|
| 451 | DimNetwork::RemoveAllServers();
|
|---|
| 452 |
|
|---|
| 453 | QApplication::postEvent(this,
|
|---|
| 454 | new FunctionEvent(boost::bind(&FactGui::handleRemoveAllServers, this)));
|
|---|
| 455 | }
|
|---|
| 456 |
|
|---|
| 457 | void AddService(const std::string &server, const std::string &service, const std::string &fmt, bool iscmd)
|
|---|
| 458 | {
|
|---|
| 459 | QApplication::postEvent(this,
|
|---|
| 460 | new FunctionEvent(boost::bind(&FactGui::handleAddService, this, server, service, fmt, iscmd)));
|
|---|
| 461 | }
|
|---|
| 462 |
|
|---|
| 463 | void RemoveService(const std::string &server, const std::string &service, bool iscmd)
|
|---|
| 464 | {
|
|---|
| 465 | if (fServices.find(server+'/'+service)!=fServices.end())
|
|---|
| 466 | UnsubscribeService(server+'/'+service);
|
|---|
| 467 |
|
|---|
| 468 | QApplication::postEvent(this,
|
|---|
| 469 | new FunctionEvent(boost::bind(&FactGui::handleRemoveService, this, server, service, iscmd)));
|
|---|
| 470 | }
|
|---|
| 471 |
|
|---|
| 472 | void RemoveAllServices(const std::string &server)
|
|---|
| 473 | {
|
|---|
| 474 | UnsubscribeServer(server);
|
|---|
| 475 |
|
|---|
| 476 | QApplication::postEvent(this,
|
|---|
| 477 | new FunctionEvent(boost::bind(&FactGui::handleRemoveAllServices, this, server)));
|
|---|
| 478 | }
|
|---|
| 479 |
|
|---|
| 480 | void AddDescription(const std::string &server, const std::string &service, const vector<Description> &vec)
|
|---|
| 481 | {
|
|---|
| 482 | QApplication::postEvent(this,
|
|---|
| 483 | new FunctionEvent(boost::bind(&FactGui::handleAddDescription, this, server, service, vec)));
|
|---|
| 484 | }
|
|---|
| 485 |
|
|---|
| 486 | // ======================================================================
|
|---|
| 487 |
|
|---|
| 488 | void handleAddServer(const std::string &server)
|
|---|
| 489 | {
|
|---|
| 490 | const State s = GetState(server, GetCurrentState(server));
|
|---|
| 491 | handleStateChanged(Time(), server, s);
|
|---|
| 492 | }
|
|---|
| 493 |
|
|---|
| 494 | void handleRemoveServer(const string &server)
|
|---|
| 495 | {
|
|---|
| 496 | handleStateOffline(server);
|
|---|
| 497 | handleRemoveAllServices(server);
|
|---|
| 498 | }
|
|---|
| 499 |
|
|---|
| 500 | void handleRemoveAllServers()
|
|---|
| 501 | {
|
|---|
| 502 | QStandardItemModel *m = 0;
|
|---|
| 503 | if ((m=dynamic_cast<QStandardItemModel*>(fDimCmdServers->model())))
|
|---|
| 504 | m->removeRows(0, m->rowCount());
|
|---|
| 505 |
|
|---|
| 506 | if ((m = dynamic_cast<QStandardItemModel*>(fDimSvcServers->model())))
|
|---|
| 507 | m->removeRows(0, m->rowCount());
|
|---|
| 508 | }
|
|---|
| 509 |
|
|---|
| 510 | void handleAddService(const std::string &server, const std::string &service, const std::string &/*fmt*/, bool iscmd)
|
|---|
| 511 | {
|
|---|
| 512 | QStandardItem *item = AddServiceItem(server, service, iscmd);
|
|---|
| 513 | const vector<Description> v = GetDescription(server, service);
|
|---|
| 514 | AddDescription(item, v);
|
|---|
| 515 | }
|
|---|
| 516 |
|
|---|
| 517 | void handleRemoveService(const std::string &server, const std::string &service, bool iscmd)
|
|---|
| 518 | {
|
|---|
| 519 | QListView *servers = iscmd ? fDimCmdServers : fDimSvcServers;
|
|---|
| 520 |
|
|---|
| 521 | QStandardItemModel *m = dynamic_cast<QStandardItemModel*>(servers->model());
|
|---|
| 522 | if (!m)
|
|---|
| 523 | return;
|
|---|
| 524 |
|
|---|
| 525 | QList<QStandardItem*> l = m->findItems(server.c_str());
|
|---|
| 526 | if (l.size()!=1)
|
|---|
| 527 | return;
|
|---|
| 528 |
|
|---|
| 529 | for (int i=0; i<l[0]->rowCount(); i++)
|
|---|
| 530 | {
|
|---|
| 531 | QStandardItem *row = l[0]->child(i);
|
|---|
| 532 | if (row->text().toStdString()==service)
|
|---|
| 533 | {
|
|---|
| 534 | l[0]->removeRow(row->index().row());
|
|---|
| 535 | return;
|
|---|
| 536 | }
|
|---|
| 537 | }
|
|---|
| 538 | }
|
|---|
| 539 |
|
|---|
| 540 | void handleRemoveAllServices(const std::string &server)
|
|---|
| 541 | {
|
|---|
| 542 | QStandardItemModel *m = 0;
|
|---|
| 543 | if ((m=dynamic_cast<QStandardItemModel*>(fDimCmdServers->model())))
|
|---|
| 544 | {
|
|---|
| 545 | QList<QStandardItem*> l = m->findItems(server.c_str());
|
|---|
| 546 | if (l.size()==1)
|
|---|
| 547 | m->removeRow(l[0]->index().row());
|
|---|
| 548 | }
|
|---|
| 549 |
|
|---|
| 550 | if ((m = dynamic_cast<QStandardItemModel*>(fDimSvcServers->model())))
|
|---|
| 551 | {
|
|---|
| 552 | QList<QStandardItem*> l = m->findItems(server.c_str());
|
|---|
| 553 | if (l.size()==1)
|
|---|
| 554 | m->removeRow(l[0]->index().row());
|
|---|
| 555 | }
|
|---|
| 556 | }
|
|---|
| 557 |
|
|---|
| 558 | void handleAddDescription(const std::string &server, const std::string &service, const vector<Description> &vec)
|
|---|
| 559 | {
|
|---|
| 560 | const bool iscmd = IsCommand(server, service)==true;
|
|---|
| 561 |
|
|---|
| 562 | QStandardItem *item = AddServiceItem(server, service, iscmd);
|
|---|
| 563 | AddDescription(item, vec);
|
|---|
| 564 | }
|
|---|
| 565 |
|
|---|
| 566 | // ======================================================================
|
|---|
| 567 |
|
|---|
| 568 | void SubscribeService(const string &service)
|
|---|
| 569 | {
|
|---|
| 570 | if (fServices.find(service)!=fServices.end())
|
|---|
| 571 | {
|
|---|
| 572 | cout << "ERROR - We are already subscribed to " << service << endl;
|
|---|
| 573 | return;
|
|---|
| 574 | }
|
|---|
| 575 |
|
|---|
| 576 | fServices[service] = new DimStampedInfo(service.c_str(), (void*)NULL, 0, this);
|
|---|
| 577 | }
|
|---|
| 578 |
|
|---|
| 579 | void UnsubscribeService(const string &service)
|
|---|
| 580 | {
|
|---|
| 581 | const map<string,DimInfo*>::iterator i=fServices.find(service);
|
|---|
| 582 |
|
|---|
| 583 | if (i==fServices.end())
|
|---|
| 584 | {
|
|---|
| 585 | cout << "ERROR - We are not subscribed to " << service << endl;
|
|---|
| 586 | return;
|
|---|
| 587 | }
|
|---|
| 588 |
|
|---|
| 589 | delete i->second;
|
|---|
| 590 |
|
|---|
| 591 | fServices.erase(i);
|
|---|
| 592 | }
|
|---|
| 593 |
|
|---|
| 594 | void UnsubscribeServer(const string &server)
|
|---|
| 595 | {
|
|---|
| 596 | for (map<string,DimInfo*>::iterator i=fServices.begin();
|
|---|
| 597 | i!=fServices.end(); i++)
|
|---|
| 598 | if (i->first.substr(0, server.length()+1)==server+'/')
|
|---|
| 599 | {
|
|---|
| 600 | delete i->second;
|
|---|
| 601 | fServices.erase(i);
|
|---|
| 602 | }
|
|---|
| 603 | }
|
|---|
| 604 |
|
|---|
| 605 | void UnsubscribeAllServers()
|
|---|
| 606 | {
|
|---|
| 607 | for (map<string,DimInfo*>::iterator i=fServices.begin();
|
|---|
| 608 | i!=fServices.end(); i++)
|
|---|
| 609 | delete i->second;
|
|---|
| 610 |
|
|---|
| 611 | fServices.clear();
|
|---|
| 612 | }
|
|---|
| 613 |
|
|---|
| 614 | // ======================================================================
|
|---|
| 615 |
|
|---|
| 616 | struct DimData
|
|---|
| 617 | {
|
|---|
| 618 | Time time;
|
|---|
| 619 | int qos;
|
|---|
| 620 | string name;
|
|---|
| 621 | string format;
|
|---|
| 622 | vector<char> data;
|
|---|
| 623 |
|
|---|
| 624 | DimInfo *info; // this is ONLY for a fast check of the type of the DimData!!
|
|---|
| 625 |
|
|---|
| 626 | DimData(DimInfo *inf) :
|
|---|
| 627 | time(inf->getTimestamp(), inf->getTimestampMillisecs()*1000),
|
|---|
| 628 | qos(inf->getQuality()),
|
|---|
| 629 | name(inf->getName()),
|
|---|
| 630 | format(inf->getFormat()),
|
|---|
| 631 | data(inf->getString(), inf->getString()+inf->getSize()),
|
|---|
| 632 | info(inf)
|
|---|
| 633 | {
|
|---|
| 634 | }
|
|---|
| 635 |
|
|---|
| 636 | template<typename T>
|
|---|
| 637 | T get() const { return *reinterpret_cast<const T*>(data.data()); }
|
|---|
| 638 |
|
|---|
| 639 | vector<char> vec(int b) const { return vector<char>(data.begin()+b, data.end()); }
|
|---|
| 640 | string str(unsigned int b) const { return b>=data.size()?string():string(data.data()+b, data.size()-b); }
|
|---|
| 641 | const char *c_str() const { return (char*)data.data(); }
|
|---|
| 642 |
|
|---|
| 643 | vector<boost::any> any() const
|
|---|
| 644 | {
|
|---|
| 645 | const Converter conv(format);
|
|---|
| 646 | conv.Print();
|
|---|
| 647 | return conv.GetAny(data.data(), data.size());
|
|---|
| 648 | }
|
|---|
| 649 | int size() const { return data.size(); }
|
|---|
| 650 | const void *ptr() const { return data.data(); }
|
|---|
| 651 | };
|
|---|
| 652 |
|
|---|
| 653 | // ======================= DNS ==========================================
|
|---|
| 654 |
|
|---|
| 655 | void handleDimDNS(int version)
|
|---|
| 656 | {
|
|---|
| 657 | ostringstream str;
|
|---|
| 658 | str << "V" << version/100 << 'r' << version%100;
|
|---|
| 659 |
|
|---|
| 660 | if (version==0)
|
|---|
| 661 | fStatusDNSLed->setIcon(QIcon(":/Resources/icons/red circle 1.png"));
|
|---|
| 662 | else
|
|---|
| 663 | fStatusDNSLed->setIcon(QIcon(":/Resources/icons/green circle 1.png"));
|
|---|
| 664 |
|
|---|
| 665 | fStatusDNSLabel->setText(version==0?"Offline":str.str().c_str());
|
|---|
| 666 | fStatusDNSLabel->setToolTip(version==0?"No connection to DIM DNS.":"Connection to DIM DNS established.");
|
|---|
| 667 | }
|
|---|
| 668 |
|
|---|
| 669 |
|
|---|
| 670 | // ======================= Logger =======================================
|
|---|
| 671 |
|
|---|
| 672 | void handleLoggerStats(const DimData &d)
|
|---|
| 673 | {
|
|---|
| 674 | const bool connected = d.size()!=0;
|
|---|
| 675 |
|
|---|
| 676 | fLoggerET->setEnabled(connected);
|
|---|
| 677 | fLoggerRate->setEnabled(connected);
|
|---|
| 678 | fLoggerWritten->setEnabled(connected);
|
|---|
| 679 | fLoggerFreeSpace->setEnabled(connected);
|
|---|
| 680 | fLoggerSpaceLeft->setEnabled(connected);
|
|---|
| 681 |
|
|---|
| 682 | if (!connected)
|
|---|
| 683 | return;
|
|---|
| 684 |
|
|---|
| 685 | const vector<boost::any> any = d.any();
|
|---|
| 686 |
|
|---|
| 687 | const size_t rate = boost::any_cast<int>(any[2]);
|
|---|
| 688 | const size_t space = boost::any_cast<long long>(any[1]);
|
|---|
| 689 | const size_t written = boost::any_cast<long long>(any[0]);
|
|---|
| 690 |
|
|---|
| 691 | fLoggerFreeSpace->setSuffix(" MB");
|
|---|
| 692 | fLoggerFreeSpace->setDecimals(0);
|
|---|
| 693 | fLoggerFreeSpace->setValue(space*1e-6);
|
|---|
| 694 |
|
|---|
| 695 | if (space> 1000000) // > 1GB
|
|---|
| 696 | {
|
|---|
| 697 | fLoggerFreeSpace->setSuffix(" GB");
|
|---|
| 698 | fLoggerFreeSpace->setDecimals(2);
|
|---|
| 699 | fLoggerFreeSpace->setValue(space*1e-9);
|
|---|
| 700 | }
|
|---|
| 701 | if (space>= 3000000) // >= 3GB
|
|---|
| 702 | {
|
|---|
| 703 | fLoggerFreeSpace->setSuffix(" GB");
|
|---|
| 704 | fLoggerFreeSpace->setDecimals(1);
|
|---|
| 705 | fLoggerFreeSpace->setValue(space*1e-9);
|
|---|
| 706 | }
|
|---|
| 707 | if (space>=100000000) // >= 100GB
|
|---|
| 708 | {
|
|---|
| 709 | fLoggerFreeSpace->setSuffix(" GB");
|
|---|
| 710 | fLoggerFreeSpace->setDecimals(0);
|
|---|
| 711 | fLoggerFreeSpace->setValue(space*1e-9);
|
|---|
| 712 | }
|
|---|
| 713 |
|
|---|
| 714 | fLoggerET->setTime(QTime().addSecs(rate>0?space/rate:0));
|
|---|
| 715 | fLoggerRate->setValue(rate*1e-3); // kB/s
|
|---|
| 716 | fLoggerWritten->setValue(written*1e-6);
|
|---|
| 717 |
|
|---|
| 718 | fLoggerRate->setSuffix(" kB/s");
|
|---|
| 719 | fLoggerRate->setDecimals(2);
|
|---|
| 720 | fLoggerRate->setValue(rate*1e-3);
|
|---|
| 721 | if (rate> 2000) // > 2kB/s
|
|---|
| 722 | {
|
|---|
| 723 | fLoggerRate->setSuffix(" kB/s");
|
|---|
| 724 | fLoggerRate->setDecimals(1);
|
|---|
| 725 | fLoggerRate->setValue(rate*1e-3);
|
|---|
| 726 | }
|
|---|
| 727 | if (rate>=100000) // >100kB/s
|
|---|
| 728 | {
|
|---|
| 729 | fLoggerRate->setSuffix(" kB/s");
|
|---|
| 730 | fLoggerRate->setDecimals(0);
|
|---|
| 731 | fLoggerRate->setValue(rate*1e-3);
|
|---|
| 732 | }
|
|---|
| 733 | if (rate>=1000000) // >100kB/s
|
|---|
| 734 | {
|
|---|
| 735 | fLoggerRate->setSuffix(" MB/s");
|
|---|
| 736 | fLoggerRate->setDecimals(2);
|
|---|
| 737 | fLoggerRate->setValue(rate*1e-6);
|
|---|
| 738 | }
|
|---|
| 739 | if (rate>=10000000) // >1MB/s
|
|---|
| 740 | {
|
|---|
| 741 | fLoggerRate->setSuffix(" MB/s");
|
|---|
| 742 | fLoggerRate->setDecimals(1);
|
|---|
| 743 | fLoggerRate->setValue(rate*1e-6);
|
|---|
| 744 | }
|
|---|
| 745 | if (rate>=100000000) // >10MB/s
|
|---|
| 746 | {
|
|---|
| 747 | fLoggerRate->setSuffix(" MB/s");
|
|---|
| 748 | fLoggerRate->setDecimals(0);
|
|---|
| 749 | fLoggerRate->setValue(rate*1e-6);
|
|---|
| 750 | }
|
|---|
| 751 |
|
|---|
| 752 | if (space/10000000>static_cast<size_t>(fLoggerSpaceLeft->maximum()))
|
|---|
| 753 | fLoggerSpaceLeft->setValue(fLoggerSpaceLeft->maximum()); // MB
|
|---|
| 754 | else
|
|---|
| 755 | fLoggerSpaceLeft->setValue(space/10000000); // MB
|
|---|
| 756 | }
|
|---|
| 757 |
|
|---|
| 758 | void handleLoggerFilenameNight(const DimData &d)
|
|---|
| 759 | {
|
|---|
| 760 | const bool connected = d.size()!=0;
|
|---|
| 761 |
|
|---|
| 762 | fLoggerFilenameNight->setEnabled(connected);
|
|---|
| 763 | if (connected)
|
|---|
| 764 | fLoggerFilenameNight->setText(d.c_str());
|
|---|
| 765 |
|
|---|
| 766 | if (d.qos&1)
|
|---|
| 767 | fLoggerLedLog->setIcon(QIcon(":/Resources/icons/gray circle 1.png"));
|
|---|
| 768 | else
|
|---|
| 769 | fLoggerLedLog->setIcon(QIcon(":/Resources/icons/green circle 1.png"));
|
|---|
| 770 |
|
|---|
| 771 | if (d.qos&2)
|
|---|
| 772 | fLoggerLedRep->setIcon(QIcon(":/Resources/icons/gray circle 1.png"));
|
|---|
| 773 | else
|
|---|
| 774 | fLoggerLedRep->setIcon(QIcon(":/Resources/icons/green circle 1.png"));
|
|---|
| 775 |
|
|---|
| 776 | if (d.qos&4)
|
|---|
| 777 | fLoggerLedFits->setIcon(QIcon(":/Resources/icons/gray circle 1.png"));
|
|---|
| 778 | else
|
|---|
| 779 | fLoggerLedFits->setIcon(QIcon(":/Resources/icons/green circle 1.png"));
|
|---|
| 780 | }
|
|---|
| 781 |
|
|---|
| 782 | void handleLoggerFilenameRun(const DimData &d)
|
|---|
| 783 | {
|
|---|
| 784 | const bool connected = d.size()!=0;
|
|---|
| 785 |
|
|---|
| 786 | fLoggerFilenameRun->setEnabled(connected);
|
|---|
| 787 | if (connected)
|
|---|
| 788 | fLoggerFilenameRun->setText(d.c_str());
|
|---|
| 789 |
|
|---|
| 790 | if (d.qos&1)
|
|---|
| 791 | fLoggerLedLog->setIcon(QIcon(":/Resources/icons/gray circle 1.png"));
|
|---|
| 792 | else
|
|---|
| 793 | fLoggerLedLog->setIcon(QIcon(":/Resources/icons/green circle 1.png"));
|
|---|
| 794 |
|
|---|
| 795 | if (d.qos&2)
|
|---|
| 796 | fLoggerLedRep->setIcon(QIcon(":/Resources/icons/gray circle 1.png"));
|
|---|
| 797 | else
|
|---|
| 798 | fLoggerLedRep->setIcon(QIcon(":/Resources/icons/green circle 1.png"));
|
|---|
| 799 |
|
|---|
| 800 | if (d.qos&4)
|
|---|
| 801 | fLoggerLedFits->setIcon(QIcon(":/Resources/icons/gray circle 1.png"));
|
|---|
| 802 | else
|
|---|
| 803 | fLoggerLedFits->setIcon(QIcon(":/Resources/icons/green circle 1.png"));
|
|---|
| 804 | }
|
|---|
| 805 |
|
|---|
| 806 | void handleLoggerNumSubs(const DimData &d)
|
|---|
| 807 | {
|
|---|
| 808 | const bool connected = d.size()!=0;
|
|---|
| 809 |
|
|---|
| 810 | fLoggerSubscriptions->setEnabled(connected);
|
|---|
| 811 | fLoggerOpenFiles->setEnabled(connected);
|
|---|
| 812 | if (!connected)
|
|---|
| 813 | return;
|
|---|
| 814 |
|
|---|
| 815 | const vector<boost::any> any = d.any();
|
|---|
| 816 |
|
|---|
| 817 | fLoggerSubscriptions->setValue(boost::any_cast<int>(any[0]));
|
|---|
| 818 | fLoggerOpenFiles->setValue(boost::any_cast<int>(any[1]));
|
|---|
| 819 | }
|
|---|
| 820 |
|
|---|
| 821 | // ===================== FTM ============================================
|
|---|
| 822 |
|
|---|
| 823 | void handleFtmTriggerCounter(const DimData &d)
|
|---|
| 824 | {
|
|---|
| 825 | if (d.size()==0)
|
|---|
| 826 | return;
|
|---|
| 827 |
|
|---|
| 828 | if (d.size()!=sizeof(FTM::DimTriggerCounter))
|
|---|
| 829 | {
|
|---|
| 830 | cout << "Size mismatch: " << d.size() << " " << sizeof(FTM::DimTriggerCounter) << endl;
|
|---|
| 831 | return;
|
|---|
| 832 | }
|
|---|
| 833 |
|
|---|
| 834 | const FTM::DimTriggerCounter &sdata = *reinterpret_cast<const FTM::DimTriggerCounter*>(d.ptr());
|
|---|
| 835 |
|
|---|
| 836 | fFtmTime->setText(QString::number(sdata.fTimeStamp));
|
|---|
| 837 | fTriggerCounter->setText(QString::number(sdata.fTriggerCounter));
|
|---|
| 838 | }
|
|---|
| 839 |
|
|---|
| 840 | void handleFtmDynamicData(const DimData &d)
|
|---|
| 841 | {
|
|---|
| 842 | if (d.size()==0)
|
|---|
| 843 | return;
|
|---|
| 844 |
|
|---|
| 845 | if (d.size()!=sizeof(FTM::DimDynamicData))
|
|---|
| 846 | {
|
|---|
| 847 | cout << "Size mismatch: " << d.size() << " " << sizeof(FTM::DimDynamicData) << endl;
|
|---|
| 848 | return;
|
|---|
| 849 | }
|
|---|
| 850 |
|
|---|
| 851 | const FTM::DimDynamicData &sdata = *reinterpret_cast<const FTM::DimDynamicData*>(d.ptr());
|
|---|
| 852 |
|
|---|
| 853 | fFtmTime->setText(QString::number(sdata.fTimeStamp));
|
|---|
| 854 | fOnTime->setText(QString::number(sdata.fOnTimeCounter));
|
|---|
| 855 |
|
|---|
| 856 | fFtmTemp0->setValue(sdata.fTempSensor[0]*0.1);
|
|---|
| 857 | fFtmTemp1->setValue(sdata.fTempSensor[1]*0.1);
|
|---|
| 858 | fFtmTemp2->setValue(sdata.fTempSensor[2]*0.1);
|
|---|
| 859 | fFtmTemp3->setValue(sdata.fTempSensor[3]*0.1);
|
|---|
| 860 |
|
|---|
| 861 |
|
|---|
| 862 | // ----------------------------------------------
|
|---|
| 863 | #ifdef HAS_ROOT
|
|---|
| 864 | TCanvas *c = fFtmTempCanv->GetCanvas();
|
|---|
| 865 |
|
|---|
| 866 | static int cntr = 0;
|
|---|
| 867 | double_t tm = cntr++;//Time().RootTime();
|
|---|
| 868 |
|
|---|
| 869 | TH1 *h = (TH1*)c->FindObject("MyFrame");
|
|---|
| 870 | h->FindBin(tm);
|
|---|
| 871 |
|
|---|
| 872 | fGraphFtmTemp[0].SetPoint(fGraphFtmTemp[0].GetN(), tm, sdata.fTempSensor[0]*0.1);
|
|---|
| 873 | fGraphFtmTemp[1].SetPoint(fGraphFtmTemp[1].GetN(), tm, sdata.fTempSensor[1]*0.1);
|
|---|
| 874 | fGraphFtmTemp[2].SetPoint(fGraphFtmTemp[2].GetN(), tm, sdata.fTempSensor[2]*0.1);
|
|---|
| 875 | fGraphFtmTemp[3].SetPoint(fGraphFtmTemp[3].GetN(), tm, sdata.fTempSensor[3]*0.1);
|
|---|
| 876 |
|
|---|
| 877 | c->Modified();
|
|---|
| 878 | c->Update();
|
|---|
| 879 |
|
|---|
| 880 | // ----------------------------------------------
|
|---|
| 881 |
|
|---|
| 882 | valarray<double> dat(0., 1438);
|
|---|
| 883 |
|
|---|
| 884 | for (int i=0; i<1438; i++)
|
|---|
| 885 | dat[i] = sdata.fRatePatch[fPatch[i]];
|
|---|
| 886 |
|
|---|
| 887 | c = fRatesCanv->GetCanvas();
|
|---|
| 888 | Camera *cam = (Camera*)c->FindObject("Camera");
|
|---|
| 889 |
|
|---|
| 890 | cam->SetData(dat);
|
|---|
| 891 |
|
|---|
| 892 | c->Modified();
|
|---|
| 893 | c->Update();
|
|---|
| 894 | #endif
|
|---|
| 895 | }
|
|---|
| 896 |
|
|---|
| 897 | FTM::DimStaticData fFtmStaticData;
|
|---|
| 898 |
|
|---|
| 899 | void handleFtmStaticData(const DimData &d)
|
|---|
| 900 | {
|
|---|
| 901 | if (d.size()==0)
|
|---|
| 902 | return;
|
|---|
| 903 |
|
|---|
| 904 | if (d.size()!=sizeof(FTM::DimStaticData))
|
|---|
| 905 | {
|
|---|
| 906 | cout << "Size mismatch: " << d.size() << " " << sizeof(FTM::DimStaticData) << endl;
|
|---|
| 907 | return;
|
|---|
| 908 | }
|
|---|
| 909 |
|
|---|
| 910 | const FTM::DimStaticData &sdata = *reinterpret_cast<const FTM::DimStaticData*>(d.ptr());
|
|---|
| 911 |
|
|---|
| 912 | fTriggerInterval->setValue(sdata.fTriggerInterval);
|
|---|
| 913 | fPhysicsCoincidence->setValue(sdata.fCoincidencePhysics);
|
|---|
| 914 | fCalibCoincidence->setValue(sdata.fCoincidenceCalib);
|
|---|
| 915 | fPhysicsWindow->setValue(sdata.fWindowPhysics);
|
|---|
| 916 | fCalibWindow->setValue(sdata.fWindowCalib);
|
|---|
| 917 |
|
|---|
| 918 | fTriggerDelay->setValue(sdata.fDelayTrigger);
|
|---|
| 919 | fTimeMarkerDelay->setValue(sdata.fDelayTimeMarker);
|
|---|
| 920 | fDeadTime->setValue(sdata.fDeadTime);
|
|---|
| 921 |
|
|---|
| 922 | fClockCondR0->setValue(sdata.fClockConditioner[0]);
|
|---|
| 923 | fClockCondR1->setValue(sdata.fClockConditioner[1]);
|
|---|
| 924 | fClockCondR8->setValue(sdata.fClockConditioner[2]);
|
|---|
| 925 | fClockCondR9->setValue(sdata.fClockConditioner[3]);
|
|---|
| 926 | fClockCondR11->setValue(sdata.fClockConditioner[4]);
|
|---|
| 927 | fClockCondR13->setValue(sdata.fClockConditioner[5]);
|
|---|
| 928 | fClockCondR14->setValue(sdata.fClockConditioner[6]);
|
|---|
| 929 | fClockCondR15->setValue(sdata.fClockConditioner[7]);
|
|---|
| 930 |
|
|---|
| 931 | fTriggerSeqPed->setValue(sdata.fTriggerSeqPed);
|
|---|
| 932 | fTriggerSeqLP1->setValue(sdata.fTriggerSeqLP1);
|
|---|
| 933 | fTriggerSeqLP2->setValue(sdata.fTriggerSeqLP2);
|
|---|
| 934 |
|
|---|
| 935 | fEnableTrigger->setChecked(sdata.HasTrigger());
|
|---|
| 936 | fEnableLP1->setChecked(sdata.HasLP1());
|
|---|
| 937 | fEnableLP2->setChecked(sdata.HasLP2());
|
|---|
| 938 | fEnableVeto->setChecked(sdata.HasVeto());
|
|---|
| 939 | fEnablePedestal->setChecked(sdata.HasPedestal());
|
|---|
| 940 | fEnableExt1->setChecked(sdata.HasExt1());
|
|---|
| 941 | fEnableExt2->setChecked(sdata.HasExt2());
|
|---|
| 942 | fEnableTimeMarker->setChecked(sdata.HasTimeMarker());
|
|---|
| 943 |
|
|---|
| 944 | for (int i=0; i<40; i++)
|
|---|
| 945 | {
|
|---|
| 946 | if (!sdata.IsActive(i))
|
|---|
| 947 | {
|
|---|
| 948 | fFtuLED[i]->setIcon(QIcon(":/Resources/icons/gray circle 1.png"));
|
|---|
| 949 | fFtuDisabled[i] = true;
|
|---|
| 950 | }
|
|---|
| 951 | else
|
|---|
| 952 | {
|
|---|
| 953 | if (fFtuDisabled[i])
|
|---|
| 954 | {
|
|---|
| 955 | fFtuLED[i]->setIcon(QIcon(":/Resources/icons/green circle 1.png"));
|
|---|
| 956 | fFtuDisabled[i] = false;
|
|---|
| 957 | }
|
|---|
| 958 | }
|
|---|
| 959 | }
|
|---|
| 960 |
|
|---|
| 961 | #ifdef HAS_ROOT
|
|---|
| 962 | Camera *cam = (Camera*)fRatesCanv->GetCanvas()->FindObject("Camera");
|
|---|
| 963 | for (int i=0; i<1438; i++)
|
|---|
| 964 | cam->SetEnable(i, sdata.IsEnabled(i));
|
|---|
| 965 | #endif
|
|---|
| 966 |
|
|---|
| 967 | const int patch1 = fThresholdIdx->value();
|
|---|
| 968 | fThresholdVal->setValue(sdata.fThreshold[patch1<0?0:patch1]);
|
|---|
| 969 |
|
|---|
| 970 | fPrescalingVal->setValue(sdata.fPrescaling[0]);
|
|---|
| 971 |
|
|---|
| 972 | fFtmStaticData = sdata;
|
|---|
| 973 | }
|
|---|
| 974 |
|
|---|
| 975 | void handleFtmPassport(const DimData &d)
|
|---|
| 976 | {
|
|---|
| 977 | if (d.size()==0)
|
|---|
| 978 | return;
|
|---|
| 979 |
|
|---|
| 980 | if (d.size()!=sizeof(FTM::DimPassport))
|
|---|
| 981 | {
|
|---|
| 982 | cout << "Size mismatch: " << d.size() << " " << sizeof(FTM::DimPassport) << endl;
|
|---|
| 983 | return;
|
|---|
| 984 | }
|
|---|
| 985 |
|
|---|
| 986 | const FTM::DimPassport &sdata = *reinterpret_cast<const FTM::DimPassport*>(d.ptr());
|
|---|
| 987 |
|
|---|
| 988 | stringstream str1, str2;
|
|---|
| 989 | str1 << hex << "0x" << setfill('0') << setw(16) << sdata.fBoardId;
|
|---|
| 990 | str2 << sdata.fFirmwareId;
|
|---|
| 991 |
|
|---|
| 992 | fFtmBoardId->setText(str1.str().c_str());
|
|---|
| 993 | fFtmFirmwareId->setText(str2.str().c_str());
|
|---|
| 994 | }
|
|---|
| 995 |
|
|---|
| 996 | void handleFtmFtuList(const DimData &d)
|
|---|
| 997 | {
|
|---|
| 998 | if (d.size()==0)
|
|---|
| 999 | return;
|
|---|
| 1000 |
|
|---|
| 1001 | if (d.size()!=sizeof(FTM::DimFtuList))
|
|---|
| 1002 | {
|
|---|
| 1003 | cout << "Size mismatch: " << d.size() << " " << sizeof(FTM::DimFtuList) << endl;
|
|---|
| 1004 | return;
|
|---|
| 1005 | }
|
|---|
| 1006 |
|
|---|
| 1007 | fPing->setChecked(false);
|
|---|
| 1008 |
|
|---|
| 1009 | const FTM::DimFtuList &sdata = *reinterpret_cast<const FTM::DimFtuList*>(d.ptr());
|
|---|
| 1010 |
|
|---|
| 1011 | stringstream str;
|
|---|
| 1012 | str << "<table width='100%'>" << setfill('0');
|
|---|
| 1013 | str << "<tr><th>Num</th><th></th><th>Addr</th><th></th><th>DNA</th></tr>";
|
|---|
| 1014 | for (int i=0; i<40; i++)
|
|---|
| 1015 | {
|
|---|
| 1016 | str << "<tr>";
|
|---|
| 1017 | str << "<td align='center'>" << dec << i << hex << "</td>";
|
|---|
| 1018 | str << "<td align='center'>:</td>";
|
|---|
| 1019 | str << "<td align='center'>0x" << setw(2) << (int)sdata.fAddr[i] << "</td>";
|
|---|
| 1020 | str << "<td align='center'>:</td>";
|
|---|
| 1021 | str << "<td align='center'>0x" << setw(16) << sdata.fDNA[i] << "</td>";
|
|---|
| 1022 | str << "</tr>";
|
|---|
| 1023 | }
|
|---|
| 1024 | str << "</table>";
|
|---|
| 1025 |
|
|---|
| 1026 | fFtuDNA->setText(str.str().c_str());
|
|---|
| 1027 |
|
|---|
| 1028 | fFtuAnswersTotal->setValue(sdata.fNumBoards);
|
|---|
| 1029 | fFtuAnswersCrate0->setValue(sdata.fNumBoardsCrate[0]);
|
|---|
| 1030 | fFtuAnswersCrate1->setValue(sdata.fNumBoardsCrate[1]);
|
|---|
| 1031 | fFtuAnswersCrate2->setValue(sdata.fNumBoardsCrate[2]);
|
|---|
| 1032 | fFtuAnswersCrate3->setValue(sdata.fNumBoardsCrate[3]);
|
|---|
| 1033 |
|
|---|
| 1034 | // Same: When error received: Needs decoding
|
|---|
| 1035 | for (int i=0; i<40; i++)
|
|---|
| 1036 | {
|
|---|
| 1037 | if (sdata.IsActive(i))
|
|---|
| 1038 | {
|
|---|
| 1039 | if (sdata.fPing[i]==0)
|
|---|
| 1040 | fFtuLED[i]->setIcon(QIcon(":/Resources/icons/red circle 1.png"));
|
|---|
| 1041 |
|
|---|
| 1042 | if (sdata.fPing[i]==1)
|
|---|
| 1043 | fFtuLED[i]->setIcon(QIcon(":/Resources/icons/green circle 1.png"));
|
|---|
| 1044 |
|
|---|
| 1045 | if (sdata.fPing[i]>1)
|
|---|
| 1046 | fFtuLED[i]->setIcon(QIcon(":/Resources/icons/orange circle 1.png"));
|
|---|
| 1047 |
|
|---|
| 1048 | fFtuDisabled[i] = false;
|
|---|
| 1049 | }
|
|---|
| 1050 | else
|
|---|
| 1051 | {
|
|---|
| 1052 | fFtuLED[i]->setIcon(QIcon(":/Resources/icons/gray circle 1.png"));
|
|---|
| 1053 | fFtuDisabled[i] = true;
|
|---|
| 1054 | }
|
|---|
| 1055 |
|
|---|
| 1056 | }
|
|---|
| 1057 | }
|
|---|
| 1058 |
|
|---|
| 1059 | void handleFtmError(const DimData &d)
|
|---|
| 1060 | {
|
|---|
| 1061 | if (d.size()==0)
|
|---|
| 1062 | return;
|
|---|
| 1063 |
|
|---|
| 1064 | const Converter conv(d.format);
|
|---|
| 1065 | cout << "Error:" << endl;
|
|---|
| 1066 | cout << conv.GetString(&d.data[0], d.size()) << endl;
|
|---|
| 1067 | }
|
|---|
| 1068 |
|
|---|
| 1069 | // ====================== MessageImp ====================================
|
|---|
| 1070 |
|
|---|
| 1071 | bool fChatOnline;
|
|---|
| 1072 |
|
|---|
| 1073 | void handleStateChanged(const Time &/*time*/, const std::string &server,
|
|---|
| 1074 | const State &s)
|
|---|
| 1075 | {
|
|---|
| 1076 | // FIXME: Prefix tooltip with time
|
|---|
| 1077 | if (server=="FTM_CONTROL")
|
|---|
| 1078 | {
|
|---|
| 1079 | fStatusFTMLabel->setText(s.name.c_str());
|
|---|
| 1080 | fStatusFTMLabel->setToolTip(s.comment.c_str());
|
|---|
| 1081 |
|
|---|
| 1082 | bool enable = false;
|
|---|
| 1083 |
|
|---|
| 1084 | if (s.index<FTM::kDisconnected) // No Dim connection
|
|---|
| 1085 | fStatusFTMLed->setIcon(QIcon(":/Resources/icons/gray circle 1.png"));
|
|---|
| 1086 | if (s.index==FTM::kDisconnected) // Dim connection / FTM disconnected
|
|---|
| 1087 | fStatusFTMLed->setIcon(QIcon(":/Resources/icons/yellow circle 1.png"));
|
|---|
| 1088 | if (s.index==FTM::kConnected || s.index==FTM::kIdle) // Dim connection / FTM connected
|
|---|
| 1089 | {
|
|---|
| 1090 | fStatusFTMLed->setIcon(QIcon(":/Resources/icons/green circle 1.png"));
|
|---|
| 1091 | enable = true;
|
|---|
| 1092 | }
|
|---|
| 1093 |
|
|---|
| 1094 | fTriggerWidget->setEnabled(enable);
|
|---|
| 1095 | fFtuWidget->setEnabled(enable);
|
|---|
| 1096 | fRatesWidget->setEnabled(enable);
|
|---|
| 1097 | }
|
|---|
| 1098 |
|
|---|
| 1099 | if (server=="FAD_CONTROL")
|
|---|
| 1100 | {
|
|---|
| 1101 | fStatusFADLabel->setText(s.name.c_str());
|
|---|
| 1102 | fStatusFADLabel->setToolTip(s.comment.c_str());
|
|---|
| 1103 |
|
|---|
| 1104 | if (s.index<FTM::kDisconnected) // No Dim connection
|
|---|
| 1105 | fStatusFADLed->setIcon(QIcon(":/Resources/icons/gray circle 1.png"));
|
|---|
| 1106 | if (s.index==FTM::kDisconnected) // Dim connection / FTM disconnected
|
|---|
| 1107 | fStatusFADLed->setIcon(QIcon(":/Resources/icons/yellow circle 1.png"));
|
|---|
| 1108 | if (s.index==FTM::kConnected) // Dim connection / FTM connected
|
|---|
| 1109 | fStatusFADLed->setIcon(QIcon(":/Resources/icons/green circle 1.png"));
|
|---|
| 1110 | }
|
|---|
| 1111 |
|
|---|
| 1112 | if (server=="DATA_LOGGER")
|
|---|
| 1113 | {
|
|---|
| 1114 | fStatusLoggerLabel->setText(s.name.c_str());
|
|---|
| 1115 | fStatusLoggerLabel->setToolTip(s.comment.c_str());
|
|---|
| 1116 |
|
|---|
| 1117 | bool enable = true;
|
|---|
| 1118 |
|
|---|
| 1119 | if (s.index<=30) // Ready/Waiting
|
|---|
| 1120 | fStatusLoggerLed->setIcon(QIcon(":/Resources/icons/yellow circle 1.png"));
|
|---|
| 1121 | if (s.index<-1) // Offline
|
|---|
| 1122 | {
|
|---|
| 1123 | fStatusLoggerLed->setIcon(QIcon(":/Resources/icons/gray circle 1.png"));
|
|---|
| 1124 | enable = false;
|
|---|
| 1125 | }
|
|---|
| 1126 | if (s.index>=0x100) // Error
|
|---|
| 1127 | fStatusLoggerLed->setIcon(QIcon(":/Resources/icons/red circle 1.png"));
|
|---|
| 1128 | if (s.index==40) // Logging
|
|---|
| 1129 | fStatusLoggerLed->setIcon(QIcon(":/Resources/icons/green circle 1.png"));
|
|---|
| 1130 |
|
|---|
| 1131 | fLoggerWidget->setEnabled(enable);
|
|---|
| 1132 | }
|
|---|
| 1133 |
|
|---|
| 1134 | if (server=="CHAT")
|
|---|
| 1135 | {
|
|---|
| 1136 | fStatusChatLabel->setText(s.name.c_str());
|
|---|
| 1137 |
|
|---|
| 1138 | fChatOnline = s.index==0;
|
|---|
| 1139 |
|
|---|
| 1140 | if (fChatOnline) // Dim connection / FTM connected
|
|---|
| 1141 | fStatusChatLed->setIcon(QIcon(":/Resources/icons/green circle 1.png"));
|
|---|
| 1142 | else
|
|---|
| 1143 | fStatusChatLed->setIcon(QIcon(":/Resources/icons/gray circle 1.png"));
|
|---|
| 1144 | }
|
|---|
| 1145 | }
|
|---|
| 1146 |
|
|---|
| 1147 | void handleStateOffline(const string &server)
|
|---|
| 1148 | {
|
|---|
| 1149 | handleStateChanged(Time(), server, State(-2, "Offline", "No connection via DIM."));
|
|---|
| 1150 | }
|
|---|
| 1151 |
|
|---|
| 1152 | void on_fTabWidget_currentChanged(int which)
|
|---|
| 1153 | {
|
|---|
| 1154 | if (fTabWidget->tabText(which)=="Chat")
|
|---|
| 1155 | fTabWidget->setTabIcon(which, QIcon());
|
|---|
| 1156 | }
|
|---|
| 1157 |
|
|---|
| 1158 | void handleWrite(const Time &time, const string &text, int qos)
|
|---|
| 1159 | {
|
|---|
| 1160 | stringstream out;
|
|---|
| 1161 |
|
|---|
| 1162 | if (text.substr(0, 6)=="CHAT: ")
|
|---|
| 1163 | {
|
|---|
| 1164 | out << "<font size='-1' color='navy'>[<B>";
|
|---|
| 1165 | out << Time::fmt("%H:%M:%S") << time << "</B>]</FONT> ";
|
|---|
| 1166 | out << text.substr(6);
|
|---|
| 1167 | fChatText->append(out.str().c_str());
|
|---|
| 1168 |
|
|---|
| 1169 | if (fTabWidget->tabText(fTabWidget->currentIndex())=="Chat")
|
|---|
| 1170 | return;
|
|---|
| 1171 |
|
|---|
| 1172 | static int num = 0;
|
|---|
| 1173 | if (num++<2)
|
|---|
| 1174 | return;
|
|---|
| 1175 |
|
|---|
| 1176 | for (int i=0; i<fTabWidget->count(); i++)
|
|---|
| 1177 | if (fTabWidget->tabText(i)=="Chat")
|
|---|
| 1178 | {
|
|---|
| 1179 | fTabWidget->setTabIcon(i, QIcon(":/Resources/icons/warning 3.png"));
|
|---|
| 1180 | break;
|
|---|
| 1181 | }
|
|---|
| 1182 |
|
|---|
| 1183 | return;
|
|---|
| 1184 | }
|
|---|
| 1185 |
|
|---|
| 1186 |
|
|---|
| 1187 | out << "<font color='";
|
|---|
| 1188 |
|
|---|
| 1189 | switch (qos)
|
|---|
| 1190 | {
|
|---|
| 1191 | case kMessage: out << "black"; break;
|
|---|
| 1192 | case kInfo: out << "green"; break;
|
|---|
| 1193 | case kWarn: out << "#FF6600"; break;
|
|---|
| 1194 | case kError: out << "maroon"; break;
|
|---|
| 1195 | case kFatal: out << "maroon"; break;
|
|---|
| 1196 | case kDebug: out << "navy"; break;
|
|---|
| 1197 | default: out << "navy"; break;
|
|---|
| 1198 | }
|
|---|
| 1199 | out << "'>" << time.GetAsStr() << " - " << text << "</font>";
|
|---|
| 1200 |
|
|---|
| 1201 | fLogText->append(out.str().c_str());
|
|---|
| 1202 |
|
|---|
| 1203 | if (qos>=kWarn)
|
|---|
| 1204 | fTextEdit->append(out.str().c_str());
|
|---|
| 1205 | }
|
|---|
| 1206 |
|
|---|
| 1207 | void IndicateStateChange(const Time &time, const std::string &server)
|
|---|
| 1208 | {
|
|---|
| 1209 | const State s = GetState(server, GetCurrentState(server));
|
|---|
| 1210 |
|
|---|
| 1211 | QApplication::postEvent(this,
|
|---|
| 1212 | new FunctionEvent(boost::bind(&FactGui::handleStateChanged, this, time, server, s)));
|
|---|
| 1213 | }
|
|---|
| 1214 |
|
|---|
| 1215 | int Write(const Time &time, const string &txt, int qos)
|
|---|
| 1216 | {
|
|---|
| 1217 | QApplication::postEvent(this,
|
|---|
| 1218 | new FunctionEvent(boost::bind(&FactGui::handleWrite, this, time, txt, qos)));
|
|---|
| 1219 |
|
|---|
| 1220 | return 0;
|
|---|
| 1221 | }
|
|---|
| 1222 |
|
|---|
| 1223 | // ====================== Dim infoHandler================================
|
|---|
| 1224 |
|
|---|
| 1225 | void handleDimInfo(const DimData &d)
|
|---|
| 1226 | {
|
|---|
| 1227 | if (d.info==&fDimDNS)
|
|---|
| 1228 | return handleDimDNS(d.get<unsigned int>());
|
|---|
| 1229 |
|
|---|
| 1230 | cout << "HandleDimInfo " << d.name << endl;
|
|---|
| 1231 |
|
|---|
| 1232 | if (d.info==&fDimLoggerStats)
|
|---|
| 1233 | return handleLoggerStats(d);
|
|---|
| 1234 |
|
|---|
| 1235 | if (d.info==&fDimLoggerFilenameNight)
|
|---|
| 1236 | return handleLoggerFilenameNight(d);
|
|---|
| 1237 |
|
|---|
| 1238 | if (d.info==&fDimLoggerNumSubs)
|
|---|
| 1239 | return handleLoggerNumSubs(d);
|
|---|
| 1240 |
|
|---|
| 1241 | if (d.info==&fDimLoggerFilenameRun)
|
|---|
| 1242 | return handleLoggerFilenameRun(d);
|
|---|
| 1243 |
|
|---|
| 1244 | if (d.info==&fDimFtmTriggerCounter)
|
|---|
| 1245 | return handleFtmTriggerCounter(d);
|
|---|
| 1246 |
|
|---|
| 1247 | if (d.info==&fDimFtmDynamicData)
|
|---|
| 1248 | return handleFtmDynamicData(d);
|
|---|
| 1249 |
|
|---|
| 1250 | if (d.info==&fDimFtmPassport)
|
|---|
| 1251 | return handleFtmPassport(d);
|
|---|
| 1252 |
|
|---|
| 1253 | if (d.info==&fDimFtmFtuList)
|
|---|
| 1254 | return handleFtmFtuList(d);
|
|---|
| 1255 |
|
|---|
| 1256 | if (d.info==&fDimFtmStaticData)
|
|---|
| 1257 | return handleFtmStaticData(d);
|
|---|
| 1258 |
|
|---|
| 1259 | if (d.info==&fDimFtmError)
|
|---|
| 1260 | return handleFtmError(d);
|
|---|
| 1261 | }
|
|---|
| 1262 |
|
|---|
| 1263 | void handleDimService(const string &txt)
|
|---|
| 1264 | {
|
|---|
| 1265 | fDimSvcText->append(txt.c_str());
|
|---|
| 1266 | }
|
|---|
| 1267 |
|
|---|
| 1268 |
|
|---|
| 1269 | void infoHandlerService(DimInfo &info)
|
|---|
| 1270 | {
|
|---|
| 1271 | const string fmt = string(info.getFormat()).empty() ? "C" : info.getFormat();
|
|---|
| 1272 |
|
|---|
| 1273 | stringstream dummy;
|
|---|
| 1274 | const Converter conv(dummy, fmt, false);
|
|---|
| 1275 |
|
|---|
| 1276 | const Time tm(info.getTimestamp(), info.getTimestampMillisecs()*1000);
|
|---|
| 1277 |
|
|---|
| 1278 | stringstream out;
|
|---|
| 1279 | out << "<font size'-1' color='navy'>[" << Time::fmt("%H:%M:%S.%f") << tm << "]</font> <B>" << info.getName() << "</B> - ";
|
|---|
| 1280 |
|
|---|
| 1281 | bool iserr = true;
|
|---|
| 1282 | if (!conv)
|
|---|
| 1283 | {
|
|---|
| 1284 | out << "Compilation of format string '" << fmt << "' failed!";
|
|---|
| 1285 | }
|
|---|
| 1286 | else
|
|---|
| 1287 | {
|
|---|
| 1288 | try
|
|---|
| 1289 | {
|
|---|
| 1290 | const string dat = conv.GetString(info.getData(), info.getSize());
|
|---|
| 1291 | out << dat;
|
|---|
| 1292 | iserr = false;
|
|---|
| 1293 | }
|
|---|
| 1294 | catch (const runtime_error &e)
|
|---|
| 1295 | {
|
|---|
| 1296 | out << "Conversion to string failed!<pre>" << e.what() << "</pre>";
|
|---|
| 1297 | }
|
|---|
| 1298 | }
|
|---|
| 1299 |
|
|---|
| 1300 | // srand(hash<string>()(string(info.getName())));
|
|---|
| 1301 | // int bg = rand()&0xffffff;
|
|---|
| 1302 |
|
|---|
| 1303 | int bg = hash<string>()(string(info.getName()));
|
|---|
| 1304 |
|
|---|
| 1305 | // allow only light colors
|
|---|
| 1306 | bg = ~(bg&0x1f1f1f)&0xffffff;
|
|---|
| 1307 |
|
|---|
| 1308 | if (iserr)
|
|---|
| 1309 | bg = 0xffffff;
|
|---|
| 1310 |
|
|---|
| 1311 | stringstream bgcol;
|
|---|
| 1312 | bgcol << hex << setfill('0') << setw(6) << bg;
|
|---|
| 1313 |
|
|---|
| 1314 | const string col = iserr ? "red" : "black";
|
|---|
| 1315 | const string str = "<table width='100%' bgcolor=#"+bgcol.str()+"><tr><td><font color='"+col+"'>"+out.str()+"</font></td></tr></table>";
|
|---|
| 1316 |
|
|---|
| 1317 | QApplication::postEvent(this,
|
|---|
| 1318 | new FunctionEvent(boost::bind(&FactGui::handleDimService, this, str)));
|
|---|
| 1319 | }
|
|---|
| 1320 |
|
|---|
| 1321 | void infoHandler()
|
|---|
| 1322 | {
|
|---|
| 1323 | // Initialize the time-stamp (what a weird workaround...)
|
|---|
| 1324 | getInfo()->getTimestamp();
|
|---|
| 1325 |
|
|---|
| 1326 | if (std::find(fDim.begin(), fDim.end(), getInfo())!=fDim.end())
|
|---|
| 1327 | {
|
|---|
| 1328 | QApplication::postEvent(this,
|
|---|
| 1329 | new FunctionEvent(boost::bind(&FactGui::handleDimInfo, this, DimData(getInfo()))));
|
|---|
| 1330 | return;
|
|---|
| 1331 | }
|
|---|
| 1332 |
|
|---|
| 1333 | for (map<string,DimInfo*>::iterator i=fServices.begin(); i!=fServices.end(); i++)
|
|---|
| 1334 | if (i->second==getInfo())
|
|---|
| 1335 | {
|
|---|
| 1336 | infoHandlerService(*i->second);
|
|---|
| 1337 | return;
|
|---|
| 1338 | }
|
|---|
| 1339 |
|
|---|
| 1340 | DimNetwork::infoHandler();
|
|---|
| 1341 | }
|
|---|
| 1342 |
|
|---|
| 1343 |
|
|---|
| 1344 | // ======================================================================
|
|---|
| 1345 |
|
|---|
| 1346 | bool event(QEvent *evt)
|
|---|
| 1347 | {
|
|---|
| 1348 | if (dynamic_cast<FunctionEvent*>(evt))
|
|---|
| 1349 | return static_cast<FunctionEvent*>(evt)->Exec();
|
|---|
| 1350 |
|
|---|
| 1351 | if (dynamic_cast<CheckBoxEvent*>(evt))
|
|---|
| 1352 | {
|
|---|
| 1353 | const QStandardItem &item = static_cast<CheckBoxEvent*>(evt)->item;
|
|---|
| 1354 | const QStandardItem *par = item.parent();
|
|---|
| 1355 | if (par)
|
|---|
| 1356 | {
|
|---|
| 1357 | const QString server = par->text();
|
|---|
| 1358 | const QString service = item.text();
|
|---|
| 1359 |
|
|---|
| 1360 | const string s = (server+'/'+service).toStdString();
|
|---|
| 1361 |
|
|---|
| 1362 | if (item.checkState()==Qt::Checked)
|
|---|
| 1363 | SubscribeService(s);
|
|---|
| 1364 | else
|
|---|
| 1365 | UnsubscribeService(s);
|
|---|
| 1366 | }
|
|---|
| 1367 | }
|
|---|
| 1368 |
|
|---|
| 1369 | return MainWindow::event(evt); // unrecognized
|
|---|
| 1370 | }
|
|---|
| 1371 |
|
|---|
| 1372 | void on_fDimCmdSend_clicked()
|
|---|
| 1373 | {
|
|---|
| 1374 | const QString server = fDimCmdServers->currentIndex().data().toString();
|
|---|
| 1375 | const QString command = fDimCmdCommands->currentIndex().data().toString();
|
|---|
| 1376 | const QString arguments = fDimCmdLineEdit->displayText();
|
|---|
| 1377 |
|
|---|
| 1378 | // FIXME: Sending a command exactly when the info Handler changes
|
|---|
| 1379 | // the list it might lead to confusion.
|
|---|
| 1380 | try
|
|---|
| 1381 | {
|
|---|
| 1382 | SendDimCommand(server.toStdString(), command.toStdString()+" "+arguments.toStdString());
|
|---|
| 1383 | fTextEdit->append("<font color='green'>Command '"+server+'/'+command+"' successfully emitted.</font>");
|
|---|
| 1384 | fDimCmdLineEdit->clear();
|
|---|
| 1385 | }
|
|---|
| 1386 | catch (const runtime_error &e)
|
|---|
| 1387 | {
|
|---|
| 1388 | stringstream txt;
|
|---|
| 1389 | txt << e.what();
|
|---|
| 1390 |
|
|---|
| 1391 | string buffer;
|
|---|
| 1392 | while (getline(txt, buffer, '\n'))
|
|---|
| 1393 | fTextEdit->append(("<font color='red'><pre>"+buffer+"</pre></font>").c_str());
|
|---|
| 1394 | }
|
|---|
| 1395 | }
|
|---|
| 1396 | void ChoosePatch(Camera &cam, int idx)
|
|---|
| 1397 | {
|
|---|
| 1398 | cam.Reset();
|
|---|
| 1399 |
|
|---|
| 1400 | fThresholdIdx->setValue(idx);
|
|---|
| 1401 | fThresholdVal->setValue(fFtmStaticData.fThreshold[idx<0?0:idx]);
|
|---|
| 1402 |
|
|---|
| 1403 | if (idx<0)
|
|---|
| 1404 | return;
|
|---|
| 1405 |
|
|---|
| 1406 | for (unsigned int i=0; i<fPatch.size(); i++)
|
|---|
| 1407 | if (fPatch[i]==idx)
|
|---|
| 1408 | cam.SetBold(i);
|
|---|
| 1409 | }
|
|---|
| 1410 |
|
|---|
| 1411 | void ChoosePixel(Camera &cam, int idx)
|
|---|
| 1412 | {
|
|---|
| 1413 | cam.SetWhite(idx);
|
|---|
| 1414 | ChoosePatch(cam, fPatch[idx]);
|
|---|
| 1415 | }
|
|---|
| 1416 |
|
|---|
| 1417 | #ifdef HAS_ROOT
|
|---|
| 1418 | void slot_RootEventProcessed(TObject *obj, unsigned int evt, TCanvas *)
|
|---|
| 1419 | {
|
|---|
| 1420 | // kMousePressEvent // TCanvas processed QEvent mousePressEvent
|
|---|
| 1421 | // kMouseMoveEvent // TCanvas processed QEvent mouseMoveEvent
|
|---|
| 1422 | // kMouseReleaseEvent // TCanvas processed QEvent mouseReleaseEvent
|
|---|
| 1423 | // kMouseDoubleClickEvent // TCanvas processed QEvent mouseDoubleClickEvent
|
|---|
| 1424 | // kKeyPressEvent // TCanvas processed QEvent keyPressEvent
|
|---|
| 1425 | // kEnterEvent // TCanvas processed QEvent enterEvent
|
|---|
| 1426 | // kLeaveEvent // TCanvas processed QEvent leaveEvent
|
|---|
| 1427 | if (dynamic_cast<TCanvas*>(obj))
|
|---|
| 1428 | return;
|
|---|
| 1429 |
|
|---|
| 1430 | TQtWidget *tipped = static_cast<TQtWidget*>(sender());
|
|---|
| 1431 |
|
|---|
| 1432 | if (evt==11/*kMouseReleaseEvent*/)
|
|---|
| 1433 | {
|
|---|
| 1434 | if (dynamic_cast<Camera*>(obj))
|
|---|
| 1435 | {
|
|---|
| 1436 | const float xx = gPad->PadtoX(gPad->AbsPixeltoX(tipped->GetEventX()));
|
|---|
| 1437 | const float yy = gPad->PadtoY(gPad->AbsPixeltoY(tipped->GetEventY()));
|
|---|
| 1438 |
|
|---|
| 1439 | Camera *cam = static_cast<Camera*>(obj);
|
|---|
| 1440 | const int idx = cam->GetIdx(xx, yy);
|
|---|
| 1441 |
|
|---|
| 1442 | ChoosePixel(*cam, idx);
|
|---|
| 1443 | }
|
|---|
| 1444 | return;
|
|---|
| 1445 | }
|
|---|
| 1446 |
|
|---|
| 1447 | if (evt==61/*kMouseDoubleClickEvent*/)
|
|---|
| 1448 | {
|
|---|
| 1449 | if (dynamic_cast<Camera*>(obj))
|
|---|
| 1450 | {
|
|---|
| 1451 | const float xx = gPad->PadtoX(gPad->AbsPixeltoX(tipped->GetEventX()));
|
|---|
| 1452 | const float yy = gPad->PadtoY(gPad->AbsPixeltoY(tipped->GetEventY()));
|
|---|
| 1453 |
|
|---|
| 1454 | Camera *cam = static_cast<Camera*>(obj);
|
|---|
| 1455 | const int idx = cam->GetIdx(xx, yy);
|
|---|
| 1456 |
|
|---|
| 1457 | cam->Toggle(idx);
|
|---|
| 1458 | }
|
|---|
| 1459 | return;
|
|---|
| 1460 | }
|
|---|
| 1461 |
|
|---|
| 1462 | // Find the object which will get picked by the GetObjectInfo
|
|---|
| 1463 | // due to buffer overflows in many root-versions
|
|---|
| 1464 | // in TH1 and TProfile we have to work around and implement
|
|---|
| 1465 | // our own GetObjectInfo which make everything a bit more
|
|---|
| 1466 | // complicated.
|
|---|
| 1467 | #if ROOT_VERSION_CODE > ROOT_VERSION(5,22,00)
|
|---|
| 1468 | const char *objectInfo =
|
|---|
| 1469 | obj->GetObjectInfo(tipped->GetEventX(),tipped->GetEventY());
|
|---|
| 1470 | #else
|
|---|
| 1471 | const char *objectInfo = dynamic_cast<TH1*>(obj) ?
|
|---|
| 1472 | "" : obj->GetObjectInfo(tipped->GetEventX(),tipped->GetEventY());
|
|---|
| 1473 | #endif
|
|---|
| 1474 |
|
|---|
| 1475 | QString tipText;
|
|---|
| 1476 | tipText += obj->GetName();
|
|---|
| 1477 | tipText += " [";
|
|---|
| 1478 | tipText += obj->ClassName();
|
|---|
| 1479 | tipText += "]: ";
|
|---|
| 1480 | tipText += objectInfo;
|
|---|
| 1481 |
|
|---|
| 1482 | if (dynamic_cast<Camera*>(obj))
|
|---|
| 1483 | {
|
|---|
| 1484 | const float xx = gPad->PadtoX(gPad->AbsPixeltoX(tipped->GetEventX()));
|
|---|
| 1485 | const float yy = gPad->PadtoY(gPad->AbsPixeltoY(tipped->GetEventY()));
|
|---|
| 1486 |
|
|---|
| 1487 | Camera *cam = static_cast<Camera*>(obj);
|
|---|
| 1488 | int idx = fPatch[cam->GetIdx(xx, yy)];
|
|---|
| 1489 |
|
|---|
| 1490 | tipText+=" Patch=";
|
|---|
| 1491 | tipText+=QString::number(idx);
|
|---|
| 1492 | }
|
|---|
| 1493 |
|
|---|
| 1494 |
|
|---|
| 1495 | fStatusBar->showMessage(tipText, 3000);
|
|---|
| 1496 |
|
|---|
| 1497 | gSystem->ProcessEvents();
|
|---|
| 1498 | //QWhatsThis::display(tipText)
|
|---|
| 1499 | }
|
|---|
| 1500 |
|
|---|
| 1501 | void slot_RootUpdate()
|
|---|
| 1502 | {
|
|---|
| 1503 | gSystem->ProcessEvents();
|
|---|
| 1504 | QTimer::singleShot(0, this, SLOT(slot_RootUpdate()));
|
|---|
| 1505 | }
|
|---|
| 1506 |
|
|---|
| 1507 | void on_fThresholdIdx_valueChanged(int idx)
|
|---|
| 1508 | {
|
|---|
| 1509 | Camera *cam = (Camera*)fRatesCanv->GetCanvas()->FindObject("Camera");
|
|---|
| 1510 | ChoosePatch(*cam, idx);
|
|---|
| 1511 | }
|
|---|
| 1512 | #endif
|
|---|
| 1513 |
|
|---|
| 1514 | TGraph fGraphFtmTemp[4];
|
|---|
| 1515 |
|
|---|
| 1516 | map<int, int> fPatch;
|
|---|
| 1517 |
|
|---|
| 1518 | public:
|
|---|
| 1519 | FactGui() :
|
|---|
| 1520 | fFtuDisabled(40),
|
|---|
| 1521 | fDimDNS("DIS_DNS/VERSION_NUMBER", 1, int(0), this),
|
|---|
| 1522 |
|
|---|
| 1523 | fDimLoggerStats ("DATA_LOGGER/STATS", (void*)NULL, 0, this),
|
|---|
| 1524 | fDimLoggerFilenameNight("DATA_LOGGER/FILENAME_NIGHT", const_cast<char*>(""), 0, this),
|
|---|
| 1525 | fDimLoggerFilenameRun ("DATA_LOGGER/FILENAME_RUN", const_cast<char*>(""), 0, this),
|
|---|
| 1526 | fDimLoggerNumSubs ("DATA_LOGGER/NUM_SUBS", const_cast<char*>(""), 0, this),
|
|---|
| 1527 |
|
|---|
| 1528 | fDimFtmPassport ("FTM_CONTROL/PASSPORT", (void*)NULL, 0, this),
|
|---|
| 1529 | fDimFtmTriggerCounter("FTM_CONTROL/TRIGGER_COUNTER", (void*)NULL, 0, this),
|
|---|
| 1530 | fDimFtmError ("FTM_CONTROL/ERROR", (void*)NULL, 0, this),
|
|---|
| 1531 | fDimFtmFtuList ("FTM_CONTROL/FTU_LIST", (void*)NULL, 0, this),
|
|---|
| 1532 | fDimFtmStaticData ("FTM_CONTROL/STATIC_DATA", (void*)NULL, 0, this),
|
|---|
| 1533 | fDimFtmDynamicData ("FTM_CONTROL/DYNAMIC_DATA", (void*)NULL, 0, this)
|
|---|
| 1534 |
|
|---|
| 1535 |
|
|---|
| 1536 | {
|
|---|
| 1537 | DimClient::sendCommand("CHAT/MSG", "GUI online.");
|
|---|
| 1538 | // + MessageDimRX
|
|---|
| 1539 |
|
|---|
| 1540 | fDim.push_back(&fDimFtmDynamicData);
|
|---|
| 1541 | fDim.push_back(&fDimFtmTriggerCounter);
|
|---|
| 1542 | fDim.push_back(&fDimFtmStaticData);
|
|---|
| 1543 | fDim.push_back(&fDimFtmFtuList);
|
|---|
| 1544 | fDim.push_back(&fDimFtmPassport);
|
|---|
| 1545 | fDim.push_back(&fDimFtmError);
|
|---|
| 1546 | fDim.push_back(&fDimLoggerStats);
|
|---|
| 1547 | fDim.push_back(&fDimLoggerFilenameNight);
|
|---|
| 1548 | fDim.push_back(&fDimLoggerFilenameRun);
|
|---|
| 1549 | fDim.push_back(&fDimLoggerNumSubs);
|
|---|
| 1550 | fDim.push_back(&fDimDNS);
|
|---|
| 1551 |
|
|---|
| 1552 | fTriggerWidget->setEnabled(false);
|
|---|
| 1553 | fFtuWidget->setEnabled(false);
|
|---|
| 1554 | fRatesWidget->setEnabled(false);
|
|---|
| 1555 | fLoggerWidget->setEnabled(false);
|
|---|
| 1556 |
|
|---|
| 1557 | // --------------------------------------------------------------------------
|
|---|
| 1558 |
|
|---|
| 1559 | ifstream fin("fact-trigger-all.txt");
|
|---|
| 1560 |
|
|---|
| 1561 | int l = 0;
|
|---|
| 1562 |
|
|---|
| 1563 | string buf;
|
|---|
| 1564 | while (getline(fin, buf, '\n'))
|
|---|
| 1565 | {
|
|---|
| 1566 | buf = Tools::Trim(buf);
|
|---|
| 1567 | if (buf[0]=='#')
|
|---|
| 1568 | continue;
|
|---|
| 1569 |
|
|---|
| 1570 | stringstream str(buf);
|
|---|
| 1571 | for (int i=0; i<9; i++)
|
|---|
| 1572 | {
|
|---|
| 1573 | int n;
|
|---|
| 1574 | str >> n;
|
|---|
| 1575 |
|
|---|
| 1576 | fPatch[n] = l;
|
|---|
| 1577 | }
|
|---|
| 1578 | l++;
|
|---|
| 1579 | }
|
|---|
| 1580 |
|
|---|
| 1581 | // --------------------------------------------------------------------------
|
|---|
| 1582 | #ifdef HAS_ROOT
|
|---|
| 1583 | TCanvas *c = fFtmTempCanv->GetCanvas();
|
|---|
| 1584 | c->SetBit(TCanvas::kNoContextMenu);
|
|---|
| 1585 | c->SetBorderMode(0);
|
|---|
| 1586 | c->SetFrameBorderMode(0);
|
|---|
| 1587 | c->SetFillColor(kWhite);
|
|---|
| 1588 | c->SetRightMargin(0.03);
|
|---|
| 1589 | c->SetTopMargin(0.03);
|
|---|
| 1590 | c->cd();
|
|---|
| 1591 |
|
|---|
| 1592 | TH1F h("MyFrame", "", 1000, 0, 1);//Time().RootTime()-1./24/60/60, Time().RootTime());
|
|---|
| 1593 | h.SetDirectory(0);
|
|---|
| 1594 | h.SetBit(TH1::kCanRebin);
|
|---|
| 1595 | h.SetStats(kFALSE);
|
|---|
| 1596 | h.SetMinimum(-20);
|
|---|
| 1597 | h.SetMaximum(100);
|
|---|
| 1598 | h.SetXTitle("Time");
|
|---|
| 1599 | h.SetYTitle("Temperature / °C");
|
|---|
| 1600 | h.GetXaxis()->CenterTitle();
|
|---|
| 1601 | h.GetYaxis()->CenterTitle();
|
|---|
| 1602 | // h.GetXaxis()->SetTitleSize(1.2);
|
|---|
| 1603 | // h.GetYaxis()->SetTitleSize(1.2);
|
|---|
| 1604 | h.DrawCopy();
|
|---|
| 1605 |
|
|---|
| 1606 | fGraphFtmTemp[0].SetMarkerStyle(kFullDotSmall);
|
|---|
| 1607 | fGraphFtmTemp[1].SetMarkerStyle(kFullDotSmall);
|
|---|
| 1608 | fGraphFtmTemp[2].SetMarkerStyle(kFullDotSmall);
|
|---|
| 1609 | fGraphFtmTemp[3].SetMarkerStyle(kFullDotSmall);
|
|---|
| 1610 |
|
|---|
| 1611 | fGraphFtmTemp[1].SetLineColor(kBlue);
|
|---|
| 1612 | fGraphFtmTemp[2].SetLineColor(kRed);
|
|---|
| 1613 | fGraphFtmTemp[3].SetLineColor(kGreen);
|
|---|
| 1614 |
|
|---|
| 1615 | fGraphFtmTemp[1].SetMarkerColor(kBlue);
|
|---|
| 1616 | fGraphFtmTemp[2].SetMarkerColor(kRed);
|
|---|
| 1617 | fGraphFtmTemp[3].SetMarkerColor(kGreen);
|
|---|
| 1618 |
|
|---|
| 1619 | fGraphFtmTemp[0].Draw("LP");
|
|---|
| 1620 | fGraphFtmTemp[1].Draw("LP");
|
|---|
| 1621 | fGraphFtmTemp[2].Draw("LP");
|
|---|
| 1622 | fGraphFtmTemp[3].Draw("LP");
|
|---|
| 1623 |
|
|---|
| 1624 | // --------------------------------------------------------------------------
|
|---|
| 1625 |
|
|---|
| 1626 | c = fRatesCanv->GetCanvas();
|
|---|
| 1627 | c->SetBit(TCanvas::kNoContextMenu);
|
|---|
| 1628 | c->SetBorderMode(0);
|
|---|
| 1629 | c->SetFrameBorderMode(0);
|
|---|
| 1630 | c->SetFillColor(kWhite);
|
|---|
| 1631 | c->cd();
|
|---|
| 1632 |
|
|---|
| 1633 | Camera *cam = new Camera;
|
|---|
| 1634 | cam->SetBit(kCanDelete);
|
|---|
| 1635 | cam->Draw();
|
|---|
| 1636 |
|
|---|
| 1637 | ChoosePixel(*cam, 1);
|
|---|
| 1638 |
|
|---|
| 1639 | // QTimer::singleShot(0, this, SLOT(slot_RootUpdate()));
|
|---|
| 1640 |
|
|---|
| 1641 | //widget->setMouseTracking(true);
|
|---|
| 1642 | //widget->EnableSignalEvents(kMouseMoveEvent);
|
|---|
| 1643 |
|
|---|
| 1644 | fFtmTempCanv->setMouseTracking(true);
|
|---|
| 1645 | fFtmTempCanv->EnableSignalEvents(kMouseMoveEvent);
|
|---|
| 1646 |
|
|---|
| 1647 | fRatesCanv->setMouseTracking(true);
|
|---|
| 1648 | fRatesCanv->EnableSignalEvents(kMouseMoveEvent|kMouseReleaseEvent|kMouseDoubleClickEvent);
|
|---|
| 1649 |
|
|---|
| 1650 | connect(fRatesCanv, SIGNAL( RootEventProcessed(TObject*, unsigned int, TCanvas*)),
|
|---|
| 1651 | this, SLOT (slot_RootEventProcessed(TObject*, unsigned int, TCanvas*)));
|
|---|
| 1652 | connect(fFtmTempCanv, SIGNAL( RootEventProcessed(TObject*, unsigned int, TCanvas*)),
|
|---|
| 1653 | this, SLOT (slot_RootEventProcessed(TObject*, unsigned int, TCanvas*)));
|
|---|
| 1654 | #endif
|
|---|
| 1655 | }
|
|---|
| 1656 |
|
|---|
| 1657 | ~FactGui()
|
|---|
| 1658 | {
|
|---|
| 1659 | UnsubscribeAllServers();
|
|---|
| 1660 | }
|
|---|
| 1661 | };
|
|---|
| 1662 |
|
|---|
| 1663 | #endif
|
|---|