1 |
|
2 |
#include <string> |
3 |
#include <log4cpp/Category.hh> |
4 |
#include "NeutronDetectorReader.h" |
5 |
|
6 |
using namespace pamela; |
7 |
using namespace pamela::neutron; |
8 |
|
9 |
static log4cpp::Category& cat = log4cpp::Category::getInstance("pamela.techmodel.neutron.NeutronDetectorReader"); |
10 |
|
11 |
/** |
12 |
* Constructor. |
13 |
*/ |
14 |
NeutronDetectorReader::NeutronDetectorReader(void): |
15 |
TechmodelAlgorithm(PacketType::Physics, "TechmodelNeutronDetectorReader") { |
16 |
cat.debug("Constructor"); |
17 |
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 |
"$Header: /home/cvsmanager/yoda/techmodel/physics/NeutronDetectorReader.cpp,v 1.1 2004/07/20 13:27:07 kusanagi Exp $"; |
26 |
} |
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 |
SetInputStream(run); |
34 |
run->WriteSubPacket(this, &neutronEvent, neutronEvent->Class()); |
35 |
} |
36 |
|
37 |
/** |
38 |
* Unpack the anticounter event from an input file. |
39 |
*/ |
40 |
void NeutronDetectorReader::RunEvent(int EventNumber) { |
41 |
|
42 |
} |
43 |
|
44 |
/** |
45 |
* Unpack the NeutronDetector data event from the physical packet. |
46 |
*/ |
47 |
void NeutronDetectorReader::RunEvent(int EventNumber, const char subData[], long int lenght) { |
48 |
NeutronRecord *rec; |
49 |
int offset = 0; |
50 |
char data[lenght]; |
51 |
//the 2 bytes subtracted belong to the final event CRC bytes |
52 |
memcpy(data, subData, lenght); |
53 |
neutronEvent->Records->Clear(); |
54 |
TClonesArray &recs = *(neutronEvent->Records); |
55 |
offset = 12; |
56 |
if (haveData(data, lenght)){ |
57 |
for (int i = 0; i < 3; i++){ |
58 |
rec = new(recs[i]) NeutronRecord(); //aggiungo un nuovo NeutronRecord all'evento |
59 |
rec->upperTrig = (((BYTE)data[lenght-offset])>>4); |
60 |
rec->bottomTrig = (((BYTE)data[lenght-offset])&0x0F); |
61 |
rec->upperBack = (((BYTE)data[lenght-offset+1])>>4); |
62 |
rec->bottomBack = (((BYTE)data[lenght-offset+1])&0x0F); |
63 |
offset = offset - 4*(i+1); |
64 |
} |
65 |
} |
66 |
} |
67 |
|
68 |
bool NeutronDetectorReader::haveData(const char data[], long int lenght){ |
69 |
bool ret = false; |
70 |
if (((data[lenght-1] && data[lenght - 5] && data[lenght - 9]) && 0x0F) && |
71 |
((data[lenght-2] | data[lenght - 6] | data[lenght - 10]) == 0x00)) ret = true; |
72 |
return ret; |
73 |
} |