Changeset 10725 for trunk/FACT++
- Timestamp:
- 05/17/11 14:30:27 (13 years ago)
- Location:
- trunk/FACT++/src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/Fits.cc
r10696 r10725 80 80 //! @param tableName the name of the table that will receive the logged data. 81 81 //! @param file a pointer to an existing FITS file. If NULL, file will be opened and managed internally 82 // 83 void Fits::Open(const std::string& fileName, const std::string& tableName, FITS* file, int* fitsCounter, std::ostream& out) 82 //! @param fitsCounter a pointer to the integer keeping track of the opened FITS files 83 //! @param out a pointer to the MessageImp that should be used to log errors 84 // 85 void Fits::Open(const std::string& fileName, const std::string& tableName, FITS* file, int* fitsCounter, MessageImp* out)//std::ostream& out) 84 86 { 85 if (fMess)86 delete fMess;87 fMess = new MessageImp(out);88 87 // if (fMess) 88 // delete fMess; 89 // fMess = new MessageImp(out); 90 fMess = out; 89 91 fFileName = fileName; 90 92 if (file == NULL) … … 183 185 } 184 186 185 fRefMjD = * static_cast<double*>(fStandardPointers[0]); 187 //As requested by Roland, the reference MjD is 0.0 188 fRefMjD = 0;//* static_cast<double*>(fStandardPointers[0]); 186 189 if (!updating) 187 190 WriteHeaderKeys(); 191 } 192 template <typename T> 193 void Fits::WriteSingleHeaderKey(string name, T value, string comment) 194 { 195 try 196 { 197 fTable->addKey(name, value, comment); 198 } 199 catch (CCfits::FitsError e) 200 { 201 std::stringstream str; 202 str << "Could not add header keys in file " << fFileName << " reason: " << e.message(); 203 fMess->Error(str); 204 } 188 205 } 189 206 // -------------------------------------------------------------------------- … … 198 215 std::string comment; 199 216 200 float floatValue;201 double doubleValue;217 // float floatValue; 218 // double doubleValue; 202 219 std::string stringValue; 203 try 204 { 205 name = "EXTREL"; 206 comment = "Release Number"; 207 floatValue = 1.0f; 208 fTable->addKey(name, floatValue, comment); 209 210 name = "BASETYPE"; 211 comment = "Base type of the data structure"; 212 stringValue = "??????"; 213 fTable->addKey(name, stringValue, comment); 214 215 name = "TELESCOP"; 216 comment = "Telescope that acquired this data"; 217 stringValue = "FACT"; 218 fTable->addKey(name, stringValue, comment); 219 220 name = "ORIGIN"; 221 comment = "Institution that wrote the file"; 222 stringValue = "ISDC"; 223 fTable->addKey(name, stringValue, comment); 224 225 name = "CREATOR"; 226 comment = "Program that wrote this file"; 227 stringValue = "FACT++_DataLogger"; 228 fTable->addKey(name, stringValue, comment); 229 230 name = "DATE"; 231 stringValue = Time().GetAsStr(); 232 stringValue[10] = 'T'; 233 comment = "File creation date"; 234 fTable->addKey(name, stringValue, comment); 235 236 name = "TIMESYS"; 237 stringValue = "TT"; 238 comment = "Time frame system"; 239 fTable->addKey(name, stringValue, comment); 240 241 name = "TIMEUNIT"; 242 stringValue = "d"; 243 comment = "Time unit"; 244 fTable->addKey(name, stringValue, comment); 245 246 name = "TIMEREF"; 247 stringValue = "UTC"; 248 comment = "Time reference frame"; 249 fTable->addKey(name, stringValue, comment); 250 251 name = "MJDREF"; 252 doubleValue = fRefMjD; 253 comment = "Modified Julian Date of origin"; 254 fTable->addKey(name, doubleValue, comment); 255 } 256 catch (CCfits::FitsError e) 257 { 258 std::stringstream str; 259 str << "Could not add header keys in file " << fFileName << " reason: " << e.message(); 260 fMess->Error(str); 261 } 262 //More ? 220 221 WriteSingleHeaderKey("EXTREL", 1.0f, "Release Number"); 222 WriteSingleHeaderKey("TELESCOP", "FACT", "Telescope that acquired this data"); 223 WriteSingleHeaderKey("ORIGIN", "ISDC", "Institution that wrote the file"); 224 WriteSingleHeaderKey("CREATOR", "FACT++ DataLogger", "Program that wrote this file"); 225 stringValue = Time().GetAsStr(); 226 stringValue[10]= 'T'; 227 WriteSingleHeaderKey("DATE", stringValue, "File creation data"); 228 WriteSingleHeaderKey("TIMESYS", "TT", "Time frame system"); 229 WriteSingleHeaderKey("TIMEUNIT", "d", "Time unit"); 230 WriteSingleHeaderKey("TIMEREF", "UTC", "Time reference frame"); 231 WriteSingleHeaderKey("MJDREF", fRefMjD, "Modified Julian Date of origin"); 263 232 } 264 233 // -------------------------------------------------------------------------- … … 270 239 { 271 240 272 try 273 { 274 fTable->makeThisCurrent(); 275 fTable->insertRows(fNumRows); 276 } 277 catch(CCfits::FitsError e) 278 { 279 std::stringstream str; 280 str << "Could not insert row in file " << fFileName << " reason: " << e.message(); 241 // try 242 // { 243 fTable->makeThisCurrent(); 244 int status(0); 245 if (fits_insert_rows(fTable->fitsPointer(), fNumRows, 1, &status)) 246 { 247 std::stringstream str; 248 str << "Could not insert row in file " << fFileName << ". cfitsio error code: " << status; 281 249 fMess->Error(str); 282 250 } 251 // fTable->insertRows(fNumRows); 252 // } 253 // catch(CCfits::FitsError e) 254 // { 255 // std::stringstream str; 256 // str << "Could not insert row in file " << fFileName << " reason: " << e.message(); 257 // fMess->Error(str); 258 // } 283 259 fNumRows++; 284 260 285 261 //the first standard variable is the current MjD 286 262 if (fEndMjD == 0) 287 263 { 288 std::string name = "TSTART"; 289 double doubleValue = *static_cast<double*>(fStandardPointers[0]) - fRefMjD; 290 std::string comment = "Time of the first received data"; 291 fTable->addKey(name, doubleValue, comment); 264 double doubleValue = *static_cast<double*>(fStandardPointers[0]);// - fRefMjD; 265 WriteSingleHeaderKey("TSTART", doubleValue, "Time of the first received data"); 292 266 } 293 267 fEndMjD = * static_cast<double*>(fStandardPointers[0]); … … 298 272 for (unsigned int i=0;i<fStandardNumBytes.size();i++) 299 273 { 300 for (int j=0; j<fStandardNumBytes[i]; j++) 301 fCopyBuffer[shift+j] = static_cast<char*>(fStandardPointers[i])[fStandardNumBytes[i]-(j+1)]; 274 const char * charSrc = static_cast<char*>(fStandardPointers[i]); 275 276 reverse_copy(charSrc, charSrc+fStandardNumBytes[i], &fCopyBuffer[shift]); 277 // for (int j=0; j<fStandardNumBytes[i]; j++) 278 // fCopyBuffer[shift+j] = static_cast<char*>(fStandardPointers[i])[fStandardNumBytes[i]-(j+1)]; 302 279 shift+= fStandardNumBytes[i]; 303 280 } … … 307 284 308 285 //data copied to buffer, can write to fits 309 int status = 0;286 // int status = 0; 310 287 //TODO check the status after the write operation 311 288 fits_write_tblbytes(fFile->fitsPointer(), fNumRows, 1, fTotalNumBytes, fCopyBuffer, &status); … … 320 297 //This forces the writting of each row to the disk. Otherwise all rows are written when the file is closed. 321 298 ///TODO check whether this consumes too much resources or not. If it does, flush every N write operations instead 322 try299 /* try 323 300 { 324 301 fFile->flush(); … … 330 307 fMess->Error(str); 331 308 } 332 }309 */} 333 310 // -------------------------------------------------------------------------- 334 311 // … … 341 318 // if (fTable != NULL) 342 319 // delete fTable; 343 std::string name = "TEND"; 344 double doubleValue = fEndMjD - fRefMjD; 345 std::string comment = "Time of the last received data"; 346 fTable->addKey(name, doubleValue, comment); 347 320 321 WriteSingleHeaderKey("TSTOP", fEndMjD, "Time of the last receied data"); 348 322 if (fFile != NULL && fOwner) 349 323 delete fFile; … … 354 328 if (fOwner && fNumOpenFitsFiles != NULL) 355 329 (*fNumOpenFitsFiles)--; 356 if (fMess) 357 delete fMess; 330 //fMess is the MessageImp part of the dataLogger itself. Thus it should NOT be deleted by the Fits files destructor. 331 // if (fMess) 332 // delete fMess; 358 333 fMess = NULL; 359 334 } -
trunk/FACT++/src/Fits.h
r10694 r10725 89 89 90 90 ///Opens a FITS file 91 void Open(const std::string& fileName, const std::string& tableName, CCfits::FITS* file, int* fitsCounter,std::ostream& out);91 void Open(const std::string& fileName, const std::string& tableName, CCfits::FITS* file, int* fitsCounter, MessageImp* out);//std::ostream& out); 92 92 93 93 ///Write one line of data. Use the given converter. … … 99 99 ///Get the size currently written on the disk 100 100 int GetWrittenSize(); 101 private: 102 template <typename T> 103 void WriteSingleHeaderKey(string name, T value, string comment); 101 104 102 105 };//Fits -
trunk/FACT++/src/dataLogger.cc
r10707 r10725 66 66 #include <sys/stat.h> 67 67 68 //#define HAVE_FITS 68 69 //#define ONE_RUN_FITS_ONLY 69 70 … … 977 978 //! @param I 978 979 //! The current DimInfo 980 //! @param sub 981 //! The dataLogger's subscription corresponding to this DimInfo 979 982 // 980 983 void DataLogger::ReportPlease(DimInfo* I, SubscriptionType& sub) … … 1088 1091 std::string n = I->getName(); 1089 1092 std::stringstream msg; 1090 msg << n .substr(0, n.find_first_of('/')) << ": " << I->getString();1093 msg << n << ": " << I->getString();//n.substr(0, n.find_first_of('/')) << ": " << I->getString(); 1091 1094 1092 1095 if (fNightlyLogFile.is_open()) … … 1699 1702 fFileSizesMap[partialName] = 0; 1700 1703 } 1701 sub.nightlyFile.Open(partialName, serviceName, NULL, &fNumSubAndFitsData.numOpenFits, Out());1704 sub.nightlyFile.Open(partialName, serviceName, NULL, &fNumSubAndFitsData.numOpenFits, this);//Out()); 1702 1705 //notify the opening 1703 1706 std::string actualTargetDir; … … 1771 1774 #ifdef ONE_RUN_FITS_ONLY 1772 1775 } 1773 sub.runFile.Open(partialName, serviceName, fRunFitsFile, &fNumSubAndFitsData.numOpenFits, Out());1776 sub.runFile.Open(partialName, serviceName, fRunFitsFile, &fNumSubAndFitsData.numOpenFits, this);//Out()); 1774 1777 #else 1775 sub.runFile.Open(partialName, serviceName, NULL, &fNumSubAndFitsData.numOpenFits, Out());1778 sub.runFile.Open(partialName, serviceName, NULL, &fNumSubAndFitsData.numOpenFits, this);//Out()); 1776 1779 #endif //one_run_fits_only 1777 1780 if (fNumSubAndFitsIsOn)
Note:
See TracChangeset
for help on using the changeset viewer.