1 |
|
2 |
#include <string> |
3 |
#include "NeutronDetectorReader.h" |
4 |
|
5 |
using namespace pamela; |
6 |
using namespace pamela::neutron; |
7 |
|
8 |
|
9 |
/** |
10 |
* Constructor. |
11 |
*/ |
12 |
NeutronDetectorReader::NeutronDetectorReader(void): |
13 |
TechmodelAlgorithm(PacketType::Physics, "TechmodelNeutronDetectorReader") { |
14 |
neutronEvent = new NeutronEvent(); |
15 |
} |
16 |
|
17 |
/** |
18 |
* Get a string with the version info of the algorithm. |
19 |
*/ |
20 |
std::string NeutronDetectorReader::GetVersionInfo(void) const { |
21 |
return |
22 |
"$Header: /afs/ba.infn.it/user/pamela/src/CVS/chewbacca/PamOffLineSW/physics/NeutronDetectorReader.cpp,v 1.1.1.1 2008/09/23 07:20:22 mocchiut Exp $"; |
23 |
} |
24 |
|
25 |
/** |
26 |
* Initialize the algorithm with a special run. This will initialize the |
27 |
* event reader routines for all packet types. |
28 |
* For definition the definition for Neutron detector data is located in the |
29 |
* end of the physics packet. |
30 |
* More explicitely the neutronData is composed by 4 bytes; |
31 |
* a pattern 00 0F TR BK |
32 |
* where: |
33 |
* 00 0f is a fixed pattern |
34 |
* TR is the NeutronCounter for a trigger event |
35 |
* BK is the NeutronCounter beetween two trigger events |
36 |
*/ |
37 |
void NeutronDetectorReader::Init(PamelaRun *run) { |
38 |
run->WriteSubPacket(this, &neutronEvent, neutronEvent->Class()); |
39 |
} |
40 |
|
41 |
/** |
42 |
* Unpack the anticounter event from an input file. |
43 |
*/ |
44 |
void NeutronDetectorReader::RunEvent(int EventNumber) { |
45 |
|
46 |
} |
47 |
|
48 |
/** |
49 |
* Unpack the NeutronDetector data event from the physical packet. |
50 |
*/ |
51 |
void NeutronDetectorReader::RunEvent(int EventNumber, const char subData[], long int length) { |
52 |
NeutronRecord *rec; |
53 |
const int lenNeutronData = 12; |
54 |
//char *data = new char[lenght]; |
55 |
//memcpy(data, subData, lenght); |
56 |
neutronEvent->Records->Clear(); |
57 |
TClonesArray &recs = *(neutronEvent->Records); |
58 |
int offset; |
59 |
if (haveData(&*subData, length)){ |
60 |
for (int i = 0; i < 3; i++){ |
61 |
offset = lenNeutronData - 4*i; |
62 |
rec = new(recs[i]) NeutronRecord(); //aggiungo un nuovo NeutronRecord all'evento |
63 |
rec->trigPhysics = (UINT8)subData[length-offset]; |
64 |
rec->upperBack = (((UINT8)subData[length-offset+1])>>4); |
65 |
rec->bottomBack = (((UINT8)subData[length-offset+1])&0x0F); |
66 |
} |
67 |
neutronEvent->unpackError = 0; |
68 |
} else { |
69 |
neutronEvent->unpackError = 1; |
70 |
//marco: scrivo in log file ... |
71 |
std::stringstream oss; |
72 |
string msg; |
73 |
oss << "NeutronDetector: " << "no data found "; |
74 |
msg=oss.str(); |
75 |
PamOffLineSW::mainLogUtil->logAll(msg); |
76 |
} |
77 |
} |
78 |
|
79 |
|
80 |
bool NeutronDetectorReader::haveData(const char data[], long int length){ |
81 |
bool ret = false; |
82 |
if (((UINT8)data[length - 1] == 0x0F)&&((UINT8)data[length - 5] == 0x0F)&&((UINT8)data[length - 9] == 0x0F)) ret = true; |
83 |
return ret; |
84 |
} |