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.5 2005/02/11 16:40:19 kusanagi Exp $ |
* $Id: S4Reader.cpp,v 5.0 2005/08/29 09:46:13 Maurizio Nagni Exp $ |
4 |
* $Author: kusanagi $ |
* $Author: Maurizio Nagni $ |
5 |
* |
* |
6 |
* Implementation of the S4Reader class. |
* Implementation of the S4Reader class. |
7 |
*/ |
*/ |
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.5 2005/02/11 16:40:19 kusanagi Exp $"; |
"$Header: /home/cvsmanager/yoda/techmodel/physics/S4Reader.cpp,v 5.0 2005/08/29 09:46:13 Maurizio Nagni 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) { |
|
const int lenS4Data = 6; |
|
|
char *data = new char[length]; |
|
58 |
int offset; |
int offset; |
59 |
int index = haveData(data, length); |
int index = haveData(&*subData, length); |
60 |
|
|
61 |
if (index > -1){ |
if (index > 0){ |
62 |
int offset = length - index; |
int offset = length - index; |
63 |
s4->S4_REG_STATUS = (((UINT8)subData[offset])&0xF0); |
s4->S4_REG_STATUS = (((UINT8)subData[offset])&0xF0); |
64 |
s4->S4_DATA = ((((UINT16)subData[offset]<<8)&0x0FFF) + (((UINT16)subData[offset+1])&0x00FF)); |
s4->S4_DATA = ((((UINT16)subData[offset]<<8)&0x0FFF) + (((UINT16)subData[offset+1])&0x00FF)); |
69 |
} else { |
} else { |
70 |
s4->unpackError = 1; |
s4->unpackError = 1; |
71 |
} |
} |
|
delete[] data; |
|
72 |
} |
} |
73 |
|
|
74 |
/* |
/* |
82 |
* Check if S4Data are present. |
* Check if S4Data are present. |
83 |
* @param const char data[] - Physics data |
* @param const char data[] - Physics data |
84 |
* @param long int lenght - Lenght of data[] |
* @param long int lenght - Lenght of data[] |
85 |
* @return int - -1 if S4 has not been found, otherwise it represent the |
* @return int represent the index from the end of data[] |
86 |
* index from the end of data[] from which S4 data starts |
* from which S4 data starts |
87 |
*/ |
*/ |
88 |
int S4Reader::haveData(const char data[], long int length){ |
int S4Reader::haveData(const char data[], long int length){ |
89 |
int ret = -1; |
int ret = 0; |
90 |
/* I start 20 bytes from the end because we have three cases: |
/* I start 20 bytes from the end because we have three cases: |
91 |
* |
* |
92 |
* 1) S4 (4bytes) + NeutronDetector (12bytes) //END PACKET |
* 1) S4 (4bytes) + NeutronDetector (12bytes) //END PACKET |
99 |
* sholud be the same of the Tracker |
* sholud be the same of the Tracker |
100 |
* |
* |
101 |
*/ |
*/ |
102 |
int index = 0; |
|
103 |
char dataByte; |
//Check the existence of NeutronDetector data |
104 |
int subIndex = 0; |
if (((UINT8)data[length - 1] == 0x0F)&&((UINT8)data[length - 5] == 0x0F)&&((UINT8)data[length - 9] == 0x0F) && |
105 |
const int subDataDepth = 20; |
((UINT8)data[length - 2] == 0x00)&&((UINT8)data[length - 6] == 0x00)&&((UINT8)data[length - 10] == 0x00)) { |
106 |
int offset = length - subDataDepth; |
//Chech the existance of S4 data before NeutronDetector |
107 |
const int subSignDim = 3; |
if (((UINT8)data[length - 14] == 0x03) && |
108 |
const unsigned char subSign[subSignDim]={0xD8, 0x00, 0x03}; |
((UINT8)data[length - 15] == 0x00) && |
109 |
while (index < subDataDepth){ |
((UINT8)data[length - 16] == 0xD8)) ret = 18; |
110 |
dataByte = data[offset + index++]; |
//NeutronDetector data does not exists |
111 |
if (dataByte == (char)(*(subSign+subIndex))){ |
} else { |
112 |
if (subIndex++ == (subSignDim-1)) { |
//Chech the existance of S4 data at the end of the Physics packet |
113 |
//If here i catch it!!! |
if ( ((UINT8)data[length - 2] == 0x03) && |
114 |
return subDataDepth - index + subSignDim + 2; |
((UINT8)data[length - 3] == 0x00) && |
115 |
} |
((UINT8)data[length - 4] == 0xD8)) ret = 6; |
116 |
} else { |
} |
|
index = index - (subIndex); |
|
|
subIndex = 0; |
|
|
} |
|
|
} |
|
117 |
return ret; |
return ret; |
118 |
} |
} |