CMS 3D CMS Logo

List of all members | Classes | Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes
LmfSource Class Reference

#include <LmfSource.h>

Inheritance diagram for LmfSource:
edm::ProducerSourceBase edm::PuttableSourceBase edm::InputSource edm::ProducerBase edm::ProductRegistryHelper

Classes

struct  IndexRecord
 

Public Member Functions

 LmfSource (const edm::ParameterSet &pset, const edm::InputSourceDescription &isd)
 
 ~LmfSource () override
 
- Public Member Functions inherited from edm::ProducerSourceBase
EventNumber_t event () const
 
unsigned int eventCreationDelay () const
 
EventID const & eventID () const
 
LuminosityBlockNumber_t luminosityBlock () const
 
unsigned int numberEventsInLumi () const
 
unsigned int numberEventsInRun () const
 
unsigned int numberEventsInThisLumi () const
 
unsigned int numberEventsInThisRun () const
 
TimeValue_t presentTime () const
 
 ProducerSourceBase (ParameterSet const &pset, InputSourceDescription const &desc, bool realData)
 
RunNumber_t run () const
 
unsigned int timeBetweenEvents () const
 
 ~ProducerSourceBase () noexcept(false) override
 
- Public Member Functions inherited from edm::PuttableSourceBase
bool hasAbilityToProduceInLumis () const final
 
bool hasAbilityToProduceInRuns () const final
 
 PuttableSourceBase (ParameterSet const &, InputSourceDescription const &)
 
void registerProducts () final
 Register any produced products. More...
 
- Public Member Functions inherited from edm::InputSource
std::shared_ptr< ActivityRegistryactReg () const
 Accessor for Activity Registry. More...
 
std::shared_ptr< BranchIDListHelper const > branchIDListHelper () const
 Accessors for branchIDListHelper. More...
 
std::shared_ptr< BranchIDListHelper > & branchIDListHelper ()
 
void closeFile (FileBlock *, bool cleaningUpAfterException)
 close current file More...
 
void doBeginJob ()
 Called by framework at beginning of job. More...
 
void doEndJob ()
 Called by framework at end of job. More...
 
ProcessingController::ForwardState forwardState () const
 
bool goToEvent (EventID const &eventID)
 
 InputSource (ParameterSet const &, InputSourceDescription const &)
 Constructor. More...
 
 InputSource (InputSource const &)=delete
 
void issueReports (EventID const &eventID, StreamID streamID)
 issue an event report More...
 
LuminosityBlockNumber_t luminosityBlock () const
 Accessor for current luminosity block number. More...
 
std::shared_ptr< LuminosityBlockAuxiliaryluminosityBlockAuxiliary () const
 Called by the framework to merge or insert lumi in principal cache. More...
 
int maxEvents () const
 
int maxLuminosityBlocks () const
 
ModuleDescription const & moduleDescription () const
 Accessor for 'module' description. More...
 
ItemType nextItemType ()
 Advances the source to the next item. More...
 
InputSourceoperator= (InputSource const &)=delete
 
ProcessConfiguration const & processConfiguration () const
 Accessor for Process Configuration. More...
 
std::string const & processGUID () const
 Accessor for global process identifier. More...
 
ProcessHistoryRegistry const & processHistoryRegistry () const
 Accessors for process history registry. More...
 
ProcessHistoryRegistryprocessHistoryRegistry ()
 
ProcessingMode processingMode () const
 RunsLumisAndEvents (default), RunsAndLumis, or Runs. More...
 
std::shared_ptr< ProductRegistry const > productRegistry () const
 Accessors for product registry. More...
 
std::shared_ptr< ProductRegistry > & productRegistry ()
 
bool randomAccess () const
 
void readAndMergeLumi (LuminosityBlockPrincipal &lbp)
 Read next luminosity block (same as a prior lumi) More...
 
void readAndMergeRun (RunPrincipal &rp)
 Read next run (same as a prior run) More...
 
void readEvent (EventPrincipal &ep, StreamContext &)
 Read next event. More...
 
bool readEvent (EventPrincipal &ep, EventID const &, StreamContext &)
 Read a specific event. More...
 
std::unique_ptr< FileBlockreadFile ()
 Read next file. More...
 
void readLuminosityBlock (LuminosityBlockPrincipal &lumiPrincipal, HistoryAppender &historyAppender)
 Read next luminosity block (new lumi) More...
 
std::shared_ptr< LuminosityBlockAuxiliaryreadLuminosityBlockAuxiliary ()
 Read next luminosity block Auxilary. More...
 
void readRun (RunPrincipal &runPrincipal, HistoryAppender &historyAppender)
 Read next run (new run) More...
 
std::shared_ptr< RunAuxiliaryreadRunAuxiliary ()
 Read next run Auxiliary. More...
 
ProcessHistoryID const & reducedProcessHistoryID () const
 
int remainingEvents () const
 
int remainingLuminosityBlocks () const
 
void repeat ()
 Reset the remaining number of events/lumis to the maximum number. More...
 
std::pair< SharedResourcesAcquirer *, std::recursive_mutex * > resourceSharedWithDelayedReader ()
 Returns nullptr if no resource shared between the Source and a DelayedReader. More...
 
ProcessingController::ReverseState reverseState () const
 
void rewind ()
 Begin again at the first event. More...
 
RunNumber_t run () const
 Accessor for current run number. More...
 
std::shared_ptr< RunAuxiliaryrunAuxiliary () const
 Called by the framework to merge or insert run in principal cache. More...
 
void setLuminosityBlockNumber_t (LuminosityBlockNumber_t lb)
 Set the luminosity block ID. More...
 
void setRunNumber (RunNumber_t r)
 Set the run number. More...
 
void skipEvents (int offset)
 
std::shared_ptr< ThinnedAssociationsHelper const > thinnedAssociationsHelper () const
 Accessors for thinnedAssociationsHelper. More...
 
