/[PAMELA software]/chewbacca/PamOffLineSW/physics/S4Reader.cpp
ViewVC logotype

Contents of /chewbacca/PamOffLineSW/physics/S4Reader.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (show annotations) (download)
Fri Jul 24 13:53:42 2009 UTC (15 years, 4 months ago) by mocchiut
Branch: MAIN
CVS Tags: v10RED, v9r00, v9r01, HEAD
Changes since 1.1: +5 -5 lines
Runtime error with ROOT 5.24 fixed, many small changes and warnings fixing

1 /** @file
2 * $Source: /afs/ba.infn.it/user/pamela/src/CVS/chewbacca/PamOffLineSW/physics/S4Reader.cpp,v $
3 * $Id: S4Reader.cpp,v 1.1.1.1 2008/09/23 07:20:23 mocchiut Exp $
4 * $Author: mocchiut $
5 *
6 * Implementation of the S4Reader class.
7 */
8
9 #include <string>
10 #include "S4Reader.h"
11
12 using namespace pamela;
13 using namespace pamela::S4;
14
15
16 /**
17 * Constructor.
18 */
19 S4Reader::S4Reader(void):
20 TechmodelAlgorithm(PacketType::Physics, "TechmodelS4Reader") {
21 s4 = new S4Event();
22 }
23
24 /**
25 * Get a string with the version info of the algorithm.
26 */
27 std::string S4Reader::GetVersionInfo(void) const {
28 return
29 "$Header: /afs/ba.infn.it/user/pamela/src/CVS/chewbacca/PamOffLineSW/physics/S4Reader.cpp,v 1.1.1.1 2008/09/23 07:20:23 mocchiut Exp $";
30 }
31
32 /**
33 * Initialize the algorithm with a special run. This will initialize the
34 * event reader routines for all packet types.
35 */
36 void S4Reader::Init(PamelaRun *run) {
37 run->WriteSubPacket(this, &s4, s4->Class());
38 }
39
40 /**
41 * Unpack the S4 event from an input file.
42 */
43 void S4Reader::RunEvent(int EventNumber) {
44
45 }
46
47 /**
48 * Unpack the S4 data event from the physical packet.
49 * Unfortunately the only definition available for S4 is "Rigth before the Neutron detector data"
50 * consequently supposing the Neutron data (12 Bytes) always present S4 start 18 Bytes before the end of the packet
51 */
52 void S4Reader::RunEvent(int EventNumber, const char subData[], long int length) {
53 // int offset;
54 int index = haveData(&*subData, length);
55
56 if (index > 0){
57 int offset = length - index;
58 s4->S4_REG_STATUS = (((UINT8)subData[offset])&0xF0);
59 s4->S4_DATA = ((((UINT16)subData[offset]<<8)&0x0FFF) + (((UINT16)subData[offset+1])&0x00FF));
60 s4->S4_CMD_NUM = (((UINT8)subData[offset+2])&0xFF);
61 s4->S4_RESP_LENGHT = ((((UINT16)subData[offset+3]<<8)&0xFF00) + (((UINT16)subData[offset+4])&0x00FF));
62 s4->S4_OVERALL_CHKCODE = (((UINT8)subData[offset+5])&0xFF);
63 s4->unpackError = 0;
64 } else {
65 s4->unpackError = 1;
66 //marco: scrivo in log file ...
67 std::stringstream oss;
68 string msg;
69 oss << "S4: " << "no data found ";
70 msg=oss.str();
71 PamOffLineSW::mainLogUtil->logAll(msg);
72 }
73 }
74
75 /*
76 *
77 * @return int
78 * It return the index, starting from the end of data[] parameter, which
79 * is the starting byte of the S4 data.
80 *
81 */
82 /**
83 * Check if S4Data are present.
84 * @param const char data[] - Physics data
85 * @param long int lenght - Lenght of data[]
86 * @return int represent the index from the end of data[]
87 * from which S4 data starts
88 */
89 int S4Reader::haveData(const char data[], long int length){
90 int ret = 0;
91 /* I start 20 bytes from the end because we have three cases:
92 *
93 * 1) S4 (4bytes) + NeutronDetector (12bytes) //END PACKET
94 * 2) S4 (4bytes) //END PACKET
95 * 3) //END PACKET
96 *
97 * so in anycase I expect to find the data into the last 20 bytes
98 * Anyway, it will be a MUST to implements also the check of the CRC
99 * on the S4 data to have a better confidence on the data; the crc algorithm
100 * sholud be the same of the Tracker
101 *
102 */
103
104 //Check the existence of NeutronDetector data
105 if (((UINT8)data[length - 1] == 0x0F)&&((UINT8)data[length - 5] == 0x0F)&&((UINT8)data[length - 9] == 0x0F)) {
106 //Chech the existance of S4 data before NeutronDetector
107 if (((UINT8)data[length - 14] == 0x03) &&
108 ((UINT8)data[length - 15] == 0x00) &&
109 ((UINT8)data[length - 16] == 0xD8)) ret = 18;
110 //NeutronDetector data does not exists
111 } else {
112 //Chech the existance of S4 data at the end of the Physics packet
113 if ( ((UINT8)data[length - 2] == 0x03) &&
114 ((UINT8)data[length - 3] == 0x00) &&
115 ((UINT8)data[length - 4] == 0xD8)) ret = 6;
116 }
117 return ret;
118 }

  ViewVC Help
Powered by ViewVC 1.1.23