CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Attributes | Static Private Attributes
DTROS25FileReader Class Reference

#include <DTROS25FileReader.h>

Inheritance diagram for DTROS25FileReader:
DaqBaseReader

Public Member Functions

virtual bool checkEndOfFile ()
 
 DTROS25FileReader (const edm::ParameterSet &pset)
 Constructor. More...
 
virtual int fillRawData (edm::EventID &eID, edm::Timestamp &tstamp, FEDRawDataCollection *&data)
 Generate and fill FED raw data for a full event. More...
 
bool isHeader (uint32_t word)
 check for a 32 bits word to be a ROS25 header More...
 
bool isTrailer (uint32_t word)
 check for a 32 bits word to be a ROS25 trailer More...
 
void swap (uint32_t &word)
 swapping the lsBits with the msBits More...
 
virtual ~DTROS25FileReader ()
 Destructor. More...
 
- Public Member Functions inherited from DaqBaseReader
 DaqBaseReader ()
 
virtual void setRunNumber (edm::RunNumber_t runNumber)
 set the run number More...
 
virtual ~DaqBaseReader ()
 

Private Attributes

edm::EventNumber_t eventNumber
 
RawFile inputFile
 
edm::RunNumber_t runNumber
 

Static Private Attributes

static const int rosWordLenght = 4
 

Detailed Description

Read DT ROS8 raw data files

Date:
2010/02/03 16:58:24
Revision:
1.6
Author
M. Zanetti - INFN Padova

Definition at line 20 of file DTROS25FileReader.h.

Constructor & Destructor Documentation

DTROS25FileReader::DTROS25FileReader ( const edm::ParameterSet pset)

Constructor.

Definition at line 32 of file DTROS25FileReader.cc.

References edm::hlt::Exception, RawFile::fail(), lut2db_cfg::filename, edm::ParameterSet::getUntrackedParameter(), inputFile, and RawFile::open().

32  :
33  runNumber(1), eventNumber(0) {
34 
35  const string & filename = pset.getUntrackedParameter<string>("fileName");
36 
37  inputFile.open(filename.c_str());
38  if( inputFile.fail() ) {
39  throw cms::Exception("InputFileMissing")
40  << "DTROS25FileReader: the input file: " << filename <<" is not present";
41  }
42 }
T getUntrackedParameter(std::string const &, T const &) const
edm::RunNumber_t runNumber
edm::EventNumber_t eventNumber
RawFile * open(const char *path)
Open file.
Definition: RawFile.cc:27
bool fail()
It is not OK.
Definition: RawFile.cc:78
tuple filename
Definition: lut2db_cfg.py:20
DTROS25FileReader::~DTROS25FileReader ( )
virtual

Destructor.

Definition at line 45 of file DTROS25FileReader.cc.

References RawFile::close(), and inputFile.

45  {
46  inputFile.close();
47 }
int close()
Close file if necessary.
Definition: RawFile.cc:60

Member Function Documentation

bool DTROS25FileReader::checkEndOfFile ( )
virtual

Definition at line 162 of file DTROS25FileReader.cc.

References RawFile::eof(), and inputFile.

162  {
163 
164  bool retval=false;
165  if ( inputFile.eof() ) retval=true;
166  return retval;
167 
168 }
int eof()
Check end of file.
Definition: RawFile.cc:100
int DTROS25FileReader::fillRawData ( edm::EventID eID,
edm::Timestamp tstamp,
FEDRawDataCollection *&  data 
)
virtual

Generate and fill FED raw data for a full event.

Implements DaqBaseReader.

Definition at line 50 of file DTROS25FileReader.cc.

References filterCSVwithJSON::copy, gather_cfg::cout, FEDRawData::data(), data, eventNumber, FEDRawDataCollection::FEDData(), i, inputFile, isHeader(), isTrailer(), FEDNumbering::MINDTFEDID, RawFile::read(), FEDRawData::resize(), rosWordLenght, runNumber, and swap().

