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
DTROS8FileReader Class Reference

#include <DTROS8FileReader.h>

Inheritance diagram for DTROS8FileReader:
DaqBaseReader

Public Member Functions

virtual bool checkEndOfFile ()
 
 DTROS8FileReader (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...
 
virtual ~DTROS8FileReader ()
 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 eventNum
 
RawFile inputFile
 
edm::RunNumber_t runNum
 

Static Private Attributes

static const int ros8WordLenght = 4
 

Detailed Description

Read DT ROS8 raw data files

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

Definition at line 18 of file DTROS8FileReader.h.

Constructor & Destructor Documentation

DTROS8FileReader::DTROS8FileReader ( const edm::ParameterSet pset)

Constructor.

Definition at line 32 of file DTROS8FileReader.cc.

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

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

Destructor.

Definition at line 45 of file DTROS8FileReader.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 DTROS8FileReader::checkEndOfFile ( )
virtual

Definition at line 143 of file DTROS8FileReader.cc.

References RawFile::eof(), and inputFile.

Referenced by fillRawData().

143  {
144 
145  bool retval=false;
146  if ( inputFile.eof() ) retval=true;
147  return retval;
148 
149 }
int eof()
Check end of file.
Definition: RawFile.cc:100
int DTROS8FileReader::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 DTROS8FileReader.cc.

References checkEndOfFile(), filterCSVwithJSON::copy, gather_cfg::cout, FEDRawData::data(), data, FEDRawDataCollection::FEDData(), i, inputFile, FEDNumbering::MINDTFEDID, RawFile::read(), FEDRawData::resize(), and ros8WordLenght.

52  {
53  data = new FEDRawDataCollection();
54 
55  try {
56 
57 
58  if( checkEndOfFile() ) throw 1;
59 
60 
61  // Get the total number of words from the 1st word in the payload
62  int numberOfWords;
63  int nread = 0;
64  nread = inputFile.read(dataPointer<int>( &numberOfWords ), ros8WordLenght);
65  if ( nread<=0 ) throw 1;
66 
67 
68  // Get the event data (all words but the 1st)
69  int* eventData = new int[numberOfWords];
70  nread = inputFile.read(dataPointer<int>( eventData + 1 ), (numberOfWords-1) * ros8WordLenght );
71  if ( nread<=0 ) throw 1;
72 
73 
74  // Check that the event data size corresponds to the 1st word datum
75  if ( eventData[numberOfWords-1] != numberOfWords ) {
76  cout << "[DTROS8FileReader]: word counter mismatch exception: "
77  << numberOfWords << " " << eventData[numberOfWords-1] << endl;
78  throw 99;
79  }
80 
81  // The header added by the local DAQ occupies 8 words, starting from the 2nd
82  int* head = eventData + 1;
83 
84  /*
85  Header word 0: run number
86  Header word 1: spill number
87  Header word 2: event number
88  Header word 3: reserved
89  Header word 4: ROS data offset
90  Header word 5: PU data offset
91  Header word 6: reserved
92  Header word 7: reserved
93  */
94 
95  // WARNING: the event number is reset at a new spill
96  eID = EventID( head[0], 1U, head[1]*head[2]);
97 
98  // The pointer to the ROS payload (the 1st word being the ROS words counter)
99  int* rosData = eventData + head[4];
100 
101  // The ROS payload size
102  int eventDataSize = *rosData * ros8WordLenght;
103  // It has to be a multiple of 8 bytes. if not, adjust the size of the FED payload
104  int adjustment = (eventDataSize/4)%2 == 1 ? 4 : 0;
105 
106  //if ( (eventDataSize/4)%2 ) adjustment = 4;
107 
108 
109  // The FED ID is always the first in the DT range
110  FEDRawData& fedRawData = data->FEDData( FEDNumbering::MINDTFEDID );
111  fedRawData.resize(eventDataSize+adjustment);
112 
113  // I pass only the ROS data to the Event
114  copy(reinterpret_cast<unsigned char*>(rosData),
115  reinterpret_cast<unsigned char*>(rosData) + eventDataSize, fedRawData.data());
116 
117  // needed to get rid of memory leaks (?)
118  delete[] eventData;
119 
120  return true;
121  }
122 
123  catch( int i ) {
124 
125  if ( i == 1 ){
126  cout << "[DTROS8FileReader]: END OF FILE REACHED. "
127  << "No information read for the requested event" << endl;
128  delete data; data=0;
129  return false;
130  }
131  else {
132  cout << "[DTROS8FileReader]: PROBLEM WITH EVENT INFORMATION ON THE FILE. "
133  << "EVENT DATA READING FAILED code= " << i << endl;
134  delete data; data=0;
135  return false;
136  }
137 
138  }
139 
140 }
int i
Definition: DBlmapReader.cc:9
virtual bool checkEndOfFile()
int read(void *data, size_t nbytes)
Read from file.
Definition: RawFile.cc:82
const FEDRawData & FEDData(int fedid) const
retrieve data for fed
void resize(size_t newsize)
Definition: FEDRawData.cc:33
static const int ros8WordLenght
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
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

Member Data Documentation

edm::EventNumber_t DTROS8FileReader::eventNum
private

Definition at line 38 of file DTROS8FileReader.h.

RawFile DTROS8FileReader::inputFile
private
const int DTROS8FileReader::ros8WordLenght = 4
staticprivate

Definition at line 40 of file DTROS8FileReader.h.

Referenced by fillRawData().

edm::RunNumber_t DTROS8FileReader::runNum
private

Definition at line 37 of file DTROS8FileReader.h.