std::shared_ptr< ThinnedAssociationsHelper > & thinnedAssociationsHelper ()
 
Timestamp const & timestamp () const
 Accessor for the current time, as seen by the input source. More...
 
virtual ~InputSource () noexcept(false)
 Destructor. More...
 
- Public Member Functions inherited from edm::ProducerBase
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
std::vector< edm::ProductResolverIndex > const & indiciesForPutProducts (BranchType iBranchType) const
 
 ProducerBase ()
 
std::vector< edm::ProductResolverIndex > const & putTokenIndexToProductResolverIndex () const
 
void registerProducts (ProducerBase *, ProductRegistry *, ModuleDescription const &)
 
std::function< void(BranchDescription const &)> registrationCallback () const
 used by the fwk to register list of products More...
 
void resolvePutIndicies (BranchType iBranchType, ModuleToResolverIndicies const &iIndicies, std::string const &moduleLabel)
 
 ~ProducerBase () noexcept(false) override
 

Private Member Functions

void checkFileNames ()
 
bool filter () const
 
bool nextEventWithinFile ()
 
bool openFile (int iFile)
 
void produce (edm::Event &e) override
 
bool readEvent (bool doSkip=false)
 
bool readEventWithinFile (bool doSkip)
 
bool readFileHeader ()
 
void readIndexTable ()
 
bool setRunAndEventInfo (edm::EventID &id, edm::TimeValue_t &time, edm::EventAuxiliary::ExperimentType &eType) override
 
std::string toString (edm::TimeValue_t &t) const
 

Private Attributes

uint32_t bx_
 
int calibTrig_
 
std::string currentFileName_
 
unsigned char dataFormatVers_
 
FEDRawData emptyFedBlock_
 
uint32_t eventNum_
 
FEDRawDataCollection fedColl_
 
int fedId_
 
std::vector< uint32_t > fileHeader_
 
std::ifstream fileList_
 
std::string fileListName_
 
std::vector< std::string > fileNames_
 
std::vector< uint32_t > header_
 
uint32_t iEvent_
 
uint32_t iEventInFile_
 
int iFile_
 
std::ifstream in_
 
std::vector< IndexRecordindexTable_
 
uint32_t indexTablePos_
 
std::string inputDir_
 
uint32_t lumiBlock_
 
int nFeds_
 
int nSecondsToSleep_
 
uint32_t orbitNum_
 
bool orderedRead_
 
unsigned preScale_
 
bool rcRead_
 
uint32_t runNum_
 
uint64_t timeStamp_
 
int verbosity_
 
bool watchFileList_
 

Static Private Attributes

static const unsigned fileHeaderSize = 2
 
static const unsigned char maxDataFormatVersion_ = 5
 
static const unsigned maxEvents_ = 1 << 20
 
static const unsigned maxEventSize_ = 1 << 20
 
static const unsigned char minDataFormatVersion_ = 4
 

Additional Inherited Members

- Public Types inherited from edm::InputSource
enum  ItemType {
  IsInvalid, IsStop, IsFile, IsRun,
  IsLumi, IsEvent, IsRepeat, IsSynchronize
}
 
enum  ProcessingMode { Runs, RunsAndLumis, RunsLumisAndEvents }
 
- Public Types inherited from edm::ProducerBase
using ModuleToResolverIndicies = std::unordered_multimap< std::string, std::tuple< edm::TypeID const *, const char *, edm::ProductResolverIndex >>
 
typedef ProductRegistryHelper::TypeLabelList TypeLabelList
 
- Static Public Member Functions inherited from edm::ProducerSourceBase
static void fillDescription (ParameterSetDescription &desc)
 
- Static Public Member Functions inherited from edm::InputSource
static const std::string & baseType ()
 
static void fillDescription (ParameterSetDescription &desc)
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &)
 
- Public Attributes inherited from edm::InputSource
signalslot::Signal< void(StreamContext const &, ModuleCallingContext const &)> postEventReadFromSourceSignal_
 
signalslot::Signal< void(StreamContext const &, ModuleCallingContext const &)> preEventReadFromSourceSignal_
 
- Protected Member Functions inherited from edm::PuttableSourceBase
void beginJob () override
 
- Protected Member Functions inherited from edm::InputSource
void decreaseRemainingEventsBy (int iSkipped)
 
bool eventCached () const
 
bool newLumi () const
 
bool newRun () const
 
ProcessHistoryRegistryprocessHistoryRegistryForUpdate ()
 
ProductRegistryproductRegistryUpdate ()
 
void reset () const
 
void resetEventCached ()
 
void resetLuminosityBlockAuxiliary (bool isNewLumi=true) const
 
void resetNewLumi ()
 
void resetNewRun ()
 
void resetRunAuxiliary (bool isNewRun=true) const
 
void setEventCached ()
 Called by the framework to merge or ached() const {return eventCached_;}. More...
 
void setLuminosityBlockAuxiliary (LuminosityBlockAuxiliary *lbp)
 
void setNewLumi ()
 
void setNewRun ()
 
void setRunAuxiliary (RunAuxiliary *rp)
 
void setTimestamp (Timestamp const &theTime)
 To set the current time, as seen by the input source. More...
 
ItemType state () const
 

Detailed Description

Definition at line 14 of file LmfSource.h.

Constructor & Destructor Documentation

LmfSource::LmfSource ( const edm::ParameterSet pset,
const edm::InputSourceDescription isd 
)

Definition at line 23 of file LmfSource.cc.

References checkFileNames(), Exception, fileList_, fileListName_, preScale_, and watchFileList_.

