27 fileNames_(pset.getParameter<vector<
string> >(
"fileNames")),
30 fileHeader_(fileHeaderSize),
33 preScale_(pset.getParameter<unsigned>(
"preScale")),
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"))
45 produces<FEDRawDataCollection>();
60 if(
iFile_==-1)
return false;
63 <<
"Opening file #" << (
iFile_+1) <<
" '"
68 if(
in_.eof())
return false;
72 <<
"File header (in hex):" << hex;
74 if(
i%8==0)
cout <<
"\n";
88 if(!(
id[0]==
'L' &&
id[1] ==
'M'
101 <<
" is not supported by this release of LmfSource module";
106 if(
verbosity_)
cout <<
"[LmfSource] File position of index table: 0x"
108 << setfill(
' ') <<
dec <<
"\n";
126 auto coll = std::make_unique<FEDRawDataCollection>();
128 if(
verbosity_)
cout <<
"[LmfSource] Putting FEDRawDataCollection in event\n";
144 <<
"Opening file " << currentFileName_ <<
"\n";
145 in_.open(currentFileName_.c_str());
152 <<
"Failed to open input file " << currentFileName_ <<
". Skipping file\n";
159 <<
" going to sleep 5 seconds\n";
164 if(iFile > (
int)
fileNames_.size()-1)
return false;
168 in_.open(currentFileName_.c_str());
171 <<
"Failed to open input file " << currentFileName_ <<
"\n";
178 if(
iFile_<0)
return false;
182 cout <<
"[LmfSource] move to event with orbit Id "
184 <<
" at file position 0x"
185 << hex << setfill(
'0')
187 << setfill(
' ') <<
dec <<
"\n";
193 cout <<
"[LmfSource] Problem while reading file "
212 <<
"No more input file";
218 << (
rcRead_?
"succeeded":
"failed") <<
"\n";
230 <<
"About to read event...\n";
245 if(!rc)
return false;
248 <<
"Setting event time to "
250 <<
"Run number to " <<
runNum_ <<
","
251 <<
"Event number to " <<
eventNum_ <<
"\n";
263 const int timeStamp32[] = {0, 0};
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};
273 const int evtHeadSize32[] = {8,10};
276 assert(iv<=
sizeof(timeStamp32)/
sizeof(timeStamp32[0]));
278 if((
int)
header_.size() < evtHeadSize32[iv])
header_.resize(evtHeadSize32[iv]);
282 <<
"Reading event header\n";
284 in_.read((
char*)&
header_[0], evtHeadSize32[iv]*4);
289 if(
in_.eof())
return false;
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";
298 cout <<
dec << setfill(
' ') <<
"\n";
308 int activeFedId = activeFedId32[iv]>=0?
315 div_t t_ms_us = div(
timeStamp_ & 0xFFFFFFFF, 1000);
317 strftime(tbuf,
sizeof(tbuf),
"%F %T", localtime(&t));
318 tbuf[
sizeof(tbuf)-1] = 0;
319 cout <<
"[LmfSource] "
321 <<
" (" << tbuf <<
" " << t_ms_us.quot <<
" ms " << t_ms_us.rem <<
" us)\n"
323 <<
"runNum: " <<
runNum_ <<
"\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";
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));
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] <<
" ";
351 if(
in_.bad())
return false;
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;
360 <<
"Size of event fragment (FED block) read from "
362 <<
"is unexpctively large (" << (eventSize8 >>10)
364 <<
"This must be an error (corrupted file?)\n";
369 <<
"Invalid FED number read from data file.";
372 int32_t toRead8 = (eventSize32-nPreRead32)*
sizeof(int32_t);
376 <<
"Event size error while reading an event from file "
382 <<
"Skipping on event. Move file pointer "
383 << toRead8 <<
" ahead.\n";
384 in_.seekg(toRead8, ios::cur);
395 copy(buf.begin(), buf.end(), (int32_t*)data_.
data());
397 in_.read((
char*)(data_.
data()) + nPreRead32*4,
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] <<
" ";
418 | ((activeFedId-600) & 0x3F);
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";
428 if(
in_.eof())
return false;
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;
446 buf2 << (tusec+500)/1000;
447 return string(buf) +
" " + buf2.str() +
" ms";
453 const char s[] =
"file:";
454 if(fileName.compare(0,
sizeof(s)-1, s)==0){
455 fileName.erase(fileName.begin(),
456 fileName.begin() +
sizeof(
s)-1);
458 if(fileName.find_first_of(
":")!=string::npos){
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)";
464 const char s1[] =
"/store";
465 if(fileName.compare(0,
sizeof(s1)-1, s1)==0){
467 <<
"CMSSW /store not supported by LmfSource. Only local file "
468 <<
"(or NFS/AFS) allowed. Path starting with /store not permitted";
476 errMsg <<
"Error while reading event index table of file "
478 <<
"option orderedRead disabled.\n";
486 in_.read((
char*)&nevts,
sizeof(nevts));
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";
virtual void produce(edm::Event &e)
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_
virtual bool setRunAndEventInfo(edm::EventID &id, edm::TimeValue_t &time, edm::EventAuxiliary::ExperimentType &eType)
FEDRawDataCollection fedColl_
static const unsigned maxEventSize_
unsigned long long TimeValue_t
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)
volatile std::atomic< bool > shutdown_flag false
std::vector< uint32_t > fileHeader_
std::vector< std::string > fileNames_
static const unsigned char maxDataFormatVersion_