CMS 3D CMS Logo

List of all members | Public Types | Public Member Functions | Private Member Functions | Private Attributes
edm::StreamerInputFile Class Reference

#include <StreamerInputFile.h>

Public Types

enum  Next { Next::kEvent, Next::kFile, Next::kStop }
 

Public Member Functions

void closeStreamerFile ()
 
EventMsgView const * currentRecord () const
 
bool newHeader ()
 
Next next ()
 
bool openNextFile ()
 
InitMsgView const * startMessage () const
 
 StreamerInputFile (std::string const &name, std::string const &LFN, std::shared_ptr< EventSkipperByID > eventSkipperByID=std::shared_ptr< EventSkipperByID >())
 
 StreamerInputFile (std::string const &name, std::shared_ptr< EventSkipperByID > eventSkipperByID=std::shared_ptr< EventSkipperByID >())
 
 StreamerInputFile (std::vector< FileCatalogItem > const &names, std::shared_ptr< EventSkipperByID > eventSkipperByID=std::shared_ptr< EventSkipperByID >())
 
 ~StreamerInputFile ()
 

Private Member Functions

bool compareHeader ()
 
void logFileAction (char const *msg)
 
void openStreamerFile (std::string const &name, std::string const &LFN)
 
storage::IOSize readBytes (char *buf, storage::IOSize nBytes)
 
int readEventMessage ()
 
void readStartMessage ()
 
storage::IOOffset skipBytes (storage::IOSize nBytes)
 

Private Attributes

edm::propagate_const< std::shared_ptr< EventMsgView > > currentEvMsg_
 
unsigned int currentFile_
 
std::string currentFileName_
 
bool currentFileOpen_
 
uint32 currProto_
 
uint32 currRun_
 
bool endOfFile_
 
std::vector< char > eventBuf_
 
edm::propagate_const< std::shared_ptr< EventSkipperByID > > eventSkipperByID_
 
std::vector< char > headerBuf_
 
bool multiStreams_
 
bool newHeader_
 
edm::propagate_const< std::shared_ptr< InitMsgView > > startMsg_
 
edm::propagate_const< std::unique_ptr< edm::storage::Storage > > storage_
 
std::vector< FileCatalogItemstreamerNames_
 

Detailed Description

Definition at line 19 of file StreamerInputFile.h.

Member Enumeration Documentation

◆ Next

Enumerator
kEvent 
kFile 
kStop 

Definition at line 34 of file StreamerInputFile.h.

34 { kEvent, kFile, kStop };
constexpr char const *const kStop
Definition: channel_names.h:34

Constructor & Destructor Documentation

◆ StreamerInputFile() [1/3]

edm::StreamerInputFile::StreamerInputFile ( std::string const &  name,
std::string const &  LFN,
std::shared_ptr< EventSkipperByID eventSkipperByID = std::shared_ptr<EventSkipperByID>() 
)
explicit

Reads a Streamer file

Definition at line 21 of file StreamerInputFile.cc.

References Skims_PA_cff::name, openStreamerFile(), and readStartMessage().

24  : startMsg_(),
25  currentEvMsg_(),
26  headerBuf_(1000 * 1000),
27  eventBuf_(1000 * 1000 * 7),
28  currentFile_(0),
30  multiStreams_(false),
32  currentFileOpen_(false),
33  eventSkipperByID_(eventSkipperByID),
34  currRun_(0),
35  currProto_(0),
36  newHeader_(false),
37  storage_(),
38  endOfFile_(false) {
39  openStreamerFile(name, LFN);
41  }
std::vector< char > eventBuf_
edm::propagate_const< std::shared_ptr< EventSkipperByID > > eventSkipperByID_
void openStreamerFile(std::string const &name, std::string const &LFN)
std::vector< char > headerBuf_
edm::propagate_const< std::shared_ptr< EventMsgView > > currentEvMsg_
std::vector< FileCatalogItem > streamerNames_
edm::propagate_const< std::shared_ptr< InitMsgView > > startMsg_
edm::propagate_const< std::unique_ptr< edm::storage::Storage > > storage_

◆ StreamerInputFile() [2/3]

edm::StreamerInputFile::StreamerInputFile ( std::string const &  name,
std::shared_ptr< EventSkipperByID eventSkipperByID = std::shared_ptr<EventSkipperByID>() 
)
explicit

