CMS 3D CMS Logo

Public Member Functions | Private Attributes | Static Private Attributes

DTROS8FileReader Class Reference

#include <DTROS8FileReader.h>

Inheritance diagram for DTROS8FileReader:
DaqBaseReader

List of all members.

Public Member Functions

virtual bool checkEndOfFile ()
 DTROS8FileReader (const edm::ParameterSet &pset)
 Constructor.
virtual int 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:
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 Exception, RawFile::fail(), lut2db_cfg::filename, edm::ParameterSet::getParameter(), inputFile, and RawFile::open().

                                                              : 
  runNum(1), eventNum(0) {
      
  const string & filename = pset.getParameter<string>("fileName");

  inputFile.open(filename.c_str());
  if( inputFile.fail() ) {
    throw cms::Exception("InputFileMissing") 
      << "DTROS8FileReader: the input file: " << filename <<" is not present";
  }
}
DTROS8FileReader::~DTROS8FileReader ( ) [virtual]

Destructor.

Definition at line 45 of file DTROS8FileReader.cc.

References RawFile::close(), and inputFile.

                                   {
  inputFile.close();
}

Member Function Documentation

bool DTROS8FileReader::checkEndOfFile ( ) [virtual]

Definition at line 143 of file DTROS8FileReader.cc.

References RawFile::eof(), and inputFile.

Referenced by fillRawData().

                                     {

  bool retval=false;
  if ( inputFile.eof() ) retval=true;
  return retval;

}
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, data, FEDRawData::data(), FEDRawDataCollection::FEDData(), i, inputFile, FEDNumbering::MINDTFEDID, RawFile::read(), FEDRawData::resize(), and ros8WordLenght.

                                                              {
  data = new FEDRawDataCollection();

  try {
    

    if( checkEndOfFile() ) throw 1; 
    

    // Get the total number of words from the 1st word in the payload
    int numberOfWords;
    int nread = 0;
    nread = inputFile.read(dataPointer<int>( &numberOfWords ), ros8WordLenght);
    if ( nread<=0 )  throw 1;


    // Get the event data (all words but the 1st)
    int* eventData = new int[numberOfWords];
    nread = inputFile.read(dataPointer<int>( eventData + 1 ), (numberOfWords-1) * ros8WordLenght );
    if ( nread<=0 ) throw 1;
    

    // Check that the event data size corresponds to the 1st word datum 
    if ( eventData[numberOfWords-1] != numberOfWords ) {
      cout << "[DTROS8FileReader]: word counter mismatch exception: "
           << numberOfWords << " " << eventData[numberOfWords-1] << endl;
      throw 99;
    }

    // The header added by the local DAQ occupies 8 words, starting from the 2nd 
    int* head = eventData + 1;
    
    /* 
      Header word 0: run number
      Header word 1: spill number
      Header word 2: event number
      Header word 3: reserved
      Header word 4: ROS data offset
      Header word 5: PU data offset
      Header word 6: reserved
      Header word 7: reserved
    */

    // WARNING: the event number is reset at a new spill
    eID = EventID( head[0], 1U, head[1]*head[2]);

    // The pointer to the ROS payload (the 1st word being the ROS words counter)
    int* rosData = eventData + head[4];

    // The ROS payload size
    int eventDataSize = *rosData * ros8WordLenght;
    // It has to be a multiple of 8 bytes. if not, adjust the size of the FED payload
    int adjustment = (eventDataSize/4)%2 == 1 ? 4 : 0;   
    
    //if ( (eventDataSize/4)%2 ) adjustment = 4;


    // The FED ID is always the first in the DT range
    FEDRawData& fedRawData = data->FEDData( FEDNumbering::MINDTFEDID );
    fedRawData.resize(eventDataSize+adjustment);
    
    // I pass only the ROS data to the Event
    copy(reinterpret_cast<unsigned char*>(rosData), 
         reinterpret_cast<unsigned char*>(rosData) + eventDataSize, fedRawData.data());

    // needed to get rid of memory leaks (?)
    delete[] eventData;

    return true;
  }

  catch( int i ) {

    if ( i == 1 ){
      cout << "[DTROS8FileReader]: END OF FILE REACHED. "
           << "No information read for the requested event" << endl;
      delete data; data=0;
      return false;
    }    
    else {
      cout << "[DTROS8FileReader]: PROBLEM WITH EVENT INFORMATION ON THE FILE. "
           << "EVENT DATA READING FAILED  code= " << i << endl;
      delete data; data=0;
      return false;
    }

  }

}

Member Data Documentation

Definition at line 38 of file DTROS8FileReader.h.

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

Definition at line 40 of file DTROS8FileReader.h.

Referenced by fillRawData().

Definition at line 37 of file DTROS8FileReader.h.