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 24 of file LmfSource.cc.

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

25  :
26  ProducerSourceBase(pset, desc, true),
27  fileNames_(pset.getParameter<vector<string> >("fileNames")),
28  iFile_ (-1),
29  fedId_(-1),
31  dataFormatVers_(5),
32  rcRead_(false),
33  preScale_(pset.getParameter<unsigned>("preScale")),
34  iEvent_(0),
35  iEventInFile_(0),
36  indexTablePos_(0),
37  orderedRead_(pset.getParameter<bool>("orderedRead")),
38  watchFileList_(pset.getParameter<bool>("watchFileList")),
39  fileListName_(pset.getParameter<std::string>("fileListName")),
40  inputDir_(pset.getParameter<std::string>("inputDir")),
41  nSecondsToSleep_(pset.getParameter<int>("nSecondsToSleep")),
42  verbosity_(pset.getUntrackedParameter<int>("verbosity"))
43 {
44  if(preScale_==0) preScale_ = 1;
45  produces<FEDRawDataCollection>();
46  // open fileListName
47  if (watchFileList_) {
48  fileList_.open( fileListName_.c_str() );
49  if (fileList_.fail()) {
50  throw cms::Exception("FileListOpenError")
51  << "Failed to open input file " << fileListName_ << "\n";
52  }
53  } else {
54  //throws a cms exception if error in fileNames parameter
56  }
57 }
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:198
static const unsigned fileHeaderSize
Definition: LmfSource.h:83
uint32_t indexTablePos_
Definition: LmfSource.h:151
bool rcRead_
Definition: LmfSource.h:139
std::string fileListName_
Definition: LmfSource.h:184
void checkFileNames()
Definition: LmfSource.cc:450
uint32_t iEventInFile_
Definition: LmfSource.h:149
uint32_t iEvent_
Definition: LmfSource.h:145
unsigned preScale_
Definition: LmfSource.h:141
ProducerSourceBase(ParameterSet const &pset, InputSourceDescription const &desc, bool realData)
std::string inputDir_
Definition: LmfSource.h:188
int verbosity_
Definition: LmfSource.h:202
unsigned char dataFormatVers_
Definition: LmfSource.h:133
int fedId_
Definition: LmfSource.h:77
bool watchFileList_
Definition: LmfSource.h:180
bool orderedRead_
Definition: LmfSource.h:175
std::ifstream fileList_
Definition: LmfSource.h:194
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 450 of file LmfSource.cc.

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

Referenced by LmfSource().

450  {
451  for(unsigned i = 0; i < fileNames_.size(); ++i){
453  const char s[] = "file:";
454  if(fileName.compare(0, sizeof(s)-1, s)==0){ //file: prefix => to strip
455  fileName.erase(fileName.begin(),
456  fileName.begin() + sizeof(s)-1);
457  }
458  if(fileName.find_first_of(":")!=string::npos){
459  throw cms::Exception("LmfSource")
460  << "Character ':' is not allowed in paths specified fileNames "
461  << "parameter. Please note only local file (or NFS, AFS)"
462  << " is supported (no rfio, no /store)";
463  }
464  const char s1[] = "/store";
465  if(fileName.compare(0, sizeof(s1)-1, s1)==0){
466  throw cms::Exception("LmfSource")
467  << "CMSSW /store not supported by LmfSource. Only local file "
468  << "(or NFS/AFS) allowed. Path starting with /store not permitted";
469  }
470  }
471 }
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 177 of file LmfSource.cc.

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

Referenced by readEvent().

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

Definition at line 132 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().

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

117  {
118  // bool rc;
119  // while(!((rc = readFileHeader()) & readEventPayload())){
120  // if(openFile(++iFile_)==false){//no more files
121  // if(verbosity_) cout << "[LmfSource]"
122  // << "No more input file";
123  // return false;
124  // }
125  // }
126  auto coll = std::make_unique<FEDRawDataCollection>();
127  coll->swap(fedColl_);
128  if(verbosity_) cout << "[LmfSource] Putting FEDRawDataCollection in event\n";
129  evt.put(std::move(coll));
130 }
FEDRawDataCollection fedColl_
Definition: LmfSource.h:68
int verbosity_
Definition: LmfSource.h:202
JetCorrectorParametersCollection coll
Definition: classes.h:10
def move(src, dest)
Definition: eostools.py:510
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 204 of file LmfSource.cc.

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

Referenced by setRunAndEventInfo().

204  {
205  while(!(nextEventWithinFile() && readEventWithinFile(doSkip))){
206  //failed to read event. Let's look for next file:
207  in_.close();
208  in_.clear();
209  bool rcOpen = openFile(++iFile_);
210  if(rcOpen==false){//no more files
211  if(verbosity_) cout << "[LmfSource]"
212  << "No more input file";
213  rcRead_ = false;
214  return rcRead_;
215  }
217  if(verbosity_) cout << "File header readout "
218  << (rcRead_?"succeeded":"failed") << "\n";
220  }
221  return rcRead_;
222 }
int iFile_
Definition: LmfSource.h:64
bool openFile(int iFile)
Definition: LmfSource.cc:132
std::ifstream in_
Definition: LmfSource.h:135
bool readEventWithinFile(bool doSkip)
Definition: LmfSource.cc:258
bool rcRead_
Definition: LmfSource.h:139
int verbosity_
Definition: LmfSource.h:202
bool orderedRead_
Definition: LmfSource.h:175
void readIndexTable()
Definition: LmfSource.cc:473
bool nextEventWithinFile()
Definition: LmfSource.cc:177
bool readFileHeader()
Definition: LmfSource.cc:59
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(), lumiQTWidget::t, timeStamp_, verbosity_, and globals_cff::x1.

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

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

