From 345fc6cda83946d1c91c30e1e7d6abc91b956522 Mon Sep 17 00:00:00 2001 From: Hades DAQ Date: Fri, 21 Feb 2014 13:57:57 +0100 Subject: [PATCH] finished new busy time monitor. --- hmon/HPlot.pm | 50 +++++++++++++++++++++++++++++---------- hmon/hmon_busy.pl | 0 hmon/hmon_busyhist.pl | 0 hmon/hmon_busynew.pl | 54 ++++++++++++++++++++++++++++++++++--------- 4 files changed, 81 insertions(+), 23 deletions(-) mode change 100644 => 100755 hmon/HPlot.pm mode change 100755 => 100644 hmon/hmon_busy.pl mode change 100755 => 100644 hmon/hmon_busyhist.pl diff --git a/hmon/HPlot.pm b/hmon/HPlot.pm old mode 100644 new mode 100755 index 3b9afb9..ef8ea04 --- a/hmon/HPlot.pm +++ b/hmon/HPlot.pm @@ -13,16 +13,18 @@ use constant {OUT_PNG => 1, OUT_SVG => 2, #n/a OUT_SCREEN => 3}; #n/a -my @color= ('#2222dd','#dd2222','#22dd22','#dd8822','#dd22dd','#22dddd','#dddd22','#8888dd','#dddd88'); +my @color= ('#2222dd','#dd2222','#22dd22','#dd8822','#dd22dd','#22dddd','#dddd22','#8888dd','#8822bb'); sub plot_write { my ($file,$str,$no) = @_; return unless $str; if($no || 0) { print $file $str; +# print $str; } else { print $file $str."\n"; +# print $str."\n"; } } @@ -46,6 +48,7 @@ sub PlotInit { $p->{$name} = $c; $p->{$name}->{fh} = $fh; $p->{$name}->{run} = 0; + $p->{$name}->{buffer} = $p->{$name}->{buffer} || 0; $p->{$name}->{sizex} = $p->{$name}->{sizex} || 600 ; $p->{$name}->{sizey} = $p->{$name}->{sizey} || 400 ; $p->{$name}->{file} = $p->{$name}->{file} || "dummy" ; @@ -65,7 +68,7 @@ sub PlotInit { if($p->{$name}->{output} == OUT_PNG) { $p->{$name}->{file} or die "No filename specified"; plot_write($fh,"set term png size ".$p->{$name}->{sizex}.",".$p->{$name}->{sizey}." font \"monospace,8\""); - plot_write($fh,"set out \"".$p->{$name}->{file}.".png\""); + plot_write($fh,"set out \"".$p->{$name}->{file}.($p->{$name}->{buffer}?"tmp":"").".png\""); } elsif($p->{$name}->{output} == OUT_SCREEN) { plot_write($fh,"set term x11 size ".$p->{$name}->{sizex}.",".$p->{$name}->{sizey}); @@ -123,11 +126,17 @@ sub PlotInit { plot_write($fh,"set style fill solid 1.00 border -1"); plot_write($fh,"set grid noxtics ytics"); plot_write($fh,"set boxwidth 2 absolute"); - plot_write($fh,"set xtics ('MDC12' 0,'MDC34' 1,'TOF' 2, 'RPC' 3, 'RICH' 4, 'SHW' 5, 'Start' 6, 'FW' 7) offset 2,0 scale 0"); + plot_write($fh,"set xtics (",1); + for(my $j=0; $j{$name}->{bartitle}};$j++) { + plot_write($fh,', ',1) if $j; + plot_write($fh,"'".$p->{$name}->{bartitle}->[$j]."' $j ",1); + } + plot_write($fh,") offset 2,0 scale 0"); plot_write($fh,"set style histogram title offset character 0, 0, 0"); plot_write($fh,"set style data histograms"); plot_write($fh,"plot ",1); for(my $j=0; $j<$p->{$name}->{curves};$j++) { + plot_write($fh,', ',1) if $j; plot_write($fh,"'-' lt rgb \"$color[$j]\" title \"".($p->{$name}->{titles}->[$j] || "$j")."\" ",1); } plot_write($fh," "); @@ -141,16 +150,29 @@ sub PlotInit { sub PlotDraw { my($name) = @_; + if($p->{$name}->{buffer} && -e $p->{$name}->{file}."tmp.png") { + rename $p->{$name}->{file}."tmp.png", $p->{$name}->{file}.".png"; + } if($p->{$name}->{run}>=1) { - plot_write($p->{$name}->{fh},"set out \"".$p->{$name}->{file}.".png\""); + plot_write($p->{$name}->{fh},"set out \"".$p->{$name}->{file}.($p->{$name}->{buffer}?"tmp":"").".png\""); plot_write($p->{$name}->{fh},makeTimeString()); plot_write($p->{$name}->{fh},"replot"); } for(my $j=0; $j<$p->{$name}->{curves}; $j++) { - for(my $i=0; $i< scalar @{$p->{$name}->{value}->[$j]}; $i++) { - plot_write($p->{$name}->{fh},(($i-$p->{$name}->{entries})/$p->{$name}->{xscale})." ".$p->{$name}->{value}->[$j]->[$i]) unless $p->{$name}->{countup}; - plot_write($p->{$name}->{fh},($i/$p->{$name}->{xscale})." ".$p->{$name}->{value}->[$j]->[$i]) if $p->{$name}->{countup}; -# print $j." ".$i." ".$p->{$name}->{entries}." ".$p->{$name}->{xscale}." ".$p->{$name}->{value}->[$j]->[$i]."\n"; + if($p->{$name}->{type} == TYPE_HISTORY) { + for(my $i=0; $i< $p->{$name}->{entries}; $i++) { + if ($p->{$name}->{countup}) { + plot_write($p->{$name}->{fh},($i/$p->{$name}->{xscale})." ".$p->{$name}->{value}->[$j]->[$i]); + } + else { + plot_write($p->{$name}->{fh},(($i-$p->{$name}->{entries})/$p->{$name}->{xscale})." ".$p->{$name}->{value}->[$j]->[$i]); + } + } + } + elsif($p->{$name}->{type} == TYPE_BARGRAPH) { + for(my $i=0; $i< $p->{$name}->{entries}; $i++) { + plot_write($p->{$name}->{fh},$p->{$name}->{value}->[$j]->[$i]); + } } plot_write($p->{$name}->{fh},"e"); } @@ -162,12 +184,16 @@ sub PlotAdd { my($name,$value,$curve) = @_; $curve = 0 unless $curve; - if($p->{$name}->{type} == TYPE_HISTORY) { - push(@{$p->{$name}->{value}->[$curve]},$value||0); - shift(@{$p->{$name}->{value}->[$curve]}); - } + push(@{$p->{$name}->{value}->[$curve]},$value||0); + shift(@{$p->{$name}->{value}->[$curve]}); } +sub PlotFill { + my($name,$value,$slot,$curve) = @_; + $curve = 0 unless $curve; + $p->{$name}->{value}->[$curve]->[$slot] = $value||0; + } + 1; diff --git a/hmon/hmon_busy.pl b/hmon/hmon_busy.pl old mode 100755 new mode 100644 diff --git a/hmon/hmon_busyhist.pl b/hmon/hmon_busyhist.pl old mode 100755 new mode 100644 diff --git a/hmon/hmon_busynew.pl b/hmon/hmon_busynew.pl index 5c6d0bc..0c87f64 100755 --- a/hmon/hmon_busynew.pl +++ b/hmon/hmon_busynew.pl @@ -34,24 +34,46 @@ $plot->{sizex} = 830; $plot->{sizey} = 420; $plot->{nokey} = 0; $plot->{xscale} = 4; +$plot->{ymin} = -1; +$plot->{ymax} = 101; +$plot->{buffer} = 1; HPlot::PlotInit($plot); -my $plot2=(); +my $plot2 = (); $plot2->{name} = "BusyTimeBars"; $plot2->{file} = "files/BusyTimeBars"; $plot2->{curves} = 1; $plot2->{type} = HPlot::TYPE_BARGRAPH; $plot2->{output} = HPlot::OUT_PNG; $plot2->{ylabel} = "Deadtime (%)"; -$plot2->{sizex} = 265; -$plot2->{sizey} = 380; +$plot2->{sizex} = 380; +$plot2->{sizey} = 265; $plot2->{nokey} = 1; +$plot2->{entries} = 9; +$plot2->{ymin} = -1; +$plot2->{ymax} = 101; +$plot2->{bartitle}->[0] = "M12"; +$plot2->{bartitle}->[1] = "M34"; +$plot2->{bartitle}->[2] = "Shw"; +$plot2->{bartitle}->[3] = "RPC"; +$plot2->{bartitle}->[4] = "Ric"; +$plot2->{bartitle}->[5] = "TOF"; +$plot2->{bartitle}->[6] = "FW"; +$plot2->{bartitle}->[7] = "Sta"; +$plot2->{bartitle}->[8] = "Pi"; +$plot2->{buffer} = 1; +HPlot::PlotInit($plot2); -my $str = Hmon::MakeTitle(12,9,"BusyTimesNew",0); +my $str = Hmon::MakeTitle(12,9,"Busy Times",0); $str .= qq@@; $str .= Hmon::MakeFooter(); - Hmon::WriteFile("BusyTimesNew",$str); + Hmon::WriteFile("busyhist",$str); + $str = Hmon::MakeTitle(5,6,"Busy Times",0); + $str .= qq@@; + $str .= Hmon::MakeFooter(); + Hmon::WriteFile("busy",$str); + my $fqa = QA::OpenQAFile() or die "No connection to QA Logfile"; trb_init_ports() or die trb_strerror(); @@ -61,9 +83,8 @@ my $old; my $iter=0; while (1) { - my $o; my $t = trb_registertime_read_mem(0x8000,0x4030,0,8); - $o->{0x8000} = $t->{0x8000}; + my $o->{0x8000} = $t->{0x8000}; $t = trb_registertime_read_mem(0x8001,0x4030,0,8); $o->{0x8001} = $t->{0x8001}; $t = trb_registertime_read_mem(0x8002,0x4030,0,8); @@ -86,18 +107,29 @@ while (1) { HPlot::PlotAdd('BusyTimes',$diff->{0x8000}->[6],0); #MDC12 HPlot::PlotAdd('BusyTimes',$diff->{0x8000}->[7],1); #MDC34 HPlot::PlotAdd('BusyTimes',$diff->{0x8000}->[3],2); #Shower - HPlot::PlotAdd('BusyTimes',max($diff->{0x8001}->[1],$diff->{0x8001}->[2]),3); #RPC HPlot::PlotAdd('BusyTimes',max($diff->{0x8001}->[3],$diff->{0x8001}->[4],$diff->{0x8001}->[5]),4); #Rich HPlot::PlotAdd('BusyTimes',$diff->{0x8002}->[1],5); #Tof HPlot::PlotAdd('BusyTimes',$diff->{0x8001}->[6],6); #Wall HPlot::PlotAdd('BusyTimes',$diff->{0x8002}->[2],7); #Start/Cts HPlot::PlotAdd('BusyTimes',max($diff->{0x8003}->[1],$diff->{0x8003}->[2]),8); #Pion + + HPlot::PlotFill('BusyTimeBars',$diff->{0x8000}->[6],0,0); #MDC12 + HPlot::PlotFill('BusyTimeBars',$diff->{0x8000}->[7],1,0); #MDC34 + HPlot::PlotFill('BusyTimeBars',$diff->{0x8000}->[3],2,0); #Shower + HPlot::PlotFill('BusyTimeBars',max($diff->{0x8001}->[1],$diff->{0x8001}->[2]),3,0); #RPC + HPlot::PlotFill('BusyTimeBars',max($diff->{0x8001}->[3],$diff->{0x8001}->[4],$diff->{0x8001}->[5]),4,0); #Rich + HPlot::PlotFill('BusyTimeBars',$diff->{0x8002}->[1],5,0); #Tof + HPlot::PlotFill('BusyTimeBars',$diff->{0x8001}->[6],6,0); #Wall + HPlot::PlotFill('BusyTimeBars',$diff->{0x8002}->[2],7,0); #Start/Cts + HPlot::PlotFill('BusyTimeBars',max($diff->{0x8003}->[1],$diff->{0x8003}->[2]),8,0); #Pion + + HPlot::PlotDraw('BusyTimeBars'); + unless(++$iter % 4) { + HPlot::PlotDraw('BusyTimes'); + } } - unless(++$iter % 4) { - HPlot::PlotDraw('BusyTimes'); - } $old = $o; usleep(250000); } -- 2.43.0