24  : ProducerSourceBase(pset, desc, true),
25  fileNames_(pset.getParameter<vector<string> >("fileNames")),
26  iFile_(-1),
27  fedId_(-1),
29  dataFormatVers_(5),
30  rcRead_(false),
31  preScale_(pset.getParameter<unsigned>("preScale")),
32  iEvent_(0),
33  iEventInFile_(0),
34  indexTablePos_(0),
35  orderedRead_(pset.getParameter<bool>("orderedRead")),
36  watchFileList_(pset.getParameter<bool>("watchFileList")),
37  fileListName_(pset.getParameter<std::string>("fileListName")),
38  inputDir_(pset.getParameter<std::string>("inputDir")),
39  nSecondsToSleep_(pset.getParameter<int>("nSecondsToSleep")),
40  verbosity_(pset.getUntrackedParameter<int>("verbosity")) {
41  if (preScale_ == 0)
42  preScale_ = 1;
43  produces<FEDRawDataCollection>();
44  // open fileListName
45  if (watchFileList_) {
46  fileList_.open(fileListName_.c_str());
47  if (fileList_.fail()) {
48  throw cms::Exception("FileListOpenError") << "Failed to open input file " << fileListName_ << "\n";
49  }
50  } else {
51  //throws a cms exception if error in fileNames parameter
53  }
54 }
int iFile_
Definition: LmfSource.h:64
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
int nSecondsToSleep_
Definition: LmfSource.h:197
static const unsigned fileHeaderSize
Definition: LmfSource.h:83
uint32_t indexTablePos_
Definition: LmfSource.h:150
bool rcRead_
Definition: LmfSource.h:138
std::string fileListName_
Definition: LmfSource.h:183
void checkFileNames()
Definition: LmfSource.cc:442
uint32_t iEventInFile_
Definition: LmfSource.h:148
uint32_t iEvent_
Definition: LmfSource.h:144
unsigned preScale_
Definition: LmfSource.h:140
ProducerSourceBase(ParameterSet const &pset, InputSourceDescription const &desc, bool realData)
std::string inputDir_
Definition: LmfSource.h:187
int verbosity_
Definition: LmfSource.h:201
unsigned char dataFormatVers_
Definition: LmfSource.h:132
int fedId_
Definition: LmfSource.h:77
bool watchFileList_
Definition: LmfSource.h:179
bool orderedRead_
Definition: LmfSource.h:174
std::ifstream fileList_
Definition: LmfSource.h:193
std::vector< uint32_t > fileHeader_
Definition: LmfSource.h:87
std::vector< std::string > fileNames_
Definition: LmfSource.h:60
LmfSource::~LmfSource ( )
inlineoverride

Member Function Documentation

void LmfSource::checkFileNames ( )
private

Checks paths specified in fileNames_ and remove eventual file: prefix.

Exceptions
cms::Exceptionin case of a non valid path

Definition at line 442 of file LmfSource.cc.

References Exception, MillePedeFileConverter_cfg::fileName, fileNames_, mps_fire::i, alignCSCRings::s, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by LmfSource().

442  {
443  for (unsigned i = 0; i < fileNames_.size(); ++i) {
445  const char s[] = "file:";
446  if (fileName.compare(0, sizeof(s) - 1, s) == 0) { //file: prefix => to strip
447  fileName.erase(fileName.begin(), fileName.begin() + sizeof(s) - 1);
448  }
449  if (fileName.find_first_of(":") != string::npos) {
450  throw cms::Exception("LmfSource") << "Character ':' is not allowed in paths specified fileNames "
451  << "parameter. Please note only local file (or NFS, AFS)"
452  << " is supported (no rfio, no /store)";
453  }
454  const char s1[] = "/store";
455  if (fileName.compare(0, sizeof(s1) - 1, s1) == 0) {
456  throw cms::Exception("LmfSource") << "CMSSW /store not supported by LmfSource. Only local file "
457  << "(or NFS/AFS) allowed. Path starting with /store not permitted";
458  }
459  }
460 }
std::vector< std::string > fileNames_
Definition: LmfSource.h:60
bool LmfSource::filter ( ) const
private
bool LmfSource::nextEventWithinFile ( )
private

Move to next event within the same file. Called by nextEvent method.

Returns
false in case of failure (end of file)

Definition at line 176 of file LmfSource.cc.

References gather_cfg::cout, currentFileName_, TauDecayModes::dec, iEventInFile_, iFile_, in_, indexTable_, orderedRead_, and verbosity_.

Referenced by readEvent().

176  {
177  if (iFile_ < 0)
178  return false; //no file opened.
179  if (orderedRead_) {
180  if (iEventInFile_ >= indexTable_.size())
181  return false;
182  if (verbosity_) {
183  cout << "[LmfSource] move to event with orbit Id " << indexTable_[iEventInFile_].orbit << " at file position 0x"
184  << hex << setfill('0') << setw(8) << indexTable_[iEventInFile_].filePos << setfill(' ') << dec << "\n";
185  }
186  const streampos pos = indexTable_[iEventInFile_].filePos;
187  in_.clear();
188  in_.seekg(pos);
189  if (in_.bad()) {
190  cout << "[LmfSource] Problem while reading file " << currentFileName_ << ". Problem with event index table?\n";
191  return false;
192  }
193  ++iEventInFile_;
194  return true;
195  } else {
196  return true;
197  }
198 }
int iFile_
Definition: LmfSource.h:64
std::ifstream in_
Definition: LmfSource.h:134
uint32_t iEventInFile_
Definition: LmfSource.h:148
int verbosity_
Definition: LmfSource.h:201
std::vector< IndexRecord > indexTable_
Definition: LmfSource.h:159
bool orderedRead_
Definition: LmfSource.h:174
std::string currentFileName_
Definition: LmfSource.h:191
bool LmfSource::openFile ( int  iFile)
private

Definition at line 129 of file LmfSource.cc.

References gather_cfg::cout, currentFileName_, Exception, fileList_, fileNames_, iEventInFile_, in_, inputDir_, nSecondsToSleep_, AlCaHLTBitMon_QueryRunRegistry::string, verbosity_, and watchFileList_.

Referenced by Vispa.Main.Application.Application::_readCommandLineAttributes(), Vispa.Main.Application.Application::doubleClickOnFile(), Vispa.Main.Application.Application::openFileDialog(), Vispa.Main.Application.Application::openRecentFileSlot(), readEvent(), and ~LmfSource().

