1 |
/** @file |
/** @file |
2 |
* $Source: /home/cvsmanager/yoda/techmodel/physics/S4Reader.cpp,v $ |
* $Source: /home/cvsmanager/yoda/techmodel/physics/S4Reader.cpp,v $ |
3 |
* $Id: S4Reader.cpp,v 2.1 2004/10/17 12:28:46 kusanagi Exp $ |
* $Id: S4Reader.cpp,v 4.2 2005/03/16 22:53:15 kusanagi Exp $ |
4 |
* $Author: kusanagi $ |
* $Author: kusanagi $ |
5 |
* |
* |
6 |
* Implementation of the S4Reader class. |
* Implementation of the S4Reader class. |
29 |
*/ |
*/ |
30 |
std::string S4Reader::GetVersionInfo(void) const { |
std::string S4Reader::GetVersionInfo(void) const { |
31 |
return |
return |
32 |
"$Header: /home/cvsmanager/yoda/techmodel/physics/S4Reader.cpp,v 2.1 2004/10/17 12:28:46 kusanagi Exp $"; |
"$Header: /home/cvsmanager/yoda/techmodel/physics/S4Reader.cpp,v 4.2 2005/03/16 22:53:15 kusanagi Exp $"; |
33 |
} |
} |
34 |
|
|
35 |
/** |
/** |
55 |
* consequently supposing the Neutron data (12 Bytes) always present S4 start 18 Bytes before the end of the packet |
* consequently supposing the Neutron data (12 Bytes) always present S4 start 18 Bytes before the end of the packet |
56 |
*/ |
*/ |
57 |
void S4Reader::RunEvent(int EventNumber, const char subData[], long int length) { |
void S4Reader::RunEvent(int EventNumber, const char subData[], long int length) { |
58 |
//char *data = new char[lenght]; |
int offset; |
59 |
//memcpy(data, subData, lenght); |
int index = haveData(&*subData, length); |
60 |
int offset = length - 18; |
|
61 |
s4->S4_REG_STATUS = (((UINT8)subData[offset])&0xF0); |
if (index > 0){ |
62 |
s4->S4_DATA = ((((UINT16)subData[offset]<<8)&0x0FFF) + (((UINT16)subData[offset+1])&0x00FF)); |
int offset = length - index; |
63 |
s4->S4_CMD_NUM = (((UINT8)subData[offset+2])&0xFF);; |
s4->S4_REG_STATUS = (((UINT8)subData[offset])&0xF0); |
64 |
s4->S4_RESP_LENGHT = ((((UINT16)subData[offset+3]<<8)&0xFF00) + (((UINT16)subData[offset+4])&0x00FF));; |
s4->S4_DATA = ((((UINT16)subData[offset]<<8)&0x0FFF) + (((UINT16)subData[offset+1])&0x00FF)); |
65 |
s4->S4_OVERALL_CHKCODE = (((UINT8)subData[offset+5])&0xFF);; |
s4->S4_CMD_NUM = (((UINT8)subData[offset+2])&0xFF); |
66 |
|
s4->S4_RESP_LENGHT = ((((UINT16)subData[offset+3]<<8)&0xFF00) + (((UINT16)subData[offset+4])&0x00FF)); |
67 |
|
s4->S4_OVERALL_CHKCODE = (((UINT8)subData[offset+5])&0xFF); |
68 |
|
s4->unpackError = 0; |
69 |
|
} else { |
70 |
|
s4->unpackError = 1; |
71 |
|
} |
72 |
} |
} |
73 |
|
|
74 |
|
/* |
75 |
|
* |
76 |
|
* @return int |
77 |
|
* It return the index, starting from the end of data[] parameter, which |
78 |
|
* is the starting byte of the S4 data. |
79 |
|
* |
80 |
|
*/ |
81 |
|
/** |
82 |
|
* Check if S4Data are present. |
83 |
|
* @param const char data[] - Physics data |
84 |
|
* @param long int lenght - Lenght of data[] |
85 |
|
* @return int represent the index from the end of data[] |
86 |
|
* from which S4 data starts |
87 |
|
*/ |
88 |
|
int S4Reader::haveData(const char data[], long int length){ |
89 |
|
int ret = 0; |
90 |
|
/* I start 20 bytes from the end because we have three cases: |
91 |
|
* |
92 |
|
* 1) S4 (4bytes) + NeutronDetector (12bytes) //END PACKET |
93 |
|
* 2) S4 (4bytes) //END PACKET |
94 |
|
* 3) //END PACKET |
95 |
|
* |
96 |
|
* so in anycase I expect to find the data into the last 20 bytes |
97 |
|
* Anyway, it will be a MUST to implements also the check of the CRC |
98 |
|
* on the S4 data to have a better confidence on the data; the crc algorithm |
99 |
|
* sholud be the same of the Tracker |
100 |
|
* |
101 |
|
*/ |
102 |
|
|
103 |
|
//Check the existence of NeutronDetector data |
104 |
|
if (((UINT8)data[length - 1] == 0x0F)&&((UINT8)data[length - 5] == 0x0F)&&((UINT8)data[length - 9] == 0x0F) && |
105 |
|
((UINT8)data[length - 2] == 0x00)&&((UINT8)data[length - 6] == 0x00)&&((UINT8)data[length - 10] == 0x00)) { |
106 |
|
//Chech the existance of S4 data before NeutronDetector |
107 |
|
if (((UINT8)data[length - 14] == 0x03) && |
108 |
|
((UINT8)data[length - 15] == 0x00) && |
109 |
|
((UINT8)data[length - 16] == 0xD8)) ret = 18; |
110 |
|
//NeutronDetector data does not exists |
111 |
|
} else { |
112 |
|
//Chech the existance of S4 data at the end of the Physics packet |
113 |
|
if ( ((UINT8)data[length - 2] == 0x03) && |
114 |
|
((UINT8)data[length - 3] == 0x00) && |
115 |
|
((UINT8)data[length - 4] == 0xD8)) ret = 6; |
116 |
|
} |
117 |
|
return ret; |
118 |
|
} |