CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | Private Member Functions
stor::StreamHandler Class Referenceabstract

#include <StreamHandler.h>

Inheritance diagram for stor::StreamHandler:
stor::EventStreamHandler stor::FaultyEventStreamHandler stor::FRDStreamHandler

Public Member Functions

void closeAllFiles ()
 
bool closeFilesForLumiSection (const uint32_t &lumiSection, std::string &)
 
void closeTimedOutFiles (utils::TimePoint_t currentTime=utils::getCurrentTime())
 
 StreamHandler (const SharedResourcesPtr, const DbFileHandlerPtr)
 
void writeEvent (const I2OChain &event)
 
virtual ~StreamHandler ()
 

Protected Types

typedef std::map< std::string,
unsigned int > 
CoreFileNamesMap
 
typedef boost::shared_ptr
< FileHandler
FileHandlerPtr
 
typedef std::vector
< FileHandlerPtr
FileHandlers
 

Protected Member Functions

virtual double fractionToDisk () const =0
 
virtual FileHandlerPtr getFileHandler (const I2OChain &event)
 
unsigned long long getMaxFileSize () const
 
FilesMonitorCollection::FileRecordPtr getNewFileRecord (const I2OChain &event)
 
virtual int getStreamMaxFileSize () const =0
 
virtual FileHandlerPtr newFileHandler (const I2OChain &event)=0
 
virtual std::string streamLabel () const =0
 

Protected Attributes

const DbFileHandlerPtr dbFileHandler_
 
const DiskWritingParamsdiskWritingParams_
 
FileHandlers fileHandlers_
 
const SharedResourcesPtr sharedResources_
 
const StatisticsReporterPtr statReporter_
 
const
StreamsMonitorCollection::StreamRecordPtr 
streamRecord_
 
CoreFileNamesMap usedCoreFileNames_
 

Private Member Functions

bool fileTooLarge (const FileHandlerPtr, const unsigned long &dataSize) const
 
std::string getBaseFilePath (const uint32_t &runNumber, uint32_t fileCount) const
 
std::string getCoreFileName (const uint32_t &runNumber, const uint32_t &lumiSection) const
 
unsigned int getFileCounter (const std::string &coreFileName)
 
std::string getFileSystem (const uint32_t &runNumber, uint32_t fileCount) const
 
StreamHandleroperator= (StreamHandler const &)
 
 StreamHandler (StreamHandler const &)
 

Detailed Description

Abstract class to handle one stream written to disk.

Author:
mommsen
Revision:
1.16
Date:
2012/04/04 12:16:58

Definition at line 31 of file StreamHandler.h.

Member Typedef Documentation

typedef std::map<std::string, unsigned int> stor::StreamHandler::CoreFileNamesMap
protected

Definition at line 145 of file StreamHandler.h.

typedef boost::shared_ptr<FileHandler> stor::StreamHandler::FileHandlerPtr
protected

Definition at line 67 of file StreamHandler.h.

typedef std::vector<FileHandlerPtr> stor::StreamHandler::FileHandlers
protected

Definition at line 142 of file StreamHandler.h.

Constructor & Destructor Documentation

stor::StreamHandler::StreamHandler ( const SharedResourcesPtr  sharedResources,
const DbFileHandlerPtr  dbFileHandler 
)

Definition at line 16 of file StreamHandler.cc.

19  :
20  sharedResources_(sharedResources),
21  statReporter_(sharedResources->statisticsReporter_),
22  streamRecord_(statReporter_->getStreamsMonitorCollection().getNewStreamRecord()),
23  diskWritingParams_(dbFileHandler->getDiskWritingParams()),
24  dbFileHandler_(dbFileHandler)
25  {}
const StatisticsReporterPtr statReporter_
const DbFileHandlerPtr dbFileHandler_
const StreamsMonitorCollection::StreamRecordPtr streamRecord_
const DiskWritingParams & diskWritingParams_
const SharedResourcesPtr sharedResources_
virtual stor::StreamHandler::~StreamHandler ( )
inlinevirtual

Definition at line 37 of file StreamHandler.h.

37 {};
stor::StreamHandler::StreamHandler ( StreamHandler const &  )
private

Member Function Documentation

void stor::StreamHandler::closeAllFiles ( )

Gracefully close all open files

Definition at line 28 of file StreamHandler.cc.

