/[PAMELA software]/yoda/techmodel/physics/NeutronDetectorReader.cpp
ViewVC logotype

Diff of /yoda/techmodel/physics/NeutronDetectorReader.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1 by kusanagi, Thu Aug 19 15:24:58 2004 UTC revision 2.3 by kusanagi, Thu Jan 13 14:50:01 2005 UTC
# Line 1  Line 1 
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    
# Line 22  NeutronDetectorReader::NeutronDetectorRe Line 22  NeutronDetectorReader::NeutronDetectorRe
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 2.2 2004/12/09 08:48:54 kusanagi Exp $";
26  }  }
27    
28  /**  /**
# Line 30  std::string NeutronDetectorReader::GetVe Line 30  std::string NeutronDetectorReader::GetVe
30   * event reader routines for all packet types.   * event reader routines for all packet types.
31   */   */
32  void NeutronDetectorReader::Init(PamelaRun *run) {  void NeutronDetectorReader::Init(PamelaRun *run) {
33      logger->debug(_T("Initialize"));
34    SetInputStream(run);    SetInputStream(run);
35    run->WriteSubPacket(this, &neutronEvent, neutronEvent->Class());    run->WriteSubPacket(this, &neutronEvent, neutronEvent->Class());
36  }  }
# Line 45  void NeutronDetectorReader::RunEvent(int Line 46  void NeutronDetectorReader::RunEvent(int
46   * Unpack the NeutronDetector data event from the physical packet.   * Unpack the NeutronDetector data event from the physical packet.
47   */   */
48  void NeutronDetectorReader::RunEvent(int EventNumber, const char subData[], long int lenght) {  void NeutronDetectorReader::RunEvent(int EventNumber, const char subData[], long int lenght) {
49      NeutronRecord *rec;     NeutronRecord *rec;
50      int offset = 0;     const int lenNeutronData = 12;
51      char data[lenght];     char *data = new char[lenght];
52      //the 2 bytes subtracted belong to the final event CRC bytes     memcpy(data, subData, lenght);
     memcpy(data, subData, lenght);  
53     neutronEvent->Records->Clear();     neutronEvent->Records->Clear();
54     TClonesArray &recs = *(neutronEvent->Records);     TClonesArray &recs = *(neutronEvent->Records);
55     offset = 12;     int offset;
56     if (haveData(data, lenght)){     if (haveData(data, lenght)){
57          for (int i = 0; i < 3; i++){          for (int i = 0; i < 3; i++){
58                offset = lenNeutronData - 4*i;
59              rec = new(recs[i]) NeutronRecord(); //aggiungo un nuovo NeutronRecord all'evento              rec = new(recs[i]) NeutronRecord(); //aggiungo un nuovo NeutronRecord all'evento
60              rec->upperTrig   = (((BYTE)data[lenght-offset])>>4);              rec->upperTrig   = (((UINT8)data[lenght-offset])>>4);
61              rec->bottomTrig  = (((BYTE)data[lenght-offset])&0x0F);              rec->bottomTrig  = (((UINT8)data[lenght-offset])&0x0F);
62              rec->upperBack   = (((BYTE)data[lenght-offset+1])>>4);              rec->upperBack   = (((UINT8)data[lenght-offset+1])>>4);
63              rec->bottomBack  = (((BYTE)data[lenght-offset+1])&0x0F);              rec->bottomBack  = (((UINT8)data[lenght-offset+1])&0x0F);
             offset = offset - 4*(i+1);  
64          }          }
65            neutronEvent->unpackError = 0;
66        } else {
67            neutronEvent->unpackError = 1;
68      }      }
69        delete[] data;
70  }  }
71    
72    /* For definition the definition for Neutron detector data is
73     * "The last data bunch in the phyics packet" */
74  bool NeutronDetectorReader::haveData(const char data[], long int lenght){  bool NeutronDetectorReader::haveData(const char data[], long int lenght){
75      bool ret = false;      bool ret = false;
76      if (((data[lenght-1] && data[lenght - 5] && data[lenght - 9]) && 0x0F) &&      if (((data[lenght-1] && data[lenght - 5] && data[lenght - 9]) && 0x0F) &&

Legend:
Removed from v.1.1  
changed lines
  Added in v.2.3

  ViewVC Help
Powered by ViewVC 1.1.23