CMS 3D CMS Logo

FileReaderSP Class Reference

#include <IORawData/CSCTFCommissioning/src/FileReaderSP.h>

Inheritance diagram for FileReaderSP:

SPReader

List of all members.

Public Member Functions

virtual void Configure ()
virtual int disableBlock ()
virtual int enableBlock ()
virtual int endBlockRead ()
 FileReaderSP ()
virtual int readSP (unsigned short **buf, const bool debug=false)
 assumes fd_schar has been set
virtual int reset ()
virtual ~FileReaderSP ()

Protected Member Functions

virtual int chunkSize ()
 How many bytes to read at a time.
int fillMiniBuf ()
bool isHeader ()

Protected Attributes

unsigned short key [3]
queue< unsigned short > miniBuf
int pointer
unsigned short refBuf [MAXBUFSIZE]

Static Protected Attributes

static const int MAXBUFSIZE = 6


Detailed Description

Definition at line 8 of file FileReaderSP.h.


Constructor & Destructor Documentation

FileReaderSP::FileReaderSP (  ) 

Definition at line 10 of file FileReaderSP.cc.

References key, and pointer.

00011 {
00012   pointer = 0;
00013   key[0] = 0xf000;
00014   key[1] = 0x7fff;
00015   key[2] = 0x7fff;
00016 }

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

Definition at line 12 of file FileReaderSP.h.

00012 {}


Member Function Documentation

int FileReaderSP::chunkSize (  )  [protected, virtual]

How many bytes to read at a time.

Implements SPReader.

Definition at line 22 of file FileReaderSP.cc.

00022                             {
00023   /*int cnt[2];
00024   read(fd_schar,cnt,4);
00025   return cnt[0];*/
00026   return 0;
00027 }

void FileReaderSP::Configure (  )  [virtual]

Reimplemented from SPReader.

Definition at line 18 of file FileReaderSP.cc.

00018                              {
00019 }

virtual int FileReaderSP::disableBlock (  )  [inline, virtual]

Implements SPReader.

Definition at line 17 of file FileReaderSP.h.

00017 {return 0;}

virtual int FileReaderSP::enableBlock (  )  [inline, virtual]

Implements SPReader.

Definition at line 16 of file FileReaderSP.h.

00016 {return 0;}

virtual int FileReaderSP::endBlockRead (  )  [inline, virtual]

Implements SPReader.

Definition at line 18 of file FileReaderSP.h.

00018 {return 0;}

int FileReaderSP::fillMiniBuf (  )  [protected]

Definition at line 92 of file FileReaderSP.cc.

References count, SPReader::fd_schar, miniBuf, SiStripLorentzAngle_cfi::read, and pyDBSRunClass::temp.

Referenced by readSP().

00093 {
00094   int count=0;
00095   unsigned short temp[1];
00096   while(miniBuf.size() < 6)
00097     {
00098       if(read(fd_schar,temp,2)==2)
00099         {
00100           miniBuf.push(temp[0]);
00101           count++;
00102         }
00103       else
00104         {
00105           return -1;
00106         }
00107     }
00108   return count;
00109 }

bool FileReaderSP::isHeader (  )  [protected]

Definition at line 111 of file FileReaderSP.cc.

References edm::holder, i, key, MAXBUFSIZE, miniBuf, and refBuf.

Referenced by readSP().

00112 {
00113   int holder = 0;
00114   for(int i=0;i<MAXBUFSIZE;i++)
00115     {
00116       holder = miniBuf.front();
00117       refBuf[i] = holder;
00118       miniBuf.pop();
00119       miniBuf.push(refBuf[i]);
00120     }    
00121 
00122   return ((refBuf[0]&key[0])==key[0] && (refBuf[1]&key[0])==key[0] && (refBuf[2]&key[0])==key[0]
00123           && (refBuf[3]&key[0])==key[0] && (refBuf[4]|key[1])==key[1] && (refBuf[5]|key[2])==key[2]);
00124 }

int FileReaderSP::readSP ( unsigned short **  buf,
const bool  debug = false 
) [virtual]

assumes fd_schar has been set

Implements SPReader.

Definition at line 30 of file FileReaderSP.cc.

References a, counter(), GenMuonPlsPt100GeV_cfg::cout, event(), SPReader::fd_schar, fillMiniBuf(), edm::holder, isHeader(), prof2calltree::last, miniBuf, pointer, SiStripLorentzAngle_cfi::read, and tmp.

00030                                                                {
00031  
00032   int counter=0;
00033   unsigned short tmp[1];
00034   unsigned short holder =0;
00035   unsigned short a[6000];
00036   int bytes_read=0;
00037 
00038   do{
00039     if(pointer == 0)
00040       {
00041         bytes_read = read(fd_schar,tmp,2);  //read only 1 line == 2 bytes of data
00042         if(bytes_read != 2)
00043           {
00044             cout<<"FileReaderSP :: Reached end of file!!!\n";
00045             return 0;
00046           }
00047         a[counter]=tmp[0];
00048       }
00049     else
00050       {
00051         holder = miniBuf.front();
00052         a[counter] = holder;
00053         miniBuf.pop();
00054         holder = 0;
00055       }
00056 
00057     counter++;
00058     if((bytes_read = fillMiniBuf())== -1)
00059       {
00060         while(miniBuf.size()>0)
00061           {
00062             holder = miniBuf.front();
00063             a[counter] = holder;
00064             miniBuf.pop();
00065             holder = 0;
00066             counter++;    
00067           }
00068         void * last = malloc((counter-1)*sizeof(unsigned short));
00069         memset(last,0,(counter-1)*sizeof(unsigned short));
00070         memcpy(last,a,(counter-1)*sizeof(unsigned short));
00071         *buf=reinterpret_cast<unsigned short*>(last);
00072         pointer = 0;
00073         return (counter-1)*sizeof(unsigned short);
00074       }
00075     pointer += bytes_read;
00076 
00077   }while(!isHeader());
00078 
00079   void * event = malloc(counter*sizeof(unsigned short));
00080   memset(event,0,counter*sizeof(unsigned short));
00081   memcpy(event,a,counter*sizeof(unsigned short));
00082   *buf=reinterpret_cast<unsigned short*>(event);
00083 
00084   
00085   
00086   //printf("\n\n\n  returning %d: \n\n\n",(count*8));
00087 
00088   return counter*sizeof(unsigned short);  //Total number of bytes read
00089 
00090 } //readSP

virtual int FileReaderSP::reset ( void   )  [inline, virtual]

Implements SPReader.

Definition at line 15 of file FileReaderSP.h.

00015 {return 0;}


Member Data Documentation

unsigned short FileReaderSP::key[3] [protected]

Definition at line 29 of file FileReaderSP.h.

Referenced by FileReaderSP(), and isHeader().

const int FileReaderSP::MAXBUFSIZE = 6 [static, protected]

Definition at line 26 of file FileReaderSP.h.

Referenced by isHeader().

queue<unsigned short> FileReaderSP::miniBuf [protected]

Definition at line 30 of file FileReaderSP.h.

Referenced by fillMiniBuf(), isHeader(), and readSP().

int FileReaderSP::pointer [protected]

Definition at line 27 of file FileReaderSP.h.

Referenced by FileReaderSP(), and readSP().

unsigned short FileReaderSP::refBuf[MAXBUFSIZE] [protected]

Definition at line 28 of file FileReaderSP.h.

Referenced by isHeader().


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