CMS 3D CMS Logo

EcalTBDaqRFIOFile Class Reference

#include <IORawData/EcalTBInputService/src/EcalTBDaqRFIOFile.h>

Inheritance diagram for EcalTBDaqRFIOFile:

EcalTBDaqFile

List of all members.

Public Member Functions

virtual bool checkEndOfFile ()
virtual void close ()
 EcalTBDaqRFIOFile (const std::string &filename, const bool &isBinary)
 Constructor.
 EcalTBDaqRFIOFile ()
 Constructor.
virtual bool getEventData (FedDataPair &data)
virtual ~EcalTBDaqRFIOFile ()
 Destructor.

Protected Attributes

std::string filename_
FILE * infile_
bool isBinary_


Detailed Description

Definition at line 11 of file EcalTBDaqRFIOFile.h.


Constructor & Destructor Documentation

EcalTBDaqRFIOFile::EcalTBDaqRFIOFile (  )  [inline]

Constructor.

Definition at line 16 of file EcalTBDaqRFIOFile.h.

00016 : filename_(), isBinary_(), infile_() {};

EcalTBDaqRFIOFile::EcalTBDaqRFIOFile ( const std::string &  filename,
const bool isBinary 
)

Constructor.

Definition at line 25 of file EcalTBDaqRFIOFile.cc.

References cmsRelvalreport::exit, fd, infile_, isBinary_, rfio_fopen(), and rfio_open().

00025                                                                                     : filename_(filename), isBinary_(isBinary)
00026 {
00027   if ( isBinary_ )
00028     {
00029       // case of binary input data file
00030       LogInfo("EcalTBDaqRFIOFile") << "@SUB=EcalTBDaqRFIOFile::initialize" << "Opening binary data file " << filename;
00031       int fd = rfio_open(filename.c_str(), O_RDONLY, 0644);
00032       if( fd < 0 ) 
00033         {
00034           LogError("EcalTBDaqRFIOFile") << "@SUB=EcalTBDaqRFIOFile::initialize" << "the input file: " << filename << " cannot be opened. Exiting program... " ;
00035           exit(1);
00036         }
00037       infile_ = rfio_fopen((char*)filename.c_str(), "r");
00038     }// end if binary
00039 
00040   else
00041     {
00042       LogInfo("EcalTBDaqRFIOFile") << "@SUB=EcalTBDaqRFIOFile::initialize" << "Opening ASCII file " << filename;
00043       int fd = rfio_open(filename.c_str(), O_RDONLY, 0644);
00044       if( fd < 0 )
00045         {
00046           LogError("EcalTBDaqRFIOFile") << "@SUB=EcalTBDaqRFIOFile::initialize" << "the input file: " << filename << " cannot be opened. Exiting program... " ;
00047           exit(1);
00048         }
00049       infile_ = rfio_fopen((char*)filename.c_str(), "r");
00050     }// end if not binary
00051 }

virtual EcalTBDaqRFIOFile::~EcalTBDaqRFIOFile (  )  [inline, virtual]

Destructor.

Definition at line 22 of file EcalTBDaqRFIOFile.h.

References close().

00023     {
00024       close();
00025     };


Member Function Documentation

bool EcalTBDaqRFIOFile::checkEndOfFile (  )  [virtual]

Reimplemented from EcalTBDaqFile.

Definition at line 153 of file EcalTBDaqRFIOFile.cc.

References end, infile_, rfio_fseek(), and rfio_ftell().

00154 {
00155   //unsigned char * buf = new unsigned char;
00156   long curr=rfio_ftell(infile_);
00157   rfio_fseek(infile_,0,SEEK_END);
00158   long end=rfio_ftell(infile_);
00159   rfio_fseek(infile_,curr,SEEK_SET);
00160   return (curr==end);
00161 }

void EcalTBDaqRFIOFile::close ( void   )  [virtual]

Reimplemented from EcalTBDaqFile.

Definition at line 164 of file EcalTBDaqRFIOFile.cc.

References infile_, and rfio_fclose().

Referenced by ~EcalTBDaqRFIOFile().

00165 {
00166   if (infile_) {
00167     rfio_fclose(infile_);
00168     infile_ = 0;
00169   }
00170 }

bool EcalTBDaqRFIOFile::getEventData ( FedDataPair data  )  [virtual]

Reimplemented from EcalTBDaqFile.

Definition at line 54 of file EcalTBDaqRFIOFile.cc.

References c, EcalTBDaqFile::EOE_, false, FedDataPair::fedData, i, infile_, isBinary_, len, FedDataPair::len, EcalTBDaqFile::maxEventSizeInBytes_, rfio_fread(), rfio_fseek(), size, and tmp.

