Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-05-31 04:19:41

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 }  // namespace edm
0020 namespace edm::streamer {
0021   class StreamerInputFile {
0022   public:
0023     /**Reads a Streamer file */
0024     explicit StreamerInputFile(std::string const& name,
0025                                std::string const& LFN,
0026                                std::shared_ptr<EventSkipperByID> eventSkipperByID = std::shared_ptr<EventSkipperByID>(),
0027                                unsigned int prefetchMBytes = 0);
0028     explicit StreamerInputFile(std::string const& name,
0029                                std::shared_ptr<EventSkipperByID> eventSkipperByID = std::shared_ptr<EventSkipperByID>(),
0030                                unsigned int prefetchMBytes = 0);
0031 
0032     /** Multiple Streamer files */
0033     explicit StreamerInputFile(std::vector<FileCatalogItem> const& names,
0034                                std::shared_ptr<EventSkipperByID> eventSkipperByID = std::shared_ptr<EventSkipperByID>(),
0035                                unsigned int prefetchMBytes = 0);
0036 
0037     ~StreamerInputFile();
0038 
0039     enum class Next { kEvent, kFile, kStop };
0040     Next next(); /** Moves the handler to next Event Record */
0041 
0042     InitMsgView const* startMessage() const { return startMsg_.get(); }
0043     /** Points to File Start Header/Message */
0044 
0045     EventMsgView const* currentRecord() const { return currentEvMsg_.get(); }
0046     /** Points to current Record */
0047 
0048     bool newHeader() {
0049       bool tmp = newHeader_;
0050       newHeader_ = false;
0051       return tmp;
0052     } /** Test bit if a new header is encountered */
0053 
0054     void closeStreamerFile();
0055     bool openNextFile();
0056 
0057   private:
0058     void openStreamerFile(std::string const& name, std::string const& LFN);
0059     std::pair<storage::IOSize, char*> readBytes(char* buf,
0060                                                 storage::IOSize nBytes,
0061                                                 bool zeroCopy,
0062                                                 unsigned int skippedHdr = 0);
0063     storage::IOOffset skipBytes(storage::IOSize nBytes);
0064 
0065     void readStartMessage();
0066     int readEventMessage();
0067 
0068     /** Compares current File header with the newly opened file header
0069                Returns false in case of mismatch */
0070     bool compareHeader();
0071 
0072     void logFileAction(char const* msg);
0073 
0074     edm::propagate_const<std::shared_ptr<InitMsgView>> startMsg_;
0075     edm::propagate_const<std::shared_ptr<EventMsgView>> currentEvMsg_;
0076 
0077     std::vector<char> headerBuf_; /** Buffer to store file Header */
0078     std::vector<char> eventBuf_;  /** Buffer to store Event Data */
0079 
0080     std::vector<char> tempBuf_; /** Buffer to store prefetched bytes */
0081     unsigned int tempLen_ = 0;
0082     unsigned int tempPos_ = 0;
0083 
0084     unsigned int currentFile_;                   /** keeps track of which file is in use at the moment*/
0085     std::vector<FileCatalogItem> streamerNames_; /** names of Streamer files */
0086     bool multiStreams_;                          /** True if Multiple Streams are Read */
0087     std::string currentFileName_;
0088     bool currentFileOpen_;
0089 
0090     edm::propagate_const<std::shared_ptr<EventSkipperByID>> eventSkipperByID_;
0091 
0092     uint32 currRun_;
0093     uint32 currProto_;
0094 
0095     bool newHeader_;
0096 
0097     edm::propagate_const<std::unique_ptr<edm::storage::Storage>> storage_;
0098 
0099     bool endOfFile_;
0100   };
0101 }  // namespace edm::streamer
0102 
0103 #endif