+++ /dev/null
-#!/usr/bin/perl -w
-
-use strict;
-use warnings;
-#use Gtk2 -init; # please, who needs gtk for this?!?
-use Data::Dumper;
-use feature 'say';
-require POSIX;
-use Bit::Vector;
-use Getopt::Long;
-use threads;
-
-
-my $thr1;
-my $thr2;
-
-my $opt_help;
-my $opt_time;
-my $time;
-
-
-GetOptions ('h|help' => \$opt_help,
- 't|time=f' => \$opt_time
- );
-
-if($opt_help) {
- &help();
- exit(0);
-}
-
-
-sub help(){
- print "Usage: exec_evtbuild_t.pl -t <float>
-
-required:
- [-t|--time <seconds>] : The runtime of the daq_netmem (effective runtime).
- [-h|--help] : Show this help.
-
-"
-}
-
-
-if (defined($opt_time)){
- $time = $opt_time;
-}
-else{
- $time = 3;
-}
-
-
-
-$thr1 = threads->new(\&execute, "timeout -s SIGINT ".($time+1.5)." daq_evtbuild -m 1 -q 32 -d file -x te -Se -S boris");
-sleep 1;
-$thr2 = threads->new(\&execute, "timeout -s SIGINT ".$time." daq_netmem -m 1 -q 32 -i 50000 -S boris");
-
-$thr1->join();
-$thr2->join();
-
-
-
-
-
-sub execute {
- my $s = shift;
- system($s);
-}
+++ /dev/null
-#!/usr/bin/perl -w
-
-# TODO
-# this is veeeeryyyy ugly!!!
-
-
-use strict;
-use warnings;
-# use Gtk2 -init;
-use Data::Dumper;
-use Time::HiRes qw( gettimeofday usleep time );
-use FileHandle;
-use feature 'say';
-use Bit::Vector;
-use POSIX qw/floor ceil/;
-use Getopt::Long;
-use CGI ':standard';
-
-my $here = qx/pwd/;
-
-my $q = CGI->new;
-
-
-my $opt_help;
-my $opt_time;
-my $time;
-my $opt_id;
-
-GetOptions ('h|help' => \$opt_help,
- 't|time=f' => \$opt_time,
- 'id=s' => \$opt_id
- );
-
-if( $q->param('id') ) {
- $opt_id = $q->param('id');
-}
-
-if( $q->param('t') ) {
- $opt_time = $q->param('t');
-}
-
-if($opt_help) {
- &help();
- exit(0);
-}
-
-unless($opt_time && $opt_id){
- &help();
-# exit(0);
- $opt_time = 0.2;
- $opt_id = "ccc1ccc1";
-}
-
-
-sub help(){
- print "Usage: run.pl -t <float>
-
-required:
- [-t|--time <seconds>] : The runtime of the daq_netmem (effective runtime).
- [-id <id>] : The id of the sensor you want to test
-optional:
- [-h|--help] : Show this help.
-
-"
-}
-
-my $file;
-my @lines;
-my $pos;
-my $str;
-my $s;
-my $i;
-my $j;
-my $k;
-my $n;
-my $runtime;
-my $id;
-my $command;
-my @skiprun;
-
-my @data;
-my $run;
-my $mode;
-my $avg;
-my $counts;
-my $good_status;
-my $bad_status;
-my $broken;
-my @tokens;
-my $line;
-my $word;
-my @status_array;
-my @debug1_array;
-my @debug2_array;
-my @timestamp1_array;
-my @timestamp2_array;
-my @dlen_array;
-my @dcounter_array;
-my @framenum_array;
-my $dcount;
-my @pixels;
-
-my $avgA = 0;
-my $avgB = 0;
-my $avgC = 0;
-my $avgD = 0;
-my $undef_data;
-my @a;
-my $size;
-my $p1;
-my $p2;
-my $row;
-my $overflow;
-my $hits;
-my $col;
-
-
-
-
-
-
-
-
-
-sub run(){
-
-# execute("cd /daq/trb_maps_jtag3/ui/;./ui.pl;");
-# execute("trbcmd w 0xf013 0xc001 0x00FFFFFF");
-# execute("trbcmd w 0xf013 0xc006 0x00002eaa");
-# execute("cd /daq/trb_maps_jtag3/ui/;./start.pl");
-# sleep 1;
-# execute("trbcmd w 0xf013 0xc001 0x00000000");
-# execute("trbcmd w 0xf013 0xc002 0x00000010");
-# execute("trbcmd w 0xf013 0xc007 0x00000200");
-
- sleep 1;
-
- #execute("trbcmd w 0xf013 0xb120 0x0000000A");
-
-
- say "All tresholds set...";
-
- system("./exec_evtbuild_t.pl -t ".$runtime); #14
- system("mv te1* ./temp.hld");
-
-
- open(PIPE,"daq_anal ./temp.hld |");
-
-
-
- undef @data;
- $run = -1;
- $mode = 0;
- $i = 0;
- $avg = 0;
- $counts = 0;
- $good_status = 0;
- $bad_status = 0;
- $broken = 0;
- foreach $line (<PIPE>){
- @tokens = split(/ +/, $line);
- chomp(@tokens);
-
- foreach $word (@tokens){
-
- if ($word =~ "00000000:"){
- $mode = 1;
- $run++;
- # $done[$run] = 0;
- $status_array[$run] = Bit::Vector->new_Hex(32, substr("0x00000000",2,8));
- $debug1_array[$run] = Bit::Vector->new_Hex(32, substr("0x00000000",2,8));
- $debug2_array[$run] = Bit::Vector->new_Hex(32, substr("0x00000000",2,8));
- $timestamp1_array[$run] = Bit::Vector->new_Hex(32, substr("0x00000000",2,8));
- $timestamp2_array[$run] = Bit::Vector->new_Hex(32, substr("0x00000000",2,8));
- $dcounter_array[$run] = Bit::Vector->new_Hex(32, substr("0x00000000",2,8));
- $framenum_array[$run] = Bit::Vector->new_Hex(32, substr("0x00000000",2,8));
- $dcount = 0;
- }
-
- if ($mode == 1){
- if ($word =~ "ffffffff"){
- # $done[$run] = 1;
- $mode = 2;
- }
- }
- elsif ($mode == 2){
- if ($word =~ ":"){}
- else{
- #$id = "aaa".$opt_sensor."aaa".$opt_sensor;
- #$id = "c".$opt_chain."s".$opt_sensor."c".$opt_chain."s".$opt_sensor;
- if ($word =~ $id){
- # $done[$run] = 2;
- $mode = 3;
- }
- else{
- $mode = 1;
- }
- }
- }
- elsif ($mode == 3){
- if ($word =~ ":"){}
- else{
- # $done[$run] = 3;
- # say $word;
- $status_array[$run] = Bit::Vector->new_Hex(32, substr($word,2,8));
- # say $run;
- # say $status_array[$i]->to_Hex();
- $mode = 4;
- }
- }
- elsif ($mode == 4){
- if ($word =~ ":"){}
- else{
- # $done[$run] = 4;
- $debug1_array[$run] = Bit::Vector->new_Hex(32, substr($word,2,8));
- $mode = 5;
- }
- }
- elsif ($mode == 5){
- if ($word =~ ":"){}
- else{
- # $done[$run] = 5;
- $debug2_array[$run] = Bit::Vector->new_Hex(32, substr($word,2,8));
- $mode = 6;
- }
- }
- elsif ($mode == 6){
- if ($word =~ ":"){}
- else{
- # $done[$run] = 6;
- $timestamp1_array[$run] = Bit::Vector->new_Hex(32, substr($word,2,8));
- $mode = 7;
- }
- }
- elsif ($mode == 7){
- if ($word =~ ":"){}
- else{
- # $done[$run] = 7;
- $timestamp2_array[$run] = Bit::Vector->new_Hex(32, substr($word,2,8));
- $mode = 8;
- }
- }
- elsif ($mode == 8){
- if ($word =~ ":"){}
- else{
- # $done[$run] = 8;
- if ($word =~ "55555555"){
- #$dcount++;
- $mode = 9;
- }
- else{
- $mode = 0;
- }
- }
- }
- elsif ($mode == 9){
- if ($word =~ ":"){}
- else{
- # $done[$run] = 9;
- #$dcount++;
- $framenum_array[$run] = Bit::Vector->new_Hex(32, substr($word,2,8));
- $mode = 10;
- }
- }
- elsif ($mode == 10){
- if ($word =~ ":"){}
- else{
- $dlen_array[$run] = Bit::Vector->new_Hex(32, substr($word,2,8));
- $mode = 11;
- }
- }
- elsif ($mode == 11){
- if ($word =~ ":"){}
- else{
- if ($word =~ "80018001"){
- # $done[$run] = 11;
- $mode = 0;
- }
- elsif ($word =~ "ffffffff"){
- # $dcounter_array[$run] = $dcount;
- $mode = 0;
- $broken++;
- }
- else{
- # $done[$run] = 10;
- push(@{$data[$run]},$word);
- # $dcount++;
- }
- }
- }
- }
- $i++;
- }
-
-
- close(PIPE);
-
- say "Total frames: ".$run." broken: ".$broken;
-
- $i = 0;
- $j = 0;
- $k = 0;
-
-
- for ($i=0;$i<576;$i++){
- for ($j=0;$j<1152;$j++){
- $pixels[$i][$j]=0;
- }
- }
-
-
-
- $good_status = 0;
- $bad_status = 0;
- $avgA = 0;
- $avgB = 0;
- $avgC = 0;
- $avgD = 0;
- $counts = 0;
- $undef_data = 0;
- for ($i=0;$i<$run;$i++){
-
- if ($status_array[$i]->to_Hex() =~ /f000000f/i){
- $good_status++;
- $counts++;
-
- if (defined($data[$i])){
- @a = @{$data[$i]};
- $size = 0;
- foreach $word (@a){
- #print "\n<<< ".$word;
- #say $word;
- $p1 = Bit::Vector->new_Hex(16, substr($word,2,4));
- $p2 = Bit::Vector->new_Hex(16, substr($word,6,4));
- if ($size == 0){
- #print "\n >>> size 0";
- $size = int($p1->Chunk_Read(4,0));
- $row = int($p1->Chunk_Read(11,4));
- $overflow = int($p1->Chunk_Read(1,15));
- $hits = int($p2->Chunk_Read(2,0));
- $col = int($p2->Chunk_Read(11,2));
- #print "\n ".$p1->to_Bin();
- #print "\n size ".$size." row ".$row." ov ".$overflow;
- #print "\n ".$p2->to_Bin();
- #print "\n col ".$col." hits ".$hits;
- #print DATA $row." ".$col."\n";
- $pixels[$row][$col]++;
- if ($col < 288) {$avgA++;} elsif ($col < 576){$avgB++;} elsif ($col < 864){$avgC++;} elsif ($col < 1152){$avgD++;}
- if ($hits > 0){
- for ($k=0;$k<$hits;$k++){
- $col++;
- if ($col < 288) {$avgA++;} elsif ($col < 576){$avgB++;} elsif ($col < 864){$avgC++;} elsif ($col < 1152){$avgD++;}
- #print "\n +col ".$col;
- #print DATA $row." ".$col."\n";
- $pixels[$row][$col]++;
- }
- }
- $size--;
- }
- elsif ($size == 1){
- #print "\n >>> size 1";
- #print "\n ".$p1->to_Bin();
- $hits = int($p1->Chunk_Read(2,0));
- $col = int($p1->Chunk_Read(11,2));
- #print "\n col ".$col." hits ".$hits;
- #print DATA $row." ".$col."\n";
- if ($col < 288) {$avgA++;} elsif ($col < 576){$avgB++;} elsif ($col < 864){$avgC++;} elsif ($col < 1152){$avgD++;}
- $pixels[$row][$col]++;
- if ($hits > 0){
- for ($k=0;$k<$hits;$k++){
- $col++;
- if ($col < 288) {$avgA++;} elsif ($col < 576){$avgB++;} elsif ($col < 864){$avgC++;} elsif ($col < 1152){$avgD++;}
- #print "\n +col ".$col;
- #print DATA $row." ".$col."\n";
- $pixels[$row][$col]++;
- }
- }
- $size = int($p2->Chunk_Read(4,0));
- $row = int($p2->Chunk_Read(11,4));
- $overflow = int($p2->Chunk_Read(1,15));
- #print "\n ".$p2->to_Bin();
- #print "\n size ".$size." row ".$row." ov ".$overflow;
- }
- else{
- #print "\n >>> size ".$size;
- $hits = int($p1->Chunk_Read(2,0));
- $col = int($p1->Chunk_Read(11,2));
- if ($col < 288) {$avgA++;} elsif ($col < 576){$avgB++;} elsif ($col < 864){$avgC++;} elsif ($col < 1152){$avgD++;}
- #print "\n ".$p1->to_Bin();
- #print "\n col ".$col." hits ".$hits;
- #print DATA $row." ".$col."\n";
- $pixels[$row][$col]++;
- if ($hits > 0){
- for ($k=0;$k<$hits;$k++){
- $col++;
- if ($col < 288) {$avgA++;} elsif ($col < 576){$avgB++;} elsif ($col < 864){$avgC++;} elsif ($col < 1152){$avgD++;}
- #print "\n +col ".$col;
- #print DATA $row." ".$col."\n";
- $pixels[$row][$col]++;
- }
- }
- $size--;
- $hits = int($p2->Chunk_Read(2,0));
- $col = int($p2->Chunk_Read(11,2));
- if ($col < 288) {$avgA++;} elsif ($col < 576){$avgB++;} elsif ($col < 864){$avgC++;} elsif ($col < 1152){$avgD++;}
- #print "\n ".$p1->to_Bin();
- #print "\n col ".$col." hits ".$hits;
- #print DATA $row." ".$col."\n";
- $pixels[$row][$col]++;
- if ($hits > 0){
- for ($k=0;$k<$hits;$k++){
- $col++;
- if ($col < 288) {$avgA++;} elsif ($col < 576){$avgB++;} elsif ($col < 864){$avgC++;} elsif ($col < 1152){$avgD++;}
- #print "\n +col ".$col;
- #print DATA $row." ".$col."\n";
- $pixels[$row][$col]++;
- #print "debug: ".$pixels[$row][$col]." ".$row." ".$col."\n";
- }
- }
- $size--;
- }
- }
- }
- else{
- $undef_data++;
- }
- }
- else{
- $bad_status++;
- }
-
- }
-
- say "good: ".$good_status." bad: ".$bad_status;
- say "Total hits: ".$avgA." ".$avgB." ".$avgC." ".$avgD."\n";
-
- if ($counts > 0){
- $avgA = $avgA/$counts;
- $avgB = $avgB/$counts;
- $avgC = $avgC/$counts;
- $avgD = $avgD/$counts;
-
- say "Normalized: ".$avgA." ".$avgB." ".$avgC." ".$avgD."\n";
-
-# $avgal->set_text("ADC A - ".$avgA);
-# $avgbl->set_text("ADC B - ".$avgB);
-# $avgcl->set_text("ADC C - ".$avgC);
-# $avgdl->set_text("ADC D - ".$avgD);
- }
- else{
- say "Error: NO GOOD FRAMES!!!";
-# $avgal->set_text("ADC A - n/a");
-# $avgbl->set_text("ADC B - n/a");
-# $avgcl->set_text("ADC C - n/a");
-# $avgdl->set_text("ADC D - n/a");
- }
-
-# $stats->set_text("Statistics (total/broken/good/bad): $run / $broken / $good_status / $bad_status");
-
- open(DATA,"> ./bitmap_1.pix") || die("Cannot create data file!");
-
- for ($i=0;$i<576;$i++){
- for ($j=0;$j<1152;$j++){
- print DATA $pixels[$i][$j]." ";
- }
- print DATA "\n";
- }
- close(DATA);
-
-
- $command = "
- gnuplot -e \"
- set terminal pngcairo;
- set palette model RGB;
- set xrange [0:1152];
- set yrange [0:576];
- set cbrange [0:20000];
- set palette defined ( 0 'white', 1 'red', 5 'black', 10 'blue', 20000 'green');
- set output './image_recalibrated_1.png';
- plot './bitmap_1.pix' matrix with image;
- exit;
- \"
- ";
-
-
- system($command);
-
-}
-
-
-sub execute {
- my $s = shift;
- system($s);
-}
-
-
-
-
-
-system("rm image_recalibrated_1.png");
-
-$runtime = $opt_time;
-$id =$opt_id;
-
-$ENV{'JTAGPATH'}="/local.1/jtag_mvd/soft/toolbox/jtag_atomic/";
-$ENV{'DAQOPSERVER'}="localhost:7";
-chdir("../");
-system("./startup.pl ../setup/testsetup.xml");
-chdir("preview");
-
-run();
-
-
-1;
+++ /dev/null
-#!/usr/bin/perl -w
-
-use English;
-use strict;
-use Getopt::Long;
-use Data::Dumper;
-use FileHandle;
-use feature "switch";
-use POSIX qw/strftime/;
-my $SensorHeaderLength = 7;
-
-my $Statistics;
-my $PMap;
-
-
-###############################################################################
-## Configuration ##############################################################
-###############################################################################
-
-
-my $file;
-my $opt_help = 0;
-my $opt_verb = 0;
-my $opt_debug = 0;
-my $opt_frameinfo = 0;
-my $totalevents = 1E9;
-my $mode = "";
-
-GetOptions ('h|help' => \$opt_help,
- 'f|file=s' => \$file,
- 'v|verb' => \$opt_verb,
- 'i|info' => \$opt_frameinfo,
- 'd|debug' => \$opt_debug,
- 'e|events=i' => \$totalevents);
-
-
-
-
-if($opt_help) {
- printf("Usage: unpack_hld.pl \n");
- printf("[-h|--help] Show this help\n");
- printf("-f|--file <file> Path to hld file\n");
- printf("[-v|--verb] Dump hld file content\n");
- printf("[-i|--info] Show frame information\n");
- printf("[-d|--debug] More debugging output\n");
- printf("\n");
- exit;
- }
-
-
-
-###############################################################################
-## HLD Reader #################################################################
-###############################################################################
-
-
-if(&checkArgs()){
- exit(0);
-}
-
-my @evtHeader_list = ();
-my $evtHeader_aref = \@evtHeader_list;
-
-my @subEvtHeader_list = ();
-my $subEvtHeader_aref = \@subEvtHeader_list;
-
-my @data_list = ();
-my $data_aref = \@data_list;
-
-my $fh = new FileHandle("$file", "r");
-
-while(1){
- @evtHeader_list = ();
-
- &getEvtHeader($fh,$evtHeader_aref);
- &printEvtHeader($evtHeader_aref) if($opt_verb);
-
- my $evtSize = $evtHeader_aref->[0];
- if (!defined $evtSize || $evtSize < 0x10) {last;}
-
- #- If the size is only 32 Bytes -> goto to
- # the next Event Header since there are no subevents
- next unless defined $evtSize;
- next if($evtSize == 32);
-
- my $size_cntr = 32; # Bytes
-
- while($evtSize > $size_cntr){
-
- @subEvtHeader_list = ();
-
- my $endian = &getSubEvtHeader($fh,$subEvtHeader_aref);
- &printSubEvtHeader($subEvtHeader_aref) if($opt_verb);
-
- my $subEvtSize = $subEvtHeader_aref->[0];
-
- $size_cntr = $size_cntr + $subEvtSize;
-
- #- If the size is only 16 Bytes -> goto to
- # the next Sub Event Header since there are no subevents
- next if($subEvtSize == 16);
-
- @data_list = ();
- &getSubEvtData($fh, $data_aref, $subEvtSize, $endian);
- &printData($data_aref) if($opt_verb);
-
- my $paddedSize = &padding($fh, $subEvtSize);
-
- $size_cntr = $size_cntr + $paddedSize;
-
- #----------> User function <---------
- &analyzeData($evtHeader_aref, $subEvtHeader_aref, $data_aref);
- }
-}
-
-WriteResults();
-
-$fh->close();
-
-exit(0);
-
-####################### END OF MAIN ###################
-
-sub printEvtHeader()
-{
- my ($data_aref) = @_;
-
- print "\n";
-
- printf("size: %08x ", $data_aref->[0]);
- printf("decoding: %08x ", $data_aref->[1]);
- printf("id: %08x ", $data_aref->[2]);
- printf("seqNr: %08x\n", $data_aref->[3]);
-
- my $year = (($data_aref->[4] >> 16) & 0xff) + 1900;
- my $mon = (($data_aref->[4] >> 8) & 0xff) + 1;
- my $mday = ($data_aref->[4] >> 0) & 0xff;
-
- my $hour = ($data_aref->[5] >> 16) & 0xff;
- my $min = ($data_aref->[5] >> 8) & 0xff;
- my $sec = ($data_aref->[5] >> 0) & 0xff;
-
- printf("date: %04d-%02d-%02d ", $year, $mon, $mday);
- printf("time: %02d:%02d:%02d ", $hour, $min, $sec);
- printf("runNr: %08x ", $data_aref->[6]);
- printf("expId: %08x\n", $data_aref->[7]);
-}
-
-sub printSubEvtHeader()
-{
- my ($data_aref) = @_;
-
- print "\n";
-
- printf("size: %08x ", $data_aref->[0]);
- printf("decoding: %08x ", $data_aref->[1]);
- printf("id: %08x ", $data_aref->[2]);
- printf("trigNr: %08x\n", $data_aref->[3]);
-}
-
-sub printData()
-{
- my ($data_aref) = @_;
-
- my $cntr = 0;
-
- print "\n";
-
- foreach my $word (@$data_aref){
- printf("%08x ", $word);
-
- $cntr++;
-
- print "\n" if( ($cntr%4) == 0);
- }
-}
-
-sub getEvtHeader()
-{
- my ($fh, $data_aref) = @_;
-
- my @tmp_list;
-
- foreach my $i (1..8){
- my $header;
-
- read($fh, $header, 4);
-# &checkEndOfFile($fh, $header);
-
- push(@tmp_list, $header);
- }
-
- my $decoding = unpack("V*", $tmp_list[1]);
- my $endian = &getEndianess($decoding);
-
- unless(defined $decoding) {
- printf "This seems to be the end\n" if $opt_verb;
- return -1;
- }
-
- if($opt_debug){
- if($endian){
- printf("\n Event Decoding: %08x Byte Order: Little Endian\n", $decoding);
- }
- else{
- printf("\n Event Decoding: %08x Byte Order: Big Endian\n", $decoding);
- }
- }
-
- foreach my $tmp (@tmp_list){
- my $word;
-
- if($endian){
- $word = unpack("V*", $tmp); # Small Endian
- }
- else{
- $word = unpack("N*", $tmp); # Big Endian
- }
-
- push(@$data_aref, $word);
- }
-}
-
-sub getSubEvtHeader()
-{
- my ($fh, $data_aref) = @_;
-
- my @tmp_list;
-
- foreach my $i (1..4){
- my $header;
-
- read($fh, $header, 4);
-# &checkEndOfFile($fh, $header);
-
- push(@tmp_list, $header);
- }
-
- my $decoding = unpack("V*", $tmp_list[1]);
- my $endian = &getEndianess($decoding);
- if($opt_debug){
- if($endian){
- printf("\n SubEvent Decoding: %08x Byte Order: Little Endian\n", $decoding);
- }
- else{
- printf("\n SubEvent Decoding: %08x Byte Order: Big Endian\n", $decoding);
- }
- }
-
- foreach my $tmp (@tmp_list){
- my $word;
-
- if($endian){
- $word = unpack("V*", $tmp); # Small Endian
- }
- else{
- $word = unpack("N*", $tmp); # Big Endian
- }
-
- push(@$data_aref, $word);
- }
-
- return $endian;
-}
-
-sub getEndianess()
-{
- my ($decoding) = @_;
-
- # Return values:
- # 0 : Big Endian
- # 1 : Little Endian
- #
- # Usually (when sent by GbE-FPGAs) Event Headers are Little Endian
- # SubEvent Headers and data are Big Endian
-
- my $retVal = 0;
-
- if(defined($decoding) && ($decoding & 0x000000ff) > 0){
- $retVal = 1; # This is Little Endian
- }
-
- return $retVal;
-}
-
-sub getSubEvtData() {
- my ($fh, $data_aref, $size, $endian) = @_;
-
- #- Subtract subevent header size and devide by word size
- my $nrOfWords = ($size - 16)/4;
- my $tmp;
-
- my @tmps;
- read($fh, $tmp, 4*$nrOfWords);
- if($endian){
- @$data_aref = unpack("v*",$tmp);
- }
- else{
- @$data_aref = unpack("n*",$tmp);
- }
-
-# my $word;
-# foreach my $i (1..$nrOfWords){
-# read($fh, $tmp, 4);
-# if($endian){
-# $word = unpack("V*", $tmp); # Little Endian
-# }
-# else{
-# $word = unpack("N*", $tmp); # Big Endian
-# }
-# push(@$data_aref, $word);
-# }
- }
-
-sub padding()
-{
- my ($fh, $size) = @_;
-
- my $retVal = 0; # Size of the padded word
-
- #- Check 64-bit (8-Byte) alignment
- unless( ($size%8) == 0){
- my $tmp;
- read($fh, $tmp, 4);
- $retVal = 4; # Bytes
- }
-
- return $retVal;
-}
-
-sub checkEndOfFile()
-{
- my ($fh, $tmp) = @_;
-
- unless( defined $tmp){
- #- The end of the file
- print "\n End of file\n";
- $fh->close();
- exit(0);
- }
-}
-
-sub checkArgs()
-{
- my $retVal = 0;
-
- unless( defined $file){
- print "\n You must provide a path to the hld file!\n";
- print " Read help.\n";
- $retVal = 1;
- }
-
- return $retVal;
-}
-
-
-
-
-
-
-
-###############################################################################
-## MVD Unpacker ###############################################################
-###############################################################################
-
-
-
-sub analyzeData() {
- my ($evtHeader, $subEvtHeader, $data) = @_;
- my $EvtId = $evtHeader->[3];
- my $pos = 0;
- my $time = 0;
- my $SubEvtSize = $subEvtHeader->[1]/4-6;
-
- SSELoop: while(1) { #Loop over SubSubEvents
-
- #Read SubSubEvent Header
- my $RocLength = $data->[$pos++];
- my $RocId = $data->[$pos++];
- if($RocId == 0x5555) {last;}
- my $RocEnd = $pos + $RocLength*2 -1;
-
- SensLoop: while(1) { #Loop over Sensors
- #Read Sensor Header
- my $SensorHead = ($data->[$pos+0] << 16) + $data->[$pos+1];
- my $SensorId = $data->[$pos+3];
- my $SensorStatus = ($data->[$pos+4] << 16) + $data->[$pos+5];
- my $SensorError = ($data->[$pos+6] << 16) + $data->[$pos+7];
- my $SensorDebug = ($data->[$pos+8] << 16) + $data->[$pos+9];
- $pos+=10;
-
- if($opt_frameinfo) {
- my $SensorTime = sprintf("%04x%04x%04x%04x",$data->[$pos+2],$data->[$pos+3],$data->[$pos],$data->[$pos+1]) if $opt_frameinfo;
- printf("Head\t%8x\tID\t%8x\tStatus\t%08x\tError\t%08x\tDebug\t%08x\tTime\t%s\n",
- $SensorHead, $SensorId, $SensorStatus, $SensorError, $SensorDebug, $SensorTime);
- }
- $pos+= 4;
-
- $PMap->{$SensorId}->[575]->[1151] = 0 unless defined $PMap->{$SensorId}->[575]->[1151];
- my $matrix = $PMap->{$SensorId};
-
-
-
-
-
- #Could it be...?
- if($SensorHead != 0xffffffff) {
- #Something is really wrong with data. Skip SubEvent!
- printf("Broken Sensor Header\n") if $opt_frameinfo;
- $Statistics->{$SensorId}->{Broken}++;
- last SSELoop;
- }
-
- #Check Status Word
- my $SensorIsValid = 0;
- if($SensorStatus == 0xf000000f) {
- $SensorIsValid = 1;
- $Statistics->{$SensorId}->{Valid}++;
- }
- else {
- $SensorIsValid = 0;
- $Statistics->{$SensorId}->{Broken}++;
- }
-
- if($SensorIsValid){
- #Hey Sensor, tell me who you are!
- my $SensorDummy = ($data->[$pos+0] << 16) + $data->[$pos+1];
- my $SensorNumber = ($data->[$pos+2] << 16) + $data->[$pos+3];
- my $SensorLength = $data->[$pos+5];
- $pos+=6;
-
- printf("\t\t\tHeader\t%08x\tFrame\t%08x\tLength\t%i\n",
- $SensorDummy, $SensorNumber, $SensorLength) if $opt_frameinfo;
-
- my $FrameEndPos = $pos + $SensorLength*2;
- my ($d, $line, $column, $pixels, $statecnt, $ovf) = (0,0,0,0,0,0);
- while(1) {
- $d = $data->[$pos++];
-
- #Is new line?
- if($statecnt-- == 0) {
- $ovf += ($d >> 15) & 1;
- $line = ($d >> 4) & 0x7FF;
- $statecnt = $d & 0xF;
- }
- else {
- $pixels = ($d & 0x3);
- $column = ($d >> 2) & 0x7FF;
- printf("\t$line, $column x %d\n",$pixels+1) if $opt_frameinfo;
-
- $matrix->[$line]->[$column]++;
- if ($pixels > 0) {
- $matrix->[$line]->[$column+1]++;
- if ($pixels > 1) {
- $matrix->[$line]->[$column+2]++;
- if ($pixels > 2) {
- $matrix->[$line]->[$column+3]++;
- }
- }
- }
- }
-
- last if $pos >= $FrameEndPos;
- }
-
-
- #Read end of frame marker without check
- $pos+=2;
- }
- else {
- #TODO: handling for frames with invalid status, but data.
- }
- if($pos >= $RocEnd){
- last SensLoop;
- }
- }
- }
- }
-
-
-sub WriteResults {
-
-
- foreach my $id (keys $Statistics) {
- #No frames? No plot!
- if(!defined $Statistics->{$id}->{Valid}) {next;}
-
- my $fn = "gnuplot";
- $fh = new FileHandle ("|$fn") or die "error: no gnuplot";
- $fh->autoflush(1);
-
- print $fh "set terminal png size 800,400 font \",9\";\n";
- print $fh strftime("set label 100 \"%H:%M:%S\" at screen 0.98,0.02 right tc rgb \"#000044\" font \"monospace,8\"\n", localtime());
- print $fh "set palette model RGB;\n";
- print $fh "set xrange [0:1152];\n";
- print $fh "set yrange [0:576];\n";
- print $fh "set cbrange [0:5000];\n";
- print $fh "set palette defined ( 0 'white', 1 'red', 5 'black', 10 'blue', 5000 'green');\n";
- my $s = sprintf("%04x",$id);
- print $fh "set output './image_recalibrated_$s.png';\n";
- print $fh "plot '-' matrix with image\n";
-
- my @matrix;
-
- for(my $y = 0; $y < 576; $y++) {
- my $map = $PMap->{$id}->[$y];
- #Define lengths of all arrays
- $map->[1152] = 0;
- #Fill undef with 0
- @matrix = map {$_ || 0 } @{$map};
- #Join lines
- my $l = join(" ",@matrix);
- print $fh $l."\n";
- }
-
- print $fh "e\nexit\n";
- $fh->close();
- }
-
-
- }
-
+++ /dev/null
-
-// var sensorIdHash = new Object();
-
-
-
-
-function reloadQuickEditArea(configFile,destId) {
-
- var configFile_ = encodeURIComponent(configFile);
- var destId_ = encodeURIComponent(destId);
- getdata("testgui.pl?action=print_quickEditArea&configFile="+configFile_+"&destId="+destId_,destId,false);
-
-}
-
-
-
-function run(time) {
-// sensorIdHash["hugo"]="hugo";
-// sensorIdHash["hugo2"]="hugonaut";
-
-
- for( var sensorId in previewAreaIdHash){
-// alert(laufid+" => "+previewAreaIdHash[laufid]);
- var sensorId_ = encodeURIComponent(sensorId);
- getdata("testgui.pl?action=showPlot&sensorId=",previewAreaIdHash[sensorId],true);
- }
-
- getdata("run.pl","theConsole",false);
-
- for( var sensorId in previewAreaIdHash){
-// alert(laufid+" => "+previewAreaIdHash[laufid]);
- var sensorId_ = encodeURIComponent(sensorId);
- getdata("testgui.pl?action=showPlot&sensorId="+sensorId_,previewAreaIdHash[sensorId],true);
- }
-}
-
-
-
-function toggleVis(elementId) {
-if(document.getElementById(elementId)){
-if( document.getElementById(elementId).style.visibility == "visible") {
- document.getElementById(elementId).style.visibility = "collapse";
-} else {
- document.getElementById(elementId).style.visibility = "visible" ;
-}
-}
-}
\ No newline at end of file
+++ /dev/null
-#!/usr/bin/perl -w
-#print "Content-type: text/html\n\n";
-
-
-my $me = "testgui.pl";
-
-use strict;
-use warnings;
-use XML::LibXML;
-use POSIX;
-use CGI ':standard';
-use CGI::Carp qw(fatalsToBrowser);
-use HTML::Entities;
-require Common;
-require xmlOperations;
-
-
-##### preliminary hardcoded stuff:
-
-our $setupDir = '../setup';
-our $confDir = '../config';
-our $specDir = '../specs';
-
-my $setupFileName = "testsetup.xml";
-my $setupFile = $setupDir."/".$setupFileName;
-
-# the file that tells me what fields should be printed in the quick edit area
-# for each sensor
-my $quickEditMaskFileName = "quickEditMask.xml";
-my $quickEditMaskFile = $confDir."/".$quickEditMaskFileName;
-
-
-#### globals:
-
-my $quickEditMaskTree;
-my $setupTree;
-my $sensorAreaId;
-my $quickEditAreaId;
-
-my %previewAreaIdHash;
-
-
-#######################
-
-my $q = CGI->new;
-
-
-
-unless($q->param()) {
- #if called without arguments,
- init_html();
-} else {
-#####################################
-######## process CGI request ########
-#####################################
- print header;
- #process the arguments
-
- if ($q->param('action') eq "print_quickEditArea") {
- my $configFileName = $q->param('configFile');
- my $destId = $q->param('destId');
- $quickEditAreaId = $destId;
- print_quickEditArea($configFileName);
- } elsif ($q->param('action') eq "showPlot") {
-
- my $sensorId = $q->param('sensorId');
- my $imgSrc = './preview/image_recalibrated_'.$sensorId.'.png';
- if (-e $imgSrc) {
- print img{src=>$imgSrc."?".rand(),title=>$sensorId};
- } else {
- print img{src=>"./preview/error.jpg",title=>$sensorId};
- }
- } else {
-
- print start_html(
- -title=>'testgui_debug',
- -style=>{'src'=>'../layout/styles.css'}
- );
- report_param();
-
- }
-
-}
-
-
-
-
-
-
-
-
-
-##################################
-#### Subs
-##################################
-
-sub parse_setupFile {
- my $parser = XML::LibXML->new();
- unless( -e $setupFile) {
- die "setup file $setupFile does not exist!\n";
- }
- $setupTree = $parser->parse_file($setupFile);
-}
-
-
-sub parse_quickEditMaskFile {
- my $parser = XML::LibXML->new();
- unless( -e $quickEditMaskFile) {
- die "quickEditMaskFile $quickEditMaskFile does not exist!\n";
- }
- $quickEditMaskTree = $parser->parse_file($quickEditMaskFile);
-}
-
-
-
-sub init_html{
-
-print header;
-print start_html(
--title=>'testgui',
--style=>[{'src'=>'../layout/styles.css'},
-{'src'=>'../layout/testgui.css'}
-],
--script=>[
-{ -type => 'text/javascript', -src => './testgui.js'},
-{ -type => 'text/javascript', -src => './getdata.js'},
-{ -type => 'text/javascript', -src => './xmlOperations.js'}
-]
-);
-
-# print h2("testgui");
-
-
-# print "<div>";
-#
-# print "<table>";
-# print "<tr><td>IVDREF1A</td><td>IVDREF1B</td></tr>";
-# print "<tr><td><input type='text' id='IVDREF1A'></td></tr>";
-# print "</table>";
-#
-#
-# print "</div>";
-
-
-
-
-# print "<div id='quickEditArea'>";
-# print_quickEditArea("0.xml");
-# print "</div>";
-print_setupStructure();
-print q%<input type='button' onClick='run(0.2)' value='run'>%;
-
-
-
-
-# pass a list of sensor Ids to the javascript side
-# more precisely: a hash consisting of $sensorId=>$previewAreaId
-# so the javascript knows which placeholders to fill with actual plots
-print "<script language='javascript'>\n";
-print "var previewAreaIdHash = new Object();\n";
-for my $sensorId (keys %previewAreaIdHash){
- print "previewAreaIdHash[\"$sensorId\"]=\"".$previewAreaIdHash{$sensorId}."\";\n";
-}
-print "</script>";
-# end of that story
-
-print "<input type='button' value='show/hide debug output' onclick='toggleVis(\"theConsole\")'>";
-print "<div id='theConsole'>[the \"console\"]</div>";
-
-print end_html;
-
-
-
-}
-
-
-
-
-sub print_setupStructure {
-
- unless(defined($setupTree)) {
- parse_setupFile();
- }
- my $setup = $setupTree->findnodes("/DetectorSetup")->shift();
- unless(defined($setup)) { die "did not find DetectorSetup node in setup file!\n";}
- my $setupDesc = $setup->findvalue("./description");
- my $setupName = $setup->findvalue("./\@name");
- print h2("Setup: $setupName");
- print "<p>description: $setupDesc</p>";
-
- my @controllers = $setup->findnodes("./controller");
- unless(scalar(@controllers) > 0) { die "no controllers in setup file!\n";}
- for my $controller (@controllers) {
- my $controllerName = $controller->findvalue("./\@name");
- my $controllerAddress = $controller->findvalue("./\@address");
- my $controllerId = $controller->findvalue("./\@id");
- print h3("Controller name:$controllerName id:$controllerId address:$controllerAddress");
-
- my @chains = $controller->findnodes("./chain");
- unless(scalar(@chains)>0) {die "no chains attached to controller $controllerName\n";}
-
- for my $chain (@chains) {
- my $chainName = $chain->findvalue("./\@name");
- my $chainId = $chain->findvalue("./\@id");
- print h4("Chain name:$chainName id:$chainId");
-
- my @sensors = $chain->findnodes("./sensor");
- unless(scalar(@sensors)>0) { die "no sensors attached to chain $chainName\n";}
- for my $sensor (@sensors) {
-
- my $sensorId = $sensor->findvalue("./\@id");
- my $sensorName = $sensor->findvalue("./\@name");
- my $sensorConfig = $sensor->findvalue("./\@config");
- my $sensorEnabled = $sensor->findvalue("./\@enabled");
- my $sensorSerial = $sensor->findvalue("./\@serial");
- my $sensorPosition = $sensor->findnodes("./position")->shift();
- my $sensorDescription = $sensor->findvalue("./description");
-
-# print h5("Sensor name:$sensorName id:$sensorId");
-# print "<p>description: $sensorDescription</p>";
- print_sensorArea($sensor);
- }
-
- }
-
- }
-
-}
-
-
-sub report_param {
- print br,br;
- print "action ".$q->param('action')." executed with following parameters:",br;
- my @params = $q->param();
- print "<table>";
- for (@params) {
- print "<tr><td>";
- print escapeHTML($_);
- print "</td><td>=</td><td>";
- print escapeHTML($q->param($_));
- print "</td>";
-
- }
- print "</table>";
-
-}
-
-
-#### html output subs ###########
-
-sub print_sensorArea {
-
- my $sensor = $_[0];
- # this is an xml object that contains the sensor node
- # from the setup file
- my $sensorId = $sensor->findvalue("./\@id");
- my $sensorName = $sensor->findvalue("./\@name");
- my $sensorConfig = $sensor->findvalue("./\@config");
- my $sensorEnabled = $sensor->findvalue("./\@enabled");
- my $sensorSerial = $sensor->findvalue("./\@serial");
- my $sensorPosition = $sensor->findnodes("./position")->shift();
- my $sensorDescription = $sensor->findvalue("./description");
-
-
- $sensorAreaId = $sensorId;
- print "<div class='sensorAreaDiv' id='".$sensorAreaId."'>";
- print "<table class='sensorAreaTable'>";
- print "<tr>";
- print "<td colspan=2 align='center' class='td_solid'>";
- print "<table><tr><td>$sensorName (id=$sensorId)</td></tr>";
- print "<tr><td>description: $sensorDescription</td></tr></table>";
- print "</td>";
- print "</tr>";
- print "<tr>";
- my $previewAreaId = "preview_".$sensorId;
- print "<td id='".$previewAreaId."' class='previewArea'> [not run yet!] </td>";
- $quickEditAreaId = "quickEdit_".$sensorId;
- print "<td id='".$quickEditAreaId."' class='quickEditArea td_solid'>";
- print_quickEditArea($sensorConfig);
- print "</td>";
- print "</tr>";
-# print "<tr>";
-# print "<td colspan=2 align='right'>";
-# my $command = "./prevImg.pl";
-# print q%<input type='button' onClick='getdata("%.$command.q%","%.$previewAreaId.q%","true")' value='run'>%;
-# print "</td>";
-# print "</tr>";
- print "</table>";
- print "</div>";
-
- $previewAreaIdHash{$sensorId}=$previewAreaId;
-}
-# description the block that is printed for each sensor,
-# containing the preview plot and the quick edit area
-
-
-sub print_quickEditArea {
-
- my $argumentConfigFile = $_[0];
-
- unless(defined($quickEditMaskTree)) {
- parse_quickEditMaskFile();
- }
-
-# print "<table>";
-# my @fields = $quickEditMaskTree->findnodes("/MAPS/register/field");
-# for my $field (@fields) {
-# print "<tr><td>";
-# print $field->findvalue("./\@name");
-# print "</td></tr>";
-#
-#
-# }
-# print "</table>";
-# print "print_registers();",br;
- parseConfigAndSpec($argumentConfigFile);
- integrateAncestry();
- print "<div align=center>".getConfigFileName()."</div>";
- print_registers(getConfigFile());
-
-
-}
-
-
-
-
-sub print_registers {
-
- my $configFile = getConfigFile();
- my $specFile = getSpecFile();
- my $configFileName = getConfigFileName();
- my $specFileName = getSpecFileName();
- my $configTree = getConfigTree();
- my $specTree = getSpecTree();
-
- my $xmlfile = $_[0];
- my $xmltree;
-# if ( $xmlfile eq $configFile ) {
-# $xmltree = $configTree;
-# }
-# elsif ( $xmlfile eq $specFile ) {
-# $xmltree = $specTree;
-# }
-# else {
-# die "xmlfile given to sub print_registers is unknown";
-# }
- my @registers = sort by_name $quickEditMaskTree->findnodes("/MAPS/register");
- print "<table class=\"registers\"";
- if ( $xmlfile eq $configFile ) {
- print "id='configFileRegisters'";
- }
- print ">";
- for my $register (@registers) {
-
- my $registerName = $register->findvalue("./\@name");
-
-# # if register not in the mask file, don't print!
-# unless( $quickEditMaskTree->findnodes("/MAPS/register[\@name='".
-# $registerName."']")) {
-# next;
-# }
-
- my $registerId = $register->findvalue("./\@id");
- my $registerSize = $register->findvalue("./\@size");
- my $registerDescr = prepare_text(
- $specTree->findvalue(
- "/MAPS/register[\@name='" . $registerName . "']/description"
- )
- || "n/a"
- );
-
- my $flistid = $configFile . "//" . $registerName;
-
- print "<tr>";
-
- print <<EOF;
-<td onClick='toggleVis("$flistid",this)' class='regheader'> + </td>
-EOF
- print "<td title=\"$registerDescr\">$registerName</td>";
-
- #print "<td>$registerId</td>";
-
-# if ( $xmlfile eq $configFile ) { # we are printing the Specifications Tree
-# print <<EOF;
-# <td class='button_move' onclick='deleteSettings("$configFileName","$registerName","");reloadQuickEditArea("$configFileName","$quickEditAreaId")'> X </td>
-# EOF
-# }
-
-
- print "</tr>";
-
- #print "<tr>";
-
- print '<tr id="' . $flistid . '" class="bitfield">';
- print '<td></td>';
- print '<td class="fieldcontainer">';
- print_fields( $configFile, $register );
- print "<td>";
- print "</tr>";
- }
- print "</table>";
-}
-
-sub print_fields {
-
- my $configFile = getConfigFile();
- my $specFile = getSpecFile();
- my $configFileName = getConfigFileName();
- my $specFileName = getSpecFileName();
- my $configTree = getConfigTree();
- my $specTree = getSpecTree();
-
- my $register = $_[1];
- my $xmlfile = $_[0];
- my $registerName = $register->findvalue("./\@name");
- my @maskFields = sort by_name $register->findnodes("./field");
- print "<table class=\"fields\">";
- for my $maskField (@maskFields) {
-
- my $fieldName = $maskField->findvalue("./\@name");
-
- my $field = $configTree->findnodes("/MAPS/register[\@name='".
- $registerName."']/field[\@name='".$fieldName."']")->shift();
-
-
- unless(defined($field)){
-
- my $specField = $specTree->findnodes("/MAPS/register[\@name='".
- $registerName."']/field[\@name='".$fieldName."']")->shift();
- $field=$register->addNewChild("","field");
- $field->setAttribute("name",$fieldName);
- $field->setAttribute("value",$specField->findvalue("./\@defaultValue"));
- $field->setAttribute( "isHeritageFrom", $specFileName );
- }
-
-
-
-
-# # if field not in the mask file, don't print!
-# unless( $quickEditMaskTree->findnodes("/MAPS/register[\@name='".
-# $registerName."']/field[\@name='".$fieldName."']")) {
-# next;
-# }
-
- my $isHeritageFrom = $field->findvalue("./\@isHeritageFrom") || "";
-# my $isHeritageFrom = "";
- my $readOnlyFlag = 0;
- my $fieldValue = $field->findvalue("./\@value");
- my $fieldSize =
- $specTree->findvalue( "/MAPS/register[\@name='"
- . $registerName
- . "']/field[\@name='"
- . $fieldName
- . "']/\@size" )
- || "n/a";
- my $fieldDescr = prepare_text(
- $specTree->findvalue(
- "/MAPS/register[\@name='"
- . $registerName
- . "']/field[\@name='"
- . $fieldName
- . "']/description"
- )
- || "n/a"
- );
-
- my $maxFieldVal = 2**$fieldSize;
- my $sizeInfo =
- sprintf(
- "Field contains %d bits, possible values: 0-%d (0x0-0x%x)\n\n",
- $fieldSize, $maxFieldVal, $maxFieldVal );
-
- $fieldDescr = $sizeInfo . $fieldDescr;
-
- unless ( $isHeritageFrom eq "" ) {
- $fieldDescr =
- "Field was inherited from $isHeritageFrom\n\n" . $fieldDescr;
- }
-
- my $fieldId = $xmlfile . "//" . $registerName . "/" . $fieldName;
- if ( $fieldValue eq "" ) {
- $fieldValue = $field->findvalue("./\@defaultValue");
- $readOnlyFlag = 1;
- }
-
- print "<tr class='fileLevel" . getFileLevel($isHeritageFrom) . "'>";
- print "<td width=120 title=\"$fieldDescr\"";
- print ">$fieldName</td>";
- print "<td> = </td>";
- if ($readOnlyFlag) {
- print <<EOF;
- <td width=120 align='right'>$fieldValue</td>
-EOF
- }
- else {
- print <<EOF;
-<td align='right'>
-<input type='text' align='right' value='$fieldValue' onchange='saveSettings("$configFileName","$registerName","$fieldName",this.value);reloadQuickEditArea("$configFileName","$quickEditAreaId")' >
-</td>
-EOF
-
- }
-
- print '</td>';
-# if ( $xmlfile eq $specFile ) { # we are printing the Specifications tree
-# print <<EOF;
-# <td class='button_move' onclick='saveSettings("$configFileName","$registerName","$fieldName","$fieldValue");'> → </td>
-# EOF
-# }
- if ( $xmlfile eq $configFile ) { # we are printing the Settings Tree
-
- if ( $isHeritageFrom eq "" )
- { # these are actual settings, not inherited!
- print <<EOF;
-<td class='button_move' onclick='deleteSettings("$configFileName","$registerName","$fieldName");reloadQuickEditArea("$configFileName","$quickEditAreaId")'> X </td>
-EOF
- }
- else {
- print "<td class='button_move_deac'> X </td>";
- }
- }
- print "</tr>";
- if ( ( any2dec($fieldValue) < 0 )
- or ( any2dec($fieldValue) > $maxFieldVal ) )
- {
- print
-"<tr class='fieldError'><td colspan = 4 align='center'>!!!Above value not in allowed range!!!</td></tr>"
- ; # just debug
- }
- }
- print "</table>";
-
-}