--- /dev/null
+#!/usr/bin/perl -w
+
+use warnings;
+use POSIX qw(strftime);
+use FileHandle;
+use lib "./code";
+use lib "../tools";
+use HADES::TrbNet;
+use List::Util qw(min max);
+use Time::HiRes qw(usleep);
+use Dmon;
+use HPlot;
+use Data::Dumper;
+use IO::Socket;
+
+
+my %config = Dmon::StartUp();
+my $script = $config{UserDirectory} . '/' . $config{PowerSupScript};
+
+HPlot::PlotInit({
+ name => "PSCurrents",
+ file => Dmon::DMONDIR."PSCurrents",
+ curves => 20,
+ entries => 300,
+ type => HPlot::TYPE_HISTORY,
+ output => HPlot::OUT_PNG,
+ xlabel => "Time [s]",
+ ylabel => "Current [A]",
+ sizex => 750,
+ sizey => 270,
+ nokey => 1,
+ buffer => 1
+ });
+
+my $str = Dmon::MakeTitle(10,6,"PSCurrents",0);
+ $str .= qq@<img src="%ADDPNG PSCurrents.png%" type="image/png">@;
+ $str .= Dmon::MakeFooter();
+Dmon::WriteFile("PSCurrents",$str);
+
+while (1) {
+ # get data from epics
+ my $dataStr = `$script`;
+ my @lines = split "\n", $dataStr;
+ my %devices = ('hameg01', 0, 'hameg02', 0, 'hameg03', 0, 'tdklambda', 0);
+
+ my $maximum = 0;
+ my $total = 0;
+
+ my @values;
+
+ for my $line (@lines) {
+ if ($line =~ /(hameg\d\d|tdklambda) CH (\d).*(\d+\.\d+) A.*(\d+\.\d+) V.*(ON|OFF)/) {
+ my $dev = $1; my $chan = $2; my $curr = $3; my $volt = $4; my $state = $5;
+
+ $curr = 0 if $state eq 'OFF';
+
+ my $i = 0; #internal mapping 0: h0.c1, 1: h0.c2, .., 4: h1.c1, 5: h1.c2, .., 11: h3.c4, 12: tdklambda
+ if ($dev eq 'tdklambda') {
+ $i = 12;
+ } else {
+ $dev =~ /(\d\d)/;
+ $i = 4 * ($1 - 1) + ($chan - 1);
+
+ $maximum = $curr if $curr > $maximum;
+ $total += $curr;
+ }
+
+ $devices{$dev} = 1;
+ $values[$i] = $curr;
+ }
+ }
+
+ for(my $i=0; $i < 12; $i++) {
+ my $val = $values[$i];
+ $val = '0' unless $val;
+ HPlot::PlotAdd('PSCurrents',$val,$i);
+ }
+
+
+ my @devFound = ();
+ my @devMissing = ();
+ for my $dev (keys %devices) {
+ push @devFound, $dev if $devices{$dev};
+ push @devMissing, $dev unless $devices{$dev};
+ }
+
+ HPlot::PlotDraw('PSCurrents');
+
+ my $title = "PS Currents";
+ my $value = sprintf("%.2fA/%.2fA", $maximum, $total);
+ my $longtext = "Maximum / Total current: " . $value . "<br />";
+ $longtext .= 'TDK: ' . $values[12] . "A<br />";
+ $longtext .= 'Sups found: ' . join(', ', @devFound) . "<br />" if @devFound;
+ $longtext .= 'Sups missing: ' . join(', ', @devMissing) if @devMissing;
+
+ my $status = Dmon::OK;
+ $status = Dmon::WARN if @devMissing;
+ $status = Dmon::FATAL unless @devFound;
+
+
+ Dmon::WriteQALog($config{flog},"pscurrents",30,$status,$title,$value,$longtext,'2-PSCurrents');
+
+ sleep 1;
+}
+
+
+
+
+
# Reset trigger logic - only a workaround for a bug
#trbcmd w 0xffff 0x20 0x33
+#20150522 Jan comment
+~/trbsoft/daqtools/padiwa.pl 0xfe4c 0 time > /dev/null;~/trbsoft/daqtools/padiwa.pl 0xfe4c 1 time > /dev/null; ~/trbsoft/daqtools/padiwa.pl 0xfe4c 2 time > /dev/null
+
# Barrel DIRC
-prepare_padiwas_invert_leds.pl --endpoints=0x2000-0x2013 --chains=0..2 --invert=0xffff --stretch=0xffff
+# enable stretch prepare_padiwas_invert_leds.pl --endpoints=0x2000-0x2013 --chains=0..2 --invert=0xffff --stretch=0xffff
+prepare_padiwas_invert_leds.pl --endpoints=0x2000-0x2013 --chains=0..2 --invert=0xffff
#padiwa_led_off.pl
# Beam
## Barrel DIRC
#./write_thresholds.pl ~/trbsoft/daqtools/users/gsi_dirc/thresh/201505101447.thr -o 600 >> /dev/null # 1.5mV at plug
#./write_thresholds.pl padiwa_threshold_results_20150511_2.log -o 400 > /dev/null # 1mV at plug
-./write_thresholds.pl padiwa_threshold_results_20150516_high_stretch_CS.log -o 400 > /dev/null # 1mV at plug
+# for stretch ./write_thresholds.pl padiwa_threshold_results_20150516_high_stretch_CS.log -o 400 > /dev/null # 1mV at plug
+#20150521
+./write_thresholds.pl padiwa_threshold_results_20150516_high_nostretch_CS.log -o 200 > /dev/null
+#./write_thresholds.pl padiwa_threshold_results_20150521_high_nostretch_CS.log -o 200 > /dev/null
./padiwa_led_off_MT.sh > /dev/null
cd -