CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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::ConfigurableInputSource edm::InputSource edm::ProductRegistryHelper

Classes

struct  IndexRecord
 

Public Member Functions

 LmfSource (const edm::ParameterSet &pset, const edm::InputSourceDescription &isd)
 
virtual ~LmfSource ()
 
- Public Member Functions inherited from edm::ConfigurableInputSource
 ConfigurableInputSource (ParameterSet const &pset, InputSourceDescription const &desc, bool realData=true)
 
EventNumber_t event () const
 
unsigned int eventCreationDelay () 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
 
RunNumber_t run () const
 
unsigned int timeBetweenEvents () const
 
virtual ~ConfigurableInputSource ()
 
- Public Member Functions inherited from edm::InputSource
boost::shared_ptr
< ActivityRegistry
actReg () const
 Accessor for Activity Registry. More...
 
void closeFile (boost::shared_ptr< FileBlock >, bool cleaningUpAfterException)
 close current file More...
 
void doBeginJob ()
 Called by framework at beginning of job. More...
 
void doBeginLumi (LuminosityBlockPrincipal &lbp)
 Called by framework at beginning of lumi block. More...
 
void doBeginRun (RunPrincipal &rp)
 Called by framework at beginning of run. More...
 
void doEndJob ()
 Called by framework at end of job. More...
 
void doEndLumi (LuminosityBlockPrincipal &lbp, bool cleaningUpAfterException)
 Called by framework at end of lumi block. More...
 
void doEndRun (RunPrincipal &rp, bool cleaningUpAfterException)
 Called by framework at end of run. More...
 
void doPostForkReacquireResources (boost::shared_ptr< multicore::MessageReceiverForSource >)
 
void doPreForkReleaseResources ()
 Called by the framework before forking the process. More...
 
ProcessingController::ForwardState forwardState () const
 
bool goToEvent (EventID const &eventID)
 
 InputSource (ParameterSet const &, InputSourceDescription const &)
 Constructor. More...
 
void issueReports (EventID const &eventID)
 issue an event report More...
 
LuminosityBlockNumber_t luminosityBlock () const
 Accessor for current luminosity block number. More...
 
boost::shared_ptr
< LuminosityBlockAuxiliary
luminosityBlockAuxiliary () const
 Called by the framework to merge or insert lumi in principal cache. More...
 
int markLumi ()
 Mark lumi as read. More...
 
int markRun ()
 Mark run as read. More...
 
int maxEvents () const
 
int maxLuminosityBlocks () const
 
ModuleDescription const & moduleDescription () const
 Accessor for 'module' description. More...
 
ItemType nextItemType ()
 
bool primary () const
 Accessor for primary input source flag. More...
 
ProcessConfiguration const & processConfiguration () const
 Accessor for Process Configuration. More...
 
std::string const & processGUID () const
 Accessor for global process identifier. More...
 
ProcessingMode processingMode () const
 RunsLumisAndEvents (default), RunsAndLumis, or Runs. More...
 
boost::shared_ptr
< ProductRegistry const > 
productRegistry () const
 Accessor for product registry. More...
 
bool randomAccess () const
 
void readAndCacheLumi (bool merge, HistoryAppender &historyAppender)
 Read next luminosity block. More...
 
void readAndCacheRun (bool merge, HistoryAppender &historyAppender)
 Read next run. More...
 
EventPrincipalreadEvent (boost::shared_ptr< LuminosityBlockPrincipal > lbCache)
 
EventPrincipalreadEvent (EventID const &)
 Read a specific event. More...
 
boost::shared_ptr< FileBlockreadFile ()
 Read next file. More...
 
boost::shared_ptr
< LuminosityBlockAuxiliary
readLuminosityBlockAuxiliary ()
 Read next luminosity block Auxilary. More...
 
boost::shared_ptr< RunAuxiliaryreadRunAuxiliary ()
 Read next run Auxiliary. More...
 
ProcessHistoryID const & reducedProcessHistoryID () const
 
void registerProducts ()
 Register any produced products. More...
 
int remainingEvents () const
 
int remainingLuminosityBlocks () const
 
void repeat ()
 Reset the remaining number of events/lumis to the maximum number. More...
 
ProcessingController::ReverseState reverseState () const
 
void rewind ()
 Begin again at the first event. More...
 
RunNumber_t run () const
 Accessor for current run number. More...
 
boost::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)
 
Timestamp const & timestamp () const
 Accessor for the current time, as seen by the input source. More...
 
virtual ~InputSource ()
 Destructor. More...
 

Private Member Functions

void checkFileNames ()
 
bool filter () const
 
bool nextEventWithinFile ()
 
bool openFile (int iFile)
 
virtual bool produce (edm::Event &e)
 
bool readEvent (bool doSkip=false)
 
