CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_7/src/EventFilter/StorageManager/src/FilesMonitorCollection.cc

Go to the documentation of this file.
00001 // $Id: FilesMonitorCollection.cc,v 1.15 2011/07/07 09:22:45 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     fileRecord->adler32 = 0;
00034     fileRecords_.push_back(fileRecord);
00035     return fileRecord;
00036   }
00037   
00038   void FilesMonitorCollection::getFileRecords(FileRecordList& fileRecords) const
00039   {
00040     boost::mutex::scoped_lock sl(fileRecordsMutex_);
00041     fileRecords = fileRecords_;
00042   }
00043   
00044   
00045   void FilesMonitorCollection::do_calculateStatistics()
00046   {
00047     // nothing to do
00048   }
00049   
00050   
00051   void FilesMonitorCollection::do_reset()
00052   {
00053     boost::mutex::scoped_lock sl(fileRecordsMutex_);
00054     fileRecords_.clear();
00055     entryCounter_ = 0;
00056   }
00057   
00058   
00059   void FilesMonitorCollection::do_appendInfoSpaceItems(InfoSpaceItems& infoSpaceItems)
00060   {
00061     infoSpaceItems.push_back(std::make_pair("openFiles", &openFiles_));
00062     infoSpaceItems.push_back(std::make_pair("closedFiles", &closedFiles_));
00063   }
00064   
00065   
00066   void FilesMonitorCollection::do_updateInfoSpaceItems()
00067   {
00068     boost::mutex::scoped_lock sl(fileRecordsMutex_);
00069     
00070     openFiles_ = 0;
00071     
00072     for (
00073       FileRecordList::const_iterator it = fileRecords_.begin(),
00074         itEnd = fileRecords_.end();
00075       it != itEnd;
00076       ++it
00077     )
00078     {
00079       if ( (*it)->isOpen )
00080         ++openFiles_;
00081     }
00082     
00083     closedFiles_ = entryCounter_ - openFiles_;
00084   }
00085   
00086   
00087   std::string FilesMonitorCollection::FileRecord::closingReason()
00088   {
00089     switch (whyClosed)
00090     {
00091       case notClosed:   return "open";
00092       case runEnded:    return "run ended";
00093       case LSended:     return "LS ended";
00094       case timeout:     return "timeout";
00095       case size:        return "file size";
00096       case truncated:   return "TRUNCATED";
00097       case inaccessible:return "INACCESSIBLE";
00098       default:          return "unknown";
00099     }
00100   }
00101   
00102   
00103   std::string FilesMonitorCollection::FileRecord::filePath(FileStatus status)
00104   {
00105     switch (status)
00106     {
00107       case open:    return ( baseFilePath + "/open/" );
00108       case closed:  return ( baseFilePath + "/closed/" );
00109       case current: return ( baseFilePath + (isOpen ? "/open/" : "/closed/") );
00110     }
00111     return "";
00112   }
00113   
00114   
00115   std::string FilesMonitorCollection::FileRecord::fileName()
00116   {
00117     std::ostringstream fileName;
00118     fileName << coreFileName 
00119       << "." << std::setfill('0') << std::setw(4) << fileCounter
00120       << ".dat";
00121     return fileName.str();
00122   }
00123   
00124 } // namespace stor
00125