Changeset 10442 for trunk/FACT++/src/Fits.cc
- Timestamp:
- 04/21/11 12:27:37 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/Fits.cc
r10380 r10442 18 18 #include "Time.h" 19 19 #include "Converter.h" 20 21 //for file stats 22 #include <sys/stat.h> 20 23 21 24 using namespace std; … … 32 35 void Fits::AddStandardColumn(Description& desc, std::string dataFormat, void* dataPointer, long unsigned int numDataBytes) 33 36 { 37 //check if entry already exist 38 for (std::vector<Description>::iterator it=fStandardColDesc.begin(); it != fStandardColDesc.end(); it++) 39 if (it->name == desc.name) 40 return; 34 41 fStandardColDesc.push_back(desc); 35 42 fStandardFormats.push_back(dataFormat); … … 53 60 else 54 61 { 62 fDataColDesc.clear(); 55 63 for (unsigned int i=0;i<dataFormat.size();i++) 56 64 { … … 69 77 //! @param fileName the filename with complete or relative path of the file to open 70 78 //! @param tableName the name of the table that will receive the logged data. 71 // 72 void Fits::Open(const std::string& fileName, const std::string& tableName) 79 //! @param file a pointer to an existing FITS file. If NULL, file will be opened and managed internally 80 // 81 void Fits::Open(const std::string& fileName, const std::string& tableName, FITS* file) 73 82 { 74 try 75 { 76 fFile = new FITS(fileName, RWmode::Write); 77 } 78 catch (FITS::CantOpen) 79 { 80 std::ostringstream err; 81 err << "Could not open " << fileName << ".Skipping it."; 82 throw runtime_error(err.str()); 83 } 83 fFileName = fileName; 84 if (file == NULL) 85 { 86 try 87 { 88 fFile = new FITS(fileName, RWmode::Write); 89 } 90 catch (FITS::CantOpen) 91 { 92 std::ostringstream err; 93 err << "Could not open " << fileName << ".Skipping it."; 94 throw runtime_error(err.str()); 95 } 96 fOwner = true; 97 } 98 else 99 { 100 fFile = file; 101 fOwner = false; 102 } 84 103 //concatenate the standard and data columns 85 104 //do it the inneficient way first: its easier and faster to code. … … 206 225 void Fits::Write(Converter* conv) 207 226 { 227 228 fTable->makeThisCurrent(); 208 229 try 209 230 { … … 240 261 241 262 //This forces the writting of each row to the disk. Otherwise all rows are written when the file is closed. 263 ///TODO check whether this consumes too much resources or not. If it does, flush every N write operations instead 242 264 fFile->flush(); 243 265 } … … 252 274 // if (fTable != NULL) 253 275 // delete fTable; 276 254 277 std::string name = "TEND"; 255 278 double doubleValue = fEndMjD; 256 279 std::string comment = "Time of the last received data"; 257 280 fTable->addKey(name, doubleValue, comment); 258 259 if (fFile != NULL )281 282 if (fFile != NULL && fOwner) 260 283 delete fFile; 261 284 fFile = NULL; … … 264 287 fCopyBuffer = NULL; 265 288 } 289 290 // -------------------------------------------------------------------------- 291 // 292 //! This closes the currently openned FITS file. 293 //! it also updates the header to reflect the time of the last logged row 294 // 295 int Fits::GetWrittenSize() 296 { 297 if (!IsOpen()) 298 return 0; 299 300 struct stat st; 301 if (stat(fFileName.c_str(), &st)) 302 return 0; 303 else 304 return st.st_size; 305 }
Note:
See TracChangeset
for help on using the changeset viewer.