CMS 3D CMS Logo

DTROS8FileReader Class Reference

Read DT ROS8 raw data files. More...

#include <IORawData/DTCommissioning/src/DTROS8FileReader.h>

Inheritance diagram for DTROS8FileReader:

DaqBaseReader

List of all members.

Public Member Functions

virtual bool checkEndOfFile ()
 DTROS8FileReader (const edm::ParameterSet &pset)
 Constructor.
virtual bool fillRawData (edm::EventID &eID, edm::Timestamp &tstamp, FEDRawDataCollection *&data)
 Generate and fill FED raw data for a full event.
virtual ~DTROS8FileReader ()
 Destructor.

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
2007/03/12 01:01:57
Revision
1.7
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 31 of file DTROS8FileReader.cc.

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

00031                                                               : 
00032   runNum(1), eventNum(0) {
00033       
00034   const string & filename = pset.getParameter<string>("fileName");
00035 
00036   inputFile.open(filename.c_str());
00037   if( inputFile.fail() ) {
00038     throw cms::Exception("InputFileMissing") 
00039       << "DTROS8FileReader: the input file: " << filename <<" is not present";
00040   }
00041 }

DTROS8FileReader::~DTROS8FileReader (  )  [virtual]

Destructor.

Definition at line 44 of file DTROS8FileReader.cc.

References RawFile::close(), and inputFile.

00044                                    {
00045   inputFile.close();
00046 }


Member Function Documentation

bool DTROS8FileReader::checkEndOfFile (  )  [virtual]

Definition at line 142 of file DTROS8FileReader.cc.

References RawFile::eof(), and inputFile.

Referenced by fillRawData().

00142                                      {
00143 
00144   bool retval=false;
00145   if ( inputFile.eof() ) retval=true;
00146   return retval;
00147 
00148 }

bool 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 49 of file DTROS8FileReader.cc.

References checkEndOfFile(), edmNew::copy(), GenMuonPlsPt100GeV_cfg::cout, FEDRawData::data(), lat::endl(), FEDRawDataCollection::FEDData(), first, FEDNumbering::getDTFEDIds(), i, inputFile, RawFile::read(), FEDRawData::resize(), and ros8WordLenght.

00051                                                                {
00052   data = new FEDRawDataCollection();
00053 
00054   try {
00055     
00056 
00057     if( checkEndOfFile() ) throw 1; 
00058     
00059 
00060     // Get the total number of words from the 1st word in the payload
00061     int numberOfWords;
00062     int nread = 0;
00063     nread = inputFile.read(dataPointer<int>( &numberOfWords ), ros8WordLenght);
00064     if ( nread<=0 )  throw 1;
00065 
00066 
00067     // Get the event data (all words but the 1st)
00068     int* eventData = new int[numberOfWords];
00069     nread = inputFile.read(dataPointer<int>( eventData + 1 ), (numberOfWords-1) * ros8WordLenght );
00070     if ( nread<=0 ) throw 1;
00071     
00072 
00073     // Check that the event data size corresponds to the 1st word datum 
00074     if ( eventData[numberOfWords-1] != numberOfWords ) {
00075       cout << "[DTROS8FileReader]: word counter mismatch exception: "
00076            << numberOfWords << " " << eventData[numberOfWords-1] << endl;
00077       throw 99;
00078     }
00079 
00080     // The header added by the local DAQ occupies 8 words, starting from the 2nd 
00081     int* head = eventData + 1;
00082     
00083     /* 
00084       Header word 0: run number
00085       Header word 1: spill number
00086       Header word 2: event number
00087       Header word 3: reserved
00088       Header word 4: ROS data offset
00089       Header word 5: PU data offset
00090       Header word 6: reserved
00091       Header word 7: reserved
00092     */
00093 
00094     // WARNING: the event number is reset at a new spill
00095     eID = EventID( head[0], head[1]*head[2]);
00096 
00097     // The pointer to the ROS payload (the 1st word being the ROS words counter)
00098     int* rosData = eventData + head[4];
00099 
00100     // The ROS payload size
00101     int eventDataSize = *rosData * ros8WordLenght;
00102     // It has to be a multiple of 8 bytes. if not, adjust the size of the FED payload
00103     int adjustment = (eventDataSize/4)%2 == 1 ? 4 : 0;   
00104     
00105     //if ( (eventDataSize/4)%2 ) adjustment = 4;
00106 
00107 
00108     // The FED ID is always the first in the DT range
00109     FEDRawData& fedRawData = data->FEDData( FEDNumbering::getDTFEDIds().first );
00110     fedRawData.resize(eventDataSize+adjustment);
00111     
00112     // I pass only the ROS data to the Event
00113     copy(reinterpret_cast<unsigned char*>(rosData), 
00114          reinterpret_cast<unsigned char*>(rosData) + eventDataSize, fedRawData.data());
00115 
00116     // needed to get rid of memory leaks (?)
00117     delete[] eventData;
00118 
00119     return true;
00120   }
00121 
00122   catch( int i ) {
00123 
00124     if ( i == 1 ){
00125       cout << "[DTROS8FileReader]: END OF FILE REACHED. "
00126            << "No information read for the requested event" << endl;
00127       delete data; data=0;
00128       return false;
00129     }    
00130     else {
00131       cout << "[DTROS8FileReader]: PROBLEM WITH EVENT INFORMATION ON THE FILE. "
00132            << "EVENT DATA READING FAILED  code= " << i << endl;
00133       delete data; data=0;
00134       return false;
00135     }
00136 
00137   }
00138 
00139 }


Member Data Documentation

edm::EventNumber_t DTROS8FileReader::eventNum [private]

Definition at line 38 of file DTROS8FileReader.h.

RawFile DTROS8FileReader::inputFile [private]

Definition at line 35 of file DTROS8FileReader.h.

Referenced by checkEndOfFile(), DTROS8FileReader(), fillRawData(), and ~DTROS8FileReader().

const int DTROS8FileReader::ros8WordLenght = 4 [static, private]

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.


The documentation for this class was generated from the following files:
Generated on Tue Jun 9 18:19:03 2009 for CMSSW by  doxygen 1.5.4