Definition at line 59 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().

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

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

Definition at line 473 of file LmfSource.cc.

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

Referenced by readEvent().

473  {
474 
475  stringstream errMsg;
476  errMsg << "Error while reading event index table of file "
477  << currentFileName_ << ". Try to read it with "
478  << "option orderedRead disabled.\n";
479 
480  if(indexTablePos_==0) throw cms::Exception("LmfSource") << errMsg.str();
481 
482  in_.clear();
483  in_.seekg(indexTablePos_);
484 
485  uint32_t nevts = 0;
486  in_.read((char*)&nevts, sizeof(nevts));
487  in_.ignore(4);
488  if(nevts>maxEvents_){
489  throw cms::Exception("LmfSource")
490  << "Number of events indicated in event index of file "
491  << currentFileName_ << " is unexpectively large. File cannot be "
492  << "read in time-ordered event mode. See orderedRead parmater of "
493  << "LmfSource module.\n";
494  }
495  //if(in_.bad()) throw cms::Exception("LmfSource") << errMsg.str();
496  if(in_.bad()) throw cms::Exception("LmfSource") << errMsg.str();
497  indexTable_.resize(nevts);
498  in_.read((char*)&indexTable_[0], nevts*sizeof(IndexRecord));
499 }
std::ifstream in_
Definition: LmfSource.h:135
uint32_t indexTablePos_
Definition: LmfSource.h:151
static const unsigned maxEvents_
Definition: LmfSource.h:165
std::vector< IndexRecord > indexTable_
Definition: LmfSource.h:160
std::string currentFileName_
Definition: LmfSource.h:192
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 224 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().

224  {
225  //empties collection:
226  if(fedId_>0){
228  }
229  if(verbosity_) cout << "[LmfSource]"
230  << "About to read event...\n";
231 
232  bool rc;
233  for(;;){
234  if(filter()){//event to read
235  rc = readEvent();
236  break; //either event is read or no more event
237  } else { //event to skip
238  rc = readEvent(true);
239  if(rc==false){//no more events
240  break;
241  }
242  }
243  }
244 
245  if(!rc) return false; //event readout failed
246 
247  if(verbosity_) cout << "[LmfSource]"
248  << "Setting event time to "
249  << /*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:128
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:202
uint32_t lumiBlock_
Definition: LmfSource.h:127
bool filter() const
Definition: LmfSource.cc:434
int fedId_
Definition: LmfSource.h:77
uint64_t timeStamp_
Definition: LmfSource.h:126
uint32_t eventNum_
Definition: LmfSource.h:130
bool readEvent(bool doSkip=false)
Definition: LmfSource.cc:204
std::string LmfSource::toString ( edm::TimeValue_t t) const
private

timeval to string conversion

Parameters
ttimestamp
Returns
human readable character string

Definition at line 438 of file LmfSource.cc.

References AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by ~LmfSource().

438  {
439  char buf[256];
440  const int secTousec = 1000*1000;
441  time_t tsec = t/secTousec;
442  uint32_t tusec = (uint32_t)(t-tsec);
443  strftime(buf, sizeof(buf), "%F %R %S s", localtime(&tsec));
444  buf[sizeof(buf)-1] = 0;
445  stringstream buf2;
446  buf2 << (tusec+500)/1000;
447  return string(buf) + " " + buf2.str() + " ms";
448 }

Member Data Documentation

uint32_t LmfSource::bx_
private

Definition at line 129 of file LmfSource.h.

Referenced by readEventWithinFile().

int LmfSource::calibTrig_
private

Definition at line 153 of file LmfSource.h.

Referenced by readEventWithinFile().

std::string LmfSource::currentFileName_
private

currently open file

Definition at line 192 of file LmfSource.h.

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

unsigned char LmfSource::dataFormatVers_
private

Definition at line 133 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 130 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 194 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 184 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 145 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 149 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 160 of file LmfSource.h.

Referenced by nextEventWithinFile(), and readIndexTable().

uint32_t LmfSource::indexTablePos_
private

Definition at line 151 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 188 of file LmfSource.h.

Referenced by openFile().

uint32_t LmfSource::lumiBlock_
private

Definition at line 127 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 96 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 165 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 170 of file LmfSource.h.

Referenced by readEventWithinFile().

const unsigned char LmfSource::minDataFormatVersion_ = 4
staticprivate

Minimal LMF data format version supported.

Definition at line 92 of file LmfSource.h.

Referenced by readEventWithinFile(), and readFileHeader().

int LmfSource::nFeds_
private

Definition at line 155 of file LmfSource.h.

Referenced by readEventWithinFile().

int LmfSource::nSecondsToSleep_
private

seconds to sleep before checking fileList_ for updates

Definition at line 198 of file LmfSource.h.

Referenced by openFile().

uint32_t LmfSource::orbitNum_
private

Definition at line 131 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 175 of file LmfSource.h.

Referenced by nextEventWithinFile(), and readEvent().

unsigned LmfSource::preScale_
private

Definition at line 141 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 139 of file LmfSource.h.

Referenced by readEvent(), and readEventWithinFile().

uint32_t LmfSource::runNum_
private

Definition at line 128 of file LmfSource.h.

Referenced by readEventWithinFile(), and setRunAndEventInfo().

uint64_t LmfSource::timeStamp_
private

Definition at line 126 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 180 of file LmfSource.h.

Referenced by LmfSource(), and openFile().