129  {
130  iEventInFile_ = 0;
131  if (watchFileList_) {
132  for (;;) {
133  // read the first field of the line, which must be the filename
135  currentFileName_ = inputDir_ + "/" + currentFileName_;
136  if (!fileList_.fail()) {
137  // skip the rest of the line
138  std::string tmp_buffer;
139  std::getline(fileList_, tmp_buffer);
140  if (verbosity_)
141  cout << "[LmfSource]"
142  << "Opening file " << currentFileName_ << "\n";
143  in_.open(currentFileName_.c_str());
144  if (!in_.fail()) {
145  // file was successfully open
146  return true;
147  } else {
148  // skip file
149  edm::LogError("FileOpenError") << "Failed to open input file " << currentFileName_ << ". Skipping file\n";
150  in_.close();
151  in_.clear();
152  }
153  }
154  // if here, no new file is available: sleep and retry later
155  if (verbosity_)
156  std::cout << "[LmfSource]"
157  << " going to sleep 5 seconds\n";
158  sleep(nSecondsToSleep_);
159  fileList_.clear();
160  }
161  } else {
162  if (iFile > (int)fileNames_.size() - 1)
163  return false;
164  currentFileName_ = fileNames_[iFile];
165  if (verbosity_)
166  cout << "[LmfSource]"
167  << "Opening file " << currentFileName_ << "\n";
168  in_.open(currentFileName_.c_str());
169  if (in_.fail()) {
170  throw cms::Exception("FileOpenError") << "Failed to open input file " << currentFileName_ << "\n";
171  }
172  }
173  return true;
174 }
int nSecondsToSleep_
Definition: LmfSource.h:197
std::ifstream in_
Definition: LmfSource.h:134
uint32_t iEventInFile_
Definition: LmfSource.h:148
std::string inputDir_
Definition: LmfSource.h:187
int verbosity_
Definition: LmfSource.h:201
bool watchFileList_
Definition: LmfSource.h:179
std::ifstream fileList_
Definition: LmfSource.h:193
std::string currentFileName_
Definition: LmfSource.h:191
std::vector< std::string > fileNames_
Definition: LmfSource.h:60
void LmfSource::produce ( edm::Event e)
overrideprivatevirtual

Called by the framework after setRunAndEventInfo()

Implements edm::ProducerSourceBase.

Definition at line 113 of file LmfSource.cc.

References coll, gather_cfg::cout, fedColl_, eostools::move(), edm::Event::put(), and verbosity_.

Referenced by JSONExport.JsonExport::export(), HTMLExport.HTMLExport::export(), HTMLExport.HTMLExportStatic::export(), and ~LmfSource().

113  {
114  // bool rc;
115  // while(!((rc = readFileHeader()) & readEventPayload())){
116  // if(openFile(++iFile_)==false){//no more files
117  // if(verbosity_) cout << "[LmfSource]"
118  // << "No more input file";
119  // return false;
120  // }
121  // }
122  auto coll = std::make_unique<FEDRawDataCollection>();
123  coll->swap(fedColl_);
124  if (verbosity_)
125  cout << "[LmfSource] Putting FEDRawDataCollection in event\n";
126  evt.put(std::move(coll));
127 }
FEDRawDataCollection fedColl_
Definition: LmfSource.h:68
int verbosity_
Definition: LmfSource.h:201
JetCorrectorParametersCollection coll
Definition: classes.h:10
def move(src, dest)
Definition: eostools.py:511
bool LmfSource::readEvent ( bool  doSkip = false)
private

Reading next event

Parameters
doSkipif true skip event instead of reading it
Returns
true iff read out succeeded

Definition at line 200 of file LmfSource.cc.

References gather_cfg::cout, iFile_, in_, nextEventWithinFile(), openFile(), orderedRead_, rcRead_, readEventWithinFile(), readFileHeader(), readIndexTable(), and verbosity_.

Referenced by setRunAndEventInfo().

200  {
201  while (!(nextEventWithinFile() && readEventWithinFile(doSkip))) {
202  //failed to read event. Let's look for next file:
203  in_.close();
204  in_.clear();
205  bool rcOpen = openFile(++iFile_);
206  if (rcOpen == false) { //no more files
207  if (verbosity_)
208  cout << "[LmfSource]"
209  << "No more input file";
210  rcRead_ = false;
211  return rcRead_;
212  }
214  if (verbosity_)
215  cout << "File header readout " << (rcRead_ ? "succeeded" : "failed") << "\n";
216  if (rcRead_ && orderedRead_)
217  readIndexTable();
218  }
219  return rcRead_;
220 }
int iFile_
Definition: LmfSource.h:64
bool openFile(int iFile)
Definition: LmfSource.cc:129
std::ifstream in_
Definition: LmfSource.h:134
bool readEventWithinFile(bool doSkip)
Definition: LmfSource.cc:258
bool rcRead_
Definition: LmfSource.h:138
int verbosity_
Definition: LmfSource.h:201
bool orderedRead_
Definition: LmfSource.h:174
void readIndexTable()
Definition: LmfSource.cc:462
bool nextEventWithinFile()
Definition: LmfSource.cc:176
bool readFileHeader()
Definition: LmfSource.cc:56
bool LmfSource::readEventWithinFile ( bool  doSkip)
private

Read event from current opened file. Called by readEvent, which deals with file chaining Beware: readEventHeader must be called beforehand.

Parameters
doSkipif true skip event instead of reading it
Returns
true iff succeeded

Definition at line 258 of file LmfSource.cc.

