File indexing completed on 2025-08-05 08:20:29
0001 #include "PktSizeMonDraw.h"
0002 #include "PktSizeCommon.h"
0003 #include "PktSizeDBodbc.h"
0004
0005 #include <onlmon/OnlMonClient.h>
0006 #include <onlmon/RunDBodbc.h>
0007
0008 #include <phool/phool.h>
0009
0010 #include <TCanvas.h>
0011 #include <TDatime.h>
0012 #include <TGraph.h>
0013 #include <TH2.h>
0014 #include <TLine.h>
0015 #include <TMarker.h>
0016 #include <TPad.h>
0017 #include <TROOT.h>
0018 #include <TStyle.h>
0019 #include <TSystem.h>
0020 #include <TText.h>
0021
0022 #include <cmath>
0023 #include <ctime>
0024 #include <fstream>
0025 #include <iomanip>
0026 #include <sstream>
0027
0028
0029
0030 #define CURRENTNOISY
0031
0032 static int bytelimit = 220;
0033 static float MAXSIZEDISP = 1000.;
0034 static float MAXPKTDISP = 26000.;
0035 static float GRANTXTOFFSET = 20.;
0036
0037 PktSizeMonDraw::PktSizeMonDraw(const std::string &name)
0038 : OnlMonDraw(name)
0039 {
0040 memset(transparent, 0, sizeof(transparent));
0041 memset(TC, 0, sizeof(TC));
0042 memset(Pad, 0, sizeof(Pad));
0043 tm = new TMarker();
0044 tm->SetMarkerStyle(8);
0045 tm->SetMarkerColor(1);
0046 lastrun = 0;
0047 return;
0048 }
0049
0050 PktSizeMonDraw::~PktSizeMonDraw()
0051 {
0052 packetmap.clear();
0053 knownbig.clear();
0054 activepackets.clear();
0055 delete rd;
0056 delete db;
0057 for ( int q = 0; q < 12; q++)
0058 {
0059 delete Frames[q];
0060 }
0061 return;
0062 }
0063
0064 int PktSizeMonDraw::Init()
0065 {
0066 PktSizeCommon::fillgranules(granulepacketlimits);
0067 db = new PktSizeDBodbc(ThisName);
0068 rd = new RunDBodbc();
0069 return 0;
0070 }
0071
0072 int PktSizeMonDraw::MakeCanvas(const char *name)
0073 {
0074 OnlMonClient *cl = OnlMonClient::instance();
0075 int xsize = cl->GetDisplaySizeX();
0076 int ysize = cl->GetDisplaySizeY();
0077 if (!strcmp(name, "PktSizeMon0"))
0078 {
0079
0080 TC[0] = new TCanvas(name, "Packet Size Monitor", -1, 0, xsize / 2, ysize);
0081
0082
0083
0084
0085
0086
0087
0088 }
0089 else if (!strcmp(name, "PktSizeMon1"))
0090 {
0091
0092 TC[1] = new TCanvas(name, "Packet Size History", -xsize / 2, 0, xsize / 2, ysize);
0093 gSystem->ProcessEvents();
0094 Pad[1] = new TPad("pktpad1", "who needs this?", 0.1, 0.05, 0.9, 0.9, 0);
0095 Pad[1]->Draw();
0096
0097 transparent[1] = new TPad("transparent1", "this does not show", 0, 0, 1, 1);
0098 transparent[1]->SetFillStyle(4000);
0099 transparent[1]->Draw();
0100 }
0101 return 0;
0102 }
0103
0104 int PktSizeMonDraw::Draw(const std::string &what)
0105 {
0106 int iret = 0;
0107 int idraw = 0;
0108 if (what == "ALL" || what == "FIRST")
0109 {
0110 iret += DrawFirst(what);
0111 idraw++;
0112 }
0113 if (what == "HISTORY")
0114 {
0115 iret += DrawHistory(what);
0116 idraw++;
0117 }
0118 if (!idraw)
0119 {
0120 std::cout << PHWHERE << " Unimplemented Drawing option: " << what << std::endl;
0121 iret = -1;
0122 }
0123 return iret;
0124 }
0125
0126 int PktSizeMonDraw::DrawFirst(const std::string & )
0127 {
0128 for ( int w = 0; w < 12; w++)
0129 {
0130 delete Frames[w];
0131 }
0132 OnlMonClient *cl = OnlMonClient::instance();
0133 if (!gROOT->FindObject("PktSizeMon0"))
0134 {
0135 MakeCanvas("PktSizeMon0");
0136 }
0137
0138 TH1 *pktsize_hist = cl->getHisto("PKTSIZEMON_0", "pktsize_hist");
0139 if (!pktsize_hist)
0140 {
0141 DrawDeadServer(transparent[0]);
0142 TC[0]->Update();
0143 return -1;
0144 }
0145 TPad* Pads[12];
0146 Pads[0] = new TPad("", "", 0, 0.66, 0.25, 1, 0);
0147 Pads[1] = new TPad("", "", 0.25, 0.66, 0.5, 1, 0);
0148 Pads[2] = new TPad("", "", 0.5, 0.66, 0.75, 1, 0);
0149 Pads[3] = new TPad("", "", 0.75, 0.66, 1, 1, 0);
0150 Pads[4] = new TPad("", "", 0, 0.33, 0.25, 0.66, 0);
0151 Pads[5] = new TPad("", "", 0.25, 0.33, 0.5, 0.66, 0);
0152 Pads[6] = new TPad("", "", 0.5, 0.33, 0.75, 0.66, 0);
0153 Pads[7] = new TPad("", "", 0.75, 0.33, 1, 0.66, 0);
0154 Pads[8] = new TPad("", "", 0, 0, .25, 0.33, 0);
0155 Pads[9] = new TPad("", "", 0.25, 0, 0.5, 0.33, 0);
0156 Pads[10] = new TPad("", "", 0.5, 0, 0.75, 0.33, 0);
0157 Pads[11] = new TPad("", "", 0.75, 0, 1, 0.33, 0);
0158
0159 Frames[0] = new TH2F("h2", "MBD", 2, 1000, 1003, 2, 0, 10000);
0160 Frames[1] = new TH2F("h2", "MVTX", 2, 2000, 2200, 2, 0, 10000);
0161 Frames[2] = new TH2F("h2", "INTT", 2, 3000, 3200, 2, 0, 10000);
0162 Frames[3] = new TH2F("h2", "TPC", 2, 4230, 4232, 2, 0, 10000);
0163 Frames[4] = new TH2F("h2", "TPOT", 2, 5000, 5200, 2, 0, 10000);
0164 Frames[5] = new TH2F("h2", "CEMC", 2, 6000, 6126, 2, 0, 10000);
0165 Frames[6] = new TH2F("h2", "IHCAL", 2, 7000, 7008, 2, 0, 10000);
0166 Frames[7] = new TH2F("h2", "OHCAL", 2, 8000, 8008, 2, 0, 10000);
0167 Frames[8] = new TH2F("h2", "SEPD", 2, 9000, 9002, 2, 0, 10000);
0168 Frames[9] = new TH2F("h2", "ZDC", 2, 12000, 12002, 2, 0, 10000);
0169 Frames[10] = new TH2F("h2", "Local lvl.1", 2, 13999, 14001, 2, 0, 10000);
0170 Frames[11] = new TH2F("h2", "Global lvl.1", 2, 14000, 14002, 2, 0, 10000);
0171
0172 int n = 0;
0173 while (n < 12)
0174 {
0175 Pads[n]->SetLeftMargin(.125);
0176 Pads[n]->Draw();
0177 n = n+1;
0178 }
0179 int x = 0;
0180 while (x < 12)
0181 {
0182 Pads[x]->cd();
0183 Frames[x]->GetXaxis()->SetTitle("Packet ID");
0184 Frames[x]->GetXaxis()->CenterTitle(true);
0185 Frames[x]->GetYaxis()->SetTitle("Packet size (bytes)");
0186 Frames[x]->GetYaxis()->CenterTitle(true);
0187 Frames[x]->SetStats(0);
0188 Frames[x]->DrawClone();
0189 x = x+1;
0190 }
0191
0192 std::map <int, double> packet;
0193 for (int i = 1; i <= pktsize_hist->GetNbinsX(); i++)
0194 {
0195 int a = pktsize_hist->GetBinError(i);
0196 double b = pktsize_hist->GetBinContent(i);
0197 packet[a] = b;
0198 if (a > 999 && a < 1003)
0199 {
0200 Pads[0]-> cd();
0201 tm->DrawMarker(a, packet[a]);
0202 }
0203 else if (a < 1000 || (a > 1002 && a < 2000))
0204 {
0205 std::cout<< "unknown packet id: " << (a) << '\n';
0206 }
0207 if (a > 1999 && a < 2201)
0208 {
0209 Pads[1]-> cd();
0210 tm->DrawMarker(a, packet[a]);
0211 }
0212 else if (a > 2200 && a < 3000)
0213 {
0214 std::cout<< "unknown packet id: " << (a) << '\n';
0215 }
0216 if (a > 2999 && a < 3201)
0217 {
0218 Pads[2]-> cd();
0219 tm->DrawMarker(a, packet[a]);
0220 }
0221 else if (a > 3200 && a < 4231)
0222 {
0223 std::cout<< "unknown packet id: " << (a) << '\n';
0224 }
0225 if (a == 4231)
0226 {
0227 Pads[3]-> cd();
0228 tm->DrawMarker(a, packet[a]);
0229 }
0230 else if (a > 4231 && a < 5000)
0231 {
0232 std::cout<< "unknown packet id: " << (a) << '\n';
0233 }
0234 if (a > 4999 && a < 5201)
0235 {
0236 Pads[4]-> cd();
0237 tm->DrawMarker(a, packet[a]);
0238 }
0239 else if (a > 5200 && a < 6000)
0240 {
0241 std::cout<< "unknown packet id: " << (a) << '\n';
0242 }
0243 if (a > 5999 && a < 6127)
0244 {
0245 Pads[5]-> cd();
0246 tm->DrawMarker(a, packet[a]);
0247 }
0248 else if (a > 6126 && a < 7000)
0249 {
0250 std::cout<< "unknown packet id: " << (a) << '\n';
0251 }
0252 if (a > 6999 && a < 7009)
0253 {
0254 Pads[6]-> cd();
0255 tm->DrawMarker(a, packet[a]);
0256 }
0257 else if ( a > 7008 && a < 8000)
0258 {
0259 std::cout<< "unknown packet id: " << (a) << '\n';
0260 }
0261 if (a > 7999 && a < 8009)
0262 {
0263 Pads[7]-> cd();
0264 tm->DrawMarker(a, packet[a]);
0265 }
0266 else if (a > 8008 && a < 9001)
0267 {
0268 std::cout<< "unknown packet id: " << (a) << '\n';
0269 }
0270 if (a == 9001)
0271 {
0272 Pads[8]-> cd();
0273 tm->DrawMarker(a, packet[a]);
0274 }
0275 else if (a > 9001 && a < 12001)
0276 {
0277 std::cout<< "unknown packet id: " << (a) << '\n';
0278 }
0279 if (a == 12001)
0280 {
0281 Pads[9]-> cd();
0282 tm->DrawMarker(a, packet[a]);
0283 }
0284 else if (a > 12001 && a < 14000)
0285 {
0286 std::cout<< "unknown packet id: " << (a) << '\n';
0287 }
0288 if (a == 14000)
0289 {
0290 Pads[10]-> cd();
0291 tm->DrawMarker(a, packet[a]);
0292 }
0293 if (a == 14001)
0294 {
0295 Pads[11]-> cd();
0296 tm->DrawMarker(a, packet[a]);
0297 }
0298 else if (a > 14001)
0299 {
0300 std::cout<< "unknown packet id: " << (a) << '\n';
0301 }
0302 }
0303 return 0;
0304 }
0305
0306 int PktSizeMonDraw::DrawOldFirst(const std::string & )
0307 {
0308 OnlMonClient *cl = OnlMonClient::instance();
0309 if (!gROOT->FindObject("PktSizeMon0"))
0310 {
0311 MakeCanvas("PktSizeMon0");
0312 }
0313 TC[0]->Clear("D");
0314 TH1 *pktsize_hist = cl->getHisto("PKTSIZEMON_0", "pktsize_hist");
0315 if (!pktsize_hist)
0316 {
0317 DrawDeadServer(transparent[0]);
0318 TC[0]->Update();
0319 return -1;
0320 }
0321 FillPacketMap(pktsize_hist);
0322 TText PrintRun;
0323 PrintRun.SetTextFont(62);
0324 PrintRun.SetTextSize(0.03);
0325 PrintRun.SetNDC();
0326 PrintRun.SetTextAlign(23);
0327 std::ostringstream runnostream;
0328 std::pair<time_t,int> evttime = cl->EventTime("CURRENT");
0329
0330 int runnumber = cl->RunNumber();
0331 runnostream << "Packet Size Display Run " << runnumber
0332 << ", Time: " << ctime(&evttime.first);
0333
0334 PrintRun.SetTextColor(evttime.second);
0335 PrintRun.DrawText(0.5, 0.98, runnostream.str().c_str());
0336 runnostream.str("");
0337 runnostream << "Based on " << pktsize_hist->GetBinContent(0) << " Events";
0338 PrintRun.DrawText(0.5, 0.94, runnostream.str().c_str());
0339 Pad[0]->cd();
0340 TH2 *htmp = new TH2F("pktsize", "", 2, 0, MAXPKTDISP, 2, 0, MAXSIZEDISP);
0341 htmp->SetStats(kFALSE);
0342 htmp->GetXaxis()->SetNoExponent();
0343 htmp->GetXaxis()->SetTitle("Packet Id");
0344 htmp->DrawCopy();
0345 delete htmp;
0346 TLine tl;
0347 tl.DrawLine(0, bytelimit, MAXPKTDISP, bytelimit);
0348 TMarker marker;
0349 TText outtxt;
0350 outtxt.SetTextFont(62);
0351 outtxt.SetTextSize(0.02);
0352 outtxt.SetTextColor(1);
0353 outtxt.SetTextAlign(13);
0354 TLine ta;
0355 TMarker ArrowHead;
0356 ArrowHead.SetMarkerSize(1.5);
0357 ArrowHead.SetMarkerColor(2);
0358 ArrowHead.SetMarkerStyle(26);
0359
0360 ta.SetLineColor(2);
0361 ta.SetLineStyle(1);
0362 std::map<int, std::map<unsigned int, float> >::const_iterator iter;
0363 std::map<unsigned int, float>::const_iterator piter;
0364 iter = packetmap.find(runnumber);
0365 float ypos = MAXSIZEDISP - 100.;
0366 int foundnoisypacket = 0;
0367 if (iter != packetmap.end())
0368 {
0369 marker.SetMarkerStyle(22);
0370 marker.SetMarkerSize(2);
0371 marker.SetMarkerColor(2);
0372 for (piter = iter->second.begin(); piter != iter->second.end(); ++piter)
0373 {
0374 if (piter->second > bytelimit)
0375 {
0376 if (!IsKnownBig(piter->first, piter->second))
0377 {
0378 float linetopend = 9;
0379 marker.DrawMarker((double) (piter->first), piter->second);
0380 std::ostringstream pktid;
0381 pktid << std::setprecision(3) << piter->first << "(" << piter->second << " w)";
0382 int xpos = ((piter->first) / 1000) * 1000;
0383 if (xpos == 21000)
0384 {
0385 xpos = ((piter->first) / 100) * 100;
0386 if (xpos == 21300)
0387 {
0388 linetopend = 50;
0389 }
0390 }
0391 else if (xpos == 7000)
0392 {
0393 xpos = ((piter->first) / 100) * 100;
0394 if (xpos == 7100)
0395 {
0396 linetopend = 50;
0397 }
0398 }
0399 else if (xpos == 24000)
0400 {
0401 xpos = ((piter->first) / 100) * 100;
0402 if (xpos == 24100)
0403 {
0404 linetopend = 50;
0405 }
0406 }
0407 float arrowoffset = linetopend + 6;
0408 ta.DrawLine(xpos, 0, xpos, MAXSIZEDISP + linetopend);
0409 ArrowHead.DrawMarker(xpos, MAXSIZEDISP + arrowoffset);
0410 outtxt.DrawText(xpos, ypos, pktid.str().c_str());
0411 ypos -= 20;
0412 foundnoisypacket = 1;
0413 }
0414 }
0415 }
0416 }
0417 if (!foundnoisypacket)
0418 {
0419 outtxt.SetNDC();
0420 outtxt.SetTextSize(0.05);
0421 outtxt.SetTextColor(3);
0422 outtxt.SetTextAlign(22);
0423 outtxt.DrawText(0.5, 0.7, "Congratulations");
0424 outtxt.DrawText(0.5, 0.5, "No");
0425 outtxt.DrawText(0.5, 0.3, "Noisy Packets");
0426 }
0427 TText granlabel;
0428 granlabel.SetTextAlign(12);
0429 granlabel.SetTextAngle(90);
0430 std::map<std::string, std::pair<unsigned int, unsigned int> >::const_iterator graniter;
0431 for (graniter = granulepacketlimits.begin(); graniter != granulepacketlimits.end(); ++graniter)
0432 {
0433 granlabel.SetTextSize(0.03);
0434 int xpos = ((graniter->second.first) / 1000) * 1000;
0435 if (xpos != 14000)
0436 {
0437 if (xpos == 24000)
0438 {
0439 granlabel.SetTextSize(0.015);
0440 xpos = ((graniter->second.first) / 100) * 100;
0441 if (xpos == 24000)
0442 {
0443 granlabel.DrawText(xpos, MAXSIZEDISP + 20, "VTXP");
0444 }
0445 else
0446 {
0447 granlabel.DrawText(xpos, MAXSIZEDISP + 70, "VTXS");
0448 }
0449 }
0450 else if (xpos == 7000)
0451 {
0452 xpos = ((graniter->second.first) / 100) * 100;
0453 granlabel.SetTextSize(0.015);
0454 if (xpos == 7000)
0455 {
0456 granlabel.DrawText(xpos, MAXSIZEDISP + 20, "TOFE");
0457 }
0458 else
0459 {
0460 granlabel.DrawText(xpos, MAXSIZEDISP + 70, "TOFW");
0461 }
0462 }
0463 else if (xpos == 21000)
0464 {
0465 xpos = ((graniter->second.first) / 100) * 100;
0466 granlabel.SetTextSize(0.015);
0467 if (xpos == 21100)
0468 {
0469 granlabel.DrawText(xpos, MAXSIZEDISP + 20, "MPC");
0470 }
0471 else
0472 {
0473 granlabel.DrawText(xpos, MAXSIZEDISP + 70, "MPCEX");
0474 }
0475 }
0476 else
0477 {
0478 granlabel.DrawText(xpos, MAXSIZEDISP + GRANTXTOFFSET, (graniter->first).c_str());
0479 }
0480 }
0481 }
0482 TC[0]->Update();
0483 return 0;
0484 }
0485
0486 int PktSizeMonDraw::FillPacketMap(const TH1 *pktsize_hist)
0487 {
0488 OnlMonClient *cl = OnlMonClient::instance();
0489 int runnumber = cl->RunNumber();
0490 std::map<int, std::map<unsigned int, float> >::iterator iter;
0491 iter = packetmap.find(runnumber);
0492 if (iter != packetmap.end())
0493 {
0494 iter->second.clear();
0495 }
0496 else
0497 {
0498 std::map<unsigned int, float> newmap;
0499 packetmap[runnumber] = newmap;
0500 iter = packetmap.find(runnumber);
0501 }
0502 for (int i = 1; i <= pktsize_hist->GetNbinsX(); i++)
0503 {
0504 unsigned int packetid = (unsigned int) pktsize_hist->GetBinError(i);
0505 iter->second[packetid] = pktsize_hist->GetBinContent(i);
0506 }
0507 ExtractActivePackets(iter->second);
0508 return 0;
0509 }
0510
0511 int PktSizeMonDraw::SavePlot(const std::string &what, const std::string &type)
0512 {
0513 OnlMonClient *cl = OnlMonClient::instance();
0514 int iret = Draw(what);
0515 if (iret)
0516 {
0517 return iret;
0518 }
0519 int icnt = 0;
0520 for (TCanvas *canvas : TC)
0521 {
0522 if (canvas == nullptr)
0523 {
0524 continue;
0525 }
0526 icnt++;
0527 std::string filename = ThisName + "_" + std::to_string(icnt) + "_" +
0528 std::to_string(cl->RunNumber()) + "." + type;
0529 cl->CanvasToPng(canvas, filename);
0530 }
0531 return 0;
0532 }
0533
0534 int PktSizeMonDraw::MakeHtml(const std::string &what)
0535 {
0536
0537 AddKnownBig(1002, 225);
0538 AddKnownBig(1003, 225);
0539
0540 for (int i = 21101; i <= 21106; i++)
0541 {
0542 AddKnownBig(i, 300);
0543 }
0544
0545
0546 for (int i = 21301; i <= 21308; i++)
0547 {
0548 AddKnownBig(i, 600);
0549 }
0550
0551 for (int i = 21351; i <= 21358; i++)
0552 {
0553 AddKnownBig(i, 600);
0554 }
0555
0556
0557 AddKnownBig(13001, 175);
0558
0559 for (int i = 24001; i < 24061; i++)
0560 {
0561 AddKnownBig(i, 400);
0562 }
0563
0564 for (int i = 24101; i < 24141; i++)
0565 {
0566 AddKnownBig(i, 400);
0567 }
0568 int iret = Draw(what);
0569 if (iret)
0570 {
0571 return iret;
0572 }
0573
0574 OnlMonClient *cl = OnlMonClient::instance();
0575
0576
0577 std::string pngfile = cl->htmlRegisterPage(*this, "PktSize", "1", "png");
0578 cl->CanvasToPng(TC[0], pngfile);
0579 pngfile = cl->htmlRegisterPage(*this, "History", "2", "png");
0580 cl->CanvasToPng(TC[1], pngfile);
0581
0582 cl->SaveLogFile(*this);
0583
0584 return 0;
0585 }
0586
0587 int PktSizeMonDraw::DrawHistory(const std::string & )
0588 {
0589 if (!gROOT->FindObject("PktSizeMon1"))
0590 {
0591 MakeCanvas("PktSizeMon1");
0592 }
0593 OnlMonClient *cl = OnlMonClient::instance();
0594 TH1 *pktsize_hist = cl->getHisto("PKTSIZEMON_0", "pktsize_hist");
0595 if (!pktsize_hist)
0596 {
0597 DrawDeadServer(transparent[1]);
0598 TC[1]->Update();
0599 return -1;
0600 }
0601
0602 if (cl->RunNumber() <= 0)
0603 {
0604 return 0;
0605 }
0606 if (!lastrun)
0607 {
0608 lastrun = cl->RunNumber();
0609 loadpreviousruns();
0610 }
0611 if (lastrun != cl->RunNumber())
0612 {
0613
0614
0615
0616
0617 if (rd->RunType(lastrun) == "PHYSICS")
0618 {
0619 ReplaceRunFromDB(lastrun);
0620 CleanOldRuns(20);
0621 }
0622 else
0623 {
0624 RemoveRun(lastrun);
0625 }
0626 lastrun = cl->RunNumber();
0627 }
0628 MakeNoisyCandidates();
0629 int firstrun = *(runlist.begin());
0630
0631
0632
0633
0634
0635
0636
0637
0638 TText PrintRun;
0639 PrintRun.SetTextFont(62);
0640 PrintRun.SetTextSize(0.03);
0641 PrintRun.SetNDC();
0642 PrintRun.SetTextAlign(23);
0643 int runnumber = cl->RunNumber();
0644 std::ostringstream runnostream;
0645 std::pair<time_t,int> evttime = cl->EventTime("CURRENT");
0646 runnostream << "Packet Size History Run " << runnumber
0647 << ", Time: " << ctime(&evttime.first);
0648 transparent[1]->cd();
0649 PrintRun.SetTextColor(evttime.second);
0650 PrintRun.DrawText(0.5, 0.98, runnostream.str().c_str());
0651 Pad[1]->cd();
0652 TH2 *htmp = new TH2F("noisepkts", "", 2, firstrun - 2, lastrun + 2, 2, 0, MAXSIZEDISP);
0653 htmp->SetStats(kFALSE);
0654 htmp->GetXaxis()->SetNoExponent();
0655 htmp->GetXaxis()->SetTitle("Run");
0656 htmp->GetXaxis()->SetLabelSize(0.025);
0657 htmp->DrawCopy();
0658 delete htmp;
0659 TGraph gr;
0660 TMarker tr;
0661 TText tx;
0662 std::set<unsigned int>::const_iterator iter;
0663 int icnt = 0;
0664 for (iter = noisypackets.begin(); iter != noisypackets.end(); ++iter)
0665 {
0666 PlotNoisy(gr, tr, tx, *iter, icnt);
0667 icnt++;
0668 }
0669 TLine tl;
0670 tl.DrawLine(firstrun - 2, bytelimit, lastrun + 2, bytelimit);
0671 TC[1]->Update();
0672
0673 return 0;
0674 }
0675
0676 int PktSizeMonDraw::loadpreviousruns(const int nruns)
0677 {
0678 std::set<int>::const_iterator iter;
0679 rd->GetRunNumbers(runlist, "PHYSICS", nruns, lastrun);
0680
0681 for (iter = runlist.begin(); iter != runlist.end(); ++iter)
0682 {
0683 std::map<unsigned int, float> pkts;
0684 FillRunPacketList(pkts, *iter);
0685 packetmap[*iter] = pkts;
0686 }
0687 return 0;
0688 }
0689
0690 int PktSizeMonDraw::AddKnownBig(const unsigned int packetid, const float maxsize)
0691 {
0692 knownbig[packetid] = maxsize;
0693 return 0;
0694 }
0695
0696 int PktSizeMonDraw::IsKnownBig(const unsigned int packetid, const float size)
0697 {
0698 std::map<unsigned int, float>::const_iterator iter = knownbig.find(packetid);
0699 if (iter != knownbig.end())
0700 {
0701 if (iter->second > size)
0702 {
0703 return 1;
0704 }
0705 }
0706 return 0;
0707 }
0708
0709 int PktSizeMonDraw::ReplaceRunFromDB(const int runno)
0710 {
0711 std::map<unsigned int, float> pkts;
0712 FillRunPacketList(pkts, runno);
0713 packetmap[runno] = pkts;
0714 return 0;
0715 }
0716
0717 int PktSizeMonDraw::FillRunPacketList(std::map<unsigned int, float> &pkts, const int runnumber)
0718 {
0719 std::map<std::string, std::pair<unsigned int, unsigned int> >::const_iterator graniter;
0720 for (graniter = granulepacketlimits.begin(); graniter != granulepacketlimits.end(); ++graniter)
0721 {
0722 db->GetPacketContent(pkts, runnumber, graniter->first);
0723 }
0724 return 0;
0725 }
0726
0727 int PktSizeMonDraw::CleanOldRuns(const unsigned int maxrun)
0728 {
0729 if (verbosity > 0)
0730 {
0731 std::cout << "Size before cleanup: " << packetmap.size() << std::endl;
0732 }
0733 while (packetmap.size() > maxrun + 1)
0734 {
0735 int runno = (packetmap.begin())->first;
0736 runlist.erase(runno);
0737 packetmap.erase(packetmap.begin());
0738 }
0739 if (verbosity > 0)
0740 {
0741 std::cout << "Size after cleanup: " << packetmap.size() << std::endl;
0742 }
0743 return 0;
0744 }
0745
0746 int PktSizeMonDraw::RemoveRun(const int runno)
0747 {
0748 std::map<int, std::map<unsigned int, float> >::iterator iter;
0749 iter = packetmap.find(runno);
0750 if (iter != packetmap.end())
0751 {
0752 packetmap.erase(iter);
0753 runlist.erase(runno);
0754 }
0755 else
0756 {
0757 std::cout << "Could not find run " << runno << " in list of runs" << std::endl;
0758 }
0759 return 0;
0760 }
0761
0762 void PktSizeMonDraw::Print(const std::string &what) const
0763 {
0764 if (what == "PACKETS" || what == "ALL")
0765 {
0766 std::map<int, std::map<unsigned int, float> >::const_iterator iter;
0767 std::map<unsigned int, float>::const_iterator piter;
0768 for (iter = packetmap.begin(); iter != packetmap.end(); ++iter)
0769 {
0770 for (piter = iter->second.begin(); piter != iter->second.end(); ++piter)
0771 {
0772 std::cout << "Run " << iter->first
0773 << ", packetid: " << piter->first
0774 << ", size: " << piter->second
0775 << std::endl;
0776 }
0777 }
0778 }
0779 if (what == "RUNS" || what == "ALL")
0780 {
0781 std::set<int>::const_iterator riter;
0782 std::cout << "List of runs in Run set: " << std::endl;
0783 for (riter = runlist.begin(); riter != runlist.end(); ++riter)
0784 {
0785 std::cout << "Run " << *riter << std::endl;
0786 }
0787 }
0788 return;
0789 }
0790
0791 int PktSizeMonDraw::ExtractActivePackets(const std::map<unsigned int, float> &packetsize)
0792 {
0793 std::map<unsigned int, float>::const_iterator piter;
0794 for (piter = packetsize.begin(); piter != packetsize.end(); ++piter)
0795 {
0796 activepackets.insert(piter->first);
0797 }
0798 return 0;
0799 }
0800
0801 int PktSizeMonDraw::MakeNoisyCandidates()
0802 {
0803 noisypackets.clear();
0804 #ifdef CURRENTNOISY
0805 OnlMonClient *cl = OnlMonClient::instance();
0806 int runnumber = cl->RunNumber();
0807 std::map<int, std::map<unsigned int, float> >::const_iterator iter;
0808 std::map<unsigned int, float>::const_iterator piter;
0809 iter = packetmap.find(runnumber);
0810 if (iter != packetmap.end())
0811 {
0812 for (piter = iter->second.begin(); piter != iter->second.end(); ++piter)
0813 {
0814 if (piter->second > bytelimit)
0815 {
0816 if (!IsKnownBig(piter->first, piter->second))
0817 {
0818 noisypackets.insert(piter->first);
0819 }
0820 }
0821 }
0822 }
0823
0824 #else
0825 std::set<unsigned int>::const_iterator piter;
0826 std::map<int, std::map<unsigned int, float> >::const_iterator siter;
0827 std::map<unsigned int, float>::const_iterator psizeiter;
0828 for (piter = activepackets.begin(); piter != activepackets.end(); ++piter)
0829 {
0830 float size = -1;
0831 for (siter = packetmap.begin(); siter != packetmap.end(); ++siter)
0832 {
0833 psizeiter = siter->second.find(*piter);
0834 if (psizeiter != siter->second.end())
0835 {
0836 if (size < 0)
0837 {
0838 size = psizeiter->second;
0839 }
0840 else
0841 {
0842 if (psizeiter->second > 200 && fabs(psizeiter->second - size) > size / 5.)
0843 {
0844 if (verbosity > 0)
0845 {
0846 std::cout << "Adding noisy packet " << *piter
0847 << " old size " << size
0848 << " current size " << psizeiter->second
0849 << " current Run " << siter->first
0850 << std::endl;
0851 }
0852 noisypackets.insert(*piter);
0853 }
0854 size = psizeiter->second;
0855 }
0856 }
0857 }
0858 }
0859 #endif
0860 return noisypackets.size();
0861 }
0862
0863 int PktSizeMonDraw::PlotNoisy(TGraph &gr, TMarker &tr, TText &tx, const unsigned int ipkt, const unsigned int icnt)
0864 {
0865 int imarker = 20;
0866 int icol = 1;
0867 std::map<int, std::map<unsigned int, float> >::const_iterator siter;
0868 std::map<unsigned int, float>::const_iterator psizeiter;
0869 std::vector<double> runno, meansize;
0870
0871 for (siter = packetmap.begin(); siter != packetmap.end(); ++siter)
0872 {
0873 psizeiter = siter->second.find(ipkt);
0874 if (psizeiter != siter->second.end())
0875 {
0876 runno.push_back((double) siter->first);
0877 meansize.push_back(psizeiter->second);
0878 }
0879 }
0880 double *x = new double[runno.size()];
0881 double *y = new double[runno.size()];
0882 for (unsigned int i = 0; i < runno.size(); i++)
0883 {
0884 x[i] = runno[i];
0885 y[i] = meansize[i];
0886 }
0887 icol += icnt - (icnt / 9) * 9;
0888 imarker += icnt / 9;
0889 gr.SetMarkerStyle(imarker);
0890 gr.SetMarkerColor(icol);
0891 gr.SetLineColor(icol);
0892 gr.SetMarkerSize(1);
0893 gr.DrawGraph(runno.size(), x, y, "LP");
0894 tr.SetNDC();
0895 tr.SetMarkerStyle(imarker);
0896 tr.SetMarkerColor(icol);
0897 tr.DrawMarker(x[0], (MAXSIZEDISP - 100) - 20 * icnt);
0898 std::ostringstream pktstring;
0899 pktstring << ipkt;
0900 tx.SetTextColor(icol);
0901 tx.SetTextSize(0.03);
0902 double txtXcoord = x[0] + (lastrun - x[0]) / 70;
0903 tx.SetTextAlign(12);
0904 tx.DrawText(txtXcoord, (MAXSIZEDISP - 100) - 20 * icnt, pktstring.str().c_str());
0905 delete[] x;
0906 delete[] y;
0907 return 0;
0908 }