ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/BuildSystem/SCRAMGrapher.pm
Revision: 1.2
Committed: Fri Dec 10 13:41:37 2004 UTC (20 years, 4 months ago) by sashby
Content type: text/plain
Branch: MAIN
CVS Tags: V1_1_7, V1_1_6, V1_1_5, V1_2_0-cand1, V1_1_4, V1_1_3, V1_1_2, V1_1_0_reltag8, V1_1_0_reltag7, V1_1_0_reltag6, V1_1_1, V1_1_0_reltag5, V1_1_0_reltag4, V1_1_0_reltag3, V1_1_0_reltag2, V1_1_0_reltag1, V1_1_0_reltag, V1_0_3-p4, V1_1_0_cand3, V1_1_0_cand2, V1_1_0_cand1, HEAD_SM_071214, forV1_1_0, v103_xml_071106, V1_0_3-p3, V1_0_3-p2, V1_1_0, v110p1, V110p6, V110p5, V110p4, V110p3, before110xmlBRmerge, V110p2, V110p1, V1_0_4p1, V1_0_3-p1, V1_0_3, V1_0_2, V1_0_2_p1, v102p1, V1_0_1, V1_0_0
Branch point for: forBinLess_SCRAM, HEAD_BRANCH_SM_071214, v200branch, v103_with_xml, v103_branch
Changes since 1.1: +152 -0 lines
Log Message:
Merged V1_0 branch to HEAD

File Contents

# User Rev Content
1 sashby 1.2 #____________________________________________________________________
2     # File: SCRAMGrapher.pm
3     #____________________________________________________________________
4     #
5     # Author: Shaun Ashby <Shaun.Ashby@cern.ch>
6     # Update: 2004-06-30 11:01:02+0200
7     # Revision: $Id: SCRAMGrapher.pm,v 1.1.2.10 2004/10/06 11:57:12 sashby Exp $
8     #
9     # Copyright: 2004 (C) Shaun Ashby
10     #
11     #--------------------------------------------------------------------
12     package BuildSystem::SCRAMGrapher;
13     require 5.004;
14     use Exporter;
15    
16     @ISA=qw(Exporter);
17     @EXPORT_OK=qw();
18    
19     sub new()
20     ###############################################################
21     # new #
22     ###############################################################
23     # modified : Wed Jun 30 11:01:31 2004 / SFA #
24     # params : #
25     # : #
26     # function : #
27     # : #
28     ###############################################################
29     {
30     my $proto=shift;
31     my $class=ref($proto) || $proto;
32     my ($depdata)=@_;
33     my $self={};
34     bless $self,$class;
35     # The dependencies will either be collected via methods in this object or
36     # as input:
37     $self->{DEPENDENCIES} = $depdata;
38     $self->{DEPENDENCIES} ||= {};
39     return $self;
40     }
41    
42     sub vertex()
43     {
44     my $self=shift;
45     my ($start) = @_;
46     $self->{DEPENDENCIES}->{$start} = {};
47     return $self;
48     }
49    
50     sub edge()
51     {
52     my $self=shift;
53     my ($start,$end)=@_;
54     # $start is a VERTEX. Add package $end to the hash of deps in
55     # the DEPENDENCIES hash:
56     $self->{DEPENDENCIES}->{$start}->{$end} = 1;
57     }
58    
59     sub _graph_init()
60     {
61     my $self=shift;
62     # If a graph object already exists (e.g. when SCRAMGrapher has
63     # been cloned), add new vertices/edges. Otherwise, start with
64     # a new Graph object:
65     if (exists ($self->{GRAPH}))
66     {
67     my $vertices = [ keys %{$self->{DEPENDENCIES}} ];
68    
69     # Loop over vertices:
70     foreach my $package (@$vertices)
71     {
72     # Add this vertex:
73     $self->{GRAPH}->add_vertex($package);
74     # For each edge from this vertex, add an edge:
75     foreach my $dep (keys %{$self->{DEPENDENCIES}->{$package}})
76     {
77     $self->{GRAPH}->add_edge($package,$dep);
78     }
79     }
80     }
81     else
82     {
83     # Init the graph with the array of vertices:
84     my $vertices = [ keys %{$self->{DEPENDENCIES}} ];
85     use Graph::Graph;
86     # Init a Graph object passing the list of vertices (this saves
87     # N_vertex calls to add_vertex()):
88     my $g = Graph->new(@$vertices);
89    
90     # Loop over vertices:
91     foreach my $package (@$vertices)
92     {
93     # For each edge from this vertex, add an edge:
94     foreach my $dep (keys %{$self->{DEPENDENCIES}->{$package}})
95     {
96     $g->add_edge($package,$dep);
97     }
98     }
99     # Store the Graph object:
100     $self->{GRAPH} = $g;
101     }
102     }
103    
104     sub sort()
105     {
106     my $self=shift;
107     # Get a graph object:
108     $self->_graph_init();
109     # Perform topological (depth-first) sort and return:
110     $self->{SORTED} = [ $self->{GRAPH}->toposort() ];
111     return $self->{SORTED};
112     }
113    
114     sub graph_write()
115     {
116     my $self=shift;
117     my ($data,$name)=@_;
118     my $dir = $ENV{LOCALTOP}.'/'.$ENV{SCRAM_INTwork};
119    
120     use Graph::Writer::SCRAMDot;
121     my $writer = Graph::Writer::SCRAMDot->new();
122    
123     $name =~ s|/|_|g;
124     # Filename (without the .dot):
125     $filename = $dir.'/'.$name;
126     # Set attributes where there's data available from
127     # a DataCollector (in local graphing only)
128     # In globale graphing we set a default colour, shape etc.
129     # in the SCRAMDot::write_graph() routine:
130     $writer->attribute_data($data);
131     $writer->write_graph($self->{DEPENDENCIES}, $filename);
132    
133     return $self;
134     }
135    
136     sub copy()
137     {
138     my $self=shift;
139     # First, we need to translate the DEPENDENCIES into a Graph object which
140     # will be stored in $self->{GRAPH}:
141     $self->_graph_init();
142     # Need to return new SCRAMGrapher object with copy of G:
143     my $sgcopy = ref($self)->new();
144     # Make a copy of the graph and set G to point to this:
145     $sgcopy->{GRAPH} = $self->{GRAPH}->copy();
146     # Reset the DEPENDENCIES store (we already have the copied vertices/edges stored):
147     $sgcopy->{DEPENDENCIES} = {};
148     # Return the new SCRAMGrapher object:
149     return $sgcopy;
150     }
151    
152     1;