References bx_, calibTrig_, popcon2dropbox::copy(), gather_cfg::cout, currentFileName_, FEDRawData::data(), dataFormatVers_, TauDecayModes::dec, eventNum_, Exception, fedColl_, FEDRawDataCollection::FEDData(), fedId_, header_, mps_fire::i, iEvent_, iFile_, in_, FEDNumbering::inRange(), lumiBlock_, maxEventSize_, minDataFormatVersion_, nFeds_, orbitNum_, rcRead_, FEDRawData::resize(), runNum_, FEDRawData::size(), protons_cff::t, timeStamp_, verbosity_, and globals_cff::x1.

Referenced by readEvent(), and ~LmfSource().

258  {
259  if (iFile_ == -1 || !rcRead_)
260  return false; //no file open
261  // or header reading failed
262  //number of 32-bit word to read first to get the event size
263  //field
264  const int timeStamp32[] = {0, 0}; //timestamp is 64-bit long
265  const int lumiBlock32[] = {2, 2};
266  const int runNum32[] = {3, 3};
267  const int orbitNum32[] = {4, 4};
268  const int bx32[] = {5, 5};
269  const int eventNum32[] = {6, 6};
270  const int activeFedId32[] = {7, -1};
271  const int calibTrig32[] = {-1, 7};
272  const int nFeds32[] = {-1, 8};
273  // const int reserved32[] = {-1,9};
274  const int evtHeadSize32[] = {8, 10};
275 
276  const unsigned char iv = dataFormatVers_ - minDataFormatVersion_;
277  assert(iv <= sizeof(timeStamp32) / sizeof(timeStamp32[0]));
278 
279  if ((int)header_.size() < evtHeadSize32[iv])
280  header_.resize(evtHeadSize32[iv]);
281 
282  if (verbosity_)
283  cout << "[LmfSource]"
284  << "Reading event header\n";
285 
286  in_.read((char*)&header_[0], evtHeadSize32[iv] * 4);
287  if (in_.bad()) { //reading error other than eof
288  throw cms::Exception("FileReadError") << "Error while reading from file " << currentFileName_;
289  }
290  if (in_.eof())
291  return false;
292 
293  if (verbosity_) {
294  cout << "[LmfSource]"
295  << "Event header (in hex):" << hex << setfill('0');
296  for (int i = 0; i < evtHeadSize32[iv]; ++i) {
297  if (i % 8 == 0)
298  cout << "\n";
299  cout << setw(8) << header_[i] << " ";
300  }
301  cout << dec << setfill(' ') << "\n";
302  }
303 
304  timeStamp_ = *(uint64_t*)&header_[timeStamp32[iv]];
305  lumiBlock_ = header_[lumiBlock32[iv]];
306  runNum_ = header_[runNum32[iv]];
307  orbitNum_ = header_[orbitNum32[iv]];
308  eventNum_ = header_[eventNum32[iv]];
309  bx_ = header_[bx32[iv]];
310  calibTrig_ = calibTrig32[iv] >= 0 ? header_[calibTrig32[iv]] : 0;
311  int activeFedId = activeFedId32[iv] >= 0 ? header_[activeFedId32[iv]] : ((calibTrig_ & 0x3F) + 600);
312  nFeds_ = nFeds32[iv] < 0 ? 1 : header_[nFeds32[iv]];
313 
314  if (verbosity_) {
315  time_t t = time_t(timeStamp_ >> 32);
316  div_t t_ms_us = div(timeStamp_ & 0xFFFFFFFF, 1000);
317  char tbuf[256];
318  strftime(tbuf, sizeof(tbuf), "%F %T", localtime(&t));
319  tbuf[sizeof(tbuf) - 1] = 0;
320  cout << "[LmfSource] "
321  << "timeStamp: " << /*toString(timeStamp_)*/ timeStamp_ << " (" << tbuf << " " << t_ms_us.quot
322  << " ms " << t_ms_us.rem << " us)\n"
323  << "lumiBlock: " << lumiBlock_ << "\n"
324  << "runNum: " << runNum_ << "\n"
325  << "orbitNum: " << orbitNum_ << "\n"
326  << "eventNum: " << eventNum_ << "\n"
327  << "bx: " << bx_ << "\n"
328  << "activeFedId: " << activeFedId << "\n"
329  << "Calib trigger type: " << ((calibTrig_ >> 8) & 0x3) << "\n"
330  << "Color: " << ((calibTrig_ >> 6) & 0x3) << "\n"
331  << "Side: " << ((calibTrig_ >> 11) & 0x1) << "\n"
332  << "nFeds: " << nFeds_ << "\n";
333  }
334 
335  const int dccLenOffset32 = 2;
336  const int fedIdOffset32 = 0;
337  const int nPreRead32 = 3;
338  vector<int32_t> buf(nPreRead32);
339  for (int iFed = 0; iFed < nFeds_; ++iFed) {
340  in_.read((char*)&buf[0], nPreRead32 * sizeof(uint32_t));
341 
342  if (verbosity_) {
343  cout << "[LmfSource] " << nPreRead32 << " first 32-bit words of "
344  << "FED block: " << hex << setfill('0');
345  for (unsigned i = 0; i < buf.size(); ++i) {
346  cout << "0x" << setw(8) << buf[i] << " ";
347  }
348  cout << dec << setfill(' ');
349  }
350 
351  if (in_.bad())
352  return false;
353 
354  const unsigned eventSize64 = buf[dccLenOffset32] & 0x00FFFFFF;
355  const unsigned eventSize32 = eventSize64 * 2;
356  const unsigned eventSize8 = eventSize64 * 8;
357  const unsigned fedId_ = (buf[fedIdOffset32] >> 8) & 0xFFF;
358 
359  if (eventSize8 > maxEventSize_) {
360  throw cms::Exception("FileReadError")
361  << "Size of event fragment (FED block) read from "
362  << " data of file " << currentFileName_ << "is unexpctively large (" << (eventSize8 >> 10) << " kByte). "
363  << "This must be an error (corrupted file?)\n";
364  }
365 
366  if (!FEDNumbering::inRange(fedId_)) {
367  throw cms::Exception("FileReadError") << "Invalid FED number read from data file.";
368  }
369 
370  int32_t toRead8 = (eventSize32 - nPreRead32) * sizeof(int32_t);
371 
372  if (toRead8 < 0) {
373  throw cms::Exception("FileReadError")
374  << "Event size error while reading an event from file " << currentFileName_ << "\n";
375  }
376 
377  if (doSkip) { //event to skip
378  if (verbosity_)
379  cout << "[LmfSource] "
380  << "Skipping on event. Move file pointer " << toRead8 << " ahead.\n";
381  in_.seekg(toRead8, ios::cur);
382  if (in_.bad()) { //reading error other than eof
383  throw cms::Exception("FileReadError") << "Error while reading from file " << currentFileName_;
384  }
385  } else {
386  //reads FED data:
387  FEDRawData& data_ = fedColl_.FEDData(fedId_);
388  data_.resize(eventSize8);
389 
390  //copy already read data:
391  copy(buf.begin(), buf.end(), (int32_t*)data_.data());
392 
393  in_.read((char*)(data_.data()) + nPreRead32 * 4, toRead8);
394 
395  if (in_.bad()) { //reading error other than eof
396  throw cms::Exception("FileReadError") << "Error while reading from file " << currentFileName_;
397  }
398 
399  if (verbosity_ && data_.size() > 16) {
400  cout << "[LmfSource]"
401  << "Head of DCC data (in hex):" << hex;
402  for (int i = 0; i < 16; ++i) {
403  if (i % 8 == 0)
404  cout << "\n";
405  cout << setw(8) << ((uint32_t*)data_.data())[i] << " ";
406  }
407  cout << dec << "\n";
408  }
409 
410  if (dataFormatVers_ <= 4) { //calib trigger in not in event header.
411  // gets it from DCC block
412  calibTrig_ = (((uint32_t*)data_.data())[5] & 0xFC0) | ((activeFedId - 600) & 0x3F);
413  if (verbosity_) {
414  cout << "[LmfSource] Old data format. "
415  "Uses information read from FED block to retrieve calibration "
416  "trigger type. Value is: 0x"
417  << hex << setfill('0') << setw(3) << calibTrig_ << setfill(' ') << dec << "\n";
418  }
419  }
420  }
421  if (in_.eof())
422  return false;
423  }
424  ++iEvent_;
425  return true;
426 }
int iFile_
Definition: LmfSource.h:64
uint32_t orbitNum_
Definition: LmfSource.h:130
std::ifstream in_
Definition: LmfSource.h:134
def copy(args, dbName)
uint32_t runNum_
Definition: LmfSource.h:127
bool rcRead_
Definition: LmfSource.h:138
std::vector< uint32_t > header_
Definition: LmfSource.h:81
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:47
uint32_t iEvent_
Definition: LmfSource.h:144
const FEDRawData & FEDData(int fedid) const
retrieve data for fed
int nFeds_
Definition: LmfSource.h:154
void resize(size_t newsize)
Definition: FEDRawData.cc:32
static const unsigned char minDataFormatVersion_
Definition: LmfSource.h:91
uint32_t bx_
Definition: LmfSource.h:128
FEDRawDataCollection fedColl_
Definition: LmfSource.h:68
int verbosity_
Definition: LmfSource.h:201
static const unsigned maxEventSize_
Definition: LmfSource.h:169
int calibTrig_
Definition: LmfSource.h:152
uint32_t lumiBlock_
Definition: LmfSource.h:126
unsigned long long uint64_t
Definition: Time.h:15
unsigned char dataFormatVers_
Definition: LmfSource.h:132
int fedId_
Definition: LmfSource.h:77
static bool inRange(int)
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:28
std::string currentFileName_
Definition: LmfSource.h:191
uint64_t timeStamp_
Definition: LmfSource.h:125
uint32_t eventNum_
Definition: LmfSource.h:129
bool LmfSource::readFileHeader ( )
private

