Go to the documentation of this file.00001
00009 #include "EventFilter/CSCRawToDigi/interface/CSCDCCEventData.h"
00010 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00011 #include <iostream>
00012 #include <cstdio>
00013 #include "EventFilter/CSCRawToDigi/src/bitset_append.h"
00014
00015 bool CSCDCCEventData::debug = false;
00016
00017 CSCDCCEventData::CSCDCCEventData(int sourceId, int nDDUs, int bx, int l1a)
00018 : theDCCHeader(bx, l1a, sourceId)
00019 {
00020 theDDUData.reserve(nDDUs);
00021 }
00022
00023 CSCDCCEventData::CSCDCCEventData(unsigned short *buf, CSCDCCExaminer* examiner)
00024 {
00025 unpack_data(buf, examiner);
00026 }
00027
00028 CSCDCCEventData::~CSCDCCEventData()
00029 {
00030 }
00031
00032
00033 void CSCDCCEventData::unpack_data(unsigned short *buf, CSCDCCExaminer* examiner)
00034 {
00035
00036
00037
00038
00039
00040
00041
00042
00043 theDDUData.clear();
00044 if (debug)
00045 LogTrace ("CSCDCCEventData|CSCRawToDigi") << "CSCDCCEventData::unpack_data() is called";
00046
00047
00048 if (debug)
00049 LogTrace ("CSCDCCEventData|CSCRawToDigi") << "unpacking dcc header...";
00050 memcpy(&theDCCHeader, buf, theDCCHeader.sizeInWords()*2);
00051
00052 buf += theDCCHeader.sizeInWords();
00053
00054
00055
00057 while ( (buf[7]==0x8000)&&(buf[6]==0x0001)&&(buf[5]==0x8000))
00058 {
00059 CSCDDUEventData dduEventData(buf, examiner);
00060
00061
00062 if (debug) LogTrace ("CSCDCCEventData|CSCRawToDigi") << " checking ddu data integrity ";
00063 if (dduEventData.check())
00064 {
00065 theDDUData.push_back(dduEventData);
00066 buf += dduEventData.sizeInWords();
00067 }
00068 else
00069 {
00070 if (debug) LogTrace("CSCDCCEventData|CSCRawToDigi") <<"DDU Data Check failed! ";
00071 break;
00072 }
00073
00074 }
00075
00076 if (debug)
00077 {
00078 LogTrace ("CSCDCCEventData|CSCRawToDigi") << "unpacking dcc trailer ";
00079 LogTrace ("CSCDCCEventData|CSCRawToDigi") << std::hex << buf[3] <<" "
00080 << buf[2]<<" " << buf[1]<<" " << buf[0];
00081 }
00082
00083
00084 if (debug) LogTrace ("CSCDCCEventData|CSCRawToDigi") <<"decoding DCC trailer";
00085 memcpy(&theDCCTrailer, buf, theDCCTrailer.sizeInWords()*2);
00086 if (debug) LogTrace("CSCDCCEventData|CSCRawToDigi") << "checking DDU Trailer" << theDCCTrailer.check();
00087 buf += theDCCTrailer.sizeInWords();
00088
00089
00090
00091 }
00092
00093
00094 bool CSCDCCEventData::check() const
00095 {
00096
00097 if (debug)
00098 {
00099 LogTrace ("CSCDCCEventData|CSCRawToDigi") << "size in Words () = " << std::dec << sizeInWords();
00100 }
00101
00102 return theDCCHeader.check() && theDCCTrailer.check();
00103 }
00104
00105
00106 void CSCDCCEventData::addChamber(CSCEventData & chamber, int dduID, int dduSlot, int dduInput, int dmbID)
00107 {
00108
00109 std::vector<CSCDDUEventData>::iterator dduItr;
00110 int dduIndex = -1;
00111 int nDDUs = theDDUData.size();
00112 for(int i = 0; dduIndex == -1 && i < nDDUs; ++i)
00113 {
00114 if(theDDUData[i].header().source_id() == dduID) dduIndex = i;
00115 }
00116 if(dduIndex == -1)
00117 {
00118
00119 CSCDDUHeader newDDUHeader(dccHeader().getCDFBunchCounter(),
00120 dccHeader().getCDFEventNumber(), dduID);
00121 theDDUData.push_back(CSCDDUEventData(newDDUHeader));
00122 dduIndex = nDDUs;
00123 dccHeader().setDAV(dduSlot);
00124 }
00125 theDDUData[dduIndex].add( chamber, dmbID, dduInput );
00126 }
00127
00128
00129 boost::dynamic_bitset<> CSCDCCEventData::pack()
00130 {
00131 boost::dynamic_bitset<> result( theDCCHeader.sizeInWords()*16);
00132 result = bitset_utilities::ushortToBitset(theDCCHeader.sizeInWords()*16, theDCCHeader.data());
00133
00134
00135
00136
00137
00138
00139
00140 for(size_t i = 0; i < theDDUData.size(); ++i)
00141 {
00142 result = bitset_utilities::append(result,theDDUData[i].pack());
00143
00144
00145
00146
00147 }
00148
00149
00150
00151
00152
00153
00154
00155 boost::dynamic_bitset<> dccTrailer = bitset_utilities::ushortToBitset(theDCCTrailer.sizeInWords()*16,
00156 theDCCTrailer.data());
00157 result = bitset_utilities::append(result,dccTrailer);
00158
00159 return result;
00160 }
00161