Definition at line 43 of file StreamerInputFile.cc.

44  : StreamerInputFile(name, name, eventSkipperByID) {}
StreamerInputFile(std::string const &name, std::string const &LFN, std::shared_ptr< EventSkipperByID > eventSkipperByID=std::shared_ptr< EventSkipperByID >())

◆ StreamerInputFile() [3/3]

edm::StreamerInputFile::StreamerInputFile ( std::vector< FileCatalogItem > const &  names,
std::shared_ptr< EventSkipperByID eventSkipperByID = std::shared_ptr<EventSkipperByID>() 
)
explicit

Multiple Streamer files

Definition at line 46 of file StreamerInputFile.cc.

References currentFile_, currProto_, currRun_, names, openStreamerFile(), readStartMessage(), and startMsg_.

48  : startMsg_(),
49  currentEvMsg_(),
50  headerBuf_(1000 * 1000),
51  eventBuf_(1000 * 1000 * 7),
52  currentFile_(0),
54  multiStreams_(true),
56  currentFileOpen_(false),
57  eventSkipperByID_(eventSkipperByID),
58  currRun_(0),
59  currProto_(0),
60  newHeader_(false),
61  endOfFile_(false) {
62  openStreamerFile(names.at(0).fileName(0), names.at(0).logicalFileName());
63  ++currentFile_;
65  currRun_ = startMsg_->run();
66  currProto_ = startMsg_->protocolVersion();
67  }
std::vector< char > eventBuf_
edm::propagate_const< std::shared_ptr< EventSkipperByID > > eventSkipperByID_
const std::string names[nVars_]
void openStreamerFile(std::string const &name, std::string const &LFN)
std::vector< char > headerBuf_
edm::propagate_const< std::shared_ptr< EventMsgView > > currentEvMsg_
std::vector< FileCatalogItem > streamerNames_
edm::propagate_const< std::shared_ptr< InitMsgView > > startMsg_

◆ ~StreamerInputFile()

edm::StreamerInputFile::~StreamerInputFile ( )

Definition at line 19 of file StreamerInputFile.cc.

References closeStreamerFile().

Member Function Documentation

◆ closeStreamerFile()

void edm::StreamerInputFile::closeStreamerFile ( )

Test bit if a new header is encountered

Definition at line 106 of file StreamerInputFile.cc.

References currentFileOpen_, logFileAction(), and storage_.

Referenced by openStreamerFile(), and ~StreamerInputFile().

106  {
107  if (currentFileOpen_ && storage_) {
108  storage_->close();
109  logFileAction(" Closed file ");
110  }
111  currentFileOpen_ = false;
112  }
void logFileAction(char const *msg)
edm::propagate_const< std::unique_ptr< edm::storage::Storage > > storage_

◆ compareHeader()

bool edm::StreamerInputFile::compareHeader ( )
private

Compares current File header with the newly opened file header Returns false in case of mismatch

Definition at line 211 of file StreamerInputFile.cc.

References currentFile_, currProto_, currRun_, Exception, edm::errors::MismatchedInputFiles, readStartMessage(), startMsg_, and streamerNames_.

Referenced by openNextFile().

211  {
212  //Get the new header
214 
215  //Values from new Header should match up
216  if (currRun_ != startMsg_->run() || currProto_ != startMsg_->protocolVersion()) {
217  throw Exception(errors::MismatchedInputFiles, "StreamerInputFile::compareHeader")
218  << "File " << streamerNames_.at(currentFile_).fileNames()[0]
219  << "\nhas different run number or protocol version than previous\n";
220  return false;
221  }
222  return true;
223  }
std::vector< FileCatalogItem > streamerNames_
edm::propagate_const< std::shared_ptr< InitMsgView > > startMsg_

◆ currentRecord()

EventMsgView const* edm::StreamerInputFile::currentRecord ( ) const
inline

Points to File Start Header/Message

Definition at line 40 of file StreamerInputFile.h.

References currentEvMsg_, and edm::propagate_const< T >::get().

40 { return currentEvMsg_.get(); }
constexpr element_type const * get() const
edm::propagate_const< std::shared_ptr< EventMsgView > > currentEvMsg_

