Changeset 10829
- Timestamp:
- 05/26/11 15:47:05 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/dataLogger.cc
r10825 r10829 125 125 #endif 126 126 runNumber = -1; 127 //give it a meaningless, 0 time to distinguish with actual, valid times 127 128 time = Time(0,0); 128 129 numCopies = new int(1); … … 453 454 ///checks with fServiceList whether or not the services got updated 454 455 bool CheckForServicesUpdate(); 456 ///retrieves the size of a file 457 off_t GetFileSize(string&); 458 ///Form the name of the nightly text files (logs and reports) 459 void FormNightlyTextFileName(string& name, bool isReport); 460 ///Form the name of the run text files (logs and reports) 461 void FormRunTextFileName(string& name, bool isReport, const int runNumber); 462 ///Form the name of the nightly Fits files 463 void FormNightlyFitsFileName(string& fileName, string& fileNameWithPath, const string& serviceName); 464 ///Form the name of the run Fits files 465 void FormRunFitsFileName(string& fileName, string& fileNameWithPath, const string& serviceName, const int runNumber); 466 ///Form the name of the grouped fits file (i.e. the file where several services are written) 467 void FormGroupedRunFitsFileName(string& fileName, string& fileNameWithPath, const int runNumber); 468 ///Form the name of the grouping fits file (i.e. the file that is created after a run ends) 469 void FormFitsGroupingFileName(string& fileNameWithPath, const int runNumber); 470 ///Check whether service is in black and/or white list 471 bool ShouldSubscribe(const string& server, const string& service); 472 ///Subscribe to a given server and service 473 DimStampedInfo* SubscribeToPlease(const string& server, const string& service); 474 ///Open a text file and checks for ofstream status 475 void OpenTextFilePlease(ofstream& stream, const string& name); 476 ///Check if a dir is . and returns the actual string corresponding to . 477 string CheckIfDirIsDot(const string& dir); 478 ///Remembers the size of newly opened files. for statistic purposes 479 bool RememberFileOrigSizePlease(string& fileName, bool nightly); 455 480 }; //DataLogger 456 481 482 // -------------------------------------------------------------------------- 483 // 484 //! 485 // 486 bool DataLogger::RememberFileOrigSizePlease(string& fileName, bool nightly) 487 { 488 //get the size of the file we're about to open 489 if (fFileSizesMap.find(fileName) == fFileSizesMap.end()) 490 { 491 if (nightly) 492 fBaseSizeNightly += GetFileSize(fileName); 493 else 494 fBaseSizeRun += GetFileSize(fileName); 495 fFileSizesMap[fileName] = 0; 496 return true; 497 } 498 return false; 499 } 500 // -------------------------------------------------------------------------- 501 // 502 //! 503 // 504 string DataLogger::CheckIfDirIsDot(const string& dir) 505 { 506 if (dir == ".") 507 { 508 char currentPath[FILENAME_MAX]; 509 if (!getcwd(currentPath, sizeof(currentPath))) 510 { 511 if (errno != 0) 512 { 513 ostringstream str; 514 str << "Unable to retrieve the current path" << ". Reason: " << strerror(errno) << " [" << errno << "]"; 515 Error(str); 516 } 517 } 518 return string(currentPath); 519 } 520 else 521 { 522 return string(dir); 523 } 524 } 525 // -------------------------------------------------------------------------- 526 // 527 //! 528 // 529 void DataLogger::OpenTextFilePlease(ofstream& stream, const string& name) 530 { 531 stream.open(name.c_str(), ios_base::out | ios_base::app); 532 if (errno != 0) 533 { 534 ostringstream str; 535 str << "Unable to open file: " << name << ". Reason: " << strerror(errno) << " [" << errno << "]"; 536 Error(str); 537 } 538 } 539 // -------------------------------------------------------------------------- 540 // 541 //! Create a new dim subscription to a given server and service 542 //! @param server the server name 543 //! @param service the service name 544 // 545 DimStampedInfo* DataLogger::SubscribeToPlease(const string& server, const string& service) 546 { 547 if (fDebugIsOn) 548 { 549 ostringstream str; 550 str << "Subscribing to service " << server << "/" << service; 551 Debug(str); 552 } 553 return new DimStampedInfo((server + "/" + service).c_str(), const_cast<char*>(""), this); 554 } 555 // -------------------------------------------------------------------------- 556 // 557 //! Check whether a service should be subscribed to, based on the black/white list entries 558 //! @param server the server name associated with the service being checked 559 //! @param service the service name associated with the service being checked 560 // 561 bool DataLogger::ShouldSubscribe(const string& server, const string& service) 562 { 563 if (service == "SERVICE_LIST") 564 return false; 565 if (fHasWhiteList && (fWhiteList.find(server + "/") == fWhiteList.end()) && 566 (fWhiteList.find(server + "/" + service) == fWhiteList.end()) && 567 (fWhiteList.find("/" + service) == fWhiteList.end())) 568 return false; 569 if (fHasBlackList && ((fBlackList.find(server + "/") != fBlackList.end()) || 570 (fBlackList.find(server + "/" + service) != fBlackList.end()) || 571 (fBlackList.find("/" + service) != fBlackList.end()))) 572 return false; 573 574 return true; 575 } 576 // -------------------------------------------------------------------------- 577 // 578 //!Form the name of the grouped fits file (i.e. the file where several services are written) 579 //! @param fileName only the file name itself (no path) 580 //! @param fileNameWithPath fileName, augmented with the prefix path 581 //! @param runNumber the current run number for which the file should be opened. 582 // 583 void DataLogger::FormGroupedRunFitsFileName(string& fileName, string& fileNameWithPath, const int runNumber) 584 { 585 ostringstream sRun; 586 sRun << runNumber; 587 fileName = sRun.str() + "_group.fits"; 588 fileNameWithPath = fRunFilePath + '/' + fileName; 589 } 590 // -------------------------------------------------------------------------- 591 // 592 //! Form the name of the grouping fits file (i.e. the file that is created after a run ends) 593 //! This file is meant to link the various fits files related to a particular run from a single file 594 //! @param fileNameWithPath the full filename 595 //! @param runNumber the current run number for which the file should be opened. -1 means nightly grouping 596 // 597 void DataLogger::FormFitsGroupingFileName(string& fileNameWithPath, const int runNumber) 598 { 599 ostringstream groupName; 600 if (runNumber != -1) 601 { 602 groupName << fRunFilePath << '/' << runNumber << ".fits"; 603 } 604 else 605 { 606 Time time; 607 ostringstream sTime; 608 sTime << time.Y() << "_" << time.M() << "_" << time.D(); 609 groupName << fNightlyFilePath << '/' << sTime.str() << ".fits"; 610 } 611 fileNameWithPath = groupName.str(); 612 613 } 614 // -------------------------------------------------------------------------- 615 // 616 //! Form the name of the nightly Fits files 617 //! @param fileName the file name only 618 //! @param fileNameWithPath the fileName augmented by the prefix path 619 //! @param serviceName the service for which this file should be opened 620 // 621 void DataLogger::FormNightlyFitsFileName(string& fileName, string& fileNameWithPath, const string& serviceName) 622 { 623 Time time; 624 ostringstream sTime; 625 sTime << time.Y() << "_" << time.M() << "_" << time.D(); 626 fileName = sTime.str() + '_' + serviceName + ".fits"; 627 fileNameWithPath = fNightlyFilePath + '/' + fileName; 628 } 629 // -------------------------------------------------------------------------- 630 // 631 //! Form the name of the run Fits files 632 //! @param fileName the file name only 633 //! @param fileNameWithPath the fileName augmented by the prefix path 634 //! @param serviceName the service for which this file should be opened 635 //! @param runNumber the current run number for which this file should be opened 636 // 637 void DataLogger::FormRunFitsFileName(string& fileName, string& fileNameWithPath, const string& serviceName, const int runNumber) 638 { 639 ostringstream sRun; 640 sRun << runNumber; 641 fileName = sRun.str() + '_' + serviceName + ".fits"; 642 fileNameWithPath = fRunFilePath + '/' + fileName; 643 } 644 // -------------------------------------------------------------------------- 645 // 646 //! Form the name of the run text files (logs and reports) 647 //! @param name the full file name 648 //! @param isReport whether a log or report name should be formed 649 //! @param runNumber the current run number for which this file should be opened 650 // 651 void DataLogger::FormRunTextFileName(string& name, bool isReport, const int runNumber) 652 { 653 ostringstream sRun; 654 sRun << runNumber; 655 656 name = fRunFilePath + '/' + sRun.str(); 657 658 if (isReport) 659 name += ".rep"; 660 else 661 name += ".log"; 662 } 663 // -------------------------------------------------------------------------- 664 // 665 //! Form the name of the nightly text files (logs and reports) 666 //! @param name the full file name 667 //! @param isReport whether a log or report name should be formed 668 // 669 void DataLogger::FormNightlyTextFileName(string& name, bool isReport) 670 { 671 Time time; 672 ostringstream sTime; 673 sTime << time.Y() << "_" << time.M() << "_" << time.D(); 674 675 name = fNightlyFilePath + '/' + sTime.str(); 676 if (isReport) 677 name += ".rep"; 678 else 679 name += ".log"; 680 } 681 // -------------------------------------------------------------------------- 682 // 683 //!retrieves the size on disk of a file 684 //! @param fileName the full file name for which the size on disk should be retrieved 685 //! @return the size of the file on disk, in bytes. 0 if the file does not exist or if an error occured 686 // 687 off_t DataLogger::GetFileSize(string& fileName) 688 { 689 struct stat st; 690 if (!stat(fileName.c_str(), &st)) 691 return st.st_size; 692 693 if (errno != 0) 694 { 695 ostringstream str; 696 str << "Unable to stat " << fileName << ". Reason: " << strerror(errno) << " [" << errno << "]"; 697 Error(str); 698 } 699 700 return 0; 701 } 457 702 // -------------------------------------------------------------------------- 458 703 // … … 532 777 Message("FITS output disabled at compilation"); 533 778 #endif 534 struct stat st;535 779 //gather log and report files sizes on disk 536 780 if (fNightlyLogFile.is_open()) 537 { 538 stat(fFullNightlyLogFileName.c_str(), &st); 539 fFileSizesMap[fFullNightlyLogFileName] = st.st_size; 540 } 781 fFileSizesMap[fFullNightlyLogFileName] = GetFileSize(fFullNightlyLogFileName); 541 782 if (fNightlyReportFile.is_open()) 542 { 543 stat(fFullNightlyReportFileName.c_str(), &st); 544 fFileSizesMap[fFullNightlyReportFileName] = st.st_size; 545 } 783 fFileSizesMap[fFullNightlyReportFileName] = GetFileSize(fFullNightlyReportFileName); 546 784 for (list<RunNumberType>::iterator it = fRunNumber.begin(); it != fRunNumber.end(); it++) 547 785 { 548 786 if (it->reportFile->is_open()) 549 { 550 stat(it->reportName.c_str(), &st); 551 fFileSizesMap[it->reportName] = st.st_size; 552 } 787 fFileSizesMap[it->reportName] = GetFileSize(it->reportName); 553 788 if (it->logFile->is_open()) 554 { 555 stat(it->logName.c_str(), &st); 556 fFileSizesMap[it->logName] = st.st_size; 557 } 789 fFileSizesMap[it->logName] = GetFileSize(it->logName); 558 790 } 559 791 struct statvfs vfs; … … 831 1063 //skip the two de-fact excluded services 832 1064 //Dim crashes if the publisher subscribes to its own service. This sounds weird, I agree. 1065 //I agree: hard coded values are bad, but in this case these two entries should always be here otherwise Dim crashes. 833 1066 if ((i->find("DIS_DNS") != string::npos) || 834 1067 (i->find("DATA_LOGGER") != string::npos)) … … 840 1073 if (cSubs != fServiceSubscriptions.end())//if the current server already is in our subscriptions 841 1074 { //then check and update our list of subscriptions 842 //first, remove the services that may have dis sapeared.1075 //first, remove the services that may have disapeared. 843 1076 map<string, SubscriptionType>::iterator serverSubs; 844 1077 vector<string>::const_iterator givenSubs; … … 860 1093 for (givenSubs = cServicesList.begin(); givenSubs != cServicesList.end(); givenSubs++) 861 1094 { 862 if ( *givenSubs == "SERVICE_LIST")1095 if (!ShouldSubscribe(*i, *givenSubs)) 863 1096 continue; 864 865 if (fHasWhiteList && (fWhiteList.find(*i + "/") == fWhiteList.end()) &&866 (fWhiteList.find(*i + "/" + *givenSubs) == fWhiteList.end()) &&867 (fWhiteList.find("/" + *givenSubs) == fWhiteList.end()))868 continue;869 if (fHasBlackList && ((fBlackList.find(*i + "/") != fBlackList.end()) ||870 (fBlackList.find(*i + "/" + *givenSubs) != fBlackList.end()) ||871 (fBlackList.find("/" + *givenSubs) != fBlackList.end())))872 continue;873 874 1097 if (cSubs->second.find(*givenSubs) == cSubs->second.end()) 875 1098 {//service not found. Add it 876 cSubs->second[*givenSubs].dimInfo = new DimStampedInfo(((*i) + "/" + *givenSubs).c_str(), const_cast<char*>(""), this);1099 cSubs->second[*givenSubs].dimInfo = SubscribeToPlease(*i, *givenSubs); 877 1100 serviceUpdated = true; 878 if(fDebugIsOn)879 {880 ostringstream str;881 str << "Subscribing to service " << *i << "/" << *givenSubs;882 Debug(str);883 }884 1101 } 885 1102 } … … 891 1108 for (vector<string>::const_iterator j = cServicesList.begin(); j!= cServicesList.end(); j++) 892 1109 { 893 if ( *j == "SERVICE_LIST")1110 if (!ShouldSubscribe(*i, *j)) 894 1111 continue; 895 if (fHasWhiteList && (fWhiteList.find(*i + "/") == fWhiteList.end()) && 896 (fWhiteList.find(*i + "/" + *j) == fWhiteList.end()) && 897 (fWhiteList.find("/" + *j) == fWhiteList.end())) 898 continue; 899 if (fHasBlackList && ((fBlackList.find(*i + "/") != fBlackList.end()) || 900 (fBlackList.find(*i + "/" + *j) != fBlackList.end()) || 901 (fBlackList.find("/" + *j) != fBlackList.end()))) 902 continue; 903 904 liste[*j].dimInfo = new DimStampedInfo(((*i) + "/" + (*j)).c_str(), const_cast<char*>(""), this); 1112 liste[*j].dimInfo = SubscribeToPlease(*i, *j); 905 1113 serviceUpdated = true; 906 if(fDebugIsOn)907 {908 ostringstream str;909 str << "Subscribing to service " << *i << "/" << *j;910 Debug(str);911 }912 1114 } 913 1115 } … … 934 1136 935 1137 fMonitoringThread.join(); 936 //close the files 937 if (fNightlyLogFile.is_open()) 938 fNightlyLogFile.close(); 939 if (fNightlyReportFile.is_open()) 940 fNightlyReportFile.close(); 941 //check if some run number entries can be deleted 1138 //clear any remaining run number (should remain only one) 942 1139 while (fRunNumber.size() > 0) 943 1140 { … … 1026 1223 int DataLogger::OpenRunFile(RunNumberType& run) 1027 1224 { 1028 ostringstream sRun;1029 sRun << run.runNumber;1030 run.logName = fRunFilePath + '/' + sRun.str() + ".log";1031 1225 if (run.logFile->is_open()) 1032 1226 { … … 1036 1230 return -1; 1037 1231 } 1038 1232 FormRunTextFileName(run.logName, false, run.runNumber); 1039 1233 run.logFile->open(run.logName.c_str(), ios_base::out | ios_base::app); 1040 1234 if (errno != 0) … … 1045 1239 } 1046 1240 //open report file 1047 run.reportName = fRunFilePath + '/' + sRun.str() + ".rep";1241 FormRunTextFileName(run.reportName, true, run.runNumber); 1048 1242 if (run.reportFile->is_open()) 1049 1243 { … … 1069 1263 } 1070 1264 //get the size of the newly opened file. 1071 struct stat st; 1072 fBaseSizeRun = 0; 1073 if (fFileSizesMap.find(run.logName) == fFileSizesMap.end()) 1074 { 1075 stat(run.logName.c_str(), &st); 1076 if (errno != 0) 1077 { 1078 ostringstream str; 1079 str << "Unable to stat " << run.logName << ". Reason: " << strerror(errno) << " [" << errno << "]"; 1080 Error(str); 1081 } 1082 else 1083 fBaseSizeRun += st.st_size; 1084 fFileSizesMap[run.logName] = 0; 1085 } 1086 if (fFileSizesMap.find(run.reportName) == fFileSizesMap.end()) 1087 { 1088 stat(run.reportName.c_str(), &st); 1089 if (errno != 0) 1090 { 1091 ostringstream str; 1092 str << "Unable to stat " << run.reportName << ". Reason: " << strerror(errno) << " [" << errno << "]"; 1093 Error(str); 1094 } 1095 else 1096 fBaseSizeRun += st.st_size; 1097 fFileSizesMap[run.reportName] = 0; 1098 } 1099 string actualTargetDir; 1100 if (fRunFilePath == ".") 1101 { 1102 char currentPath[FILENAME_MAX]; 1103 if (!getcwd(currentPath, sizeof(currentPath))) 1104 { 1105 if (errno != 0) 1106 { 1107 ostringstream str; 1108 str << "Unable to retrieve the current path" << ". Reason: " << strerror(errno) << " [" << errno << "]"; 1109 Error(str); 1110 } 1111 } 1112 actualTargetDir = currentPath; 1113 } 1114 else 1115 { 1116 actualTargetDir = fRunFilePath; 1117 } 1118 //TODO this notification scheme might be messed up now.... fix it ! 1119 NotifyOpenedFile(actualTargetDir + '/' + sRun.str(), 3, fOpenedRunFiles); 1265 RememberFileOrigSizePlease(run.logName, false); 1266 RememberFileOrigSizePlease(run.reportName, false); 1267 1268 //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); 1120 1272 run.openedFits.clear(); 1121 1273 return 0; … … 1273 1425 if (fNightlyReportFile.is_open()) 1274 1426 { 1275 if (fDebugIsOn)1276 {1277 ostringstream str;1278 str << "Writing: \"" << header.str() << text << "\" to Nightly report file";1279 Debug(str);1280 }1281 1427 fNightlyReportFile << header.str() << text << endl; 1282 1428 //check if either eof, bailbit or batbit are set … … 1291 1437 if (targetRunFile && targetRunFile->is_open()) 1292 1438 { 1293 if (fDebugIsOn)1294 {1295 ostringstream str;1296 str << "Writing: \"" << header.str() << text << "\" to Run report file";1297 Debug(str);1298 }1299 1439 *targetRunFile << header.str() << text << endl; 1300 1440 if (!targetRunFile->good()) … … 1314 1454 if (fNightlyLogFile.is_open()) 1315 1455 { 1316 if (fDebugIsOn)1317 {1318 ostringstream str;1319 str << "Writing: \"" << msg.str() << "\" to Nightly log file";1320 Debug(str);1321 }1322 1456 MessageImp nightlyMess(fNightlyLogFile); 1323 1457 nightlyMess.Write(cTime, msg.str().c_str(), fQuality); … … 1331 1465 if (targetRunFile && targetRunFile->is_open()) 1332 1466 { 1333 if (fDebugIsOn)1334 {1335 ostringstream str;1336 str << "Writing: \"" << msg.str() << "\" to Run log file";1337 Debug(str);1338 }1339 1467 MessageImp runMess(*targetRunFile); 1340 1468 runMess.Write(cTime, msg.str().c_str(), fQuality); … … 1471 1599 Message("-----------------------------------------"); 1472 1600 //print the path configuration 1473 string actualTargetDir; 1474 if (fNightlyFilePath == ".") 1475 { 1476 char currentPath[FILENAME_MAX]; 1477 if (getcwd(currentPath, sizeof(currentPath))) 1478 actualTargetDir = currentPath; 1479 } 1480 else 1481 actualTargetDir = fNightlyFilePath; 1482 Message("Nightly Path: " + actualTargetDir); 1483 if (fRunFilePath == ".") 1484 { 1485 char currentPath[FILENAME_MAX]; 1486 if (getcwd(currentPath, sizeof(currentPath))) 1487 actualTargetDir = currentPath; 1488 } 1489 else 1490 actualTargetDir = fRunFilePath; 1491 Message("Run Path: " + actualTargetDir); 1601 Message("Nightly Path: " + CheckIfDirIsDot(fNightlyFilePath)); 1602 Message("Run Path: " + CheckIfDirIsDot(fRunFilePath)); 1603 1604 //print active run numbers 1492 1605 ostringstream str; 1493 str << "Active Run Numbers: "; //<< fRunNumber;1606 str << "Active Run Numbers: "; 1494 1607 for (list<RunNumberType>::iterator it=fRunNumber.begin(); it!=fRunNumber.end(); it++) 1495 1608 str << "\n" << it->runNumber; … … 1610 1723 return GetCurrentState(); 1611 1724 } 1612 if ( fStatsPeriodDuration!= fStatsPeriodDuration)1725 if (!finite(fStatsPeriodDuration))// != fStatsPeriodDuration) 1613 1726 { 1614 1727 Error("Provided duration does not appear to be a valid float. discarding it."); … … 1772 1885 Debug("Starting..."); 1773 1886 } 1774 Time time; 1775 ostringstream sTime; 1776 sTime << time.Y() << "_" << time.M() << "_" << time.D(); 1777 1778 fFullNightlyLogFileName = fNightlyFilePath + '/' + sTime.str() + ".log"; 1779 fNightlyLogFile.open(fFullNightlyLogFileName.c_str(), ios_base::out | ios_base::app); 1780 if (errno != 0) 1781 { 1782 ostringstream str; 1783 str << "Unable to open Nightly Log " << fFullNightlyLogFileName << ". Reason: " << strerror(errno) << " [" << errno << "]"; 1784 Error(str); 1785 } 1786 fFullNightlyReportFileName = fNightlyFilePath + '/' + sTime.str() + ".rep"; 1787 fNightlyReportFile.open(fFullNightlyReportFileName.c_str(), ios_base::out | ios_base::app); 1788 if (errno != 0) 1789 { 1790 ostringstream str; 1791 str << "Unable to open Nightly Report " << fFullNightlyReportFileName << ". Reason: " << strerror(errno) << " [" << errno << "]"; 1792 Error(str); 1793 } 1887 1888 FormNightlyTextFileName(fFullNightlyLogFileName, false); 1889 OpenTextFilePlease(fNightlyLogFile, fFullNightlyLogFileName); 1890 1891 FormNightlyTextFileName(fFullNightlyReportFileName, true); 1892 OpenTextFilePlease(fNightlyReportFile, fFullNightlyReportFileName); 1794 1893 1795 1894 if (!fNightlyLogFile.is_open() || !fNightlyReportFile.is_open()) … … 1801 1900 } 1802 1901 //get the size of the newly opened file. 1803 struct stat st; 1804 stat(fFullNightlyLogFileName.c_str(), &st); 1805 fBaseSizeNightly = st.st_size; 1806 stat(fFullNightlyReportFileName.c_str(), &st); 1807 fBaseSizeNightly += st.st_size; 1902 fBaseSizeNightly = GetFileSize(fFullNightlyLogFileName); 1903 fBaseSizeNightly += GetFileSize(fFullNightlyReportFileName); 1808 1904 fFileSizesMap.clear(); 1809 1905 fBaseSizeRun = 0; 1810 1906 fPreviousSize = 0; 1811 //notify that files were opened 1812 string actualTargetDir; 1813 if (fNightlyFilePath == ".") 1814 { 1815 char currentPath[FILENAME_MAX]; 1816 if (!getcwd(currentPath, sizeof(currentPath))) 1817 { 1818 if (errno != 0) 1819 { 1820 ostringstream str; 1821 str << "Unable retrieve current path" << ". Reason: " << strerror(errno) << " [" << errno << "]"; 1822 Error(str); 1823 } 1824 } 1825 actualTargetDir = currentPath; 1826 } 1827 else 1828 { 1829 actualTargetDir = fNightlyFilePath; 1830 } 1907 1831 1908 //notify that a new file has been opened. 1832 NotifyOpenedFile(actualTargetDir + '/' + sTime.str(), 3, fOpenedNightlyFiles); 1909 Time time; 1910 ostringstream sTime; 1911 sTime << time.Y() << "_" << time.M() << "_" << time.D(); 1912 NotifyOpenedFile(CheckIfDirIsDot(fNightlyFilePath) + '/' + sTime.str(), 3, fOpenedNightlyFiles); 1833 1913 1834 1914 fOpenedNightlyFits.clear(); … … 1850 1930 { 1851 1931 if (fDebugIsOn) 1852 {1853 1932 Debug("Run number changed. Closing " + sub.runFile.fFileName); 1854 }1855 1933 sub.runFile.Close(); 1856 1934 } … … 1877 1955 } 1878 1956 } 1879 Time time;1880 ostringstream sTime;1881 sTime << time.Y() << "_" << time.M() << "_" << time.D();1882 1957 //we open the NightlyFile anyway, otherwise this function shouldn't have been called. 1883 1958 if (!sub.nightlyFile.IsOpen()) 1884 1959 { 1885 string fileNameOnly = sTime.str() + '_' + serviceName + ".fits";1886 string partialName = fNightlyFilePath + '/' + fileNameOnly;1960 string fileNameOnly, partialName; 1961 FormNightlyFitsFileName(fileNameOnly, partialName, serviceName); 1887 1962 AllocateFITSBuffers(sub); 1888 1963 //get the size of the file we're about to open 1889 if (fFileSizesMap.find(partialName) == fFileSizesMap.end()) 1890 { 1891 struct stat st; 1892 if (!stat(partialName.c_str(), &st)) 1893 fBaseSizeNightly += st.st_size; 1894 fFileSizesMap[partialName] = 0; 1895 //remember that this file was opened. 1964 if (RememberFileOrigSizePlease(partialName, true))//and remember that the file was opened (i.e. not an update) 1896 1965 fOpenedNightlyFits[fileNameOnly].push_back(serviceName); 1897 } 1966 1898 1967 sub.nightlyFile.Open(partialName, serviceName, NULL, &fNumSubAndFitsData.numOpenFits, this, -1);//Out()); 1899 1968 1900 1969 //notify the opening 1901 string actualTargetDir; 1902 if (fNightlyFilePath == ".") 1903 { 1904 char currentPath[FILENAME_MAX]; 1905 if (getcwd(currentPath, sizeof(currentPath))) 1906 actualTargetDir = currentPath; 1907 } 1908 else 1909 { 1910 actualTargetDir = fNightlyFilePath; 1911 } 1912 NotifyOpenedFile(actualTargetDir + '/' + sTime.str(), 7, fOpenedNightlyFiles); 1970 Time time; 1971 ostringstream sTime; 1972 sTime << time.Y() << "_" << time.M() << "_" << time.D(); 1973 NotifyOpenedFile(CheckIfDirIsDot(fNightlyFilePath) + '/' + sTime.str(), 7, fOpenedNightlyFiles); 1913 1974 if (fNumSubAndFitsIsOn) 1914 1975 fNumSubAndFits->updateService(); … … 1920 1981 } 1921 1982 } 1922 // to the actual file open1983 //do the actual file open 1923 1984 if (!sub.runFile.IsOpen() && (GetCurrentState() == kSM_Logging) && sub.runNumber != -1) 1924 1985 {//buffer for the run file have already been allocated when doing the Nightly file 1925 ostringstream sRun;1926 sRun << sub.runNumber;1927 1986 string fileNameOnly; 1928 1987 string partialName; … … 1930 1989 if (hasGrouping) 1931 1990 { 1932 fileNameOnly = sRun.str() + "_group.fits"; 1933 partialName = fRunFilePath + '/' + fileNameOnly; 1991 FormGroupedRunFitsFileName(fileNameOnly, partialName, sub.runNumber); 1934 1992 } 1935 1993 else 1936 1994 { 1937 fileNameOnly = sRun.str() + '_' + serviceName + ".fits"; 1938 partialName = fRunFilePath + '/' + fileNameOnly; 1995 FormRunFitsFileName(fileNameOnly, partialName, serviceName, sub.runNumber); 1939 1996 } 1940 1997 //get the size of the file we're about to open 1941 if (fFileSizesMap.find(partialName) == fFileSizesMap.end()) 1942 { 1943 struct stat st; 1944 if (!stat(partialName.c_str(), &st)) 1945 fBaseSizeRun += st.st_size; 1946 else 1947 fBaseSizeRun = 0; 1948 fFileSizesMap[partialName] = 0; 1998 if (RememberFileOrigSizePlease(partialName, false))//and remember that the file was opened (i.e. not an update) 1949 1999 cRunNumber->openedFits[fileNameOnly].push_back(serviceName); 1950 }1951 2000 else 1952 2001 if (hasGrouping) … … 1979 2028 } 1980 2029 1981 string actualTargetDir; 1982 if (fRunFilePath == ".") 1983 { 1984 char currentPath[FILENAME_MAX]; 1985 if (getcwd(currentPath, sizeof(currentPath))) 1986 actualTargetDir = currentPath; 1987 } 1988 else 1989 { 1990 actualTargetDir = fRunFilePath; 1991 } 1992 NotifyOpenedFile(actualTargetDir + '/' + sRun.str(), 7, fOpenedRunFiles);// + '_' + serviceName, 4); 2030 ostringstream sRun; 2031 sRun << sub.runNumber; 2032 NotifyOpenedFile(CheckIfDirIsDot(fRunFilePath) + '/' + sRun.str(), 7, fOpenedRunFiles);// + '_' + serviceName, 4); 1993 2033 if (hasGrouping) 1994 2034 sub.runFile.Open(partialName, serviceName, cRunNumber->runFitsFile, &fNumSubAndFitsData.numOpenFits, this, sub.runNumber);//Out()); … … 2169 2209 return; 2170 2210 } 2171 ostringstream groupName; 2172 if (runNumber != -1) 2173 { 2174 groupName << fRunFilePath << '/' << runNumber << ".fits"; 2175 } 2176 else 2177 { 2178 Time time; 2179 ostringstream sTime; 2180 sTime << time.Y() << "_" << time.M() << "_" << time.D(); 2181 2182 groupName << fNightlyFilePath << '/' << sTime.str() << ".fits"; 2183 } 2211 string groupName; 2212 FormFitsGroupingFileName(groupName, runNumber); 2184 2213 CCfits::Table* groupTable; 2185 2214 int maxCharLength = 50;//FILENAME_MAX; 2186 2215 try 2187 2216 { 2188 groupFile = new CCfits::FITS(groupName .str(), CCfits::RWmode::Write);2217 groupFile = new CCfits::FITS(groupName, CCfits::RWmode::Write); 2189 2218 //setup the column names 2190 2219 ostringstream pathTypeName; … … 2207 2236 { 2208 2237 ostringstream str; 2209 str << "Could not open or create FITS table GROUPING in file " << groupName .str()<< " reason: " << e.message();2238 str << "Could not open or create FITS table GROUPING in file " << groupName << " reason: " << e.message(); 2210 2239 Error(str); 2211 2240 return; … … 2374 2403 Debug(" " + *it); 2375 2404 } 2405 //Adding entries that should ALWAYS be ignored, because of Dim: otherwise the DataLogger would crash 2406 fBlackList.insert("DATA_LOGGER/"); 2407 fBlackList.insert("/SERVICE_LIST"); 2408 fBlackList.insert("DIS_DNS/"); 2376 2409 } 2377 2410 if (conf.Has("allow")) … … 2555 2588 int main(int argc, const char* argv[]) 2556 2589 { 2590 2591 float salut1 = 1.0f/0.0f; 2592 if (salut1 != salut1) 2593 cout << "NaN !"; 2594 else 2595 cout << "regular number"; 2596 2557 2597 Configuration conf(argv[0]); 2558 2598 conf.SetPrintUsage(PrintUsage);
Note:
See TracChangeset
for help on using the changeset viewer.