CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
HcalDTCHeader.cc
Go to the documentation of this file.
1 /*
2  * \author J. Mans -- UMD
3  */
6 #include <string.h>
7 #include <stdint.h>
8 
9 const int HcalDTCHeader::SLOT_COUNT = 12;
10 const int HcalDTCHeader::MINIMUM_SLOT = 1;
11 const int HcalDTCHeader::MAXIMUM_SLOT = 12;
12 
14 
15 unsigned int HcalDTCHeader::getTotalLengthBytes() const {
16  unsigned int totalSize=sizeof(HcalDTCHeader);
17  for (int i=0; i<SLOT_COUNT; i++)
18  totalSize+=(slotInfo[i]&0xFFF)*sizeof(uint16_t);
19  return totalSize;
20 }
21 
22 int HcalDTCHeader::getSlotData(int nslot, HcalHTRData& decodeTool, int validSize) const {
23  const unsigned short* base=((unsigned short*)this)+sizeof(HcalDTCHeader)/sizeof(unsigned short);
24  int offset=0,i,len=0;
25  for (i=1; i<=nslot; i++) {
26  offset+=len;
27  len=(slotInfo[i-1]&0xFFF);
28  }
29  if ((offset+len+sizeof(HcalDTCHeader)/sizeof(unsigned short))<(validSize/sizeof(unsigned short))) {
30  decodeTool.adoptData(base+offset,len);
31  return 0;
32  } else { return -1; }
33 }
34 
37  commondataformat1=0x50000000u;
40  dcch0=0x1; // format version 1
41  dcch1=0;
42  for (int i=0; i<SLOT_COUNT; i++)
43  slotInfo[i]=0;
44 }
45 
46 void HcalDTCHeader::setHeader(int sourceid, int bcn, int l1aN, int orbN) {
47  commondataformat0=0x8|((sourceid&0xFFF)<<8)|((bcn&0xFFF)<<20);
48  commondataformat1=0x50000000u|(l1aN&0xFFFFFF);
49 }
50 
51 void HcalDTCHeader::copySlotData(unsigned int slot_id, const HcalHTRData& data, bool valid) {
52  if (slot_id==0 || slot_id>(unsigned int)SLOT_COUNT) return;
53  // construct the slot info
54  slotInfo[slot_id-1]=(data.getRawLength())|0xc000;
55  if (valid) slotInfo[slot_id-1]|=0x2000;
56  // status info...
57  // if (valid) dcch0|=(1<<(slot_id+14));
58  // copy
59  unsigned int lenSoFar=0;
60  for (unsigned int i=1; i<slot_id; i++) lenSoFar+=getSlotDataLength(i);
61  unsigned short* startingPoint=((unsigned short*)this)+sizeof(HcalDTCHeader)/sizeof(unsigned short)+lenSoFar;
62  memcpy(startingPoint,data.getRawData(),sizeof(unsigned short)*data.getRawLength());
63  // update the trailer...
64  lenSoFar+=data.getRawLength();
65  uint32_t* trailer=((uint32_t*)this)+sizeof(HcalDTCHeader)/sizeof(uint32_t)+lenSoFar/2;
66  int len64=sizeof(HcalDTCHeader)/8+lenSoFar/4+1;
67  trailer[1]=0;
68  trailer[0]=0xA0000000u|len64;
69 }
70 
71 std::ostream& operator<<(std::ostream& s, const HcalDTCHeader& head) {
72 
73  for (int i=0; i<HcalDTCHeader::SLOT_COUNT; i++) {
74  s << "Slot " << i << " : " << head.getSlotDataLength(i) << " bytes, ";
75  if (head.getSlotEnabled(i)) s << "E";
76  if (head.getSlotPresent(i)) s << "P";
77  if (head.getSlotValid(i)) s << "V";
78  if (head.getSlotCRCError(i)) s << "C";
79  // s << ". Error codes: " << std::hex << int(head.getSlotErrorBits(i)) << "," << int(head.getLRBErrorBits(i)) << std::dec;
80  s << std::endl;
81  }
82  return s;
83 }
void copySlotData(unsigned int slot_id, const HcalHTRData &data, bool valid=true)
Add the given HcalHTRData as the given slot&#39;s data. This should be done in increasing slot order! ...
tuple base
Main Program
Definition: newFWLiteAna.py:92
int i
Definition: DBlmapReader.cc:9
uint16_t slotInfo[12]
static const int MINIMUM_SLOT
Definition: HcalDTCHeader.h:21
std::ostream & operator<<(std::ostream &out, const ALILine &li)
Definition: ALILine.cc:187
uint32_t commondataformat0
uint32_t commondataformat2
const int getRawLength() const
Get the length of the raw data.
Definition: HcalHTRData.h:39
uint32_t dcch1
bool getSlotValid(unsigned int nslot) const
Read the &quot;VALID&quot; bit for this slot; TTC EvN matched HTR EvN.
Definition: HcalDTCHeader.h:82
bool getSlotPresent(unsigned int nslot) const
Read the &quot;PRESENT&quot; bit for this slot.
Definition: HcalDTCHeader.h:80
unsigned int getTotalLengthBytes() const
bool getSlotEnabled(unsigned int nslot) const
Read the &quot;ENABLED&quot; bit for this slot.
Definition: HcalDTCHeader.h:78
uint32_t commondataformat1
uint32_t dcch0
const unsigned short * getRawData() const
Get a pointer to the raw data.
Definition: HcalHTRData.h:36
void adoptData(const unsigned short *data, int length)
Definition: HcalHTRData.cc:47
int getSlotData(int nslot, HcalHTRData &decodeTool, int validSize) const
unsigned int getSlotDataLength(int nslot) const
Definition: HcalDTCHeader.h:75
uint32_t commondataformat3
static const int SLOT_COUNT
Definition: HcalDTCHeader.h:20
static const int MAXIMUM_SLOT
Definition: HcalDTCHeader.h:22
void setHeader(int sourceid, int bcn, int l1aN, int orbN)
bool getSlotCRCError(unsigned int nslot) const
Read the &quot;CRC-Mismatch&quot; bit for this slot.
Definition: HcalDTCHeader.h:84