Go to the documentation of this file.00001 #include "EventFilter/CSCTFRawToDigi/src/CSCSPEvent.h"
00002 #include <map>
00003 #include <list>
00004 #include <iostream>
00005
00006 bool CSCSPEvent::unpack(const unsigned short *&buf) throw() {
00007 bool unpackError = false;
00008
00009 if( (buf[0]&0xF000) != 0x9000 || (buf[1]&0xF000) != 0x9000 || (buf[2]&0xF000) != 0x9000 || (buf[3]&0xF000) != 0x9000 ||
00010 (buf[4]&0xF000) != 0xA000 || (buf[5]&0xF000) != 0xA000 || (buf[6]&0xF000) != 0xA000 || (buf[7]&0xF000) != 0xA000 )
00011 return true;
00012 else
00013 unpackError |= header_.unpack(buf);
00014
00015 if( !header_.empty() ){
00016
00017 if( header_.format_version() )
00018 unpackError |= counters_.unpack(buf);
00019
00020 if( header_.format_version()<3 || !header_.suppression() ){
00021 for(unsigned short tbin=0; tbin<header_.nTBINs(); tbin++)
00022 unpackError |= record_[tbin].unpack(buf,header_.active(),header_.suppression(),tbin);
00023 } else {
00024
00025 for(unsigned short tbin=0, actual_tbin = (buf[7] >> 8) & 0x7; tbin<header_.nTBINs(); tbin++){
00026 bzero(&(record_[tbin]),sizeof(record_[tbin]));
00027
00028 if( (buf[0]&0xF000)==0xF000 && (buf[1]&0xF000)==0xF000 && (buf[2]&0xF000)==0xF000 && (buf[3]&0xF000)==0xF000 &&
00029 (buf[4]&0xF000)==0xE000 && (buf[5]&0xF000)==0xE000 && (buf[6]&0xF000)==0xE000 && (buf[7]&0xF000)==0xE000 ) break;
00030
00031 if( tbin+1 != actual_tbin ) continue;
00032
00033 unpackError |= record_[tbin].unpack(buf,header_.active(),header_.suppression(),tbin);
00034 actual_tbin = (buf[7] >> 8) & 0x7;
00035 }
00036 }
00037
00038
00039 for(unsigned short tbin=0; tbin<header_.nTBINs(); tbin++){
00040 for(unsigned short trk=0; trk<3; trk++){
00041 CSCSP_SPblock &track = record_[tbin].sp[trk];
00042 if( track.ME1_id()==0 && track.ME2_id()==0 && track.ME3_id()==0 && track.ME4_id()==0 && track.MB_id()==0 ) continue;
00043
00044 int second_earliest_lct_delay = -1;
00045 if( track.mode() != 15 && track.mode() != 11 ){
00046
00047 std::map< int, std::list<int> > timeline;
00048 if( track.ME1_id() ) timeline[track.ME1_tbin()].push_back(1);
00049 if( track.ME2_id() ) timeline[track.ME2_tbin()].push_back(2);
00050 if( track.ME3_id() ) timeline[track.ME3_tbin()].push_back(3);
00051 if( track.ME4_id() ) timeline[track.ME4_tbin()].push_back(4);
00052 if( track.MB_id() ) timeline[track.MB_tbin() ].push_back(5);
00053 int earliest_lct_delay = -1;
00054
00055 for(int delay=7; delay>=0 && second_earliest_lct_delay==-1; delay--){
00056 std::list<int>::const_iterator iter = timeline[delay].begin();
00057 while( iter != timeline[delay].end() && second_earliest_lct_delay==-1 ){
00058 if( earliest_lct_delay==-1 ) earliest_lct_delay=delay;
00059 else if( second_earliest_lct_delay==-1 ) second_earliest_lct_delay=delay;
00060 iter++;
00061 }
00062 }
00063 } else second_earliest_lct_delay = 0;
00064
00065
00066
00067 if( track.ME1_id() ){
00068 unsigned int mpc = ( track.ME1_id()>3 ? 1 : 0 );
00069 int ME1_tbin = tbin + second_earliest_lct_delay - track.ME1_tbin();
00071 if( ME1_tbin>=0 && ME1_tbin<7 ) {
00072 std::vector<CSCSP_MEblock> lcts = record_[ME1_tbin].LCTs(mpc);
00073 for(std::vector<CSCSP_MEblock>::const_iterator lct=lcts.begin(); lct!=lcts.end(); lct++)
00074
00075
00076 if( ((lct->spInput()-1)%3+1)==(mpc?track.ME1_id()-3:track.ME1_id()) ){
00077 track.lct_[0] = *lct;
00078 track.lctFilled[0] = true;
00079 }
00080 }
00081 }
00082 if( track.ME2_id() ){
00083 int ME2_tbin = tbin + second_earliest_lct_delay - track.ME2_tbin();
00085 if( ME2_tbin>=0 && ME2_tbin<7 ) {
00086 std::vector<CSCSP_MEblock> lcts = record_[ME2_tbin].LCTs(2);
00087 for(std::vector<CSCSP_MEblock>::const_iterator lct=lcts.begin(); lct!=lcts.end(); lct++)
00088
00089
00090 if( ((lct->spInput()-1)%3+1)==track.ME2_id() ){
00091 track.lct_[1] = *lct;
00092 track.lctFilled[1] = true;
00093 }
00094 }
00095 }
00096 if( track.ME3_id() ){
00097 int ME3_tbin = tbin + second_earliest_lct_delay - track.ME3_tbin();
00099 if( ME3_tbin>=0 && ME3_tbin<7 ) {
00100 std::vector<CSCSP_MEblock> lcts = record_[ME3_tbin].LCTs(3);
00101 for(std::vector<CSCSP_MEblock>::const_iterator lct=lcts.begin(); lct!=lcts.end(); lct++)
00102
00103
00104 if( ((lct->spInput()-1)%3+1)==track.ME3_id() ){
00105 track.lct_[2] = *lct;
00106 track.lctFilled[2] = true;
00107 }
00108 }
00109 }
00110 if( track.ME4_id() ){
00111 int ME4_tbin = tbin + second_earliest_lct_delay - track.ME4_tbin();
00113 if( ME4_tbin>=0 && ME4_tbin<7 ) {
00114 std::vector<CSCSP_MEblock> lcts = record_[ME4_tbin].LCTs(4);
00115 for(std::vector<CSCSP_MEblock>::const_iterator lct=lcts.begin(); lct!=lcts.end(); lct++)
00116
00117
00118 if( ((lct->spInput()-1)%3+1)==track.ME4_id() ){
00119 track.lct_[3] = *lct;
00120 track.lctFilled[3] = true;
00121 }
00122 }
00123 }
00124 if( track.MB_id() ){
00125 int MB_tbin = tbin + second_earliest_lct_delay - track.MB_tbin();
00127 if( MB_tbin>=0 && MB_tbin<7 ) {
00128 std::vector<CSCSP_MBblock> stubs = record_[MB_tbin].mbStubs();
00129 for(std::vector<CSCSP_MBblock>::const_iterator stub=stubs.begin(); stub!=stubs.end(); stub++)
00130 if( (stub->id()==1 && track.MB_id()%2==1) || (stub->id()==2 && track.MB_id()%2==0) ){
00131 track.dt_ = *stub;
00132 track.dtFilled = true;
00133 }
00134 }
00135 }
00136 }
00137 }
00138 }
00139 unpackError |= trailer_.unpack(buf);
00140
00141 return unpackError;
00142 }
00143