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  * $Date: 2008/09/11 13:19:22 $
3  * $Revision: 1.5 $
4  * \author A. Campbell -- DESY
5  */
10 #include <string.h>
11 #include <stdint.h>
12 
13 const int CastorCTDCHeader::SPIGOT_COUNT = 2; // COR spigots - does not include merger pay load
14 
16 
18  unsigned int totalSize=sizeof(CastorCTDCHeader);
19  for (int i=0; i<SPIGOT_COUNT+1; i++) // includes merger pay load
20  totalSize+=(spigotInfo[i]&0x3FF)*4;
21  return totalSize; // doesn't include the trailer
22 }
23 
24 int CastorCTDCHeader::getSpigotData(int nspigot, CastorCORData& decodeTool, int validSize) const {
25  const unsigned short* base=((unsigned short*)this)+sizeof(CastorCTDCHeader)/sizeof(unsigned short);
26  int offset=0,i,len=0;
27  for (i=0; i<=nspigot; i++) {
28  offset+=len;
29  len=(spigotInfo[i]&0x3FF)*2;
30  }
31  if ((offset+len+sizeof(CastorCTDCHeader)/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  ctdch0=0x1; // format version 1
43  ctdch1=0;
44  for (int i=0; i<3; i++)
45  spigotInfo[i]=0;
46  spigotInfo[3]=0x12345678; // end DCC header pattern
47 
48 }
49 
50 void CastorCTDCHeader::setHeader(int sourceid, int bcn, int l1aN, int orbN) {
51  commondataformat0=0x8|((sourceid&0xFFF)<<8)|((bcn&0xFFF)<<20);
52  commondataformat1=0x50000000u|(l1aN&0xFFFFFF);
53 }
54 
55 void CastorCTDCHeader::copySpigotData(unsigned int spigot_id, const CastorCORData& data, bool valid, unsigned char LRB_error_word) {
56  if (spigot_id>=(unsigned int)SPIGOT_COUNT) return;
57  // construct the spigot info
58  spigotInfo[spigot_id]=(data.getRawLength()/2)|0xc000;
59  if (valid) spigotInfo[spigot_id]|=0x2000;
60  spigotInfo[spigot_id]|=(LRB_error_word<<16)|((data.getErrorsWord()&0xFF)<<24);
61  // status info...
62  if (valid) ctdch0|=(1<<(spigot_id+14));
63  // copy
64  unsigned int lenSoFar=0;
65  for (unsigned int i=0; i<spigot_id; i++) lenSoFar+=getSpigotDataLength(i);
66  unsigned short* startingPoint=((unsigned short*)this)+sizeof(CastorCTDCHeader)/sizeof(unsigned short)+lenSoFar*2;
67  memcpy(startingPoint,data.getRawData(),sizeof(unsigned short)*data.getRawLength());
68  // update the trailer...
69  lenSoFar+=data.getRawLength()/2; // 32-bit words
70  uint32_t* trailer=((uint32_t*)this)+sizeof(CastorCTDCHeader)/sizeof(uint32_t)+lenSoFar;
71  int len64=sizeof(CastorCTDCHeader)/8+lenSoFar/2+1;
72  trailer[1]=0;
73  trailer[0]=0xA0000000u|len64;
74 }
75 
77  unsigned int spigot_id = 2;
78  // construct the spigot info
79  spigotInfo[spigot_id]=(data.getRawLength()/2)|0xc000; // Enabled & Present
80  if (valid) spigotInfo[spigot_id]|=0x2000; // Valid
81  spigotInfo[spigot_id]|=((data.getErrorsWord()&0xFF)<<24);
82  // status info...
83  if (valid) ctdch0|=(1<<(spigot_id+14));
84  // copy
85  unsigned int lenSoFar=0;
86  for (unsigned int i=0; i<spigot_id; i++) lenSoFar+=getSpigotDataLength(i);
87  unsigned short* startingPoint=((unsigned short*)this)+sizeof(CastorCTDCHeader)/sizeof(unsigned short)+lenSoFar*2;
88  memcpy(startingPoint,data.getRawData(),sizeof(unsigned short)*data.getRawLength());
89  // update the trailer...
90  lenSoFar+=data.getRawLength()/2; // 32-bit words
91  uint32_t* trailer=((uint32_t*)this)+sizeof(CastorCTDCHeader)/sizeof(uint32_t)+lenSoFar;
92  int len64=sizeof(CastorCTDCHeader)/8+lenSoFar/2+1;
93  trailer[1]=0;
94  trailer[0]=0xA0000000u|len64;
95 }
96 
97 std::ostream& operator<<(std::ostream& s, const CastorCTDCHeader& head) {
98 
99  for (int i=0; i<CastorCTDCHeader::SPIGOT_COUNT+1; i++) {
100  s << "Spigot " << i << " : " << head.getSpigotDataLength(i) << " bytes, ";
101  if (head.getSpigotEnabled(i)) s << "E";
102  if (head.getSpigotPresent(i)) s << "P";
103  if (head.getSpigotValid(i)) s << "V";
104  s << ". Error codes: " << std::hex << int(head.getSpigotErrorBits(i)) << std::dec;
105  s << std::endl;
106  }
107  return s;
108 }
int getSpigotData(int nspigot, CastorCORData &decodeTool, int validSize) const
tuple base
Main Program
Definition: newFWLiteAna.py:92
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:187
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 offset(bool)
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:38
const unsigned short * getRawData() const
Get a pointer to the raw data.
Definition: CastorCORData.h:35
bool getSpigotPresent(unsigned int nspigot) const
Read the &quot;PRESENT&quot; bit for this spigot.
unsigned int ctdch1
string s
Definition: asciidump.py:422
unsigned char getSpigotErrorBits(unsigned int nspigot) const
Access the HTR error bits (decoding tbd)
unsigned int ctdch0