CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CastorCTDCHeader.cc
Go to the documentation of this file.
1 /*
2  * \author A. Campbell -- DESY
3  */
8 #include <string.h>
9 #include <stdint.h>
10 
11 const int CastorCTDCHeader::SPIGOT_COUNT = 2; // COR spigots - does not include merger pay load
12 
14 
16  unsigned int totalSize=sizeof(CastorCTDCHeader);
17  for (int i=0; i<SPIGOT_COUNT+1; i++) // includes merger pay load
18  totalSize+=(spigotInfo[i]&0x3FF)*4;
19  return totalSize; // doesn't include the trailer
20 }
21 
22 int CastorCTDCHeader::getSpigotData(int nspigot, CastorCORData& decodeTool, int validSize) const {
23  const unsigned short* base=((unsigned short*)this)+sizeof(CastorCTDCHeader)/sizeof(unsigned short);
24  int offset=0,i,len=0;
25  for (i=0; i<=nspigot; i++) {
26  offset+=len;
27  len=(spigotInfo[i]&0x3FF)*2;
28  }
29  if ((offset+len+sizeof(CastorCTDCHeader)/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  ctdch0=0x1; // format version 1
41  ctdch1=0;
42  for (int i=0; i<3; i++)
43  spigotInfo[i]=0;
44  spigotInfo[3]=0x12345678; // end DCC header pattern
45 
46 }
47 
48 void CastorCTDCHeader::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 CastorCTDCHeader::copySpigotData(unsigned int spigot_id, const CastorCORData& data, bool valid, unsigned char LRB_error_word) {
54  if (spigot_id>=(unsigned int)SPIGOT_COUNT) return;
55  // construct the spigot info
56  spigotInfo[spigot_id]=(data.getRawLength()/2)|0xc000;
57  if (valid) spigotInfo[spigot_id]|=0x2000;
58  spigotInfo[spigot_id]|=(LRB_error_word<<16)|((data.getErrorsWord()&0xFF)<<24);
59  // status info...
60  if (valid) ctdch0|=(1<<(spigot_id+14));
61  // copy
62  unsigned int lenSoFar=0;
63  for (unsigned int i=0; i<spigot_id; i++) lenSoFar+=getSpigotDataLength(i);
64  unsigned short* startingPoint=((unsigned short*)this)+sizeof(CastorCTDCHeader)/sizeof(unsigned short)+lenSoFar*2;
65  memcpy(startingPoint,data.getRawData(),sizeof(unsigned short)*data.getRawLength());
66  // update the trailer...
67  lenSoFar+=data.getRawLength()/2; // 32-bit words
68  uint32_t* trailer=((uint32_t*)this)+sizeof(CastorCTDCHeader)/sizeof(uint32_t)+lenSoFar;
69  int len64=sizeof(CastorCTDCHeader)/8+lenSoFar/2+1;
70  trailer[1]=0;
71  trailer[0]=0xA0000000u|len64;
72 }
73 
75  unsigned int spigot_id = 2;
76  // construct the spigot info
77  spigotInfo[spigot_id]=(data.getRawLength()/2)|0xc000; // Enabled & Present
78  if (valid) spigotInfo[spigot_id]|=0x2000; // Valid
79  spigotInfo[spigot_id]|=((data.getErrorsWord()&0xFF)<<24);
80  // status info...
81  if (valid) ctdch0|=(1<<(spigot_id+14));
82  // copy
83  unsigned int lenSoFar=0;
84  for (unsigned int i=0; i<spigot_id; i++) lenSoFar+=getSpigotDataLength(i);
85  unsigned short* startingPoint=((unsigned short*)this)+sizeof(CastorCTDCHeader)/sizeof(unsigned short)+lenSoFar*2;
86  memcpy(startingPoint,data.getRawData(),sizeof(unsigned short)*data.getRawLength());
87  // update the trailer...
88  lenSoFar+=data.getRawLength()/2; // 32-bit words
89  uint32_t* trailer=((uint32_t*)this)+sizeof(CastorCTDCHeader)/sizeof(uint32_t)+lenSoFar;
90  int len64=sizeof(CastorCTDCHeader)/8+lenSoFar/2+1;
91  trailer[1]=0;
92  trailer[0]=0xA0000000u|len64;
93 }
94 
95 std::ostream& operator<<(std::ostream& s, const CastorCTDCHeader& head) {
96 
97  for (int i=0; i<CastorCTDCHeader::SPIGOT_COUNT+1; i++) {
98  s << "Spigot " << i << " : " << head.getSpigotDataLength(i) << " bytes, ";
99  if (head.getSpigotEnabled(i)) s << "E";
100  if (head.getSpigotPresent(i)) s << "P";
101  if (head.getSpigotValid(i)) s << "V";
102  s << ". Error codes: " << std::hex << int(head.getSpigotErrorBits(i)) << std::dec;
103  s << std::endl;
104  }
105  return s;
106 }
int getSpigotData(int nspigot, CastorCORData &decodeTool, int validSize) const
tuple base
Main Program
Definition: newFWLiteAna.py:91
int i
Definition: DBlmapReader.cc:9
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)
bool getSpigotEnabled(unsigned int nspigot) const
Read the &quot;ENABLED&quot; bit for this spigot.
unsigned int getTotalLengthBytes() const
const int getRawLength() const
Get the length of the raw data.
void setHeader(int sourceid, int bcn, int l1aN, int orbN)
unsigned int getErrorsWord() const
Get the errors word.
unsigned int getErrorsWord() const
Get the errors word.
std::ostream & operator<<(std::ostream &out, const ALILine &li)
Definition: ALILine.cc:188
static const int SPIGOT_COUNT
unsigned int commondataformat0
void copySpigotData(unsigned int spigot_id, const CastorCORData &data, bool valid=true, unsigned char LRB_error_word=0)
Add the given CastorCORData as the given spigot&#39;s data. This should be done in increasing spigot orde...
unsigned int commondataformat3
void copyMergerData(const CastorMergerData &data, bool valid)
unsigned int spigotInfo[4]
unsigned int getSpigotDataLength(int nspigot) const
unsigned int commondataformat2
unsigned int commondataformat1
const unsigned short * getRawData() const
Get a pointer to the raw data.
const int getRawLength() const
Get the length of the raw data.
Definition: CastorCORData.h:36
const unsigned short * getRawData() const
Get a pointer to the raw data.
Definition: CastorCORData.h:33
bool getSpigotPresent(unsigned int nspigot) const
Read the &quot;PRESENT&quot; bit for this spigot.
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
unsigned int ctdch1
unsigned char getSpigotErrorBits(unsigned int nspigot) const
Access the HTR error bits (decoding tbd)
unsigned int ctdch0