CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
HcalDCCHeader.cc
Go to the documentation of this file.
1 /*
2  * \author J. Mans -- UMD
3  */
7 #include <string.h>
8 #include <stdint.h>
9 
10 const int HcalDCCHeader::SPIGOT_COUNT = 15;
11 
13 
14 unsigned int HcalDCCHeader::getTotalLengthBytes() const {
15  unsigned int totalSize=sizeof(HcalDCCHeader);
16  for (int i=0; i<SPIGOT_COUNT; i++)
17  totalSize+=(spigotInfo[i]&0x3FF)*4;
18  return totalSize;
19 }
20 
21 void HcalDCCHeader::getSpigotData(int nspigot, HcalHTRData& decodeTool) const {
22  edm::LogWarning("HCAL-Unpacker") << "Using unsafe getSpigotData without length controls. Not recommended! Replace with new getSpigotData call";
23  getSpigotData(nspigot,decodeTool,10000000);
24 }
25 
26 
27 int HcalDCCHeader::getSpigotData(int nspigot, HcalHTRData& decodeTool, int validSize) const {
28  const unsigned short* base=((unsigned short*)this)+sizeof(HcalDCCHeader)/sizeof(unsigned short);
29  int offset=0,i,len=0;
30  for (i=0; i<=nspigot; i++) {
31  offset+=len;
32  len=(spigotInfo[i]&0x3FF)*2;
33  }
34  if ((offset+len+sizeof(HcalDCCHeader)/sizeof(unsigned short))<(validSize/sizeof(unsigned short))) {
35  decodeTool.adoptData(base+offset,len);
36  return 0;
37  } else { return -1; }
38 }
39 
42  commondataformat1=0x50000000u;
45  dcch0=0x1; // format version 1
46  dcch1=0;
47  for (int i=0; i<18; i++)
48  spigotInfo[i]=0;
49 }
50 
51 void HcalDCCHeader::setHeader(int sourceid, int bcn, int l1aN, int orbN) {
52  commondataformat0=0x8|((sourceid&0xFFF)<<8)|((bcn&0xFFF)<<20);
53  commondataformat1=0x50000000u|(l1aN&0xFFFFFF);
54  commondataformat2=((orbN&0xFFFFFFF)<<4);
55  commondataformat3=((orbN>>28)&0xF);
56 }
57 
58 void HcalDCCHeader::copySpigotData(unsigned int spigot_id, const HcalHTRData& data, bool valid, unsigned char LRB_error_word) {
59  if (spigot_id>=(unsigned int)SPIGOT_COUNT) return;
60  // construct the spigot info
61  spigotInfo[spigot_id]=(data.getRawLength()/2)|0xc000;
62  if (valid) spigotInfo[spigot_id]|=0x2000;
63  spigotInfo[spigot_id]|=(LRB_error_word<<16)|((data.getErrorsWord()&0xFF)<<24);
64  // status info...
65  if (valid) dcch0|=(1<<(spigot_id+14));
66  // copy
67  unsigned int lenSoFar=0;
68  for (unsigned int i=0; i<spigot_id; i++) lenSoFar+=getSpigotDataLength(i);
69  unsigned short* startingPoint=((unsigned short*)this)+sizeof(HcalDCCHeader)/sizeof(unsigned short)+lenSoFar*2;
70  memcpy(startingPoint,data.getRawData(),sizeof(unsigned short)*data.getRawLength());
71  // update the trailer...
72  lenSoFar+=data.getRawLength()/2; // 32-bit words
73  uint32_t* trailer=((uint32_t*)this)+sizeof(HcalDCCHeader)/sizeof(uint32_t)+lenSoFar;
74  int len64=sizeof(HcalDCCHeader)/8+lenSoFar/2+1;
75  trailer[1]=0;
76  trailer[0]=0xA0000000u|len64;
77 }
78 
79 std::ostream& operator<<(std::ostream& s, const HcalDCCHeader& head) {
80 
81  for (int i=0; i<HcalDCCHeader::SPIGOT_COUNT; i++) {
82  s << "Spigot " << i << " : " << head.getSpigotDataLength(i) << " bytes, ";
83  if (head.getSpigotEnabled(i)) s << "E";
84  if (head.getSpigotPresent(i)) s << "P";
85  if (head.getSpigotValid(i)) s << "V";
86  s << ". Error codes: " << std::hex << int(head.getSpigotErrorBits(i)) << "," << int(head.getLRBErrorBits(i)) << std::dec;
87  s << std::endl;
88  }
89  return s;
90 }
tuple base
Main Program
Definition: newFWLiteAna.py:92
int i
Definition: DBlmapReader.cc:9
unsigned char getSpigotErrorBits(unsigned int nspigot) const
Access the HTR error bits (decoding tbd)
unsigned int getSpigotDataLength(int nspigot) const
Definition: HcalDCCHeader.h:96
uint32_t spigotInfo[18]
uint32_t dcch0
std::ostream & operator<<(std::ostream &out, const ALILine &li)
Definition: ALILine.cc:187
int getSpigotData(int nspigot, HcalHTRData &decodeTool, int validSize) const
unsigned char getLRBErrorBits(unsigned int nspigot) const
Access the Link Receiver Board error bits (decoding tbd)
unsigned int getTotalLengthBytes() const
void copySpigotData(unsigned int spigot_id, const HcalHTRData &data, bool valid=true, unsigned char LRB_error_word=0)
Add the given HcalHTRData as the given spigot&#39;s data. This should be done in increasing spigot order!...
uint32_t commondataformat0
const int getRawLength() const
Get the length of the raw data.
Definition: HcalHTRData.h:39
uint32_t commondataformat3
void setHeader(int sourceid, int bcn, int l1aN, int orbN)
bool getSpigotPresent(unsigned int nspigot) const
Read the &quot;PRESENT&quot; bit for this spigot.
uint32_t dcch1
bool getSpigotEnabled(unsigned int nspigot) const
Read the &quot;ENABLED&quot; bit for this spigot.
Definition: HcalDCCHeader.h:99
const unsigned short * getRawData() const
Get a pointer to the raw data.
Definition: HcalHTRData.h:36
unsigned int getErrorsWord() const
Get the errors word.
Definition: HcalHTRData.h:157
uint32_t commondataformat2
bool getSpigotValid(unsigned int nspigot) const
Read the &quot;VALID&quot; bit for this spigot; TTC EvN matched HTR EvN.
void adoptData(const unsigned short *data, int length)
Definition: HcalHTRData.cc:47
static const int SPIGOT_COUNT
Definition: HcalDCCHeader.h:19
uint32_t commondataformat1
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82