| 1 | kusanagi | 1.1 | /** @file | 
| 2 |  |  | * $Source: /home/cvsmanager/yoda/techmodel/physics/AnticounterReader.cpp,v $ | 
| 3 | kusanagi | 6.2 | * $Id: AnticounterReader.cpp,v 6.1 2006/03/08 08:17:06 kusanagi Exp $ | 
| 4 | kusanagi | 6.0 | * $Author: kusanagi $ | 
| 5 | kusanagi | 1.1 | * | 
| 6 |  |  | * Implementation of the AnticounterReader class. | 
| 7 |  |  | */ | 
| 8 |  |  |  | 
| 9 |  |  | #include <string> | 
| 10 | kusanagi | 1.3 | #include <log4cxx/logger.h> | 
| 11 | kusanagi | 1.1 | #include "AnticounterReader.h" | 
| 12 |  |  |  | 
| 13 |  |  | extern "C" { | 
| 14 | kusanagi | 2.1 | #include "../forroutines/anticounter/AC.h" | 
| 15 | kusanagi | 2.5 | extern int ACphysics(int, unsigned char[] , struct physicsstruct*); | 
| 16 | kusanagi | 1.1 | } | 
| 17 |  |  |  | 
| 18 |  |  | using namespace pamela; | 
| 19 |  |  | using namespace pamela::anticounter; | 
| 20 |  |  |  | 
| 21 | kusanagi | 1.3 | static log4cxx::LoggerPtr logger = log4cxx::Logger::getLogger(_T("pamela.techmodel.anticounter.AnticounterReader")); | 
| 22 | kusanagi | 1.1 |  | 
| 23 |  |  | /** | 
| 24 |  |  | * Constructor. | 
| 25 |  |  | */ | 
| 26 |  |  | AnticounterReader::AnticounterReader(void): | 
| 27 |  |  | TechmodelAlgorithm(PacketType::Physics, "TechmodelAnticounterReader") { | 
| 28 | kusanagi | 1.3 | logger->debug(_T("Constructor")); | 
| 29 | kusanagi | 1.1 | anticounter = new AnticounterEvent(); | 
| 30 |  |  | } | 
| 31 |  |  |  | 
| 32 |  |  | /** | 
| 33 |  |  | * Get a string with the version info of the algorithm. | 
| 34 |  |  | */ | 
| 35 |  |  | std::string AnticounterReader::GetVersionInfo(void) const { | 
| 36 |  |  | return | 
| 37 | kusanagi | 6.2 | "$Header: /home/cvsmanager/yoda/techmodel/physics/AnticounterReader.cpp,v 6.1 2006/03/08 08:17:06 kusanagi Exp $"; | 
| 38 | kusanagi | 1.1 | } | 
| 39 |  |  |  | 
| 40 |  |  | /** | 
| 41 |  |  | * Initialize the algorithm with a special run. This will initialize the | 
| 42 |  |  | * event reader routines for all packet types. | 
| 43 |  |  | */ | 
| 44 |  |  | void AnticounterReader::Init(PamelaRun *run) { | 
| 45 | kusanagi | 1.3 | logger->debug(_T("Initialize")); | 
| 46 | kusanagi | 1.1 | SetInputStream(run); | 
| 47 |  |  | run->WriteSubPacket(this, &anticounter, anticounter->Class()); | 
| 48 |  |  | } | 
| 49 |  |  |  | 
| 50 |  |  | /** | 
| 51 |  |  | * Unpack the anticounter event from an input file. | 
| 52 |  |  | */ | 
| 53 |  |  | void AnticounterReader::RunEvent(int EventNumber) { | 
| 54 |  |  |  | 
| 55 |  |  | } | 
| 56 |  |  |  | 
| 57 |  |  | /** | 
| 58 |  |  | * Unpack the Anticounter data event from the physical packet. | 
| 59 |  |  | */ | 
| 60 |  |  | void AnticounterReader::RunEvent(int EventNumber, const char subData[], long int length) { | 
| 61 | kusanagi | 3.1 | std::stringstream oss; | 
| 62 | kusanagi | 1.3 | char *data = new char[length]; | 
| 63 | kusanagi | 1.1 | memcpy(data, subData, length); | 
| 64 | kusanagi | 2.5 | struct physicsstruct output[2] = {0}; | 
| 65 |  |  |  | 
| 66 |  |  |  | 
| 67 | kusanagi | 1.1 |  | 
| 68 |  |  | //Call to the routine that unpack anitocounter events | 
| 69 | kusanagi | 2.5 | //anticounter->ERROR = ACphysics(length, (unsigned char*) data, &(*output)); | 
| 70 | kusanagi | 2.6 | anticounter->unpackError = ACphysics(length, (unsigned char*) data, output); | 
| 71 | kusanagi | 2.2 |  | 
| 72 | kusanagi | 6.2 | oss.str(""); | 
| 73 | kusanagi | 3.1 | switch (anticounter->unpackError){ | 
| 74 | kusanagi | 6.2 | case 0xFF: | 
| 75 |  |  | oss << "Anticounter unpacking: " << "data (physics or calibration) from both cards found"; | 
| 76 |  |  | logger->debug(oss.str().c_str()); | 
| 77 | kusanagi | 3.1 | break; | 
| 78 | kusanagi | 6.2 | case 0xF0: | 
| 79 |  |  | oss << "Anticounter unpacking: " << "only data from main card found"; | 
| 80 |  |  | logger->error(oss.str().c_str()); | 
| 81 | kusanagi | 3.1 | break; | 
| 82 | kusanagi | 6.2 | case 0x0F: | 
| 83 |  |  | oss << "Anticounter unpacking: " << "only data from extra card found"; | 
| 84 |  |  | logger->error(oss.str().c_str()); | 
| 85 | kusanagi | 3.1 | break; | 
| 86 | kusanagi | 6.2 | case 0x00: | 
| 87 |  |  | oss << "Anticounter unpacking: " << "no data found"; | 
| 88 |  |  | logger->error(oss.str().c_str()); | 
| 89 | kusanagi | 3.1 | break; | 
| 90 | kusanagi | 6.2 | oss << "Anticounter unpacking: " << "ANTICOUNTER ERRROR CODE UNIDENTIFIED"; | 
| 91 |  |  | logger->error(oss.str().c_str()); | 
| 92 | kusanagi | 1.2 | } | 
| 93 | kusanagi | 6.2 |  | 
| 94 | kusanagi | 2.2 |  | 
| 95 | kusanagi | 2.4 | for(int i = 0; i<2; i++){ | 
| 96 |  |  | memcpy(anticounter->header[i], output[i].header, sizeof(anticounter->header[i])); | 
| 97 |  |  | anticounter->status[i] = output[i].status; | 
| 98 |  |  | anticounter->hitmap[i] = output[i].hitmap; | 
| 99 |  |  | memcpy(anticounter->regist[i],     output[i].regist,    sizeof(output[i].regist)); | 
| 100 |  |  | memcpy(anticounter->shift[i],      output[i].shift,     sizeof(output[i].shift)); | 
| 101 |  |  | memcpy(anticounter->counters[i],   output[i].counters,  sizeof(output[i].counters)); | 
| 102 |  |  | memcpy(anticounter->coinc[i],      output[i].coinc,     sizeof(output[i].coinc)); | 
| 103 |  |  | anticounter->trigg[i] = output[i].trigg; | 
| 104 |  |  | memcpy(anticounter->clock[i],      output[i].clock,     sizeof(output[i].clock)); | 
| 105 |  |  | memcpy(anticounter->temp[i],       output[i].temp,      sizeof(output[i].temp)); | 
| 106 |  |  | memcpy(anticounter->DAC[i],        output[i].DAC,       sizeof(output[i].DAC)); | 
| 107 | kusanagi | 2.7 | anticounter->CRC[i]         = output[i].CRC; | 
| 108 |  |  | anticounter->CRCcheck[i]    = output[i].CRCcheck; | 
| 109 | kusanagi | 2.4 | } | 
| 110 |  |  |  | 
| 111 | kusanagi | 1.2 | //} | 
| 112 | kusanagi | 3.1 | delete [] data; | 
| 113 | kusanagi | 1.1 | } |