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";
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?
314 cout <<
"[LmfSource] "
317 <<
"runNum: " <<
runNum_ <<
"\n"
320 <<
"bx: " <<
bx_ <<
"\n"
321 <<
"activeFedId: " << activeFedId <<
"\n"
322 <<
"Calib trigger type: " << ((
calibTrig_ >>8) & 0x3) <<
"\n"
323 <<
"Color: " << ((
calibTrig_ >>6) & 0x3) <<
"\n"
324 <<
"nFeds: " <<
nFeds_ <<
"\n";
327 const int dccLenOffset32 = 2;
328 const int fedIdOffset32 = 0;
329 const int nPreRead32 = 3;
330 vector<int32_t> buf(nPreRead32);
331 for(
int iFed = 0; iFed <
nFeds_; ++iFed){
332 in_.read((
char*) &buf[0], nPreRead32*
sizeof(uint32_t));
335 cout <<
"[LmfSource] " << nPreRead32 <<
" first 32-bit words of "
336 <<
"FED block: " << hex << setfill(
'0');
337 for(
unsigned i = 0;
i< buf.size(); ++
i){
338 cout <<
"0x" << setw(8) << buf[
i] <<
" ";
344 if(
in_.bad())
return false;
346 const unsigned eventSize64 = buf[dccLenOffset32] & 0x00FFFFFF;
347 const unsigned eventSize32 = eventSize64*2;
348 const unsigned eventSize8 = eventSize64*8;
349 const unsigned fedId_ = (buf[fedIdOffset32] >>8) & 0xFFF;
353 <<
"Size of event fragment (FED block) read from "
355 <<
"is unexpctively large (" << (eventSize8 >>10)
357 <<
"This must be an error (corrupted file?)\n";
362 <<
"Invalid FED number read from data file.";
365 int32_t toRead8 = (eventSize32-nPreRead32)*
sizeof(int32_t);
369 <<
"Event size error while reading an event from file "
375 <<
"Skipping on event. Move file pointer "
376 << toRead8 <<
" ahead.\n";
377 in_.seekg(toRead8, ios::cur);
388 copy(buf.begin(), buf.end(), (int32_t*)data_.
data());
390 in_.read((
char*)(data_.
data()) + nPreRead32*4,
399 cout <<
"[LmfSource]"
400 <<
"Head of DCC data (in hex):" << hex;
401 for(
int i=0;
i < 16; ++
i){
402 if(
i%8==0)
cout <<
"\n";
403 cout << setw(8) << ((uint32_t*)data_.
data())[
i] <<
" ";
411 | ((activeFedId-600) & 0x3F);
413 cout <<
"[LmfSource] Old data format. "
414 "Uses information read from FED block to retrieve calibration "
415 "trigger type. Value is: 0x"
416 << hex << setfill(
'0') << setw(3) <<
calibTrig_
417 << setfill(
' ') <<
dec <<
"\n";
421 if(
in_.eof())
return false;
433 const int secTousec = 1000*1000;
434 time_t tsec = t/secTousec;
435 uint32_t tusec = (uint32_t)(t-tsec);
436 strftime(buf,
sizeof(buf),
"%F %R %S s", localtime(&tsec));
437 buf[
sizeof(buf)-1] = 0;
439 buf2 << (tusec+500)/1000;
440 return string(buf) +
" " + buf2.str() +
" ms";
446 const char s[] =
"file:";
447 if(fileName.compare(0,
sizeof(s)-1, s)==0){
448 fileName.erase(fileName.begin(),
449 fileName.begin() +
sizeof(
s)-1);
451 if(fileName.find_first_of(
":")!=string::npos){
453 <<
"Character ':' is not allowed in paths specified fileNames "
454 <<
"parameter. Please note only local file (or NFS, AFS)"
455 <<
" is supported (no rfio, no /store)";
457 const char s1[] =
"/store";
458 if(fileName.compare(0,
sizeof(s1)-1, s1)==0){
460 <<
"CMSSW /store not supported by LmfSource. Only local file "
461 <<
"(or NFS/AFS) allowed. Path starting with /store not permitted";
469 errMsg <<
"Error while reading event index table of file "
471 <<
"option orderedRead disabled.\n";
479 in_.read((
char*)&nevts,
sizeof(nevts));
483 <<
"Number of events indicated in event index of file "
484 << currentFileName_ <<
" is unexpectively large. File cannot be "
485 <<
"read in time-ordered event mode. See orderedRead parmater of "
486 <<
"LmfSource module.\n";
virtual void produce(edm::Event &e)
static unsigned char maxDataFormatVersion_
static unsigned char minDataFormatVersion_
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)
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
static const unsigned maxEvents_
virtual bool setRunAndEventInfo(edm::EventID &id, edm::TimeValue_t &time, edm::EventAuxiliary::ExperimentType &eType)
static unsigned fileHeaderSize
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_