CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes
FedRawDataInputSource Class Reference

#include <FedRawDataInputSource.h>

Inheritance diagram for FedRawDataInputSource:
edm::RawInputSource edm::InputSource edm::ProductRegistryHelper

Public Member Functions

 FedRawDataInputSource (edm::ParameterSet const &, edm::InputSourceDescription const &)
 
virtual ~FedRawDataInputSource ()
 
- Public Member Functions inherited from edm::RawInputSource
 RawInputSource (ParameterSet const &pset, InputSourceDescription const &desc)
 
virtual ~RawInputSource ()
 
- Public Member Functions inherited from edm::InputSource
boost::shared_ptr
< ActivityRegistry
actReg () const
 Accessor for Activity Registry. More...
 
boost::shared_ptr
< BranchIDListHelper
branchIDListHelper () const
 Accessor for branchIDListHelper. More...
 
void closeFile (FileBlock *, bool cleaningUpAfterException)
 close current file More...
 
void doBeginJob ()
 Called by framework at beginning of job. More...
 
void doBeginLumi (LuminosityBlockPrincipal &lbp, ProcessContext const *)
 Called by framework at beginning of lumi block. More...
 
void doBeginRun (RunPrincipal &rp, ProcessContext const *)
 Called by framework at beginning of run. More...
 
void doEndJob ()
 Called by framework at end of job. More...
 
void doEndLumi (LuminosityBlockPrincipal &lbp, bool cleaningUpAfterException, ProcessContext const *)
 Called by framework at end of lumi block. More...
 
void doEndRun (RunPrincipal &rp, bool cleaningUpAfterException, ProcessContext const *)
 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...
 
 InputSource (InputSource const &)=delete
 
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 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
 
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...
 
ProcessHistoryRegistry const & processHistoryRegistry () const
 Const accessor for process history registry. More...
 
ProcessHistoryRegistryprocessHistoryRegistryForUpdate ()
 Non-const accessor for process history registry. 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 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...
 
boost::shared_ptr
< LuminosityBlockAuxiliary
readLuminosityBlockAuxiliary ()
 Read next luminosity block Auxilary. More...
 
void readRun (RunPrincipal &runPrincipal, HistoryAppender &historyAppender)
 Read next run (new run) 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)
 
bool skipForForking ()
 
Timestamp const & timestamp () const
 Accessor for the current time, as seen by the input source. More...
 
virtual ~InputSource ()
 Destructor. More...
 

Protected Member Functions

virtual bool checkNextEvent () override
 
virtual void read (edm::EventPrincipal &eventPrincipal) override
 
- Protected Member Functions inherited from edm::RawInputSource
void makeEvent (EventPrincipal &eventPrincipal, EventAuxiliary const &eventAuxiliary)
 
void setInputFileTransitionsEachEvent ()
 
- Protected Member Functions inherited from edm::InputSource
void decreaseRemainingEventsBy (int iSkipped)
 
bool eventCached () const
 
boost::shared_ptr
< LuminosityBlockPrincipal >
const 
luminosityBlockPrincipal () const
 
bool newLumi () const
 
bool newRun () const
 
ProcessHistoryRegistryprocessHistoryRegistryUpdate () const
 
ProductRegistryproductRegistryUpdate () const
 
void reset () const
 
void resetEventCached ()
 
void resetLuminosityBlockAuxiliary (bool isNewLumi=true) const
 
void resetNewLumi ()
 
void resetNewRun ()
 
void resetRunAuxiliary (bool isNewRun=true) const
 
boost::shared_ptr
< RunPrincipal > const 
runPrincipal () 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...
 
virtual void skip (int offset)
 
ItemType state () const
 

Private Member Functions

int cacheNextEvent ()
 
void closeCurrentFile ()
 
bool eofReached () const
 
edm::Timestamp fillFEDRawDataCollection (std::auto_ptr< FEDRawDataCollection > &) const
 
bool grabNextJsonFile (boost::filesystem::path const &)
 
void maybeOpenNewLumiSection (const uint32_t lumiSection)
 
void openDataFile (std::string const &)
 
int openNextFile ()
 
virtual void postForkReacquireResources (boost::shared_ptr< edm::multicore::MessageReceiverForSource >) override
 
virtual void preForkReleaseResources () override
 
int readNextChunkIntoBuffer ()
 
void renameToNextFree () const
 
virtual void rewind_ () override
 
int searchForNextFile ()
 

Private Attributes

unsigned char * bufferCursor_
 
uint32_t bufferLeft_
 
