startTimeout => 2,
%options
};
+ unless (defined( $self->{plotDir} )){
+ $self->{plotDir} = $self->{shm}."_plots";
+ }
bless($self, $class);
}
sub deleteShm {
my $self = shift;
unlink $self->{shm};
+# unless (defined( $self->{plotDir} )){
+# $self->{plotDir} = $self->{shm}."_plots";
+# }
system("rm -rf ".$self->{plotDir});
}
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;
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};
};
-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;
my $suicideTimeout = 5;
+
use strict;
use warnings;
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;
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));
-PlotJob::initXmlDb("/local.1/htdocs/daqtools/xml-db/cache/CbController.entity");
+PlotJob::initXmlDb("../../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) {
package PlotJob;
use HPlot;
-use HADES::TrbNet;
+# use HADES::TrbNet;
use AccessXmlDb;
my $xmldb;
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});
}