◆ logFileAction()

void edm::StreamerInputFile::logFileAction ( char const *  msg)
private

Definition at line 288 of file StreamerInputFile.cc.

References currentFileName_, edm::FlushMessageLog(), and mps_check::msg.

Referenced by closeStreamerFile(), and openStreamerFile().

288  {
289  LogAbsolute("fileAction") << std::setprecision(0) << TimeOfDay() << msg << currentFileName_;
290  FlushMessageLog();
291  }
void FlushMessageLog()
tuple msg
Definition: mps_check.py:285
Log< level::System, true > LogAbsolute

◆ newHeader()

bool edm::StreamerInputFile::newHeader ( )
inline

Points to current Record

Definition at line 43 of file StreamerInputFile.h.

References newHeader_, and createJobs::tmp.

43  {
44  bool tmp = newHeader_;
45  newHeader_ = false;
46  return tmp;
47  }
tmp
align.sh
Definition: createJobs.py:716

◆ next()

StreamerInputFile::Next edm::StreamerInputFile::next ( void  )

Definition at line 177 of file StreamerInputFile.cc.

References currentFile_, kEvent, kFile, kStop, multiStreams_, newHeader_, readEventMessage(), and streamerNames_.

177  {
178  if (this->readEventMessage()) {
179  return Next::kEvent;
180  }
181  if (multiStreams_) {
182  //Try opening next file
183  if (currentFile_ <= streamerNames_.size() - 1) {
184  newHeader_ = true;
185  return Next::kFile;
186  }
187  }
188  return Next::kStop;
189  }
std::vector< FileCatalogItem > streamerNames_

◆ openNextFile()

bool edm::StreamerInputFile::openNextFile ( )

Definition at line 191 of file StreamerInputFile.cc.

References compareHeader(), currentFile_, endOfFile_, FDEBUG, openStreamerFile(), startMsg_, and streamerNames_.

191  {
192  if (currentFile_ <= streamerNames_.size() - 1) {
193  FDEBUG(10) << "Opening file " << streamerNames_.at(currentFile_).fileNames()[0].c_str() << std::endl;
194 
195  openStreamerFile(streamerNames_.at(currentFile_).fileNames()[0],
196  streamerNames_.at(currentFile_).logicalFileName());
197 
198  // If start message was already there, then compare the
199  // previous and new headers
200  if (startMsg_) {
201  FDEBUG(10) << "Comparing Header" << std::endl;
202  compareHeader();
203  }
204  ++currentFile_;
205  endOfFile_ = false;
206  return true;
207  }
208  return false;
209  }
#define FDEBUG(lev)
Definition: DebugMacros.h:19
void openStreamerFile(std::string const &name, std::string const &LFN)
std::vector< FileCatalogItem > streamerNames_
edm::propagate_const< std::shared_ptr< InitMsgView > > startMsg_

◆ openStreamerFile()

void edm::StreamerInputFile::openStreamerFile ( std::string const &  name,
std::string const &  LFN 
)
private

Definition at line 69 of file StreamerInputFile.cc.

References cms::Exception::addContext(), edm::check(), cms::Exception::clearMessage(), closeStreamerFile(), currentFileName_, currentFileOpen_, MillePedeFileConverter_cfg::e, Exception, edm::errors::FileOpenError, get, logFileAction(), Skims_PA_cff::name, edm::storage::IOFlags::OpenRead, findQualityFiles::size, and storage_.

Referenced by openNextFile(), and StreamerInputFile().

