]> jspc29.x-matter.uni-frankfurt.de Git - hades_mdc_settings.git/commitdiff
add command line options and help text to scripts
authorJan Michel <michel@physik.uni-frankfurt.de>
Thu, 1 Sep 2022 17:20:34 +0000 (19:20 +0200)
committerJan Michel <michel@physik.uni-frankfurt.de>
Thu, 1 Sep 2022 17:21:02 +0000 (19:21 +0200)
scripts/generate_pasttrec_settings.pl
scripts/pasttrec_baseline_finder.pl

index fcdbe7132c35575ece260eef10588e78094eebaa..6c405fc3ec4b35baa2f2d01cf6a2ae71974ded1c 100755 (executable)
@@ -5,10 +5,12 @@ use FileHandle;
 use Getopt::Long;
 use Data::Dumper;
 use HADES::TrbNet;
+use Pod::Usage;
+
 
 my $DEBUG = 0;       #print debug messages
-my $LOAD_DIRECT = 1; #load settings and initialize 
-my $WRITE_FILES = 1; #write configration files
+my $NO_LOAD_DIRECT = 0; #load settings and initialize 
+my $NO_WRITE_FILES = 0; #write configration files
 
 my @default_settings = (0x50010,    #1:0 peaking 10ns, 3:2 gain 4mV, 4 internal bandgap
                         0x5011e,    #2:0 tail1 R 27k, 5:3 tail1 C 10pF
@@ -23,6 +25,22 @@ my $serials;   #uid -> serial
 my $addresses; #addr -> serial
 my $settings;  #addr -> @registers(0xa040-0xa07F)
 
+my $threshold = 0;
+my $help = 0;
+
+Getopt::Long::Configure(qw(gnu_getopt));
+GetOptions(
+           'help|h' => \$help,
+           'threshold|t=i' => \$threshold,
+           'noload' => \$NO_LOAD_DIRECT,
+           'nowrite' => \$NO_WRITE_FILES,
+           'debug|d' => \$DEBUG,
+          ) ;
+pod2usage(1) if $help;
+         
+$default_settings[3] = ($default_settings[3] & 0xfff00) + ($threshold & 0x7f);
+
+
 ###############################################################################
 #Read baseline file and store values
 ###############################################################################
@@ -91,7 +109,7 @@ foreach my $a (keys %$addresses) {
 ############################################################################### 
 #Load settings via trbcmd
 ###############################################################################
-if($LOAD_DIRECT) {
+if(! $NO_LOAD_DIRECT) {
   foreach my $a (keys %$settings) {
     trb_register_write_mem($a,0xa002,0,[0x4c504c40,0x4c704c60],2);#set register sets
     trb_register_write_mem($a,0xa040,0,$settings->{$a},64);       #write settings
@@ -102,7 +120,7 @@ if($LOAD_DIRECT) {
 ###############################################################################
 #Write configuration files
 ###############################################################################
-if($WRITE_FILES) {
+if(! $NO_WRITE_FILES) {
   system("mkdir -p ../settings_tdc/auto");
   system("rm ../settings_tdc/auto/????_10_pasttrec_settings.trbcmd");
   foreach my $a (keys %$settings) {
@@ -118,3 +136,50 @@ if($WRITE_FILES) {
   }
 
 
+__END__
+
+=head1 NAME
+
+generate_pasttrec_settings.pl - Loads and configures Pasttrec settings, writes configuration files
+
+=head1 SYNOPSIS
+
+generate_pasttrec_settings.pl [options]
+
+ Options:
+   -h, --help          brief help message
+   -t, --threshold N   use threshold N
+   -d, --debug         write debug messages
+   --noload            don't load settings
+   --nowrite           don't save settings
+
+=head1 OPTIONS
+
+=over 15
+
+=item B<-h | --help>
+
+Print a brief help message and exit.
+
+=item B<-t N | --threshold N>
+
+Use defined threshold (0..127) instead of default one
+
+=item B<--noload>
+
+Do not load settings to Pasttrec
+
+=item B<--nowrite>
+
+Do not write configuration files
+
+=item B<-d | --debug>
+
+Write debug messages
+
+=back
+
+=head1 DESCRIPTION
+
+
+=cut
index 87251c5ef8eab90c3d3671c18c57d3d0d74cf687..5339e836e2ec108b04bb2f66c08f1a8382632c4d 100755 (executable)
@@ -5,34 +5,57 @@ use FileHandle;
 use Getopt::Long;
 use Data::Dumper;
 use HADES::TrbNet;
+use Pod::Usage;
+use Time::HiRes qw(usleep);
 
 my $DEBUG = 0;       #print debug messages
-my $LOAD_DIRECT = 1; #load settings and initialize 
-my $WRITE_FILES = 1; #write configration files
+
 
 my @default_settings = (0x50010,    #1:0 peaking 10ns, 3:2 gain 4mV, 4 internal bandgap
                         0x5011e,    #2:0 tail1 R 27k, 5:3 tail1 C 10pF
                         0x50215,    #2:0 tail1 R 23k, 5:3 tail1 C 0.9pF
-                        0x50302,    #6:0 global threshold 5=10mV
+                        0x50300,    #6:0 global threshold 0
                         0x50400,0x50500,0x50600,0x50700,0x50800,0x50900,0x50a00,0x50b00,
                         0,0,0,0);
 
+my $counters; 
+my $counters2;
+my $rates;
+my $baselines;  
 
 my $serials;   #uid -> serial
 my $addresses; #addr -> serial
 my $settings;  #addr -> @registers(0xa040-0xa07F)
+
+
+my $threshold = 0;
+my $help = 0;
+my $waittime = 1;
+Getopt::Long::Configure(qw(gnu_getopt));
+GetOptions(
+           'help|h' => \$help,
+           'threshold|t=i' => \$threshold,
+           'debug|d' => \$DEBUG,
+           'wait|w=f'  => \$waittime,
+          ) ;
+pod2usage(1) if $help;
+
+$default_settings[3] = ($default_settings[3] & 0xfff00) + ($threshold & 0x7f);
+       
 trb_init_ports() or die trb_strerror();
 
+
+###############################################################################
+#Function to set pasttrec registers
+###############################################################################
 sub init_pasttrecs {
-  foreach my $a (keys %$addresses) {
-    printf("board %04x found.\n",$a) if $DEBUG;
-    trb_register_write_mem($a,0xa002,0,[0x4c304c30,0x4c304c30],2);#set register sets
-    trb_register_write($a,0xaa00,1);                              #init Pasttrec
-    
-    foreach my $pt (0..3) { 
-      foreach my $i (0..11) { 
-        trb_register_write($a,0xa200+($pt << 4)+$i,$default_settings[$i]);
-        }
+  trb_register_write_mem(0xfe91,0xa002,0,[0x4c304c30,0x4c304c30],2);#set register sets
+  trb_register_write(0xfe91,0xaa00,1);                              #init Pasttrec
+  trb_register_write_mem(0xfe91,0xa002,0,[0x4c704c60,0x4c504c40],2);#clean-up register sets
+  
+  foreach my $pt (0..3) { 
+    foreach my $i (0..11) { 
+      trb_register_write(0xfe91,0xa200+($pt << 4)+$i,$default_settings[$i]);
       }
     }
   }
@@ -40,13 +63,9 @@ sub init_pasttrecs {
   
 sub set_baseline {
   my $baseline = $_[0] // 0;
-  
-  foreach my $a (keys %$addresses) {
-    printf("board %04x found.\n",$a) if $DEBUG;
-    foreach my $pt (0..3) { 
-      foreach my $i (4..11) { 
-        trb_register_write($a,0xa200+($pt << 4)+$i,$default_settings[$i]+$baseline);
-        }
+  foreach my $pt (0..3) { 
+    foreach my $i (4..11) { 
+      trb_register_write(0xfe91,0xa200+($pt << 4)+$i,$default_settings[$i]+$baseline);
       }
     }
   }
@@ -76,20 +95,20 @@ foreach my $uid (keys %$boards) {
     }
   }
 
-  my $counters; 
-  my $counters2;
-  my $rates;
-  my $baselines;  
 ###############################################################################
 #Prepare Scan
 ###############################################################################
 init_pasttrecs();
 set_baseline(0);
+
+###############################################################################
+#Do Scan
+###############################################################################
 foreach my $i (0..31) {
   print("Set baseline $i\n");
   set_baseline($i);
   $counters = trb_register_read_mem(0xfe91,0xdfc0,0,32);
-  sleep(1);
+  usleep($waittime*1E6);
   $counters2 = trb_register_read_mem(0xfe91,0xdfc0,0,32);
   
   foreach my $b (keys %{$counters}) {
@@ -101,7 +120,9 @@ foreach my $i (0..31) {
     }
   }
 
-  
+###############################################################################
+#Calculate means
+###############################################################################  
 foreach my $b (keys %{$rates}) {
   foreach my $c (0..31) {
     my $sum=0; my $tot=0;
@@ -113,8 +134,11 @@ foreach my $b (keys %{$rates}) {
     if($tot==0) {$baselines->{$b}[$c]=0x63;}
     }
   }
-print Dumper $baselines;  
 
+
+###############################################################################
+#Output Data
+###############################################################################
 foreach my $b (sort keys %{$rates}) {
   foreach my $p (0..3) {
     printf("   %i\t%i\t%02i\t%02i\t%02i\t%02i\t%02i\t%02i\t%02i\t%02i\n",
@@ -131,3 +155,45 @@ foreach my $b (sort keys %{$rates}) {
     }
   }
   
+
+__END__
+
+=head1 NAME
+
+pasttrec_baseline_finder.pl - Scans baselines for all available Pasttrec chips
+
+=head1 SYNOPSIS
+
+pasttrec_baseline_finder.pl [options]
+
+ Options:
+   -h, --help          brief help message
+   -t, --threshold N   use threshold N
+   -d, --debug         write debug messages
+
+=head1 OPTIONS
+
+=over 15
+
+=item B<-h | --help>
+
+Print a brief help message and exit.
+
+=item B<-t N | --threshold N>
+
+Use defined threshold (0..127) instead of default (0)
+
+=item B<-d | --debug>
+
+Write debug messages
+
+=item B<-w F| --wait F>
+
+Time to wait between two steps in seconds
+
+=back
+
+=head1 DESCRIPTION
+
+
+=cut