const std::string buInputDir_
 
unsigned int currentInputEventCount_
 
boost::filesystem::path currentInputJson_
 
unsigned int currentLumiSection_
 
const edm::DaqProvenanceHelper daqProvenanceHelper_
 
unsigned char * dataBuffer_
 
bool eorFileSeen_
 
std::unique_ptr< FRDEventMsgViewevent_
 
const unsigned int eventChunkSize_
 
edm::EventID eventID_
 
FILE * fileStream_
 
const std::string fuOutputDir_
 
const bool getLSFromFilename_
 
boost::filesystem::path openFile_
 
edm::ProcessHistoryID processHistoryID_
 
Json::Reader reader_
 
const edm::RunNumber_t runNumber_
 
const bool testModeNoBuilderUnit_
 
const bool verifyAdler32_
 

Additional Inherited Members

- Public Types inherited from edm::InputSource
enum  ItemType {
  IsInvalid, IsStop, IsFile, IsRun,
  IsLumi, IsEvent, IsRepeat, IsSynchronize
}
 
enum  ProcessingMode { Runs, RunsAndLumis, RunsLumisAndEvents }
 
typedef
ProductRegistryHelper::TypeLabelList 
TypeLabelList
 
- Static Public Member Functions inherited from edm::RawInputSource
static void fillDescription (ParameterSetDescription &description)
 
- 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 &)
 

Detailed Description

Definition at line 26 of file FedRawDataInputSource.h.

Constructor & Destructor Documentation

FedRawDataInputSource::FedRawDataInputSource ( edm::ParameterSet const &  pset,
edm::InputSourceDescription const &  desc 
)
explicit

Definition at line 38 of file FedRawDataInputSource.cc.

References edm::Timestamp::beginOfTime(), edm::DaqProvenanceHelper::daqInit(), daqProvenanceHelper_, eventChunkSize_, edm::Timestamp::invalidTimestamp(), processHistoryID_, edm::InputSource::processHistoryRegistryForUpdate(), edm::InputSource::productRegistryUpdate(), edm::InputSource::runAuxiliary(), runNumber_, edm::InputSource::setNewRun(), edm::InputSource::setRunAuxiliary(), and testModeNoBuilderUnit_.

39  :
40  edm::RawInputSource(pset, desc),
41  eventChunkSize_(pset.getUntrackedParameter<unsigned int> ("eventChunkSize",16)),
42  getLSFromFilename_(pset.getUntrackedParameter<bool> ("getLSFromFilename", true)),
43  verifyAdler32_(pset.getUntrackedParameter<bool> ("verifyAdler32", true)),
44  testModeNoBuilderUnit_(edm::Service<evf::EvFDaqDirector>()->getTestModeNoBuilderUnit()),
49  fileStream_(0),
50  eventID_(),
55  eorFileSeen_(false),
56  dataBuffer_(new unsigned char[1024 * 1024 * eventChunkSize_]),
58  bufferLeft_(0)
59 {
60  char thishost[256];
61  gethostname(thishost, 255);
62  edm::LogInfo("FedRawDataInputSource") << "test mode: "
63  << testModeNoBuilderUnit_ << ", read-ahead chunk size: " << eventChunkSize_
64  << " on host " << thishost;
65 
67  setNewRun();
70  runAuxiliary()->setProcessHistoryID(processHistoryID_);
71 }
static Timestamp invalidTimestamp()
Definition: Timestamp.h:101
static Timestamp beginOfTime()
Definition: Timestamp.h:103
boost::filesystem::path currentInputJson_
const edm::RunNumber_t runNumber_
edm::ProcessHistoryID processHistoryID_
const edm::DaqProvenanceHelper daqProvenanceHelper_
ProcessHistoryID daqInit(ProductRegistry &productRegistry, ProcessHistoryRegistry &processHistoryRegistry) const
const std::string fuOutputDir_
const unsigned int eventChunkSize_
ProductRegistry & productRegistryUpdate() const
Definition: InputSource.h:343
const std::string buInputDir_
boost::shared_ptr< RunAuxiliary > runAuxiliary() const
Called by the framework to merge or insert run in principal cache.
Definition: InputSource.h:255
ProcessHistoryRegistry & processHistoryRegistryForUpdate()
Non-const accessor for process history registry.
Definition: InputSource.h:173
void setRunAuxiliary(RunAuxiliary *rp)
Definition: InputSource.h:346
unsigned int currentInputEventCount_
FedRawDataInputSource::~FedRawDataInputSource ( )
virtual

