#include #include #include "NeutronDetectorReader.h" using namespace pamela; using namespace pamela::neutron; static log4cxx::LoggerPtr logger = log4cxx::Logger::getLogger(_T("pamela.techmodel.neutron.NeutronDetectorReader")); /** * Constructor. */ NeutronDetectorReader::NeutronDetectorReader(void): TechmodelAlgorithm(PacketType::Physics, "TechmodelNeutronDetectorReader") { logger->debug(_T("Constructor")); neutronEvent = new NeutronEvent(); } /** * Get a string with the version info of the algorithm. */ std::string NeutronDetectorReader::GetVersionInfo(void) const { return "$Header: /home/cvsmanager/yoda/techmodel/physics/NeutronDetectorReader.cpp,v 1.1 2004/08/19 15:24:58 kusanagi Exp $"; } /** * Initialize the algorithm with a special run. This will initialize the * event reader routines for all packet types. */ void NeutronDetectorReader::Init(PamelaRun *run) { logger->debug(_T("Initialize")); SetInputStream(run); run->WriteSubPacket(this, &neutronEvent, neutronEvent->Class()); } /** * Unpack the anticounter event from an input file. */ void NeutronDetectorReader::RunEvent(int EventNumber) { } /** * Unpack the NeutronDetector data event from the physical packet. */ void NeutronDetectorReader::RunEvent(int EventNumber, const char subData[], long int lenght) { NeutronRecord *rec; int offset = 0; char *data = new char[lenght]; //the 2 bytes subtracted belong to the final event CRC bytes memcpy(data, subData, lenght); neutronEvent->Records->Clear(); TClonesArray &recs = *(neutronEvent->Records); offset = 12; if (haveData(data, lenght)){ for (int i = 0; i < 3; i++){ rec = new(recs[i]) NeutronRecord(); //aggiungo un nuovo NeutronRecord all'evento rec->upperTrig = (((BYTE)data[lenght-offset])>>4); rec->bottomTrig = (((BYTE)data[lenght-offset])&0x0F); rec->upperBack = (((BYTE)data[lenght-offset+1])>>4); rec->bottomBack = (((BYTE)data[lenght-offset+1])&0x0F); offset = offset - 4*(i+1); } } delete[] data; } bool NeutronDetectorReader::haveData(const char data[], long int lenght){ bool ret = false; if (((data[lenght-1] && data[lenght - 5] && data[lenght - 9]) && 0x0F) && ((data[lenght-2] | data[lenght - 6] | data[lenght - 10]) == 0x00)) ret = true; return ret; }