- Timestamp:
- 06/22/12 15:30:55 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/datalogger.cc
r14172 r14217 80 80 #include "DimNetwork.h" 81 81 82 83 82 #ifdef HAVE_FITS 84 83 #include "Fits.h" 85 84 #endif 85 86 86 87 87 //Dim structures … … 99 99 ///Run number record. Used to keep track of which run numbers are still active 100 100 struct RunNumberType { 101 #ifdef RUN_LOGS 102 ///the run number log file 103 shared_ptr<ofstream> logFile; 104 #endif 105 ///the run number report file 106 shared_ptr<ofstream> reportFile; 107 #ifdef HAVE_FITS 108 ///the run number group fits file 109 shared_ptr<CCfits::FITS> runFitsFile; 110 #endif 111 #ifdef RUN_LOGS 112 ///the log filename 113 string logName; 114 #endif 115 ///the report filename 116 string reportName; 101 117 102 ///the actual run number 118 103 int32_t runNumber; 119 104 ///the time at which the run number was received 120 105 Time time; 121 ///list of opened fits used to create the fits grouping when the run ends122 map<string, vector<string> > openedFits;123 106 ///default constructor 124 107 RunNumberType() 125 108 { 126 #ifdef RUN_LOGS127 logFile = shared_ptr<ofstream>(new ofstream());128 #endif129 reportFile = shared_ptr<ofstream>(new ofstream());130 #ifdef HAVE_FITS131 runFitsFile = shared_ptr<CCfits::FITS>();132 #endif133 109 runNumber = 0; 134 110 } … … 137 113 { 138 114 139 }140 141 void addServiceToOpenedFits(const string& fileName, const string& serviceName)142 {143 //most likely I should add this service name.144 //the only case for which I should not add it is if a service disapeared, hence the file was closed145 //and reopened again. Unlikely to happen, but well it may146 147 if (find(openedFits[fileName].begin(), openedFits[fileName].end(),148 serviceName)==openedFits[fileName].end())149 openedFits[fileName].push_back(serviceName);150 115 } 151 116 }; … … 156 121 ///Nightly FITS output file 157 122 Fits nightlyFile; 158 ///run-specific FITS output file159 Fits runFile;160 123 #endif 161 124 ///the server … … 171 134 ///whether or not the fits buffer was allocated already 172 135 bool fitsBufferAllocated; 173 174 136 ///the actual dimInfo pointer (must be the last in the list to ensure 175 137 /// that it is the first which is deleted -- and consequently none of 176 138 /// the other members can still be in use in an infoHandler) 177 139 shared_ptr<DimStampedInfo> dimInfo; 178 179 140 ///Dim info constructor 180 141 SubscriptionType(DimStampedInfo* info=NULL) … … 189 150 dimInfo = shared_ptr<DimStampedInfo>(info); 190 151 } 191 192 152 ///default destructor 193 153 ~SubscriptionType() … … 284 244 #ifdef HAVE_FITS 285 245 ///Open fits files 286 void OpenFITSFiles(SubscriptionType& sub , RunNumberType* cRunNumber);246 void OpenFITSFiles(SubscriptionType& sub); 287 247 ///Write data to FITS files 288 248 void WriteToFITS(SubscriptionType& sub); … … 313 273 ///configuration flags 314 274 bool fDebugIsOn; 315 // float fStatsPeriodDuration;316 275 bool fOpenedFilesIsOn; 317 276 bool fNumSubAndFitsIsOn; … … 331 290 map<string, vector<string> > fOpenedNightlyFits; 332 291 ///creates a group fits file based on a list of files to be grouped 333 void CreateFitsGrouping(map<string, vector<string> >& filesToGroup , int runNumber);292 void CreateFitsGrouping(map<string, vector<string> >& filesToGroup); 334 293 335 294 bool OpenStreamImp(ofstream &stream, const string &filename, bool mightbeopen); … … 349 308 void AppendYearMonthDaytoPath(string& path); 350 309 ///Form the files path 351 string CompileFileNameWithPath(const string &path, const string &service, const string & extension , uint32_t run=0/*, const Time &time=Time()*/);310 string CompileFileNameWithPath(const string &path, const string &service, const string & extension); 352 311 ///Form the file names only 353 string CompileFileName(const string& service, const string& extension, uint32_t run=0,const Time& time=Time()) const;312 string CompileFileName(const string& service, const string& extension, const Time& time=Time()) const; 354 313 ///Check whether service is in black and/or white list 355 314 bool ShouldSubscribe(const string& server, const string& service); … … 498 457 void DataLogger::RemoveService(string server, string service, bool isCmd) 499 458 { 500 Info("Got request for removingservice: "+server+"/"+service);459 Info("Got request to remove service: "+server+"/"+service); 501 460 if (fDestructing)//this function is called by the super class, after the destructor has deleted its own subscriptions 502 461 return; … … 666 625 //! @param extension the extension to add, if any 667 626 // 668 //string DataLogger::CompileFileName(const string &path, const string &service, const string & extension, const Time &time) 669 string DataLogger::CompileFileName(const string& service, const string& extension, uint32_t run, const Time& time) const 627 string DataLogger::CompileFileName(const string& service, const string& extension, const Time& time) const 670 628 { 671 629 ostringstream str; … … 674 632 str << ftime.NightAsInt(); 675 633 676 if (run>0)677 str << '_' << setfill('0') << setw(3) << run;678 679 634 if (!service.empty()) 680 635 str << '.' << service; … … 686 641 } 687 642 688 string DataLogger::CompileFileNameWithPath(const string& path, const string& service, const string& extension , uint32_t run/*, const Time& time*/)643 string DataLogger::CompileFileNameWithPath(const string& path, const string& service, const string& extension) 689 644 { 690 645 ostringstream str; … … 702 657 CreateDirectory(str.str()); 703 658 704 str << '/' << CompileFileName(service, extension, run,time);659 str << '/' << CompileFileName(service, extension, time); 705 660 706 661 return str.str(); … … 733 688 Debug(str); 734 689 } 735 CreateFitsGrouping(fRunNumber.front().openedFits, fRunNumber.front().runNumber);736 737 //crawl through the subscriptions to see if there are still corresponding fits files opened.738 for (SubscriptionsListType::iterator x=fServiceSubscriptions.begin();739 x!=fServiceSubscriptions.end(); x++)740 for (map<string, SubscriptionType>::iterator y=x->second.begin();741 y!=x->second.end(); y++)742 if (y->second.runFile.fRunNumber == fRunNumber.front().runNumber && y->second.runFile.IsOpen())743 {744 y->second.runFile.Close();745 }746 //if a grouping file is on, decrease the number of opened fits manually747 if (fRunNumber.front().runFitsFile)748 (fNumSubAndFitsData.numOpenFits)--;749 690 //remove the entry 750 691 fRunNumber.pop_front(); … … 787 728 (bind(&DataLogger::GoToReady, this)) 788 729 ("Stop all data logging, close all files."); 789 /* 790 AddEvent(kSM_Logging, "START_RUN", kSM_WaitingRun, kSM_BadRunConfig) 791 (bind(&DataLogger::StartRun, this)) 792 ("Start the run logging. Run file location must be specified already."); 793 794 AddEvent(kSM_WaitingRun, "STOP_RUN", kSM_Logging) 795 (bind(&DataLogger::StopRunLogging, this)) 796 ("Wait for a run to be started, open run-files as soon as a run number arrives."); 797 */ 730 798 731 AddEvent("RESET", kSM_Error, kSM_BadFolder, kSM_DailyWriteError, kSM_RunWriteError) 799 732 (bind(&DataLogger::GoToReady, this)) … … 808 741 ("Go from the wait for run to nightly open state."); 809 742 810 /*811 // Add the possible configurations for this machine812 AddEvent("SET_FOLDER", "C", kSM_Ready, kSM_BadNightlyConfig)813 (bind(&DataLogger::ConfigureNightlyFileName, this, placeholders::_1))814 ("Configure the base folder for the nightly files."815 "|Path[string]:Absolute or relative path name where the nightly files should be stored.");816 817 AddEvent("SET_RUN_FOLDER", "C", kSM_Ready, kSM_BadNightlyConfig, kSM_NightlyOpen, kSM_WaitingRun, kSM_BadRunConfig)818 (bind(&DataLogger::ConfigureRunFileName, this, placeholders::_1))819 ("Configure the base folder for the run files."820 "|Path[string]:Absolute or relative path name where the run files should be stored.");821 */822 743 // Provide a print command 823 744 AddEvent("PRINT_INFO") … … 909 830 fDestructing = true; 910 831 911 //first, let's backup the datalogger/message service subscription912 // shared_ptr<DimStampedInfo> messageBackup;913 // const SubscriptionsListType::iterator x = fServiceSubscriptions.find("DATA_LOGGER");914 // if (x != fServiceSubscriptions.end())915 // {916 // const map<string, SubscriptionType>::iterator y = x->second.find("MESSAGE");917 // if (y != x->second.end())918 // messageBackup = y->second.dimInfo;919 // }920 921 922 832 //now clear the services subscriptions 923 833 dim_lock(); … … 933 843 GoToReady(); 934 844 935 936 845 Info("Will soon close the daily log file"); 937 846 … … 940 849 delete fNumSubAndFits; 941 850 942 //release message service before closing nightly log file943 // if (messageBackup)944 // messageBackup.reset();945 946 851 if (fNightlyLogFile.is_open())//this file is the only one that has not been closed by GoToReady 947 852 { 948 // dim_lock();949 853 fNightlyLogFile << endl; 950 854 fNightlyLogFile.close(); 951 // dim_unlock();952 855 } 953 856 … … 984 887 SetCurrentState(Start()); 985 888 } 986 else {if (GetCurrentState() > kSM_Ready) 889 else 890 { 891 if (GetCurrentState() > kSM_Ready) 987 892 fAutoStarted = true; 988 893 } … … 1022 927 return; 1023 928 } 1024 1025 1026 929 // Make sure that getTimestampMillisecs is NEVER called before 930 // getTimestamp is properly called 931 // check that the message has been updated by something, i.e. must be different from its initial value 1027 932 if (I->getTimestamp() == 0) 1028 933 { … … 1046 951 // -------------------------------------------------------------------------- 1047 952 // 1048 //! Open the text files associated with the given run number1049 //! @param run the run number to be dealt with1050 //1051 int DataLogger::OpenRunFile(RunNumberType& run)1052 {1053 #ifdef RUN_LOGS1054 // open log file1055 run.logName = CompileFileName(fFilePath, "", "log", run.runNumber);1056 if (!OpenStream(run.logFile, run.logName))1057 return -1;1058 #endif1059 1060 // open report file1061 run.reportName = CompileFileNameWithPath(fFilePath, "", "rep", run.runNumber);1062 if (!OpenStream(run.reportFile, run.reportName))1063 return -1;1064 1065 //get the size of the newly opened file.1066 #ifdef RUN_LOGS1067 fFilesStats.FileOpened(run.logName);1068 #endif1069 fFilesStats.FileOpened(run.reportName);1070 //TODO this notification scheme might be messed up now.... fix it !1071 const string baseFileName = CompileFileNameWithPath(fFilePath, "", "", run.runNumber);1072 NotifyOpenedFile(baseFileName, 3, fOpenedRunFiles);1073 run.openedFits.clear();1074 return 0;1075 }1076 // --------------------------------------------------------------------------1077 //1078 953 //! Add a new active run number 1079 954 //! @param newRun the new run number … … 1114 989 if (GetCurrentState() != kSM_Logging && GetCurrentState() != kSM_WaitingRun ) 1115 990 return; 1116 //open the log and report files1117 if (fRunNumber.back().runNumber > 0)1118 if (OpenRunFile(fRunNumber.back()) != 0)1119 {//an error occured. close current run files and go to error state1120 for (list<RunNumberType>::iterator it=fRunNumber.begin(); it != fRunNumber.end(); it++)1121 {1122 if (it->reportFile->is_open())1123 {1124 it->reportFile->close();1125 Info("Closed: "+it->reportName);1126 }1127 #ifdef RUN_LOGS1128 if (it->logFile->is_open())1129 {1130 it->logFile->close();1131 Info("Closed: "+it->logName);1132 }1133 #endif1134 }1135 StopRunLogging();1136 SetCurrentState(kSM_BadFolder);1137 }1138 991 1139 992 if (newRun > 0 && GetCurrentState() == kSM_WaitingRun) … … 1207 1060 } 1208 1061 1209 // if (Time().h() == 12 && !fDailyFileDayChangedAlready)1210 1062 if (newDayNumber != fCurrentDay) 1211 1063 { … … 1249 1101 return; 1250 1102 } 1251 1252 // fDailyFileDayChangedAlready = true; 1253 } 1254 // if (Time().h() != 12 && fDailyFileDayChangedAlready) 1255 // fDailyFileDayChangedAlready = false; 1256 1103 } 1257 1104 //create the converter for that service 1258 1105 if (!sub.fConv) … … 1282 1129 fMjD = cTime.Mjd() ? cTime.Mjd()-40587 : 0; 1283 1130 1284 //figure out which run file should be used1285 ofstream* targetRunFile = NULL;1286 RunNumberType* cRunNumber = NULL;1287 if (GetCurrentState() == kSM_Logging || GetCurrentState() == kSM_WaitingRun)1288 {1289 list<RunNumberType>::reverse_iterator rit;1290 for (rit=fRunNumber.rbegin(); rit!=fRunNumber.rend(); rit++)1291 {1292 if (rit->time < cTime) //this is the run number that we want to use1293 {1294 //Find something better to convert iterator to pointer than the ugly line below....1295 cRunNumber = &(*rit);1296 sub.runNumber = rit->runNumber;1297 1298 if (rit->runNumber <= 0)//take only positive numbers.1299 break;1300 #ifdef RUN_LOGS1301 targetRunFile = isItaReport ? (rit->reportFile).get() : (rit->logFile).get();1302 #else1303 targetRunFile = isItaReport ? (rit->reportFile).get() : NULL;1304 #endif1305 break;1306 }1307 }1308 if (rit == fRunNumber.rend() && fRunNumber.size() != 0)1309 {1310 Error("Could not find an appropriate run number for info coming at time "+cTime.GetAsStr());1311 Error("Active run numbers: ");1312 for (rit=fRunNumber.rbegin(); rit != fRunNumber.rend(); rit++)1313 {1314 ostringstream str;1315 str << " -> " << rit->runNumber;1316 Error(str);1317 }1318 1319 }1320 }1321 1322 1131 if (isItaReport) 1323 1132 { … … 1342 1151 //because these operators use references to elements, and because they're supposed here to erase these objects on the way, I'm not too sure... so duplicate the names ! 1343 1152 RemoveService(sub.server, sub.service, false); 1344 // string server = sub.server;1345 // string service = sub.service;1346 // fServiceSubscriptions.find(server)->second.erase(service);1347 1153 return; 1348 1154 } … … 1366 1172 return; 1367 1173 } 1368 //write entry to run-report1369 if (targetRunFile && targetRunFile->is_open())1370 {1371 *targetRunFile << header.str() << text << endl;1372 if (!CheckForOfstreamError(*targetRunFile, false))1373 return;1374 }1375 1174 #ifdef HAVE_FITS 1376 1175 //check if the last received event was before noon and if current one is after noon. 1377 1176 //if so, close the file so that it gets reopened. 1378 // if (sub.nightlyFile.IsOpen()) 1379 // if ((sub.lastReceivedEvent != Time::None) && (sub.lastReceivedEvent.h() < 12) && (cTime.h() >= 12)) 1380 // { 1381 // sub.nightlyFile.Close(); 1382 // } 1383 sub.lastReceivedEvent = cTime;//ici 1384 if (!sub.nightlyFile.IsOpen() || !sub.runFile.IsOpen() || sub.runNumber != sub.runFile.fRunNumber) 1177 sub.lastReceivedEvent = cTime; 1178 if (!sub.nightlyFile.IsOpen()) 1385 1179 if (GetCurrentState() != kSM_Ready) 1386 OpenFITSFiles(sub , cRunNumber);1180 OpenFITSFiles(sub); 1387 1181 WriteToFITS(sub); 1388 1182 #endif … … 1404 1198 //because these operators use references to elements, and because they're supposed here to erase these objects on the way, I'm not too sure... so duplicate the names ! 1405 1199 RemoveService(sub.server, sub.service, false); 1406 // string server = sub.server;1407 // string service = sub.service;1408 // fServiceSubscriptions.find(server)->second.erase(service);1409 1200 return; 1410 1201 } … … 1424 1215 return; 1425 1216 } 1426 if (targetRunFile && targetRunFile->is_open()) 1427 { 1428 MessageImp(*targetRunFile).Write(cTime, msg.str().c_str(), fQuality); 1429 if (!CheckForOfstreamError(*targetRunFile, false)) 1430 return; 1431 } 1432 1433 sub.lastReceivedEvent = cTime;//ici 1434 if (!sub.nightlyFile.IsOpen() || !sub.runFile.IsOpen() || sub.runNumber != sub.runFile.fRunNumber) 1217 1218 sub.lastReceivedEvent = cTime; 1219 if (!sub.nightlyFile.IsOpen()) 1435 1220 if (GetCurrentState() != kSM_Ready) 1436 OpenFITSFiles(sub , cRunNumber);1221 OpenFITSFiles(sub); 1437 1222 WriteToFITS(sub); 1438 1223 } … … 1482 1267 Message("Nightly report-file: "+fFullNightlyReportFileName); 1483 1268 1484 for (list<RunNumberType>::const_iterator it=fRunNumber.begin(); it!=fRunNumber.end(); it++)1485 {1486 #ifdef RUN_LOGS1487 if (it->logFile->is_open())1488 Message("Run log-file: " + it->logName);1489 #endif1490 if (it->reportFile->is_open())1491 Message("Run report-file: " + it->reportName);1492 }1493 1494 1269 const DimWriteStatistics::Stats statVar = fFilesStats.GetTotalSizeWritten(); 1495 1270 // /*const bool statWarning =*/ calculateTotalSizeWritten(statVar, true); … … 1670 1445 // -------------------------------------------------------------------------- 1671 1446 // 1672 //! Sets the path to use for the Nightly log file.1673 //! @param evt1674 //! the event transporting the path1675 //! @returns1676 //! currently only the current state.1677 /*1678 int DataLogger::ConfigureFilePath(const Event& evt)1679 {1680 if (!evt.GetText())1681 {1682 Error("Empty folder given. Please specify a valid path.");1683 return GetCurrentState();1684 }1685 1686 const string givenPath = evt.GetText();1687 if (!DoesPathExist(givenPath))1688 {1689 Error("Provided path '"+givenPath+"' is not a valid folder... ignored.");1690 return GetCurrentState();1691 }1692 1693 Message("New folder: "+givenPath);1694 1695 fFilePath = givenPath;1696 1697 fFilesStats.SetCurrentFolder(givenPath);1698 1699 return GetCurrentState();1700 }1701 */1702 1703 // --------------------------------------------------------------------------1704 //1705 1447 //! Notifies the DIM service that a particular file was opened 1706 1448 //! @ param name the base name of the opened file, i.e. without path nor extension. … … 1783 1525 //! @param sub 1784 1526 //! the current DimInfo subscription being examined 1785 void DataLogger::OpenFITSFiles(SubscriptionType& sub , RunNumberType* cRunNumber)1527 void DataLogger::OpenFITSFiles(SubscriptionType& sub) 1786 1528 { 1787 1529 string serviceName(sub.dimInfo->getName()); 1788 1530 1789 //if run number has changed, reopen a new fits file with the correct run number.1790 if (sub.runFile.IsOpen() && sub.runFile.fRunNumber != sub.runNumber)1791 {1792 sub.runFile.Close();1793 Info("Closed: "+sub.runFile.GetName()+" (new run number)");1794 }1795 1796 //we must check if we should group this service subscription to a single fits file before we replace the / by _1797 bool hasGrouping = false;1798 if (!sub.runFile.IsOpen() && ((GetCurrentState() == kSM_Logging) || (GetCurrentState() == kSM_WaitingRun)))1799 {//will we find this service in the grouping list ?1800 for (set<string>::const_iterator it=fGrouping.begin(); it!=fGrouping.end(); it++)1801 {1802 if (serviceName.find(*it) != string::npos)1803 {1804 hasGrouping = true;1805 break;1806 }1807 }1808 }1809 1531 for (unsigned int i=0;i<serviceName.size(); i++) 1810 1532 { … … 1843 1565 fNumSubAndFits->Update(); 1844 1566 } 1845 //do the actual file open 1846 if (!sub.runFile.IsOpen() && (GetCurrentState() == kSM_WaitingRun || GetCurrentState() == kSM_Logging) && sub.runNumber > 0) 1847 {//buffer for the run file have already been allocated when doing the Nightly file 1848 1849 const string partialName = 1850 CompileFileNameWithPath(fFilePath, hasGrouping ? "" : serviceName, "fits", sub.runNumber); 1851 1852 const string fileNameOnly = 1853 partialName.substr(partialName.find_last_of('/')+1, partialName.size()); 1854 1855 //get the size of the file we're about to open 1856 if (fFilesStats.FileOpened(partialName)) 1857 cRunNumber->openedFits[fileNameOnly].push_back(serviceName); 1858 else 1859 if (hasGrouping) 1860 { 1861 cRunNumber->addServiceToOpenedFits(fileNameOnly, serviceName); 1862 } 1863 1864 if (hasGrouping && (!cRunNumber->runFitsFile.get())) 1865 try 1866 { 1867 cRunNumber->runFitsFile = shared_ptr<CCfits::FITS>(new CCfits::FITS(partialName, CCfits::RWmode::Write)); 1868 (fNumSubAndFitsData.numOpenFits)++; 1869 } 1870 catch (CCfits::FitsException e) 1871 { 1872 ostringstream str; 1873 str << "Open FITS file " << partialName << ": " << e.message(); 1874 Error(str); 1875 cRunNumber->runFitsFile = shared_ptr<CCfits::FITS>(); 1876 GoToRunWriteErrorState(); 1877 return; 1878 } 1879 1880 const string baseFileName = CompileFileNameWithPath(fFilePath, "", "", sub.runNumber); 1881 NotifyOpenedFile(baseFileName, 7, fOpenedRunFiles); 1882 1883 if (hasGrouping) 1884 { 1885 if (!sub.runFile.Open(partialName, serviceName, &fNumSubAndFitsData.numOpenFits, this, sub.runNumber, cRunNumber->runFitsFile.get())) 1886 { 1887 GoToRunWriteErrorState(); 1888 return; 1889 } 1890 } 1891 else 1892 { 1893 if (!sub.runFile.Open(partialName, serviceName, &fNumSubAndFitsData.numOpenFits, this, sub.runNumber)) 1894 { 1895 GoToRunWriteErrorState(); 1896 return; 1897 } 1898 } 1899 1900 ostringstream str; 1901 str << "Opened: " << partialName << " (Nfits=" << fNumSubAndFitsData.numOpenFits << ")"; 1902 Info(str); 1903 1904 if (fNumSubAndFitsIsOn) 1905 fNumSubAndFits->Update(); 1906 } 1567 1907 1568 } 1908 1569 // -------------------------------------------------------------------------- … … 1916 1577 Description dateDesc(string("Time"), string("Modified Julian Date"), string("MJD")); 1917 1578 sub.nightlyFile.AddStandardColumn(dateDesc, "1D", &fMjD, sizeof(double)); 1918 sub.runFile.AddStandardColumn(dateDesc, "1D", &fMjD, sizeof(double));1919 1579 1920 1580 Description QoSDesc("QoS", "Quality of service", ""); 1921 1581 sub.nightlyFile.AddStandardColumn(QoSDesc, "1J", &fQuality, sizeof(int)); 1922 sub.runFile.AddStandardColumn(QoSDesc, "1J", &fQuality, sizeof(int));1923 1582 1924 1583 // Compilation failed … … 1937 1596 Info(str); 1938 1597 sub.nightlyFile.InitDataColumns(GetDescription(sub.server, sub.service), dataFormatsLocal, sub.dimInfo->getData(), this); 1939 sub.runFile.InitDataColumns(GetDescription(sub.server, sub.service), dataFormatsLocal, sub.dimInfo->getData(), this);1940 1598 1941 1599 sub.fitsBufferAllocated = true; … … 1952 1610 if (!sub.nightlyFile.Write(*sub.fConv.get())) 1953 1611 { 1954 //sub.nightlyFile.Close();1955 1612 RemoveService(sub.server, sub.service, false); 1956 1613 GoToNightlyWriteErrorState(); 1957 1614 return; 1958 1615 } 1959 // sub.nightlyFile.Flush();1960 1616 } 1961 1962 if (sub.runFile.IsOpen())1963 {1964 if (!sub.runFile.Write(*sub.fConv.get()))1965 {1966 sub.runFile.Close();1967 RemoveService(sub.server, sub.service, false);1968 GoToRunWriteErrorState();1969 return;1970 }1971 }1972 1617 } 1973 1618 #endif //if has_fits … … 1992 1637 } 1993 1638 1994 /* 1995 // -------------------------------------------------------------------------- 1996 // 1997 //! Implements the StartRun transition. 1998 //! Concatenates the given path for the run file and the filename itself (based on the run number), 1999 //! and tries to open it. 2000 //! @returns 2001 //! kSM_Logging if success, kSM_BadRunConfig if failure. 2002 int DataLogger::StartRun() 2003 { 2004 if (fDebugIsOn) 2005 { 2006 Debug("Starting Run Logging..."); 2007 } 2008 //open all the relevant run-files. i.e. all the files associated with run numbers. 2009 for (list<RunNumberType>::iterator it=fRunNumber.begin(); it != fRunNumber.end(); it++) 2010 if (OpenRunFile(*it) != 0) 2011 { 2012 StopRun(); 2013 return kSM_BadRunConfig; 2014 } 2015 2016 return kSM_Logging; 2017 } 2018 */ 1639 2019 1640 #ifdef HAVE_FITS 2020 1641 // -------------------------------------------------------------------------- … … 2025 1646 //! @param runNumber the run number that should be used for grouping. 0 means nightly group 2026 1647 // 2027 void DataLogger::CreateFitsGrouping(map<string, vector<string> > & filesToGroup , int runNumber)1648 void DataLogger::CreateFitsGrouping(map<string, vector<string> > & filesToGroup) 2028 1649 { 2029 1650 if (fDebugIsOn) 2030 1651 { 2031 1652 ostringstream str; 2032 str << "Creating fits group for "; 2033 if (runNumber != 0) 2034 str << "run files"; 2035 else 2036 str << "nightly files"; 1653 str << "Creating fits group for nightly files"; 2037 1654 Debug(str); 2038 1655 } … … 2064 1681 return; 2065 1682 } 2066 const string groupName = CompileFileNameWithPath(fFilePath, "", "fits" , runNumber);1683 const string groupName = CompileFileNameWithPath(fFilePath, "", "fits"); 2067 1684 2068 1685 Info("Creating FITS group in: "+groupName); 2069 1686 2070 1687 CCfits::Table* groupTable; 2071 // const int maxCharLength = FILENAME_MAX; 1688 2072 1689 try 2073 1690 { … … 2122 1739 char *startOfLocation = realBuffer.data()+8+3; 2123 1740 char *startOfName = realBuffer.data()+8+3+maxCharLength; 2124 // char* startOfMemVer = reinterpret_cast<char*>(&fitsBuffer[8+3+2*maxCharLength]);2125 // char* startOfMemPos = reinterpret_cast<char*>(&fitsBuffer[8+3+2*maxCharLength+1]);2126 1741 2127 1742 strcpy(startOfExtension, "BINTABLE"); … … 2181 1796 Debug("Stopping Run Logging..."); 2182 1797 } 2183 //it may be that dim tries to write a dimInfo at the same time as we're closing files. Prevent this 2184 2185 // dim_lock(); 2186 for (list<RunNumberType>::const_iterator it=fRunNumber.begin(); it != fRunNumber.end(); it++) 2187 { 2188 #ifdef RUN_LOGS 2189 if (!it->logFile->is_open() || !it->reportFile->is_open()) 2190 #else 2191 if (!it->reportFile->is_open()) 2192 #endif 2193 return kSM_FatalError; 2194 #ifdef RUN_LOGS 2195 it->logFile->close(); 2196 Info("Closed: "+it->logName); 2197 2198 #endif 2199 it->reportFile->close(); 2200 Info("Closed: "+it->reportName); 2201 } 2202 2203 #ifdef HAVE_FITS 2204 for (SubscriptionsListType::iterator i = fServiceSubscriptions.begin(); i != fServiceSubscriptions.end(); i++) 2205 for (map<string, SubscriptionType>::iterator j = i->second.begin(); j != i->second.end(); j++) 2206 { 2207 if (j->second.runFile.IsOpen()) 2208 j->second.runFile.Close(); 2209 } 2210 #endif 2211 NotifyOpenedFile("", 0, fOpenedRunFiles); 1798 2212 1799 if (fNumSubAndFitsIsOn) 2213 1800 fNumSubAndFits->Update(); … … 2217 1804 RemoveOldestRunNumber(); 2218 1805 } 2219 // dim_unlock();2220 1806 return kSM_WaitingRun; 2221 1807 } … … 2260 1846 } 2261 1847 #ifdef HAVE_FITS 2262 CreateFitsGrouping(fOpenedNightlyFits , 0);1848 CreateFitsGrouping(fOpenedNightlyFits); 2263 1849 #endif 2264 1850 return kSM_Ready; … … 2274 1860 { 2275 1861 int cState = GetCurrentState(); 2276 2277 // if (cState == kSM_Logging)2278 // cState = kSM_NightlyOpen;2279 1862 2280 1863 if (cState == kSM_Ready) … … 2473 2056 return 127; 2474 2057 2475 // try2476 2058 { 2477 2059 // No console access at all … … 2485 2067 return RunShell<LocalConsole>(conf); 2486 2068 } 2487 /* catch (exception& e) 2488 { 2489 cerr << "Exception: " << e.what() << endl; 2490 return -1; 2491 }*/ 2069 2492 2070 2493 2071 return 0;
Note:
See TracChangeset
for help on using the changeset viewer.