Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-10-01 22:40:44

0001 #ifndef IOPool_Streamer_StreamerInputFile_h
0002 #define IOPool_Streamer_StreamerInputFile_h
0003 
0004 #include "IOPool/Streamer/interface/InitMessage.h"
0005 #include "IOPool/Streamer/interface/EventMessage.h"
0006 #include "IOPool/Streamer/interface/MsgTools.h"
0007 #include "Utilities/StorageFactory/interface/IOTypes.h"
0008 #include "Utilities/StorageFactory/interface/Storage.h"
0009 #include "FWCore/Utilities/interface/propagate_const.h"
0010 
0011 #include <memory>
0012 
0013 #include <string>
0014 #include <vector>
0015 
0016 namespace edm {
0017   class EventSkipperByID;
0018   class FileCatalogItem;
0019   class StreamerInputFile {
0020   public:
0021     /**Reads a Streamer file */
0022     explicit StreamerInputFile(std::string const& name,
0023                                std::string const& LFN,
0024                                std::shared_ptr<EventSkipperByID> eventSkipperByID = std::shared_ptr<EventSkipperByID>());
0025     explicit StreamerInputFile(std::string const& name,
0026                                std::shared_ptr<EventSkipperByID> eventSkipperByID = std::shared_ptr<EventSkipperByID>());
0027 
0028     /** Multiple Streamer files */
0029     explicit StreamerInputFile(std::vector<FileCatalogItem> const& names,
0030                                std::shared_ptr<EventSkipperByID> eventSkipperByID = std::shared_ptr<EventSkipperByID>());
0031 
0032     ~StreamerInputFile();
0033 
0034     enum class Next { kEvent, kFile, kStop };
0035     Next next(); /** Moves the handler to next Event Record */
0036 
0037     InitMsgView const* startMessage() const { return startMsg_.get(); }
0038     /** Points to File Start Header/Message */
0039 
0040     EventMsgView const* currentRecord() const { return currentEvMsg_.get(); }
0041     /** Points to current Record */
0042 
0043     bool newHeader() {
0044       bool tmp = newHeader_;
0045       newHeader_ = false;
0046       return tmp;
0047     } /** Test bit if a new header is encountered */
0048 
0049     void closeStreamerFile();
0050     bool openNextFile();
0051 
0052   private:
0053     void openStreamerFile(std::string const& name, std::string const& LFN);
0054     storage::IOSize readBytes(char* buf, storage::IOSize nBytes);
0055     storage::IOOffset skipBytes(storage::IOSize nBytes);
0056 
0057     void readStartMessage();
0058     int readEventMessage();
0059 
0060     /** Compares current File header with the newly opened file header
0061                Returns false in case of mismatch */
0062     bool compareHeader();
0063 
0064     void logFileAction(char const* msg);
0065 
0066     edm::propagate_const<std::shared_ptr<InitMsgView>> startMsg_;
0067     edm::propagate_const<std::shared_ptr<EventMsgView>> currentEvMsg_;
0068 
0069     std::vector<char> headerBuf_; /** Buffer to store file Header */
0070     std::vector<char> eventBuf_;  /** Buffer to store Event Data */
0071 
0072     unsigned int currentFile_;                   /** keeps track of which file is in use at the moment*/
0073     std::vector<FileCatalogItem> streamerNames_; /** names of Streamer files */
0074     bool multiStreams_;                          /** True if Multiple Streams are Read */
0075     std::string currentFileName_;
0076     bool currentFileOpen_;
0077 
0078     edm::propagate_const<std::shared_ptr<EventSkipperByID>> eventSkipperByID_;
0079 
0080     uint32 currRun_;
0081     uint32 currProto_;
0082 
0083     bool newHeader_;
0084 
0085     edm::propagate_const<std::unique_ptr<edm::storage::Storage>> storage_;
0086 
0087     bool endOfFile_;
0088   };
0089 }  // namespace edm
0090 
0091 #endif