CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch9/src/EventFilter/StorageManager/src/FilesMonitorCollection.cc

Go to the documentation of this file.
00001 // $Id: FilesMonitorCollection.cc,v 1.14 2011/03/07 15:31:32 mommsen Exp $
00003 
00004 #include <string>
00005 #include <sstream>
00006 #include <iomanip>
00007 
00008 #include "EventFilter/StorageManager/interface/Exception.h"
00009 #include "EventFilter/StorageManager/interface/FilesMonitorCollection.h"
00010 
00011 
00012 namespace stor {
00013   
00014   FilesMonitorCollection::FilesMonitorCollection(const utils::Duration_t& updateInterval) :
00015   MonitorCollection(updateInterval),
00016   maxFileEntries_(250),
00017   entryCounter_(0)
00018   {
00019     boost::mutex::scoped_lock sl(fileRecordsMutex_);
00020     fileRecords_.set_capacity(maxFileEntries_);
00021   }
00022   
00023   
00024   const FilesMonitorCollection::FileRecordPtr
00025   FilesMonitorCollection::getNewFileRecord()
00026   {
00027     boost::mutex::scoped_lock sl(fileRecordsMutex_);
00028     
00029     boost::shared_ptr<FileRecord> fileRecord(new FilesMonitorCollection::FileRecord());
00030     fileRecord->entryCounter = entryCounter_++;
00031     fileRecord->fileSize = 0;
00032     fileRecord->eventCount = 0;
00033     fileRecords_.push_back(fileRecord);
00034     return fileRecord;
00035   }
00036   
00037   void FilesMonitorCollection::getFileRecords(FileRecordList& fileRecords) const
00038   {
00039     boost::mutex::scoped_lock sl(fileRecordsMutex_);
00040     fileRecords = fileRecords_;
00041   }
00042   
00043   
00044   void FilesMonitorCollection::do_calculateStatistics()
00045   {
00046     // nothing to do
00047   }
00048   
00049   
00050   void FilesMonitorCollection::do_reset()
00051   {
00052     boost::mutex::scoped_lock sl(fileRecordsMutex_);
00053     fileRecords_.clear();
00054     entryCounter_ = 0;
00055   }
00056   
00057   
00058   void FilesMonitorCollection::do_appendInfoSpaceItems(InfoSpaceItems& infoSpaceItems)
00059   {
00060     infoSpaceItems.push_back(std::make_pair("openFiles", &openFiles_));
00061     infoSpaceItems.push_back(std::make_pair("closedFiles", &closedFiles_));
00062   }
00063   
00064   
00065   void FilesMonitorCollection::do_updateInfoSpaceItems()
00066   {
00067     boost::mutex::scoped_lock sl(fileRecordsMutex_);
00068     
00069     openFiles_ = 0;
00070     
00071     for (
00072       FileRecordList::const_iterator it = fileRecords_.begin(),
00073         itEnd = fileRecords_.end();
00074       it != itEnd;
00075       ++it
00076     )
00077     {
00078       if ( (*it)->isOpen )
00079         ++openFiles_;
00080     }
00081     
00082     closedFiles_ = entryCounter_ - openFiles_;
00083   }
00084   
00085   
00086   std::string FilesMonitorCollection::FileRecord::closingReason()
00087   {
00088     switch (whyClosed)
00089     {
00090       case notClosed:   return "open";
00091       case runEnded:    return "run ended";
00092       case LSended:     return "LS ended";
00093       case timeout:     return "timeout";
00094       case size:        return "file size";
00095       case truncated:   return "TRUNCATED";
00096       case inaccessible:return "INACCESSIBLE";
00097       default:          return "unknown";
00098     }
00099   }
00100   
00101   
00102   std::string FilesMonitorCollection::FileRecord::filePath(FileStatus status)
00103   {
00104     switch (status)
00105     {
00106       case open:    return ( baseFilePath + "/open/" );
00107       case closed:  return ( baseFilePath + "/closed/" );
00108       case current: return ( baseFilePath + (isOpen ? "/open/" : "/closed/") );
00109     }
00110     return "";
00111   }
00112   
00113   
00114   std::string FilesMonitorCollection::FileRecord::fileName()
00115   {
00116     std::ostringstream fileName;
00117     fileName << coreFileName 
00118       << "." << std::setfill('0') << std::setw(4) << fileCounter
00119       << ".dat";
00120     return fileName.str();
00121   }
00122   
00123 } // namespace stor
00124