FEI Version of the Day
fei_Pattern.cpp
00001 /*--------------------------------------------------------------------*/
00002 /*    Copyright 2005 Sandia Corporation.                              */
00003 /*    Under the terms of Contract DE-AC04-94AL85000, there is a       */
00004 /*    non-exclusive license for use of this work by or on behalf      */
00005 /*    of the U.S. Government.  Export of this program may require     */
00006 /*    a license from the United States Government.                    */
00007 /*--------------------------------------------------------------------*/
00008 
00009 #include "fei_Pattern.hpp"
00010 
00011 //-----------------------------------------------------------------------------
00012 fei::Pattern::Pattern(int numIDs, int idType, snl_fei::RecordCollection* recordCollection)
00013   : type_(Pattern::NO_FIELD),
00014     numIDs_(numIDs),
00015     totalNumFields_(0),
00016     numIndices_(numIDs),
00017     data_(),
00018     recordCollections_(numIDs, recordCollection)
00019 {
00020   int i, len = numIDs_*4;
00021   data_.resize(len);
00022   int offset = 0;
00023 
00024   //set idTypes
00025   for(i=0; i<numIDs_; ++i) {
00026     data_[offset++] = idType;
00027   }
00028 
00029   //set numFieldsPerID
00030   for(i=0; i<numIDs_; ++i) {
00031     data_[offset++] = 0;
00032   }
00033 
00034   //set numIndicesPerID
00035   for(i=0; i<numIDs_; ++i) {
00036     data_[offset++] = 1;
00037   }
00038 
00039   //set fieldIDs
00040   for(i=0; i<numIDs_; ++i) {
00041     data_[offset++] = -1;
00042   }
00043 
00044   idTypes_        = &(data_[0]);
00045   numFieldsPerID_ = idTypes_+numIDs_;
00046   numIndicesPerID_= idTypes_+2*numIDs_;
00047   fieldIDs_       = idTypes_+3*numIDs_;
00048 }
00049 
00050 //-----------------------------------------------------------------------------
00051 fei::Pattern::Pattern(int numIDs, int idType, snl_fei::RecordCollection* recordCollection,
00052         int fieldID, int fieldSize)
00053   : type_(Pattern::SIMPLE),
00054     numIDs_(numIDs),
00055     totalNumFields_(numIDs),
00056     numIndices_(0), //numIndices_ to be calculated
00057     data_(),
00058     recordCollections_(numIDs, recordCollection)
00059 {
00060   int i, len = numIDs_*4;
00061   data_.resize(len);
00062   int offset = 0;
00063 
00064   //set idTypes
00065   for(i=0; i<numIDs_; ++i) {
00066     data_[offset++] = idType;
00067   }
00068 
00069   //set numFieldsPerID
00070   for(i=0; i<numIDs_; ++i) {
00071     data_[offset++] = 1;
00072   }
00073 
00074   //set numIndicesPerID
00075   for(i=0; i<numIDs_; ++i) {
00076     data_[offset++] = fieldSize;
00077   }
00078 
00079   //set fieldIDs
00080   for(i=0; i<numIDs_; ++i) {
00081     data_[offset++] = fieldID;
00082   }
00083 
00084   numIndices_ = numIDs_*fieldSize;
00085 
00086   idTypes_        = &(data_[0]);
00087   numFieldsPerID_ = idTypes_+numIDs_;
00088   numIndicesPerID_= idTypes_+2*numIDs_;
00089   fieldIDs_       = idTypes_+3*numIDs_;
00090 }
00091 
00092 //-----------------------------------------------------------------------------
00093 fei::Pattern::Pattern(int numIDs, int idType, snl_fei::RecordCollection* recordCollection,
00094         const int* numFieldsPerID,
00095         const int* fieldIDs,
00096         const int* fieldSizes)
00097   : type_(Pattern::SINGLE_IDTYPE),
00098     numIDs_(numIDs),
00099     totalNumFields_(0), //totalNumFields_ to be calculated
00100     numIndices_(0), //numIndices_ to be calculated
00101     data_(),
00102     recordCollections_(numIDs, recordCollection)
00103 {
00104   int i, len = numIDs_*3;
00105   int maxNumFieldsPerID = 0;
00106   bool oneDistinctFieldID = true;
00107 
00108   for(i=0; i<numIDs; ++i) len += numFieldsPerID[i];
00109   data_.resize(len);
00110 
00111   int offset = 0;
00112   //set idTypes
00113   for(i=0; i<numIDs_; ++i) {
00114     data_[offset++] = idType;
00115   }
00116 
00117   //set numFieldsPerID
00118   for(i=0; i<numIDs; ++i) {
00119     data_[offset++] = numFieldsPerID[i];
00120     if (numFieldsPerID[i] > maxNumFieldsPerID) {
00121       maxNumFieldsPerID = numFieldsPerID[i];
00122     }
00123   }
00124 
00125   //next set numIndicesPerID and fieldIDs
00126   int firstFieldID = 0;
00127   if (numIDs > 0) firstFieldID = fieldIDs[0];
00128 
00129   int fieldIDOffset = offset + numIDs;
00130   for(i=0; i<numIDs; ++i) {
00131     int thisNumIndices = 0;
00132     for(int j=0; j<numFieldsPerID[i]; ++j) {
00133       int fieldSize = fieldSizes[totalNumFields_];
00134       int fieldID = fieldIDs[totalNumFields_++];
00135       if (fieldID != firstFieldID) oneDistinctFieldID = false;
00136       data_[fieldIDOffset++] = fieldID;
00137       numIndices_ += fieldSize;
00138       thisNumIndices += fieldSize;
00139     }
00140     data_[offset+i] = thisNumIndices;
00141   }
00142 
00143   if (oneDistinctFieldID == true && maxNumFieldsPerID < 2) {
00144     type_ = Pattern::SIMPLE;
00145   }
00146 
00147   idTypes_        = &(data_[0]);
00148   numFieldsPerID_ = idTypes_+numIDs_;
00149   numIndicesPerID_= idTypes_+2*numIDs_;
00150   fieldIDs_       = idTypes_+3*numIDs_;
00151 }
00152 
00153 //-----------------------------------------------------------------------------
00154 fei::Pattern::Pattern(int numIDs, const int* idTypes, snl_fei::RecordCollection*const* recordCollections,
00155         const int* numFieldsPerID,
00156         const int* fieldIDs,
00157         const int* fieldSizes)
00158   : type_(Pattern::GENERAL),
00159     numIDs_(numIDs),
00160     totalNumFields_(0), //totalNumFields_ to be calculated
00161     numIndices_(0), //numIndices_ to be calculated
00162     data_(),
00163     recordCollections_(recordCollections, recordCollections+numIDs)
00164 {
00165   int i, len = numIDs*3;
00166   int maxNumFieldsPerID = 0;
00167   bool oneDistinctFieldID = true;
00168   bool oneDistinctIDType = true;
00169 
00170   for(i=0; i<numIDs; ++i) len += numFieldsPerID[i];
00171   data_.resize(len);
00172 
00173   int firstIDType = 0;
00174   if (numIDs > 0) firstIDType = idTypes[0];
00175 
00176   int offset = 0;
00177   //set idTypes
00178   for(i=0; i<numIDs; ++i) {
00179     data_[offset++] = idTypes[i];
00180     if (idTypes[i] != firstIDType) oneDistinctIDType = false;
00181   }
00182 
00183   //set numFieldsPerID
00184   for(i=0; i<numIDs; ++i) {
00185     data_[offset++] = numFieldsPerID[i];
00186     if (numFieldsPerID[i] > maxNumFieldsPerID) {
00187       maxNumFieldsPerID = numFieldsPerID[i];
00188     }
00189   }
00190 
00191   //next set numIndicesPerID and fieldIDs
00192   int firstFieldID = 0;
00193   if (numIDs > 0) firstFieldID = fieldIDs[0];
00194 
00195   int fieldIDOffset = offset + numIDs;
00196   for(i=0; i<numIDs; ++i) {
00197     int thisNumIndices = 0;
00198     for(int j=0; j<numFieldsPerID[i]; ++j) {
00199       int fieldSize = fieldSizes[totalNumFields_];
00200       int fieldID = fieldIDs[totalNumFields_++];
00201       if (fieldID != firstFieldID) oneDistinctFieldID = false;
00202       data_[fieldIDOffset++] = fieldID;
00203       numIndices_ += fieldSize;
00204       thisNumIndices += fieldSize;
00205     }
00206     data_[offset+i] = thisNumIndices;
00207   }
00208 
00209   if (oneDistinctFieldID == true && maxNumFieldsPerID < 2 &&
00210       oneDistinctIDType == true) {
00211     type_ = Pattern::SIMPLE;
00212   }
00213   else if (oneDistinctIDType == true) {
00214     type_ = Pattern::SINGLE_IDTYPE;
00215   }
00216 
00217   idTypes_        = &(data_[0]);
00218   numFieldsPerID_ = idTypes_+numIDs_;
00219   numIndicesPerID_= idTypes_+2*numIDs_;
00220   fieldIDs_       = idTypes_+3*numIDs_;
00221 }
00222 
00223 //-----------------------------------------------------------------------------
00224 fei::Pattern::~Pattern()
00225 {
00226 }
00227 
00228 //-----------------------------------------------------------------------------
00229 bool fei::Pattern::operator==(const fei::Pattern& rhs) const
00230 {
00231   return type_ == rhs.type_ &&
00232          numIDs_ == rhs.numIDs_ &&
00233          totalNumFields_ == rhs.totalNumFields_ &&
00234          numIndices_ == rhs.numIndices_ &&
00235          data_ == rhs.data_;
00236 }
00237 
00238 //-----------------------------------------------------------------------------
00239 bool fei::Pattern::operator!=(const fei::Pattern& rhs) const
00240 {
00241   return !(*this == rhs);
00242 }
00243 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends