File indexing completed on 2025-08-03 08:21:00
0001 #include "DaqMonDraw.h"
0002
0003 #include <onlmon/OnlMonClient.h>
0004 #include <onlmon/OnlMonDB.h>
0005
0006 #include <TAxis.h> // for TAxis
0007 #include <TCanvas.h>
0008 #include <TDatime.h>
0009 #include <TGraphErrors.h>
0010 #include <TH1.h>
0011 #include <TLine.h>
0012 #include <TPad.h>
0013 #include <TROOT.h>
0014 #include <TSystem.h>
0015 #include <TText.h>
0016
0017 #include <cstring> // for memset
0018 #include <ctime>
0019 #include <fstream>
0020 #include <iostream> // for operator<<, basic_ostream, basic_os...
0021 #include <sstream>
0022 #include <vector> // for vector
0023
0024 DaqMonDraw::DaqMonDraw(const std::string &name)
0025 : OnlMonDraw(name)
0026 {
0027 return;
0028 }
0029
0030 int DaqMonDraw::Init()
0031 {
0032 gStyle->SetOptStat(0);
0033 daqStyle = new TStyle("daqStyle", "daqStyle");
0034
0035
0036
0037
0038
0039
0040
0041
0042 daqStyle->SetOptStat(0);
0043 daqStyle->SetPadTickX(1);
0044 daqStyle->SetPadTickY(1);
0045
0046 Int_t colors[3];
0047 colors[0] = kWhite;
0048 colors[1] = kRed;
0049 colors[2] = kGreen;
0050
0051 daqStyle->SetPalette(3, colors);
0052 daqStyle->SetOptStat(0);
0053 gROOT->SetStyle("daqStyle");
0054 gROOT->ForceStyle();
0055 return 0;
0056 }
0057
0058 int DaqMonDraw::MakeCanvas(const std::string &name)
0059 {
0060 OnlMonClient *cl = OnlMonClient::instance();
0061 int xsize = cl->GetDisplaySizeX();
0062 int ysize = cl->GetDisplaySizeY();
0063 if (name == "DaqMon1")
0064 {
0065
0066 TC[0] = new TCanvas(name.c_str(), "Calo ADC System Clock Check", -1, 0, xsize *0.7, ysize*0.7);
0067
0068
0069
0070
0071 gSystem->ProcessEvents();
0072
0073
0074
0075
0076
0077
0078 Pad[0] = new TPad("hist", "On the top", 0., 0.2, 1., 1.);
0079 Pad[0]->Draw();
0080
0081 transparent[0] = new TPad("transparent0", "this does not show", 0, 0, 1, 1);
0082 transparent[0]->SetFillStyle(4000);
0083 transparent[0]->Draw();
0084 TC[0]->SetEditable(false);
0085 gStyle->SetOptStat(0);
0086 }
0087 else if (name == "DaqMon2")
0088 {
0089 gStyle->SetOptStat(0);
0090 TC[1] = new TCanvas(name.c_str(), "Calo ADC FEM Check", -1, 0, xsize *0.7, ysize * 0.8);
0091 gSystem->ProcessEvents();
0092 Pad[1] = new TPad("pad2", "pad2", 0., 0.2, 1., 1.);
0093 Pad[1]->Draw();
0094 transparent[1] = new TPad("transparent1", "this does not show", 0, 0, 1, 1);
0095 transparent[1]->SetFillStyle(4000);
0096 transparent[1]->Draw();
0097 TC[1]->SetEditable(false);
0098 gStyle->SetOptStat(0);
0099 }
0100 else if (name == "DaqMonServerStats")
0101 {
0102 gStyle->SetOptStat(0);
0103 TC[2] = new TCanvas(name.c_str(), "DaqMon Server Stats", -1, 0, xsize, ysize);
0104 gSystem->ProcessEvents();
0105 transparent[2] = new TPad("transparent2", "this does not show", 0, 0, 1, 1);
0106 transparent[2]->SetFillColor(kGray);
0107 transparent[2]->Draw();
0108 TC[2]->SetEditable(false);
0109 gStyle->SetOptStat(0);
0110 }
0111 return 0;
0112 }
0113
0114 int DaqMonDraw::Draw(const std::string &what)
0115 {
0116 int iret = 0;
0117 int idraw = 0;
0118 if (what == "ALL" || what == "FIRST")
0119 {
0120 iret += DrawFirst(what);
0121 idraw++;
0122 }
0123 if (what == "ALL" || what == "SECOND")
0124 {
0125 iret += DrawSecond(what);
0126 idraw++;
0127 }
0128 if (what == "ALL" || what == "SERVERSTATS")
0129 {
0130 iret += DrawServerStats();
0131 idraw++;
0132 }
0133 if (!idraw)
0134 {
0135 std::cout << __PRETTY_FUNCTION__ << " Unimplemented Drawing option: " << what << std::endl;
0136 iret = -1;
0137 }
0138 return iret;
0139 }
0140
0141 int DaqMonDraw::DrawFirst(const std::string & )
0142 {
0143 gStyle->SetOptStat(0);
0144 OnlMonClient *cl = OnlMonClient::instance();
0145
0146 if (!gROOT->FindObject("DaqMon1"))
0147 {
0148 MakeCanvas("DaqMon1");
0149 }
0150 TC[0]->SetEditable(true);
0151 TC[0]->Clear("D");
0152 TC[0]->SetLeftMargin(0.1);
0153 Pad[0]->cd();
0154 Pad[0]->SetTicks(1, 1);
0155 Pad[0]->SetGrid(1, 0);
0156
0157 int start = -1;
0158 bool IsGL1MisMatch=false;
0159 TH2 *h_gl1_clock_diff[m_ServerSet.size()];
0160 int i = 0;
0161 for (auto server = ServerBegin(); server != ServerEnd(); ++server)
0162 {
0163 h_gl1_clock_diff[i] = (TH2 *) cl->getHisto(*server, "h_gl1_clock_diff");
0164 if (!h_gl1_clock_diff[i])
0165 {
0166 continue;
0167 }
0168 h_gl1_clock_diff[i]->GetXaxis()->SetTitleSize(0);
0169
0170 for (int ibinx = 1; ibinx <= h_gl1_clock_diff[i]->GetNbinsX(); ibinx++)
0171 {
0172 for (int ibiny = 1; ibiny <= h_gl1_clock_diff[i]->GetNbinsY(); ibiny++)
0173 {
0174 float content = h_gl1_clock_diff[i]->GetBinContent(ibinx, ibiny);
0175 if (content < 20)
0176 {
0177 h_gl1_clock_diff[i]->SetBinContent(ibinx, ibiny, 0);
0178 }
0179 }
0180 }
0181
0182 if (start == -1)
0183 {
0184 start = i;
0185 }
0186 else if (i > start)
0187 {
0188 h_gl1_clock_diff[start]->Add(h_gl1_clock_diff[i], 1);
0189 }
0190 i++;
0191 }
0192 if (start < 0)
0193 {
0194 return 0;
0195 }
0196
0197 Int_t color[3];
0198 color[0] = kWhite;
0199 color[1] = kRed;
0200 color[2] = kGreen;
0201 gStyle->SetPalette(3, color);
0202
0203 int nbinsx = h_gl1_clock_diff[start]->GetNbinsX();
0204 int nbinsy = h_gl1_clock_diff[start]->GetNbinsY();
0205 for (int ibx = 1; ibx <= nbinsx; ibx++)
0206 {
0207 for (int iby = 1; iby <= nbinsy; iby++)
0208 {
0209 double content = h_gl1_clock_diff[start]->GetBinContent(ibx,iby);
0210 if(content >0){
0211 h_gl1_clock_diff[start]->SetBinContent(ibx,iby,iby);
0212 }
0213 if(iby==1 && h_gl1_clock_diff[start]->GetBinContent(ibx,iby)>0) IsGL1MisMatch = true;
0214 }
0215 }
0216
0217 h_gl1_clock_diff[start]->Draw("col");
0218 TLine line(h_gl1_clock_diff[start]->GetXaxis()->GetXmin(), h_gl1_clock_diff[start]->GetMaximum()/2, h_gl1_clock_diff[start]->GetXaxis()->GetXmax(), h_gl1_clock_diff[start]->GetMaximum()/2);
0219 line.SetLineColor(kBlack);
0220 TText PrintRun;
0221 PrintRun.SetTextFont(62);
0222 PrintRun.SetTextSize(0.025);
0223 PrintRun.SetNDC();
0224 PrintRun.SetTextAlign(23);
0225 std::ostringstream runnostream;
0226 std::string runstring;
0227 std::pair<time_t,int> evttime = cl->EventTime("CURRENT");
0228
0229 runnostream << ThisName << ": Calo-GL1 Lock Full History, Run" << cl->RunNumber()
0230 << ", Time: " << ctime(&evttime.first);
0231 runstring = runnostream.str();
0232 transparent[0]->cd();
0233 PrintRun.SetTextColor(evttime.second);
0234 PrintRun.DrawText(0.5, 0.99, runstring.c_str());
0235 line.Draw();
0236
0237 TLatex latex;
0238 latex.SetNDC();
0239 latex.SetTextFont(62);
0240
0241 if(IsGL1MisMatch){
0242 latex.SetTextSize(0.035);
0243 latex.SetTextColor(kRed);
0244 latex.DrawLatex(0.21,0.84,"#bf{If this happened within 1 min of the run --> Stop the run}");
0245 latex.DrawLatex(0.21,0.68,"#bf{GL1 Clock Mismatch! Put a special note in the e-log}");
0246 }
0247 else{
0248 latex.SetTextSize(0.035);
0249 latex.SetTextColor(kGreen);
0250 latex.DrawLatex(0.21,0.42,"#bf{Good! GL1 Clock aligned!}");
0251 }
0252
0253 TC[0]->SetEditable(false);
0254 gStyle->SetOptStat(0);
0255 return 0;
0256 }
0257
0258 int DaqMonDraw::DrawSecond(const std::string & )
0259 {
0260 gStyle->SetOptStat(0);
0261 OnlMonClient *cl = OnlMonClient::instance();
0262
0263 if (!gROOT->FindObject("DaqMon2"))
0264 {
0265 MakeCanvas("DaqMon2");
0266 }
0267 TC[1]->SetEditable(true);
0268 TC[1]->Clear("D");
0269 TC[1]->SetLeftMargin(0.1);
0270 Pad[1]->cd();
0271 Pad[1]->SetTicks(1, 1);
0272 Pad[1]->SetGridy(1);
0273
0274 int start = -1;
0275 TH2 *h_fem_match[m_ServerSet.size()];
0276 bool IsMisMatch=false;
0277 int i = 0;
0278 for (auto server = ServerBegin(); server != ServerEnd(); ++server)
0279 {
0280 h_fem_match[i] = (TH2 *) cl->getHisto(Form("DAQMON_%d", i), "h_fem_match");
0281 if (!h_fem_match[i])
0282 {
0283 continue;
0284 }
0285
0286 for (int ibinx = 1; ibinx <= h_fem_match[i]->GetNbinsX(); ibinx++)
0287 {
0288 for (int ibiny = 1; ibiny <= h_fem_match[i]->GetNbinsY(); ibiny++)
0289 {
0290 float content = h_fem_match[i]->GetBinContent(ibinx, ibiny);
0291 if (content < 20)
0292 {
0293 h_fem_match[i]->SetBinContent(ibinx, ibiny, 0);
0294 }
0295 else IsMisMatch = true;
0296 }
0297 }
0298
0299 if (start == -1)
0300 {
0301 start = i;
0302 }
0303 else if (i > start)
0304 {
0305 h_fem_match[start]->Add(h_fem_match[i], 1);
0306 }
0307 i++;
0308 }
0309 if (start < 0)
0310 {
0311 return 0;
0312 }
0313 h_fem_match[start]->GetXaxis()->SetTitleSize(0);
0314 h_fem_match[start]->GetYaxis()->SetTitleSize(0);
0315 h_fem_match[start]->GetYaxis()->SetNdivisions(100);
0316 h_fem_match[start]->GetYaxis()->SetLabelSize(0);
0317
0318 h_fem_match[start]->Draw("col");
0319
0320 TText PrintRun;
0321 PrintRun.SetTextFont(62);
0322 PrintRun.SetTextSize(0.025);
0323 PrintRun.SetNDC();
0324 PrintRun.SetTextAlign(23);
0325 std::ostringstream runnostream;
0326 std::string runstring;
0327 std::pair<time_t,int> evttime = cl->EventTime("CURRENT");
0328
0329 runnostream << ThisName << ": Calo ADC FEM Check, Run" << cl->RunNumber()
0330 << ", Time: " << ctime(&evttime.first);
0331 runstring = runnostream.str();
0332 transparent[1]->cd();
0333 PrintRun.SetTextColor(evttime.second);
0334 PrintRun.DrawText(0.5, 0.99, runstring.c_str());
0335
0336 TLatex latex;
0337 latex.SetNDC();
0338 latex.SetTextFont(62);
0339
0340 if(IsMisMatch){
0341 latex.SetTextSize(0.035);
0342 latex.SetTextColor(kRed);
0343 latex.DrawLatex(0.21,0.74,"#bf{If this happened within 1 min of the run --> Stop the run}");
0344 latex.DrawLatex(0.21,0.6,"#bf{Calo FEM Mismatch! Put a special note in the e-log}");
0345 }
0346 else{
0347 latex.SetTextColor(kGreen+1);
0348 latex.SetTextSize(0.035);
0349 latex.DrawLatex(0.25,0.7,"#bf{Good! FEMs are locked}");
0350 latex.DrawLatex(0.25,0.5,"#bf{Continue data taking}");
0351 }
0352
0353 TC[1]->SetEditable(false);
0354 gStyle->SetOptStat(0);
0355
0356
0357
0358
0359
0360
0361
0362
0363
0364
0365
0366
0367
0368
0369
0370
0371
0372
0373
0374
0375
0376
0377
0378
0379
0380 return 0;
0381 }
0382 int DaqMonDraw::SavePlot(const std::string &what, const std::string &type)
0383 {
0384 OnlMonClient *cl = OnlMonClient::instance();
0385 int iret = Draw(what);
0386 if (iret)
0387 {
0388 return iret;
0389 }
0390 int icnt = 0;
0391 for (TCanvas *canvas : TC)
0392 {
0393 if (canvas == nullptr)
0394 {
0395 continue;
0396 }
0397 icnt++;
0398 std::string filename = ThisName + "_" + std::to_string(icnt) + "_" +
0399 std::to_string(cl->RunNumber()) + "." + type;
0400 cl->CanvasToPng(canvas, filename);
0401 }
0402 return 0;
0403 }
0404 int DaqMonDraw::MakeHtml(const std::string &what)
0405 {
0406 int iret = Draw(what);
0407 if (iret)
0408 {
0409 return iret;
0410 }
0411
0412 OnlMonClient *cl = OnlMonClient::instance();
0413 int icnt = 0;
0414 for (TCanvas *canvas : TC)
0415 {
0416 if (canvas == nullptr)
0417 {
0418 continue;
0419 }
0420 icnt++;
0421
0422 std::string pngfile = cl->htmlRegisterPage(*this, canvas->GetTitle(), std::to_string(icnt), "png");
0423 cl->CanvasToPng(canvas, pngfile);
0424 }
0425
0426
0427
0428
0429
0430
0431
0432
0433
0434
0435
0436
0437
0438
0439
0440
0441
0442 return 0;
0443 }
0444
0445 int DaqMonDraw::DrawServerStats()
0446 {
0447 OnlMonClient *cl = OnlMonClient::instance();
0448 if (!gROOT->FindObject("DaqMonServerStats"))
0449 {
0450 MakeCanvas("DaqMonServerStats");
0451 }
0452 TC[2]->Clear("D");
0453 TC[2]->SetEditable(true);
0454 transparent[2]->cd();
0455 TText PrintRun;
0456 PrintRun.SetTextFont(62);
0457 PrintRun.SetNDC();
0458 PrintRun.SetTextAlign(23);
0459 PrintRun.SetTextSize(0.04);
0460 PrintRun.SetTextColor(1);
0461 PrintRun.DrawText(0.5, 0.99, "Server Statistics");
0462
0463 PrintRun.SetTextSize(0.02);
0464 double vdist = 0.04;
0465 double vstart = 0.92;
0466 double vpos = vstart;
0467 double hpos = 0.5;
0468 int i = 0;
0469 for (const auto &server : m_ServerSet)
0470 {
0471 std::ostringstream txt;
0472 auto servermapiter = cl->GetServerMap(server);
0473 if (servermapiter == cl->GetServerMapEnd())
0474 {
0475 txt << "Server " << server
0476 << " is dead ";
0477 PrintRun.SetTextColor(kRed);
0478 }
0479 else
0480 {
0481 int gl1counts = std::get<4>(servermapiter->second);
0482 txt << "Server " << server
0483 << ", run number " << std::get<1>(servermapiter->second)
0484 << ", event count: " << std::get<2>(servermapiter->second);
0485 if (gl1counts >= 0)
0486 {
0487 txt << ", gl1 count: " << std::get<4>(servermapiter->second);
0488 }
0489 txt << ", current time " << ctime(&(std::get<3>(servermapiter->second)));
0490 if (std::get<0>(servermapiter->second))
0491 {
0492 PrintRun.SetTextColor(kGray+2);
0493 }
0494 else
0495 {
0496 PrintRun.SetTextColor(kRed);
0497 }
0498 }
0499
0500 PrintRun.DrawText(hpos, vpos, txt.str().c_str());
0501 vpos -= vdist;
0502 i++;
0503 }
0504 TC[2]->Update();
0505 TC[2]->Show();
0506 TC[2]->SetEditable(false);
0507
0508 return 0;
0509 }