69  {
71 
73 
74  // Check if the logical file name was found.
75  if (currentFileName_.empty()) {
76  // LFN not found in catalog.
77  throw cms::Exception("LogicalFileNameNotFound", "StreamerInputFile::openStreamerFile()\n")
78  << "Logical file name '" << LFN << "' was not found in the file catalog.\n"
79  << "If you wanted a local file, you forgot the 'file:' prefix\n"
80  << "before the file name in your configuration file.\n";
81  return;
82  }
83 
84  logFileAction(" Initiating request to open file ");
85 
86  using namespace edm::storage;
87  IOOffset size = -1;
88  if (StorageFactory::get()->check(name, &size)) {
89  try {
91  } catch (cms::Exception& e) {
93  ex.addContext("Calling StreamerInputFile::openStreamerFile()");
94  ex.clearMessage();
95  ex << "Error Opening Streamer Input File: " << name << "\n";
96  throw ex;
97  }
98  } else {
99  throw Exception(errors::FileOpenError, "StreamerInputFile::openStreamerFile")
100  << "Error Opening Streamer Input File, file does not exist: " << name << "\n";
101  }
102  currentFileOpen_ = true;
103  logFileAction(" Successfully opened file ");
104  }
size
Write out results.
int64_t IOOffset
Definition: IOTypes.h:20
void logFileAction(char const *msg)
static void check(T const &p, std::string const &id, SelectedProducts const &iProducts, bool iVerbose)
#define get
edm::propagate_const< std::unique_ptr< edm::storage::Storage > > storage_

◆ readBytes()

storage::IOSize edm::StreamerInputFile::readBytes ( char *  buf,
storage::IOSize  nBytes 
)
private

Definition at line 114 of file StreamerInputFile.cc.

References cms::Exception::addContext(), visDQMUpload::buf, edm::errors::FileReadError, dqmiodumpmetadata::n, and storage_.

Referenced by readEventMessage(), and readStartMessage().

114  {
115  storage::IOSize n = 0;
116  try {
117  n = storage_->read(buf, nBytes);
118  } catch (cms::Exception& ce) {
119  Exception ex(errors::FileReadError, "", ce);
120  ex.addContext("Calling StreamerInputFile::readBytes()");
121  throw ex;
122  }
123  return n;
124  }
size_t IOSize
Definition: IOTypes.h:15
edm::propagate_const< std::unique_ptr< edm::storage::Storage > > storage_

◆ readEventMessage()

int edm::StreamerInputFile::readEventMessage ( )
private

Definition at line 225 of file StreamerInputFile.cc.

References HeaderView::code(), convert32(), convert64(), currentEvMsg_, endOfFile_, Header::EVENT, EventHeader::event_, eventBuf_, eventSkipperByID_, Exception, edm::errors::FileReadError, EventHeader::lumi_, readBytes(), EventHeader::run_, HeaderView::size(), and skipBytes().

Referenced by next().

225  {
226  if (endOfFile_)
227  return 0;
228 
229  using namespace edm::storage;
230  bool eventRead = false;
231  while (!eventRead) {
232  IOSize nWant = sizeof(EventHeader);
233  IOSize nGot = readBytes(&eventBuf_[0], nWant);
234  if (nGot == 0) {
235  // no more data available
236  endOfFile_ = true;
237  return 0;
238  }
239  if (nGot != nWant) {
240  throw edm::Exception(errors::FileReadError, "StreamerInputFile::readEventMessage")
241  << "Failed reading streamer file, first read in readEventMessage\n"
242  << "Requested " << nWant << " bytes, read function returned " << nGot << " bytes\n";
243  }
244  HeaderView head(&eventBuf_[0]);
245  uint32 code = head.code();
246 
247  // If it is not an event then something is wrong.
248  if (code != Header::EVENT) {
249  throw Exception(errors::FileReadError, "StreamerInputFile::readEventMessage")
250  << "Failed reading streamer file, unknown code in event header\n"
251  << "code = " << code << "\n";
252  }
253  uint32 eventSize = head.size();
254  if (eventSize <= sizeof(EventHeader)) {
255  throw edm::Exception(errors::FileReadError, "StreamerInputFile::readEventMessage")
256  << "Failed reading streamer file, event header size from data too small\n";
257  }
258  eventRead = true;
259  if (eventSkipperByID_) {
260  EventHeader* evh = (EventHeader*)(&eventBuf_[0]);
261  if (eventSkipperByID_->skipIt(convert32(evh->run_), convert32(evh->lumi_), convert64(evh->event_))) {
262  eventRead = false;
263  }
264  }
265  nWant = eventSize - sizeof(EventHeader);
266  if (eventRead) {
267  if (eventBuf_.size() < eventSize)
268  eventBuf_.resize(eventSize);
269  nGot = readBytes(&eventBuf_[sizeof(EventHeader)], nWant);
270  if (nGot != nWant) {
271  throw Exception(errors::FileReadError, "StreamerInputFile::readEventMessage")
272  << "Failed reading streamer file, second read in readEventMessage\n"
273  << "Requested " << nWant << " bytes, read function returned " << nGot << " bytes\n";
274  }
275  } else {
276  nGot = skipBytes(nWant);
277  if (nGot != nWant) {
278  throw Exception(errors::FileReadError, "StreamerInputFile::readEventMessage")
279  << "Failed reading streamer file, skip event in readEventMessage\n"
280  << "Requested " << nWant << " bytes skipped, seek function returned " << nGot << " bytes\n";
281  }
282  }
283  }
284  currentEvMsg_ = std::make_shared<EventMsgView>((void*)&eventBuf_[0]); // propagate_const<T> has no reset() function
285  return 1;
286  }
uint64 convert64(char_uint64 v)
Definition: MsgTools.h:20
std::vector< char > eventBuf_
edm::propagate_const< std::shared_ptr< EventSkipperByID > > eventSkipperByID_
char_uint32 lumi_
Definition: EventMessage.h:66
storage::IOOffset skipBytes(storage::IOSize nBytes)
storage::IOSize readBytes(char *buf, storage::IOSize nBytes)
unsigned int uint32
Definition: MsgTools.h:13
char_uint32 run_
Definition: EventMessage.h:64
size_t IOSize
Definition: IOTypes.h:15
char_uint64 event_
Definition: EventMessage.h:65
uint32 convert32(char_uint32 v)
Definition: MsgTools.h:28
edm::propagate_const< std::shared_ptr< EventMsgView > > currentEvMsg_