00054                                                       {
00055 
00056   if (isBinary_){
00057     ulong dataStore=1;
00058   
00059     // read first words of event, seeking for event size 
00060     if (rfio_fread(reinterpret_cast<char *>(&dataStore),sizeof(ulong),1,infile_) < 0)
00061       return false;
00062     if (rfio_fread(reinterpret_cast<char *>(&dataStore),sizeof(ulong),1,infile_) < 0)
00063       return false;
00064     if (rfio_fread(reinterpret_cast<char *>(&dataStore),sizeof(ulong),1,infile_) < 0)
00065       return false;
00066 
00067     int size =  dataStore & 0xffffff ;
00068     //     cout << "[EcalTB DaqFileReader::getEventTrailer] event size masked  "<<  size 
00069     //   << " (max size in byte is " << maxEventSizeInBytes_ << ")"<< endl;
00070     if (size > EcalTBDaqFile::maxEventSizeInBytes_){
00071       LogWarning("EcalTBDaqRFIOFile") << "@SUB=EcalTBDaqRFIOFile::getEventData" << "event size larger than allowed";
00072       return false;
00073     }
00074   
00075 
00076     if (rfio_fseek(infile_,-2*4,SEEK_CUR) < 0)
00077       return false ;
00078     if (rfio_fread(reinterpret_cast<char *>(&dataStore),sizeof(ulong),1,infile_) < 0)
00079       return false;
00080     //cout << "is it beginning?\t"<< a << endl;
00081     if (rfio_fseek(infile_,-2*4,SEEK_CUR) < 0)
00082       return false;
00083   
00084     // 
00085     char   * bufferChar =  new  char [8* size];
00086     if (rfio_fread(bufferChar,size*8,1,infile_) < 0)
00087       return false;
00088 
00089     data.len         = size*8;
00090     data.fedData = reinterpret_cast<unsigned char*>(bufferChar);
00091 
00092   }// end in case of binary file
00093   
00094 
00095   else{
00096     string myWord;
00097 
00098     // allocate max memory allowed, use only what needed
00099     int len=0;
00100     ulong* buf = new ulong [EcalTBDaqFile::maxEventSizeInBytes_];
00101     ulong* tmp=buf;
00102 
00103     // importing data word by word
00104     for ( int i=0; i< EcalTBDaqFile::maxEventSizeInBytes_/4; ++i) {
00105 //      infile_ >> myWord;
00106 
00107       myWord = "";
00108       while ( 1 ) {
00109         char c[1];
00110         if (rfio_fread(c,1,1,infile_) < 0)
00111           return false;
00112         if ( c[0] == '\n' )
00113           break;
00114         myWord += c[0];
00115       }
00116 
00117       if (sscanf( myWord.c_str(),"%x",buf) == EOF)
00118         return false;
00119       int val= *buf >> 28;
00120 
00121 //       if (i<4)
00122 //      cout << " myWord " << myWord << " myWord >> 28 " << val << endl;
00123 
00124 
00125       if ( len%2!=0 ) {
00126         // looking for end of event searching a tag
00127         if ( val  == EcalTBDaqFile::EOE_ ) {
00128           //        cout << " EcalTBDaqSimpleFile::getEventTrailer EOE_ reached " <<   endl;
00129           len++;
00130           break;
00131         }
00132       }
00133       buf+=1;
00134       len++;
00135 
00136     }// end loop importing data word by word
00137 
00138     //    cout << " Number of 32 words in the event " << len << endl;
00139     len*=4;
00140     //    cout << " Length in bytes " << len << endl;
00141 
00142     data.len = len;
00143     //fedData = reinterpret_cast<unsigned char*>(tmp);
00144     data.fedData = reinterpret_cast<unsigned char*>(tmp);
00145 
00146 
00147   }// end in case of ASCII file
00148 
00149   return true;
00150 }


Member Data Documentation

std::string EcalTBDaqRFIOFile::filename_ [protected]

Definition at line 37 of file EcalTBDaqRFIOFile.h.

FILE* EcalTBDaqRFIOFile::infile_ [protected]

Definition at line 39 of file EcalTBDaqRFIOFile.h.

Referenced by checkEndOfFile(), close(), EcalTBDaqRFIOFile(), and getEventData().

bool EcalTBDaqRFIOFile::isBinary_ [protected]

Definition at line 38 of file EcalTBDaqRFIOFile.h.

Referenced by EcalTBDaqRFIOFile(), and getEventData().


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