quick.cpp

Go to the documentation of this file.
00001 /* ****************************************************************** **
00002 **    OpenSees - Open System for Earthquake Engineering Simulation    **
00003 **          Pacific Earthquake Engineering Research Center            **
00004 **                                                                    **
00005 **                                                                    **
00006 ** (C) Copyright 1999, The Regents of the University of California    **
00007 ** All Rights Reserved.                                               **
00008 **                                                                    **
00009 ** Commercial use of this program without express permission of the   **
00010 ** University of California, Berkeley, is strictly prohibited.  See   **
00011 ** file 'COPYRIGHT'  in main directory for information on usage and   **
00012 ** redistribution,  and for a DISCLAIMER OF ALL WARRANTIES.           **
00013 **                                                                    **
00014 ** Developed by:                                                      **
00015 **   Frank McKenna (fmckenna@ce.berkeley.edu)                         **
00016 **   Gregory L. Fenves (fenves@ce.berkeley.edu)                       **
00017 **   Filip C. Filippou (filippou@ce.berkeley.edu)                     **
00018 **                                                                    **
00019 ** ****************************************************************** */
00020                                                                         
00021 // $Revision: 1.2 $
00022 // $Date: 2003/02/14 23:00:54 $
00023 // $Source: /usr/local/cvs/OpenSees/SRC/database/quick.cpp,v $
00024                                                                         
00025                                                                         
00026 int 
00027 FileDatastore::sendID(int dataTag, int commitTag, 
00028                       const ID &theID, 
00029                       ChannelAddress *theAddress)
00030 {
00031 
00032   // we first ensure that the ID is not too big
00033   int idSize = theID.Size();
00034   if (idSize >= maxIDsize) {
00035     opserr << "FileDatastore::sendID() - the database does not deal with IDs of this size ";
00036     opserr << idSize << endln;
00037   }
00038 
00039 
00040   // open a file if not already opened
00041   if (ids[idSize] == 0) {
00042     char fileName[70];
00043     char intName[10];
00044     strcpy(fileName, dataBase);
00045     itoa(idSize, intName);
00046     strcat(fileName,".IDs.");
00047     strcat(fileName,intName);
00048     ids[idSize] = this->openFile(fileName);    
00049     int loc = ids[idSize]->tellg();
00050     if (loc == -1) loc = 0;
00051     opserr << "LOCATION: " << loc << endln;
00052     fileEnds.ids[idSize] = loc;
00053   }
00054 
00055   // we now found the location in the file to write the data
00056   fstream *theStream = ids[idSize];
00057   int fileEnd = fileEnds.ids[idSize];
00058   int stepSize = (2 + idSize)*sizeof(int);
00059 
00060   theStream->seekg(0);
00061   bool found = false;
00062   int pos =0;
00063 
00064   while ((pos < fileEnd) && (found == false)) {
00065     theStream->read((char *)&idBuffer, stepSize);
00066     if ((idBuffer.dbTag == dataTag) && (idBuffer.commitTag == commitTag)) 
00067       found = true;
00068     else {
00069       pos += stepSize;
00070     }
00071   }
00072 
00073   // we now place the data to be sent into our buffer
00074   idBuffer.dbTag = dataTag;
00075   idBuffer.commitTag = commitTag;
00076   for (int i=0; i<idSize; i++)
00077     idBuffer.data[i] = theID(i);
00078 
00079   // we now write the data
00080   if (found == true)
00081     theStream->seekp(pos);
00082 
00083   theStream->write((char *)&idBuffer, stepSize);
00084 
00085   // update the size of file if we have added to eof
00086   if (fileEnd <= pos)
00087     fileEnds.ids[idSize] += stepSize;
00088 
00089   return 0;
00090 }                      
00091 
00092 int 
00093 FileDatastore::recvID(int dataTag, int commitTag, 
00094                       ID &theID, 
00095                       ChannelAddress *theAddress)    
00096 {
00097   // we first check ID not too big
00098   int idSize = theID.Size();
00099   if (idSize >= maxIDsize) {
00100     opserr << "FileDatastore::recvID() - the database does not deal with IDs";
00101     opserr << " of this size "  << idSize << endln;
00102     return -1;
00103   }
00104   
00105   // open the file - if not already opened
00106   if (ids[idSize] == 0) {
00107     char fileName[70];
00108     char intName[10];
00109     strcpy(fileName, dataBase);
00110     itoa(idSize, intName);
00111     strcat(fileName,".IDs.");
00112     strcat(fileName,intName);
00113     ids[idSize] = this->openFile(fileName);    
00114     int loc = ids[idSize]->tellg();
00115     if (loc == -1) loc = 0;
00116     fileEnds.ids[idSize] = loc;
00117   }
00118 
00119   // we now read in the data unti we reach eof or find the data
00120   int stepSize = (2 + idSize)*sizeof(int);
00121   fstream *theStream = ids[idSize];
00122 
00123   theStream->seekg(0);
00124   bool found = false;
00125   int pos =0; 
00126   int fileEnd = fileEnds.ids[idSize];
00127 
00128   while ((pos < fileEnd) && (found == false)) {
00129     theStream->read((char *)&idBuffer, stepSize);
00130     if ((idBuffer.dbTag == dataTag) && (idBuffer.commitTag == commitTag))
00131       found = true;
00132     pos += stepSize;
00133   }
00134   
00135   if (found == false) {
00136     opserr << "FileDatastore::recvID() - failed to find data for ID of size ";
00137     opserr << idSize << endln;
00138     return -1;
00139   }
00140 
00141   // we now place the received data into the ID 
00142   idBuffer.dbTag = dataTag;
00143   idBuffer.commitTag = commitTag;
00144   for (int i=0; i<idSize; i++)
00145     theID(i) = idBuffer.data[i];
00146 
00147   return 0;
00148 }                      

Generated on Mon Oct 23 15:05:00 2006 for OpenSees by doxygen 1.5.0