00001 #include "EventFilter/CSCRawToDigi/interface/CSCTMBHeader.h"
00002 #include "EventFilter/CSCRawToDigi/interface/CSCDMBHeader.h"
00003 #include "EventFilter/CSCRawToDigi/src/cscPackerCompare.h"
00004 #include "EventFilter/CSCRawToDigi/interface/CSCTMBHeader2006.h"
00005 #include "EventFilter/CSCRawToDigi/interface/CSCTMBHeader2007.h"
00006 #include "EventFilter/CSCRawToDigi/interface/CSCTMBHeader2007_rev0x50c3.h"
00007 #include "DataFormats/CSCDigi/interface/CSCCLCTDigi.h"
00008 #include "DataFormats/CSCDigi/interface/CSCCorrelatedLCTDigi.h"
00009 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00010 #include <math.h>
00011 #include <string.h>
00012
00013 bool CSCTMBHeader::debug = false;
00014
00015 CSCTMBHeader::CSCTMBHeader(int firmwareVersion, int firmwareRevision):
00016 theHeaderFormat(),
00017 theFirmwareVersion(firmwareVersion)
00018 {
00019 if(firmwareVersion == 2006)
00020 {
00021 theHeaderFormat = boost::shared_ptr<CSCVTMBHeaderFormat>(new CSCTMBHeader2006());
00022 }
00023 else if(firmwareVersion == 2007)
00024 {
00025 if(firmwareRevision >= 0x50c3)
00026 {
00027 theHeaderFormat = boost::shared_ptr<CSCVTMBHeaderFormat>(new CSCTMBHeader2007_rev0x50c3());
00028 }
00029 else
00030 {
00031 theHeaderFormat = boost::shared_ptr<CSCVTMBHeaderFormat>(new CSCTMBHeader2007());
00032 }
00033 }
00034 else
00035 {
00036 edm::LogError("CSCTMBHeader|CSCRawToDigi") <<"failed to determine TMB firmware version!!";
00037 }
00038 }
00039
00040
00041
00042
00043
00044 CSCTMBHeader::CSCTMBHeader(const unsigned short * buf)
00045 : theHeaderFormat()
00046 {
00048 if (buf[0]==0xDB0C) {
00049 theFirmwareVersion=2007;
00050 theHeaderFormat = boost::shared_ptr<CSCVTMBHeaderFormat>(new CSCTMBHeader2007(buf));
00051 if(theHeaderFormat->firmwareRevision() >= 0x50c3)
00052 {
00053 theHeaderFormat = boost::shared_ptr<CSCVTMBHeaderFormat>(new CSCTMBHeader2007_rev0x50c3(buf));
00054 }
00055 }
00056 else if (buf[0]==0x6B0C) {
00057 theFirmwareVersion=2006;
00058 theHeaderFormat = boost::shared_ptr<CSCVTMBHeaderFormat>(new CSCTMBHeader2006(buf));
00059 }
00060 else {
00061 edm::LogError("CSCTMBHeader|CSCRawToDigi") <<"failed to determine TMB firmware version!!";
00062 }
00063 }
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099 void CSCTMBHeader::add(const std::vector<CSCCLCTDigi> & digis)
00100 {
00101
00102 if(digis.size() > 0) addCLCT0(digis[0]);
00103 if(digis.size() > 1) addCLCT1(digis[1]);
00104 }
00105
00106 void CSCTMBHeader::add(const std::vector<CSCCorrelatedLCTDigi> & digis)
00107 {
00108
00109 if(digis.size() > 0) addCorrelatedLCT0(digis[0]);
00110 if(digis.size() > 1) addCorrelatedLCT1(digis[1]);
00111 }
00112
00113
00114 CSCTMBHeader2007 CSCTMBHeader::tmbHeader2007() const {
00115 CSCTMBHeader2007 * result = dynamic_cast<CSCTMBHeader2007 *>(theHeaderFormat.get());
00116 if(result == 0)
00117 {
00118 throw cms::Exception("Could not get 2007 TMB header format");
00119 }
00120 return *result;
00121 }
00122
00123
00124 CSCTMBHeader2006 CSCTMBHeader::tmbHeader2006() const {
00125 CSCTMBHeader2006 * result = dynamic_cast<CSCTMBHeader2006 *>(theHeaderFormat.get());
00126 if(result == 0)
00127 {
00128 throw cms::Exception("Could not get 2006 TMB header format");
00129 }
00130 return *result;
00131 }
00132
00133
00134 void CSCTMBHeader::selfTest()
00135 {
00136 static bool debug = false;
00137
00138
00139 for(int station = 1; station <= 4; ++station) {
00140 for(int iendcap = 1; iendcap <= 2; ++iendcap) {
00141 CSCDetId detId(iendcap, station, 1, 1, 0);
00142
00143
00144
00145
00146
00147
00148 CSCCLCTDigi clct0(1, 1, 4, 1, 0, 30, 4, 2, 1);
00149 CSCCLCTDigi clct1(1, 1, 2, 1, 1, 31, 1, 2, 2);
00150
00151
00152
00153 CSCCorrelatedLCTDigi lct0(1, 1, 2, 10, 98, 5, 0, 1, 0, 0, 0, 0);
00154 CSCCorrelatedLCTDigi lct1(2, 1, 2, 20, 15, 9, 1, 0, 0, 0, 0, 0);
00155
00156 CSCTMBHeader tmbHeader(2007, 0x50c3);
00157 tmbHeader.addCLCT0(clct0);
00158 tmbHeader.addCLCT1(clct1);
00159 tmbHeader.addCorrelatedLCT0(lct0);
00160 tmbHeader.addCorrelatedLCT1(lct1);
00161 std::vector<CSCCLCTDigi> clcts = tmbHeader.CLCTDigis(detId.rawId());
00162
00163 assert(cscPackerCompare(clcts[0],clct0));
00164 assert(cscPackerCompare(clcts[1],clct1));
00165 if (debug) {
00166 std::cout << "Match for: " << clct0 << "\n";
00167 std::cout << " " << clct1 << "\n \n";
00168 }
00169
00170 std::vector<CSCCorrelatedLCTDigi> lcts = tmbHeader.CorrelatedLCTDigis(detId.rawId());
00171 assert(cscPackerCompare(lcts[0], lct0));
00172 assert(cscPackerCompare(lcts[1], lct1));
00173 if (debug) {
00174 std::cout << "Match for: " << lct0 << "\n";
00175 std::cout << " " << lct1 << "\n";
00176 }
00177
00178
00179 unsigned short int * data = tmbHeader.data();
00180 CSCTMBHeader newHeader(data);
00181 clcts = newHeader.CLCTDigis(detId.rawId());
00182 assert(cscPackerCompare(clcts[0],clct0));
00183 assert(cscPackerCompare(clcts[1],clct1));
00184 lcts = newHeader.CorrelatedLCTDigis(detId.rawId());
00185 assert(cscPackerCompare(lcts[0], lct0));
00186 assert(cscPackerCompare(lcts[1], lct1));
00187
00188
00189 }
00190 }
00191 }
00192
00193
00194 std::ostream & operator<<(std::ostream & os, const CSCTMBHeader & hdr) {
00195 hdr.theHeaderFormat->print(os);
00196 return os;
00197 }