Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PktSizeMonDraw.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file PktSizeMonDraw.cc
1 #include "PktSizeMonDraw.h"
2 #include "PktSizeCommon.h"
3 #include "PktSizeDBodbc.h"
4 
5 #include <onlmon/OnlMonClient.h>
6 #include <onlmon/RunDBodbc.h>
7 
8 #include <phool/phool.h>
9 
10 #include <TCanvas.h>
11 #include <TDatime.h>
12 #include <TGraph.h>
13 #include <TH2.h>
14 #include <TLine.h>
15 #include <TMarker.h>
16 #include <TPad.h>
17 #include <TROOT.h>
18 #include <TStyle.h>
19 #include <TSystem.h>
20 #include <TText.h>
21 
22 #include <cmath>
23 #include <ctime>
24 #include <fstream>
25 #include <iomanip>
26 #include <sstream>
27 
28 // make history for currently noisy packets, not packets whose size has
29 // changed significantly with respect to previous runs
30 #define CURRENTNOISY
31 
32 static int bytelimit = 220;
33 static float MAXSIZEDISP = 1000.;
34 static float MAXPKTDISP = 26000.;
35 static float GRANTXTOFFSET = 20.;
36 
38  : OnlMonDraw(name)
39 {
40  memset(transparent, 0, sizeof(transparent));
41  memset(TC, 0, sizeof(TC));
42  memset(Pad, 0, sizeof(Pad));
43  tm = new TMarker();
44  tm->SetMarkerStyle(8);
45  tm->SetMarkerColor(1);
46  lastrun = 0;
47  return;
48 }
49 
51 {
52  packetmap.clear();
53  knownbig.clear();
54  activepackets.clear();
55  delete rd;
56  delete db;
57  for ( int q = 0; q < 12; q++)
58  {
59  delete Frames[q];
60  }
61  return;
62 }
63 
65 {
67  db = new PktSizeDBodbc(ThisName);
68  rd = new RunDBodbc();
69  return 0;
70 }
71 
73 {
75  int xsize = cl->GetDisplaySizeX();
76  int ysize = cl->GetDisplaySizeY();
77  if (!strcmp(name, "PktSizeMon0"))
78  {
79  // xpos (-1) negative: do not draw menu bar
80  TC[0] = new TCanvas(name, "Packet Size Monitor", -1, 0, xsize / 2, ysize);
81  // gSystem->ProcessEvents();
82  // Pad[0] = new TPad("pktpad1", "who needs this?", 0.1, 0.05, 0.9, 0.9, 0);
83  // Pad[0]->Draw();
84  // // this one is used to plot the run number on the canvas
85  // transparent[0] = new TPad("transparent0", "this does not show", 0, 0, 1, 1);
86  // transparent[0]->SetFillStyle(4000);
87  // transparent[0]->Draw();
88  }
89  else if (!strcmp(name, "PktSizeMon1"))
90  {
91  // xpos negative: do not draw menu bar
92  TC[1] = new TCanvas(name, "Packet Size History", -xsize / 2, 0, xsize / 2, ysize);
93  gSystem->ProcessEvents();
94  Pad[1] = new TPad("pktpad1", "who needs this?", 0.1, 0.05, 0.9, 0.9, 0);
95  Pad[1]->Draw();
96  // this one is used to plot the run number on the canvas
97  transparent[1] = new TPad("transparent1", "this does not show", 0, 0, 1, 1);
98  transparent[1]->SetFillStyle(4000);
99  transparent[1]->Draw();
100  }
101  return 0;
102 }
103 
105 {
106  int iret = 0;
107  int idraw = 0;
108  if (what == "ALL" || what == "FIRST")
109  {
110  iret += DrawFirst(what);
111  idraw++;
112  }
113  if (what == "HISTORY")
114  {
115  iret += DrawHistory(what);
116  idraw++;
117  }
118  if (!idraw)
119  {
120  std::cout << PHWHERE << " Unimplemented Drawing option: " << what << std::endl;
121  iret = -1;
122  }
123  return iret;
124 }
125 
127 {
128  for ( int w = 0; w < 12; w++)
129  {
130  delete Frames[w];
131  }
133  if (!gROOT->FindObject("PktSizeMon0"))
134  {
135  MakeCanvas("PktSizeMon0");
136  }
137  // TC[0]->Clear("D");
138  TH1 *pktsize_hist = cl->getHisto("PKTSIZEMON_0", "pktsize_hist");
139  if (!pktsize_hist)
140  {
142  TC[0]->Update();
143  return -1;
144  }
145  TPad* Pads[12];
146  Pads[0] = new TPad("", "", 0, 0.66, 0.25, 1, 0);
147  Pads[1] = new TPad("", "", 0.25, 0.66, 0.5, 1, 0);
148  Pads[2] = new TPad("", "", 0.5, 0.66, 0.75, 1, 0);
149  Pads[3] = new TPad("", "", 0.75, 0.66, 1, 1, 0);
150  Pads[4] = new TPad("", "", 0, 0.33, 0.25, 0.66, 0);
151  Pads[5] = new TPad("", "", 0.25, 0.33, 0.5, 0.66, 0);
152  Pads[6] = new TPad("", "", 0.5, 0.33, 0.75, 0.66, 0);
153  Pads[7] = new TPad("", "", 0.75, 0.33, 1, 0.66, 0);
154  Pads[8] = new TPad("", "", 0, 0, .25, 0.33, 0);
155  Pads[9] = new TPad("", "", 0.25, 0, 0.5, 0.33, 0);
156  Pads[10] = new TPad("", "", 0.5, 0, 0.75, 0.33, 0);
157  Pads[11] = new TPad("", "", 0.75, 0, 1, 0.33, 0);
158 
159  Frames[0] = new TH2F("h2", "MBD", 2, 1000, 1003, 2, 0, 10000);
160  Frames[1] = new TH2F("h2", "MVTX", 2, 2000, 2200, 2, 0, 10000);
161  Frames[2] = new TH2F("h2", "INTT", 2, 3000, 3200, 2, 0, 10000);
162  Frames[3] = new TH2F("h2", "TPC", 2, 4230, 4232, 2, 0, 10000);
163  Frames[4] = new TH2F("h2", "TPOT", 2, 5000, 5200, 2, 0, 10000);
164  Frames[5] = new TH2F("h2", "CEMC", 2, 6000, 6126, 2, 0, 10000);
165  Frames[6] = new TH2F("h2", "IHCAL", 2, 7000, 7008, 2, 0, 10000);
166  Frames[7] = new TH2F("h2", "OHCAL", 2, 8000, 8008, 2, 0, 10000);
167  Frames[8] = new TH2F("h2", "SEPD", 2, 9000, 9002, 2, 0, 10000);
168  Frames[9] = new TH2F("h2", "ZDC", 2, 12000, 12002, 2, 0, 10000);
169  Frames[10] = new TH2F("h2", "Local lvl.1", 2, 13999, 14001, 2, 0, 10000);
170  Frames[11] = new TH2F("h2", "Global lvl.1", 2, 14000, 14002, 2, 0, 10000);
171 
172  int n = 0;
173  while (n < 12)
174  {
175  Pads[n]->SetLeftMargin(.125);
176  Pads[n]->Draw();
177  n = n+1;
178  }
179  int x = 0;
180  while (x < 12)
181  {
182  Pads[x]->cd();
183  Frames[x]->GetXaxis()->SetTitle("Packet ID");
184  Frames[x]->GetXaxis()->CenterTitle(true);
185  Frames[x]->GetYaxis()->SetTitle("Packet size (bytes)");
186  Frames[x]->GetYaxis()->CenterTitle(true);
187  Frames[x]->SetStats(0);
188  Frames[x]->DrawClone();
189  x = x+1;
190  }
191 
192  std::map <int, double> packet;
193  for (int i = 1; i <= pktsize_hist->GetNbinsX(); i++)
194  {
195  int a = pktsize_hist->GetBinError(i);
196  double b = pktsize_hist->GetBinContent(i);
197  packet[a] = b;
198  if (a > 999 && a < 1003)
199  {
200  Pads[0]-> cd();
201  tm->DrawMarker(a, packet[a]);
202  }
203  else if (a < 1000 || (a > 1002 && a < 2000))
204  {
205  std::cout<< "unknown packet id: " << (a) << '\n';
206  }
207  if (a > 1999 && a < 2201)
208  {
209  Pads[1]-> cd();
210  tm->DrawMarker(a, packet[a]);
211  }
212  else if (a > 2200 && a < 3000)
213  {
214  std::cout<< "unknown packet id: " << (a) << '\n';
215  }
216  if (a > 2999 && a < 3201)
217  {
218  Pads[2]-> cd();
219  tm->DrawMarker(a, packet[a]);
220  }
221  else if (a > 3200 && a < 4231)
222  {
223  std::cout<< "unknown packet id: " << (a) << '\n';
224  }
225  if (a == 4231)
226  {
227  Pads[3]-> cd();
228  tm->DrawMarker(a, packet[a]);
229  }
230  else if (a > 4231 && a < 5000)
231  {
232  std::cout<< "unknown packet id: " << (a) << '\n';
233  }
234  if (a > 4999 && a < 5201)
235  {
236  Pads[4]-> cd();
237  tm->DrawMarker(a, packet[a]);
238  }
239  else if (a > 5200 && a < 6000)
240  {
241  std::cout<< "unknown packet id: " << (a) << '\n';
242  }
243  if (a > 5999 && a < 6127)
244  {
245  Pads[5]-> cd();
246  tm->DrawMarker(a, packet[a]);
247  }
248  else if (a > 6126 && a < 7000)
249  {
250  std::cout<< "unknown packet id: " << (a) << '\n';
251  }
252  if (a > 6999 && a < 7009)
253  {
254  Pads[6]-> cd();
255  tm->DrawMarker(a, packet[a]);
256  }
257  else if ( a > 7008 && a < 8000)
258  {
259  std::cout<< "unknown packet id: " << (a) << '\n';
260  }
261  if (a > 7999 && a < 8009)
262  {
263  Pads[7]-> cd();
264  tm->DrawMarker(a, packet[a]);
265  }
266  else if (a > 8008 && a < 9001)
267  {
268  std::cout<< "unknown packet id: " << (a) << '\n';
269  }
270  if (a == 9001)
271  {
272  Pads[8]-> cd();
273  tm->DrawMarker(a, packet[a]);
274  }
275  else if (a > 9001 && a < 12001)
276  {
277  std::cout<< "unknown packet id: " << (a) << '\n';
278  }
279  if (a == 12001)
280  {
281  Pads[9]-> cd();
282  tm->DrawMarker(a, packet[a]);
283  }
284  else if (a > 12001 && a < 14000)
285  {
286  std::cout<< "unknown packet id: " << (a) << '\n';
287  }
288  if (a == 14000)
289  {
290  Pads[10]-> cd();
291  tm->DrawMarker(a, packet[a]);
292  }
293  if (a == 14001)
294  {
295  Pads[11]-> cd();
296  tm->DrawMarker(a, packet[a]);
297  }
298  else if (a > 14001)
299  {
300  std::cout<< "unknown packet id: " << (a) << '\n';
301  }
302  }
303  return 0;
304 }
305 
307 {
309  if (!gROOT->FindObject("PktSizeMon0"))
310  {
311  MakeCanvas("PktSizeMon0");
312  }
313  TC[0]->Clear("D");
314  TH1 *pktsize_hist = cl->getHisto("PKTSIZEMON_0", "pktsize_hist");
315  if (!pktsize_hist)
316  {
318  TC[0]->Update();
319  return -1;
320  }
321  FillPacketMap(pktsize_hist);
322  TText PrintRun;
323  PrintRun.SetTextFont(62);
324  PrintRun.SetTextSize(0.03);
325  PrintRun.SetNDC(); // set to normalized coordinates
326  PrintRun.SetTextAlign(23); // center/top alignment
327  std::ostringstream runnostream;
328  time_t evttime = cl->EventTime("CURRENT");
329  // fill run number and event time into string
330  int runnumber = cl->RunNumber();
331  runnostream << "Packet Size Display Run " << runnumber
332  << ", Time: " << ctime(&evttime);
333  // transparent[0]->cd();
334  PrintRun.DrawText(0.5, 0.98, runnostream.str().c_str());
335  runnostream.str("");
336  runnostream << "Based on " << pktsize_hist->GetBinContent(0) << " Events";
337  PrintRun.DrawText(0.5, 0.94, runnostream.str().c_str());
338  Pad[0]->cd();
339  TH2 *htmp = new TH2F("pktsize", "", 2, 0, MAXPKTDISP, 2, 0, MAXSIZEDISP);
340  htmp->SetStats(kFALSE);
341  htmp->GetXaxis()->SetNoExponent();
342  htmp->GetXaxis()->SetTitle("Packet Id");
343  htmp->DrawCopy();
344  delete htmp;
345  TLine tl;
346  tl.DrawLine(0, bytelimit, MAXPKTDISP, bytelimit);
347  TMarker marker;
348  TText outtxt;
349  outtxt.SetTextFont(62);
350  outtxt.SetTextSize(0.02);
351  outtxt.SetTextColor(1);
352  outtxt.SetTextAlign(13);
353  TLine ta;
354  TMarker ArrowHead;
355  ArrowHead.SetMarkerSize(1.5);
356  ArrowHead.SetMarkerColor(2);
357  ArrowHead.SetMarkerStyle(26);
358 
359  ta.SetLineColor(2);
360  ta.SetLineStyle(1);
361  std::map<int, std::map<unsigned int, float> >::const_iterator iter;
362  std::map<unsigned int, float>::const_iterator piter;
363  iter = packetmap.find(runnumber);
364  float ypos = MAXSIZEDISP - 100.;
365  int foundnoisypacket = 0;
366  if (iter != packetmap.end())
367  {
368  marker.SetMarkerStyle(22);
369  marker.SetMarkerSize(2);
370  marker.SetMarkerColor(2);
371  for (piter = iter->second.begin(); piter != iter->second.end(); ++piter)
372  {
373  if (piter->second > bytelimit)
374  {
375  if (!IsKnownBig(piter->first, piter->second))
376  {
377  float linetopend = 9;
378  marker.DrawMarker((double) (piter->first), piter->second);
379  std::ostringstream pktid;
380  pktid << std::setprecision(3) << piter->first << "(" << piter->second << " w)";
381  int xpos = ((piter->first) / 1000) * 1000;
382  if (xpos == 21000)
383  {
384  xpos = ((piter->first) / 100) * 100;
385  if (xpos == 21300)
386  {
387  linetopend = 50;
388  }
389  }
390  else if (xpos == 7000)
391  {
392  xpos = ((piter->first) / 100) * 100;
393  if (xpos == 7100)
394  {
395  linetopend = 50;
396  }
397  }
398  else if (xpos == 24000)
399  {
400  xpos = ((piter->first) / 100) * 100;
401  if (xpos == 24100)
402  {
403  linetopend = 50;
404  }
405  }
406  float arrowoffset = linetopend + 6;
407  ta.DrawLine(xpos, 0, xpos, MAXSIZEDISP + linetopend);
408  ArrowHead.DrawMarker(xpos, MAXSIZEDISP + arrowoffset);
409  outtxt.DrawText(xpos, ypos, pktid.str().c_str());
410  ypos -= 20;
411  foundnoisypacket = 1;
412  }
413  }
414  }
415  }
416  if (!foundnoisypacket)
417  {
418  outtxt.SetNDC();
419  outtxt.SetTextSize(0.05);
420  outtxt.SetTextColor(3);
421  outtxt.SetTextAlign(22);
422  outtxt.DrawText(0.5, 0.7, "Congratulations");
423  outtxt.DrawText(0.5, 0.5, "No");
424  outtxt.DrawText(0.5, 0.3, "Noisy Packets");
425  }
426  TText granlabel;
427  granlabel.SetTextAlign(12);
428  granlabel.SetTextAngle(90);
429  std::map<std::string, std::pair<unsigned int, unsigned int> >::const_iterator graniter;
430  for (graniter = granulepacketlimits.begin(); graniter != granulepacketlimits.end(); ++graniter)
431  {
432  granlabel.SetTextSize(0.03);
433  int xpos = ((graniter->second.first) / 1000) * 1000;
434  if (xpos != 14000)
435  {
436  if (xpos == 24000)
437  {
438  granlabel.SetTextSize(0.015);
439  xpos = ((graniter->second.first) / 100) * 100;
440  if (xpos == 24000)
441  {
442  granlabel.DrawText(xpos, MAXSIZEDISP + 20, "VTXP");
443  }
444  else
445  {
446  granlabel.DrawText(xpos, MAXSIZEDISP + 70, "VTXS");
447  }
448  }
449  else if (xpos == 7000)
450  {
451  xpos = ((graniter->second.first) / 100) * 100;
452  granlabel.SetTextSize(0.015);
453  if (xpos == 7000)
454  {
455  granlabel.DrawText(xpos, MAXSIZEDISP + 20, "TOFE");
456  }
457  else
458  {
459  granlabel.DrawText(xpos, MAXSIZEDISP + 70, "TOFW");
460  }
461  }
462  else if (xpos == 21000)
463  {
464  xpos = ((graniter->second.first) / 100) * 100;
465  granlabel.SetTextSize(0.015);
466  if (xpos == 21100)
467  {
468  granlabel.DrawText(xpos, MAXSIZEDISP + 20, "MPC");
469  }
470  else
471  {
472  granlabel.DrawText(xpos, MAXSIZEDISP + 70, "MPCEX");
473  }
474  }
475  else
476  {
477  granlabel.DrawText(xpos, MAXSIZEDISP + GRANTXTOFFSET, (graniter->first).c_str());
478  }
479  }
480  }
481  TC[0]->Update();
482  return 0;
483 }
484 
485 int PktSizeMonDraw::FillPacketMap(const TH1 *pktsize_hist)
486 {
488  int runnumber = cl->RunNumber();
489  std::map<int, std::map<unsigned int, float> >::iterator iter;
490  iter = packetmap.find(runnumber);
491  if (iter != packetmap.end())
492  {
493  iter->second.clear();
494  }
495  else
496  {
497  std::map<unsigned int, float> newmap;
498  packetmap[runnumber] = newmap;
499  iter = packetmap.find(runnumber);
500  }
501  for (int i = 1; i <= pktsize_hist->GetNbinsX(); i++)
502  {
503  unsigned int packetid = (unsigned int) pktsize_hist->GetBinError(i);
504  iter->second[packetid] = pktsize_hist->GetBinContent(i);
505  }
506  ExtractActivePackets(iter->second); // make set with all currently active packets
507  return 0;
508 }
509 
511 {
513  int iret = Draw(what);
514  if (iret) // on error no ps files please
515  {
516  return iret;
517  }
518  int icnt = 0;
519  for (TCanvas *canvas : TC)
520  {
521  if (canvas == nullptr)
522  {
523  continue;
524  }
525  icnt++;
526  std::string filename = ThisName + "_" + std::to_string(icnt) + "_" +
527  std::to_string(cl->RunNumber()) + "." + type;
528  cl->CanvasToPng(canvas, filename);
529  }
530  return 0;
531 }
532 
534 {
535  // bbc
536  AddKnownBig(1002, 225);
537  AddKnownBig(1003, 225);
538  // mpc
539  for (int i = 21101; i <= 21106; i++)
540  {
541  AddKnownBig(i, 300);
542  }
543  // mpc-ex
544  // north
545  for (int i = 21301; i <= 21308; i++)
546  {
547  AddKnownBig(i, 600);
548  }
549  // south
550  for (int i = 21351; i <= 21358; i++)
551  {
552  AddKnownBig(i, 600);
553  }
554 
555  // zdc
556  AddKnownBig(13001, 175);
557  // vtxp
558  for (int i = 24001; i < 24061; i++)
559  {
560  AddKnownBig(i, 400);
561  }
562  // vtxs
563  for (int i = 24101; i < 24141; i++)
564  {
565  AddKnownBig(i, 400);
566  }
567  int iret = Draw(what);
568  if (iret) // on error no html output please
569  {
570  return iret;
571  }
572 
574 
575  // Register the 1st canvas png file to the menu and produces the png file.
576  std::string pngfile = cl->htmlRegisterPage(*this, "PktSize", "1", "png");
577  cl->CanvasToPng(TC[0], pngfile);
578  pngfile = cl->htmlRegisterPage(*this, "History", "2", "png");
579  cl->CanvasToPng(TC[1], pngfile);
580 
581  cl->SaveLogFile(*this);
582 
583  return 0;
584 }
585 
587 {
588  if (!gROOT->FindObject("PktSizeMon1"))
589  {
590  MakeCanvas("PktSizeMon1");
591  }
593  TH1 *pktsize_hist = cl->getHisto("PKTSIZEMON_0", "pktsize_hist");
594  if (!pktsize_hist)
595  {
597  TC[1]->Update();
598  return -1;
599  }
600  // prevent runnumber=0/-1 from startup to screw things up
601  if (cl->RunNumber() <= 0)
602  {
603  return 0;
604  }
605  if (!lastrun)
606  {
607  lastrun = cl->RunNumber();
609  }
610  if (lastrun != cl->RunNumber())
611  {
612  // plot only physics run history
613  // if the last run was physics, read it from DB and
614  // enter into list
615  // if not, remove the packet entries from this run from internal list
616  if (rd->RunType(lastrun) == "PHYSICS")
617  {
619  CleanOldRuns(20);
620  }
621  else
622  {
624  }
625  lastrun = cl->RunNumber();
626  }
628  int firstrun = *(runlist.begin());
629  // somehow I see run=0, no idea where this comes from
630  // this led to infinite (or very long) loops in the erase
631  // if ( firstrun < 300000)
632  // {
633  // Print("RUNS");
634  // runlist.erase(runlist.begin());
635  // firstrun = *(runlist.begin());
636  // }
637  TText PrintRun;
638  PrintRun.SetTextFont(62);
639  PrintRun.SetTextSize(0.03);
640  PrintRun.SetNDC(); // set to normalized coordinates
641  PrintRun.SetTextAlign(23); // center/top alignment
642  int runnumber = cl->RunNumber();
643  std::ostringstream runnostream;
644  time_t evttime = cl->EventTime("CURRENT");
645  runnostream << "Packet Size History Run " << runnumber
646  << ", Time: " << ctime(&evttime);
647  transparent[1]->cd();
648  PrintRun.DrawText(0.5, 0.98, runnostream.str().c_str());
649  Pad[1]->cd();
650  TH2 *htmp = new TH2F("noisepkts", "", 2, firstrun - 2, lastrun + 2, 2, 0, MAXSIZEDISP);
651  htmp->SetStats(kFALSE);
652  htmp->GetXaxis()->SetNoExponent();
653  htmp->GetXaxis()->SetTitle("Run");
654  htmp->GetXaxis()->SetLabelSize(0.025);
655  htmp->DrawCopy();
656  delete htmp;
657  TGraph gr;
658  TMarker tr;
659  TText tx;
660  std::set<unsigned int>::const_iterator iter;
661  int icnt = 0;
662  for (iter = noisypackets.begin(); iter != noisypackets.end(); ++iter)
663  {
664  PlotNoisy(gr, tr, tx, *iter, icnt);
665  icnt++;
666  }
667  TLine tl;
668  tl.DrawLine(firstrun - 2, bytelimit, lastrun + 2, bytelimit);
669  TC[1]->Update();
670 
671  return 0;
672 }
673 
675 {
676  std::set<int>::const_iterator iter;
677  rd->GetRunNumbers(runlist, "PHYSICS", nruns, lastrun);
678 
679  for (iter = runlist.begin(); iter != runlist.end(); ++iter)
680  {
681  std::map<unsigned int, float> pkts;
682  FillRunPacketList(pkts, *iter);
683  packetmap[*iter] = pkts;
684  }
685  return 0;
686 }
687 
688 int PktSizeMonDraw::AddKnownBig(const unsigned int packetid, const float maxsize)
689 {
690  knownbig[packetid] = maxsize;
691  return 0;
692 }
693 
694 int PktSizeMonDraw::IsKnownBig(const unsigned int packetid, const float size)
695 {
696  std::map<unsigned int, float>::const_iterator iter = knownbig.find(packetid);
697  if (iter != knownbig.end())
698  {
699  if (iter->second > size)
700  {
701  return 1;
702  }
703  }
704  return 0;
705 }
706 
708 {
709  std::map<unsigned int, float> pkts;
710  FillRunPacketList(pkts, runno);
711  packetmap[runno] = pkts;
712  return 0;
713 }
714 
715 int PktSizeMonDraw::FillRunPacketList(std::map<unsigned int, float> &pkts, const int runnumber)
716 {
717  std::map<std::string, std::pair<unsigned int, unsigned int> >::const_iterator graniter;
718  for (graniter = granulepacketlimits.begin(); graniter != granulepacketlimits.end(); ++graniter)
719  {
720  db->GetPacketContent(pkts, runnumber, graniter->first);
721  }
722  return 0;
723 }
724 
725 int PktSizeMonDraw::CleanOldRuns(const unsigned int maxrun)
726 {
727  if (verbosity > 0)
728  {
729  std::cout << "Size before cleanup: " << packetmap.size() << std::endl;
730  }
731  while (packetmap.size() > maxrun + 1) // current run is in this map -> maxrun+1
732  {
733  int runno = (packetmap.begin())->first;
734  runlist.erase(runno);
735  packetmap.erase(packetmap.begin());
736  }
737  if (verbosity > 0)
738  {
739  std::cout << "Size after cleanup: " << packetmap.size() << std::endl;
740  }
741  return 0;
742 }
743 
744 int PktSizeMonDraw::RemoveRun(const int runno)
745 {
746  std::map<int, std::map<unsigned int, float> >::iterator iter;
747  iter = packetmap.find(runno);
748  if (iter != packetmap.end())
749  {
750  packetmap.erase(iter);
751  runlist.erase(runno);
752  }
753  else
754  {
755  std::cout << "Could not find run " << runno << " in list of runs" << std::endl;
756  }
757  return 0;
758 }
759 
760 void PktSizeMonDraw::Print(const std::string &what) const
761 {
762  if (what == "PACKETS" || what == "ALL")
763  {
764  std::map<int, std::map<unsigned int, float> >::const_iterator iter;
765  std::map<unsigned int, float>::const_iterator piter;
766  for (iter = packetmap.begin(); iter != packetmap.end(); ++iter)
767  {
768  for (piter = iter->second.begin(); piter != iter->second.end(); ++piter)
769  {
770  std::cout << "Run " << iter->first
771  << ", packetid: " << piter->first
772  << ", size: " << piter->second
773  << std::endl;
774  }
775  }
776  }
777  if (what == "RUNS" || what == "ALL")
778  {
779  std::set<int>::const_iterator riter;
780  std::cout << "List of runs in Run set: " << std::endl;
781  for (riter = runlist.begin(); riter != runlist.end(); ++riter)
782  {
783  std::cout << "Run " << *riter << std::endl;
784  }
785  }
786  return;
787 }
788 
789 int PktSizeMonDraw::ExtractActivePackets(const std::map<unsigned int, float> &packetsize)
790 {
791  std::map<unsigned int, float>::const_iterator piter;
792  for (piter = packetsize.begin(); piter != packetsize.end(); ++piter)
793  {
794  activepackets.insert(piter->first);
795  }
796  return 0;
797 }
798 
800 {
801  noisypackets.clear();
802 #ifdef CURRENTNOISY
804  int runnumber = cl->RunNumber();
805  std::map<int, std::map<unsigned int, float> >::const_iterator iter;
806  std::map<unsigned int, float>::const_iterator piter;
807  iter = packetmap.find(runnumber);
808  if (iter != packetmap.end())
809  {
810  for (piter = iter->second.begin(); piter != iter->second.end(); ++piter)
811  {
812  if (piter->second > bytelimit)
813  {
814  if (!IsKnownBig(piter->first, piter->second))
815  {
816  noisypackets.insert(piter->first);
817  }
818  }
819  }
820  }
821 
822 #else
823  std::set<unsigned int>::const_iterator piter;
824  std::map<int, std::map<unsigned int, float> >::const_iterator siter;
825  std::map<unsigned int, float>::const_iterator psizeiter;
826  for (piter = activepackets.begin(); piter != activepackets.end(); ++piter)
827  {
828  float size = -1;
829  for (siter = packetmap.begin(); siter != packetmap.end(); ++siter)
830  {
831  psizeiter = siter->second.find(*piter);
832  if (psizeiter != siter->second.end())
833  {
834  if (size < 0)
835  {
836  size = psizeiter->second;
837  }
838  else
839  {
840  if (psizeiter->second > 200 && fabs(psizeiter->second - size) > size / 5.)
841  {
842  if (verbosity > 0)
843  {
844  std::cout << "Adding noisy packet " << *piter
845  << " old size " << size
846  << " current size " << psizeiter->second
847  << " current Run " << siter->first
848  << std::endl;
849  }
850  noisypackets.insert(*piter);
851  }
852  size = psizeiter->second;
853  }
854  }
855  }
856  }
857 #endif
858  return noisypackets.size();
859 }
860 
861 int PktSizeMonDraw::PlotNoisy(TGraph &gr, TMarker &tr, TText &tx, const unsigned int ipkt, const unsigned int icnt)
862 {
863  int imarker = 20;
864  int icol = 1;
865  std::map<int, std::map<unsigned int, float> >::const_iterator siter;
866  std::map<unsigned int, float>::const_iterator psizeiter;
867  std::vector<double> runno, meansize;
868 
869  for (siter = packetmap.begin(); siter != packetmap.end(); ++siter)
870  {
871  psizeiter = siter->second.find(ipkt);
872  if (psizeiter != siter->second.end())
873  {
874  runno.push_back((double) siter->first);
875  meansize.push_back(psizeiter->second);
876  }
877  }
878  double *x = new double[runno.size()];
879  double *y = new double[runno.size()];
880  for (unsigned int i = 0; i < runno.size(); i++)
881  {
882  x[i] = runno[i];
883  y[i] = meansize[i];
884  }
885  icol += icnt - (icnt / 9) * 9;
886  imarker += icnt / 9;
887  gr.SetMarkerStyle(imarker);
888  gr.SetMarkerColor(icol);
889  gr.SetLineColor(icol);
890  gr.SetMarkerSize(1);
891  gr.DrawGraph(runno.size(), x, y, "LP");
892  tr.SetNDC();
893  tr.SetMarkerStyle(imarker);
894  tr.SetMarkerColor(icol);
895  tr.DrawMarker(x[0], (MAXSIZEDISP - 100) - 20 * icnt);
896  std::ostringstream pktstring;
897  pktstring << ipkt;
898  tx.SetTextColor(icol);
899  tx.SetTextSize(0.03);
900  double txtXcoord = x[0] + (lastrun - x[0]) / 70;
901  tx.SetTextAlign(12);
902  tx.DrawText(txtXcoord, (MAXSIZEDISP - 100) - 20 * icnt, pktstring.str().c_str());
903  delete[] x;
904  delete[] y;
905  return 0;
906 }