Definition at line 73 of file FedRawDataInputSource.cc.

References fileStream_.

74 {
75  if (fileStream_)
76  fclose(fileStream_);
77  fileStream_ = 0;
78 }

Member Function Documentation

int FedRawDataInputSource::cacheNextEvent ( )
private

Definition at line 148 of file FedRawDataInputSource.cc.

References bufferCursor_, bufferLeft_, CastorDataFrameFilter_impl::check(), event_, edm::hlt::Exception, dttmaxenums::L, readNextChunkIntoBuffer(), and verifyAdler32_.

Referenced by checkNextEvent().

149 {
150  //return values or cachenext -1 :== run ended, 0:== LS ended, 1 :== cache good
151  if ( bufferLeft_ < (4 + 1024) * sizeof(uint32) ) //minimal size to fit any version of FRDEventHeader
152  {
154  if ( check ==-1) return 0;
155  if ( check ==-100) return -1;
156  }
157 
158  event_.reset( new FRDEventMsgView(bufferCursor_) );
159 
160  const uint32_t msgSize = event_->size();
161 
162  if ( bufferLeft_ < msgSize )
163  {
164  if ( readNextChunkIntoBuffer()<0 || bufferLeft_ < msgSize )
165  {
166  throw cms::Exception("FedRawDataInputSource::cacheNextEvent") <<
167  "Premature end of input file while reading event data";
168  }
169  event_.reset( new FRDEventMsgView(bufferCursor_) );
170  }
171 
172  if ( verifyAdler32_ && event_->version() >= 3 )
173  {
174  uint32_t adler = adler32(0L,Z_NULL,0);
175  adler = adler32(adler,(Bytef*)event_->payload(),event_->eventSize());
176 
177  if ( adler != event_->adler32() ) {
178  throw cms::Exception("FedRawDataInputSource::cacheNextEvent") <<
179  "Found a wrong Adler32 checksum: expected 0x" << std::hex << event_->adler32() <<
180  " but calculated 0x" << adler;
181  }
182  }
183 
184  bufferLeft_ -= msgSize;
185  bufferCursor_ += msgSize;
186 
187  return 1;
188 }
bool check(const DataFrame &df, bool capcheck, bool dvercheck)
unsigned int uint32
Definition: MsgTools.h:13
std::unique_ptr< FRDEventMsgView > event_
bool FedRawDataInputSource::checkNextEvent ( )
overrideprotectedvirtual

Implements edm::RawInputSource.

Definition at line 80 of file FedRawDataInputSource.cc.

References cacheNextEvent(), closeCurrentFile(), currentLumiSection_, event_, eventID_, getLSFromFilename_, maybeOpenNewLumiSection(), edm::InputSource::resetLuminosityBlockAuxiliary(), and edm::InputSource::setEventCached().

81 {
82  int eventAvailable = cacheNextEvent();
83  if (eventAvailable < 0) {
84  // run has ended
87  return false;
88  }
89  else if(eventAvailable == 0) {
90  edm::LogInfo("FedRawDataInputSource") << "No Event files at this time, but a new lumisection was detected : " << currentLumiSection_;
91 
92  return true;
93  }
94  else {
95  if (!getLSFromFilename_) {
96  //get new lumi from file header
98  }
99 
101  event_->run(),
103  event_->event());
104 
105  setEventCached();
106 
107  return true;
108  }
109 }
void maybeOpenNewLumiSection(const uint32_t lumiSection)
void setEventCached()
Called by the framework to merge or ached() const {return eventCached_;}.
Definition: InputSource.h:377
std::unique_ptr< FRDEventMsgView > event_
void resetLuminosityBlockAuxiliary(bool isNewLumi=true) const
Definition: InputSource.h:358
void FedRawDataInputSource::closeCurrentFile ( )
private

Definition at line 235 of file FedRawDataInputSource.cc.

References fileStream_, openFile_, python.multivaluedict::remove(), renameToNextFree(), and testModeNoBuilderUnit_.

Referenced by checkNextEvent(), and readNextChunkIntoBuffer().

236 {
237  if (fileStream_) {
238 
239  edm::LogInfo("FedRawDataInputSource") << "Closing input file " << openFile_.string();
240 
241  fclose(fileStream_);
242  fileStream_ = 0;
243 
244  if (!testModeNoBuilderUnit_) {
245  boost::filesystem::remove(openFile_); // won't work in case of forked children
246  } else {
248  }
249  }
250 }
boost::filesystem::path openFile_
bool FedRawDataInputSource::eofReached ( ) const
private