Definition at line 56 of file LmfSource.cc.

References gather_cfg::cout, currentFileName_, dataFormatVers_, TauDecayModes::dec, Exception, fileHeader_, fileHeaderSize, mps_fire::i, iFile_, in_, indexTablePos_, createfilelist::int, maxDataFormatVersion_, minDataFormatVersion_, and verbosity_.

Referenced by readEvent(), and ~LmfSource().

56  {
57  if (iFile_ == -1)
58  return false; //no file open
59 
60  if (verbosity_)
61  cout << "[LmfSource]"
62  << "Opening file #" << (iFile_ + 1) << " '" << currentFileName_ << "'\n";
63 
64  in_.read((char*)&fileHeader_[0], fileHeaderSize * sizeof(uint32_t));
65 
66  if (in_.eof())
67  return false;
68 
69  if (verbosity_) {
70  cout << "[LmfSource]"
71  << "File header (in hex):" << hex;
72  for (unsigned i = 0; i < fileHeaderSize; ++i) {
73  if (i % 8 == 0)
74  cout << "\n";
75  cout << setw(8) << fileHeader_[i] << " ";
76  }
77  cout << dec << "\n";
78  }
79 
80  char id[4];
81 
82  id[0] = fileHeader_[0] & 0xFF;
83  id[1] = (fileHeader_[0] >> 8) & 0xFF;
84  id[2] = (fileHeader_[0] >> 16) & 0xFF;
85  id[3] = (fileHeader_[0] >> 24) & 0xFF;
86 
87  if (!(id[0] == 'L' && id[1] == 'M' && id[2] == 'F')) {
88  throw cms::Exception("FileReadError") << currentFileName_ << " is not a file in LMF format!";
89  }
90  dataFormatVers_ = id[3];
91  if (verbosity_)
92  cout << "[LmfSource]"
93  << "LMF format: " << (int)dataFormatVers_ << "\n";
94 
96  throw cms::Exception("FileReadError") << currentFileName_ << ": LMF format version " << (int)dataFormatVers_
97  << " is not supported by this release of LmfSource module";
98  }
99 
101 
102  if (verbosity_)
103  cout << "[LmfSource] File position of index table: 0x" << setfill('0') << hex << setw(8) << indexTablePos_
104  << setfill(' ') << dec << "\n";
105 
106  if (dataFormatVers_ < 5) {
107  in_.ignore(4);
108  }
109 
110  return true;
111 }
int iFile_
Definition: LmfSource.h:64
std::ifstream in_
Definition: LmfSource.h:134
static const unsigned fileHeaderSize
Definition: LmfSource.h:83
uint32_t indexTablePos_
Definition: LmfSource.h:150
static const unsigned char minDataFormatVersion_
Definition: LmfSource.h:91
int verbosity_
Definition: LmfSource.h:201
unsigned char dataFormatVers_
Definition: LmfSource.h:132
std::string currentFileName_
Definition: LmfSource.h:191
std::vector< uint32_t > fileHeader_
Definition: LmfSource.h:87
static const unsigned char maxDataFormatVersion_
Definition: LmfSource.h:95
void LmfSource::readIndexTable ( )
private