◆ readStartMessage()

void edm::StreamerInputFile::readStartMessage ( )
private

Not an init message should return

Definition at line 140 of file StreamerInputFile.cc.

References HeaderView::code(), Exception, edm::errors::FileReadError, headerBuf_, Header::INIT, readBytes(), HeaderView::size(), and startMsg_.

Referenced by compareHeader(), and StreamerInputFile().

140  {
141  using namespace edm::storage;
142  IOSize nWant = sizeof(HeaderView);
143  IOSize nGot = readBytes(&headerBuf_[0], nWant);
144  if (nGot != nWant) {
145  throw Exception(errors::FileReadError, "StreamerInputFile::readStartMessage")
146  << "Failed reading streamer file, first read in readStartMessage\n";
147  }
148 
149  HeaderView head(&headerBuf_[0]);
150  uint32 code = head.code();
151  if (code != Header::INIT)
152  {
153  throw Exception(errors::FileReadError, "StreamerInputFile::readStartMessage")
154  << "Expecting an init Message at start of file\n";
155  return;
156  }
157 
158  uint32 headerSize = head.size();
159  if (headerBuf_.size() < headerSize)
160  headerBuf_.resize(headerSize);
161 
162  if (headerSize > sizeof(HeaderView)) {
163  nWant = headerSize - sizeof(HeaderView);
164  nGot = readBytes(&headerBuf_[sizeof(HeaderView)], nWant);
165  if (nGot != nWant) {
166  throw Exception(errors::FileReadError, "StreamerInputFile::readStartMessage")
167  << "Failed reading streamer file, second read in readStartMessage\n";
168  }
169  } else {
170  throw Exception(errors::FileReadError, "StreamerInputFile::readStartMessage")
171  << "Failed reading streamer file, init header size from data too small\n";
172  }
173 
174  startMsg_ = std::make_shared<InitMsgView>(&headerBuf_[0]); // propagate_const<T> has no reset() function
175  }
storage::IOSize readBytes(char *buf, storage::IOSize nBytes)
unsigned int uint32
Definition: MsgTools.h:13
size_t IOSize
Definition: IOTypes.h:15
std::vector< char > headerBuf_
edm::propagate_const< std::shared_ptr< InitMsgView > > startMsg_

◆ skipBytes()

storage::IOOffset edm::StreamerInputFile::skipBytes ( storage::IOSize  nBytes)
private

Definition at line 126 of file StreamerInputFile.cc.

References cms::Exception::addContext(), edm::storage::Storage::CURRENT, edm::errors::FileReadError, dqmiodumpmetadata::n, and storage_.

Referenced by readEventMessage().

