25 fileNames_(pset.getParameter<vector<
string> >(
"fileNames")),
28 fileHeader_(fileHeaderSize),
31 preScale_(pset.getParameter<unsigned>(
"preScale")),
35 orderedRead_(pset.getParameter<
bool>(
"orderedRead")),
36 watchFileList_(pset.getParameter<
bool>(
"watchFileList")),
37 fileListName_(pset.getParameter<
std::
string>(
"fileListName")),
38 inputDir_(pset.getParameter<
std::
string>(
"inputDir")),
39 nSecondsToSleep_(pset.getParameter<
int>(
"nSecondsToSleep")),
40 verbosity_(pset.getUntrackedParameter<
int>(
"verbosity")) {
43 produces<FEDRawDataCollection>();
71 <<
"File header (in hex):" << hex;
87 if (!(
id[0] ==
'L' &&
id[1] ==
'M' &&
id[2] ==
'F')) {
97 <<
" is not supported by this release of LmfSource module";
103 cout <<
"[LmfSource] File position of index table: 0x" << setfill(
'0') << hex << setw(8) << indexTablePos_
104 << setfill(
' ') <<
dec <<
"\n";
122 auto coll = std::make_unique<FEDRawDataCollection>();
125 cout <<
"[LmfSource] Putting FEDRawDataCollection in event\n";
141 cout <<
"[LmfSource]" 142 <<
"Opening file " << currentFileName_ <<
"\n";
143 in_.open(currentFileName_.c_str());
149 edm::LogError(
"FileOpenError") <<
"Failed to open input file " << currentFileName_ <<
". Skipping file\n";
157 <<
" going to sleep 5 seconds\n";
166 cout <<
"[LmfSource]" 168 in_.open(currentFileName_.c_str());
170 throw cms::Exception(
"FileOpenError") <<
"Failed to open input file " << currentFileName_ <<
"\n";
190 cout <<
"[LmfSource] Problem while reading file " <<
currentFileName_ <<
". Problem with event index table?\n";
206 if (rcOpen ==
false) {
208 cout <<
"[LmfSource]" 209 <<
"No more input file";
215 cout <<
"File header readout " << (
rcRead_ ?
"succeeded" :
"failed") <<
"\n";
228 cout <<
"[LmfSource]" 229 <<
"About to read event...\n";
248 cout <<
"[LmfSource]" 249 <<
"Setting event time to " <<
timeStamp_ <<
", " 250 <<
"Run number to " <<
runNum_ <<
"," 251 <<
"Event number to " <<
eventNum_ <<
"\n";
264 const int timeStamp32[] = {0, 0};
265 const int lumiBlock32[] = {2, 2};
266 const int runNum32[] = {3, 3};
267 const int orbitNum32[] = {4, 4};
268 const int bx32[] = {5, 5};
269 const int eventNum32[] = {6, 6};
270 const int activeFedId32[] = {7, -1};
271 const int calibTrig32[] = {-1, 7};
272 const int nFeds32[] = {-1, 8};
274 const int evtHeadSize32[] = {8, 10};
277 assert(iv <=
sizeof(timeStamp32) /
sizeof(timeStamp32[0]));
279 if ((
int)
header_.size() < evtHeadSize32[iv])
280 header_.resize(evtHeadSize32[iv]);
283 cout <<
"[LmfSource]" 284 <<
"Reading event header\n";
286 in_.read((
char*)&
header_[0], evtHeadSize32[iv] * 4);
294 cout <<
"[LmfSource]" 295 <<
"Event header (in hex):" << hex << setfill(
'0');
296 for (
int i = 0;
i < evtHeadSize32[iv]; ++
i) {
301 cout <<
dec << setfill(
' ') <<
"\n";
311 int activeFedId = activeFedId32[iv] >= 0 ?
header_[activeFedId32[iv]] : ((
calibTrig_ & 0x3F) + 600);
316 div_t t_ms_us = div(
timeStamp_ & 0xFFFFFFFF, 1000);
318 strftime(tbuf,
sizeof(tbuf),
"%F %T", localtime(&t));
319 tbuf[
sizeof(tbuf) - 1] = 0;
320 cout <<
"[LmfSource] " 321 <<
"timeStamp: " <<
timeStamp_ <<
" (" << tbuf <<
" " << t_ms_us.quot
322 <<
" ms " << t_ms_us.rem <<
" us)\n" 324 <<
"runNum: " <<
runNum_ <<
"\n" 327 <<
"bx: " <<
bx_ <<
"\n" 328 <<
"activeFedId: " << activeFedId <<
"\n" 329 <<
"Calib trigger type: " << ((
calibTrig_ >> 8) & 0x3) <<
"\n" 330 <<
"Color: " << ((
calibTrig_ >> 6) & 0x3) <<
"\n" 332 <<
"nFeds: " <<
nFeds_ <<
"\n";
335 const int dccLenOffset32 = 2;
336 const int fedIdOffset32 = 0;
337 const int nPreRead32 = 3;
338 vector<int32_t> buf(nPreRead32);
339 for (
int iFed = 0; iFed <
nFeds_; ++iFed) {
340 in_.read((
char*)&buf[0], nPreRead32 *
sizeof(uint32_t));
343 cout <<
"[LmfSource] " << nPreRead32 <<
" first 32-bit words of " 344 <<
"FED block: " << hex << setfill(
'0');
345 for (
unsigned i = 0;
i < buf.size(); ++
i) {
346 cout <<
"0x" << setw(8) << buf[
i] <<
" ";
354 const unsigned eventSize64 = buf[dccLenOffset32] & 0x00FFFFFF;
355 const unsigned eventSize32 = eventSize64 * 2;
356 const unsigned eventSize8 = eventSize64 * 8;
357 const unsigned fedId_ = (buf[fedIdOffset32] >> 8) & 0xFFF;
361 <<
"Size of event fragment (FED block) read from " 362 <<
" data of file " <<
currentFileName_ <<
"is unexpctively large (" << (eventSize8 >> 10) <<
" kByte). " 363 <<
"This must be an error (corrupted file?)\n";
367 throw cms::Exception(
"FileReadError") <<
"Invalid FED number read from data file.";
370 int32_t toRead8 = (eventSize32 - nPreRead32) *
sizeof(int32_t);
374 <<
"Event size error while reading an event from file " <<
currentFileName_ <<
"\n";
379 cout <<
"[LmfSource] " 380 <<
"Skipping on event. Move file pointer " << toRead8 <<
" ahead.\n";
381 in_.seekg(toRead8, ios::cur);
391 copy(buf.begin(), buf.end(), (int32_t*)data_.
data());
393 in_.read((
char*)(data_.
data()) + nPreRead32 * 4, toRead8);
400 cout <<
"[LmfSource]" 401 <<
"Head of DCC data (in hex):" << hex;
402 for (
int i = 0;
i < 16; ++
i) {
405 cout << setw(8) << ((uint32_t*)data_.
data())[
i] <<
" ";
412 calibTrig_ = (((uint32_t*)data_.
data())[5] & 0xFC0) | ((activeFedId - 600) & 0x3F);
414 cout <<
"[LmfSource] Old data format. " 415 "Uses information read from FED block to retrieve calibration " 416 "trigger type. Value is: 0x" 417 << hex << setfill(
'0') << setw(3) <<
calibTrig_ << setfill(
' ') <<
dec <<
"\n";
432 const int secTousec = 1000 * 1000;
433 time_t tsec = t / secTousec;
434 uint32_t tusec = (uint32_t)(t - tsec);
435 strftime(buf,
sizeof(buf),
"%F %R %S s", localtime(&tsec));
436 buf[
sizeof(buf) - 1] = 0;
438 buf2 << (tusec + 500) / 1000;
439 return string(buf) +
" " + buf2.str() +
" ms";
445 const char s[] =
"file:";
446 if (fileName.compare(0,
sizeof(s) - 1, s) == 0) {
447 fileName.erase(fileName.begin(), fileName.begin() +
sizeof(
s) - 1);
449 if (fileName.find_first_of(
":") != string::npos) {
450 throw cms::Exception(
"LmfSource") <<
"Character ':' is not allowed in paths specified fileNames " 451 <<
"parameter. Please note only local file (or NFS, AFS)" 452 <<
" is supported (no rfio, no /store)";
454 const char s1[] =
"/store";
455 if (fileName.compare(0,
sizeof(s1) - 1, s1) == 0) {
456 throw cms::Exception(
"LmfSource") <<
"CMSSW /store not supported by LmfSource. Only local file " 457 <<
"(or NFS/AFS) allowed. Path starting with /store not permitted";
464 errMsg <<
"Error while reading event index table of file " <<
currentFileName_ <<
". Try to read it with " 465 <<
"option orderedRead disabled.\n";
474 in_.read((
char*)&nevts,
sizeof(nevts));
477 throw cms::Exception(
"LmfSource") <<
"Number of events indicated in event index of file " << currentFileName_
478 <<
" is unexpectively large. File cannot be " 479 <<
"read in time-ordered event mode. See orderedRead parmater of " 480 <<
"LmfSource module.\n";
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
static const unsigned fileHeaderSize
bool readEventWithinFile(bool doSkip)
std::vector< uint32_t > header_
std::string fileListName_
size_t size() const
Lenght of the data buffer in bytes.
LmfSource(const edm::ParameterSet &pset, const edm::InputSourceDescription &isd)
const FEDRawData & FEDData(int fedid) const
retrieve data for fed
void resize(size_t newsize)
static const unsigned char minDataFormatVersion_
static const unsigned maxEvents_
FEDRawDataCollection fedColl_
static const unsigned maxEventSize_
unsigned long long TimeValue_t
bool setRunAndEventInfo(edm::EventID &id, edm::TimeValue_t &time, edm::EventAuxiliary::ExperimentType &eType) override
void produce(edm::Event &e) override
unsigned long long uint64_t
unsigned char dataFormatVers_
std::vector< IndexRecord > indexTable_
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
bool nextEventWithinFile()
std::string currentFileName_
std::string toString(edm::TimeValue_t &t) const
bool readEvent(bool doSkip=false)
std::vector< uint32_t > fileHeader_
std::vector< std::string > fileNames_
static const unsigned char maxDataFormatVersion_