From a688504132988efef5a27ac07ea33689f7475d71 Mon Sep 17 00:00:00 2001 From: Hades DAQ Date: Thu, 24 Jan 2019 14:06:49 +0100 Subject: [PATCH] update HPlot with features from Hades DAQ --- tools/HPlot.pm | 211 ++++++++++++++++++++++++++++--------------------- 1 file changed, 122 insertions(+), 89 deletions(-) diff --git a/tools/HPlot.pm b/tools/HPlot.pm index 88e5ceb..4f1087e 100755 --- a/tools/HPlot.pm +++ b/tools/HPlot.pm @@ -48,7 +48,7 @@ sub setranges { } elsif(defined $min) { plot_write($fh,"set $name [$min:]"); - } + } } sub PlotInit { @@ -71,11 +71,14 @@ sub PlotInit { $p->{$name}->{file} = $p->{$name}->{file} || "dummy" ; $p->{$name}->{curves} = $p->{$name}->{curves} || 1 ; $p->{$name}->{xscale} = $p->{$name}->{xscale} || 1; + $p->{$name}->{yscale} = $p->{$name}->{yscale} || 1; + $p->{$name}->{cbscale} = $p->{$name}->{cbscale} || 1; $p->{$name}->{type} or die "No plot type specified"; $p->{$name}->{output} or die "No destination specified"; $p->{$name}->{colors} = $p->{$name}->{colors} || \@color; $p->{$name}->{showvalues} = $p->{$name}->{showvalues} || 0; $p->{$name}->{storable} = $p->{$name}->{storable} || 0; + $p->{$name}->{plot_string} = ""; # to store the plot command $p->{$name}->{xticks} = $p->{$name}->{xticks} || 0; $p->{$name}{additional} = $p->{$name}{additional} || ''; @@ -84,13 +87,15 @@ sub PlotInit { $storefile->{$name} = $name.'-'.$p->{$name}->{curves}.'-'.$p->{$name}->{entries}.'-'.$filename.'.store'; $storefile->{$name} =~ s%/%%g; $storefile->{$name} = "/dev/shm/".$storefile->{$name}; - - foreach my $i (0..($c->{entries}-1)) { - for my $j (0..($c->{curves}-1)) { - push(@{$p->{$name}->{value}->[$j]},0) ; + + unless ($p->{$name}{noinit}) { + foreach my $i (0..($c->{entries}-1)) { + for my $j (0..($c->{curves}-1)) { + push(@{$p->{$name}->{value}->[$j]},0) ; + } } - } - + } + if($p->{$name}->{storable}) { if (-e $storefile->{$name}) { $p->{$name}->{value} = lock_retrieve($storefile->{$name}); @@ -120,6 +125,7 @@ sub PlotInit { plot_write($fh,"set xlabel \"".$p->{$name}->{xlabel}."\"") if $p->{$name}->{xlabel}; plot_write($fh,"set ylabel \"".$p->{$name}->{ylabel}."\"") if $p->{$name}->{ylabel}; + plot_write($fh,"set cblabel \"".$p->{$name}->{cblabel}."\"") if $p->{$name}->{cblabel}; setranges($fh,'xrange',$p->{$name}->{xmin},$p->{$name}->{xmax}); setranges($fh,'yrange',$p->{$name}->{ymin},$p->{$name}->{ymax}); @@ -128,91 +134,108 @@ sub PlotInit { if($p->{$name}->{addCmd} && $p->{$name}->{addCmd} ne "") { plot_write($fh,$p->{$name}->{addCmd}); - } - - if($p->{$name}->{type} == TYPE_HISTORY) { - if($p->{$name}->{fill}) { + } + + if ($p->{$name}->{type} == TYPE_HISTORY) { + if ($p->{$name}->{fill}) { plot_write($fh,"set style fill solid 1.00"); - } + } else { plot_write($fh,"set style fill solid 0"); - } + } plot_write($fh,"set boxwidth 2 absolute"); plot_write($fh,"set autoscale fix"); plot_write($fh,"set xtics autofreq"); #$p->{$name}->{entries} plot_write($fh,"set grid"); plot_write($fh,$p->{$name}{additional}) if $p->{$name}{additional}; -# plot_write($fh,"set style fill solid 1.0"); - plot_write($fh,"plot ",1,$name); - for(my $j=0; $j<$p->{$name}->{curves};$j++) { - if($p->{$name}->{fill}) { - plot_write($fh,"'-' using 1:2 with filledcurves x1 lt rgb \"".$p->{$name}->{colors}->[$j]."\" title \"".($p->{$name}->{titles}->[$j] || "$j")."\" ",1,$name); - } - elsif($p->{$name}->{dots}) { - plot_write($fh,"'-' using 1:2 with points pointsize 0.6 pointtype 2 lt rgb \"".$p->{$name}->{colors}->[$j]."\" title \"".($p->{$name}->{titles}->[$j] || "$j")."\" ",1,$name); - } + # plot_write($fh,"set style fill solid 1.0"); + #plot_write($fh,"plot ",1); + $p->{$name}->{plot_string} .= "plot "; + for (my $j=0; $j<$p->{$name}->{curves};$j++) { + if ($p->{$name}->{fill}) { + #plot_write($fh,"'-' using 1:2 with filledcurves x1 lt rgb \"".$p->{$name}->{colors}->[$j]."\" title \"".($p->{$name}->{titles}->[$j] || "$j")."\" ",1); + $p->{$name}->{plot_string} .= "'-' using 1:2 with filledcurves x1 lt rgb \"".$p->{$name}->{colors}->[$j]."\" title \"".($p->{$name}->{titles}->[$j] || "$j")."\" "; + } + elsif ($p->{$name}->{dots}) { + #plot_write($fh,"'-' using 1:2 with points pointsize 0.6 pointtype 2 lt rgb \"".$p->{$name}->{colors}->[$j]."\" title \"".($p->{$name}->{titles}->[$j] || "$j")."\" ",1); + $p->{$name}->{plot_string} .= "'-' using 1:2 with points pointsize 0.6 pointtype 2 lt rgb \"".$p->{$name}->{colors}->[$j]."\" title \"".($p->{$name}->{titles}->[$j] || "$j")."\" "; + } else { - plot_write($fh,"'-' using 1:2 with lines lt rgb \"".$p->{$name}->{colors}->[$j]."\" title \"".($p->{$name}->{titles}->[$j] || "$j")."\" ",1,$name); - } - plot_write($fh,', ',1,$name) unless ($j+1==$p->{$name}->{curves}); + #plot_write($fh,"'-' using 1:2 with lines lt rgb \"".$p->{$name}->{colors}->[$j]."\" title \"".($p->{$name}->{titles}->[$j] || "$j")."\" ",1); + $p->{$name}->{plot_string} .= "'-' using 1:2 with lines lt rgb \"".$p->{$name}->{colors}->[$j]."\" title \"".($p->{$name}->{titles}->[$j] || "$j")."\" "; } - plot_write($fh," ",0,$name); + #plot_write($fh,', ',1) unless ($j+1==$p->{$name}->{curves}); + $p->{$name}->{plot_string} .= ', ' unless ($j+1==$p->{$name}->{curves}); } - elsif($p->{$name}->{type} == TYPE_BARGRAPH) { - my $stacked = $p->{$name}{stacked}?' rowstacked':''; - print $stacked; - plot_write($fh,"set style fill solid 1.00 border -1"); + #plot_write($fh," "); + $p->{$name}->{plot_string} .= " \n"; + plot_write($fh, $p->{$name}->{plot_string}); + } + elsif ($p->{$name}->{type} == TYPE_BARGRAPH) { + my $stacked = $p->{$name}{stacked}?'rowstacked':''; + #print $stacked; + plot_write($fh,"set style fill solid 1.00 "); plot_write($fh,"set grid noxtics ytics"); plot_write($fh,"set boxwidth ".($p->{$name}->{curvewidth}||4)." absolute"); - plot_write($fh,"set style histogram gap ".($p->{$name}->{bargap}||1).' '.$stacked); -#title offset character 0, 0, 0 + plot_write($fh,"set style histogram ".$stacked." gap ".($p->{$name}->{bargap}||1)); if($p->{$name}->{xticks}) { plot_write("set xtics rotate by 90 offset .7,-1.7 scale .7 "); - } + } - if(defined $p->{$name}->{bartitle} && scalar @{$p->{$name}->{bartitle}}) { + if (defined $p->{$name}->{bartitle} && scalar @{$p->{$name}->{bartitle}}) { plot_write($fh,"set xtics (",1); - for(my $j=0; $j{$name}->{bartitle}};$j++) { + 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.5,0 scale 0"); } + plot_write($fh,") offset ".($p->{$name}->{xtickoffset}//0).",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,$p->{$name}{additional}); - - plot_write($fh,"plot ",1,$name); - for(my $j=0; $j<$p->{$name}->{curves};$j++) { - plot_write($fh,', ',1,$name) if $j; - plot_write($fh,"'-' with histograms ",1,$name); - plot_write($fh,"using 2:xticlabels(1) ",1,$name) if ($p->{$name}->{xticks}); - plot_write($fh, "lt rgb \"".$p->{$name}->{colors}->[$j]."\" title \"".($p->{$name}->{titles}->[$j] || "$j")."\" ",1,$name); - } - plot_write($fh," ",0,$name); + #plot_write($fh,"plot ",1); + $p->{$name}->{plot_string} .= "plot "; + for (my $j=0; $j<$p->{$name}->{curves};$j++) { + ##plot_write($fh,', ',1) if $j; + $p->{$name}->{plot_string} .= ', ' if $j; + ##plot_write($fh,"'-' lt rgb \"".$p->{$name}->{colors}->[$j]."\" title \"".($p->{$name}->{titles}->[$j] || "$j")."\" ",1); + #$p->{$name}->{plot_string} .= "'-' lt rgb \"".$p->{$name}->{colors}->[$j]."\" title \"".($p->{$name}->{titles}->[$j] || "$j")."\" "; + + $p->{$name}->{plot_string} .= "'-' with histograms "; + $p->{$name}->{plot_string} .= "using 2:xticlabels(1) " if ($p->{$name}->{xticks}); + $p->{$name}->{plot_string} .= "lt rgb \"".$p->{$name}->{colors}->[$j]."\" title \"".($p->{$name}->{titles}->[$j] || "$j")."\" "; } - elsif($p->{$name}->{type} == TYPE_HEATMAP) { + #plot_write($fh," "); + $p->{$name}->{plot_string} .= " \n"; + plot_write($fh, $p->{$name}->{plot_string}); + } + elsif ($p->{$name}->{type} == TYPE_HEATMAP) { plot_write($fh,"set view map"); if(defined $p->{$name}->{palette}) { plot_write($fh,"set palette ".$p->{$name}->{palette}); } else { plot_write($fh,"set palette rgbformulae 22,13,-31"); - } + } + plot_write($fh,$p->{$name}{additional}); if ($p->{$name}->{showvalues} == 0) { - plot_write($fh,"splot '-' matrix with image",0,$name); - } + #plot_write($fh,"splot '-' matrix with image"); + $p->{$name}->{plot_string} .= "plot '-' matrix with image \n" + } else { - plot_write($fh,"plot '-' matrix with image, '-' matrix using 1:2:(sprintf('%i', \$3)) with labels tc rgb \"#ffffff\" font ',10'",0,$name); -# plot_write($fh,"plot '-' matrix with image, '-' matrix using 1:2:(sprintf('%i', \$3)):3 with labels tc palette font ',10'"); - } + #plot_write($fh,"plot '-' matrix with image, '-' matrix using 1:2:(sprintf('%i', \$3)) with labels tc rgb \"#ffffff\" font ',10'"); + $p->{$name}->{plot_string} .= "plot '-' matrix with image, '-' matrix using 1:2:(sprintf('%i', \$3)) with labels tc rgb \"#ffffff\" font ',10'"; + #### plot_write($fh,"plot '-' matrix with image, '-' matrix using 1:2:(sprintf('%i', \$3)):3 with labels tc palette font ',10'"); } + plot_write($fh, $p->{$name}->{plot_string}); + } else { die "Plot type not supported"; - } - } +} + sub PlotDraw { my($name) = @_; @@ -222,63 +245,68 @@ sub PlotDraw { if($p->{$name}->{run}>=1) { 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},$plotstring->{$name}); + plot_write($p->{$name}->{fh}, $p->{$name}->{plot_string}); } + + if($p->{$name}->{type} == TYPE_HISTORY) { my $realentries = $p->{$name}{limitentries} || $p->{$name}->{entries}; for(my $j=0; $j<$p->{$name}->{curves}; $j++) { for(my $i=$p->{$name}->{entries}-$realentries; $i< $p->{$name}->{entries}; $i++) { if ($p->{$name}->{countup}) { - plot_write($p->{$name}->{fh},(($i-($p->{$name}->{entries}-$realentries))/$p->{$name}->{xscale})." ".$p->{$name}->{value}->[$j]->[$i]); + plot_write($p->{$name}->{fh},(($i-($p->{$name}->{entries}-$realentries))/$p->{$name}->{xscale})." ".$p->{$name}->{value}->[$j]->[$i]/($p->{$name}->{yscale}||1)); } else { - plot_write($p->{$name}->{fh},(($i-$realentries)/($p->{$name}->{xscale}||1))." ".($p->{$name}->{value}->[$j]->[$i]||0)); + plot_write($p->{$name}->{fh},(($i-$realentries)/($p->{$name}->{xscale}||1))." ".($p->{$name}->{value}->[$j]->[$i]||0)/($p->{$name}->{yscale}||1)); } } plot_write($p->{$name}->{fh},"e"); - } + } } - - - if($p->{$name}->{type} == TYPE_BARGRAPH) { + + if($p->{$name}->{type} == TYPE_BARGRAPH) { my $realentries = $p->{$name}{limitentries} || $p->{$name}->{entries}; for(my $j=0; $j<$p->{$name}->{curves}; $j++) { for(my $i=$p->{$name}->{entries}-$realentries; $i< $p->{$name}->{entries}; $i++) { - plot_write($p->{$name}->{fh},' '.$p->{$name}->{value}->[$j]->[$i]); + plot_write($p->{$name}->{fh},' '.(($p->{$name}->{value}->[$j]->[$i]||0)/($p->{$name}->{yscale}||1))); #?? maybe without ||0 } plot_write($p->{$name}->{fh},"e"); } } - - - if($p->{$name}->{type} == TYPE_HEATMAP) { - if($p->{$name}->{showvalues}) { + + + if($p->{$name}->{type} == TYPE_HEATMAP) { + # if($p->{$name}->{showvalues}) { for(my $j=0; $j<$p->{$name}->{curves}; $j++) { for(my $i=0; $i< $p->{$name}->{entries}; $i++) { - plot_write($p->{$name}->{fh},($p->{$name}->{value}->[$j]->[$i]||0)." ",1); + plot_write($p->{$name}->{fh},($p->{$name}->{value}->[$j]->[$i]//'NaN')/($p->{$name}->{cbscale}||1)." ",1);#"NaN" + #plot_write($p->{$name}->{fh},((int((($p->{$name}->{value}->[$j]->[$i]||0)*100+0.5)/100))//'NaN')." ",1);#"NaN" } plot_write($p->{$name}->{fh}," ",0); } - plot_write($p->{$name}->{fh},"e"); - plot_write($p->{$name}->{fh},"e"); - } - - for(my $j=0; $j<$p->{$name}->{curves}; $j++) { - for(my $i=0; $i< $p->{$name}->{entries}; $i++) { - plot_write($p->{$name}->{fh},($p->{$name}->{value}->[$j]->[$i]||0)." ",1); + plot_write($p->{$name}->{fh},"e"); + plot_write($p->{$name}->{fh},"e"); + # } + + if ($p->{$name}{showvalues}) { + for(my $j=0; $j<$p->{$name}->{curves}; $j++) { + for(my $i=0; $i< $p->{$name}->{entries}; $i++) { + plot_write($p->{$name}->{fh},($p->{$name}->{value}->[$j]->[$i]||0)/($p->{$name}->{cbscale}||1)." ",1); + #plot_write($p->{$name}->{fh},(int((($p->{$name}->{value}->[$j]->[$i]||0)*100+0.5)/100))." ",1); + } + plot_write($p->{$name}->{fh}," ",0); + } + plot_write($p->{$name}->{fh},"e"); + plot_write($p->{$name}->{fh},"e"); } - plot_write($p->{$name}->{fh}," ",0); - } - plot_write($p->{$name}->{fh},"e"); - plot_write($p->{$name}->{fh},"e"); } - - + + $p->{$name}->{run}++; - - + + if($p->{$name}->{storable}) { lock_store($p->{$name}->{value},$storefile->{$name}); } @@ -294,15 +322,20 @@ sub PlotAdd { } sub PlotFill { - my($name,$value,$slot,$curve) = @_; + my($name,$value,$slot,$curve,$add) = @_; $curve = 0 unless $curve; - $p->{$name}->{value}->[$curve]->[$slot] = $value||0; + if($add) { + $p->{$name}->{value}->[$curve]->[$slot] += $value||0; + } + else { + $p->{$name}->{value}->[$curve]->[$slot] = $value||0; + } } - + sub PlotLimitEntries { - my($name,$entries) = @_; - $p->{$name}{limitentries} = $entries; + my ($name,$entries) = @_; + $p->{$name}{limitentries} = $entries; } - + 1; -- 2.43.0