/[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.4 by kusanagi, Thu Jan 13 14:50:01 2005 UTC revision 4.1 by kusanagi, Wed Mar 16 16:36:23 2005 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.3 2004/12/16 17:33:03 kusanagi Exp $   * $Id: S4Reader.cpp,v 4.0 2005/03/06 04:33:02 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.3 2004/12/16 17:33:03 kusanagi Exp $";      "$Header: /home/cvsmanager/yoda/techmodel/physics/S4Reader.cpp,v 4.0 2005/03/06 04:33:02 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) {
58     //char *data = new char[lenght];     const int lenS4Data = 6;
59     //memcpy(data, subData, lenght);     char *data = new char[length];
60     int offset = length - 18;     int offset;
61     s4->S4_REG_STATUS        = (((UINT8)subData[offset])&0xF0);     int index = haveData(data, length);
62     s4->S4_DATA              = ((((UINT16)subData[offset]<<8)&0x0FFF) + (((UINT16)subData[offset+1])&0x00FF));    
63     s4->S4_CMD_NUM           = (((UINT8)subData[offset+2])&0xFF);     if (index > 0){
64     s4->S4_RESP_LENGHT       = ((((UINT16)subData[offset+3]<<8)&0xFF00) + (((UINT16)subData[offset+4])&0x00FF));          int offset = length - index;
65     s4->S4_OVERALL_CHKCODE   = (((UINT8)subData[offset+5])&0xFF);          s4->S4_REG_STATUS        = (((UINT8)subData[offset])&0xF0);
66     s4->unpackError          = 0;          s4->S4_DATA              = ((((UINT16)subData[offset]<<8)&0x0FFF) + (((UINT16)subData[offset+1])&0x00FF));
67            s4->S4_CMD_NUM           = (((UINT8)subData[offset+2])&0xFF);
68            s4->S4_RESP_LENGHT       = ((((UINT16)subData[offset+3]<<8)&0xFF00) + (((UINT16)subData[offset+4])&0x00FF));
69            s4->S4_OVERALL_CHKCODE   = (((UINT8)subData[offset+5])&0xFF);
70            s4->unpackError          = 0;
71        } else {
72            s4->unpackError = 1;
73        }
74        delete[] data;
75  }  }
76    
77    /*
78     *
79     * @return int
80     * It return the index, starting from the end of data[] parameter, which
81     * is the starting byte of the S4 data.
82     *
83    */
84    /**
85     * Check if S4Data are present.
86     * @param const char data[] - Physics data
87     * @param long int lenght - Lenght of data[]
88     * @return int represent the index from the end of data[]
89     *             from which S4 data starts
90     */
91    int S4Reader::haveData(const char data[], long int length){
92        /* I start 20 bytes from the end because we have three cases:
93         *
94         * 1) S4 (4bytes) + NeutronDetector (12bytes) //END PACKET
95         * 2) S4 (4bytes) //END PACKET
96         * 3) //END PACKET
97         *
98         * so in anycase I expect to find the data into the last 20 bytes
99         * Anyway, it will be a MUST to implements also the check of the CRC
100         * on the S4 data to have a better confidence on the data; the crc algorithm
101         * sholud be the same of the Tracker
102         *
103         */
104            
105        //Check the existence of NeutronDetector data
106        if (((data[length-1] && data[length - 5] && data[length - 9]) && 0x0F) &&
107            ((data[length-2] | data[length - 6] | data[length - 10]) == 0x00)) {
108            //Chech the existance of S4 data before NeutronDetector
109            if ((data[length-14] && 0x03) && (data[length - 15] && 0x00) &&
110                (data[length - 16] && 0xD8)) return 18;
111          //NeutronDetector data does not exists    
112        } else {
113            //Chech the existance of S4 data at the end of the Physics packet
114            if ((data[length-14] && 0x03) && (data[length - 15] && 0x00) &&
115                (data[length - 16] && 0xD8)) return 6;
116        }
117        return 0;
118    }

Legend:
Removed from v.2.4  
changed lines
  Added in v.4.1

  ViewVC Help
Powered by ViewVC 1.1.23