126  {
127  storage::IOOffset n = 0;
128  try {
129  // We wish to return the number of bytes skipped, not the final offset.
130  n = storage_->position(0, storage::Storage::CURRENT);
131  n = storage_->position(nBytes, storage::Storage::CURRENT) - n;
132  } catch (cms::Exception& ce) {
133  Exception ex(errors::FileReadError, "", ce);
134  ex.addContext("Calling StreamerInputFile::skipBytes()");
135  throw ex;
136  }
137  return n;
138  }
int64_t IOOffset
Definition: IOTypes.h:20
edm::propagate_const< std::unique_ptr< edm::storage::Storage > > storage_

◆ startMessage()

InitMsgView const* edm::StreamerInputFile::startMessage ( ) const
inline

Moves the handler to next Event Record

Definition at line 37 of file StreamerInputFile.h.

References edm::propagate_const< T >::get(), and startMsg_.

37 { return startMsg_.get(); }
constexpr element_type const * get() const
edm::propagate_const< std::shared_ptr< InitMsgView > > startMsg_

Member Data Documentation

◆ currentEvMsg_

edm::propagate_const<std::shared_ptr<EventMsgView> > edm::StreamerInputFile::currentEvMsg_
private

Definition at line 67 of file StreamerInputFile.h.

Referenced by currentRecord(), and readEventMessage().

◆ currentFile_

unsigned int edm::StreamerInputFile::currentFile_
private

Buffer to store Event Data

Definition at line 72 of file StreamerInputFile.h.

Referenced by compareHeader(), next(), openNextFile(), and StreamerInputFile().

◆ currentFileName_

std::string edm::StreamerInputFile::currentFileName_
private

True if Multiple Streams are Read

Definition at line 75 of file StreamerInputFile.h.

Referenced by logFileAction(), and openStreamerFile().

◆ currentFileOpen_

bool edm::StreamerInputFile::currentFileOpen_
private

Definition at line 76 of file StreamerInputFile.h.

Referenced by closeStreamerFile(), and openStreamerFile().

◆ currProto_

uint32 edm::StreamerInputFile::currProto_
private

Definition at line 81 of file StreamerInputFile.h.

Referenced by compareHeader(), and StreamerInputFile().

◆ currRun_

uint32 edm::StreamerInputFile::currRun_
private

Definition at line 80 of file StreamerInputFile.h.

Referenced by compareHeader(), and StreamerInputFile().

◆ endOfFile_

bool edm::StreamerInputFile::endOfFile_
private

Definition at line 87 of file StreamerInputFile.h.

Referenced by openNextFile(), and readEventMessage().

◆ eventBuf_

std::vector<char> edm::StreamerInputFile::eventBuf_
private

Buffer to store file Header

Definition at line 70 of file StreamerInputFile.h.

Referenced by readEventMessage().

◆ eventSkipperByID_

edm::propagate_const<std::shared_ptr<EventSkipperByID> > edm::StreamerInputFile::eventSkipperByID_
private

Definition at line 78 of file StreamerInputFile.h.

Referenced by readEventMessage().

◆ headerBuf_

std::vector<char> edm::StreamerInputFile::headerBuf_
private

Definition at line 69 of file StreamerInputFile.h.

Referenced by readStartMessage().

◆ multiStreams_

bool edm::StreamerInputFile::multiStreams_
private

names of Streamer files

Definition at line 74 of file StreamerInputFile.h.

Referenced by next().

◆ newHeader_

bool edm::StreamerInputFile::newHeader_
private

Definition at line 83 of file StreamerInputFile.h.

Referenced by newHeader(), and next().

◆ startMsg_

edm::propagate_const<std::shared_ptr<InitMsgView> > edm::StreamerInputFile::startMsg_
private

◆ storage_

edm::propagate_const<std::unique_ptr<edm::storage::Storage> > edm::StreamerInputFile::storage_
private

Definition at line 85 of file StreamerInputFile.h.

Referenced by closeStreamerFile(), openStreamerFile(), readBytes(), and skipBytes().

◆ streamerNames_

std::vector<FileCatalogItem> edm::StreamerInputFile::streamerNames_
private

keeps track of which file is in use at the moment

Definition at line 73 of file StreamerInputFile.h.

Referenced by compareHeader(), next(), and openNextFile().