CMS 3D CMS Logo

Public Types | Public Member Functions | Private Attributes

FileReaderDCC Class Reference

#include <FileReaderDCC.h>

List of all members.

Public Types

enum  {
  Header = 1, Trailer = 2, DCCoversize = 4, FFFF = 8,
  Unknown = 16, EndOfStream = 32
}
enum  {
  Type1 = Header|Trailer, Type2 = Header, Type3 = Header|DCCoversize, Type4 = Trailer,
  Type5 = Unknown, Type6 = Unknown|DCCoversize, Type7 = FFFF
}

Public Member Functions

void accept (unsigned int criteria) throw ()
 FileReaderDCC (void)
size_t next (const unsigned short *&buf) throw (std::runtime_error)
int open (const char *filename) throw (std::runtime_error)
size_t read (const unsigned short *&buf) throw (std::runtime_error)
void reject (unsigned int criteria) throw ()
void select (unsigned int criteria) throw ()
unsigned int status (void) const throw ()
virtual ~FileReaderDCC (void)

Private Attributes

unsigned int acceptCriteria
unsigned long long * end
unsigned int eventStatus
int fd
unsigned long long file_buffer [4000]
unsigned long long * file_buffer_end
unsigned short * raw_event
unsigned int rejectCriteria
unsigned int selectCriteria
unsigned long long word_0
unsigned long long word_1
unsigned long long word_2

Detailed Description

Definition at line 7 of file FileReaderDCC.h.


Member Enumeration Documentation

anonymous enum
Enumerator:
Header 
Trailer 
DCCoversize 
FFFF 
Unknown 
EndOfStream 

Definition at line 17 of file FileReaderDCC.h.

anonymous enum
Enumerator:
Type1 
Type2 
Type3 
Type4 
Type5 
Type6 
Type7 

Definition at line 18 of file FileReaderDCC.h.


Constructor & Destructor Documentation

FileReaderDCC::FileReaderDCC ( void  )

Definition at line 15 of file FileReaderDCC.cc.

References acceptCriteria, DCCoversize, end, eventStatus, fd, FFFF, file_buffer, file_buffer_end, raw_event, rejectCriteria, selectCriteria, AlCaHLTBitMon_QueryRunRegistry::string, Trailer, Unknown, word_0, word_1, and word_2.

                                {
        if( sizeof(unsigned long long)!=8 || sizeof(unsigned short)!=2 )
                throw std::runtime_error(std::string("Wrong platform: sizeof(unsigned long long)!=8 || sizeof(unsigned short)!=2"));
        raw_event = new unsigned short [200000*40];
        end = (file_buffer_end = file_buffer + sizeof(file_buffer)/sizeof(unsigned long long));
        bzero(raw_event,  sizeof(raw_event)  );
        bzero(file_buffer,sizeof(file_buffer));
        word_0=0; word_1=0; word_2=0;
        eventStatus = 0;
        selectCriteria = Header|Trailer;
        rejectCriteria = DCCoversize|FFFF|Unknown;
        acceptCriteria = 0x3F; // Everything
        fd = 0;
}
FileReaderDCC::~FileReaderDCC ( void  ) [virtual]

Definition at line 30 of file FileReaderDCC.cc.

References fd.

{ if( fd ) close(fd); }

Member Function Documentation

void FileReaderDCC::accept ( unsigned int  criteria) throw () [inline]

Definition at line 29 of file FileReaderDCC.h.

References acceptCriteria.

{ acceptCriteria = criteria; } // return all events satisfying any of criteria
size_t FileReaderDCC::next ( const unsigned short *&  buf) throw (std::runtime_error)

Definition at line 126 of file FileReaderDCC.cc.

References SiPixelLorentzAngle_cfi::read, and findQualityFiles::size.

Referenced by CSCFileReader::readFU().

                                                                             {
        size_t size=0;
        do {
                if( (size = read(buf)) == 0 ) break;
        } while( rejectCriteria&eventStatus || !(acceptCriteria&eventStatus) || (selectCriteria?selectCriteria!=eventStatus:0) );
        return size;
}
int FileReaderDCC::open ( const char *  filename) throw (std::runtime_error)

Definition at line 32 of file FileReaderDCC.cc.

References python::multivaluedict::append(), lut2db_cfg::filename, O_LARGEFILE, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by CSCFileReader::CSCFileReader(), and CSCFileReader::readFU().

                                                                     {
        if( fd ) close(fd);
        fd = ::open(filename,O_RDONLY|O_LARGEFILE);
        if( fd == -1 ) throw ( std::runtime_error(std::string("Error opening ").append(filename).append(" data file.")) );
        return fd;
}
size_t FileReaderDCC::read ( const unsigned short *&  buf) throw (std::runtime_error)

Definition at line 39 of file FileReaderDCC.cc.