bool readEventWithinFile (bool doSkip)
 
bool readFileHeader ()
 
void readIndexTable ()
 
virtual void setRunAndEventInfo ()
 
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 unsigned fileHeaderSize = 2
 
static unsigned char maxDataFormatVersion_ = 5
 
static const unsigned maxEvents_ = 1<<20
 
static const unsigned maxEventSize_ = 1<<20
 
static unsigned char minDataFormatVersion_ = 4
 

Additional Inherited Members

- Public Types inherited from edm::InputSource
enum  ItemType {
  IsInvalid, IsStop, IsFile, IsRun,
  IsLumi, IsEvent, IsRepeat
}
 
enum  ProcessingMode { Runs, RunsAndLumis, RunsLumisAndEvents }
 
typedef
ProductRegistryHelper::TypeLabelList 
TypeLabelList
 
- Static Public Member Functions inherited from edm::ConfigurableInputSource
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 &)
 
- Protected Member Functions inherited from edm::ConfigurableInputSource
void reallyReadEvent ()
 
void setEventNumber (EventNumber_t e)
 
void setTime (TimeValue_t t)
 
- Protected Member Functions inherited from edm::InputSource
void decreaseRemainingEventsBy (int iSkipped)
 
EventPrincipaleventPrincipalCache ()
 
boost::shared_ptr
< LuminosityBlockPrincipal >
const 
luminosityBlockPrincipal () const
 
PrincipalCache const & principalCache () const
 
PrincipalCacheprincipalCache ()
 
ProductRegistryproductRegistryUpdate () const
 
void reset () const
 
void resetLuminosityBlockAuxiliary () const
 
void resetRunAuxiliary () const
 
boost::shared_ptr
< RunPrincipal > const 
runPrincipal () const
 
void setLuminosityBlockAuxiliary (LuminosityBlockAuxiliary *lbp)
 
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 26 of file LmfSource.cc.

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

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

Definition at line 25 of file LmfSource.h.

25 {}

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

References edm::hlt::Exception, convertXMLtoSQLite_cfg::fileName, fileNames_, i, and alignCSCRings::s.

Referenced by LmfSource().

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

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

Referenced by readEvent().

182  {
183  if(iFile_<0) return false; //no file opened.
184  if(orderedRead_){
185  if(iEventInFile_>=indexTable_.size()) return false;
186  if(verbosity_){
187  cout << "[LmfSource] move to event with orbit Id "
188  << indexTable_[iEventInFile_].orbit
189  << " at file position 0x"
190  << hex << setfill('0')
191  << setw(8) << indexTable_[iEventInFile_].filePos
192  << setfill(' ') << dec << "\n";
193  }
194  const streampos pos = indexTable_[iEventInFile_].filePos;
195  in_.clear();
196  in_.seekg(pos);
197  if(in_.bad()){
198  cout << "[LmfSource] Problem while reading file "
199  << currentFileName_ << ". Problem with event index table?\n";
200  return false;
201  }
202  ++iEventInFile_;
203  return true;
204  } else{
205  return true;
206  }
207 }
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
tuple cout
Definition: gather_cfg.py:121
bool LmfSource::openFile ( int  iFile)
private

Definition at line 137 of file LmfSource.cc.

References gather_cfg::cout, currentFileName_, edm::hlt::Exception, fileList_, fileNames_, iEventInFile_, in_, inputDir_, nSecondsToSleep_, stor::utils::sleep(), 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(), and readEvent().

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

Called by the framework after setRunAndEventInfo()

Implements edm::ConfigurableInputSource.

Definition at line 119 of file LmfSource.cc.

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

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

119  {
120  // bool rc;
121  // while(!((rc = readFileHeader()) & readEventPayload())){
122  // if(openFile(++iFile_)==false){//no more files
123  // if(verbosity_) cout << "[LmfSource]"
124  // << "No more input file";
125  // return false;
126  // }
127  // }
128  if(rcRead_){//readout succeeded
129  auto_ptr<FEDRawDataCollection> coll(new FEDRawDataCollection);
130  coll->swap(fedColl_);
131  if(verbosity_) cout << "[LmfSource] Putting FEDRawDataCollection in event\n";
132  evt.put(coll);
133  }
134  return rcRead_;
135 }
bool rcRead_
Definition: LmfSource.h:139
FEDRawDataCollection fedColl_
Definition: LmfSource.h:68
int verbosity_
Definition: LmfSource.h:202
JetCorrectorParametersCollection coll
Definition: classes.h:14
tuple cout
Definition: gather_cfg.py:121
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 209 of file LmfSource.cc.

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

Referenced by setRunAndEventInfo().