Definition at line 223 of file FedRawDataInputSource.cc.

References trackerHits::c, and fileStream_.

Referenced by readNextChunkIntoBuffer().

224 {
225  if (fileStream_ == 0)
226  return true;
227 
228  int c;
229  c = fgetc(fileStream_);
230  ungetc(c, fileStream_);
231 
232  return (c == EOF);
233 }
edm::Timestamp FedRawDataInputSource::fillFEDRawDataCollection ( std::auto_ptr< FEDRawDataCollection > &  rawData) const
private

Definition at line 286 of file FedRawDataInputSource.cc.

References FEDRawData::data(), event(), event_, fedt_struct::eventsize, evf::evtn::evm_board_setformat(), FED_EVSZ_EXTRACT, FED_SOID_EXTRACT, evf::evtn::getgpshigh(), evf::evtn::getgpslow(), FEDNumbering::MINTriggerGTPFEDID, FEDRawData::resize(), and fedh_struct::sourceid.

Referenced by read().

287 {
288  edm::Timestamp tstamp;
289  uint32_t eventSize = event_->eventSize();
290  char* event = (char*)event_->payload();
291 
292  while (eventSize > 0) {
293  eventSize -= sizeof(fedt_t);
294  const fedt_t* fedTrailer = (fedt_t*) (event + eventSize);
295  const uint32_t fedSize = FED_EVSZ_EXTRACT(fedTrailer->eventsize) << 3; //trailer length counts in 8 bytes
296  eventSize -= (fedSize - sizeof(fedh_t));
297  const fedh_t* fedHeader = (fedh_t *) (event + eventSize);
298  const uint16_t fedId = FED_SOID_EXTRACT(fedHeader->sourceid);
299  if (fedId == FEDNumbering::MINTriggerGTPFEDID) {
301  const uint64_t gpsl = evf::evtn::getgpslow((unsigned char*) fedHeader);
302  const uint64_t gpsh = evf::evtn::getgpshigh((unsigned char*) fedHeader);
303  tstamp = edm::Timestamp(static_cast<edm::TimeValue_t> ((gpsh << 32) + gpsl));
304  }
305  FEDRawData& fedData = rawData->FEDData(fedId);
306  fedData.resize(fedSize);
307  memcpy(fedData.data(), event + eventSize, fedSize);
308  }
309  assert(eventSize == 0);
310 
311  return tstamp;
312 }
unsigned int getgpshigh(const unsigned char *)
struct fedh_struct fedh_t
unsigned int sourceid
Definition: fed_header.h:32
void evm_board_setformat(size_t size)
void resize(size_t newsize)
Definition: FEDRawData.cc:32
struct fedt_struct fedt_t
#define FED_EVSZ_EXTRACT(a)
Definition: fed_trailer.h:36
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
unsigned long long uint64_t
Definition: Time.h:15
std::unique_ptr< FRDEventMsgView > event_
unsigned int eventsize
Definition: fed_trailer.h:33
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:28
unsigned int getgpslow(const unsigned char *)
#define FED_SOID_EXTRACT(a)
Definition: fed_header.h:53
bool FedRawDataInputSource::grabNextJsonFile ( boost::filesystem::path const &  jsonSourcePath)
private

Definition at line 353 of file FedRawDataInputSource.cc.

References filterCSVwithJSON::copy, currentInputEventCount_, currentInputJson_, data, jsoncollector::DataPoint::deserialize(), reco::dp, alignCSCRings::e, cppFunctionSkipper::exception, fuOutputDir_, jsoncollector::DataPoint::getData(), Json::Reader::parse(), getHLTPrescaleColumns::path, reader_, python.multivaluedict::remove(), AlCaHLTBitMon_QueryRunRegistry::string, and testModeNoBuilderUnit_.

Referenced by searchForNextFile().

