29 fileNames_(pset.getParameter<vector<string> >(
"fileNames")),
32 fileHeader_(fileHeaderSize),
35 preScale_(pset.getParameter<unsigned>(
"preScale")),
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"))
47 produces<FEDRawDataCollection>();
62 if(
iFile_==-1)
return false;
65 <<
"Opening file #" << (
iFile_+1) <<
" '"
70 if(
in_.eof())
return false;
74 <<
"File header (in hex):" << hex;
76 if(
i%8==0)
cout <<
"\n";
90 if(!(
id[0]==
'L' &&
id[1] ==
'M'
103 <<
" is not supported by this release of LmfSource module";
108 if(
verbosity_)
cout <<
"[LmfSource] File position of index table: 0x"
110 << setfill(
' ') << dec <<
"\n";
131 if(
verbosity_)
cout <<
"[LmfSource] Putting FEDRawDataCollection in event\n";
146 std::string tmp_buffer;
149 <<
"Opening file " << currentFileName_ <<
"\n";
150 in_.open(currentFileName_.c_str());
157 <<
"Failed to open input file " << currentFileName_ <<
". Skipping file\n";
164 <<
" going to sleep 5 seconds\n";
169 if(iFile > (
int)
fileNames_.size()-1)
return false;
173 in_.open(currentFileName_.c_str());
176 <<
"Failed to open input file " << currentFileName_ <<
"\n";
183 if(
iFile_<0)
return false;
187 cout <<
"[LmfSource] move to event with orbit Id "
189 <<
" at file position 0x"
190 << hex << setfill(
'0')
192 << setfill(
' ') << dec <<
"\n";
198 cout <<
"[LmfSource] Problem while reading file "
217 <<
"No more input file";
223 << (
rcRead_?
"succeeded":
"failed") <<
"\n";
235 <<
"About to read event...\n";
253 <<
"Setting event time to "
255 <<
"Run number to " <<
runNum_ <<
","
256 <<
"Event number to " <<
eventNum_ <<
"\n";
269 const int timeStamp32[] = {0, 0};
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};
279 const int evtHeadSize32[] = {8,10};
282 assert(iv<=
sizeof(timeStamp32)/
sizeof(timeStamp32[0]));
284 if((
int)
header_.size() < evtHeadSize32[iv])
header_.resize(evtHeadSize32[iv]);
288 <<
"Reading event header\n";
290 in_.read((
char*)&
header_[0], evtHeadSize32[iv]*4);
295 if(
in_.eof())
return false;
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";
304 cout << dec << setfill(
' ') <<
"\n";
314 int activeFedId = activeFedId32[iv]>=0?
320 cout <<
"[LmfSource] "
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 <<
"nFeds: " <<
nFeds_ <<
"\n";
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));
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] <<
" ";
346 cout << dec << setfill(
' ');
350 if(
in_.bad())
return false;
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;
359 <<
"Size of event fragment (FED block) read from "
361 <<
"is unexpctively large (" << (eventSize8 >>10)
363 <<
"This must be an error (corrupted file?)\n";
368 <<
"Invalid FED number read from data file.";
371 int32_t toRead8 = (eventSize32-nPreRead32)*
sizeof(int32_t);
375 <<
"Event size error while reading an event from file "
381 <<
"Skipping on event. Move file pointer "
382 << toRead8 <<
" ahead.\n";
383 in_.seekg(toRead8, ios::cur);
394 copy(buf.begin(), buf.end(), (int32_t*)data_.
data());
396 in_.read((
char*)(data_.
data()) + nPreRead32*4,
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] <<
" ";
417 | ((activeFedId-600) & 0x3F);
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";
427 if(
in_.eof())
return false;
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;
445 buf2 << (tusec+500)/1000;
446 return string(buf) +
" " + buf2.str() +
" ms";
452 const char s[] =
"file:";
453 if(fileName.compare(0,
sizeof(s)-1, s)==0){
454 fileName.erase(fileName.begin(),
455 fileName.begin() +
sizeof(
s)-1);
457 if(fileName.find_first_of(
":")!=string::npos){
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)";
463 const char s1[] =
"/store";
464 if(fileName.compare(0,
sizeof(s1)-1, s1)==0){
466 <<
"CMSSW /store not supported by LmfSource. Only local file "
467 <<
"(or NFS/AFS) allowed. Path starting with /store not permitted";
475 errMsg <<
"Error while reading event index table of file "
477 <<
"option orderedRead disabled.\n";
485 in_.read((
char*)&nevts,
sizeof(nevts));
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";
static unsigned char maxDataFormatVersion_
static unsigned char minDataFormatVersion_
virtual void setRunAndEventInfo()
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_
static unsigned fileHeaderSize
FEDRawDataCollection fedColl_
static const unsigned maxEventSize_
unsigned long long TimeValue_t
virtual bool produce(edm::Event &e)
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_