Go to the documentation of this file.00001
00002
00003
00004
00005
00006 #include "EventFilter/HcalRawToDigi/interface/HcalHTRData.h"
00007 #include "EventFilter/HcalRawToDigi/interface/HcalDTCHeader.h"
00008 #include <string.h>
00009 #include <stdint.h>
00010
00011 const int HcalDTCHeader::SLOT_COUNT = 12;
00012 const int HcalDTCHeader::MINIMUM_SLOT = 1;
00013 const int HcalDTCHeader::MAXIMUM_SLOT = 12;
00014
00015 HcalDTCHeader::HcalDTCHeader() { }
00016
00017 unsigned int HcalDTCHeader::getTotalLengthBytes() const {
00018 unsigned int totalSize=sizeof(HcalDTCHeader);
00019 for (int i=0; i<SLOT_COUNT; i++)
00020 totalSize+=(slotInfo[i]&0xFFF)*sizeof(uint16_t);
00021 return totalSize;
00022 }
00023
00024 int HcalDTCHeader::getSlotData(int nslot, HcalHTRData& decodeTool, int validSize) const {
00025 const unsigned short* base=((unsigned short*)this)+sizeof(HcalDTCHeader)/sizeof(unsigned short);
00026 int offset=0,i,len=0;
00027 for (i=1; i<=nslot; i++) {
00028 offset+=len;
00029 len=(slotInfo[i-1]&0xFFF);
00030 }
00031 if ((offset+len+sizeof(HcalDTCHeader)/sizeof(unsigned short))<(validSize/sizeof(unsigned short))) {
00032 decodeTool.adoptData(base+offset,len);
00033 return 0;
00034 } else { return -1; }
00035 }
00036
00037 void HcalDTCHeader::clear() {
00038 commondataformat0=0;
00039 commondataformat1=0x50000000u;
00040 commondataformat2=0;
00041 commondataformat3=0;
00042 dcch0=0x1;
00043 dcch1=0;
00044 for (int i=0; i<SLOT_COUNT; i++)
00045 slotInfo[i]=0;
00046 }
00047
00048 void HcalDTCHeader::setHeader(int sourceid, int bcn, int l1aN, int orbN) {
00049 commondataformat0=0x8|((sourceid&0xFFF)<<8)|((bcn&0xFFF)<<20);
00050 commondataformat1=0x50000000u|(l1aN&0xFFFFFF);
00051 }
00052
00053 void HcalDTCHeader::copySlotData(unsigned int slot_id, const HcalHTRData& data, bool valid) {
00054 if (slot_id==0 || slot_id>(unsigned int)SLOT_COUNT) return;
00055
00056 slotInfo[slot_id-1]=(data.getRawLength())|0xc000;
00057 if (valid) slotInfo[slot_id-1]|=0x2000;
00058
00059
00060
00061 unsigned int lenSoFar=0;
00062 for (unsigned int i=1; i<slot_id; i++) lenSoFar+=getSlotDataLength(i);
00063 unsigned short* startingPoint=((unsigned short*)this)+sizeof(HcalDTCHeader)/sizeof(unsigned short)+lenSoFar;
00064 memcpy(startingPoint,data.getRawData(),sizeof(unsigned short)*data.getRawLength());
00065
00066 lenSoFar+=data.getRawLength();
00067 uint32_t* trailer=((uint32_t*)this)+sizeof(HcalDTCHeader)/sizeof(uint32_t)+lenSoFar/2;
00068 int len64=sizeof(HcalDTCHeader)/8+lenSoFar/4+1;
00069 trailer[1]=0;
00070 trailer[0]=0xA0000000u|len64;
00071 }
00072
00073 std::ostream& operator<<(std::ostream& s, const HcalDTCHeader& head) {
00074
00075 for (int i=0; i<HcalDTCHeader::SLOT_COUNT; i++) {
00076 s << "Slot " << i << " : " << head.getSlotDataLength(i) << " bytes, ";
00077 if (head.getSlotEnabled(i)) s << "E";
00078 if (head.getSlotPresent(i)) s << "P";
00079 if (head.getSlotValid(i)) s << "V";
00080 if (head.getSlotCRCError(i)) s << "C";
00081
00082 s << std::endl;
00083 }
00084 return s;
00085 }