References alignCSCRings::e, stor::AlarmHandler::ERROR, cppFunctionSkipper::exception, edm::hlt::Exception, fileHandlers_, stor::FilesMonitorCollection::FileRecord::runEnded, sharedResources_, streamLabel(), and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by stor::DiskWriter::destroyStreams(), and stor::FaultyEventStreamHandler::getFileHandler().

29  {
30  std::string errorMsg = "Failed to close all files for stream " + streamLabel() + ": ";
31 
32  for (FileHandlers::const_iterator it = fileHandlers_.begin(),
33  itEnd = fileHandlers_.end(); it != itEnd; ++it)
34  {
35  try
36  {
38  }
39  catch(xcept::Exception& e)
40  {
41  XCEPT_DECLARE_NESTED( stor::exception::DiskWriting,
42  sentinelException, errorMsg, e );
43  sharedResources_->alarmHandler_->
44  notifySentinel(AlarmHandler::ERROR, sentinelException);
45  }
46  catch(std::exception &e)
47  {
48  errorMsg += e.what();
49  XCEPT_DECLARE( stor::exception::DiskWriting,
50  sentinelException, errorMsg );
51  sharedResources_->alarmHandler_->
52  notifySentinel(AlarmHandler::ERROR, sentinelException);
53  }
54  catch(...)
55  {
56  errorMsg += "Unknown exception";
57  XCEPT_DECLARE( stor::exception::DiskWriting,
58  sentinelException, errorMsg );
59  sharedResources_->alarmHandler_->
60  notifySentinel(AlarmHandler::ERROR, sentinelException);
61  }
62  }
63  fileHandlers_.clear();
64  }
virtual std::string streamLabel() const =0
FileHandlers fileHandlers_
const SharedResourcesPtr sharedResources_
bool stor::StreamHandler::closeFilesForLumiSection ( const uint32_t &  lumiSection,
std::string &  str 
)

Close all files which belong to the given lumi section and print number of files for this lumi section into the passed string. Returns true if at least one file was closed.

Definition at line 79 of file StreamHandler.cc.

References stor::FileHandler::isFromLumiSection().

83  {
84  fileHandlers_.erase(
85  std::remove_if(fileHandlers_.begin(),
86  fileHandlers_.end(),
87  boost::bind(&FileHandler::isFromLumiSection,
88  _1, lumiSection)),
89  fileHandlers_.end());
90 
91  return streamRecord_->reportLumiSectionInfo(lumiSection, str);
92  }
const StreamsMonitorCollection::StreamRecordPtr streamRecord_
FileHandlers fileHandlers_
bool isFromLumiSection(const uint32_t lumiSection)
Definition: FileHandler.cc:144
void stor::StreamHandler::closeTimedOutFiles ( utils::TimePoint_t  currentTime = utils::getCurrentTime())

Close all files which are have not seen any recent events

Definition at line 67 of file StreamHandler.cc.

References fileHandlers_, and stor::FileHandler::tooOld().

Referenced by stor::DiskWriter::closeTimedOutFiles().

68  {
69  fileHandlers_.erase(
70  std::remove_if(fileHandlers_.begin(),
71  fileHandlers_.end(),
72  boost::bind(&FileHandler::tooOld,
73  _1, currentTime)),
74  fileHandlers_.end());
75  }
bool tooOld(const utils::TimePoint_t currentTime=utils::getCurrentTime())
Definition: FileHandler.cc:129
FileHandlers fileHandlers_
bool stor::StreamHandler::fileTooLarge ( const FileHandlerPtr  ,
const unsigned long &  dataSize 
) const
private

Return true if the file would become too large when adding dataSize in Bytes

virtual double stor::StreamHandler::fractionToDisk ( ) const
protectedpure virtual
std::string stor::StreamHandler::getBaseFilePath ( const uint32_t &  runNumber,
uint32_t  fileCount 
) const
private

Get path w/o working directory

Definition at line 160 of file StreamHandler.cc.

Referenced by getNewFileRecord().

164  {
166  }
const DiskWritingParams & diskWritingParams_
std::string getFileSystem(const uint32_t &runNumber, uint32_t fileCount) const
std::string stor::StreamHandler::getCoreFileName ( const uint32_t &  runNumber,
const uint32_t &  lumiSection 
) const
private

Get the core file name

