From: hadaq Date: Wed, 6 May 2015 21:28:04 +0000 (+0200) Subject: channel by channel, mt X-Git-Url: https://jspc29.x-matter.uni-frankfurt.de/git/?a=commitdiff_plain;h=48a290421384eaac028488730d41163557fb240b;p=daqtools.git channel by channel, mt --- diff --git a/thresholds/thresholds_automatic.pl b/thresholds/thresholds_automatic.pl index e31f17e..5031de2 100755 --- a/thresholds/thresholds_automatic.pl +++ b/thresholds/thresholds_automatic.pl @@ -34,7 +34,7 @@ my $start_value = int ( ($valid_interval[1] + $valid_interval[0])/2 ); my $sleep_time = 0.2; my $accepted_dark_rate = 10; -my $number_of_iterations = 40; # at least 15 are recommended +my $number_of_iterations = 30; # at least 15 are recommended my $endpoint = 0x0303; my $mode = "padiwa"; @@ -43,6 +43,8 @@ my $offset = 0; my $opt_skip = 99; my $polarity = 1; my @channels = (); +my $channel_to_set = undef; +my $channel_by_channel = false; my $channel32 = undef; my $opt_finetune = false; @@ -51,6 +53,8 @@ our $chain = 0; my $result = GetOptions ( "h|help" => \$help, "c|chain=i" => \$chain, + "channel_to_set=i" => \$channel_to_set, + "channel_by_channel" => \$channel_by_channel, "e|endpoint=s" => \$endpoint, "m|mode=s" => \$mode, "p|polarity=i" => \$polarity, @@ -139,6 +143,34 @@ my $number_of_steps = 0; my $rh_res; my $old_rh_res; +my $outermost_channel_loop_counter = 0; + +#set default values +my @zero_array = (0) x 16; +write_thresholds($mode, $chain, \@zero_array); + +if($channel_by_channel == true) { + $outermost_channel_loop_counter = 15; +} + +my @outermost_channel_loop = (0); + +if($channel_by_channel) { + @outermost_channel_loop = (0 .. $outermost_channel_loop_counter); +} + +#print "channellist:\n"; +#print Dumper \@outermost_channel_loop; + +foreach my $current_channel_outer_loop (@outermost_channel_loop) { + +if($channel_by_channel) { + $channel_to_set = $current_channel_outer_loop; + write_thresholds($mode, $chain, \@zero_array); +} + +$number_of_steps = 0; + while ($number_of_steps < $number_of_iterations || grep({$_ == 0} @best_thresh) > 0 ) { @@ -147,7 +179,7 @@ while ($number_of_steps < $number_of_iterations || if ($mode eq "padiwa") { - write_thresholds($mode, $chain, \@current_thresh); + write_thresholds($mode, $chain, \@current_thresh, $channel_to_set); # wait settling time, experimentally determined to 0.04 seconds select(undef, undef, undef, 0.05); @@ -160,8 +192,12 @@ while ($number_of_steps < $number_of_iterations || #print Dumper $rh_res; #print Dumper $old_rh_res; + my @iterate_loop = (0..15); + if($channel_by_channel) { + @iterate_loop = ($current_channel_outer_loop); + } - foreach my $i (0..15) { + foreach my $i (@iterate_loop) { $interval_step = $interval_step[$i]; my $cur_hitreg = $rh_res->{$endpoint}->[$i*$hitchannel_multiplicator]; @@ -221,6 +257,7 @@ while ($number_of_steps < $number_of_iterations || "new thresh: " . sprintf("0x%x", $current_thresh[$i]) . ", step_size: " . sprintf ("0x%04x best: 0x%04x", $interval_step[$i], $best_thresh[$i]); + #print "$str\n"; $logger->info($str); } # end of loop over 15 channel @@ -230,12 +267,14 @@ while ($number_of_steps < $number_of_iterations || } #end of loop over steps + map { $_-= $offset } @best_thresh; -write_thresholds($mode, $chain, \@best_thresh); +write_thresholds($mode, $chain, \@best_thresh, $channel_to_set); my $uid; -foreach my $i (reverse (0..3)) { +foreach my $i (reverse (0 .. 3)) { #print "send command: $endpoint , i: $i\n"; + # read uids $rh_res = Dmon::PadiwaSendCmd(0x10000000 | $i * 0x10000, $endpoint, $chain); $uid .= sprintf("%04x", $rh_res->{$endpoint} &0xffff); #print $uid; @@ -244,11 +283,25 @@ foreach my $i (reverse (0..3)) { my $str; #$logger_data->info("thresholds have been set to the following values:"); #$logger_data->info(sprintf "endpoint: %04x, chain: %02d, uid: $uid", $endpoint, $chain); -$logger_data->info("\t".time); -foreach my $i (0..15) { - $logger_data->info(sprintf "endpoint: 0x%04x, chain: %02d, channel: %2d threshold: 0x%04x, uid: %s", $endpoint, $chain, $i, $best_thresh[$i], $uid ); +#$logger_data->info("\t".time); + +my @range = (0 .. 15); + +if($channel_by_channel) { + @range = ($current_channel_outer_loop .. $current_channel_outer_loop); } +#print "range2: "; +#print Dumper @range; + +foreach my $i (@range) { + my $str = sprintf "endpoint: 0x%04x, chain: %02d, channel: %2d threshold: 0x%04x, uid: %s", $endpoint, $chain, $i, $best_thresh[$i], $uid; + #print "$str\n"; + $logger_data->info($str); +} + +} # end of channel_by_channel loop + exit; @@ -267,7 +320,7 @@ sub read_thresholds { # my $rh_res = trb_register_write($endpoint,0xd410, 1 << $chain); - foreach my $current_channel (0..15) { + foreach my $current_channel (0 .. 15) { my $command; my $fixed_bits; @@ -299,7 +352,7 @@ sub read_thresholds { sub write_thresholds { - (my $mode, my $chain, my $ra_thresh) = @_; + (my $mode, my $chain, my $ra_thresh, my $channel_to_set) = @_; $share->store($chain); @@ -310,7 +363,14 @@ sub write_thresholds { ### old and wrong way #my $rh_res = trb_register_write($endpoint,0xd410, 1 << $chain); - foreach my $current_channel (0..15) { + my @range = (0 .. 15); + if (defined $channel_to_set && $channel_to_set <16 ) { + @range = ($channel_to_set .. $channel_to_set); + #print "range: \n"; + } + + #print Dumper \@range; + foreach my $current_channel (@range) { my $command; my $fixed_bits;