Changeset 10955
- Timestamp:
- 06/09/11 17:13:03 (14 years ago)
- Location:
- trunk/FACT++/src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/Fits.cc
r10947 r10955 84 84 //! @param runNumber the runNumber for which this file is opened. 0 means nightly file. 85 85 // 86 voidFits::Open(const string& fileName, const string& tableName, FITS* file, int* fitsCounter, MessageImp* out, int runNumber)86 bool Fits::Open(const string& fileName, const string& tableName, FITS* file, int* fitsCounter, MessageImp* out, int runNumber) 87 87 { 88 88 // if (fMess) … … 104 104 fMess->Error(str); 105 105 fFile = NULL; 106 return ;106 return false; 107 107 } 108 108 fOwner = true; … … 166 166 { 167 167 fMess->Error("The table " + factTableName + " could not be created nor loaded. skipping it"); 168 return; 168 Close(); 169 return false; 169 170 } 170 171 fTable->makeThisCurrent(); … … 177 178 { 178 179 fMess->Error("The table " + factTableName + " could not be converted to a binary table. skipping"); 179 return; 180 Close(); 181 return false; 180 182 } 181 183 //read the table binary data. … … 192 194 { 193 195 fMess->Error("Column " + cMapIt->first + "Could not be read back from the disk"); 194 return; 196 Close(); 197 return false; 195 198 } 196 199 } … … 205 208 fMess->Error(str); 206 209 fTable = NULL; 210 Close(); 211 return false; 207 212 } 208 213 … … 210 215 fRefMjD = 0;//* static_cast<double*>(fStandardPointers[0]); 211 216 if (!updating) 212 WriteHeaderKeys(); 217 return WriteHeaderKeys(); 218 219 return true; 213 220 } 214 221 // -------------------------------------------------------------------------- … … 219 226 //!@param a comment explaining the meaning of the key 220 227 template <typename T> 221 voidFits::WriteSingleHeaderKey(string name, T value, string comment)228 bool Fits::WriteSingleHeaderKey(string name, T value, string comment) 222 229 { 223 230 try … … 230 237 str << "Could not add header keys in file " << fFileName << " reason: " << e.message(); 231 238 fMess->Error(str); 232 } 239 return false; 240 } 241 return true; 233 242 } 234 243 // -------------------------------------------------------------------------- … … 236 245 //! This writes the standard header 237 246 // 238 voidFits::WriteHeaderKeys()247 bool Fits::WriteHeaderKeys() 239 248 { 240 249 if (!fTable) 241 return ;250 return false; 242 251 string name; 243 252 string comment; … … 245 254 string stringValue; 246 255 247 WriteSingleHeaderKey("EXTREL", 1.0f, "Release Number");248 WriteSingleHeaderKey("TELESCOP", "FACT", "Telescope that acquired this data");249 WriteSingleHeaderKey("ORIGIN", "ISDC", "Institution that wrote the file");250 WriteSingleHeaderKey("CREATOR", "FACT++ DataLogger", "Program that wrote this file");256 if (!WriteSingleHeaderKey("EXTREL", 1.0f, "Release Number")) return false; 257 if (!WriteSingleHeaderKey("TELESCOP", "FACT", "Telescope that acquired this data")) return false; 258 if (!WriteSingleHeaderKey("ORIGIN", "ISDC", "Institution that wrote the file")) return false; 259 if (!WriteSingleHeaderKey("CREATOR", "FACT++ DataLogger", "Program that wrote this file")) return false; 251 260 stringValue = Time().GetAsStr(); 252 261 stringValue[10]= 'T'; 253 WriteSingleHeaderKey("DATE", stringValue, "File creation data"); 254 WriteSingleHeaderKey("TIMESYS", "TT", "Time frame system"); 255 WriteSingleHeaderKey("TIMEUNIT", "d", "Time unit"); 256 WriteSingleHeaderKey("TIMEREF", "UTC", "Time reference frame"); 257 WriteSingleHeaderKey("MJDREF", fRefMjD, "Modified Julian Date of origin"); 258 WriteSingleHeaderKey("TSTOP", fEndMjD, "Time of the last receied data"); 262 if (!WriteSingleHeaderKey("DATE", stringValue, "File creation data")) return false; 263 if (!WriteSingleHeaderKey("TIMESYS", "TT", "Time frame system")) return false; 264 if (!WriteSingleHeaderKey("TIMEUNIT", "d", "Time unit")) return false; 265 if (!WriteSingleHeaderKey("TIMEREF", "UTC", "Time reference frame")) return false; 266 if (!WriteSingleHeaderKey("MJDREF", fRefMjD, "Modified Julian Date of origin")) return false; 267 if (!WriteSingleHeaderKey("TSTOP", fEndMjD, "Time of the last receied data")) return false; 268 return true; 259 269 } 260 270 // -------------------------------------------------------------------------- … … 263 273 //! @param conv the converter corresponding to the service being logged 264 274 // 265 voidFits::Write(Converter* conv)275 bool Fits::Write(Converter* conv) 266 276 { 267 277 //first copy the standard variables to the copy buffer … … 284 294 str << fFileName << ": " << e.what(); 285 295 fMess->Error(str); 286 return ;296 return false; 287 297 } 288 298 … … 295 305 str << "Inserting row into " << fFileName << " failed (fits_insert_rows, rc=" << status << ")"; 296 306 fMess->Error(str); 297 // FIXME: What is a proper action here? 307 Close(); 308 return false; 298 309 } 299 310 … … 310 321 311 322 //data copied to buffer, can write to fits 312 fits_write_tblbytes(fFile->fitsPointer(), fNumRows, 1, fTotalNumBytes, fCopyBuffer, &status); 313 if (status) 323 if (fits_write_tblbytes(fFile->fitsPointer(), fNumRows, 1, fTotalNumBytes, fCopyBuffer, &status)) 314 324 { 315 325 char text[30];//max length of cfitsio error strings (from doc) … … 318 328 str << "Writing FITS row " << fNumRows << " in " << fFileName << ": " << text << " (file_write_tblbytes, rc=" << status << ")"; 319 329 fMess->Error(str); 320 // FIXME: What is a proper action here? 321 } 330 Close(); 331 return false; 332 } 333 return true; 322 334 } 323 335 -
trunk/FACT++/src/Fits.h
r10934 r10955 50 50 double fRefMjD; 51 51 ///Write the FITS header keys 52 voidWriteHeaderKeys();52 bool WriteHeaderKeys(); 53 53 public: 54 54 ///Name of the openned file. For querying stats … … 94 94 95 95 ///Opens a FITS file 96 voidOpen(const string& fileName, const string& tableName, CCfits::FITS* file, int* fitsCounter, MessageImp* out, int runNumber);//ostream& out);96 bool Open(const string& fileName, const string& tableName, CCfits::FITS* file, int* fitsCounter, MessageImp* out, int runNumber);//ostream& out); 97 97 98 98 ///Write one line of data. Use the given converter. 99 voidWrite(Converter* conv);99 bool Write(Converter* conv); 100 100 101 101 ///Close the currently opened file. … … 106 106 private: 107 107 template <typename T> 108 voidWriteSingleHeaderKey(string name, T value, string comment);108 bool WriteSingleHeaderKey(string name, T value, string comment); 109 109 110 110 };//Fits -
trunk/FACT++/src/dataLogger.cc
r10954 r10955 199 199 kSM_BadNightlyConfig = 0x101, ///< the folder specified for Nightly logging does not exist or has bad permissions 200 200 kSM_BadRunConfig = 0x102, ///< the folder specified for the run logging does not exist or has wrong permissions or no run number 201 kSM_WriteError = 0x103, ///< Denotes that an error occured while writing a file (text or fits). 201 202 } localstates_t; 202 203 … … 297 298 ///from NightlyOpen to waiting transition 298 299 int NightlyToWaitRunPlease(); 300 /// from writing to error 301 std::string SetCurrentState(int state, const char *txt="", const std::string &cmd=""); 299 302 #ifdef HAVE_FITS 300 303 ///Open fits files … … 560 563 if (out.is_open()) 561 564 out.close(); 565 SetCurrentState(kSM_WriteError); 562 566 } 563 567 } … … 928 932 AddStateName(kSM_BadNightlyConfig, "ErrNightlyFolder", "The folder for the nighly summary files is invalid."); 929 933 AddStateName(kSM_BadRunConfig, "ErrRunFolder", "The folder for the run files is invalid."); 934 AddStateName(kSM_WriteError, "ErrWrite", "An error occured while writing to a file."); 930 935 931 936 /*Add the possible transitions for this machine*/ … … 934 939 ("Start the nightly logging. Nightly file location must be specified already"); 935 940 936 AddEvent(kSM_Ready, fTransStop, kSM_NightlyOpen, kSM_WaitingRun, kSM_Logging )941 AddEvent(kSM_Ready, fTransStop, kSM_NightlyOpen, kSM_WaitingRun, kSM_Logging, kSM_WriteError) 937 942 (boost::bind(&DataLogger::GoToReadyPlease, this)) 938 943 ("Stop all data logging, close all files."); … … 946 951 ("Wait for a run to be started, open run-files as soon as a run number arrives."); 947 952 948 AddEvent(kSM_Ready, fTransReset, kSM_Error, kSM_BadNightlyConfig, kSM_BadRunConfig, kSM_ Error)953 AddEvent(kSM_Ready, fTransReset, kSM_Error, kSM_BadNightlyConfig, kSM_BadRunConfig, kSM_WriteError) 949 954 (boost::bind(&DataLogger::GoToReadyPlease, this)) 950 955 ("Transition to exit error states. Closes the nightly file if already opened."); … … 970 975 //Provide a print command 971 976 ostringstream str; 972 str << kSM_Ready << " " << kSM_NightlyOpen << " " << kSM_WaitingRun << " " << kSM_Logging << " " << kSM_BadNightlyConfig ;977 str << kSM_Ready << " " << kSM_NightlyOpen << " " << kSM_WaitingRun << " " << kSM_Logging << " " << kSM_BadNightlyConfig << " " << kSM_WriteError; 973 978 str << " " << kSM_BadRunConfig; 974 979 AddEvent(fPrintCommand, str.str().c_str(), "") … … 1309 1314 1310 1315 //create the converter for that service 1311 if ( sub.fConv&& isItaReport)1316 if ((!sub.fConv.get()) && isItaReport) 1312 1317 { 1313 1318 //trick the converter in case of 'C'. why do I do this ? well simple: the converter checks that the right number … … 1851 1856 fOpenedNightlyFits[fileNameOnly].push_back(serviceName); 1852 1857 1853 sub.nightlyFile.Open(partialName, serviceName, NULL, &fNumSubAndFitsData.numOpenFits, this, 0);//Out()); 1854 1858 if (!sub.nightlyFile.Open(partialName, serviceName, NULL, &fNumSubAndFitsData.numOpenFits, this, 0)) 1859 { 1860 SetCurrentState(kSM_WriteError); 1861 return; 1862 } 1855 1863 //notify the opening 1856 1864 string baseFileName = CompileFileName(fNightlyFilePath, "", ""); … … 1889 1897 } 1890 1898 1891 if (hasGrouping && cRunNumber->runFitsFile)1899 if (hasGrouping && (!cRunNumber->runFitsFile.get())) 1892 1900 try 1893 1901 { … … 1906 1914 NotifyOpenedFile(baseFileName, 7, fOpenedRunFiles);// + '_' + serviceName, 4); 1907 1915 if (hasGrouping) 1908 sub.runFile.Open(partialName, serviceName, (cRunNumber->runFitsFile).get(), &fNumSubAndFitsData.numOpenFits, this, sub.runNumber);//Out()); 1916 { 1917 if (!sub.runFile.Open(partialName, serviceName, (cRunNumber->runFitsFile).get(), &fNumSubAndFitsData.numOpenFits, this, sub.runNumber)) 1918 { 1919 SetCurrentState(kSM_WriteError); 1920 return; 1921 } 1922 } 1909 1923 else 1910 sub.runFile.Open(partialName, serviceName, NULL, &fNumSubAndFitsData.numOpenFits, this, sub.runNumber);//Out()); 1911 1924 { 1925 if (sub.runFile.Open(partialName, serviceName, NULL, &fNumSubAndFitsData.numOpenFits, this, sub.runNumber)) 1926 { 1927 SetCurrentState(kSM_WriteError); 1928 return; 1929 } 1930 } 1912 1931 if (fNumSubAndFitsIsOn) 1913 1932 fNumSubAndFits->updateService(); … … 2010 2029 if (sub.nightlyFile.IsOpen()) 2011 2030 { 2012 sub.nightlyFile.Write(sub.fConv.get()); 2013 if (fDebugIsOn) 2014 { 2015 Debug("Writing to nightly FITS " + sub.nightlyFile.fFileName); 2016 } 2017 } 2031 if (!sub.nightlyFile.Write(sub.fConv.get())) 2032 SetCurrentState(kSM_WriteError); 2033 } 2018 2034 if (sub.runFile.IsOpen()) 2019 2035 { 2020 sub.runFile.Write(sub.fConv.get()); 2021 if (fDebugIsOn) 2022 { 2023 Debug("Writing to Run FITS " + sub.runFile.fFileName); 2024 } 2036 if (!sub.runFile.Write(sub.fConv.get())) 2037 SetCurrentState(kSM_WriteError); 2025 2038 } 2026 2039 } 2027 2040 #endif //if has_fits 2041 2042 std::string DataLogger::SetCurrentState(int state, const char *txt, const std::string &cmd) 2043 { 2044 if (state == kSM_WriteError && GetCurrentState() == kSM_WriteError) 2045 return ""; 2046 return StateMachineImp::SetCurrentState(state, txt, cmd); 2047 } 2028 2048 // -------------------------------------------------------------------------- 2029 2049 //
Note:
See TracChangeset
for help on using the changeset viewer.