From 9fcb6aed513199f95c5fa5e73cad21b347d9bd75 Mon Sep 17 00:00:00 2001 From: Andreas Neiser Date: Sun, 30 Jun 2013 21:23:29 +0200 Subject: [PATCH] First idea for descriptive setup files --- xml-db/database/TDC.xml | 2 +- xml-db/database/TrbNetCommon.xsd | 44 ++++--------- xml-db/database/TrbNetEntity.xsd | 82 ++++++++++++++++++------ xml-db/database/TrbNetSetup.xsd | 29 +++++++++ xml-db/database/testing.xml | 31 ---------- xml-db/trb-setup.xml | 77 +++++++++++++++++++++++ xml-db/xml-db.pl | 103 +++++++++++++++++++------------ 7 files changed, 244 insertions(+), 124 deletions(-) delete mode 100644 xml-db/database/testing.xml create mode 100644 xml-db/trb-setup.xml diff --git a/xml-db/database/TDC.xml b/xml-db/database/TDC.xml index 868dded..2dd89ec 100644 --- a/xml-db/database/TDC.xml +++ b/xml-db/database/TDC.xml @@ -215,7 +215,7 @@ Enable signals/hits of the specific channel. LSB is channel 1. - + diff --git a/xml-db/database/TrbNetCommon.xsd b/xml-db/database/TrbNetCommon.xsd index 823c56b..e195800 100644 --- a/xml-db/database/TrbNetCommon.xsd +++ b/xml-db/database/TrbNetCommon.xsd @@ -103,22 +103,6 @@ Complex Elements ==============================--> - - - - - - - - - - - - - - - - @@ -131,11 +115,11 @@ - - - + @@ -168,27 +152,21 @@ an error is indicated by this field --> + + + + + - - - - - - - - - - - + - + diff --git a/xml-db/database/TrbNetEntity.xsd b/xml-db/database/TrbNetEntity.xsd index c6505e6..25ba769 100644 --- a/xml-db/database/TrbNetEntity.xsd +++ b/xml-db/database/TrbNetEntity.xsd @@ -4,6 +4,39 @@ they are collected in a common scheme --> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -14,19 +47,19 @@ - - - - + + + + - + + entities very easy to specify (which is desirable in setup files) --> @@ -39,7 +72,7 @@ - + @@ -50,18 +83,27 @@ - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + @@ -69,5 +111,5 @@ - + diff --git a/xml-db/database/TrbNetSetup.xsd b/xml-db/database/TrbNetSetup.xsd index ffcac39..ed72878 100644 --- a/xml-db/database/TrbNetSetup.xsd +++ b/xml-db/database/TrbNetSetup.xsd @@ -1,5 +1,34 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/xml-db/database/testing.xml b/xml-db/database/testing.xml deleted file mode 100644 index 27550a2..0000000 --- a/xml-db/database/testing.xml +++ /dev/null @@ -1,31 +0,0 @@ - - - Just some testing - - - - Wait time between write sequence and start signal. - - The number of MAPS clock cycles to wait after last write before sending the start signal. - - - - diff --git a/xml-db/trb-setup.xml b/xml-db/trb-setup.xml new file mode 100644 index 0000000..7a2fef1 --- /dev/null +++ b/xml-db/trb-setup.xml @@ -0,0 +1,77 @@ + + + + + + + + + + 5900000337e29728 + cf00000337e29e28 + ad00000338175028 + 0e00000338174b28 + 4400000338174628 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 0-15 => 1, + 34 => 1, + + + + + + + + + diff --git a/xml-db/xml-db.pl b/xml-db/xml-db.pl index 80338d6..271846e 100755 --- a/xml-db/xml-db.pl +++ b/xml-db/xml-db.pl @@ -24,13 +24,13 @@ GetOptions( 'help|h' => \$help, 'man' => \$man, 'verbose|v+' => \$verbose, - 'db-dir=s' => \$db_dir + 'db-dir=s' => \$db_dir ) or pod2usage(2); pod2usage(1) if $help; pod2usage(-exitval => 0, -verbose => 2) if $man; # tell something about the configuration -if($verbose) { +if ($verbose) { print "Database directory: $db_dir\n"; } @@ -39,16 +39,30 @@ if($verbose) { &Main; sub Main { - # load the unmerged database - my $db = &LoadDB; - # load the topology - DoSomethingWithDb($db); + # load the unmerged database and the provided files + my ($db,$files) = &LoadDBAndFiles; + + + # testing... + #DumpDatabase($db); +} + +sub LoadFile() { + my $schema = XML::LibXML::Schema->new(location => "$db_dir/TrbNetSetup.xsd"); + + } -sub DoSomethingWithDb($) { +sub DumpDatabase($) { my $db = shift; + foreach my $file (keys %$db) { + print "Dumping $file...\n"; + DumpDatabaseFile($db->{$file}); + } +} - my $doc = $db->{'TDC.xml'}; +sub DumpDatabaseFile($) { + my $doc = shift; #my $doc = $db->{'testing.xml'}; #my $doc = $db->{'jtag_registers_SPEC.xml'}; #print Dumper($doc->findnodes('TrbNet')->toDebuggingHash); @@ -76,52 +90,63 @@ sub DoSomethingWithDb($) { my $address = $baseaddress+hex($curNode->getAttribute('address')); #printf("%s %04x\n\n",$name,$address); foreach my $field ($curNode->findnodes('field')) { - printf("%04x:%02d:%02d %s/%s\n", $address, - $field->getAttribute('start'), - $field->getAttribute('size') || 1, - $name, $field->getAttribute('name')); + $field->getAttribute('start'), + $field->getAttribute('size') || 1, + $name, $field->getAttribute('name')); #print $field->getAttribute('errorflag') || 'false',"\n"; } } } } -sub GetBaseNameAndAddress($) { - my $node = shift; - - #return ($baseName, $baseAddress); -} -sub LoadDB { - # change to he db_dir here in this subroutine - local $CWD = $db_dir; +sub LoadDBAndFiles { + my $schemas = {}; + my $db = {}; + my $parser = XML::LibXML->new(line_numbers => 1); + + { + # change to the db_dir in the first part + local $CWD = $db_dir; - # we first load the schemas and parse them - # so we can validate the XML files - my %schemas = (); - while(<*.xsd>) { - $schemas{$_} = XML::LibXML::Schema->new(location => $_); - print "Loaded schema <$_>\n" if $verbose; + + # we first load the schemas and parse them + # so we can validate the XML files + while (<*.xsd>) { + $schemas->{$_} = XML::LibXML::Schema->new(location => $_); + print "Loaded schema <$_> from database\n" if $verbose; + } + + # load the xml files in the database + while (<*.xml>) { + my $doc = $parser->parse_file($_); + ValidateXML($doc, $schemas); + $db->{$_} = $doc; + print "Loaded and validated <$_> from database\n" if $verbose; + } } - # load the xml files - my $parser = XML::LibXML->new(line_numbers => 1); - my $db = {}; - while(<*.xml>) { + # now, back in the normal working directoy, load and + # validate the provided files + my $files = {}; + for (@ARGV) { my $doc = $parser->parse_file($_); - my $xsd_file = $doc->getDocumentElement->getAttribute('xsi:noNamespaceSchemaLocation'); - die "Schema $xsd_file not found to validate <$_>" unless defined $schemas{$xsd_file}; - $schemas{$xsd_file}->validate($doc); - $db->{$_} = $doc; + ValidateXML($doc, $schemas); + $files->{$_} = $doc; print "Loaded and validated <$_>\n" if $verbose; } - return $db; -} - - + return ($db, $files); +} +sub ValidateXML($$) { + my $doc = shift; + my $schemas = shift; + my $xsd_file = $doc->getDocumentElement->getAttribute('xsi:noNamespaceSchemaLocation'); + die "Schema $xsd_file not found to validate <$_>" unless defined $schemas->{$xsd_file}; + $schemas->{$xsd_file}->validate($doc); +} #print $xsd; @@ -135,7 +160,7 @@ xml-db.pl - Manipulate the TrbNet descriptively using XML =head1 SYNOPSIS -xml-db.pl [options] [xml file] +xml-db.pl [options] [xml file(s)] Options: -h, --help brief help message -- 2.43.0