4 * Copyright (c) 1993, 1994 Barton P. Miller, Jeff Hollingsworth,
5 * Bruce Irvin, Jon Cargille, Krishna Kunchithapadam, Karen
6 * Karavanic, Tia Newhall, Mark Callaghan. All rights reserved.
8 * This software is furnished under the condition that it may not be
9 * provided or otherwise made available to, or used by, any other
10 * person, except as provided for by the terms of applicable license
11 * agreements. No title to or ownership of the software is hereby
12 * transferred. The name of the principals may not be used in any
13 * advertising or publicity related to this software without specific,
14 * written prior authorization. Any use of this software must include
15 * the above copyright notice.
19 /* $Log: datagrid.h,v $
20 /* Revision 1.8 1994/06/07 17:47:16 newhall
21 /* added method functions to support adding metrics
22 /* and resources to an existing data grid
24 * Revision 1.7 1994/05/23 20:55:16 newhall
25 * To visi_GridCellHisto class: added deleted flag, SumValue
26 * method function, and fixed AggregateValue method function
28 * Revision 1.6 1994/05/11 17:11:03 newhall
29 * changed data values from double to float
31 * Revision 1.5 1994/04/13 21:22:51 newhall
32 * *** empty log message ***
34 * Revision 1.4 1994/03/26 04:17:44 newhall
35 * change all floats to double
37 * Revision 1.3 1994/03/17 05:17:25 newhall
38 * added lastBucketFilled data member to class visi_GridCellHisto: value of
39 * the largest bucket number for which new data values have been added
41 * Revision 1.2 1994/03/15 02:03:19 newhall
42 * added public member "userdata" to class visi_GridCellHisto
43 * to allow visi writer to add info to grid cells
45 * Revision 1.1 1994/03/14 20:27:26 newhall
46 * changed visi subdirectory structure
48 /////////////////////////////////
49 // Data Grid Class definitions
50 /////////////////////////////////
55 #include "visiTypes.h"
61 char *units; // how units are measured i.e. "ms"
62 char *name; // for y-axis labeling
63 int Id; // unique metric Id
64 int aggregate; //either SUM or AVE, for fold operation
66 Metric(){units = NULL; name = NULL; Id = NOVALUE; aggregate=SUM;}
67 Metric(char* ,char*,int,int);
68 ~Metric(){delete[] units;delete[] name;}
69 char *Units(){return(units);}
70 char *Name(){return(name);}
71 int Identifier(){return(Id);}
72 int Aggregate(){return(aggregate);}
77 char *name; // obj. name for graph labeling
78 int Id; // unique resource id
80 Resource(){name = NULL; Id = -1;}
82 ~Resource(){ delete[] name;}
83 char *Name(){return(name);}
84 int Identifier(){return(Id);}
88 ///////////////////////////////////////////////
89 // visi_GridCellHisto: A grid cell element
90 // (histogram) is an instance of this class
91 // valid: indicates that the cell contains a histogram
92 // deleted: indicates that the cell cannot accept new data values
93 // size: number of buckets
94 // lastBucketFilled: number of full buckets
95 ////////////////////////////////////////////
97 class visi_GridCellHisto {
101 int lastBucketFilled; // bucket number of last data value added
102 int deleted; // set on delete cell element, cleared on add new element
105 void *userdata; // to allow visi writer to add info to grid cells
106 visi_GridCellHisto(){value = NULL; valid = 0; size = 0;
107 userdata = NULL; lastBucketFilled = -1; deleted = 0;}
108 visi_GridCellHisto(int);
109 ~visi_GridCellHisto(){delete[] value;}
110 int LastBucketFilled(){return(lastBucketFilled);}
111 sampleType *Value(){ return(value);}
113 sampleType Value(int i) {
114 if((i < 0) || (i > size)){
120 int Size(){return(size);}
121 int Valid(){return(valid);}
122 int Deleted(){return(deleted);}
123 void SetDeleted(){deleted = 1;}
124 void ClearDeleted(){deleted = 0;}
125 void Invalidate(){delete[] value; value = NULL; size = 0;
126 valid = 0; lastBucketFilled = -1;}
128 int AddNewValues(sampleType *temp,int arraySize,int lbf,void *ud){
130 // initialize cell to temp values
131 value = new sampleType[arraySize];
135 lastBucketFilled = lbf;
136 for(int i=0;i<size;i++){
143 void Fold(int method){
146 for(i=0,j=0;(i< (lastBucketFilled+1)/2) // new bucket counter
147 && (j< (lastBucketFilled+1)); // old bucket counter
149 if((value[j] != ERROR) && (value[j+1] != ERROR))
150 value[i] = value[j] + value[j+1];
153 if((value[i] != ERROR))
154 value[i] = value[i]/2;
156 for(i=(lastBucketFilled+1)/2; i < size; i++){
159 lastBucketFilled = ((lastBucketFilled+1)/2)-1;
163 sampleType SumValue(timeType width){
168 for(sum=0.0,i=0; i< size; i++){
169 if(!isnan(value[i])){
180 sampleType AggregateValue(int method){
185 for(sum=0.0,num=i=0; i< size; i++){
186 if(!isnan(value[i])){
193 return(sum/(1.0*num));
200 visi_ErrorHandler(ERROR_AGGREGATE,"values == NULL");
201 return(ERROR_AGGREGATE);
205 int AddValue(sampleType x,
211 if (deleted){ // if deleted is set, don't add values
214 if (!valid){ // if this is the first value create a histo cell array
216 value = new sampleType[numElements];
224 if((i < 0) || (i >= size))
225 return(ERROR_SUBSCRIPT);
227 if(i > lastBucketFilled)
228 lastBucketFilled = i;
232 sampleType operator[](int i){
233 if((i >= size) || (i < 0)){
234 visi_ErrorHandler(ERROR_SUBSCRIPT,
235 "error in [] operator in histogridcell");
243 class visi_GridHistoArray {
245 visi_GridCellHisto *values;
248 visi_GridHistoArray(){values = NULL; size = 0;}
249 visi_GridHistoArray(int);
250 ~visi_GridHistoArray();
252 int LastBucketFilled(int resource){
253 if((resource < 0) || (resource >= size))
254 return(ERROR_SUBSCRIPT);
256 return(values[resource].LastBucketFilled());
259 int AddValue(sampleType x,
264 if((resource < 0) || (resource >= size))
265 return(ERROR_SUBSCRIPT);
266 return(values[resource].AddValue(x,bucketNum,numBuckets));
268 int Size(){ return(size);}
269 visi_GridCellHisto *Value(){return(values);}
272 int AddNewResources(int);
273 int AddNewValues(visi_GridCellHisto *,int);
275 for(int i = 0; i < size; i++){
276 values[i].ClearDeleted();
280 void Fold(int method){
282 for(i=0; i< size; i++)
283 values[i].Fold(method);
286 sampleType AggregateValue(int i,
289 return(values[i].AggregateValue(method));
293 sampleType SumValue(int i,timeType width){
295 return(values[i].SumValue(width));
300 visi_GridCellHisto& operator[](int i){
301 if ((i>= 0) && (i < size)){
305 visi_ErrorHandler(ERROR_SUBSCRIPT,
306 "error in [] operator GridHistoArray");
313 class visi_DataGrid {
321 visi_GridHistoArray *data_values;
326 numMetrics=numResources=0;
332 visi_DataGrid(int,int,Metric *,Resource *,int,timeType);
333 visi_DataGrid(int,int,visi_metricType *,visi_resourceType *,int,timeType);
334 virtual ~visi_DataGrid();
335 char *MetricName(int i);
336 char *MetricUnits(int i);
337 char *ResourceName(int j);
338 int NumMetrics(){return(numMetrics);}
340 int NumResources(){return(numResources);}
341 int MetricId(int); // returns metric Id
342 int ResourceId(int); // returns Resource Id
343 int NumBins(){return(numBins);}
344 timeType BinWidth(){return(binWidth);}
346 int Invalidate(int,int);
347 int AddNewMetrics(int,visi_metricType *);
348 int AddNewResource(int,visi_resourceType *);
349 int ResourceInGrid(int);
350 int MetricInGrid(int);
352 for(int i = 0; i < numMetrics; i++){
353 data_values[i].ClearDeleted();
357 sampleType AggregateValue(int i,int j){
358 if((i>=0)&&(i<numMetrics))
359 return(data_values[i].AggregateValue(j,metrics[i].Aggregate()));
364 sampleType SumValue(int i,int j){
365 if((i>=0)&&(i<numMetrics))
366 return(data_values[i].SumValue(j,binWidth));
371 void Fold(timeType width){
373 for(i=0; i < numMetrics; i++)
374 data_values[i].Fold(metrics[i].Aggregate());
378 int AddValue(int metric,
382 if((metric < 0) || (metric >= numMetrics))
383 return(ERROR_SUBSCRIPT);
384 return(data_values[metric].AddValue(value,resource,bucket,numBins));
387 visi_GridHistoArray& operator[](int i){
388 if((i < 0) || (i >= numMetrics)){
389 visi_ErrorHandler(ERROR_SUBSCRIPT,
390 "error in [] operator DATAGRID");
391 return(data_values[0]);
393 return(data_values[i]);
396 int LastBucketFilled(int metric,int resource){
397 if((metric < 0) || (metric >= numMetrics))
398 return(ERROR_SUBSCRIPT);
399 return(data_values[metric].LastBucketFilled(resource));