1 |
|
|
2 |
#include <string> |
#include <string> |
3 |
#include <log4cpp/Category.hh> |
#include <log4cxx/logger.h> |
4 |
#include "NeutronDetectorReader.h" |
#include "NeutronDetectorReader.h" |
5 |
|
|
6 |
using namespace pamela; |
using namespace pamela; |
7 |
using namespace pamela::neutron; |
using namespace pamela::neutron; |
8 |
|
|
9 |
static log4cpp::Category& cat = log4cpp::Category::getInstance("pamela.techmodel.neutron.NeutronDetectorReader"); |
static log4cxx::LoggerPtr logger = log4cxx::Logger::getLogger(_T("pamela.techmodel.neutron.NeutronDetectorReader")); |
10 |
|
|
11 |
/** |
/** |
12 |
* Constructor. |
* Constructor. |
13 |
*/ |
*/ |
14 |
NeutronDetectorReader::NeutronDetectorReader(void): |
NeutronDetectorReader::NeutronDetectorReader(void): |
15 |
TechmodelAlgorithm(PacketType::Physics, "TechmodelNeutronDetectorReader") { |
TechmodelAlgorithm(PacketType::Physics, "TechmodelNeutronDetectorReader") { |
16 |
cat.debug("Constructor"); |
logger->debug(_T("Constructor")); |
17 |
neutronEvent = new NeutronEvent(); |
neutronEvent = new NeutronEvent(); |
18 |
} |
} |
19 |
|
|
22 |
*/ |
*/ |
23 |
std::string NeutronDetectorReader::GetVersionInfo(void) const { |
std::string NeutronDetectorReader::GetVersionInfo(void) const { |
24 |
return |
return |
25 |
"$Header: /home/cvsmanager/yoda/techmodel/physics/NeutronDetectorReader.cpp,v 1.1 2004/07/20 13:27:07 kusanagi Exp $"; |
"$Header: /home/cvsmanager/yoda/techmodel/physics/NeutronDetectorReader.cpp,v 6.0 2006/02/07 17:11:11 kusanagi Exp $"; |
26 |
} |
} |
27 |
|
|
28 |
/** |
/** |
29 |
* Initialize the algorithm with a special run. This will initialize the |
* Initialize the algorithm with a special run. This will initialize the |
30 |
* event reader routines for all packet types. |
* event reader routines for all packet types. |
31 |
|
* For definition the definition for Neutron detector data is located in the |
32 |
|
* end of the physics packet. |
33 |
|
* More explicitely the neutronData is composed by 4 bytes; |
34 |
|
* a pattern 00 0F TR BK |
35 |
|
* where: |
36 |
|
* 00 0f is a fixed pattern |
37 |
|
* TR is the NeutronCounter for a trigger event |
38 |
|
* BK is the NeutronCounter beetween two trigger events |
39 |
*/ |
*/ |
40 |
void NeutronDetectorReader::Init(PamelaRun *run) { |
void NeutronDetectorReader::Init(PamelaRun *run) { |
41 |
|
logger->debug(_T("Initialize")); |
42 |
SetInputStream(run); |
SetInputStream(run); |
43 |
run->WriteSubPacket(this, &neutronEvent, neutronEvent->Class()); |
run->WriteSubPacket(this, &neutronEvent, neutronEvent->Class()); |
44 |
} |
} |
53 |
/** |
/** |
54 |
* Unpack the NeutronDetector data event from the physical packet. |
* Unpack the NeutronDetector data event from the physical packet. |
55 |
*/ |
*/ |
56 |
void NeutronDetectorReader::RunEvent(int EventNumber, const char subData[], long int lenght) { |
void NeutronDetectorReader::RunEvent(int EventNumber, const char subData[], long int length) { |
57 |
NeutronRecord *rec; |
NeutronRecord *rec; |
58 |
int offset = 0; |
const int lenNeutronData = 12; |
59 |
char data[lenght]; |
//char *data = new char[lenght]; |
60 |
//the 2 bytes subtracted belong to the final event CRC bytes |
//memcpy(data, subData, lenght); |
|
memcpy(data, subData, lenght); |
|
61 |
neutronEvent->Records->Clear(); |
neutronEvent->Records->Clear(); |
62 |
TClonesArray &recs = *(neutronEvent->Records); |
TClonesArray &recs = *(neutronEvent->Records); |
63 |
offset = 12; |
int offset; |
64 |
if (haveData(data, lenght)){ |
if (haveData(&*subData, length)){ |
65 |
for (int i = 0; i < 3; i++){ |
for (int i = 0; i < 3; i++){ |
66 |
|
offset = lenNeutronData - 4*i; |
67 |
rec = new(recs[i]) NeutronRecord(); //aggiungo un nuovo NeutronRecord all'evento |
rec = new(recs[i]) NeutronRecord(); //aggiungo un nuovo NeutronRecord all'evento |
68 |
rec->upperTrig = (((BYTE)data[lenght-offset])>>4); |
rec->trigPhysics = (UINT8)subData[length-offset]; |
69 |
rec->bottomTrig = (((BYTE)data[lenght-offset])&0x0F); |
rec->upperBack = (((UINT8)subData[length-offset+1])>>4); |
70 |
rec->upperBack = (((BYTE)data[lenght-offset+1])>>4); |
rec->bottomBack = (((UINT8)subData[length-offset+1])&0x0F); |
|
rec->bottomBack = (((BYTE)data[lenght-offset+1])&0x0F); |
|
|
offset = offset - 4*(i+1); |
|
71 |
} |
} |
72 |
|
neutronEvent->unpackError = 0; |
73 |
|
} else { |
74 |
|
neutronEvent->unpackError = 1; |
75 |
} |
} |
76 |
} |
} |
77 |
|
|
78 |
bool NeutronDetectorReader::haveData(const char data[], long int lenght){ |
|
79 |
|
bool NeutronDetectorReader::haveData(const char data[], long int length){ |
80 |
bool ret = false; |
bool ret = false; |
81 |
if (((data[lenght-1] && data[lenght - 5] && data[lenght - 9]) && 0x0F) && |
if (((UINT8)data[length - 1] == 0x0F)&&((UINT8)data[length - 5] == 0x0F)&&((UINT8)data[length - 9] == 0x0F)) ret = true; |
|
((data[lenght-2] | data[lenght - 6] | data[lenght - 10]) == 0x00)) ret = true; |
|
82 |
return ret; |
return ret; |
83 |
} |
} |