354 {
355  try {
356  // assemble json destination path
358 
359  std::ostringstream fileNameWithPID;
360  fileNameWithPID << jsonSourcePath.stem().string() << "_pid"
361  << std::setfill('0') << std::setw(5) << getpid() << ".jsn";
362  const boost::filesystem::path filePathWithPID(fileNameWithPID.str());
363  jsonDestPath /= fileNameWithPID.str();
364 
365  edm::LogInfo("FedRawDataInputSource") << " JSON rename " << jsonSourcePath << " to "
366  << jsonDestPath;
367 
369  boost::filesystem::copy(jsonSourcePath,jsonDestPath);
370  else {
371  //boost::filesystem::rename(jsonSourcePath,jsonDestPath);
372  boost::filesystem::copy(jsonSourcePath,jsonDestPath);
373  boost::filesystem::remove(jsonSourcePath);
374  }
375 
376  currentInputJson_ = jsonDestPath; // store location for later deletion.
377  boost::filesystem::ifstream ij(jsonDestPath);
378  Json::Value deserializeRoot;
379  DataPoint dp;
380  if(!reader_.parse(ij,deserializeRoot)){
381  throw std::runtime_error("Cannot deserialize input JSON file");
382  }
383  else {
384  dp.deserialize(deserializeRoot);
385  std::string data = dp.getData()[0];
386  currentInputEventCount_=atoi(data.c_str()); //all this is horrible...
387  }
388 
389  return true;
390  }
391 
392  catch (const boost::filesystem::filesystem_error& ex)
393  {
394  // Input dir gone?
395  edm::LogError("FedRawDataInputSource") << " - grabNextFile BOOST FILESYSTEM ERROR CAUGHT: " << ex.what()
396  << " - Maybe the BU run dir disappeared? Ending process with code 0...";
397  _exit(0);
398  }
399  catch (std::runtime_error e)
400  {
401  // Another process grabbed the file and NFS did not register this
402  edm::LogError("FedRawDataInputSource") << " - grabNextFile runtime Exception: " << e.what() << std::endl;
403  }
404  catch (std::exception e)
405  {
406  // BU run directory disappeared?
407  edm::LogError("FedRawDataInputSource") << " - grabNextFileSOME OTHER EXCEPTION OCCURED!!!! ->" << e.what()
408  << std::endl;
409  }
410  return false;
411 }
bool parse(const std::string &document, Value &root, bool collectComments=true)
Read a Value from a JSON document.
Represents a JSON value.
Definition: value.h:111
boost::filesystem::path currentInputJson_
virtual void deserialize(Json::Value &root)
Definition: DataPoint.cc:36
const std::string fuOutputDir_
std::vector< std::string > getData() const
Definition: DataPoint.h:40
auto dp
Definition: deltaR.h:24
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
unsigned int currentInputEventCount_
void FedRawDataInputSource::maybeOpenNewLumiSection ( const uint32_t  lumiSection)
private

Definition at line 111 of file FedRawDataInputSource.cc.

References currentLumiSection_, newFWLiteAna::found, edm::Timestamp::invalidTimestamp(), edm::InputSource::luminosityBlock(), edm::InputSource::luminosityBlockAuxiliary(), processHistoryID_, edm::InputSource::resetLuminosityBlockAuxiliary(), edm::InputSource::run(), edm::InputSource::runAuxiliary(), and edm::InputSource::setLuminosityBlockAuxiliary().

Referenced by checkNextEvent(), and searchForNextFile().

112 {
114  || luminosityBlockAuxiliary()->luminosityBlock() != lumiSection) {
115 
116  if ( currentLumiSection_ > 0 ) {
117  const string fuEoLS =
119  struct stat buf;
120  bool found = (stat(fuEoLS.c_str(), &buf) == 0);
121  if ( !found ) {
122  int eol_fd = open(fuEoLS.c_str(), O_RDWR|O_CREAT, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH);
123  close(eol_fd);
124  }
125  }
126 
127  currentLumiSection_ = lumiSection;
128 
130 
131  timeval tv;
132  gettimeofday(&tv, 0);
133  const edm::Timestamp lsopentime( (unsigned long long) tv.tv_sec * 1000000 + (unsigned long long) tv.tv_usec );
134 
135  edm::LuminosityBlockAuxiliary* lumiBlockAuxiliary =
137  runAuxiliary()->run(),
138  lumiSection, lsopentime,
140 
141  setLuminosityBlockAuxiliary(lumiBlockAuxiliary);
142  luminosityBlockAuxiliary()->setProcessHistoryID(processHistoryID_);
143 
144  edm::LogInfo("FedRawDataInputSource") << "New lumi section " << lumiSection << " opened";
145  }
146 }
static Timestamp invalidTimestamp()
Definition: Timestamp.h:101
boost::shared_ptr< LuminosityBlockAuxiliary > luminosityBlockAuxiliary() const
Called by the framework to merge or insert lumi in principal cache.
Definition: InputSource.h:258
RunNumber_t run() const
Accessor for current run number.
Definition: InputSource.cc:600
void setLuminosityBlockAuxiliary(LuminosityBlockAuxiliary *lbp)
Definition: InputSource.h:350
edm::ProcessHistoryID processHistoryID_
LuminosityBlockNumber_t luminosityBlock() const
Accessor for current luminosity block number.
Definition: InputSource.cc:606
void resetLuminosityBlockAuxiliary(bool isNewLumi=true) const
Definition: InputSource.h:358
boost::shared_ptr< RunAuxiliary > runAuxiliary() const
Called by the framework to merge or insert run in principal cache.
Definition: InputSource.h:255
void FedRawDataInputSource::openDataFile ( std::string const &  nextFile)
private

