1 |
kusanagi |
1.1 |
|
2 |
|
|
#include <string> |
3 |
kusanagi |
1.2 |
#include <log4cxx/logger.h> |
4 |
kusanagi |
1.1 |
#include "NeutronDetectorReader.h" |
5 |
|
|
|
6 |
|
|
using namespace pamela; |
7 |
|
|
using namespace pamela::neutron; |
8 |
|
|
|
9 |
kusanagi |
1.2 |
static log4cxx::LoggerPtr logger = log4cxx::Logger::getLogger(_T("pamela.techmodel.neutron.NeutronDetectorReader")); |
10 |
kusanagi |
1.1 |
|
11 |
|
|
/** |
12 |
|
|
* Constructor. |
13 |
|
|
*/ |
14 |
|
|
NeutronDetectorReader::NeutronDetectorReader(void): |
15 |
|
|
TechmodelAlgorithm(PacketType::Physics, "TechmodelNeutronDetectorReader") { |
16 |
kusanagi |
1.2 |
logger->debug(_T("Constructor")); |
17 |
kusanagi |
1.1 |
neutronEvent = new NeutronEvent(); |
18 |
|
|
} |
19 |
|
|
|
20 |
|
|
/** |
21 |
|
|
* Get a string with the version info of the algorithm. |
22 |
|
|
*/ |
23 |
|
|
std::string NeutronDetectorReader::GetVersionInfo(void) const { |
24 |
|
|
return |
25 |
kusanagi |
2.3 |
"$Header: /home/cvsmanager/yoda/techmodel/physics/NeutronDetectorReader.cpp,v 2.2 2004/12/09 08:48:54 kusanagi Exp $"; |
26 |
kusanagi |
1.1 |
} |
27 |
|
|
|
28 |
|
|
/** |
29 |
|
|
* Initialize the algorithm with a special run. This will initialize the |
30 |
|
|
* event reader routines for all packet types. |
31 |
|
|
*/ |
32 |
|
|
void NeutronDetectorReader::Init(PamelaRun *run) { |
33 |
kusanagi |
1.2 |
logger->debug(_T("Initialize")); |
34 |
kusanagi |
1.1 |
SetInputStream(run); |
35 |
|
|
run->WriteSubPacket(this, &neutronEvent, neutronEvent->Class()); |
36 |
|
|
} |
37 |
|
|
|
38 |
|
|
/** |
39 |
|
|
* Unpack the anticounter event from an input file. |
40 |
|
|
*/ |
41 |
|
|
void NeutronDetectorReader::RunEvent(int EventNumber) { |
42 |
|
|
|
43 |
|
|
} |
44 |
|
|
|
45 |
|
|
/** |
46 |
|
|
* Unpack the NeutronDetector data event from the physical packet. |
47 |
|
|
*/ |
48 |
|
|
void NeutronDetectorReader::RunEvent(int EventNumber, const char subData[], long int lenght) { |
49 |
kusanagi |
2.2 |
NeutronRecord *rec; |
50 |
|
|
const int lenNeutronData = 12; |
51 |
|
|
char *data = new char[lenght]; |
52 |
|
|
memcpy(data, subData, lenght); |
53 |
kusanagi |
1.1 |
neutronEvent->Records->Clear(); |
54 |
|
|
TClonesArray &recs = *(neutronEvent->Records); |
55 |
kusanagi |
2.1 |
int offset; |
56 |
kusanagi |
1.1 |
if (haveData(data, lenght)){ |
57 |
|
|
for (int i = 0; i < 3; i++){ |
58 |
kusanagi |
2.1 |
offset = lenNeutronData - 4*i; |
59 |
kusanagi |
1.1 |
rec = new(recs[i]) NeutronRecord(); //aggiungo un nuovo NeutronRecord all'evento |
60 |
kusanagi |
2.3 |
rec->upperTrig = (((UINT8)data[lenght-offset])>>4); |
61 |
|
|
rec->bottomTrig = (((UINT8)data[lenght-offset])&0x0F); |
62 |
|
|
rec->upperBack = (((UINT8)data[lenght-offset+1])>>4); |
63 |
|
|
rec->bottomBack = (((UINT8)data[lenght-offset+1])&0x0F); |
64 |
kusanagi |
1.1 |
} |
65 |
kusanagi |
2.3 |
neutronEvent->unpackError = 0; |
66 |
|
|
} else { |
67 |
|
|
neutronEvent->unpackError = 1; |
68 |
kusanagi |
1.1 |
} |
69 |
kusanagi |
1.2 |
delete[] data; |
70 |
kusanagi |
1.1 |
} |
71 |
|
|
|
72 |
kusanagi |
2.2 |
/* For definition the definition for Neutron detector data is |
73 |
|
|
* "The last data bunch in the phyics packet" */ |
74 |
kusanagi |
1.1 |
bool NeutronDetectorReader::haveData(const char data[], long int lenght){ |
75 |
|
|
bool ret = false; |
76 |
|
|
if (((data[lenght-1] && data[lenght - 5] && data[lenght - 9]) && 0x0F) && |
77 |
|
|
((data[lenght-2] | data[lenght - 6] | data[lenght - 10]) == 0x00)) ret = true; |
78 |
|
|
return ret; |
79 |
|
|
} |