From f1760b614cc18faf0b3a0581cbd22418a42a72d8 Mon Sep 17 00:00:00 2001 From: Cbm Rich Date: Sun, 16 Nov 2014 12:23:17 +0100 Subject: [PATCH] Update of dmon scripts --- dmon/scripts/dmon_beamintensity.pl | 2 - dmon/scripts/dmon_beammonitors.pl | 76 +++++++++++++++++++++++ dmon/scripts/dmon_billboard.pl | 37 ++++++++--- dmon/scripts/dmon_deadtime.pl | 2 - dmon/scripts/dmon_heatmaprich.pl | 42 +++---------- dmon/scripts/dmon_mbs.pl | 2 - dmon/scripts/dmon_numfee.pl | 1 - dmon/scripts/dmon_padiwatemp.pl | 2 - dmon/scripts/dmon_ping.pl | 3 - dmon/scripts/dmon_qa.pl | 2 +- dmon/scripts/dmon_richenvironment.pl | 93 ++++++++++++++++++++++++++++ dmon/scripts/dmon_trgrate.pl | 2 - perllibs/ChannelMapping.pm | 1 + tools/HPlot.pm | 7 ++- users/cern_cbmrich/dmon_config.pl | 9 +-- users/cern_cbmrich/makethresholds.sh | 5 +- 16 files changed, 218 insertions(+), 68 deletions(-) create mode 100755 dmon/scripts/dmon_beammonitors.pl create mode 100755 dmon/scripts/dmon_richenvironment.pl create mode 120000 perllibs/ChannelMapping.pm diff --git a/dmon/scripts/dmon_beamintensity.pl b/dmon/scripts/dmon_beamintensity.pl index 6d1e507..ab7877a 100755 --- a/dmon/scripts/dmon_beamintensity.pl +++ b/dmon/scripts/dmon_beamintensity.pl @@ -3,8 +3,6 @@ use warnings; use POSIX qw(strftime); use FileHandle; -use lib "./code"; -use lib "../tools"; use HADES::TrbNet; use Time::HiRes qw(usleep); use Dmon; diff --git a/dmon/scripts/dmon_beammonitors.pl b/dmon/scripts/dmon_beammonitors.pl new file mode 100755 index 0000000..c3c2f6d --- /dev/null +++ b/dmon/scripts/dmon_beammonitors.pl @@ -0,0 +1,76 @@ +#!/usr/bin/perl -w + +use warnings; +use POSIX qw(strftime); +use FileHandle; +use HADES::TrbNet; +use Time::HiRes qw(usleep); +use Dmon; +use HPlot; +use Data::Dumper; + +my %config = Dmon::StartUp(); + +HPlot::PlotInit({ + name => "Beam", + file => Dmon::DMONDIR."BeamMonitors", + entries => scalar @{$config{BeamDetectorsName}}, + type => HPlot::TYPE_BARGRAPH, + output => HPlot::OUT_PNG, + bartitle => $config{BeamDetectorsName}, + xlabel => "", + ylabel => "Counts/s", + sizex => 430, + sizey => 360, + curvewidth => 1.5, +# ymin => -1, + ymax => "1000<*", +# xscale => 5, + nokey => 1, + buffer => 1 + }); + +my $str = Dmon::MakeTitle(6,8,"BeamMonitors",0); + $str .= qq@@; + $str .= Dmon::MakeFooter(); +Dmon::WriteFile("BeamMonitors",$str); + +my @old; + +while(1) { + my @regs; + for (my $c = 0; $c < scalar @{$config{BeamDetectorsTrb}}; $c++) { + my $t = trb_registertime_read($config{BeamDetectorsTrb}->[$c],$config{BeamDetectorsChan}->[$c]); + $regs[$c] = $t->{$config{BeamDetectorsTrb}->[$c]}; + } + + for (my $c = 0; $c < scalar @{$config{BeamDetectorsTrb}}; $c++) { + my $value = $regs[$c]->{value}[0]; + + $value -= $old[$c]->{value}[0] || 0; + + HPlot::PlotFill('Beam',$value,$c,0); + } + + + HPlot::PlotDraw('Beam'); + Dmon::WriteQALog($config{flog},"beammonitors",60,Dmon::OK,"Beam Monitors","","Just plotting","1-BeamMonitors"); + +# my $curr = $sig->{$config{BeamTRB}} & 0xffffff; +# +# if($curr - $old > $config{SpillThreshold}) { +# $value += $curr - $old||0; +# } +# else { +# if ($value > 0) { +# my $longtext = "Number of signals in last spill: ".$value; +# my $status = Dmon::OK; +# Dmon::WriteQALog($config{flog},"beamintensity",60,$status,$title,$value,$longtext); +# $value = 0; +# } +# } + + + @old = @regs; + sleep 1; + } diff --git a/dmon/scripts/dmon_billboard.pl b/dmon/scripts/dmon_billboard.pl index 82cdc7f..755be5a 100755 --- a/dmon/scripts/dmon_billboard.pl +++ b/dmon/scripts/dmon_billboard.pl @@ -14,11 +14,16 @@ use Perl2Epics; my %config = Dmon::StartUp(); my $t0; -for(my $i = 1; $i<=20; $i++) { - my $name = sprintf('CBM:PWRSWITCH:GetCurrent%02x',$i); - Perl2Epics::Connect("C".$i,$name); +for(my $i = 0; $i< 16 ; $i++) { + Perl2Epics::Connect("PC".$i, sprintf('CBM:PWRSWITCH:GetCurrent%02x',$i)); + + Perl2Epics::Connect("HV_U".$i, sprintf('OUTPUT_TERMINAL_VOLTAGE_U%d',$i)); + Perl2Epics::Connect("HV_I".$i, sprintf('MEASUREMENT_CURRENT_U%d',$i)); } +Perl2Epics::Connect("Pres","CBM:BMP180:GetPressure"); +Perl2Epics::Connect("Temp","CBM:BMP180:GetTemp"); + while(1) { # update billboard my @billboardValues = (); @@ -27,19 +32,33 @@ while(1) { my $epicsData = Perl2Epics::GetAll(); # temp & pressure - $billboardValues[0] = 0xdeadc0de; + push @billboardValues, + (($billboardVersion & 0x3) << 30) | # version 2 bit + (($epicsData{"Pres"} & 0x1fffff) << 9) | # pressure 21 bit + (($epicsData{"Temp"} & 0x1ff ) << 0); # temp 9 bit - # currents - for(my $i = 1; $i<=20; $i++) { - my $milAmp = $epicsData->{"C".$i}->{"val"} * 1000; + # padiwa currents + for(my $i = 0; $i < 16; $i++) { + my $milAmp = $epicsData->{"PC".$i}->{"val"} * 1000; $reg = 0 unless $i & 1; $reg |= ($milAmp & 0xffff) << (16 * ($i&1)); - $billboardValues[$i / 2 + 1] = $reg; + push @billboardValues, $reg if $i & 1; } + # threshold timestamp + my $threshTime = do($config{UserDirectory} . '/thresh/billboard_info') || 0; + push @billboardValues, $threshTime & 0xffffffff; + + # hv values + for(my $i=0; $i < 16; $i++) { + push @billboardValues, + ((("HV_I".$i) * 1e6) & 0xffff) << 16) | + ((("HV_U".$i) * 1e2) & 0xffff) << 0); + } + trb_register_write_mem($config{BillboardAddress}, 0xb100, 0, \@billboardValues, scalar @billboardValues); # copy data trb_register_write($config{BillboardAddress}, 0xb000, scalar @billboardValues); # commit - + # build statistics my $title = "Billboard"; my $longtext=''; diff --git a/dmon/scripts/dmon_deadtime.pl b/dmon/scripts/dmon_deadtime.pl index b8a837a..e53e86a 100755 --- a/dmon/scripts/dmon_deadtime.pl +++ b/dmon/scripts/dmon_deadtime.pl @@ -3,8 +3,6 @@ use warnings; use POSIX qw(strftime); use FileHandle; -use lib "./code"; -use lib "../tools"; use HADES::TrbNet; use Time::HiRes qw(usleep); use Dmon; diff --git a/dmon/scripts/dmon_heatmaprich.pl b/dmon/scripts/dmon_heatmaprich.pl index 234c55d..b79db38 100755 --- a/dmon/scripts/dmon_heatmaprich.pl +++ b/dmon/scripts/dmon_heatmaprich.pl @@ -4,8 +4,6 @@ use warnings; use strict; use POSIX qw(strftime); use FileHandle; -use lib "./code"; -use lib "../tools"; use lib "../users/cern_cbmrich"; use HADES::TrbNet; use Time::HiRes qw(usleep); @@ -36,53 +34,26 @@ $plot2->{xmax} = 32.5; $plot2->{ymin} = 0.5; $plot2->{ymax} = 32.5; $plot2->{cbmin} = "0"; -$plot2->{cbmax} = "100<*<1000000"; +$plot2->{cbmax} = "100<*"; $plot2->{showvalues} = 0; $plot2->{xlabel} = "column"; $plot2->{ylabel} = "row"; -$plot2->{addCmd} = "set lmargin at screen 0.07\nset rmargin at screen 0.80\nset bmargin at screen 0.07\nset tmargin at screen 0.95"; +$plot2->{addCmd} = "set lmargin at screen 0.07\nset rmargin at screen 0.85\nset bmargin at screen 0.07\nset tmargin at screen 0.95"; HPlot::PlotInit($plot2); my $str = Dmon::MakeTitle(9,14,"HeatmapRich",0); - $str .= qq@
@; + $str .= qq@@; $str .= Dmon::MakeFooter(); Dmon::WriteFile("HeatmapRich",$str); -sub generateDef { - my $x = 56; my $y = 51; my $w = (564-$x) / 32.0; my $h = (619-$y) / 32.0; - - $str = qq@ - var HeatmapDef = { - 'x': $x, 'y': $y, 'w': $w, 'h': $h, - 'labels': [ - @; - - for my $ix (1..32) { - $str .= '['; - for my $iy (1..32) { - my $fpga = $ChannelMapping::chanmap->{fpga}->[$ix]->[$iy]; - my $channel = ($ChannelMapping::chanmap->{chan}->[$ix]->[$iy]-1) / 2; - - $str .= sprintf("'0x%04x CH: %d'", $fpga, $channel) . ($iy == 32 ? '' : ','); - } - $str .= ']' . ($ix == 32 ? '' : ',') . "\n"; - } - - $str .= ']};'; - return $str; -} - -open FH, ">", Dmon::DMONDIR . '/HeatmapRichDefs.js'; -print FH generateDef; -close FH; my $old; my $oldtime = time(); my $time = time(); my $diff; - while (1) { + my $sum = 0; my $o = trb_register_read_mem($config{PadiwaBroadcastAddress},0xc000,0,33); if (defined $old) { @@ -100,14 +71,15 @@ while (1) { my $fpga = $ChannelMapping::chanmap->{fpga}->[$x]->[$y]; my $channel = $ChannelMapping::chanmap->{chan}->[$x]->[$y]; HPlot::PlotFill('HeatmapRich',$diff->{$fpga}->[$channel],$x,$y); + $sum += $diff->{$fpga}->[$channel]; } } HPlot::PlotDraw('HeatmapRich'); } my $status = Dmon::OK; my $title = "Heatmap"; - my $value = ""; - my $longtext = "See plot"; + my $value = Dmon::SciNotation($sum); + my $longtext = "Total: ".$value; Dmon::WriteQALog($config{flog},"heatmaprich",5,$status,$title,$value,$longtext,'1-HeatmapRich'); $old = $o; $oldtime = time(); diff --git a/dmon/scripts/dmon_mbs.pl b/dmon/scripts/dmon_mbs.pl index 73ff2c8..71210b2 100755 --- a/dmon/scripts/dmon_mbs.pl +++ b/dmon/scripts/dmon_mbs.pl @@ -3,8 +3,6 @@ use warnings; use POSIX qw(strftime); use FileHandle; -use lib "./code"; -use lib "../tools"; use HADES::TrbNet; use Time::HiRes qw(usleep); use Dmon; diff --git a/dmon/scripts/dmon_numfee.pl b/dmon/scripts/dmon_numfee.pl index b3b9670..50c8151 100755 --- a/dmon/scripts/dmon_numfee.pl +++ b/dmon/scripts/dmon_numfee.pl @@ -3,7 +3,6 @@ use warnings; use POSIX qw(strftime); use FileHandle; -use lib "./code"; use HADES::TrbNet; use Dmon; diff --git a/dmon/scripts/dmon_padiwatemp.pl b/dmon/scripts/dmon_padiwatemp.pl index cd61e5d..8166ff7 100755 --- a/dmon/scripts/dmon_padiwatemp.pl +++ b/dmon/scripts/dmon_padiwatemp.pl @@ -1,8 +1,6 @@ #!/usr/bin/perl -w use warnings; -use lib "./code"; -use lib "../tools"; use HADES::TrbNet; use Dmon; use HPlot; diff --git a/dmon/scripts/dmon_ping.pl b/dmon/scripts/dmon_ping.pl index 219d801..de2e66e 100755 --- a/dmon/scripts/dmon_ping.pl +++ b/dmon/scripts/dmon_ping.pl @@ -3,8 +3,6 @@ use warnings; use POSIX qw(strftime); use FileHandle; -use lib "./code"; -use lib "./tools"; use HADES::TrbNet; use Time::HiRes qw(usleep); use Dmon; @@ -21,7 +19,6 @@ while(1) { my $total = scalar @{$config{TrbIP}}; foreach my $p (@{$config{TrbIP}}) { my $r = $ping->ping($p,1); -# print $p."\t$r\n"; $found += $r || 0; $notavail += 1-($r||0); $list .= " $p" unless $r; diff --git a/dmon/scripts/dmon_qa.pl b/dmon/scripts/dmon_qa.pl index c06ccd8..e31cd41 100755 --- a/dmon/scripts/dmon_qa.pl +++ b/dmon/scripts/dmon_qa.pl @@ -50,7 +50,7 @@ while($a = ) { #Generate output file at most once per second if(1 || $oldtime < time) { $oldtime = scalar time(); - $str = Dmon::MakeTitle($width,7,"Tactical Overview",1); + $str = Dmon::MakeTitle($width,8,"Tactical Overview",1); $str .= "
"; foreach my $row (@{$config{activeScripts}}) { $str .= "
".($config{qaNames}->[$i++])."
\n"; diff --git a/dmon/scripts/dmon_richenvironment.pl b/dmon/scripts/dmon_richenvironment.pl new file mode 100755 index 0000000..fe21c32 --- /dev/null +++ b/dmon/scripts/dmon_richenvironment.pl @@ -0,0 +1,93 @@ +#!/usr/bin/perl -w + +use warnings; +use POSIX qw(strftime); +use FileHandle; +use HADES::TrbNet; +# use List::Util qw(min max); +# use Time::HiRes qw(usleep); +use Dmon; +use HPlot; +use Perl2Epics; +# use Data::Dumper; + +my %config = Dmon::StartUp(); + +HPlot::PlotInit({ + name => "temperature", + file => Dmon::DMONDIR."RichEnvironmentTemperature", + curves => 1, + entries => 3000, + type => HPlot::TYPE_HISTORY, + output => HPlot::OUT_PNG, + xlabel => "Time [m]", + ylabel => "Temperature", + sizex => 750, + sizey => 270, + ymin => 10, + ymax => "30<*", + nokey => 1, + storable=> 1, + buffer => 1 + }); +HPlot::PlotInit({ + name => "pressure", + file => Dmon::DMONDIR."RichEnvironmentPressure", + curves => 1, + entries => 3000, + type => HPlot::TYPE_HISTORY, + output => HPlot::OUT_PNG, + xlabel => "Time [m]", + ylabel => "Pressure", + sizex => 750, + sizey => 270, + ymin => 900, + ymax => 1000, + nokey => 1, + storable=> 1, + buffer => 1 + }); + +my $str = Dmon::MakeTitle(10,12,"RichEnvironment",0); + $str .= qq@@."\n"; + $str .= qq@\n@; + $str .= Dmon::MakeFooter(); +Dmon::WriteFile("RichEnvironment",$str); + +Perl2Epics::Connect("T","CBM:BMP180:GetTemp"); +Perl2Epics::Connect("P","CBM:BMP180:GetPressure"); + +my $iter = 0; + +while (1) { + + # get data from epics + my $data = Perl2Epics::GetAll(); + my $temperature = $data->{"T"}->{"val"} / 10.; + my $pressure = $data->{"P"}->{"val"} / 100.; + + my $title = "Environment"; + my $value = sprintf("%.1f / %.1f", $pressure, $temperature); + my $longtext = "Pressue (mbar) / Temperatur (°C): ". $value; + my $status = Dmon::OK; +# print time."\t".$data->{"P"}->{"tme"}."\t".$data->{"T"}->{"tme"}."\n"; + if (time - $data->{"P"}->{"tme"} > 240 || time - $data->{"T"}->{"tme"} > 240) { + $status = Dmon::WARN; + $longtext .="
Updates missing"; + } + + Dmon::WriteQALog($config{flog},"richenvironment",15,$status,$title,$value,$longtext,'30-RichEnvironment'); + + if($iter++ % 12 == 0) { + HPlot::PlotAdd('temperature',$temperature); + HPlot::PlotAdd('pressure',$pressure); + HPlot::PlotDraw('temperature'); + HPlot::PlotDraw('pressure'); + } + sleep 5; + } + + + + + diff --git a/dmon/scripts/dmon_trgrate.pl b/dmon/scripts/dmon_trgrate.pl index 9bb4a1d..aa178e7 100755 --- a/dmon/scripts/dmon_trgrate.pl +++ b/dmon/scripts/dmon_trgrate.pl @@ -3,8 +3,6 @@ use warnings; use POSIX qw(strftime); use FileHandle; -use lib "./code"; -use lib "../tools"; use HADES::TrbNet; use Time::HiRes qw(usleep); use Dmon; diff --git a/perllibs/ChannelMapping.pm b/perllibs/ChannelMapping.pm new file mode 120000 index 0000000..dc585e9 --- /dev/null +++ b/perllibs/ChannelMapping.pm @@ -0,0 +1 @@ +../users/cern_cbmrich/ChannelMapping.pm \ No newline at end of file diff --git a/tools/HPlot.pm b/tools/HPlot.pm index 7990a7a..dd49f87 100755 --- a/tools/HPlot.pm +++ b/tools/HPlot.pm @@ -77,9 +77,10 @@ sub PlotInit { my $filename = $p->{$name}->{file}; $filename =~ s%/%%; - $storefile->{$name} = "/dev/shm/".$name.'-'.$p->{$name}->{curves}.'-'.$p->{$name}->{entries}.'-'.$filename.'.store'; - - + $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) ; diff --git a/users/cern_cbmrich/dmon_config.pl b/users/cern_cbmrich/dmon_config.pl index 81c8b36..5091531 100755 --- a/users/cern_cbmrich/dmon_config.pl +++ b/users/cern_cbmrich/dmon_config.pl @@ -4,7 +4,7 @@ #Scripts to start & order of icons in the Overview activeScripts => [['time','ping','-','-','daqop'], ['numfee','temperature','reftime','billboard','mbs'], - ['beamintensity','-','-','-','-'], + ['beamintensity','beammonitors','-','-','richenvironment'], ['trgrate','datarate','deadtime','-','-'], ['heatmaprich','padiwatemp','padiwaonline','currents','pscurrents'], ['cbmnetlink','cbmnetdata','cbmnetsync','-','-']], @@ -13,7 +13,7 @@ activeScripts => [['time','ping','-','-','daqop'], qaNames => ['sys','main','beam','rate','Pdwa','CNet','-'], #Expected number of FPGAs in system -NumberOfFpga => 90, +NumberOfFpga => 90, #The address of the individual boards CtsAddress => 0x7005, @@ -88,8 +88,9 @@ BeamChan => 0xc005, SpillThreshold => 30, #Name detectors -BeamDetectorsTrb => [0x0111,0x0111,0x0111,0x0110], -BeamDetectorsChan => [0xc001,0xc005,0xc009,0xc005], +BeamDetectorsTrb => [0x0111,0x0110,0x0111,0x0110,0x0113,0x0110], +BeamDetectorsChan => [0xc001,0xc009,0xc005,0xc00b,0xc009,0xc005], +BeamDetectorsName => ['C1', 'C1d', 'C2', 'C2d', 'Lead', 'Hodo'], #User directory UserDirectory => '/home/hadaq/trbsoft/daqtools/users/cern_cbmrich/', diff --git a/users/cern_cbmrich/makethresholds.sh b/users/cern_cbmrich/makethresholds.sh index c30607b..d767ac2 100755 --- a/users/cern_cbmrich/makethresholds.sh +++ b/users/cern_cbmrich/makethresholds.sh @@ -1,7 +1,7 @@ #!/bin/bash rm padiwa_threshold_results.log ./write_thresholds.pl thresh/dummythresholds.thr -o 0 - +trbcmd setbit 0x7005 0xa00c 0x80000000 # ./run_thresh_on_system.pl \ # --endpoints=0x0013,0x0021,0x0033,0x0041,0x0053,0x0061,0x0073,0x0081,0x0093,0x00a1,0x00b3,0x00c1,0x00d3,0x00e1,0x00f3,0x0101 \ @@ -26,4 +26,5 @@ rm padiwa_threshold_results.log ./run_thresh_on_system.pl --endpoints=0x0010-0x0013,0x0020-0x0023,0x0030-0x0033,0x0040-0x0043,0x0050-0x0053,0x0060-0x0063,0x0070-0x0073,0x0080-0x0083,0x0090-0x0093,0x00a0-0x00a3,0x00b0-0x00b3,0x00c0-0x00c3,0x00d0-0x00d3,0x00e0-0x00e3,0x00f0-0x00f3,0x0100-0x0103\ --32channel --chains=0 --offset=0 --polarity 1 --tool ./thresholds_new.pl -./write_thresholds.pl padiwa_threshold_results.log -o 0 \ No newline at end of file +./write_thresholds.pl padiwa_threshold_results.log -o 0 +trbcmd clearbit 0x7005 0xa00c 0x80000000 -- 2.43.0