References end, event(), SiPixelLorentzAngle_cfi::read, dqm_diff::start, and Unknown.

                                                                              {
        // Check for ubnormal situation
        if( end>file_buffer_end || end<file_buffer ) throw ( std::runtime_error("Error of reading") );
        if( !fd ) throw ( std::runtime_error("Open some file first") );

        unsigned long long *start = end;
        unsigned short     *event = raw_event;

        eventStatus = 0;
        size_t dccWordCount = 0;
        end = 0;

        while( !end && dccWordCount<50000*40 ){
                unsigned long long *dccWord = start;
                unsigned long long preHeader = 0;

                // Did we reach end of current buffer and want to read next block?
                // If it was first time and we don't have file buffer then we won't get inside
                while( dccWord<file_buffer_end && dccWordCount<50000 ){
                        word_0 =  word_1; // delay by 2 DCC words
                        word_1 =  word_2; // delay by 1 DCC word
                        word_2 = *dccWord;// current DCC word
                        if( (word_1&0xF0000000000000FFLL)==0x500000000000005FLL && // let's call this a preHeader
                                (word_2&0xFF000000000000FFLL)==0xD900000000000017LL ){ // and this is a header
                                if( eventStatus&Header ){ // Second header
                                        word_2 = word_1; // Fall back to get rigth preHeader next time
                                        end = dccWord;   // Even if we end with preHeader of next evet put it to the end of this event too
                                        break;
                                }
                                if( dccWordCount>1 ){ // Extra words between trailer and header
                                        if( (word_0&0xFFFFFFFFFFFF0000LL)==0xFFFFFFFFFFFF0000LL ) eventStatus |= FFFF;
                                        word_2 = word_1; // Fall back to get rigth preHeader next time
                                        end = dccWord;
                                        break;
                                }
                                eventStatus |= Header;
                                if( event==raw_event ) preHeader = word_1; // If preHeader not yet in event then put it there
                                start = dccWord;
                        }
                        if( (word_1&0xFF00000000000000LL)==0xEF00000000000000LL &&
                                (word_2&0xFF0000000000000FLL)==0xAF00000000000007LL ){
                                eventStatus |= Trailer;
                                end = ++dccWord;
                                break;
                        }
                        // Increase counters by one DCC word
                        dccWord++;
                        dccWordCount++;
                }

                // If have DCC Header
                if( preHeader ){
                        // Need to account first word of DCC Header
                        memcpy(event,&preHeader,sizeof(preHeader));
                        event += sizeof(preHeader)/sizeof(unsigned short);
                }

                // Take care of the rest
                memcpy(event,start,(dccWord-start)*sizeof(unsigned long long));
                event += (dccWord-start)*sizeof(unsigned long long)/sizeof(unsigned short);

                // If reach max length
                if( dccWordCount==50000*40 ){ end = dccWord; break; }

                if( !end ){
                        // Need to read next block for the rest of this event
                        ssize_t length = ::read(fd,file_buffer,sizeof(file_buffer));
                        if( length==-1 ) throw ( std::runtime_error("Error of reading") );
                        if( length== 0 ){
                                eventStatus |= EndOfStream;
                                end = (file_buffer_end = file_buffer + sizeof(file_buffer)/sizeof(unsigned long long));
                                break;
                        }
                        file_buffer_end = file_buffer + length/sizeof(unsigned long long);

                        // Will start from the beginning of new buffer next time we read it
                        start = file_buffer;
                }
        }

        if( !end ) eventStatus |= DCCoversize;
        if( !(eventStatus&Header) && !(eventStatus&Trailer) && !(eventStatus&FFFF) ) eventStatus |= Unknown;

        buf = (const unsigned short*)raw_event;
        return (eventStatus&FFFF?event-raw_event-4:event-raw_event);
}
void FileReaderDCC::reject ( unsigned int  criteria) throw () [inline]

Definition at line 30 of file FileReaderDCC.h.

References rejectCriteria.

Referenced by CSCFileReader::CSCFileReader().

{ rejectCriteria = criteria; } // return events not satisfying any of criteria
void FileReaderDCC::select ( unsigned int  criteria) throw () [inline]

Definition at line 28 of file FileReaderDCC.h.

References selectCriteria.

Referenced by CSCFileReader::CSCFileReader().

{ selectCriteria = criteria; } // return events satisfying all criteria
unsigned int FileReaderDCC::status ( void  ) const throw () [inline]

Definition at line 32 of file FileReaderDCC.h.

References eventStatus.

{ return eventStatus; }

Member Data Documentation

unsigned int FileReaderDCC::acceptCriteria [private]

Definition at line 20 of file FileReaderDCC.h.

Referenced by accept(), and FileReaderDCC().

unsigned long long* FileReaderDCC::end [private]

Definition at line 14 of file FileReaderDCC.h.

Referenced by FileReaderDCC().

unsigned int FileReaderDCC::eventStatus [private]

Definition at line 20 of file FileReaderDCC.h.

Referenced by FileReaderDCC(), and status().

int FileReaderDCC::fd [private]

Definition at line 22 of file FileReaderDCC.h.

Referenced by FileReaderDCC(), and ~FileReaderDCC().

unsigned long long FileReaderDCC::file_buffer[4000] [private]

Definition at line 12 of file FileReaderDCC.h.

Referenced by FileReaderDCC().

unsigned long long * FileReaderDCC::file_buffer_end [private]

Definition at line 14 of file FileReaderDCC.h.

Referenced by FileReaderDCC().

unsigned short* FileReaderDCC::raw_event [private]

Definition at line 9 of file FileReaderDCC.h.

Referenced by FileReaderDCC().

unsigned int FileReaderDCC::rejectCriteria [private]

Definition at line 20 of file FileReaderDCC.h.

Referenced by FileReaderDCC(), and reject().

unsigned int FileReaderDCC::selectCriteria [private]

Definition at line 20 of file FileReaderDCC.h.

Referenced by FileReaderDCC(), and select().

unsigned long long FileReaderDCC::word_0 [private]

Definition at line 11 of file FileReaderDCC.h.

Referenced by FileReaderDCC().

unsigned long long FileReaderDCC::word_1 [private]

Definition at line 11 of file FileReaderDCC.h.

Referenced by FileReaderDCC().

unsigned long long FileReaderDCC::word_2 [private]

Definition at line 11 of file FileReaderDCC.h.

Referenced by FileReaderDCC().