CMS 3D CMS Logo

CSCDCCEventData.cc
Go to the documentation of this file.
1 
11 #include <iostream>
12 #include <cstdio>
14 
15 #ifdef LOCAL_UNPACK
16 bool CSCDCCEventData::debug = false;
17 #else
18 #include <atomic>
19 std::atomic<bool> CSCDCCEventData::debug{false};
20 #endif
21 
22 CSCDCCEventData::CSCDCCEventData(int sourceId, int nDDUs, int bx, int l1a) : theDCCHeader(bx, l1a, sourceId) {
23  theDDUData.reserve(nDDUs);
24 }
25 
26 CSCDCCEventData::CSCDCCEventData(const uint16_t* buf, CSCDCCExaminer* examiner) { unpack_data(buf, examiner); }
27 
29 
30 void CSCDCCEventData::unpack_data(const uint16_t* buf, CSCDCCExaminer* examiner) {
31  /*
32  for (int i=0;i<20;i++) {
33  printf("%04x %04x %04x %04x\n",buf[i+3],buf[i+2],buf[i+1],buf[i]);
34  i+=3;
35  }
36 */
37 
38  theDDUData.clear();
39  if (debug)
40  LogTrace("CSCDCCEventData|CSCRawToDigi") << "CSCDCCEventData::unpack_data() is called";
41 
42  // decode DCC header (128 bits)
43  if (debug)
44  LogTrace("CSCDCCEventData|CSCRawToDigi") << "unpacking dcc header...";
46  //theDCCHeader = CSCDCCHeader(buf); // direct unpacking instead of bitfields
48 
49  //std::cout <<"Sandrik DCC Id = " << theDCCHeader.getCDFSourceId() << std::endl;
50 
52  while ((buf[7] == 0x8000) && (buf[6] == 0x0001) && (buf[5] == 0x8000)) {
53  CSCDDUEventData dduEventData(buf, examiner);
54  // CSCDDUEventData dduEventData(buf);
55 
56  if (debug)
57  LogTrace("CSCDCCEventData|CSCRawToDigi") << " checking ddu data integrity ";
58  if (dduEventData.check()) {
59  theDDUData.push_back(dduEventData);
60  buf += dduEventData.sizeInWords();
61  } else {
62  if (debug)
63  LogTrace("CSCDCCEventData|CSCRawToDigi") << "DDU Data Check failed! ";
64  break;
65  }
66  }
67 
68  if (debug) {
69  LogTrace("CSCDCCEventData|CSCRawToDigi") << "unpacking dcc trailer ";
70  LogTrace("CSCDCCEventData|CSCRawToDigi") << std::hex << buf[3] << " " << buf[2] << " " << buf[1] << " " << buf[0];
71  }
72 
73  //decode dcc trailer (128 bits)
74  if (debug)
75  LogTrace("CSCDCCEventData|CSCRawToDigi") << "decoding DCC trailer";
77  if (debug)
78  LogTrace("CSCDCCEventData|CSCRawToDigi") << "checking DDU Trailer" << theDCCTrailer.check();
79 
80  // buf += theDCCTrailer.sizeInWords(); /* =VB= Commented out to please static analyzer */
81 
82  //std::cout << " DCC Size: " << std::dec << theSizeInWords << std::endl;
83  //std::cout << "LastBuf: " << std::hex << inputBuf[theSizeInWords-4] << std::endl;
84 }
85 
86 bool CSCDCCEventData::check() const {
87  // the trailer counts in 64-bit words
88  if (debug) {
89  LogTrace("CSCDCCEventData|CSCRawToDigi") << "size in Words () = " << std::dec << sizeInWords();
90  }
91 
92  return theDCCHeader.check() && theDCCTrailer.check();
93 }
94 
96  CSCEventData& chamber, int dduID, int dduSlot, int dduInput, int dmbID, uint16_t format_version) {
97  // first, find this DDU
98  int dduIndex = -1;
99  int nDDUs = theDDUData.size();
100  for (int i = 0; dduIndex == -1 && i < nDDUs; ++i) {
101  if (theDDUData[i].header().source_id() == dduID)
102  dduIndex = i;
103  }
104 
106  unsigned ddu_fmt_version = 0x6; // 2005 Format
107  if (format_version == 2013)
108  ddu_fmt_version = 0x7;
109 
110  if (dduIndex == -1) {
111  // make a new one
112  CSCDDUHeader newDDUHeader(
113  dccHeader().getCDFBunchCounter(), dccHeader().getCDFEventNumber(), dduID, ddu_fmt_version);
114  theDDUData.push_back(CSCDDUEventData(newDDUHeader));
115  dduIndex = nDDUs;
116  dccHeader().setDAV(dduSlot);
117  }
118  theDDUData[dduIndex].add(chamber, dmbID, dduInput, format_version);
119 }
120 
121 boost::dynamic_bitset<> CSCDCCEventData::pack() {
122  boost::dynamic_bitset<> result(theDCCHeader.sizeInWords() * 16);
124  //std::cout <<"SANDRIK DCC size of header in words"<< theDCCHeader.sizeInWords()*16 <<std::endl;
125  //std::cout <<"SANDRIK DCC size of header in bits"<< result.size()<<std::endl;
126  //for(size_t i = 0; i < result.size(); ++i) {
127  // std::cout<<result[i];
128  // if (((i+1)%32)==0) std::cout<<std::endl;
129  //}
130 
131  for (size_t i = 0; i < theDDUData.size(); ++i) {
133  //std::cout <<"SANDRIK here is ddu data check ";
134  //theDDUData[i].header().check();
135  //std::cout <<std::endl;
136  //bitset_utilities::printWords(result);
137  }
138 
139  //std::cout <<"SANDRIK packed dcc size is "<<result.size()<<std::endl;
140  //for(size_t i = 0; i < result.size(); ++i) {
141  // std::cout<<result[i];
142  // if (((i+1)%32)==0) std::cout<<std::endl;
143  //}
144 
145  boost::dynamic_bitset<> dccTrailer =
148  // bitset_utilities::printWords(result);
149  return result;
150 }
mps_fire.i
i
Definition: mps_fire.py:428
CSCDCCEventData::theDCCHeader
CSCDCCHeader theDCCHeader
Definition: CSCDCCEventData.h:54
CSCEventData
Definition: CSCEventData.h:29
MessageLogger.h
CSCDCCEventData::debug
static std::atomic< bool > debug
Definition: CSCDCCEventData.h:49
CSCDCCTrailer::sizeInWords
static unsigned sizeInWords()
Definition: CSCDCCTrailer.h:46
CSCDDUHeader
Definition: CSCDDUHeader.h:11
CSCDCCEventData::check
bool check() const
for making events. Sets the bxnum and lvl1num inside the chamber event
Definition: CSCDCCEventData.cc:86
CSCDCCEventData::~CSCDCCEventData
~CSCDCCEventData()
Definition: CSCDCCEventData.cc:28
l1GtPatternGenerator_cfi.bx
bx
Definition: l1GtPatternGenerator_cfi.py:18
CSCDCCTrailer::setFromBuffer
void setFromBuffer(uint16_t const *buf)
Definition: CSCDCCTrailer.h:24
CSCDCCHeader::sizeInWords
static unsigned sizeInWords()
Definition: CSCDCCHeader.h:29
bitset_utilities::append
boost::dynamic_bitset append(const boost::dynamic_bitset<> &bs1, const boost::dynamic_bitset<> &bs2)
this method takes two bitsets bs1 and bs2 and returns result of bs2 appended to the end of bs1
Definition: bitset_append.cc:10
CSCDCCHeader::setFromBuffer
void setFromBuffer(uint16_t const *buf)
Definition: CSCDCCHeader.h:19
CSCDCCHeader::check
bool check() const
Definition: CSCDCCHeader.h:27
CSCDCCEventData::addChamber
void addChamber(CSCEventData &chamber, int dduID, int dduSlot, int dduInput, int dmbID, uint16_t format_version=2005)
Definition: CSCDCCEventData.cc:95
CSCDCCHeader::data
unsigned short * data()
Definition: CSCDCCHeader.h:28
CSCDCCEventData::dccHeader
CSCDCCHeader dccHeader() const
Definition: CSCDCCEventData.h:28
CSCDCCEventData.h
CSCDCCEventData::pack
boost::dynamic_bitset pack()
packs data into bits
Definition: CSCDCCEventData.cc:121
CSCDCCTrailer::data
unsigned short * data()
Definition: CSCDCCTrailer.h:49
CSCDCCEventData::theDCCTrailer
CSCDCCTrailer theDCCTrailer
Definition: CSCDCCEventData.h:57
CSCDCCExaminer
Definition: CSCDCCExaminer.h:15
CSCDCCEventData::CSCDCCEventData
CSCDCCEventData(int sourceId, int nDDUs, int bx, int l1a)
Definition: CSCDCCEventData.cc:22
CSCDCCTrailer::check
bool check() const
Definition: CSCDCCTrailer.h:48
visDQMUpload.buf
buf
Definition: visDQMUpload.py:154
CSCDCCEventData::sizeInWords
int sizeInWords() const
Definition: CSCDCCEventData.h:38
objects.autophobj.sourceId
sourceId
Definition: autophobj.py:239
CSCDCCHeader::setDAV
void setDAV(int dduSlot)
Definition: CSCDCCHeader.cc:28
CSCDDUEventData
Definition: CSCDDUEventData.h:19
bitset_utilities::ushortToBitset
boost::dynamic_bitset ushortToBitset(const unsigned int numberOfBits, unsigned short *buf)
this method takes numberOfBits bits from unsigned short * array and returns them in the bitset obj.
Definition: bitset_append.cc:23
CSCDCCEventData::theDDUData
std::vector< CSCDDUEventData > theDDUData
Definition: CSCDCCEventData.h:56
CSCDCCEventData::dccTrailer
CSCDCCTrailer dccTrailer() const
Definition: CSCDCCEventData.h:29
bitset_append.h
relativeConstraints.chamber
chamber
Definition: relativeConstraints.py:53
CSCDDUEventData::check
bool check() const
Definition: CSCDDUEventData.cc:289
RecoTauValidation_cfi.header
header
Definition: RecoTauValidation_cfi.py:292
CSCDDUEventData::sizeInWords
int sizeInWords() const
Definition: CSCDDUEventData.h:54
mps_fire.result
result
Definition: mps_fire.py:311
LogTrace
#define LogTrace(id)
Definition: MessageLogger.h:234
CSCDCCEventData::unpack_data
void unpack_data(const uint16_t *buf, CSCDCCExaminer *examiner=nullptr)
Definition: CSCDCCEventData.cc:30
TauDecayModes.dec
dec
Definition: TauDecayModes.py:143