Changeset 10887 for trunk/FACT++
- Timestamp:
- 05/31/11 10:19:09 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/dataLogger.cc
r10867 r10887 194 194 } 195 195 196 void addServiceToOpenedFits(const string& fileName, const string& serviceName) 197 {//most likely I should add this service name. 198 //the only case for which I should not add it is if a service disapeared, hence the file was closed 199 //and reopened again. Unlikely to happen, but well it may 200 bool found = false; 201 for (vector<string>::iterator it=openedFits[fileName].begin(); it!=openedFits[fileName].end(); it++) 202 if (*it == serviceName) 203 { 204 found = true; 205 break; 206 } 207 if (!found) 208 openedFits[fileName].push_back(serviceName); 209 } 210 196 211 }; 197 212 ///Dim subscription type. Stores all the relevant info to handle a Dim subscription … … 456 471 ///retrieves the size of a file 457 472 off_t GetFileSize(string&); 473 ///Form the base (without extension) name of the nightly text files (logs and reports) 474 void FormBaseNightlyTextFileName(string& name); 458 475 ///Form the name of the nightly text files (logs and reports) 459 476 void FormNightlyTextFileName(string& name, bool isReport); 477 ///Form the base (without extension) name of the run text files (logs and reports) 478 void FormBaseRunTextFileName(string& name, const int runNumber); 460 479 ///Form the name of the run text files (logs and reports) 461 480 void FormRunTextFileName(string& name, bool isReport, const int runNumber); … … 478 497 ///Remembers the size of newly opened files. for statistic purposes 479 498 bool RememberFileOrigSizePlease(string& fileName, bool nightly); 499 ///Checks if the input osftream is in error state, and if so close it. 500 void CheckForOfstreamError(ofstream& out); 480 501 }; //DataLogger 481 502 482 503 // -------------------------------------------------------------------------- 483 504 // 484 //! 505 //! Checks if the given ofstream is in error state and if so, close it 506 //! @param out the ofstream that should be checked 507 // 508 void DataLogger::CheckForOfstreamError(ofstream& out) 509 { 510 if (!out.good()) 511 { 512 Error("An error occured while writing to a text file. Closing it"); 513 if (out.is_open()) 514 out.close(); 515 } 516 } 517 // -------------------------------------------------------------------------- 518 // 519 //! Checks the size on disk of a given size, and remembers it in the relevant member variable 520 //! @param fileName the file for which the size on disk should be retrieved 521 //! @param nightly whether this is a run or nightly file, so that its size is added to the correct member variable 485 522 // 486 523 bool DataLogger::RememberFileOrigSizePlease(string& fileName, bool nightly) … … 500 537 // -------------------------------------------------------------------------- 501 538 // 502 //! 539 //! Checks if a given directory is simply '.' and retrieves the coresponding full path 540 //! @param dir the input directory that should be checked against 541 //! @return the full path corresponding to the input directory 503 542 // 504 543 string DataLogger::CheckIfDirIsDot(const string& dir) … … 525 564 // -------------------------------------------------------------------------- 526 565 // 527 //! 566 //! Open a text file and checks for error code 567 //! @param stream the ofstream for which the file should be opened 568 //! @name the file name 528 569 // 529 570 void DataLogger::OpenTextFilePlease(ofstream& stream, const string& name) … … 644 685 // -------------------------------------------------------------------------- 645 686 // 687 //! Form the base (without extension) name of the run text files (logs and reports) 688 //! @param name the full file name 689 //! @param runNumber the current run number for which this file should be opened 690 // 691 void DataLogger::FormBaseRunTextFileName(string& name, const int runNumber) 692 { 693 ostringstream sRun; 694 sRun << runNumber; 695 696 name = CheckIfDirIsDot(fRunFilePath) + '/' + sRun.str(); 697 } 698 // -------------------------------------------------------------------------- 699 // 646 700 //! Form the name of the run text files (logs and reports) 647 701 //! @param name the full file name … … 651 705 void DataLogger::FormRunTextFileName(string& name, bool isReport, const int runNumber) 652 706 { 653 ostringstream sRun; 654 sRun << runNumber; 655 656 name = fRunFilePath + '/' + sRun.str(); 707 FormBaseRunTextFileName(name, runNumber); 657 708 658 709 if (isReport) … … 663 714 // -------------------------------------------------------------------------- 664 715 // 716 //! Form the base (without extension) name of the nightly text files (logs and reports) 717 //! @param name the full file name 718 // 719 void DataLogger::FormBaseNightlyTextFileName(string& name) 720 { 721 Time time; 722 ostringstream sTime; 723 sTime << time.Y() << "_" << time.M() << "_" << time.D(); 724 725 name = CheckIfDirIsDot(fNightlyFilePath) + '/' + sTime.str(); 726 } 727 // -------------------------------------------------------------------------- 728 // 665 729 //! Form the name of the nightly text files (logs and reports) 666 730 //! @param name the full file name … … 669 733 void DataLogger::FormNightlyTextFileName(string& name, bool isReport) 670 734 { 671 Time time; 672 ostringstream sTime; 673 sTime << time.Y() << "_" << time.M() << "_" << time.D(); 674 675 name = fNightlyFilePath + '/' + sTime.str(); 735 FormBaseNightlyTextFileName(name); 736 676 737 if (isReport) 677 738 name += ".rep"; … … 1267 1328 1268 1329 //TODO this notification scheme might be messed up now.... fix it ! 1269 ostringstream sRun;1270 sRun << run.runNumber;1271 NotifyOpenedFile( CheckIfDirIsDot(fRunFilePath) + '/' + sRun.str(), 3, fOpenedRunFiles);1330 string baseFileName; 1331 FormBaseRunTextFileName(baseFileName, run.runNumber); 1332 NotifyOpenedFile(baseFileName, 3, fOpenedRunFiles); 1272 1333 run.openedFits.clear(); 1273 1334 return 0; … … 1426 1487 { 1427 1488 fNightlyReportFile << header.str() << text << endl; 1428 //check if either eof, bailbit or batbit are set 1429 if (!fNightlyReportFile.good()) 1430 { 1431 Error("An error occured while writing to the nightly report file. Closing it"); 1432 if (fNightlyReportFile.is_open()) 1433 fNightlyReportFile.close(); 1434 } 1489 CheckForOfstreamError(fNightlyReportFile); 1435 1490 } 1436 1491 //write entry to run-report … … 1438 1493 { 1439 1494 *targetRunFile << header.str() << text << endl; 1440 if (!targetRunFile->good()) 1441 { 1442 Error("An error occured while writing to the run report file. Closing it."); 1443 if (targetRunFile->is_open()) 1444 targetRunFile->close(); 1445 } 1495 CheckForOfstreamError(*targetRunFile); 1446 1496 } 1447 1497 } … … 1456 1506 MessageImp nightlyMess(fNightlyLogFile); 1457 1507 nightlyMess.Write(cTime, msg.str().c_str(), fQuality); 1458 if (!fNightlyLogFile.good()) 1459 { 1460 Error("An error occured while writing to the nightly log file. Closing it."); 1461 if (fNightlyLogFile.is_open()) 1462 fNightlyLogFile.close(); 1463 } 1508 CheckForOfstreamError(fNightlyLogFile); 1464 1509 } 1465 1510 if (targetRunFile && targetRunFile->is_open()) … … 1467 1512 MessageImp runMess(*targetRunFile); 1468 1513 runMess.Write(cTime, msg.str().c_str(), fQuality); 1469 if (!targetRunFile->good()) 1470 { 1471 Error("An error occured while writing to the run log file. Closing it."); 1472 if (targetRunFile->is_open()) 1473 targetRunFile->close(); 1474 } 1514 CheckForOfstreamError(*targetRunFile); 1475 1515 } 1476 1516 } … … 1864 1904 Debug(str); 1865 1905 } 1906 if (name.size()+1 > FILENAME_MAX) 1907 { 1908 Error("Provided file name \"" + name + "\" is longer than allowed file name length"); 1909 } 1866 1910 OpenFileToDim fToDim; 1867 1911 fToDim.code = type; … … 1907 1951 1908 1952 //notify that a new file has been opened. 1909 Time time; 1910 ostringstream sTime; 1911 sTime << time.Y() << "_" << time.M() << "_" << time.D(); 1912 NotifyOpenedFile(CheckIfDirIsDot(fNightlyFilePath) + '/' + sTime.str(), 3, fOpenedNightlyFiles); 1953 string baseFileName; 1954 FormBaseNightlyTextFileName(baseFileName); 1955 NotifyOpenedFile(baseFileName, 3, fOpenedNightlyFiles); 1913 1956 1914 1957 fOpenedNightlyFits.clear(); … … 1968 2011 1969 2012 //notify the opening 1970 Time time; 1971 ostringstream sTime; 1972 sTime << time.Y() << "_" << time.M() << "_" << time.D(); 1973 NotifyOpenedFile(CheckIfDirIsDot(fNightlyFilePath) + '/' + sTime.str(), 7, fOpenedNightlyFiles); 2013 string baseFileName; 2014 FormBaseNightlyTextFileName(baseFileName); 2015 NotifyOpenedFile(baseFileName, 7, fOpenedNightlyFiles); 1974 2016 if (fNumSubAndFitsIsOn) 1975 2017 fNumSubAndFits->updateService(); … … 2000 2042 else 2001 2043 if (hasGrouping) 2002 {//most likely I should add this service name. 2003 //the only case for which I should not add it is if a service disapeared, hence the file was closed 2004 //and reopened again. Unlikely to happen, but well it may 2005 bool found = false; 2006 for (vector<string>::iterator it=cRunNumber->openedFits[fileNameOnly].begin(); it!=cRunNumber->openedFits[fileNameOnly].end(); it++) 2007 if (*it == serviceName) 2008 { 2009 found = true; 2010 break; 2011 } 2012 if (!found) 2013 cRunNumber->openedFits[fileNameOnly].push_back(serviceName); 2044 { 2045 cRunNumber->addServiceToOpenedFits(fileNameOnly, serviceName); 2014 2046 } 2015 2047 … … 2028 2060 } 2029 2061 2030 ostringstream sRun;2031 sRun << sub.runNumber;2032 NotifyOpenedFile( CheckIfDirIsDot(fRunFilePath) + '/' + sRun.str(), 7, fOpenedRunFiles);// + '_' + serviceName, 4);2062 string baseFileName; 2063 FormBaseRunTextFileName(baseFileName, sub.runNumber); 2064 NotifyOpenedFile(baseFileName, 7, fOpenedRunFiles);// + '_' + serviceName, 4); 2033 2065 if (hasGrouping) 2034 2066 sub.runFile.Open(partialName, serviceName, cRunNumber->runFitsFile, &fNumSubAndFitsData.numOpenFits, this, sub.runNumber);//Out()); … … 2588 2620 int main(int argc, const char* argv[]) 2589 2621 { 2590 2591 float salut1 = 1.0f/0.0f;2592 if (salut1 != salut1)2593 cout << "NaN !";2594 else2595 cout << "regular number";2596 2597 2622 Configuration conf(argv[0]); 2598 2623 conf.SetPrintUsage(PrintUsage);
Note:
See TracChangeset
for help on using the changeset viewer.