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

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

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

revision 2.5 by kusanagi, Fri Feb 11 16:40:19 2005 UTC revision 6.1 by kusanagi, Wed Aug 16 08:20:30 2006 UTC
# Line 1  Line 1 
1  /** @file  /** @file
2   * $Source: /home/cvsmanager/yoda/techmodel/physics/S4Reader.cpp,v $   * $Source: /home/cvsmanager/yoda/techmodel/physics/S4Reader.cpp,v $
3   * $Id: S4Reader.cpp,v 2.4 2005/01/13 14:50:01 kusanagi Exp $   * $Id: S4Reader.cpp,v 6.0 2006/02/07 17:11:11 kusanagi Exp $
4   * $Author: kusanagi $   * $Author: kusanagi $
5   *   *
6   * Implementation of the S4Reader class.   * Implementation of the S4Reader class.
# Line 29  S4Reader::S4Reader(void): Line 29  S4Reader::S4Reader(void):
29   */   */
30  std::string S4Reader::GetVersionInfo(void) const {  std::string S4Reader::GetVersionInfo(void) const {
31    return    return
32      "$Header: /home/cvsmanager/yoda/techmodel/physics/S4Reader.cpp,v 2.4 2005/01/13 14:50:01 kusanagi Exp $";      "$Header: /home/cvsmanager/yoda/techmodel/physics/S4Reader.cpp,v 6.0 2006/02/07 17:11:11 kusanagi Exp $";
33  }  }
34    
35  /**  /**
# Line 55  void S4Reader::RunEvent(int EventNumber) Line 55  void S4Reader::RunEvent(int EventNumber)
55   * consequently supposing the Neutron data (12 Bytes) always present S4 start 18 Bytes before the end of the packet   * consequently supposing the Neutron data (12 Bytes) always present S4 start 18 Bytes before the end of the packet
56   */   */
57  void S4Reader::RunEvent(int EventNumber, const char subData[], long int length) {  void S4Reader::RunEvent(int EventNumber, const char subData[], long int length) {
    const int lenS4Data = 6;  
    char *data = new char[length];  
58     int offset;     int offset;
59     int index = haveData(data, length);     int index = haveData(&*subData, length);
60        
61     if (index > -1){     if (index > 0){
62          int offset = length - index;          int offset = length - index;
63          s4->S4_REG_STATUS        = (((UINT8)subData[offset])&0xF0);          s4->S4_REG_STATUS        = (((UINT8)subData[offset])&0xF0);
64          s4->S4_DATA              = ((((UINT16)subData[offset]<<8)&0x0FFF) + (((UINT16)subData[offset+1])&0x00FF));          s4->S4_DATA              = ((((UINT16)subData[offset]<<8)&0x0FFF) + (((UINT16)subData[offset+1])&0x00FF));
# Line 71  void S4Reader::RunEvent(int EventNumber, Line 69  void S4Reader::RunEvent(int EventNumber,
69      } else {      } else {
70          s4->unpackError = 1;          s4->unpackError = 1;
71      }      }
     delete[] data;  
72  }  }
73    
74  /*  /*
# Line 85  void S4Reader::RunEvent(int EventNumber, Line 82  void S4Reader::RunEvent(int EventNumber,
82   * Check if S4Data are present.   * Check if S4Data are present.
83   * @param const char data[] - Physics data   * @param const char data[] - Physics data
84   * @param long int lenght - Lenght of data[]   * @param long int lenght - Lenght of data[]
85   * @return int - -1 if S4 has not been found, otherwise it represent the   * @return int represent the index from the end of data[]
86   *               index from the end of data[] from which S4 data starts   *             from which S4 data starts
87   */   */
88  int S4Reader::haveData(const char data[], long int length){  int S4Reader::haveData(const char data[], long int length){
89      int ret = -1;      int ret = 0;
90      /* I start 20 bytes from the end because we have three cases:      /* I start 20 bytes from the end because we have three cases:
91       *       *
92       * 1) S4 (4bytes) + NeutronDetector (12bytes) //END PACKET       * 1) S4 (4bytes) + NeutronDetector (12bytes) //END PACKET
# Line 102  int S4Reader::haveData(const char data[] Line 99  int S4Reader::haveData(const char data[]
99       * sholud be the same of the Tracker       * sholud be the same of the Tracker
100       *       *
101       */       */
102      int  index = 0;          
103      char dataByte;      //Check the existence of NeutronDetector data
104      int subIndex = 0;      if (((UINT8)data[length - 1] == 0x0F)&&((UINT8)data[length - 5] == 0x0F)&&((UINT8)data[length - 9] == 0x0F)) {
105      const int subDataDepth = 20;          //Chech the existance of S4 data before NeutronDetector
106      int offset = length - subDataDepth;          if (((UINT8)data[length - 14] == 0x03) &&
107      const int subSignDim = 3;              ((UINT8)data[length - 15] == 0x00) &&
108      const unsigned char subSign[subSignDim]={0xD8, 0x00, 0x03};              ((UINT8)data[length - 16] == 0xD8)) ret = 18;
109      while (index < subDataDepth){        //NeutronDetector data does not exists    
110          dataByte = data[offset + index++];      } else {
111          if (dataByte == (char)(*(subSign+subIndex))){          //Chech the existance of S4 data at the end of the Physics packet
112              if (subIndex++ == (subSignDim-1)) {          if ( ((UINT8)data[length - 2] == 0x03) &&
113                  //If here i catch it!!!               ((UINT8)data[length - 3] == 0x00) &&
114                  return subDataDepth - index + subSignDim + 2;               ((UINT8)data[length - 4] == 0xD8)) ret = 6;
115              }      }
         } else {  
             index = index - (subIndex);  
             subIndex = 0;  
         }  
     }  
116      return ret;      return ret;
117  }  }

Legend:
Removed from v.2.5  
changed lines
  Added in v.6.1

  ViewVC Help
Powered by ViewVC 1.1.23