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.12 1994/08/11 02:52:09 newhall
18 /* removed calls to grid cell Deleted member functions
20 * Revision 1.11 1994/07/30 03:25:35 newhall
21 * added enabled member to gridcell to indicate that the metric associated
22 * w/ this cell has been enabled and data will arrive for it eventually
23 * updated member functions affected by this addition
25 * Revision 1.10 1994/07/20 22:17:50 newhall
26 * added FirstValidBucket method function to visi_GridCellHisto class
28 * Revision 1.9 1994/07/07 22:40:30 newhall
29 * fixed compile warnings
31 * Revision 1.8 1994/06/16 18:24:50 newhall
32 * fix to visualization::Data
34 * Revision 1.7 1994/06/07 17:48:46 newhall
35 * support for adding metrics and resources to existing visualization
37 * Revision 1.6 1994/05/23 20:56:46 newhall
38 * To visi_GridCellHisto class: added deleted flag, SumValue
39 * method function, and fixed AggregateValue method function
41 * Revision 1.5 1994/05/11 17:12:44 newhall
42 * changed data values type from double to float
43 * fixed fold method function to support a folding
44 * at any point in the histogram, rather than only
45 * when the histogram is full
47 * Revision 1.4 1994/03/26 04:19:46 newhall
48 * changed all floats to double
49 * fix problem with null string returned for first resource name
51 * Revision 1.3 1994/03/17 05:19:59 newhall
52 * changed bucket width and time value's type to double
54 * Revision 1.2 1994/03/14 20:28:44 newhall
55 * changed visi subdirectory structure
57 ///////////////////////////////////////////////
58 // Member functions for the following classes:
59 // Metric, Resource, visi_GridCellHisto,
60 // visi_GridHistoArray, visi_DataGrid
61 ///////////////////////////////////////////////
62 #include "visi/h/datagrid.h"
64 Metric::Metric(char *metricUnits,
71 if(metricUnits != NULL){
72 len = strlen(metricUnits);
73 units = new char[len + 1];
74 strcpy(units,metricUnits);
80 if(metricName != NULL){
81 len = strlen(metricName);
82 name = new char[len + 1];
83 strcpy(name,metricName);
91 aggregate = foldMethod;
96 ///////////////////////////////////////////
98 // Resource constructor
100 Resource::Resource(char *resourceName,
104 if(resourceName != NULL){
105 len = strlen(resourceName);
106 name = new char[len+1];
107 strcpy(name,resourceName);
119 ///////////////////////////////////////////
121 // visi_GridCellHisto constructor
123 visi_GridCellHisto::visi_GridCellHisto(int numElements){
128 value = new sampleType[numElements];
129 for(i = 0; i < numElements; i++)
135 lastBucketFilled = -1;
136 firstValidBucket = -1;
139 ///////////////////////////////////////////
141 // constructor for class GridHistoArray
143 visi_GridHistoArray::visi_GridHistoArray(int numElements){
146 values = new visi_GridCellHisto[numElements];
154 // destructor for class GridHistoArray
156 visi_GridHistoArray::~visi_GridHistoArray(){
162 // evaluates to true if the grid cell indexed by i (foucus index)
163 // contains a histogram (is a valid metric/focus pair)
165 int visi_GridHistoArray::Valid(int i){
167 if ((i< 0) || (i>= size)){
168 visi_ErrorHandler(ERROR_SUBSCRIPT,"visi_GridHistoArray::Valid");
169 return(ERROR_SUBSCRIPT);
171 return(values[i].Valid());
177 // invalidates the grid cell indexed by i
179 int visi_GridHistoArray::Invalidate(int i){
181 if ((i< 0) || (i>= size)){
182 visi_ErrorHandler(ERROR_SUBSCRIPT,"visi_GridHistoArray::Invalidate");
183 return(ERROR_SUBSCRIPT);
185 values[i].Invalidate();
191 // add new elements to the values array
193 int visi_GridHistoArray::AddNewResources(int howmany){
195 visi_GridCellHisto *temp;
199 values = new visi_GridCellHisto[howmany + size];
200 for(int i = 0; i < size; i++){
201 if(values[i].AddNewValues(temp[i].Value(),
203 temp[i].LastBucketFilled(),
206 temp[i].Enabled()) != OK){
207 return(ERROR_CREATEGRID);
209 temp[i].userdata = NULL;
220 // add new elements to the values array
222 int visi_GridHistoArray::AddNewValues(visi_GridCellHisto *rarray,int howmany){
231 ///////////////////////////////////////////
233 // DataGrid constructor: creates metric and
234 // resource lists and empty datagrid
236 visi_DataGrid::visi_DataGrid(int noMetrics,
239 Resource *resourceList,
244 numMetrics = noMetrics;
245 numResources = noResources;
246 metrics = new Metric[noMetrics];
247 resources = new Resource[noResources];
249 for(i = 0; i < noMetrics; i++){
250 metrics[i].Metric(metricList[i].Units(),metricList[i].Name(),
251 metricList[i].Identifier(),metricList[i].Aggregate());
253 for(i = 0; i < noResources; i++){
254 resources[i].Resource(resourceList[i].Name(),resourceList[i].Identifier());
257 data_values = new visi_GridHistoArray[noMetrics];
258 for (i = 0; i < noMetrics; i++)
259 data_values[i].visi_GridHistoArray(noResources);
267 // DataGrid constructor: creates metric and
268 // resource lists and empty datagrid
270 visi_DataGrid::visi_DataGrid(int noMetrics,
272 visi_metricType *metricList,
273 visi_resourceType *resourceList,
278 numMetrics = noMetrics;
279 numResources = noResources;
280 metrics = new Metric[noMetrics];
281 resources = new Resource[noResources];
283 for(i = 0; i < noMetrics; i++){
284 metrics[i].Metric(metricList[i].units,metricList[i].name,
285 metricList[i].Id,metricList[i].aggregate);
287 for(i = 0; i < noResources; i++){
288 resources[i].Resource(resourceList[i].name,resourceList[i].Id);
290 data_values = new visi_GridHistoArray[noMetrics];
291 for (i = 0; i < noMetrics; i++)
292 data_values[i].visi_GridHistoArray(noResources);
301 // DataGrid destructor
303 visi_DataGrid::~visi_DataGrid(){
307 delete[] data_values;
311 // returns metric name for metric number i
313 char *visi_DataGrid::MetricName(int i){
314 if((i < numMetrics) && (i>=0))
315 return(metrics[i].Name());
320 // returns metric units for metric number i
322 char *visi_DataGrid::MetricUnits(int i){
324 if((i < numMetrics) && (i>=0))
325 return(metrics[i].Units());
331 // returns resource name for resource number j
333 char *visi_DataGrid::ResourceName(int j){
335 if((j < numResources) && (j>=0))
336 return(resources[j].Name());
342 // returns fold method for metric i
344 int visi_DataGrid::FoldMethod(int i){
346 if((i < numMetrics) && (i >= 0))
347 return(metrics[i].Aggregate());
348 visi_ErrorHandler(ERROR_SUBSCRIPT,"visi_DataGrid::FoldMethod");
349 return(ERROR_SUBSCRIPT);
354 // returns metric identifier associated with metric number i
356 int visi_DataGrid::MetricId(int i){
358 if((i < numMetrics) && (i >= 0))
359 return(metrics[i].Identifier());
360 visi_ErrorHandler(ERROR_SUBSCRIPT,"visi_DataGrid::MetricId");
361 return(ERROR_SUBSCRIPT);
365 // returns resource identifier associated with resource number j
367 int visi_DataGrid::ResourceId(int j){
369 if((j < numResources) && (j >= 0))
370 return(resources[j].Identifier());
371 visi_ErrorHandler(ERROR_SUBSCRIPT,"visi_DataGrid::ResourceId");
372 return(ERROR_SUBSCRIPT);
376 // returns 1 if datagrid element indicated by metric#, resource#
377 // contains histogram values, otherwise returns false
379 int visi_DataGrid::Valid(int metric,
382 if((metric < 0) || (metric >= numMetrics)){
383 visi_ErrorHandler(ERROR_SUBSCRIPT,"visi_HistoDataGrid::Valid");
384 return(ERROR_SUBSCRIPT);
386 return(data_values[metric].Valid(resource));
391 // invalidates data_grid element indicated by metric#, resource#
392 // sets valid to 0 and frees histogram space
394 int visi_DataGrid::Invalidate(int metric,
397 if((metric < 0) || (metric >= numMetrics)){
398 visi_ErrorHandler(ERROR_SUBSCRIPT,"visi_HistoDataGrid::Invalidate");
399 return(ERROR_SUBSCRIPT);
401 return(data_values[metric].Invalidate(resource));
407 // adds a new set of resources to the data grid
409 int visi_DataGrid::AddNewResource(int howmany,visi_resourceType *rlist){
414 // add new values to resource list
416 resources = new Resource[numResources + howmany];
418 for(i = 0; i < numResources; i++){
419 resources[i].Resource(temp[i].Name(),temp[i].Identifier());
421 for(i = numResources; i < (numResources + howmany); i++){
422 resources[i].Resource(rlist[i-numResources].name,
423 rlist[i-numResources].Id);
426 numResources += howmany;
428 // add space to data grid for new resources
429 for(i = 0; i < numMetrics; i++){
430 if((ok = data_values[i].AddNewResources(howmany)) != OK)
438 // adds a new set of resources to the data grid
440 int visi_DataGrid::AddNewMetrics(int howmany,visi_metricType *mlist){
442 visi_GridHistoArray *tempdata;
446 // add new values to metric list
448 metrics = new Metric[numMetrics + howmany];
450 for(i = 0; i < numMetrics; i++){
451 metrics[i].Metric(temp[i].Units(),temp[i].Name(),
452 temp[i].Identifier(),temp[i].Aggregate());
454 for(i = numMetrics; i < (numMetrics + howmany); i++){
455 metrics[i].Metric(mlist[i-numMetrics].units, mlist[i-numMetrics].name,
456 mlist[i-numMetrics].Id, mlist[i-numMetrics].aggregate);
460 // add space to data grid for new metrics
462 tempdata = data_values;
463 data_values = new visi_GridHistoArray[numMetrics + howmany];
465 for(i=0; i < numMetrics; i++){
466 if(data_values[i].AddNewValues(tempdata[i].Value(),tempdata[i].Size())
468 return(ERROR_CREATEGRID);
472 for(i=numMetrics; i < (numMetrics + howmany); i++){
473 data_values[i].visi_GridHistoArray(numResources);
476 numMetrics += howmany;
484 // returns 1 if metric with Id equal to test_id is in the data grid
486 int visi_DataGrid::MetricInGrid(int test_id){
488 for(int i = 0; i < numMetrics; i++){
489 if (test_id == metrics[i].Identifier()){
498 // returns 1 if resource with Id equal to test_id is in the data grid
500 int visi_DataGrid::ResourceInGrid(int test_id){
502 for(int i = 0; i < numResources; i++){
503 if (test_id == resources[i].Identifier()){