Definition at line 413 of file FedRawDataInputSource.cc.

References edm::hlt::Exception, fileStream_, and openFile_.

Referenced by searchForNextFile().

414 {
415  const int fileDescriptor = open(nextFile.c_str(), O_RDONLY);
416  if (fileDescriptor != -1) {
417  fileStream_ = fdopen(fileDescriptor, "rb");
418  openFile_ = nextFile;
419  edm::LogInfo("FedRawDataInputSource") << " opened file " << nextFile;
420  }
421  else
422  {
423  throw cms::Exception("FedRawDataInputSource::openDataFile") <<
424  " failed to open file " << nextFile << " fd:" << fileDescriptor;
425  }
426 }
boost::filesystem::path openFile_
int FedRawDataInputSource::openNextFile ( )
private

Definition at line 252 of file FedRawDataInputSource.cc.

References eorFileSeen_, and searchForNextFile().

Referenced by readNextChunkIntoBuffer().

253 {
254  int nextfile = -1;
255  while((nextfile = searchForNextFile())<0){
256  if(eorFileSeen_)
257  return 0;
258  else{
259  edm::LogInfo("FedRawDataInputSource") << "No file for me... sleep and try again..." << std::endl;
260  usleep(100000);
261  }
262  }
263  return nextfile;
264 }
void FedRawDataInputSource::postForkReacquireResources ( boost::shared_ptr< edm::multicore::MessageReceiverForSource )
overrideprivatevirtual

Definition at line 442 of file FedRawDataInputSource.cc.

References edm::Timestamp::beginOfTime(), edm::Timestamp::invalidTimestamp(), runNumber_, and edm::InputSource::setRunAuxiliary().

443 {
444  InputSource::rewind();
448 }
static Timestamp invalidTimestamp()
Definition: Timestamp.h:101
static Timestamp beginOfTime()
Definition: Timestamp.h:103
const edm::RunNumber_t runNumber_
void setRunAuxiliary(RunAuxiliary *rp)
Definition: InputSource.h:346
void FedRawDataInputSource::preForkReleaseResources ( )
overrideprivatevirtual

Reimplemented from edm::RawInputSource.

Definition at line 439 of file FedRawDataInputSource.cc.

440 {}
void FedRawDataInputSource::read ( edm::EventPrincipal eventPrincipal)
overrideprotectedvirtual

Implements edm::RawInputSource.

Definition at line 266 of file FedRawDataInputSource.cc.

References printConversionInfo::aux, edm::DaqProvenanceHelper::constBranchDescription_, currentInputEventCount_, daqProvenanceHelper_, edm::DaqProvenanceHelper::dummyProvenance_, eventID_, fillFEDRawDataCollection(), edm::RawInputSource::makeEvent(), edm::EventAuxiliary::PhysicsTrigger, edm::InputSource::processGUID(), processHistoryID_, edm::EventPrincipal::put(), and edm::EventAuxiliary::setProcessHistoryID().

Referenced by Vispa.Plugins.EdmBrowser.EdmDataAccessor.EdmDataAccessor::goto(), and Vispa.Plugins.EdmBrowser.EdmDataAccessor.EdmDataAccessor::setFilterBranches().

