use HADES::TrbNet;
+use constant false => 0;
+use constant true => 1;
my $opt_help;
my @opt_endpoints;
my @opt_chains;
my $opt_offset = 0;
my $opt_polarity = 0;
+my $opt_32channel = 0;
+my $opt_finetune = false;
my $opt_verb;
GetOptions ('h|help' => \$opt_help,
'c|chains=s' => \@opt_chains,
'o|offset=s' => \$opt_offset,
'p|polarity=i' => \$opt_polarity,
+ '32|32channel' => \$opt_32channel,
+ 'f|finetune' => \$opt_finetune,
'v|verb' => \$opt_verb);
#print Dumper $endpoints;
#print Dumper $chains;
+if($opt_32channel == 1) {
+ $opt_32channel="--32channel";
+}
+else {
+ $opt_32channel="";
+}
+
+
+if($opt_finetune == true) {
+ $opt_finetune="--finetune";
+}
+else {
+ $opt_finetune="";
+}
+
my $command;
foreach my $endpoint (@$endpoints) {
foreach my $chain (@$chains) {
my $endpoint = sprintf("0x%04x", $endpoint);
- $command = "./thresholds_automatic.pl -e $endpoint -o $opt_offset -c $chain -p $opt_polarity";
+ $command = "./thresholds_automatic.pl -e $endpoint -o $opt_offset -c $chain -p $opt_polarity $opt_32channel $opt_finetune";
print "command: $command\n";
my $pid = fork();
if($pid==0) { #child
use IPC::ShareLite qw( :lock );
+use constant false => 0;
+use constant true => 1;
+
my $share = IPC::ShareLite->new(
-key => 3214,
-create => 'yes',
my $interval_step = ($valid_interval[1] - $valid_interval[0])/2;
my $start_value = int ( ($valid_interval[1] + $valid_interval[0])/2 );
-
my $sleep_time = 0.2;
my $accepted_dark_rate = 30;
my $number_of_iterations = 40; # at least 15 are recommended
my $polarity = 1;
my @channels = ();
my $channel32 = undef;
+my $opt_finetune = false;
our $chain = 0;
"o|offset=s" => \$offset,
"32|32channel" => \$channel32,
"s|skip=i" => \$opt_skip,
+ "f|finetune" => \$opt_finetune,
);
if($help) {
$best_thresh[$opt_skip] = 0x7000;
}
+if ($opt_finetune == true) {
+ my $ra_thresh = read_thresholds("padiwa", $chain);
+ @current_thresh = @$ra_thresh;
+ #print Dumper \@current_thresh;
+
+ $interval_step = 4;
+
+}
+
my $hit_diff = 0;
my $number_of_steps = 0;
foreach my $i (0..15) {
- $interval_step = $interval_step[$i];
+ $interval_step = $interval_step[$i];
my $cur_hitreg = $rh_res->{$endpoint}->[$i*$hitchannel_multiplicator];
my $old_hitreg = $old_rh_res->{$endpoint}->[$i*$hitchannel_multiplicator] & 0x7fffffff;
exit;
+sub read_thresholds {
+ (my $mode, my $chain) = @_;
+
+ my @thresh = ();
+
+ $share->store($chain);
+
+ my $res = $share->lock(LOCK_EX);
+ if(!defined $res || $res != 1) {
+ die "could not lock shared element";
+ }
+
+ my $rh_res = trb_register_write($endpoint,0xd410, 1 << $chain);
+
+ foreach my $current_channel (0..15) {
+
+ my $command;
+ my $fixed_bits;
+ my $shift_bits;
+
+ if($mode eq "padiwa") {
+ $fixed_bits = 0x00000000;
+ $shift_bits = 0;
+ }
+ elsif ($mode eq "cbmrich") {
+ die "readout of channels in cbmrich is not implemented";
+ $fixed_bits = 0x00300000;
+ $shift_bits = 4;
+ }
+
+ $command = $fixed_bits | ($current_channel << 16) ;
+ my $rh_res = send_command($endpoint, $command);
+ push (@thresh , $rh_res->{$endpoint});
+ }
+
+ #sleep 10 if($current_channel == 15 && $chain==1);
+ #sleep 1;
+ $share->unlock();
+
+
+ return \@thresh;
+
+}
+
+
sub write_thresholds {
(my $mode, my $chain, my $ra_thresh) = @_;