Reads event index table from input file. readFileHeader() must be called beforehand.

Definition at line 462 of file LmfSource.cc.

References currentFileName_, Exception, in_, indexTable_, indexTablePos_, and maxEvents_.

Referenced by readEvent().

462  {
463  stringstream errMsg;
464  errMsg << "Error while reading event index table of file " << currentFileName_ << ". Try to read it with "
465  << "option orderedRead disabled.\n";
466 
467  if (indexTablePos_ == 0)
468  throw cms::Exception("LmfSource") << errMsg.str();
469 
470  in_.clear();
471  in_.seekg(indexTablePos_);
472 
473  uint32_t nevts = 0;
474  in_.read((char*)&nevts, sizeof(nevts));
475  in_.ignore(4);
476  if (nevts > maxEvents_) {
477  throw cms::Exception("LmfSource") << "Number of events indicated in event index of file " << currentFileName_
478  << " is unexpectively large. File cannot be "
479  << "read in time-ordered event mode. See orderedRead parmater of "
480  << "LmfSource module.\n";
481  }
482  //if(in_.bad()) throw cms::Exception("LmfSource") << errMsg.str();
483  if (in_.bad())
484  throw cms::Exception("LmfSource") << errMsg.str();
485  indexTable_.resize(nevts);
486  in_.read((char*)&indexTable_[0], nevts * sizeof(IndexRecord));
487 }
std::ifstream in_
Definition: LmfSource.h:134
uint32_t indexTablePos_
Definition: LmfSource.h:150
static const unsigned maxEvents_
Definition: LmfSource.h:164
std::vector< IndexRecord > indexTable_
Definition: LmfSource.h:159
std::string currentFileName_
Definition: LmfSource.h:191
bool LmfSource::setRunAndEventInfo ( edm::EventID id,
edm::TimeValue_t time,
edm::EventAuxiliary::ExperimentType eType 
)
overrideprivatevirtual

Callback funtion to set run and event information (lumi block, run number, event number, timestamp) Called by the framework before produce()

Implements edm::ProducerSourceBase.

Definition at line 222 of file LmfSource.cc.

References gather_cfg::cout, eventNum_, fedColl_, FEDRawDataCollection::FEDData(), fedId_, filter(), lumiBlock_, readEvent(), FEDRawData::resize(), runNum_, timeStamp_, and verbosity_.

Referenced by ~LmfSource().

222  {
223  //empties collection:
224  if (fedId_ > 0) {
226  }
227  if (verbosity_)
228  cout << "[LmfSource]"
229  << "About to read event...\n";
230 
231  bool rc;
232  for (;;) {
233  if (filter()) { //event to read
234  rc = readEvent();
235  break; //either event is read or no more event
236  } else { //event to skip
237  rc = readEvent(true);
238  if (rc == false) { //no more events
239  break;
240  }
241  }
242  }
243 
244  if (!rc)
245  return false; //event readout failed
246 
247  if (verbosity_)
248  cout << "[LmfSource]"
249  << "Setting event time to " << /*toString(*/ timeStamp_ /*)*/ << ", "
250  << "Run number to " << runNum_ << ","
251  << "Event number to " << eventNum_ << "\n";
252 
253  time = timeStamp_;
254  id = EventID(runNum_, lumiBlock_, eventNum_);
255  return true;
256 }
uint32_t runNum_
Definition: LmfSource.h:127
const FEDRawData & FEDData(int fedid) const
retrieve data for fed
void resize(size_t newsize)
Definition: FEDRawData.cc:32
FEDRawDataCollection fedColl_
Definition: LmfSource.h:68
int verbosity_
Definition: LmfSource.h:201
uint32_t lumiBlock_
Definition: LmfSource.h:126
bool filter() const
Definition: LmfSource.cc:428
int fedId_
Definition: LmfSource.h:77
uint64_t timeStamp_
Definition: LmfSource.h:125
uint32_t eventNum_
Definition: LmfSource.h:129
bool readEvent(bool doSkip=false)
Definition: LmfSource.cc:200
std::string LmfSource::toString ( edm::TimeValue_t t) const
private

timeval to string conversion

Parameters
ttimestamp
Returns
human readable character string

Definition at line 430 of file LmfSource.cc.

References AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by ~LmfSource().

430  {
431  char buf[256];
432  const int secTousec = 1000 * 1000;
433  time_t tsec = t / secTousec;
434  uint32_t tusec = (uint32_t)(t - tsec);
435  strftime(buf, sizeof(buf), "%F %R %S s", localtime(&tsec));
436  buf[sizeof(buf) - 1] = 0;
437  stringstream buf2;
438  buf2 << (tusec + 500) / 1000;
439  return string(buf) + " " + buf2.str() + " ms";
440 }

Member Data Documentation

uint32_t LmfSource::bx_
private

Definition at line 128 of file LmfSource.h.

Referenced by readEventWithinFile().

