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";
130 if(
verbosity_)
cout <<
"[LmfSource] Putting FEDRawDataCollection in event\n";
146 <<
"Opening file " << currentFileName_ <<
"\n";
147 in_.open(currentFileName_.c_str());
154 <<
"Failed to open input file " << currentFileName_ <<
". Skipping file\n";
161 <<
" going to sleep 5 seconds\n";
166 if(iFile > (
int)
fileNames_.size()-1)
return false;
170 in_.open(currentFileName_.c_str());
173 <<
"Failed to open input file " << currentFileName_ <<
"\n";
180 if(
iFile_<0)
return false;
184 cout <<
"[LmfSource] move to event with orbit Id "
186 <<
" at file position 0x"
187 << hex << setfill(
'0')
189 << setfill(
' ') << dec <<
"\n";
195 cout <<
"[LmfSource] Problem while reading file "
214 <<
"No more input file";
220 << (
rcRead_?
"succeeded":
"failed") <<
"\n";
232 <<
"About to read event...\n";
247 if(!rc)
return false;
250 <<
"Setting event time to "
252 <<
"Run number to " <<
runNum_ <<
","
253 <<
"Event number to " <<
eventNum_ <<
"\n";
265 const int timeStamp32[] = {0, 0};
266 const int lumiBlock32[] = {2, 2};
267 const int runNum32[] = {3, 3};
268 const int orbitNum32[] = {4, 4};
269 const int bx32[] = {5, 5};
270 const int eventNum32[] = {6, 6};
271 const int activeFedId32[] = {7,-1};
272 const int calibTrig32[] = {-1,7};
273 const int nFeds32[] = {-1,8};
275 const int evtHeadSize32[] = {8,10};
278 assert(iv<=
sizeof(timeStamp32)/
sizeof(timeStamp32[0]));
280 if((
int)
header_.size() < evtHeadSize32[iv])
header_.resize(evtHeadSize32[iv]);
284 <<
"Reading event header\n";
286 in_.read((
char*)&
header_[0], evtHeadSize32[iv]*4);
291 if(
in_.eof())
return false;
294 cout <<
"[LmfSource]"
295 <<
"Event header (in hex):" << hex << setfill(
'0');
296 for(
int i=0;
i < evtHeadSize32[iv]; ++
i){
297 if(
i%8==0)
cout <<
"\n";
300 cout << dec << setfill(
' ') <<
"\n";
310 int activeFedId = activeFedId32[iv]>=0?
316 cout <<
"[LmfSource] "
319 <<
"runNum: " <<
runNum_ <<
"\n"
322 <<
"bx: " <<
bx_ <<
"\n"
323 <<
"activeFedId: " << activeFedId <<
"\n"
324 <<
"Calib trigger type: " << ((
calibTrig_ >>8) & 0x3) <<
"\n"
325 <<
"Color: " << ((
calibTrig_ >>6) & 0x3) <<
"\n"
326 <<
"nFeds: " <<
nFeds_ <<
"\n";
329 const int dccLenOffset32 = 2;
330 const int fedIdOffset32 = 0;
331 const int nPreRead32 = 3;
332 vector<int32_t> buf(nPreRead32);
333 for(
int iFed = 0; iFed <
nFeds_; ++iFed){
334 in_.read((
char*) &buf[0], nPreRead32*
sizeof(uint32_t));
337 cout <<
"[LmfSource] " << nPreRead32 <<
" first 32-bit words of "
338 <<
"FED block: " << hex << setfill(
'0');
339 for(
unsigned i = 0;
i< buf.size(); ++
i){
340 cout <<
"0x" << setw(8) << buf[
i] <<
" ";
342 cout << dec << setfill(
' ');
346 if(
in_.bad())
return false;
348 const unsigned eventSize64 = buf[dccLenOffset32] & 0x00FFFFFF;
349 const unsigned eventSize32 = eventSize64*2;
350 const unsigned eventSize8 = eventSize64*8;
351 const unsigned fedId_ = (buf[fedIdOffset32] >>8) & 0xFFF;
355 <<
"Size of event fragment (FED block) read from "
357 <<
"is unexpctively large (" << (eventSize8 >>10)
359 <<
"This must be an error (corrupted file?)\n";
364 <<
"Invalid FED number read from data file.";
367 int32_t toRead8 = (eventSize32-nPreRead32)*
sizeof(int32_t);
371 <<
"Event size error while reading an event from file "
377 <<
"Skipping on event. Move file pointer "
378 << toRead8 <<
" ahead.\n";
379 in_.seekg(toRead8, ios::cur);
390 copy(buf.begin(), buf.end(), (int32_t*)data_.
data());
392 in_.read((
char*)(data_.
data()) + nPreRead32*4,
401 cout <<
"[LmfSource]"
402 <<
"Head of DCC data (in hex):" << hex;
403 for(
int i=0;
i < 16; ++
i){
404 if(
i%8==0)
cout <<
"\n";
405 cout << setw(8) << ((uint32_t*)data_.
data())[
i] <<
" ";
413 | ((activeFedId-600) & 0x3F);
415 cout <<
"[LmfSource] Old data format. "
416 "Uses information read from FED block to retrieve calibration "
417 "trigger type. Value is: 0x"
418 << hex << setfill(
'0') << setw(3) <<
calibTrig_
419 << setfill(
' ') << dec <<
"\n";
423 if(
in_.eof())
return false;
435 const int secTousec = 1000*1000;
436 time_t tsec = t/secTousec;
437 uint32_t tusec = (uint32_t)(t-tsec);
438 strftime(buf,
sizeof(buf),
"%F %R %S s", localtime(&tsec));
439 buf[
sizeof(buf)-1] = 0;
441 buf2 << (tusec+500)/1000;
442 return string(buf) +
" " + buf2.str() +
" ms";
448 const char s[] =
"file:";
449 if(fileName.compare(0,
sizeof(s)-1, s)==0){
450 fileName.erase(fileName.begin(),
451 fileName.begin() +
sizeof(
s)-1);
453 if(fileName.find_first_of(
":")!=string::npos){
455 <<
"Character ':' is not allowed in paths specified fileNames "
456 <<
"parameter. Please note only local file (or NFS, AFS)"
457 <<
" is supported (no rfio, no /store)";
459 const char s1[] =
"/store";
460 if(fileName.compare(0,
sizeof(s1)-1, s1)==0){
462 <<
"CMSSW /store not supported by LmfSource. Only local file "
463 <<
"(or NFS/AFS) allowed. Path starting with /store not permitted";
471 errMsg <<
"Error while reading event index table of file "
473 <<
"option orderedRead disabled.\n";
481 in_.read((
char*)&nevts,
sizeof(nevts));
485 <<
"Number of events indicated in event index of file "
486 << currentFileName_ <<
" is unexpectively large. File cannot be "
487 <<
"read in time-ordered event mode. See orderedRead parmater of "
488 <<
"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)
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)
std::vector< uint32_t > fileHeader_
std::vector< std::string > fileNames_