Index: /branches/0.4/web/addons/job_monarch/libtoga.php
===================================================================
--- /branches/0.4/web/addons/job_monarch/libtoga.php	(revision 748)
+++ /branches/0.4/web/addons/job_monarch/libtoga.php	(revision 749)
@@ -609,4 +609,5 @@
         $this->offline_nodes    = array();
         $this->clustername    = $clustername;
+        $this->proc_cluster = null;
         $this->fqdn        = 1;
     }
@@ -694,6 +695,4 @@
     function startElement( $parser, $name, $attrs )
     {
-        $jobs = $this->jobs;
-        $nodes = $this->nodes;
 
         if( isset( $attrs['TN'] ) )
@@ -704,5 +703,5 @@
                 if ( $attrs['TN'] > $attrs['TMAX'] * 4 )
                 {
-                    return;
+                    return null;
                 }
             }
@@ -714,21 +713,32 @@
         {
             $this->proc_cluster = $attrs['NAME'];
-        }
-        else if( $name == 'HOST' and $this->proc_cluster == $this->clustername)
+            //printf("set proc cluster to %s\n", $attrs['NAME'] );
+            return null;
+        }
+        if( $this->proc_cluster != $this->clustername )
+        {
+            //printf("cluster does not match: %s\n", $this->clustername );
+            return null;
+        }
+
+        if( $name == 'HOST' )
         {
             $hostname = $attrs['NAME'];
 
-            $location = $attrs['LOCATION'];
-
-            if( !isset( $nodes[$hostname] ) )
-            {
-                $nodes[$hostname] = new NodeImage( $this->proc_cluster, $hostname );
-            }
-        }
-        else if( $name == 'METRIC' and ( strpos( $attrs['NAME'], 'zplugin_monarch' ) !== false ) and $this->proc_cluster == $this->clustername )
+            //printf( "host %s\n", $hostname );
+            //$location = $attrs['LOCATION'];
+
+            if( !isset( $this->nodes[$hostname] ) )
+            {
+                $this->nodes[$hostname] = new NodeImage( $this->proc_cluster, $hostname );
+            }
+            return null;
+        }
+        if( $name == 'METRIC' and ( strpos( $attrs['NAME'], 'zplugin_monarch' ) !== false ) )
         {
             if( strpos( $attrs['NAME'], 'zplugin_monarch_heartbeat' ) !== false )
             {
                 $this->heartbeat['time'] = $attrs['VAL'];
+                return;
             }
             else if( strpos( $attrs['NAME'], 'zplugin_monarch_down' ) !== false )
@@ -767,4 +777,5 @@
                     }
                 }
+                return;
             }
             else if( strpos( $attrs['NAME'], 'zplugin_monarch_offline' ) !== false )
@@ -803,4 +814,5 @@
                     }
                 }
+                return;
             }
             else if( strpos( $attrs['NAME'], 'zplugin_monarch_job' ) !== false )
@@ -808,7 +820,7 @@
                 sscanf( $attrs['NAME'], 'zplugin_monarch_job_%d_%s$', $monincr, $jobid );
 
-                if( !isset( $jobs[$jobid] ) )
-                {
-                    $jobs[$jobid] = array();
+                if( !isset( $this->jobs[$jobid] ) )
+                {
+                    $this->jobs[$jobid] = array();
                 }
 
@@ -824,9 +836,9 @@
                     if( $toganame == 'nodes' )
                     {
-                        if( $jobs[$jobid]['status'] == 'R' )
+                        if( $this->jobs[$jobid]['status'] == 'R' )
                         {
-                            if( !isset( $jobs[$jobid][$toganame] ) )
+                            if( !isset( $this->jobs[$jobid][$toganame] ) )
                             {
-                                $jobs[$jobid][$toganame] = array();
+                                $this->jobs[$jobid][$toganame] = array();
                             }
 
@@ -835,35 +847,35 @@
                             foreach( $mynodes as $node )
                             {
-                                if( !in_array( $node, $jobs[$jobid][$toganame] ) )
+                                if( !in_array( $node, $this->jobs[$jobid][$toganame] ) )
                                 {
-                                    array_push( $jobs[$jobid][$toganame], $node );
+                                    array_push( $this->jobs[$jobid][$toganame], $node );
                                 }
                             }
 
                         }
-                        else if( $jobs[$jobid]['status'] == 'Q' )
+                        else if( $this->jobs[$jobid]['status'] == 'Q' )
                         {
-                            $jobs[$jobid][$toganame] = $togavalue;
+                            $this->jobs[$jobid][$toganame] = $togavalue;
                         }
                     }
                     else
                     {
-                        $jobs[$jobid][$toganame] = $togavalue;
+                        $this->jobs[$jobid][$toganame] = $togavalue;
                     }
                 }
 
-                if( isset( $jobs[$jobid]['nodes'] ) )
-                {
-                    $nr_nodes = count( $jobs[$jobid]['nodes'] );
+                if( isset( $this->jobs[$jobid]['nodes'] ) )
+                {
+                    $nr_nodes = count( $this->jobs[$jobid]['nodes'] );
         
-                    if( $jobs[$jobid]['status'] == 'R' )
+                    if( $this->jobs[$jobid]['status'] == 'R' )
                     {
 
-                        if( isset( $jobs[$jobid]['domain'] ) )
+                        if( isset( $this->jobs[$jobid]['domain'] ) )
                         {
-                            $domain        = $jobs[$jobid]['domain'];
+                            $domain        = $this->jobs[$jobid]['domain'];
                             $domain_len    = 0 - strlen( $domain );
 
-                            $nodekeys     = array_keys( $nodes );
+                            $nodekeys     = array_keys( $this->nodes );
 
                             $first_host    = $nodekeys[0];
@@ -880,10 +892,10 @@
                         }
 
-                        foreach( $jobs[$jobid]['nodes'] as $node )
+                        foreach( $this->jobs[$jobid]['nodes'] as $node )
                         {
 
                             // Only add domain name to the hostname if Ganglia is doing that too
                             //
-                            if( $this->fqdn && isset( $jobs[$jobid]['domain'] ) )
+                            if( $this->fqdn && isset( $this->jobs[$jobid]['domain'] ) )
                             {
                                 if( strpos( $node, $domain ) === false )
@@ -900,5 +912,5 @@
                             }
 
-                            if( !isset( $nodes[$host] ) )
+                            if( !isset( $this->nodes[$host] ) )
                             {
                                 $my_node = new NodeImage( $this->proc_cluster, $host );
@@ -906,5 +918,5 @@
                             else
                             {
-                                $my_node = $nodes[$host];
+                                $my_node = $this->nodes[$host];
                             }
 
@@ -921,12 +933,11 @@
                             }
 
-                            $nodes[$host] = $my_node;
+                            $this->nodes[$host] = $my_node;
                         }
                     }
                 }
             }
-        }
-        $this->jobs    = $jobs;
-        $this->nodes    = $nodes;
+            return;
+        }
     }
 
