]> jspc29.x-matter.uni-frankfurt.de Git - mvdsensorcontrol.git/commitdiff
progress on plot scheduling
authorMichael Wiebusch <antiquark@gmx.net>
Wed, 22 Jan 2014 22:25:27 +0000 (23:25 +0100)
committerMichael Wiebusch <antiquark@gmx.net>
Wed, 22 Jan 2014 22:25:27 +0000 (23:25 +0100)
tools/PlotScheduler.pm
tools/adcmon.pl
tools/plotService.pl

index 5294449b52637429e08d4b0c08e49851b335d229..c14398559f627d14912095dc19c1d428120baecd 100644 (file)
@@ -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};
 };
index e1a6821671e7958aacbca165579022ec8b15bcf8..f75044576360b189cc38bc3c90799b6cd15784cc 100755 (executable)
@@ -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;
index 38f52c209b0d3ea5adad5dd5c065ea1f140d7adf..2ec9292ff48e1579ba143ff613b91c715e10d683 100755 (executable)
@@ -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});
 }