int LmfSource::calibTrig_
private

Definition at line 152 of file LmfSource.h.

Referenced by readEventWithinFile().

std::string LmfSource::currentFileName_
private

currently open file

Definition at line 191 of file LmfSource.h.

Referenced by nextEventWithinFile(), openFile(), readEventWithinFile(), readFileHeader(), and readIndexTable().

unsigned char LmfSource::dataFormatVers_
private

Definition at line 132 of file LmfSource.h.

Referenced by readEventWithinFile(), and readFileHeader().

FEDRawData LmfSource::emptyFedBlock_
private

empty fed block

Definition at line 72 of file LmfSource.h.

uint32_t LmfSource::eventNum_
private

Definition at line 129 of file LmfSource.h.

Referenced by readEventWithinFile(), and setRunAndEventInfo().

FEDRawDataCollection LmfSource::fedColl_
private

Buffer for FED block collection

Definition at line 68 of file LmfSource.h.

Referenced by produce(), readEventWithinFile(), and setRunAndEventInfo().

int LmfSource::fedId_
private

FED ID present in FED data collection (only one FED at a time)

Definition at line 77 of file LmfSource.h.

Referenced by readEventWithinFile(), and setRunAndEventInfo().

std::vector<uint32_t> LmfSource::fileHeader_
private

Buffer for file header readout

Definition at line 87 of file LmfSource.h.

Referenced by readFileHeader().

const unsigned LmfSource::fileHeaderSize = 2
staticprivate

Definition at line 83 of file LmfSource.h.

Referenced by readFileHeader().

std::ifstream LmfSource::fileList_
private

Definition at line 193 of file LmfSource.h.

Referenced by LmfSource(), and openFile().

std::string LmfSource::fileListName_
private

name of the textfile with the input file list

Definition at line 183 of file LmfSource.h.

Referenced by LmfSource().

std::vector<std::string> LmfSource::fileNames_
private

List of names of the input files

Definition at line 60 of file LmfSource.h.

Referenced by checkFileNames(), and openFile().

std::vector<uint32_t> LmfSource::header_
private

Buffer for event header readout

Definition at line 81 of file LmfSource.h.

Referenced by readEventWithinFile().

uint32_t LmfSource::iEvent_
private

Sequential number of event.

Definition at line 144 of file LmfSource.h.

Referenced by filter(), and readEventWithinFile().

uint32_t LmfSource::iEventInFile_
private

Sequential number of event reset at each newly opened file

Definition at line 148 of file LmfSource.h.

Referenced by nextEventWithinFile(), and openFile().

int LmfSource::iFile_
private

Index of the current process file

Definition at line 64 of file LmfSource.h.

Referenced by nextEventWithinFile(), readEvent(), readEventWithinFile(), and readFileHeader().

std::ifstream LmfSource::in_
private
std::vector<IndexRecord> LmfSource::indexTable_
private

Table with file position of each event order by event time (orbit id used as time measurement).

Definition at line 159 of file LmfSource.h.

Referenced by nextEventWithinFile(), and readIndexTable().

uint32_t LmfSource::indexTablePos_
private

Definition at line 150 of file LmfSource.h.

Referenced by readFileHeader(), and readIndexTable().

std::string LmfSource::inputDir_
private

absolute path from which filename in fileListName_ is valid

Definition at line 187 of file LmfSource.h.

Referenced by openFile().

uint32_t LmfSource::lumiBlock_
private

Definition at line 126 of file LmfSource.h.

Referenced by readEventWithinFile(), and setRunAndEventInfo().

const unsigned char LmfSource::maxDataFormatVersion_ = 5
staticprivate

Maximal LMF data format version supported.

Definition at line 95 of file LmfSource.h.

Referenced by readFileHeader().

const unsigned LmfSource::maxEvents_ = 1 << 20
staticprivate

Limit of number of events to prevent exhausting memory with indexTable_ in case of file corruption.

Definition at line 164 of file LmfSource.h.

Referenced by readIndexTable().

const unsigned LmfSource::maxEventSize_ = 1 << 20
staticprivate

Limit on event size to prevent exhausting memory in case of error in the event size read from file.

Definition at line 169 of file LmfSource.h.

Referenced by readEventWithinFile().

const unsigned char LmfSource::minDataFormatVersion_ = 4
staticprivate

Minimal LMF data format version supported.

Definition at line 91 of file LmfSource.h.

Referenced by readEventWithinFile(), and readFileHeader().

int LmfSource::nFeds_
private

Definition at line 154 of file LmfSource.h.

Referenced by readEventWithinFile().

int LmfSource::nSecondsToSleep_
private

seconds to sleep before checking fileList_ for updates

Definition at line 197 of file LmfSource.h.

Referenced by openFile().

uint32_t LmfSource::orbitNum_
private

Definition at line 130 of file LmfSource.h.

Referenced by readEventWithinFile().

bool LmfSource::orderedRead_
private

Switch for enabling reading event in ordered using event index table

Definition at line 174 of file LmfSource.h.

Referenced by nextEventWithinFile(), and readEvent().

unsigned LmfSource::preScale_
private

Definition at line 140 of file LmfSource.h.

Referenced by filter(), and LmfSource().

bool LmfSource::rcRead_
private

Flags of last event read success: true->succeeded, false->failed

Definition at line 138 of file LmfSource.h.

Referenced by readEvent(), and readEventWithinFile().

uint32_t LmfSource::runNum_
private

Definition at line 127 of file LmfSource.h.

Referenced by readEventWithinFile(), and setRunAndEventInfo().

uint64_t LmfSource::timeStamp_
private

Definition at line 125 of file LmfSource.h.

Referenced by readEventWithinFile(), and setRunAndEventInfo().

int LmfSource::verbosity_
private
bool LmfSource::watchFileList_
private

enable reading input file list from text file and keep watching the text file for updates

Definition at line 179 of file LmfSource.h.

Referenced by LmfSource(), and openFile().