Changeset 10931


Ignore:
Timestamp:
06/08/11 18:28:04 (13 years ago)
Author:
tbretz
Message:
Moved the default black list entries out of the check for the --block option; commented the default for DATA_LOGGER/ it gives troubles; added many const-qualifiers; fixed a few typoes in some output; localized the scoping of some iterators
File:
1 edited

Legend:

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

    r10930 r10931  
    7777
    7878//Dim structures
    79 ///Distributes the writting statistics
     79///Distributes the writing statistics
    8080struct DataLoggerStats {
    8181    long sizeWritten;
     
    129129#endif
    130130        runNumber = 0;
    131         //give it a meaningless, 0 time to distinguish with actual, valid times
    132         time = Time(0,0);
    133131    }
    134132    ///default destructor
     
    138136    }
    139137    ///copy operator
     138    /*
    140139    void operator = (const RunNumberType& other)
    141140    {
     
    151150        runFitsFile = other.runFitsFile;
    152151#endif
    153     }
     152}*/
     153
    154154    ///copy constructor
    155155    RunNumberType(const RunNumberType& other)
     
    169169
    170170    void addServiceToOpenedFits(const string& fileName, const string& serviceName)
    171     {//most likely I should add this service name.
    172      //the only case for which I should not add it is if a service disapeared, hence the file was closed
    173      //and reopened again. Unlikely to happen, but well it may
    174         bool found = false;
    175         for (vector<string>::iterator it=openedFits[fileName].begin(); it!=openedFits[fileName].end(); it++)
    176             if (*it == serviceName)
    177             {
    178                 found = true;
    179                 break;
    180             }
    181         if (!found)
     171    {
     172         //most likely I should add this service name.
     173         //the only case for which I should not add it is if a service disapeared, hence the file was closed
     174         //and reopened again. Unlikely to happen, but well it may
     175
     176         if (find(openedFits[fileName].begin(), openedFits[fileName].end(),
     177                  serviceName)==openedFits[fileName].end())
    182178            openedFits[fileName].push_back(serviceName);
    183179    }
     
    203199    uint32_t runNumber;
    204200    ///copy operator
     201    /*
    205202    void operator = (const SubscriptionType& other)
    206203    {
     
    214211        fConv = other.fConv;
    215212        runNumber = other.runNumber;
    216     }
    217     ///copy constructor
     213        }*/
     214
     215/*    ///copy constructor
    218216    SubscriptionType(const SubscriptionType& other)
    219217    {
     
    227225        fConv = other.fConv;
    228226        runNumber = other.runNumber;
    229     }
     227    }*/
    230228    ///Dim info constructor
    231     SubscriptionType(DimStampedInfo* info)
     229    SubscriptionType(DimStampedInfo* info=NULL)
    232230    {
    233231        dimInfo = shared_ptr<DimStampedInfo>(info);
     
    236234    }
    237235    ///default constructor
    238     SubscriptionType()
     236/*    SubscriptionType()
    239237    {
    240238        dimInfo = shared_ptr<DimStampedInfo>();
    241239        fConv = shared_ptr<Converter>();
    242240        runNumber = 0;
    243     }
     241    }*/
    244242    ///default destructor
    245243    ~SubscriptionType()
     
    380378    NumSubAndFitsType fNumSubAndFitsData;
    381379    ///Small function for calculating the total size written so far
    382     void calculateTotalSizeWritten(DataLoggerStats& statVar, bool& shouldWarn, bool isPrinting);
     380    bool calculateTotalSizeWritten(DataLoggerStats& statVar, bool isPrinting);
    383381
    384382    /***************************************************
     
    417415    void RemoveOldestRunNumber();
    418416    ///retrieves the size of a file
    419     off_t GetFileSize(string&);
     417    off_t GetFileSize(const string&);
    420418    ///Get the digits of year, month and day for filenames and paths
    421419    void GetYearMonthDayForFiles(unsigned short& year, unsigned short& month, unsigned short& day);
     
    616614{
    617615    //get the size of the file we're about to open
    618     if (fFileSizesMap.find(fileName) == fFileSizesMap.end())
    619     {
    620         if (nightly)
    621             fBaseSizeNightly += GetFileSize(fileName);
    622         else
    623             fBaseSizeRun += GetFileSize(fileName);
    624         fFileSizesMap[fileName] = 0;
    625         return true;
    626     }
    627     return false;
     616    if (fFileSizesMap.find(fileName) != fFileSizesMap.end())
     617        return false;
     618
     619    if (nightly)
     620        fBaseSizeNightly += GetFileSize(fileName);
     621    else
     622        fBaseSizeRun += GetFileSize(fileName);
     623    fFileSizesMap[fileName] = 0;
     624    return true;
    628625}
    629626
     
    754751//! @return the size of the file on disk, in bytes. 0 if the file does not exist or if an error occured
    755752//
    756 off_t DataLogger::GetFileSize(string& fileName)
     753off_t DataLogger::GetFileSize(const string& fileName)
    757754{
    758755    errno = 0;
     
    784781    }
    785782    CreateFitsGrouping(fRunNumber.front().openedFits, fRunNumber.front().runNumber);
     783
    786784    //crawl through the subscriptions to see if there are still corresponding fits files opened.
    787     SubscriptionsListType::iterator x;
    788     map<string, SubscriptionType>::iterator y;
    789     for (x=fServiceSubscriptions.begin(); x != fServiceSubscriptions.end(); x++)
    790         for (y=x->second.begin(); y != x->second.end(); y++)
     785    for (SubscriptionsListType::iterator x=fServiceSubscriptions.begin();
     786         x!=fServiceSubscriptions.end(); x++)
     787        for (map<string, SubscriptionType>::iterator y=x->second.begin();
     788             y!=x->second.end(); y++)
    791789            if (y->second.runFile.fRunNumber == fRunNumber.front().runNumber && y->second.runFile.IsOpen())
    792790            {
     
    813811//! @param isPrinting whether this function was called from the PRINT command or not. If so, displays relevant information
    814812//
    815 void DataLogger::calculateTotalSizeWritten(DataLoggerStats& statVar, bool& shouldWarn, bool isPrinting)
     813bool DataLogger::calculateTotalSizeWritten(DataLoggerStats& statVar, bool isPrinting)
    816814{
    817815#ifdef HAVE_FITS
     
    822820        Message(str);
    823821    }
    824     SubscriptionsListType::iterator x;
    825     map<string, SubscriptionType>::iterator y;
    826 ///TODO the grouping file is dealt with several times. This should not be a problem but well, better to fix it I guess.
    827     for (x=fServiceSubscriptions.begin(); x != fServiceSubscriptions.end(); x++)
    828     {
    829         for (y=x->second.begin(); y != x->second.end(); y++)
     822
     823    ///TODO the grouping file is dealt with several times. This should not be a problem but well, better to fix it I guess.
     824    for (SubscriptionsListType::const_iterator x=fServiceSubscriptions.begin();
     825         x!=fServiceSubscriptions.end(); x++)
     826    {
     827        for (map<string, SubscriptionType>::const_iterator y=x->second.begin();
     828             y!=x->second.end(); y++)
    830829        {
    831830            if (y->second.runFile.IsOpen())
     
    861860#endif
    862861    }
     862
     863    bool shouldWarn = false;
    863864    struct statvfs vfs;
    864865    if (!statvfs(fNightlyFilePath.c_str(), &vfs))
    865     {
    866866        statVar.freeSpace = vfs.f_bsize*vfs.f_bavail;
    867         shouldWarn = false;
    868     }
    869867    else
    870868    {
     
    873871        if (!shouldWarn)
    874872            Error(str);
    875         shouldWarn = true;
    876873        statVar.freeSpace = -1;
    877874    }
    878875    //sum up all the file sizes. past and present
    879876    statVar.sizeWritten = 0;
    880     for (map<string, long>::iterator it=fFileSizesMap.begin(); it != fFileSizesMap.end();  it++)
     877    for (map<string, long>::const_iterator it=fFileSizesMap.begin(); it != fFileSizesMap.end();  it++)
    881878        statVar.sizeWritten += it->second;
    882879    statVar.sizeWritten -= fBaseSizeNightly;
    883880    statVar.sizeWritten -= fBaseSizeRun;
     881
     882    return shouldWarn;
    884883}
    885884//static members initialization
     
    922921        DimDescribedService srvc ("DATA_LOGGER/STATS", "X:3", statVar, "Add description here");
    923922        fPreviousSize = 0;
    924         bool statWarning = false;
     923        //bool statWarning = false;
    925924        bool resetDone = false;
    926925        //loop-wait for broadcast
     
    967966                sleep(fStatsPeriodDuration);
    968967            //update the fits files sizes
    969             calculateTotalSizeWritten(statVar, statWarning, false);
     968            /*statWarning =*/ calculateTotalSizeWritten(statVar, false);
    970969            if (fStatsPeriodDuration == 0.0f)
    971970                continue;
     
    979978                {
    980979                    ostringstream str;
    981                     str << "Size written: " << statVar.sizeWritten/1000 << " kB; writting rate: ";
     980                    str << "Size written: " << statVar.sizeWritten/1000 << " kB; writing rate: ";
    982981                    str << statVar.writingRate/1000 << " kB/s; free space: ";
    983982                    str << statVar.freeSpace/(1000*100) << " MB";
     
    10811080                               "|NumOpenFiles[int]:number of files currently open by the data logger");
    10821081
    1083      //black/white list
    1084      fBlackList.clear();
    1085      fWhiteList.clear();
    10861082     //services parameters
    10871083     fDebugIsOn = false;
     
    10941090             (boost::bind(&DataLogger::SetDebugOnOff, this, _1))
    10951091             ("Switch debug mode on off. Debug mode prints ifnormation about every service written to a file."
    1096               "|Enable[bool]:Enable of disable debuig mode (yes/no).");
     1092              "|Enable[bool]:Enable of disable debug mode (yes/no).");
    10971093
    10981094     AddEvent(fStatsPeriod, "F", kSM_NightlyOpen, kSM_Logging, kSM_WaitingRun, kSM_Ready)
     
    13671363    {
    13681364        list<RunNumberType>::reverse_iterator rit;
    1369         for (rit=fRunNumber.rbegin(); rit != fRunNumber.rend(); rit++)
     1365        for (rit=fRunNumber.rbegin(); rit!=fRunNumber.rend(); rit++)
    13701366        {
    13711367            if (rit->time < cTime) //this is the run number that we want to use
     
    14971493    ostringstream str;
    14981494    str << "Active Run Numbers:";
    1499     for (list<RunNumberType>::iterator it=fRunNumber.begin(); it!=fRunNumber.end(); it++)
     1495    for (list<RunNumberType>::const_iterator it=fRunNumber.begin(); it!=fRunNumber.end(); it++)
    15001496        str << " " << it->runNumber;
    15011497    if (fRunNumber.size()==0)
     
    15111507        Message("Nightly report-file: OPEN");
    15121508
    1513     for (list<RunNumberType>::iterator it=fRunNumber.begin(); it!=fRunNumber.end(); it++)
     1509    for (list<RunNumberType>::const_iterator it=fRunNumber.begin(); it!=fRunNumber.end(); it++)
    15141510    {
    15151511#ifdef RUN_LOGS
     
    15211517    }
    15221518
    1523     bool statWarning = false;
    15241519    DataLoggerStats statVar;
    1525     calculateTotalSizeWritten(statVar, statWarning, false);
     1520    /*const bool statWarning =*/ calculateTotalSizeWritten(statVar, false);
     1521
    15261522    Message("----------------- STATS ------------------");
    15271523    str.str("");
     
    15511547
    15521548    Message("--------------- BLOCK LIST ---------------");
    1553     for (set<string>::iterator it=fBlackList.begin(); it != fBlackList.end(); it++)
     1549    for (set<string>::const_iterator it=fBlackList.begin(); it != fBlackList.end(); it++)
    15541550        Message(" -> "+*it);
    15551551    if (fBlackList.size()==0)
     
    15571553
    15581554    Message("--------------- ALLOW LIST ---------------");
    1559     for (set<string>::iterator it=fWhiteList.begin(); it != fWhiteList.end(); it++)
     1555    for (set<string>::const_iterator it=fWhiteList.begin(); it != fWhiteList.end(); it++)
    15601556        Message(" -> "+*it);
    15611557    if (fWhiteList.size()==0)
     
    15651561    Message("The following servers and/or services will");
    15661562    Message("be grouped into a single fits file:");
    1567     for (set<string>::iterator it=fGrouping.begin(); it != fGrouping.end(); it++)
     1563    for (set<string>::const_iterator it=fGrouping.begin(); it != fGrouping.end(); it++)
    15681564        Message(" -> "+*it);
    15691565    if (fGrouping.size()==0)
     
    18411837    if (!sub.runFile.IsOpen() && (GetCurrentState() == kSM_Logging))
    18421838    {//will we find this service in the grouping list ?
    1843         for (set<string>::iterator it=fGrouping.begin(); it!=fGrouping.end(); it++)
     1839        for (set<string>::const_iterator it=fGrouping.begin(); it!=fGrouping.end(); it++)
    18441840        {
    18451841            if (serviceName.find(*it) != string::npos)
     
    20872083    CCfits::FITS* groupFile;
    20882084    unsigned int numFilesToGroup = 0;
    2089     for (map<string, vector<string> >::iterator it=filesToGroup.begin(); it != filesToGroup.end(); it++)
     2085    for (map<string, vector<string> >::const_iterator it=filesToGroup.begin(); it != filesToGroup.end(); it++)
    20902086    {
    20912087        numFilesToGroup += it->second.size();
     
    21582154
    21592155    int i=1;
    2160     for (map<string, vector<string> >::iterator it=filesToGroup.begin(); it!=filesToGroup.end(); it++)
    2161         for (vector<string>::iterator jt=it->second.begin(); jt != it->second.end(); jt++, i++)
     2156    for (map<string, vector<string> >::const_iterator it=filesToGroup.begin(); it!=filesToGroup.end(); it++)
     2157        for (vector<string>::const_iterator jt=it->second.begin(); jt != it->second.end(); jt++, i++)
    21622158        {
    21632159            strcpy(startOfLocation, it->first.c_str());
     
    21992195        Debug("Stopping Run Logging...");   
    22002196    }
    2201     for (list<RunNumberType>::iterator it=fRunNumber.begin(); it != fRunNumber.end(); it++)
     2197    for (list<RunNumberType>::const_iterator it=fRunNumber.begin(); it != fRunNumber.end(); it++)
    22022198    {
    22032199#ifdef RUN_LOGS
     
    23002296    fWhiteList.clear();
    23012297
     2298    //Adding entries that should ALWAYS be ignored
     2299    //fBlackList.insert("DATA_LOGGER/");
     2300    fBlackList.insert("/SERVICE_LIST");
     2301    fBlackList.insert("DIS_DNS/");
     2302
    23022303    if (conf.Has("block"))
    23032304    {
     
    23052306
    23062307        fBlackList.insert(vec.begin(), vec.end());
    2307 
    2308         //Adding entries that should ALWAYS be ignored
    2309         fBlackList.insert("DATA_LOGGER/");
    2310         fBlackList.insert("/SERVICE_LIST");
    2311         fBlackList.insert("DIS_DNS/");
    23122308    }
    23132309
Note: See TracChangeset for help on using the changeset viewer.