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  * $Date: 2012/10/22 14:05:56 $
3  * $Revision: 1.1 $
4  * \author J. Mans -- UMD
5  */
8 #include <string.h>
9 #include <stdint.h>
10 
11 const int HcalDTCHeader::SLOT_COUNT = 12;
12 const int HcalDTCHeader::MINIMUM_SLOT = 1;
13 const int HcalDTCHeader::MAXIMUM_SLOT = 12;
14 
16 
17 unsigned int HcalDTCHeader::getTotalLengthBytes() const {
18  unsigned int totalSize=sizeof(HcalDTCHeader);
19  for (int i=0; i<SLOT_COUNT; i++)
20  totalSize+=(slotInfo[i]&0xFFF)*sizeof(uint16_t);
21  return totalSize;
22 }
23 
24 int HcalDTCHeader::getSlotData(int nslot, HcalHTRData& decodeTool, int validSize) const {
25  const unsigned short* base=((unsigned short*)this)+sizeof(HcalDTCHeader)/sizeof(unsigned short);
26  int offset=0,i,len=0;
27  for (i=1; i<=nslot; i++) {
28  offset+=len;
29  len=(slotInfo[i-1]&0xFFF);
30  }
31  if ((offset+len+sizeof(HcalDTCHeader)/sizeof(unsigned short))<(validSize/sizeof(unsigned short))) {
32  decodeTool.adoptData(base+offset,len);
33  return 0;
34  } else { return -1; }
35 }
36 
39  commondataformat1=0x50000000u;
42  dcch0=0x1; // format version 1
43  dcch1=0;
44  for (int i=0; i<SLOT_COUNT; i++)
45  slotInfo[i]=0;
46 }
47 
48 void HcalDTCHeader::setHeader(int sourceid, int bcn, int l1aN, int orbN) {
49  commondataformat0=0x8|((sourceid&0xFFF)<<8)|((bcn&0xFFF)<<20);
50  commondataformat1=0x50000000u|(l1aN&0xFFFFFF);
51 }
52 
53 void HcalDTCHeader::copySlotData(unsigned int slot_id, const HcalHTRData& data, bool valid) {
54  if (slot_id==0 || slot_id>(unsigned int)SLOT_COUNT) return;
55  // construct the slot info
56  slotInfo[slot_id-1]=(data.getRawLength())|0xc000;
57  if (valid) slotInfo[slot_id-1]|=0x2000;
58  // status info...
59  // if (valid) dcch0|=(1<<(slot_id+14));
60  // copy
61  unsigned int lenSoFar=0;
62  for (unsigned int i=1; i<slot_id; i++) lenSoFar+=getSlotDataLength(i);
63  unsigned short* startingPoint=((unsigned short*)this)+sizeof(HcalDTCHeader)/sizeof(unsigned short)+lenSoFar;
64  memcpy(startingPoint,data.getRawData(),sizeof(unsigned short)*data.getRawLength());
65  // update the trailer...
66  lenSoFar+=data.getRawLength();
67  uint32_t* trailer=((uint32_t*)this)+sizeof(HcalDTCHeader)/sizeof(uint32_t)+lenSoFar/2;
68  int len64=sizeof(HcalDTCHeader)/8+lenSoFar/4+1;
69  trailer[1]=0;
70  trailer[0]=0xA0000000u|len64;
71 }
72 
73 std::ostream& operator<<(std::ostream& s, const HcalDTCHeader& head) {
74 
75  for (int i=0; i<HcalDTCHeader::SLOT_COUNT; i++) {
76  s << "Slot " << i << " : " << head.getSlotDataLength(i) << " bytes, ";
77  if (head.getSlotEnabled(i)) s << "E";
78  if (head.getSlotPresent(i)) s << "P";
79  if (head.getSlotValid(i)) s << "V";
80  if (head.getSlotCRCError(i)) s << "C";
81  // s << ". Error codes: " << std::hex << int(head.getSlotErrorBits(i)) << "," << int(head.getLRBErrorBits(i)) << std::dec;
82  s << std::endl;
83  }
84  return s;
85 }
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:23
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:41
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:84
unsigned int offset(bool)
bool getSlotPresent(unsigned int nslot) const
Read the &quot;PRESENT&quot; bit for this slot.
Definition: HcalDTCHeader.h:82
unsigned int getTotalLengthBytes() const
bool getSlotEnabled(unsigned int nslot) const
Read the &quot;ENABLED&quot; bit for this slot.
Definition: HcalDTCHeader.h:80
uint32_t commondataformat1
uint32_t dcch0
const unsigned short * getRawData() const
Get a pointer to the raw data.
Definition: HcalHTRData.h:38
void adoptData(const unsigned short *data, int length)
Definition: HcalHTRData.cc:49
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
int getSlotData(int nslot, HcalHTRData &decodeTool, int validSize) const
unsigned int getSlotDataLength(int nslot) const
Definition: HcalDTCHeader.h:77
uint32_t commondataformat3
static const int SLOT_COUNT
Definition: HcalDTCHeader.h:22
static const int MAXIMUM_SLOT
Definition: HcalDTCHeader.h:24
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:86