]> jspc29.x-matter.uni-frankfurt.de Git - daqtools.git/commitdiff
Adding --dumpitem support to xml-db.pl
authorAndreas Neiser <neiser@kph.uni-mainz.de>
Mon, 14 Oct 2013 06:40:51 +0000 (08:40 +0200)
committerAndreas Neiser <neiser@kph.uni-mainz.de>
Mon, 14 Oct 2013 06:40:51 +0000 (08:40 +0200)
xml-db/xml-db.pl

index 9f3366d899e334b26a594373c0e39adce6c9969a..7a2b839671ede2dc6e0ea639431426fae3a746ab 100755 (executable)
@@ -22,6 +22,7 @@ my $verbose = 0;
 my $warnings = 1;
 my $dir = $RealBin;
 my $dump = 0;
+my $dumpitem;
 
 Getopt::Long::Configure(qw(gnu_getopt));
 GetOptions(
@@ -30,7 +31,8 @@ GetOptions(
            'verbose|v+' => \$verbose,
            'warnings|w!' => \$warnings,
            'dir=s' => \$dir,
-           'dump' => \$dump
+           'dump' => \$dump,
+           'dumpitem|i=s' => \$dumpitem
           ) or pod2usage(2);
 pod2usage(1) if $help;
 pod2usage(-exitval => 0, -verbose => 2) if $man;
@@ -50,6 +52,7 @@ if ($verbose) {
 # jump to subroutine which handles the job,
 # depending on the options
 
+
 &Main;
 
 sub Main {
@@ -59,13 +62,13 @@ sub Main {
 
   my @docs;
   {
+    local $CWD = $db_dir;
     my %filter;
     foreach (@ARGV) {
       $_ = "$_.xml" unless /\.xml$/;
       $filter{$_} = 1;
     }
     my $num = scalar @ARGV;
-    local $CWD = $db_dir;
     while (<*.xml>) {
       next if $num>0 and not defined $filter{$_};
       my $doc = LoadXML($_);
@@ -84,14 +87,18 @@ sub Main {
     #print Dumper($db->{'ReadoutFSM'});
     #print Dumper($db->{'JtagErrorCount1'});
     #print Dumper($db->{'JtagLastDataChanged'});
-    #print Dumper($db->{'IdleTime'});
-    #print DumpTree($db);
     my $name = $doc->getDocumentElement->getAttribute('name');
+    if($dumpitem) {
+      my $item = $db->{$dumpitem};
+      next unless defined $item;
+      MyDumpTree($item,"$dumpitem (in entity $name)");
+      next;
+    }
+    #print DumpTree($db);
     my $cachefile = "cache/$name.entity";
     lock_store($db, $cachefile);
     print STDERR "Wrote $cachefile\n" if $verbose>0;
     print STDERR "\n",DumpTree($db,$name),"\n" if $verbose>2;
-
   }
 
 
@@ -236,10 +243,13 @@ sub DumpDocument {
   # recursively populate tree and print it
   my $tree = {};
   IterateChildren($tree, $doc->getDocumentElement, $entityAddr);
-  print DumpTree($tree, $entityName,
+  MyDumpTree($tree, $entityName);
+}
+
+sub MyDumpTree {
+  print DumpTree(shift, shift,
                  USE_ASCII => 0, DISPLAY_OBJECT_TYPE => 0,
                  DISPLAY_ADDRESS => 0, NO_NO_ELEMENTS => 1);
-
 }
 
 sub IterateChildren {
@@ -332,6 +342,7 @@ xml-db.pl - Create cached data structures from the XML entities
 
 xml-db.pl [entity names]
 xml-db.pl --dump [entity names]
+xml-db.pl --dumpitem=<name> [entity names]
 
  Options:
    -h, --help     brief help message
@@ -339,6 +350,7 @@ xml-db.pl --dump [entity names]
    -w, --warnings print warnings to STDERR
    --dir          directory that contains database and schema subdirs
    --dump         dump the database as tree, restricted to given entity names
+   -i, --dumpitem dump a given named item as tree
 
 =head1 OPTIONS
 
@@ -358,13 +370,22 @@ Set the base directory where the default XML files can be found in
 sub-directories database and schema. In the same directory the cache
 will be created.
 
+=item B<--dump>
+
+Dump the Database.
+
+=item B<--dumpitem>
+
+Dump a given item (specify the unique name) to be found in the
+database of the given entities.
+
 =back
 
 =head1 DESCRIPTION
 
-B<This program> updates the cache directory from the provided XML
-files in the database directory (also validates them against the
-schema). You can restrict the files being worked by stating them as
-arguments, the extension .xml will be added for convenience.
+This program updates the cache directory from the provided XML files
+in the database directory (also validates them against the schema).
+You can restrict the files being worked by stating them as arguments,
+the extension .xml will be added for convenience.
 
 =cut