File indexing completed on 2023-10-25 09:45:14
0001 #include "EventFilter/CSCTFRawToDigi/src/CSCSPEvent.h"
0002 #include <map>
0003 #include <list>
0004 #include <iostream>
0005
0006 bool CSCSPEvent::unpack(const unsigned short *&buf) throw() {
0007 bool unpackError = false;
0008
0009 if ((buf[0] & 0xF000) != 0x9000 || (buf[1] & 0xF000) != 0x9000 || (buf[2] & 0xF000) != 0x9000 ||
0010 (buf[3] & 0xF000) != 0x9000 || (buf[4] & 0xF000) != 0xA000 || (buf[5] & 0xF000) != 0xA000 ||
0011 (buf[6] & 0xF000) != 0xA000 || (buf[7] & 0xF000) != 0xA000)
0012 return true;
0013 else
0014 unpackError |= header_.unpack(buf);
0015
0016 if (!header_.empty()) {
0017
0018 if (header_.format_version())
0019 unpackError |= counters_.unpack(buf);
0020
0021 if (header_.format_version() < 3 || !header_.suppression()) {
0022 for (unsigned short tbin = 0; tbin < header_.nTBINs(); tbin++)
0023 unpackError |= record_[tbin].unpack(buf, header_.active(), header_.suppression(), tbin);
0024 } else {
0025
0026 for (unsigned short tbin = 0, actual_tbin = (buf[7] >> 8) & 0x7; tbin < header_.nTBINs(); tbin++) {
0027 bzero(&(record_[tbin]), sizeof(record_[tbin]));
0028
0029 if ((buf[0] & 0xF000) == 0xF000 && (buf[1] & 0xF000) == 0xF000 && (buf[2] & 0xF000) == 0xF000 &&
0030 (buf[3] & 0xF000) == 0xF000 && (buf[4] & 0xF000) == 0xE000 && (buf[5] & 0xF000) == 0xE000 &&
0031 (buf[6] & 0xF000) == 0xE000 && (buf[7] & 0xF000) == 0xE000)
0032 break;
0033
0034 if (tbin + 1 != actual_tbin)
0035 continue;
0036
0037 unpackError |= record_[tbin].unpack(buf, header_.active(), header_.suppression(), tbin);
0038 actual_tbin = (buf[7] >> 8) & 0x7;
0039 }
0040 }
0041
0042
0043 for (unsigned short tbin = 0; tbin < header_.nTBINs(); tbin++) {
0044 for (unsigned short trk = 0; trk < 3; trk++) {
0045 CSCSP_SPblock &track = record_[tbin].sp[trk];
0046 if (track.ME1_id() == 0 && track.ME2_id() == 0 && track.ME3_id() == 0 && track.ME4_id() == 0 &&
0047 track.MB_id() == 0)
0048 continue;
0049
0050 int second_earliest_lct_delay =
0051 -1;
0052 if (track.mode() != 15 && track.mode() != 11) {
0053
0054 std::map<int, std::list<int> > timeline;
0055 if (track.ME1_id())
0056 timeline[track.ME1_tbin()].push_back(1);
0057 if (track.ME2_id())
0058 timeline[track.ME2_tbin()].push_back(2);
0059 if (track.ME3_id())
0060 timeline[track.ME3_tbin()].push_back(3);
0061 if (track.ME4_id())
0062 timeline[track.ME4_tbin()].push_back(4);
0063 if (track.MB_id())
0064 timeline[track.MB_tbin()].push_back(5);
0065 int earliest_lct_delay = -1;
0066
0067 for (int delay = 7; delay >= 0 && second_earliest_lct_delay == -1; delay--) {
0068 std::list<int>::const_iterator iter = timeline[delay].begin();
0069 while (iter != timeline[delay].end() && second_earliest_lct_delay == -1) {
0070 if (earliest_lct_delay == -1)
0071 earliest_lct_delay = delay;
0072 else if (second_earliest_lct_delay == -1)
0073 second_earliest_lct_delay = delay;
0074 iter++;
0075 }
0076 }
0077 } else
0078 second_earliest_lct_delay = 0;
0079
0080
0081
0082 if (track.ME1_id()) {
0083 unsigned int mpc = (track.ME1_id() > 3 ? 1 : 0);
0084 int ME1_tbin = tbin + second_earliest_lct_delay - track.ME1_tbin();
0085
0086 if (ME1_tbin >= 0 && ME1_tbin < 7) {
0087 std::vector<CSCSP_MEblock> lcts = record_[ME1_tbin].LCTs(mpc);
0088 for (std::vector<CSCSP_MEblock>::const_iterator lct = lcts.begin(); lct != lcts.end(); lct++)
0089
0090
0091 if (((lct->spInput() - 1) % 3 + 1) == (mpc ? track.ME1_id() - 3 : track.ME1_id())) {
0092 track.lct_[0] = *lct;
0093 track.lctFilled[0] = true;
0094 }
0095 }
0096 }
0097 if (track.ME2_id()) {
0098 int ME2_tbin = tbin + second_earliest_lct_delay - track.ME2_tbin();
0099
0100 if (ME2_tbin >= 0 && ME2_tbin < 7) {
0101 std::vector<CSCSP_MEblock> lcts = record_[ME2_tbin].LCTs(2);
0102 for (std::vector<CSCSP_MEblock>::const_iterator lct = lcts.begin(); lct != lcts.end(); lct++)
0103
0104
0105 if (((lct->spInput() - 1) % 3 + 1) == track.ME2_id()) {
0106 track.lct_[1] = *lct;
0107 track.lctFilled[1] = true;
0108 }
0109 }
0110 }
0111 if (track.ME3_id()) {
0112 int ME3_tbin = tbin + second_earliest_lct_delay - track.ME3_tbin();
0113
0114 if (ME3_tbin >= 0 && ME3_tbin < 7) {
0115 std::vector<CSCSP_MEblock> lcts = record_[ME3_tbin].LCTs(3);
0116 for (std::vector<CSCSP_MEblock>::const_iterator lct = lcts.begin(); lct != lcts.end(); lct++)
0117
0118
0119 if (((lct->spInput() - 1) % 3 + 1) == track.ME3_id()) {
0120 track.lct_[2] = *lct;
0121 track.lctFilled[2] = true;
0122 }
0123 }
0124 }
0125 if (track.ME4_id()) {
0126 int ME4_tbin = tbin + second_earliest_lct_delay - track.ME4_tbin();
0127
0128 if (ME4_tbin >= 0 && ME4_tbin < 7) {
0129 std::vector<CSCSP_MEblock> lcts = record_[ME4_tbin].LCTs(4);
0130 for (std::vector<CSCSP_MEblock>::const_iterator lct = lcts.begin(); lct != lcts.end(); lct++)
0131
0132
0133 if (((lct->spInput() - 1) % 3 + 1) == track.ME4_id()) {
0134 track.lct_[3] = *lct;
0135 track.lctFilled[3] = true;
0136 }
0137 }
0138 }
0139 if (track.MB_id()) {
0140 int MB_tbin = tbin + second_earliest_lct_delay - track.MB_tbin();
0141
0142 if (MB_tbin >= 0 && MB_tbin < 7) {
0143 std::vector<CSCSP_MBblock> stubs = record_[MB_tbin].mbStubs();
0144 for (std::vector<CSCSP_MBblock>::const_iterator stub = stubs.begin(); stub != stubs.end(); stub++)
0145 if ((stub->id() == 1 && track.MB_id() % 2 == 1) || (stub->id() == 2 && track.MB_id() % 2 == 0)) {
0146 track.dt_ = *stub;
0147 track.dtFilled = true;
0148 }
0149 }
0150 }
0151 }
0152 }
0153 }
0154 unpackError |= trailer_.unpack(buf);
0155
0156 return unpackError;
0157 }