Go to the documentation of this file.00001 #include "EventFilter/CSCTFRawToDigi/src/CSCTFEvent.h"
00002 #include "EventFilter/CSCTFRawToDigi/src/CSCSPHeader.h"
00003 #include <string.h>
00004 #include <stdexcept>
00005
00006 unsigned int CSCTFEvent::unpack(const unsigned short *buf, unsigned int length) throw() {
00007
00008 nRecords = 0;
00009 bzero(sp,sizeof(sp));
00010
00011
00012 if( sizeof(unsigned long long)!=8 || sizeof(unsigned short)!=2 )
00013 throw std::runtime_error(std::string("Wrong platform: sizeof(unsigned long long)!=8 || sizeof(unsigned short)!=2"));
00014
00015
00016 unsigned long coruptions=0;
00017
00018
00019 unsigned long long *dduWord = (unsigned long long*) buf, word_1=0, word_2=0;
00020
00021 length /= sizeof(unsigned long long)/sizeof(unsigned short);
00022
00023 bool spHeader=false, spTrailer=false;
00024 unsigned long spWordCount=0, spWordCountExpected=0;
00025
00026
00027 unsigned int index=0;
00028 while( index<length ){
00029 word_1 = word_2;
00030 word_2 = dduWord[index];
00031
00032 if( spHeader && !spTrailer ) spWordCount++;
00033
00034 if( (word_1&0xF000F000F000F000LL)==0x9000900090009000LL &&
00035 (word_2&0xF000F000F000F000LL)==0xA000A000A000A000LL ){
00036 if( spHeader ){
00037 coruptions |= MISSING_TRAILER;
00038 break;
00039 }
00040 spHeader=true;
00041 spTrailer=false;
00042
00043 spWordCount=0;
00044 spWordCountExpected=0;
00045
00046 CSCSPHeader header;
00047 const unsigned short *spWord = (unsigned short*) &dduWord[index-1];
00048
00049 header.unpack(spWord);
00050
00051
00052 if( header.format_version() && !header.empty() ){
00053 if( length > index+1 ){ spWord += 4; } else { coruptions |= OUT_OF_BUFFER; break; }
00054 }
00055
00056
00057 for(unsigned short tbin=0,shift=0; tbin<header.nTBINs() && !header.empty(); tbin++){
00058
00059 if( length <= index+spWordCountExpected+2 ){
00060 coruptions |= OUT_OF_BUFFER;
00061 break;
00062 } else {
00063
00064 if( header.format_version()>=3 && header.suppression() ){
00065
00066 if( ((spWord[shift+7]>>8) & 0x7) != tbin+1 ) continue;
00067
00068 if( (spWord[shift+0]&0xF000)==0xF000 && (spWord[shift+1]&0xF000)==0xF000 && (spWord[shift+2]&0xF000)==0xF000 && (spWord[shift+3]&0xF000)==0xF000 &&
00069 (spWord[shift+4]&0xF000)==0xE000 && (spWord[shift+5]&0xF000)==0xE000 && (spWord[shift+6]&0xF000)==0xE000 && (spWord[shift+7]&0xF000)==0xE000 ) break;
00070 }
00071
00072
00073 spWordCountExpected += 2;
00074
00075 for(unsigned int me_block=0; me_block<15; me_block++)
00076 if( header.active()&(1<<(me_block/3)) && (!header.suppression() || spWord[shift+0]&(1<<me_block)) )
00077 spWordCountExpected += 1;
00078
00079 for(unsigned int mb_block=0; mb_block<2; mb_block++)
00080 if( header.active()&0x20 && (!header.suppression() || spWord[shift+1]&(1<<(mb_block+12))) )
00081 spWordCountExpected += 1;
00082
00083 for(unsigned int sp_block=0; sp_block<3; sp_block++)
00084 if( header.active()&0x40 && (!header.suppression() || spWord[shift+1]&(0xF<<(sp_block*4))) )
00085 spWordCountExpected += 1;
00086
00087 shift = spWordCountExpected*4;
00088 }
00089 }
00090
00091
00092 if( header.format_version() && !header.empty() ) spWordCountExpected += 1;
00093
00094 if( coruptions&OUT_OF_BUFFER ) break;
00095 }
00096
00097
00098
00099 if( (word_1&0xF000F000F000F000LL)==0xF000F000F000F000LL &&
00100 (word_2&0xF000F000F000F000LL)==0xE000E000E000E000LL ){
00101 if( spTrailer ){
00102 coruptions |= MISSING_HEADER;
00103 break;
00104 }
00105 spHeader=false;
00106 spTrailer=true;
00107
00108 if( spWordCount!=spWordCountExpected+2 ){
00109 coruptions |= WORD_COUNT;
00110 break;
00111 }
00112
00113 const unsigned short *spWord = (unsigned short*) &dduWord[index-spWordCount-1];
00114 if( nRecords<12 ) {
00115 if( sp[nRecords++].unpack(spWord) ) coruptions |= NONSENSE;
00116 } else {
00117 coruptions |= CONFIGURATION;
00118 break;
00119 }
00120 }
00121
00122 index++;
00123 }
00124
00125 return coruptions;
00126 }