- Timestamp:
- 06/09/11 23:31:28 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/dataLogger.cc
r10955 r10968 416 416 if (path[path.size()-1] == '/') 417 417 path = path.substr(0, path.size()-1); 418 418 419 //create boost path 419 boost::filesystem::path fullPath = boost::filesystem::system_complete(boost::filesystem::path(path));420 const boost::filesystem::path fullPath = boost::filesystem::system_complete(boost::filesystem::path(path)); 420 421 421 422 //if path does not exist, check if upper levels exist already 422 if (!boost::filesystem::exists(fullPath)) 423 { 424 if (path.size() <= 1) 425 {//we're hitting "/", which SHOULD have existed... 426 Error("Something unexpected happened while creating a path"); 427 } 428 CreateDirectory(path.substr(0, path.find_last_of('/'))); 429 } 430 else 431 {//if path already exist, make sure it does not designate a file (filenames cannot be checked if they do not exist) 432 if (!boost::filesystem::is_directory(fullPath)) 433 { 434 Error("Path to be created contains a file name: '" + path + "'"); 435 return false; 436 } 437 438 return true; 439 } 423 if (boost::filesystem::exists(fullPath)) 424 { 425 //if path already exist, make sure it does not designate a file (filenames cannot be checked if they do not exist) 426 if (boost::filesystem::is_directory(fullPath)) 427 return true; 428 429 Error("Path to be created contains a file name: '" + path + "'"); 430 return false; 431 } 432 433 if (path.size() <= 1) 434 {//we're hitting "/", which SHOULD have existed... 435 Error("Something unexpected happened while creating a path"); 436 } 437 CreateDirectory(path.substr(0, path.find_last_of('/'))); 438 440 439 //path does not exist, and upper level have been created already by recusrion. 441 mode_t rightsMask = S_IRWXU | S_IXGRP | S_IRGRP | S_IXOTH | S_IROTH; //everybody read, owner writes442 443 int returnValue = mkdir(path.c_str(), rightsMask);440 const mode_t rightsMask = S_IRWXU | S_IXGRP | S_IRGRP | S_IXOTH | S_IROTH; //everybody read, owner writes 441 442 const int returnValue = mkdir(path.c_str(), rightsMask); 444 443 445 444 if (returnValue != 0) … … 461 460 bool DataLogger::DoesPathExist(string path) 462 461 { 463 boost::filesystem::path fullPath = boost::filesystem::system_complete(boost::filesystem::path(path)); 464 462 const boost::filesystem::path fullPath = boost::filesystem::system_complete(boost::filesystem::path(path)); 465 463 466 464 if (!boost::filesystem::exists(fullPath)) … … 596 594 errno = 0; 597 595 stream.open(name.c_str(), ios_base::out | ios_base::app); 598 if ( errno != 0)596 if (!stream) 599 597 { 600 598 ostringstream str; 601 str << " Unable to open file: " << name << ". Reason: " << strerror(errno) << " [" << errno << "]";599 str << "Open file " << name << ": " << strerror(errno) << " (errno=" << errno << ")"; 602 600 Error(str); 603 601 } … … 793 791 if (y->second.runFile.IsOpen()) 794 792 { 795 796 797 793 fFileSizesMap[y->second.runFile.fFileName] = y->second.runFile.GetWrittenSize(); 794 if (isPrinting) 795 Message("-> "+y->second.runFile.fFileName); 798 796 } 799 797 if (y->second.nightlyFile.IsOpen()) … … 848 846 return shouldWarn; 849 847 } 848 850 849 //static members initialization 851 850 //since I do not check the transition/config names any longer, indeed maybe these could be hard-coded... but who knows what will happen in the future ? … … 1130 1129 1131 1130 //update the fits files sizes 1132 Time cTime = Time();1131 const Time cTime = Time(); 1133 1132 if ((fStatsPeriodDuration != 0) && ((cTime.Mjd() - fPreviousStatsUpdateTime)*24*60*60 > fStatsPeriodDuration)) 1134 1133 { … … 1163 1162 } 1164 1163 run.logName = CompileFileName(fRunFilePath, run.runNumber, "", "log"); 1164 1165 1165 errno = 0; 1166 1166 run.logFile->open(run.logName.c_str(), ios_base::out | ios_base::app); … … 1168 1168 { 1169 1169 ostringstream str; 1170 str << "Unable to open run Log " << run.logName << ". Reason: " << strerror(errno) << " [" << errno << "]";1170 str << "Unable to open log-file " << run.logName << ": " << strerror(errno) << " (errno=" << errno << ")"; 1171 1171 Error(str); 1172 1172 } … … 1181 1181 return -1; 1182 1182 } 1183 1183 1184 errno = 0; 1184 1185 run.reportFile->open(run.reportName.c_str(), ios_base::out | ios_base::app); … … 1186 1187 { 1187 1188 ostringstream str; 1188 str << "Unable to open r un report " << run.reportName << ". Reason: " << strerror(errno) << " [" << errno << "]";1189 str << "Unable to open rep-file " << run.reportName << ": " << strerror(errno) << " (errno=" << errno << ")"; 1189 1190 Error(str); 1190 1191 } … … 1212 1213 1213 1214 //TODO this notification scheme might be messed up now.... fix it ! 1214 string baseFileName = CompileFileName(fRunFilePath, run.runNumber, "", "");1215 const string baseFileName = CompileFileName(fRunFilePath, run.runNumber, "", ""); 1215 1216 NotifyOpenedFile(baseFileName, 3, fOpenedRunFiles); 1216 1217 run.openedFits.clear(); … … 1653 1654 int DataLogger::SetNumSubsAndFitsOnOff(const Event& evt) 1654 1655 { 1655 bool backupSubs = fNumSubAndFitsIsOn;1656 const bool backupSubs = fNumSubAndFitsIsOn; 1656 1657 fNumSubAndFitsIsOn = evt.GetBool(); 1658 1657 1659 if (fNumSubAndFitsIsOn == backupSubs) 1658 1660 Warn("Warning: Number of subscriptions service mode was already in the requested state"); … … 1700 1702 int DataLogger::ConfigureRunFileName(const Event& evt) 1701 1703 { 1702 if (evt.GetText() != NULL) 1703 { 1704 string givenPath = string(evt.GetText()); 1705 if (!DoesPathExist(givenPath)) 1706 { 1707 Error("Provided path is not a valid folder. Ignored"); 1708 return GetCurrentState(); 1709 } 1710 fRunFilePath = givenPath; 1711 Message("New Run folder specified: " + fRunFilePath); 1712 } 1713 else 1704 if (evt.GetText() == NULL) 1705 { 1714 1706 Error("Empty Nightly folder given. Please specify a valid path"); 1707 return GetCurrentState(); 1708 } 1709 1710 const string givenPath = string(evt.GetText()); 1711 if (!DoesPathExist(givenPath)) 1712 { 1713 Error("Provided path is not a valid folder. Ignored"); 1714 return GetCurrentState(); 1715 } 1716 1717 fRunFilePath = givenPath; 1718 Message("New Run folder specified: " + fRunFilePath); 1715 1719 1716 1720 return GetCurrentState(); … … 1798 1802 1799 1803 //notify that a new file has been opened. 1800 string baseFileName = CompileFileName(fNightlyFilePath, "", "");1804 const string baseFileName = CompileFileName(fNightlyFilePath, "", ""); 1801 1805 NotifyOpenedFile(baseFileName, 3, fOpenedNightlyFiles); 1802 1806 … … 1815 1819 { 1816 1820 string serviceName(sub.dimInfo->getName()); 1821 1817 1822 //if run number has changed, reopen a new fits file with the correct run number. 1818 1823 if (sub.runFile.IsOpen() && sub.runFile.fRunNumber != sub.runNumber) … … 1822 1827 sub.runFile.Close(); 1823 1828 } 1824 //we must check if we should group this service subscription to a single fits file before we replace the / by _ 1829 1830 //we must check if we should group this service subscription to a single fits file before we replace the / by _ 1825 1831 bool hasGrouping = false; 1826 1832 if (!sub.runFile.IsOpen() && (GetCurrentState() == kSM_Logging)) … … 1847 1853 if (!sub.nightlyFile.IsOpen()) 1848 1854 { 1849 string fileNameOnly, partialName;1850 partialName = CompileFileName(fNightlyFilePath, serviceName, "fits"); 1851 fileNameOnly = partialName.substr(partialName.find_last_of('/')+1, partialName.size());1855 string partialName = CompileFileName(fNightlyFilePath, serviceName, "fits"); 1856 1857 const string fileNameOnly = partialName.substr(partialName.find_last_of('/')+1, partialName.size()); 1852 1858 if (!sub.fitsBufferAllocated) 1853 1859 AllocateFITSBuffers(sub); … … 1862 1868 } 1863 1869 //notify the opening 1864 string baseFileName = CompileFileName(fNightlyFilePath, "", "");1870 const string baseFileName = CompileFileName(fNightlyFilePath, "", ""); 1865 1871 NotifyOpenedFile(baseFileName, 7, fOpenedNightlyFiles); 1866 1872 if (fNumSubAndFitsIsOn) … … 1911 1917 } 1912 1918 1913 string baseFileName = CompileFileName(fRunFilePath, sub.runNumber, "", "");1919 const string baseFileName = CompileFileName(fRunFilePath, sub.runNumber, "", ""); 1914 1920 NotifyOpenedFile(baseFileName, 7, fOpenedRunFiles);// + '_' + serviceName, 4); 1915 1921 if (hasGrouping) … … 1946 1952 void DataLogger::AllocateFITSBuffers(SubscriptionType& sub) 1947 1953 { 1948 int size = sub.dimInfo->getSize();1949 1950 1954 //Init the time columns of the file 1951 1955 Description dateDesc(string("Time"), string("Modified Julian Date"), string("MjD")); … … 1967 1971 //we've got a nice structure describing the format of this service's messages. 1968 1972 //Let's create the appropriate FITS columns 1973 int size = sub.dimInfo->getSize(); 1974 1969 1975 vector<string> dataFormatsLocal; 1970 1976 for (unsigned int i=0;i<flist.size()-1;i++) … … 2003 2009 break; 2004 2010 case 'S': 2011 size--; 2005 2012 //for strings, the number of elements I get is wrong. Correct it 2006 2013 dataQualifier.str(""); //clear 2007 dataQualifier << size-1 << "A"; 2008 size = size-1; 2014 dataQualifier << size << "A"; 2009 2015 break; 2010 2016 … … 2032 2038 SetCurrentState(kSM_WriteError); 2033 2039 } 2040 2034 2041 if (sub.runFile.IsOpen()) 2035 2042 {
Note:
See TracChangeset
for help on using the changeset viewer.