2 * Copyright (c) 1993, 1994 Barton P. Miller, Jeff Hollingsworth,
3 * Bruce Irvin, Jon Cargille, Krishna Kunchithapadam, Karen
4 * Karavanic, Tia Newhall, Mark Callaghan. All rights reserved.
6 * This software is furnished under the condition that it may not be
7 * provided or otherwise made available to, or used by, any other
8 * person, except as provided for by the terms of applicable license
9 * agreements. No title to or ownership of the software is hereby
10 * transferred. The name of the principals may not be used in any
11 * advertising or publicity related to this software without specific,
12 * written prior authorization. Any use of this software must include
13 * the above copyright notice.
16 /* $Log: datagrid.C,v $
17 /* Revision 1.13 1994/11/02 04:14:57 newhall
20 * Revision 1.12 1994/08/11 02:52:09 newhall
21 * removed calls to grid cell Deleted member functions
23 * Revision 1.11 1994/07/30 03:25:35 newhall
24 * added enabled member to gridcell to indicate that the metric associated
25 * w/ this cell has been enabled and data will arrive for it eventually
26 * updated member functions affected by this addition
28 * Revision 1.10 1994/07/20 22:17:50 newhall
29 * added FirstValidBucket method function to visi_GridCellHisto class
31 * Revision 1.9 1994/07/07 22:40:30 newhall
32 * fixed compile warnings
34 * Revision 1.8 1994/06/16 18:24:50 newhall
35 * fix to visualization::Data
37 * Revision 1.7 1994/06/07 17:48:46 newhall
38 * support for adding metrics and resources to existing visualization
40 * Revision 1.6 1994/05/23 20:56:46 newhall
41 * To visi_GridCellHisto class: added deleted flag, SumValue
42 * method function, and fixed AggregateValue method function
44 * Revision 1.5 1994/05/11 17:12:44 newhall
45 * changed data values type from double to float
46 * fixed fold method function to support a folding
47 * at any point in the histogram, rather than only
48 * when the histogram is full
50 * Revision 1.4 1994/03/26 04:19:46 newhall
51 * changed all floats to double
52 * fix problem with null string returned for first resource name
54 * Revision 1.3 1994/03/17 05:19:59 newhall
55 * changed bucket width and time value's type to double
57 * Revision 1.2 1994/03/14 20:28:44 newhall
58 * changed visi subdirectory structure
60 ///////////////////////////////////////////////
61 // Member functions for the following classes:
62 // Metric, Resource, visi_GridCellHisto,
63 // visi_GridHistoArray, visi_DataGrid
64 ///////////////////////////////////////////////
65 #include "visi/h/datagrid.h"
67 Metric::Metric(char *metricUnits,
74 if(metricUnits != NULL){
75 len = strlen(metricUnits);
76 units = new char[len + 1];
77 strcpy(units,metricUnits);
83 if(metricName != NULL){
84 len = strlen(metricName);
85 name = new char[len + 1];
86 strcpy(name,metricName);
94 aggregate = foldMethod;
103 if(name) delete[] name;
105 if(units) delete[] units;
110 ///////////////////////////////////////////
112 // Resource constructor
114 Resource::Resource(char *resourceName,
118 if(resourceName != NULL){
119 len = strlen(resourceName);
120 name = new char[len+1];
121 strcpy(name,resourceName);
133 // Resource destructor
135 Resource::~Resource(){
137 if(name) delete[] name;
142 ///////////////////////////////////////////
144 // visi_GridCellHisto constructor
146 visi_GridCellHisto::visi_GridCellHisto(int numElements){
151 value = new sampleType[numElements];
152 for(i = 0; i < numElements; i++)
158 lastBucketFilled = -1;
159 firstValidBucket = -1;
163 // destructor for class visi_GridCellHisto
165 visi_GridCellHisto::~visi_GridCellHisto(){
167 if(value) delete[] value;
174 ///////////////////////////////////////////
176 // constructor for class GridHistoArray
178 visi_GridHistoArray::visi_GridHistoArray(int numElements){
181 values = new visi_GridCellHisto[numElements];
189 // destructor for class GridHistoArray
191 visi_GridHistoArray::~visi_GridHistoArray(){
197 // evaluates to true if the grid cell indexed by i (foucus index)
198 // contains a histogram (is a valid metric/focus pair)
200 int visi_GridHistoArray::Valid(int i){
202 if ((i< 0) || (i>= size)){
203 visi_ErrorHandler(ERROR_SUBSCRIPT,"visi_GridHistoArray::Valid");
204 return(ERROR_SUBSCRIPT);
206 return(values[i].Valid());
212 // invalidates the grid cell indexed by i
214 int visi_GridHistoArray::Invalidate(int i){
216 if ((i< 0) || (i>= size)){
217 visi_ErrorHandler(ERROR_SUBSCRIPT,"visi_GridHistoArray::Invalidate");
218 return(ERROR_SUBSCRIPT);
220 values[i].Invalidate();
226 // add new elements to the values array
228 int visi_GridHistoArray::AddNewResources(int howmany){
230 visi_GridCellHisto *temp = 0;
234 values = new visi_GridCellHisto[howmany + size];
235 for(int i = 0; i < size; i++){
236 if(values[i].AddNewValues(temp[i].Value(),
238 temp[i].LastBucketFilled(),
241 temp[i].Enabled()) != OK){
242 return(ERROR_CREATEGRID);
244 temp[i].userdata = NULL;
256 // add new elements to the values array
258 int visi_GridHistoArray::AddNewValues(visi_GridCellHisto *rarray,int howmany){
267 ///////////////////////////////////////////
269 // DataGrid constructor: creates metric and
270 // resource lists and empty datagrid
272 visi_DataGrid::visi_DataGrid(int noMetrics,
275 Resource *resourceList,
280 numMetrics = noMetrics;
281 numResources = noResources;
282 metrics = new Metric[noMetrics];
283 resources = new Resource[noResources];
285 for(i = 0; i < noMetrics; i++){
286 metrics[i].Metric(metricList[i].Units(),metricList[i].Name(),
287 metricList[i].Identifier(),metricList[i].Aggregate());
289 for(i = 0; i < noResources; i++){
290 resources[i].Resource(resourceList[i].Name(),resourceList[i].Identifier());
293 data_values = new visi_GridHistoArray[noMetrics];
294 for (i = 0; i < noMetrics; i++)
295 data_values[i].visi_GridHistoArray(noResources);
303 // DataGrid constructor: creates metric and
304 // resource lists and empty datagrid
306 visi_DataGrid::visi_DataGrid(int noMetrics,
308 visi_metricType *metricList,
309 visi_resourceType *resourceList,
314 numMetrics = noMetrics;
315 numResources = noResources;
316 metrics = new Metric[noMetrics];
317 resources = new Resource[noResources];
319 for(i = 0; i < noMetrics; i++){
320 metrics[i].Metric(metricList[i].units,metricList[i].name,
321 metricList[i].Id,metricList[i].aggregate);
323 for(i = 0; i < noResources; i++){
324 resources[i].Resource(resourceList[i].name,resourceList[i].Id);
326 data_values = new visi_GridHistoArray[noMetrics];
327 for (i = 0; i < noMetrics; i++)
328 data_values[i].visi_GridHistoArray(noResources);
337 // DataGrid destructor
339 visi_DataGrid::~visi_DataGrid(){
343 delete[] data_values;
347 // returns metric name for metric number i
349 char *visi_DataGrid::MetricName(int i){
350 if((i < numMetrics) && (i>=0))
351 return(metrics[i].Name());
356 // returns metric units for metric number i
358 char *visi_DataGrid::MetricUnits(int i){
360 if((i < numMetrics) && (i>=0))
361 return(metrics[i].Units());
367 // returns resource name for resource number j
369 char *visi_DataGrid::ResourceName(int j){
371 if((j < numResources) && (j>=0))
372 return(resources[j].Name());
378 // returns fold method for metric i
380 int visi_DataGrid::FoldMethod(int i){
382 if((i < numMetrics) && (i >= 0))
383 return(metrics[i].Aggregate());
384 visi_ErrorHandler(ERROR_SUBSCRIPT,"visi_DataGrid::FoldMethod");
385 return(ERROR_SUBSCRIPT);
390 // returns metric identifier associated with metric number i
392 int visi_DataGrid::MetricId(int i){
394 if((i < numMetrics) && (i >= 0))
395 return(metrics[i].Identifier());
396 visi_ErrorHandler(ERROR_SUBSCRIPT,"visi_DataGrid::MetricId");
397 return(ERROR_SUBSCRIPT);
401 // returns resource identifier associated with resource number j
403 int visi_DataGrid::ResourceId(int j){
405 if((j < numResources) && (j >= 0))
406 return(resources[j].Identifier());
407 visi_ErrorHandler(ERROR_SUBSCRIPT,"visi_DataGrid::ResourceId");
408 return(ERROR_SUBSCRIPT);
412 // returns 1 if datagrid element indicated by metric#, resource#
413 // contains histogram values, otherwise returns false
415 int visi_DataGrid::Valid(int metric,
418 if((metric < 0) || (metric >= numMetrics)){
419 visi_ErrorHandler(ERROR_SUBSCRIPT,"visi_HistoDataGrid::Valid");
420 return(ERROR_SUBSCRIPT);
422 return(data_values[metric].Valid(resource));
427 // invalidates data_grid element indicated by metric#, resource#
428 // sets valid to 0 and frees histogram space
430 int visi_DataGrid::Invalidate(int metric,
433 if((metric < 0) || (metric >= numMetrics)){
434 visi_ErrorHandler(ERROR_SUBSCRIPT,"visi_HistoDataGrid::Invalidate");
435 return(ERROR_SUBSCRIPT);
437 return(data_values[metric].Invalidate(resource));
443 // adds a new set of resources to the data grid
445 int visi_DataGrid::AddNewResource(int howmany,visi_resourceType *rlist){
450 // add new values to resource list
452 resources = new Resource[numResources + howmany];
454 for(i = 0; i < numResources; i++){
455 resources[i].Resource(temp[i].Name(),temp[i].Identifier());
457 for(i = numResources; i < (numResources + howmany); i++){
458 resources[i].Resource(rlist[i-numResources].name,
459 rlist[i-numResources].Id);
462 numResources += howmany;
464 // add space to data grid for new resources
465 for(i = 0; i < numMetrics; i++){
466 if((ok = data_values[i].AddNewResources(howmany)) != OK){
480 // adds a new set of resources to the data grid
482 int visi_DataGrid::AddNewMetrics(int howmany,visi_metricType *mlist){
484 visi_GridHistoArray *tempdata;
488 // add new values to metric list
490 metrics = new Metric[numMetrics + howmany];
492 for(i = 0; i < numMetrics; i++){
493 metrics[i].Metric(temp[i].Units(),temp[i].Name(),
494 temp[i].Identifier(),temp[i].Aggregate());
496 for(i = numMetrics; i < (numMetrics + howmany); i++){
497 metrics[i].Metric(mlist[i-numMetrics].units, mlist[i-numMetrics].name,
498 mlist[i-numMetrics].Id, mlist[i-numMetrics].aggregate);
502 // add space to data grid for new metrics
504 tempdata = data_values;
505 data_values = new visi_GridHistoArray[numMetrics + howmany];
507 for(i=0; i < numMetrics; i++){
508 if(data_values[i].AddNewValues(tempdata[i].Value(),tempdata[i].Size())
510 return(ERROR_CREATEGRID);
514 for(i=numMetrics; i < (numMetrics + howmany); i++){
515 data_values[i].visi_GridHistoArray(numResources);
518 numMetrics += howmany;
526 // returns 1 if metric with Id equal to test_id is in the data grid
528 int visi_DataGrid::MetricInGrid(int test_id){
530 for(int i = 0; i < numMetrics; i++){
531 if (test_id == metrics[i].Identifier()){
540 // returns 1 if resource with Id equal to test_id is in the data grid
542 int visi_DataGrid::ResourceInGrid(int test_id){
544 for(int i = 0; i < numResources; i++){
545 if (test_id == resources[i].Identifier()){