Definition at line 193 of file StreamHandler.cc.

References StorageManager_cfg::streamLabel.

Referenced by getNewFileRecord().

197  {
198  std::ostringstream coreFileName;
199  coreFileName << diskWritingParams_.setupLabel_
200  << "." << std::setfill('0') << std::setw(8) << runNumber
201  << "." << std::setfill('0') << std::setw(4) << lumiSection
202  << "." << streamLabel()
203  << "." << diskWritingParams_.fileName_
204  << "." << std::setfill('0') << std::setw(2) << diskWritingParams_.smInstanceString_;
205 
206  return coreFileName.str();
207  }
std::string smInstanceString_
Definition: Configuration.h:51
virtual std::string streamLabel() const =0
const DiskWritingParams & diskWritingParams_
unsigned int stor::StreamHandler::getFileCounter ( const std::string &  coreFileName)
private

Get the instance count of this core file name

Definition at line 210 of file StreamHandler.cc.

References pos, and usedCoreFileNames_.

Referenced by getNewFileRecord().

211  {
212  CoreFileNamesMap::iterator pos = usedCoreFileNames_.find(coreFileName);
213  if (pos == usedCoreFileNames_.end())
214  {
215  usedCoreFileNames_.insert(pos, std::make_pair(coreFileName, 0));
216  return 0;
217  }
218  else
219  {
220  ++(pos->second);
221  return pos->second;
222  }
223  }
CoreFileNamesMap usedCoreFileNames_
StreamHandler::FileHandlerPtr stor::StreamHandler::getFileHandler ( const I2OChain event)
protectedvirtual

Get the file handler responsible for the event

Reimplemented in stor::FaultyEventStreamHandler.

Definition at line 105 of file StreamHandler.cc.

References fileHandlers_, newFileHandler(), and stor::I2OChain::totalDataSize().

Referenced by writeEvent().

106  {
107  for (
108  FileHandlers::iterator it = fileHandlers_.begin(), itEnd = fileHandlers_.end();
109  it != itEnd;
110  ++it
111  )
112  {
113  if ( (*it)->lumiSection() == event.lumiSection() )
114  {
115  if ( (*it)->tooLarge(event.totalDataSize()) )
116  {
117  fileHandlers_.erase(it);
118  break;
119  }
120  else
121  {
122  return (*it);
123  }
124  }
125  }
126  return newFileHandler(event);
127  }
virtual FileHandlerPtr newFileHandler(const I2OChain &event)=0
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
FileHandlers fileHandlers_
std::string stor::StreamHandler::getFileSystem ( const uint32_t &  runNumber,
uint32_t  fileCount 
) const
private

Get file system string

Definition at line 170 of file StreamHandler.cc.

174  {
175  // if the number of logical disks is not specified, don't
176  // add a file system subdir to the path
177  if (diskWritingParams_.nLogicalDisk_ <= 0) {return "";}
178 
179  unsigned int fileSystemNumber =
180  (runNumber
181  + atoi(diskWritingParams_.smInstanceString_.c_str())
182  + fileCount)
184 
185  std::ostringstream fileSystem;
186  fileSystem << "/" << std::setfill('0') << std::setw(2) << fileSystemNumber;
187 
188  return fileSystem.str();
189  }
std::string smInstanceString_
Definition: Configuration.h:51
const DiskWritingParams & diskWritingParams_
unsigned long long stor::StreamHandler::getMaxFileSize ( ) const
protected

Return the maximum file size in bytes

Definition at line 226 of file StreamHandler.cc.

References diskWritingParams_, getStreamMaxFileSize(), and stor::DiskWritingParams::maxFileSizeMB_.

Referenced by stor::FRDStreamHandler::newFileHandler(), and stor::EventStreamHandler::newFileHandler().

227  {
228  const unsigned long long maxFileSizeMB =
231 
232  return ( maxFileSizeMB * 1024 * 1024 );
233  }
virtual int getStreamMaxFileSize() const =0
const DiskWritingParams & diskWritingParams_
FilesMonitorCollection::FileRecordPtr stor::StreamHandler::getNewFileRecord ( const I2OChain event)
protected

Return a new file record for the event

Definition at line 131 of file StreamHandler.cc.

