From: Michael Wiebusch Date: Wed, 22 Jan 2014 22:25:27 +0000 (+0100) Subject: progress on plot scheduling X-Git-Url: https://jspc29.x-matter.uni-frankfurt.de/git/?a=commitdiff_plain;h=8e1a578cb64b460e99c8fe699b08f15acc270d4f;p=mvdsensorcontrol.git progress on plot scheduling --- diff --git a/tools/PlotScheduler.pm b/tools/PlotScheduler.pm index 5294449..c143985 100644 --- a/tools/PlotScheduler.pm +++ b/tools/PlotScheduler.pm @@ -27,6 +27,9 @@ sub new { startTimeout => 2, %options }; + unless (defined( $self->{plotDir} )){ + $self->{plotDir} = $self->{shm}."_plots"; + } bless($self, $class); } @@ -108,6 +111,9 @@ sub listRequests { sub deleteShm { my $self = shift; unlink $self->{shm}; +# unless (defined( $self->{plotDir} )){ +# $self->{plotDir} = $self->{shm}."_plots"; +# } system("rm -rf ".$self->{plotDir}); } @@ -122,7 +128,7 @@ sub startPlotService { if (-e $self->{shm}) { die "service already running!\n"; } else { - system("./plotService.pl --shm ".$self->{shm}." 1>/dev/null 2>&1 & disown"); + system("./plotService.pl --shm ".$self->{shm}.' >/dev/null &'); for (my $i = 0; $i< $self->{startTimeout}*100; $i++){ if( -e $self->{shm} ) { return 1; @@ -139,9 +145,9 @@ sub createShm { my $self = shift; die "shm ".$self->{shm}." already exists!\n" if( -e $self->{shm} ); lock_store({},$self->{shm}); - unless (defined( $self->{plotDir} )){ - $self->{plotDir} = $self->{shm}."_plots"; - } +# unless (defined( $self->{plotDir} )){ +# $self->{plotDir} = $self->{shm}."_plots"; +# } die "plot directory ".$self->{plotDir}." already exists!\n" if( -e $self->{plotDir} ); mkdir $self->{plotDir}; }; diff --git a/tools/adcmon.pl b/tools/adcmon.pl index e1a6821..f750445 100755 --- a/tools/adcmon.pl +++ b/tools/adcmon.pl @@ -30,14 +30,14 @@ use Environment; -my $ps = PlotScheduler->new( shm => "/dev/shm/DQ55_88" ); +my $ps = PlotScheduler->new( shm => "/dev/shm/DQ55" ); # $ps->addRequest( FPGA => "0xd882", CB => "0", chip => "1", channel => "TEMP"); # $ps->storeRequests(); $ps->startPlotService() unless $ps->plotServiceRunning(); while(1){ $ps->retrieveRequests(); - $ps->addRequest( FPGA => "0xd882", CB => "0", chip => "1", channel => "VDDA"); + $ps->addRequest( FPGA => "0xd882", CB => "0", chip => "1", channel => "CurrentDigital"); $ps->listRequests(); $ps->storeRequests(); sleep 1; diff --git a/tools/plotService.pl b/tools/plotService.pl index 38f52c2..2ec9292 100755 --- a/tools/plotService.pl +++ b/tools/plotService.pl @@ -7,6 +7,7 @@ my $verbose = 1; my $suicideTimeout = 5; + use strict; use warnings; use POSIX; @@ -14,7 +15,7 @@ use POSIX; # use CGI::Carp qw(fatalsToBrowser); use Storable qw(lock_store lock_retrieve); use Data::Dumper; -use HADES::TrbNet; +# use HADES::TrbNet; use HPlot; use Getopt::Long; use Time::HiRes; @@ -23,13 +24,14 @@ require Common; use PlotScheduler; - use FindBin; use lib "$FindBin::Bin/.."; my $shm = "/dev/null"; my $timeout = 10; my $suicideTimer = time(); +my $updateInterval = 1; #s +my $updateTS = time(); Getopt::Long::Configure(qw(gnu_getopt)); @@ -40,7 +42,7 @@ GetOptions( -PlotJob::initXmlDb("/local.1/htdocs/daqtools/xml-db/cache/CbController.entity"); +PlotJob::initXmlDb("../../daqtools/xml-db/cache/CbController.entity"); @@ -51,30 +53,75 @@ PlotJob::initXmlDb("/local.1/htdocs/daqtools/xml-db/cache/CbController.entity"); # print Dumper $testJob; # # exit; - - - - - - + + +my $jobs = {}; + + my $ps = PlotScheduler->new( shm => $shm, timeout => $timeout); +$ps->deleteShm(); $ps->createShm(); # create empty shm while(1) { + updateTasks(); + samplingTasks(); +# drawingTasks(); + Time::HiRes::sleep(0.1); + +} + +sub samplingTasks { + print "sampling\n" if $verbose; + + for my $requestString ( keys %{$ps->{requests}} ) { + $jobs->{$requestString}->sample(); + } + +} + +# sub drawingTasks { +# print "drawing\n" if $verbose; +# +# for my $requestString ( keys %{$ps->{requests}} ) { +# $jobs->{$requestString}->draw(); +# } +# +# } + +sub updateTasks { + + return unless ( time()-$updateTS ge $updateInterval); + $updateTS = time(); + print "update\n" if $verbose; + $ps->retrieveRequests(); $ps->enforceTimeout(); $ps->storeRequests(); - $ps->listRequests() if $verbose; +# $ps->listRequests() if $verbose; + + # find new requests, create new jobs + for my $requestString ( keys %{$ps->{requests}} ) { + unless( defined( $jobs->{$requestString} ) ) { + #if job not already started ... + $jobs->{$requestString} = PlotJob->new( + requestString => $requestString, + plotDir => $ps->{plotDir} + ); + } + + + $jobs->{$requestString}->draw(); + } + + print Dumper (keys %{$jobs}) if $verbose; print "number of requests:".$ps->requestCount()."\n" if $verbose; keepAlive($ps->requestCount()); - sleep 1; - - } + sub keepAlive { my $argument = shift; if($argument) { @@ -91,7 +138,7 @@ sub keepAlive { package PlotJob; use HPlot; -use HADES::TrbNet; +# use HADES::TrbNet; use AccessXmlDb; my $xmldb; @@ -109,16 +156,35 @@ sub new { my %options = @_; my $self = { requestString => '', + plotDir => '/dev/null', %options }; - bless($self, $class); - + # get information from requestString ($self->{FPGA},$self->{CB},$self->{chip},$self->{channel}) = split("-",$self->{requestString}); + # get information from xml-db $self = { %$self, %{$xmldb->channelParm($self->{chip},$self->{channel}) } }; + # combine both into this object hash + my $plot = (); + $plot->{name} = $self->{requestString}; + $plot->{file} = $self->{plotDir}."/".$self->{requestString}; + $plot->{entries} = 400; + $plot->{type} = HPlot::TYPE_HISTORY; + $plot->{output} = HPlot::OUT_PNG; + $plot->{titles}->[0] = $self->{requestString}; - - return $self; + HPlot::PlotInit($plot); + bless($self, $class); +} + +sub sample { + my $self = shift; + HPlot::PlotAdd($self->{requestString},rand()); + +} +sub draw { + my $self = shift; + HPlot::PlotDraw($self->{requestString}); }