267 {
269  std::auto_ptr<FEDRawDataCollection> rawData(new FEDRawDataCollection);
270  edm::Timestamp tstamp = fillFEDRawDataCollection(rawData);
271 
272  edm::EventAuxiliary aux(eventID_, processGUID(), tstamp, true,
274  aux.setProcessHistoryID(processHistoryID_);
275  makeEvent(eventPrincipal, aux);
276 
279 
282 
283  return;
284 }
ProductProvenance dummyProvenance_
std::string const & processGUID() const
Accessor for global process identifier.
Definition: InputSource.h:210
edm::ProcessHistoryID processHistoryID_
const edm::DaqProvenanceHelper daqProvenanceHelper_
edm::Timestamp fillFEDRawDataCollection(std::auto_ptr< FEDRawDataCollection > &) const
void makeEvent(EventPrincipal &eventPrincipal, EventAuxiliary const &eventAuxiliary)
unsigned int currentInputEventCount_
BranchDescription const constBranchDescription_
void put(BranchDescription const &bd, WrapperOwningHolder const &edp, ProductProvenance const &productProvenance)
int FedRawDataInputSource::readNextChunkIntoBuffer ( )
private

Definition at line 190 of file FedRawDataInputSource.cc.

References bufferCursor_, bufferLeft_, closeCurrentFile(), dataBuffer_, eofReached(), eventChunkSize_, fileStream_, and openNextFile().

Referenced by cacheNextEvent().

191 {
192  //this function is called when we reach the end of the buffer (i.e. bytes to read are more than bytes left in buffer)
193  // NOTA BENE: A positive or 0 value is returned if data are buffered
194  // a value of -1 indicates no data can be buffered but there is a new
195  // lumi section to account for
196  int fileStatus = 100; //file is healthy for now
197  if (eofReached()){
199  fileStatus = openNextFile(); // this can now return even if there is
200  //no file only temporarily
201  if(fileStatus==0) return -100; //should only happen when requesting the next event header and the run is over
202  }
203  if(fileStatus==100){ //either file was not over or a new one was opened
204  if (bufferLeft_ == 0) { //in the rare case the last byte barely fit
205  uint32_t chunksize = 1024 * 1024 * eventChunkSize_;
206  bufferLeft_ = fread((void*) dataBuffer_, sizeof(unsigned char),
207  chunksize, fileStream_); //reads a maximum of chunksize bytes from file into buffer
208  } else { //refill the buffer after having moved the bufferLeft_ bytes at the head
209  uint32_t chunksize = 1024 * 1024 * eventChunkSize_ - bufferLeft_;
210  memcpy((void*) dataBuffer_, bufferCursor_, bufferLeft_); //this copy could be avoided
211  bufferLeft_ += fread((void*) (dataBuffer_ + bufferLeft_),
212  sizeof(unsigned char), chunksize, fileStream_);
213  }
214  bufferCursor_ = dataBuffer_; // reset the cursor at the beginning of the buffer
215  return bufferLeft_;
216  }
217  else{
218  // no file to read but a new lumi section has been cached
219  return -1;
220  }
221 }
const unsigned int eventChunkSize_
void FedRawDataInputSource::renameToNextFree ( ) const
private

Definition at line 428 of file FedRawDataInputSource.cc.

References openFile_, getHLTPrescaleColumns::path, and source.

Referenced by closeCurrentFile().

429 {
431  boost::filesystem::path destination( edm::Service<evf::EvFDaqDirector>()->getJumpFilePath() );
432 
433  edm::LogInfo("FedRawDataInputSource") << "Instead of delete, RENAME: " << openFile_
434  << " to: " << destination.string();
435  boost::filesystem::rename(source,destination);
436  boost::filesystem::rename(source.replace_extension(".jsn"),destination.replace_extension(".jsn"));
437 }
boost::filesystem::path openFile_
static std::string const source
Definition: EdmProvDump.cc:43
void FedRawDataInputSource::rewind_ ( )
overrideprivatevirtual

Reimplemented from edm::RawInputSource.

Definition at line 450 of file FedRawDataInputSource.cc.

451 {}
int FedRawDataInputSource::searchForNextFile ( )
private

Definition at line 314 of file FedRawDataInputSource.cc.

References currentInputEventCount_, currentInputJson_, currentLumiSection_, eorFileSeen_, edm::hlt::Exception, getLSFromFilename_, grabNextJsonFile(), dataset::jsonFile, python.rootplot.utilities::ls(), maybeOpenNewLumiSection(), openDataFile(), getHLTPrescaleColumns::path, evf::FastMonitoringService::startedLookingForFile(), evf::FastMonitoringService::stoppedLookingForFile(), and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by openNextFile().

315 {
316  int retval = -1;
318  throw cms::Exception("RuntimeError") << "Went to search for next file but according to BU more events in "
319  << currentInputJson_.string();
320  }
321 
322  std::string nextFile;
323  uint32_t ls;
324 
325  edm::LogInfo("FedRawDataInputSource") << "Asking for next file... to the DaqDirector";
327  fms->startedLookingForFile();
328  bool fileIsOKToGrab = edm::Service<evf::EvFDaqDirector>()->updateFuLock(ls,nextFile,eorFileSeen_);
329 
330  if (fileIsOKToGrab) {
331 
332  edm::LogInfo("FedRawDataInputSource") << "The director says to grab: " << nextFile;
333 
334  fms->stoppedLookingForFile();
335 
337  jsonFile.replace_extension(".jsn");
338  assert( grabNextJsonFile(jsonFile) );
339  openDataFile(nextFile);
340  retval = 100;
341  } else {
342  edm::LogInfo("FedRawDataInputSource") << "The DAQ Director has nothing for me! ";
343  }
344 
345  while( getLSFromFilename_ && ls > currentLumiSection_ ) {
347  retval = 1;
348  }
349 
350  return retval;
351 }
void maybeOpenNewLumiSection(const uint32_t lumiSection)
tuple jsonFile
Definition: dataset.py:390
boost::filesystem::path currentInputJson_
bool grabNextJsonFile(boost::filesystem::path const &)
void openDataFile(std::string const &)
unsigned int currentInputEventCount_