References alignCSCRings::e, getBaseFilePath(), getCoreFileName(), getFileCounter(), stor::FilesMonitorCollection::FileRecord::notClosed, sharedResources_, statReporter_, and streamLabel().

Referenced by stor::FRDStreamHandler::newFileHandler(), stor::EventStreamHandler::newFileHandler(), and stor::FaultyEventStreamHandler::newFileHandler().

132  {
134  statReporter_->getFilesMonitorCollection().getNewFileRecord();
135 
136  try
137  {
138  fileRecord->runNumber = event.runNumber();
139  fileRecord->lumiSection = event.lumiSection();
140  }
141  catch(stor::exception::IncompleteEventMessage &e)
142  {
143  fileRecord->runNumber = sharedResources_->configuration_->getRunNumber();
144  fileRecord->lumiSection = 0;
145  }
146  fileRecord->streamLabel = streamLabel();
147  fileRecord->baseFilePath =
148  getBaseFilePath(fileRecord->runNumber, fileRecord->entryCounter);
149  fileRecord->coreFileName =
150  getCoreFileName(fileRecord->runNumber, fileRecord->lumiSection);
151  fileRecord->fileCounter = getFileCounter(fileRecord->coreFileName);
152  fileRecord->whyClosed = FilesMonitorCollection::FileRecord::notClosed;
153  fileRecord->isOpen = true;
154 
155  return fileRecord;
156  }
std::string getCoreFileName(const uint32_t &runNumber, const uint32_t &lumiSection) const
const StatisticsReporterPtr statReporter_
boost::shared_ptr< FileRecord > FileRecordPtr
virtual std::string streamLabel() const =0
unsigned int getFileCounter(const std::string &coreFileName)
std::string getBaseFilePath(const uint32_t &runNumber, uint32_t fileCount) const
const SharedResourcesPtr sharedResources_
virtual int stor::StreamHandler::getStreamMaxFileSize ( ) const
protectedpure virtual

Return the maximum file size for the stream in MB

Implemented in stor::FaultyEventStreamHandler, stor::EventStreamHandler, and stor::FRDStreamHandler.

Referenced by getMaxFileSize().

virtual FileHandlerPtr stor::StreamHandler::newFileHandler ( const I2OChain event)
protectedpure virtual

Return a new file handler for the provided event

Implemented in stor::FaultyEventStreamHandler, stor::EventStreamHandler, and stor::FRDStreamHandler.

Referenced by getFileHandler().

StreamHandler& stor::StreamHandler::operator= ( StreamHandler const &  )
private
virtual std::string stor::StreamHandler::streamLabel ( ) const
protectedpure virtual
void stor::StreamHandler::writeEvent ( const I2OChain event)

Write the event to the stream file

Definition at line 95 of file StreamHandler.cc.

References getFileHandler(), statReporter_, streamRecord_, and stor::I2OChain::totalDataSize().

96  {
98  handler->writeEvent(event);
99  streamRecord_->addSizeInBytes(event.totalDataSize());
100  statReporter_->getThroughputMonitorCollection().
101  addDiskWriteSample(event.totalDataSize());
102  }
const StatisticsReporterPtr statReporter_
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
virtual FileHandlerPtr getFileHandler(const I2OChain &event)
const StreamsMonitorCollection::StreamRecordPtr streamRecord_
boost::shared_ptr< FileHandler > FileHandlerPtr
Definition: StreamHandler.h:67

Member Data Documentation

const DbFileHandlerPtr stor::StreamHandler::dbFileHandler_
protected
const DiskWritingParams& stor::StreamHandler::diskWritingParams_
protected

Definition at line 139 of file StreamHandler.h.

Referenced by getMaxFileSize().

FileHandlers stor::StreamHandler::fileHandlers_
protected
const SharedResourcesPtr stor::StreamHandler::sharedResources_
protected

Definition at line 136 of file StreamHandler.h.

Referenced by closeAllFiles(), and getNewFileRecord().

const StatisticsReporterPtr stor::StreamHandler::statReporter_
protected

Definition at line 137 of file StreamHandler.h.

Referenced by getNewFileRecord(), and writeEvent().

const StreamsMonitorCollection::StreamRecordPtr stor::StreamHandler::streamRecord_
protected
CoreFileNamesMap stor::StreamHandler::usedCoreFileNames_
protected

Definition at line 146 of file StreamHandler.h.

Referenced by getFileCounter().