209  {
210  while(!(nextEventWithinFile() && readEventWithinFile(doSkip))){
211  //failed to read event. Let's look for next file:
212  in_.close();
213  in_.clear();
214  bool rcOpen = openFile(++iFile_);
215  if(rcOpen==false){//no more files
216  if(verbosity_) cout << "[LmfSource]"
217  << "No more input file";
218  rcRead_ = false;
219  return rcRead_;
220  }
222  if(verbosity_) cout << "File header readout "
223  << (rcRead_?"succeeded":"failed") << "\n";
225  }
226  return rcRead_;
227 }
int iFile_
Definition: LmfSource.h:64
bool openFile(int iFile)
Definition: LmfSource.cc:137
std::ifstream in_
Definition: LmfSource.h:135
bool readEventWithinFile(bool doSkip)
Definition: LmfSource.cc:264
bool rcRead_
Definition: LmfSource.h:139
int verbosity_
Definition: LmfSource.h:202
bool orderedRead_
Definition: LmfSource.h:175
void readIndexTable()
Definition: LmfSource.cc:472
bool nextEventWithinFile()
Definition: LmfSource.cc:182
bool readFileHeader()
Definition: LmfSource.cc:61
tuple cout
Definition: gather_cfg.py:121
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 264 of file LmfSource.cc.

References bx_, calibTrig_, filterCSVwithJSON::copy, gather_cfg::cout, currentFileName_, FEDRawData::data(), dataFormatVers_, eventNum_, edm::hlt::Exception, fedColl_, FEDRawDataCollection::FEDData(), fedId_, header_, i, iEvent_, iFile_, in_, FEDNumbering::inRange(), lumiBlock_, maxEventSize_, minDataFormatVersion_, nFeds_, orbitNum_, rcRead_, FEDRawData::resize(), runNum_, FEDRawData::size(), timeStamp_, and verbosity_.

Referenced by readEvent().

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

Definition at line 61 of file LmfSource.cc.

References gather_cfg::cout, currentFileName_, dataFormatVers_, edm::hlt::Exception, fileHeader_, fileHeaderSize, i, iFile_, in_, indexTablePos_, maxDataFormatVersion_, minDataFormatVersion_, and verbosity_.

Referenced by readEvent().

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

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

Definition at line 472 of file LmfSource.cc.

References currentFileName_, edm::hlt::Exception, in_, indexTable_, indexTablePos_, maxEvents_, and launcher::nevts.

Referenced by readEvent().

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

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

Reimplemented from edm::ConfigurableInputSource.

Definition at line 229 of file LmfSource.cc.

References gather_cfg::cout, eventNum_, fedColl_, FEDRawDataCollection::FEDData(), fedId_, filter(), lumiBlock_, readEvent(), FEDRawData::resize(), runNum_, edm::ConfigurableInputSource::setEventNumber(), edm::InputSource::setLuminosityBlockNumber_t(), edm::InputSource::setRunNumber(), edm::ConfigurableInputSource::setTime(), timeStamp_, and verbosity_.

229  {
230  //empties collection:
231  if(fedId_>0){
233  }
234  if(verbosity_) cout << "[LmfSource]"
235  << "About to read event...\n";
236 
237  bool rc;
238  for(;;){
239  if(filter()){//event to read
240  rc = readEvent();
241  break; //either event is read or no more event
242  } else { //event to skip
243  rc = readEvent(true);
244  if(rc==false){//no more events
245  break;
246  }
247  }
248  }
249 
250  if(!rc) return; //event readout failed
251 
252  if(verbosity_) cout << "[LmfSource]"
253  << "Setting event time to "
254  << /*toString(*/timeStamp_/*)*/ << ", "
255  << "Run number to " << runNum_ << ","
256  << "Event number to " << eventNum_ << "\n";
257 
260  setEventNumber(eventNum_);
262 }
uint32_t runNum_
Definition: LmfSource.h:128
void setLuminosityBlockNumber_t(LuminosityBlockNumber_t lb)
Set the luminosity block ID.
Definition: InputSource.h:146
const FEDRawData & FEDData(int fedid) const
retrieve data for fed
void resize(size_t newsize)
Definition: FEDRawData.cc:33
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:433
int fedId_
Definition: LmfSource.h:77
void setRunNumber(RunNumber_t r)
Set the run number.
Definition: InputSource.h:143
void setEventNumber(EventNumber_t e)
uint64_t timeStamp_
Definition: LmfSource.h:126
uint32_t eventNum_
Definition: LmfSource.h:130
tuple cout
Definition: gather_cfg.py:121
bool readEvent(bool doSkip=false)
Definition: LmfSource.cc:209
std::string LmfSource::toString ( edm::TimeValue_t t) const
private

timeval to string conversion

Parameters
ttimestamp
Returns
human readable character string

Definition at line 437 of file LmfSource.cc.

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

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().

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().

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().

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 produce(), 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().