--- /dev/null
+#!/usr/bin/perl -w
+
+
+# my $me = "adcmon.pl";
+
+use strict;
+use warnings;
+use POSIX;
+# use CGI ':standard';
+# use CGI::Carp qw(fatalsToBrowser);
+# use HTML::Entities;
+use Data::Dumper;
+use FileHandle;
+
+
+
+use FindBin;
+use lib "$FindBin::Bin/..";
+# my $entityFile = "../../daqtools/xml-db/cache/CbController.entity";
+# my $xmldb = AccessXmlDb->new( entityFile => $entityFile );
+# print any2hex(1234);
+# print join(":",@{$xmldb->channelList()});
+# print "\n";
+#
+
+my $xml_cbctrl_entity = "/home/micha/mnt/55local1/htdocs/daqtools/xml-db/cache/CbController.entity";
+
+my $daqopserver="jspc55:88";
+$ENV{'DAQOPSERVER'} = $daqopserver;
+
+
+my $xmldb = xmlDbMethods->new( entityFile => $xml_cbctrl_entity);
+
+
+
+
+
+$xmldb->dumpItem('EnaA');
+$xmldb->dumpItem('MiscConf');
+
+my $list = $xmldb->unfoldTree('CbUcRegs');
+# my $list = $xmldb->unfoldTree('MiscConf');
+
+my $data = [];
+
+for my $name (@$list) { # processing the list
+ my $node = $xmldb->{entity}->{$name};
+ my $type = $node->{type};
+ my $repeat = $node->{repeat} || 1;
+ my $stepsize = $node->{stepsize}||0;
+
+ my $bits = "";
+ if ($type ne 'register'){
+ my $start = $node->{start};
+ my $stop = $node->{start}+$node->{bits}-1;
+ if ($start == $stop){
+ $bits = $start;
+ } else {
+ $bits = "$start--$stop";
+ }
+ }
+
+ #indent register fields
+ if ($type eq 'field'){
+ $name= '\quad '.$name;
+ }
+
+ for (my $i=0;$i<$repeat;$i++){
+ my $name_ = $name;
+ if ($repeat > 1) {
+ $name_ = $name.".$i";
+ }
+ my $addr_ = $node->{address}+$i*$stepsize;
+ my $hexaddr = sprintf("0x%04x",$addr_ );
+ push(@{$data},{%$node, name => $name_, addr => $hexaddr, bits => $bits});
+ }
+}
+
+@$data = sort { $a->{bits} cmp $b->{bits} } @$data;
+@$data = sort { $a->{addr} cmp $b->{addr} } @$data;
+
+my $table = textabular->new();
+
+for my $item (@$data){
+$table->addData(%$item);
+}
+
+
+
+
+
+
+$table->{dataKeys} = [ 'name', 'addr', 'bits', 'description' ];
+$table->{format} = '@{} l l l p{8cm} @{}';
+
+my $tablefile = FileHandle->new("./table.tex", 'w');
+print $tablefile $table->generateString();
+$tablefile->close();
+
+print $table->generateString();
+
+package xmlDbMethods;
+
+use Storable qw(lock_store lock_retrieve);
+use Data::Dumper;
+
+sub new {
+ my $class = shift;
+ my %options = @_;
+ my $self = {
+ entityFile => '/dev/null',
+ %options
+ };
+ bless($self, $class);
+ $self->{entity} = lock_retrieve($self->{entityFile});
+ die "cannot open xml-db entity file ".$self->{entityFile}."\n" unless defined $self->{entity};
+ return $self;
+}
+
+sub channelParm {
+ my $self = shift;
+ my $chip = shift;
+ my $channel = shift;
+
+ my $parm;
+ %{$parm}= %{$self->{entity}->{$channel."D"}};
+
+ die "entry $channel does not exist for chip=".$chip."\n" if ($chip ge $parm->{repeat});
+
+ $parm->{address} += $chip * $parm->{stepsize};
+ return $parm;
+}
+
+sub dumpItem { # for debug
+ my $self = shift;
+ my $item = shift;
+ unless (defined($item)){
+ print Dumper $self->{entity};
+ } else {
+ print Dumper $self->{entity}->{$item};
+ }
+}
+
+sub channelList {
+ my $self = shift;
+ return $self->{entity}->{AdcSensor}->{children};# returns a reference to an array
+}
+
+sub unfoldTree {
+ my $self = shift;
+ my $name = shift;
+ my $depth = shift||0;
+ my $list = shift || [];
+
+ my $node = $self->{entity}->{$name};
+
+# for (my $i = 0; $i<$depth; $i++){
+# print " ";
+# }
+# print $node->{type}."\t$name\n";
+ unless($node->{type} eq 'group'){
+ push(@{$list},$name);
+ }
+
+ if ($node->{type} eq 'group' || $node->{type} eq 'register' ){
+ for my $child (@{$node->{'children'}}){
+# print $child."\n";
+ $self->unfoldTree($child,$depth+1,$list);
+ }
+ }
+
+ return $list;
+}
+
+1;
+
+package textabular;
+
+
+sub new {
+ my $class = shift;
+ my %options = @_;
+ my $self = {
+# entityFile => '/dev/null',
+ dataKeys => [],
+ header => [],
+ data => [],
+ %options
+ };
+ bless($self, $class);
+ return $self;
+}
+
+sub addData {
+ my $self = shift;
+ my %data = @_;
+ push(@{$self->{data}}, \%data);
+ return $self;
+}
+
+sub generateString {
+ my $self = shift;
+ my $str = "";
+
+ $str.='\begin{table}[tbp]
+ \centering';
+
+
+ $str .= '\begin{tabular}'."\n";
+ $str .="{".($self->{format}||"")."}\n";
+ $str.='\toprule'."\n";
+ if ( @{$self->{header}} ){ # if no header list ...
+ $str.= " ".join(" & ",@{$self->{header}}).' \\\\'."\n";
+ } else { # print the keys instead
+ $str.= " ".join(" & ",@{$self->{dataKeys}}).' \\\\'."\n";
+ }
+ $str.='\midrule'."\n";
+
+ for my $data (@{$self->{data}}){
+ my @line;
+ for my $dataKey (@{$self->{dataKeys}}){
+ push(@line,$data->{$dataKey});
+ }
+ my $line = " ".join(" & ", @line) . ' \\\\'."\n";
+ $line =~ s/_/\\_/g; # remove all stupid underscores
+ $str.=$line;
+ }
+ $str.='\bottomrule'."\n";
+ $str.='\end{tabular}'."\n";
+
+ $str.='\caption{'.$self->{caption}.'}' if defined $self->{caption}."\n";
+ $str.='\label{'.$self->{label}.'}' if defined $self->{label}."\n";
+ $str.='\end{table}'."\n";
+ return $str;
+}
\ No newline at end of file