Changeset 10829


Ignore:
Timestamp:
05/26/11 15:47:05 (13 years ago)
Author:
lyard
Message:
Moved many things to functions
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/FACT++/src/dataLogger.cc

    r10825 r10829  
    125125#endif
    126126        runNumber = -1;
     127        //give it a meaningless, 0 time to distinguish with actual, valid times
    127128        time = Time(0,0);
    128129        numCopies = new int(1);
     
    453454    ///checks with fServiceList whether or not the services got updated
    454455    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);
    455480}; //DataLogger
    456481
     482// --------------------------------------------------------------------------
     483//
     484//!
     485//
     486bool 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//
     504string 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//
     529void 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//
     545DimStampedInfo* 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//
     561bool 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//
     583void 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//
     597void 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//
     621void 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//
     637void 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//
     651void 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//
     669void 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//
     687off_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}
    457702// --------------------------------------------------------------------------
    458703//
     
    532777        Message("FITS output disabled at compilation");
    533778#endif
    534     struct stat st;
    535779    //gather log and report files sizes on disk
    536780    if (fNightlyLogFile.is_open())
    537     {
    538         stat(fFullNightlyLogFileName.c_str(), &st);
    539         fFileSizesMap[fFullNightlyLogFileName] = st.st_size;
    540     }
     781        fFileSizesMap[fFullNightlyLogFileName] = GetFileSize(fFullNightlyLogFileName);
    541782    if (fNightlyReportFile.is_open())
    542     {
    543         stat(fFullNightlyReportFileName.c_str(), &st);
    544         fFileSizesMap[fFullNightlyReportFileName] = st.st_size;
    545     }
     783        fFileSizesMap[fFullNightlyReportFileName] = GetFileSize(fFullNightlyReportFileName);
    546784    for (list<RunNumberType>::iterator it = fRunNumber.begin(); it != fRunNumber.end(); it++)
    547785    {
    548786        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);
    553788        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);
    558790    }
    559791    struct statvfs vfs;
     
    8311063        //skip the two de-fact excluded services
    8321064        //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.
    8331066        if ((i->find("DIS_DNS") != string::npos) ||
    8341067            (i->find("DATA_LOGGER") != string::npos))
     
    8401073        if (cSubs != fServiceSubscriptions.end())//if the current server already is in our subscriptions
    8411074        {                                         //then check and update our list of subscriptions
    842             //first, remove the services that may have dissapeared.
     1075            //first, remove the services that may have disapeared.
    8431076            map<string, SubscriptionType>::iterator serverSubs;
    8441077            vector<string>::const_iterator givenSubs;
     
    8601093            for (givenSubs = cServicesList.begin(); givenSubs != cServicesList.end(); givenSubs++)
    8611094            {
    862                 if (*givenSubs == "SERVICE_LIST")
     1095                if (!ShouldSubscribe(*i, *givenSubs))
    8631096                    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 
    8741097                if (cSubs->second.find(*givenSubs) == cSubs->second.end())
    8751098                {//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);
    8771100                    serviceUpdated = true;
    878                     if(fDebugIsOn)
    879                     {
    880                         ostringstream str;
    881                         str << "Subscribing to service " << *i << "/" << *givenSubs;
    882                         Debug(str);
    883                     }
    8841101                }   
    8851102            }
     
    8911108            for (vector<string>::const_iterator j = cServicesList.begin(); j!= cServicesList.end(); j++)
    8921109            {
    893                 if (*j == "SERVICE_LIST")
     1110                if (!ShouldSubscribe(*i, *j))
    8941111                    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);
    9051113                serviceUpdated = true;
    906                 if(fDebugIsOn)
    907                 {
    908                     ostringstream str;
    909                     str << "Subscribing to service " << *i << "/" << *j;
    910                     Debug(str);
    911                 }
    9121114            }
    9131115        }   
     
    9341136
    9351137    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)
    9421139     while (fRunNumber.size() > 0)
    9431140     {
     
    10261223int DataLogger::OpenRunFile(RunNumberType& run)
    10271224{
    1028     ostringstream sRun;
    1029     sRun << run.runNumber;
    1030     run.logName = fRunFilePath + '/' + sRun.str() + ".log";
    10311225    if (run.logFile->is_open())
    10321226    {
     
    10361230        return -1;
    10371231    }
    1038 
     1232    FormRunTextFileName(run.logName, false, run.runNumber);
    10391233    run.logFile->open(run.logName.c_str(), ios_base::out | ios_base::app);
    10401234    if (errno != 0)
     
    10451239    }
    10461240    //open report file
    1047     run.reportName = fRunFilePath + '/' + sRun.str() + ".rep";
     1241    FormRunTextFileName(run.reportName, true, run.runNumber);
    10481242    if (run.reportFile->is_open())
    10491243    {
     
    10691263    }
    10701264    //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);
    11201272    run.openedFits.clear();
    11211273    return 0;
     
    12731425        if (fNightlyReportFile.is_open())
    12741426        {
    1275             if (fDebugIsOn)
    1276             {
    1277                 ostringstream str;
    1278                 str << "Writing: \"" << header.str() << text << "\" to Nightly report file";
    1279                 Debug(str);
    1280             }
    12811427            fNightlyReportFile << header.str() << text << endl;
    12821428            //check if either eof, bailbit or batbit are set
     
    12911437        if (targetRunFile && targetRunFile->is_open())
    12921438        {
    1293             if (fDebugIsOn)
    1294             {
    1295                 ostringstream str;
    1296                 str << "Writing: \"" << header.str() << text << "\" to Run report file";
    1297                 Debug(str);
    1298             }
    12991439            *targetRunFile << header.str() << text << endl;
    13001440            if (!targetRunFile->good())
     
    13141454        if (fNightlyLogFile.is_open())
    13151455        {
    1316             if (fDebugIsOn)
    1317             {
    1318                 ostringstream str;
    1319                 str << "Writing: \"" << msg.str() << "\" to Nightly log file";
    1320                 Debug(str);
    1321             }
    13221456            MessageImp nightlyMess(fNightlyLogFile);
    13231457            nightlyMess.Write(cTime, msg.str().c_str(), fQuality);
     
    13311465        if (targetRunFile && targetRunFile->is_open())
    13321466        {
    1333             if (fDebugIsOn)
    1334             {
    1335                 ostringstream str;
    1336                 str << "Writing: \"" << msg.str() << "\" to Run log file";
    1337                 Debug(str);
    1338             }
    13391467            MessageImp runMess(*targetRunFile);
    13401468            runMess.Write(cTime, msg.str().c_str(), fQuality);
     
    14711599    Message("-----------------------------------------");
    14721600    //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
    14921605    ostringstream str;
    1493     str << "Active Run Numbers: ";//<< fRunNumber;
     1606    str << "Active Run Numbers: ";
    14941607    for (list<RunNumberType>::iterator it=fRunNumber.begin(); it!=fRunNumber.end(); it++)
    14951608        str << "\n" << it->runNumber;
     
    16101723        return GetCurrentState();   
    16111724    }
    1612     if (fStatsPeriodDuration != fStatsPeriodDuration)
     1725    if (!finite(fStatsPeriodDuration))// != fStatsPeriodDuration)
    16131726    {
    16141727        Error("Provided duration does not appear to be a valid float. discarding it.");
     
    17721885        Debug("Starting...");   
    17731886    }
    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);
    17941893
    17951894    if (!fNightlyLogFile.is_open() || !fNightlyReportFile.is_open())
     
    18011900    }
    18021901    //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);
    18081904    fFileSizesMap.clear();
    18091905    fBaseSizeRun = 0;
    18101906    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
    18311908    //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);
    18331913
    18341914    fOpenedNightlyFits.clear();
     
    18501930     {
    18511931         if (fDebugIsOn)
    1852          {
    18531932             Debug("Run number changed. Closing " + sub.runFile.fFileName);
    1854          }
    18551933         sub.runFile.Close();
    18561934     }
     
    18771955        }   
    18781956    }
    1879     Time time;
    1880     ostringstream sTime;
    1881     sTime << time.Y() << "_" << time.M() << "_" << time.D();
    18821957    //we open the NightlyFile anyway, otherwise this function shouldn't have been called.
    18831958    if (!sub.nightlyFile.IsOpen())
    18841959    {
    1885         string fileNameOnly = sTime.str() + '_' + serviceName + ".fits";
    1886         string partialName = fNightlyFilePath + '/' + fileNameOnly;
     1960        string fileNameOnly, partialName;
     1961        FormNightlyFitsFileName(fileNameOnly, partialName, serviceName);
    18871962        AllocateFITSBuffers(sub);
    18881963        //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)
    18961965            fOpenedNightlyFits[fileNameOnly].push_back(serviceName);
    1897         }
     1966
    18981967        sub.nightlyFile.Open(partialName, serviceName, NULL, &fNumSubAndFitsData.numOpenFits, this, -1);//Out());
    18991968
    19001969        //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);
    19131974        if (fNumSubAndFitsIsOn)
    19141975            fNumSubAndFits->updateService();
     
    19201981        }
    19211982    }
    1922     //to the actual file open
     1983    //do the actual file open
    19231984    if (!sub.runFile.IsOpen() && (GetCurrentState() == kSM_Logging) && sub.runNumber != -1)
    19241985    {//buffer for the run file have already been allocated when doing the Nightly file
    1925         ostringstream sRun;
    1926         sRun << sub.runNumber;
    19271986        string fileNameOnly;
    19281987        string partialName;
     
    19301989        if (hasGrouping)
    19311990        {
    1932             fileNameOnly = sRun.str() + "_group.fits";
    1933             partialName = fRunFilePath + '/' + fileNameOnly;
     1991            FormGroupedRunFitsFileName(fileNameOnly, partialName, sub.runNumber);
    19341992        }
    19351993        else
    19361994        {
    1937             fileNameOnly = sRun.str() + '_' + serviceName + ".fits";
    1938             partialName = fRunFilePath + '/' + fileNameOnly;
     1995            FormRunFitsFileName(fileNameOnly, partialName, serviceName, sub.runNumber);
    19391996        }
    19401997        //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)
    19491999            cRunNumber->openedFits[fileNameOnly].push_back(serviceName);
    1950         }
    19512000        else
    19522001            if (hasGrouping)
     
    19792028            }
    19802029
    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);
    19932033        if (hasGrouping)
    19942034            sub.runFile.Open(partialName, serviceName, cRunNumber->runFitsFile, &fNumSubAndFitsData.numOpenFits, this, sub.runNumber);//Out());
     
    21692209        return;
    21702210    }
    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);
    21842213    CCfits::Table* groupTable;
    21852214    int maxCharLength = 50;//FILENAME_MAX;
    21862215    try
    21872216    {
    2188         groupFile = new CCfits::FITS(groupName.str(), CCfits::RWmode::Write);
     2217        groupFile = new CCfits::FITS(groupName, CCfits::RWmode::Write);
    21892218        //setup the column names
    21902219        ostringstream pathTypeName;
     
    22072236     {
    22082237         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();
    22102239         Error(str);
    22112240         return;
     
    23742403                Debug("                   " + *it);
    23752404        }
     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/");
    23762409    }
    23772410    if (conf.Has("allow"))
     
    25552588int main(int argc, const char* argv[])
    25562589{
     2590
     2591    float salut1 = 1.0f/0.0f;
     2592    if (salut1 != salut1)
     2593        cout << "NaN !";
     2594        else
     2595            cout << "regular number";
     2596
    25572597    Configuration conf(argv[0]);
    25582598    conf.SetPrintUsage(PrintUsage);
Note: See TracChangeset for help on using the changeset viewer.