52  {
53  data = new FEDRawDataCollection();
54 
55  vector<uint32_t> eventData;
56  size_t estimatedEventDimension = 102400; // dimensione hardcoded
57  eventData.reserve(estimatedEventDimension);
58  uint32_t word = 0;
59 
60 
61  try {
62 
63  bool marked = false;
64 
65  // getting the data word by word from the file
66  // do it until you get the ROS25 trailer
67  while ( !isTrailer(word) ) {
68 
69  // get the first word
70  int nread = inputFile.read(dataPointer<uint32_t>( &word ), rosWordLenght);
71 
72  // WARNING!!! ||swapping it|| (Check whether it is necessary)
73  swap(word);
74 
75  if ( nread<=0 ) throw 1;
76 
77  // get the ROS25 header
78  if (isHeader(word)) marked=true;
79 
80  // from now on fill the eventData with the ROS data
81  if (marked) {
82  eventData.push_back(word);
83 
84  }
85  }
86 
87  // next event reading will start with meaningless trailer+header from DTLocalDAQ
88  // those will be skipped automatically when seeking for the ROS25 header
89 
90  //if (eventData.size() > estimatedEventDimension) throw 2;
91 
92  // Setting the Event ID
93  eID = EventID( runNumber, 1U, eventNumber);
94 
95  // eventDataSize = (Number Of Words)* (Word Size)
96  int eventDataSize = eventData.size()*rosWordLenght;
97  // It has to be a multiple of 8 bytes. if not, adjust the size of the FED payload
98  int adjustment = (eventDataSize/4)%2 == 1 ? 4 : 0;
99 
100  // The FED ID is always the first in the DT range
101  FEDRawData& fedRawData = data->FEDData( FEDNumbering::MINDTFEDID );
102  fedRawData.resize(eventDataSize+adjustment);
103 
104  copy(reinterpret_cast<unsigned char*>(&eventData[0]),
105  reinterpret_cast<unsigned char*>(&eventData[0]) + eventDataSize, fedRawData.data());
106 
107  return true;
108  }
109 
110  catch( int i ) {
111 
112  if ( i == 1 ){
113  cout<<"[DTROS25FileReader]: ERROR! failed to get the trailer"<<endl;
114  delete data; data=0;
115  return false;
116  }
117  else {
118  cout<<"[DTROS25FileReader]:"
119  <<" ERROR! ROS data exceeding estimated event dimension. Event size = "
120  <<eventData.size()<<endl;
121  delete data; data=0;
122  return false;
123  }
124 
125  }
126 
127 }
int i
Definition: DBlmapReader.cc:9
edm::RunNumber_t runNumber
edm::EventNumber_t eventNumber
static const int rosWordLenght
int read(void *data, size_t nbytes)
Read from file.
Definition: RawFile.cc:82
bool isTrailer(uint32_t word)
check for a 32 bits word to be a ROS25 trailer
const FEDRawData & FEDData(int fedid) const
retrieve data for fed
void resize(size_t newsize)
Definition: FEDRawData.cc:33
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
void swap(uint32_t &word)
swapping the lsBits with the msBits
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:29
tuple cout
Definition: gather_cfg.py:121
bool isHeader(uint32_t word)
check for a 32 bits word to be a ROS25 header
bool DTROS25FileReader::isHeader ( uint32_t  word)

check for a 32 bits word to be a ROS25 header

Definition at line 139 of file DTROS25FileReader.cc.

References eventNumber.

Referenced by fillRawData().

139  {
140 
141  bool it_is = false;
142  if ( (word >> 24 ) == 31 ) {
143  it_is = true;
144  ++eventNumber;
145  }
146 
147  return it_is;
148 }
edm::EventNumber_t eventNumber
bool DTROS25FileReader::isTrailer ( uint32_t  word)

check for a 32 bits word to be a ROS25 trailer

Definition at line 151 of file DTROS25FileReader.cc.

Referenced by fillRawData().

151  {
152 
153  bool it_is = false;
154  if ( (word >> 24 ) == 63 ) {
155  it_is = true;
156  }
157 
158  return it_is;
159 }
void DTROS25FileReader::swap ( uint32_t &  word)

swapping the lsBits with the msBits

Definition at line 129 of file DTROS25FileReader.cc.

References twoNibble::lsBits, and twoNibble::msBits.

Referenced by fillRawData().

129  {
130 
131  twoNibble* newWorld = reinterpret_cast<twoNibble*>(&word);
132 
133  uint16_t msBits_tmp = newWorld->msBits;
134  newWorld->msBits = newWorld->lsBits;
135  newWorld->lsBits = msBits_tmp;
136 }

Member Data Documentation

edm::EventNumber_t DTROS25FileReader::eventNumber
private
RawFile DTROS25FileReader::inputFile
private
const int DTROS25FileReader::rosWordLenght = 4
staticprivate

Definition at line 54 of file DTROS25FileReader.h.

Referenced by fillRawData().

edm::RunNumber_t DTROS25FileReader::runNumber
private

Definition at line 51 of file DTROS25FileReader.h.

Referenced by fillRawData().