Member Data Documentation

unsigned char* FedRawDataInputSource::bufferCursor_
private

Definition at line 81 of file FedRawDataInputSource.h.

Referenced by cacheNextEvent(), and readNextChunkIntoBuffer().

uint32_t FedRawDataInputSource::bufferLeft_
private

Definition at line 82 of file FedRawDataInputSource.h.

Referenced by cacheNextEvent(), and readNextChunkIntoBuffer().

const std::string FedRawDataInputSource::buInputDir_
private

Definition at line 62 of file FedRawDataInputSource.h.

unsigned int FedRawDataInputSource::currentInputEventCount_
private

Definition at line 76 of file FedRawDataInputSource.h.

Referenced by grabNextJsonFile(), read(), and searchForNextFile().

boost::filesystem::path FedRawDataInputSource::currentInputJson_
private

Definition at line 75 of file FedRawDataInputSource.h.

Referenced by grabNextJsonFile(), and searchForNextFile().

unsigned int FedRawDataInputSource::currentLumiSection_
private
const edm::DaqProvenanceHelper FedRawDataInputSource::daqProvenanceHelper_
private

Definition at line 65 of file FedRawDataInputSource.h.

Referenced by FedRawDataInputSource(), and read().

unsigned char* FedRawDataInputSource::dataBuffer_
private

Definition at line 80 of file FedRawDataInputSource.h.

Referenced by readNextChunkIntoBuffer().

bool FedRawDataInputSource::eorFileSeen_
private

Definition at line 78 of file FedRawDataInputSource.h.

Referenced by openNextFile(), and searchForNextFile().

std::unique_ptr<FRDEventMsgView> FedRawDataInputSource::event_
private
const unsigned int FedRawDataInputSource::eventChunkSize_
private

Definition at line 53 of file FedRawDataInputSource.h.

Referenced by FedRawDataInputSource(), and readNextChunkIntoBuffer().

edm::EventID FedRawDataInputSource::eventID_
private

Definition at line 71 of file FedRawDataInputSource.h.

Referenced by checkNextEvent(), and read().

FILE* FedRawDataInputSource::fileStream_
private
const std::string FedRawDataInputSource::fuOutputDir_
private

Definition at line 63 of file FedRawDataInputSource.h.

Referenced by grabNextJsonFile().

const bool FedRawDataInputSource::getLSFromFilename_
private

Definition at line 56 of file FedRawDataInputSource.h.

Referenced by checkNextEvent(), and searchForNextFile().

boost::filesystem::path FedRawDataInputSource::openFile_
private

Definition at line 69 of file FedRawDataInputSource.h.

Referenced by closeCurrentFile(), openDataFile(), and renameToNextFree().

edm::ProcessHistoryID FedRawDataInputSource::processHistoryID_
private

Definition at line 72 of file FedRawDataInputSource.h.

Referenced by FedRawDataInputSource(), maybeOpenNewLumiSection(), and read().

Json::Reader FedRawDataInputSource::reader_
private

Definition at line 84 of file FedRawDataInputSource.h.

Referenced by grabNextJsonFile().

const edm::RunNumber_t FedRawDataInputSource::runNumber_
private

Definition at line 60 of file FedRawDataInputSource.h.

Referenced by FedRawDataInputSource(), and postForkReacquireResources().

const bool FedRawDataInputSource::testModeNoBuilderUnit_
private
const bool FedRawDataInputSource::verifyAdler32_
private

Definition at line 57 of file FedRawDataInputSource.h.

Referenced by cacheNextEvent().