#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 2.2 2004/12/09 08:48:54 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; const int lenNeutronData = 12; char *data = new char[lenght]; memcpy(data, subData, lenght); neutronEvent->Records->Clear(); TClonesArray &recs = *(neutronEvent->Records); int offset; if (haveData(data, lenght)){ for (int i = 0; i < 3; i++){ offset = lenNeutronData - 4*i; rec = new(recs[i]) NeutronRecord(); //aggiungo un nuovo NeutronRecord all'evento rec->upperTrig = (((UINT8)data[lenght-offset])>>4); rec->bottomTrig = (((UINT8)data[lenght-offset])&0x0F); rec->upperBack = (((UINT8)data[lenght-offset+1])>>4); rec->bottomBack = (((UINT8)data[lenght-offset+1])&0x0F); } neutronEvent->unpackError = 0; } else { neutronEvent->unpackError = 1; } delete[] data; } /* For definition the definition for Neutron detector data is * "The last data bunch in the phyics packet" */ 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; }