/[PAMELA software]/yoda/techmodel/TmtcReader.cpp
ViewVC logotype

Annotation of /yoda/techmodel/TmtcReader.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 5.1 - (hide annotations) (download)
Sat Feb 4 12:37:45 2006 UTC (18 years, 9 months ago) by kusanagi
Branch: MAIN
Changes since 5.0: +3 -3 lines
Several new features in this release:
a) all the packets are conform to the Mass Memory Format specifications (http://people.roma2.infn.it/~cpu/Mass_Memory_Format.html)
b) unpacking either using the old files structure OR the new one file unpacking.
c) parametrized root files compression factor
d) deleting of the following packet: TofTest, TrkTest, TrkEvent.
e) the Tracker routines now work without the use of temp files.

The point a) allow Yoda to unpack in the root file all the packets generated by the CPU. According to the MassMemoryFormat; that is three possible data are available:

1) almost explicit structure of the packet (like for Log, Tracker, Mcmd, etc....);
2) dummy data collection structure (InitHeader, InitTrailer, CalibHeader, CalibTrailer);
3) just the data of the packet (almost all Alarm and Init procedures). The class regarding this packets have only one parameters, a TArrayC class, which contain the data-block included in the packet (tat is the data below the packet Header).

The point b) has been implemented as a consequence of an agreement about a more compact structure of the unpacked data. Up to now the structure of each unpacked data consisted of a folder, named after the packet type, and three files: xxx.Header.root, xxx.NamePacket.root, xxx.Registry.root.
Starting from this release YODA, by default will unpack the data in a unique root file. The structure of this file will consist of:
- several TTree(s) named after the packet type;
- into each TTree are foreseen three TBranche(s):
    - 'Header'  (the old xxx.Header.root file)
    - 'NameOfThePacket' (the old xxx.Event.root file or the xxx.Event.DETECTOR.root)
    - 'Registry' (the old xxx.Registry.root file)

Anyway is still possible, but deprecated, to unpack using the old structure, passing to the "yoda" command the optional parameter "-multifile"

The point c) has been implemented because is well know that writing time in a TTree is as much fast as much lower is the compression factor for the root file; anyway for a PAMELA dat file, a compression equal to 0 will generate a root file which will be more than two times the original size. To modify the compression parameter just add the optional parameter "-c [0-9]" to the yoda command line.

1 kusanagi 1.1 /** @file
2 kusanagi 1.2 * $Source: /home/cvsmanager/yoda/techmodel/TmtcReader.cpp,v $
3 kusanagi 5.1 * $Id: TmtcReader.cpp,v 5.0 2005/08/29 09:46:13 Maurizio Nagni Exp $
4     * $Author: Maurizio Nagni $
5 kusanagi 1.1 *
6     * Implementation of the TmtcReader class.
7     * ToBeDone:
8     * Control the CRC for the entire data Packet not just for single records
9     */
10    
11     #include <string>
12 kusanagi 1.4 #include <log4cxx/logger.h>
13 kusanagi 1.1 extern "C" {
14     #include <sys/time.h>
15     #include "CRC.h"
16     }
17    
18     #include <fstream>
19     #include "stdio.h"
20     #include "ReaderAlgorithms.h"
21    
22     #include "event/tmtc/TmtcRecord.h"
23    
24     using namespace pamela;
25     using namespace pamela::techmodel;
26    
27 kusanagi 1.4 static log4cxx::LoggerPtr logger = log4cxx::Logger::getLogger(_T("pamela.techmodel.TmtcReader"));
28 kusanagi 1.1
29     /**
30     * Constructor.
31     */
32     TmtcReader::TmtcReader(void):
33     TechmodelAlgorithm(PacketType::Tmtc, "TechmodelTmtcReader") {
34 kusanagi 1.4 logger->debug(_T("Constructor"));
35 kusanagi 1.1 Tmtc = new TmtcEvent();
36     }
37    
38     /**
39     * Get a string with the version info of the algorithm.
40     */
41     std::string TmtcReader::GetVersionInfo(void) const {
42     return
43 kusanagi 5.1 "$Header: /home/cvsmanager/yoda/techmodel/TmtcReader.cpp,v 5.0 2005/08/29 09:46:13 Maurizio Nagni Exp $\n";
44 kusanagi 1.1 }
45    
46     /**
47     * Initialize the algorithm with a special run. This will initialize the
48     * event reader routines for all packet types.
49     */
50     void TmtcReader::Init(PamelaRun *run) {
51     SetInputStream(run);
52     run->WriteSubPacket(this, &Tmtc, Tmtc->Class());
53     }
54    
55     /**
56     * Unpack the Tmtc event from an input file.
57     */
58 kusanagi 2.1 void TmtcReader::RunEvent(int EventNumber, long int length) throw (WrongCRCException){
59 kusanagi 1.1
60     int i, j;
61 kusanagi 1.2 char subData[TMTC_SUB_LENGTH];
62 kusanagi 1.1 char CRCbuff[TMTC_SUBCRC_LENGTH];
63     char eventCRC[TMTC_CRC_LENGTH];
64     int numRecords = (length-TMTC_CRC_LENGTH)/(TMTC_SUB_LENGTH + TMTC_SUBCRC_LENGTH); //subtract the last two bytes because are the final CRC
65     long int start;
66 kusanagi 1.2
67     TmtcRecord* rec;
68 kusanagi 1.1 Tmtc->Records->Clear();
69     TClonesArray &recs = *(Tmtc->Records);
70 kusanagi 1.2
71 kusanagi 1.1 UINT16 partialCRC = 0; //partial CRC updated as mcmd packet is read (to compare with the last two bytes of this event)
72     UINT16 readCRC = 0; //partial CRC updated as mcmd packet is read (to compare with the last two bytes of this event)
73 kusanagi 2.6 for(int i = 0; i < numRecords; i++) {
74 kusanagi 1.1 start = InputFile->tellg();
75 kusanagi 1.2 InputFile->read(subData, sizeof(subData));
76 kusanagi 1.1 InputFile->read(CRCbuff, sizeof(CRCbuff));
77    
78 kusanagi 1.2 partialCRC = CM_Compute_CRC16(partialCRC, (UINT8*)&subData, TMTC_SUB_LENGTH);
79 kusanagi 1.1 partialCRC = CM_Compute_CRC16(partialCRC, (UINT8*)&CRCbuff, TMTC_SUBCRC_LENGTH);
80    
81     //This == CRCBuff is not really parametric take care if have to change the static lengths
82 kusanagi 1.2 if((UINT8)(CM_Compute_CRC16(0, (UINT8*)&subData, TMTC_SUB_LENGTH)) == (UINT8)CRCbuff[0]){
83     rec = new(recs[i]) TmtcRecord(); //add a new TmtcRecord
84 kusanagi 2.4 rec->TM_RECORD_OBT = (((UINT32)subData[0]<<24)&0xFF000000) + (((UINT32)subData[1]<<16)&0x00FF0000) + (((UINT32)subData[2]<<8)&0x0000FF00) + (((UINT32)subData[3])&0x000000FF);
85     rec->TM_DIAG_AND_BILEVEL_ACQ = (((UINT16)subData[4]<<8)&0x0000FF00) + (((UINT16)subData[5])&0x000000FF);
86 kusanagi 4.1
87 kusanagi 4.2 for(int j = 0; j < 16; j++) {
88 kusanagi 4.1 rec->TM_TH_ANA[j] = ((((UINT16)subData[6 + 2*j]<<8)&0xFF00) + (((UINT16)subData[7 + 2*j])&0x00FF)); //20 is the size of TM_DEA_ANA(16) + OBT(4)
89 kusanagi 1.1 }
90    
91 kusanagi 2.6 for(int j = 0; j < 6; j++) {
92 kusanagi 4.4 rec->TM_DEA_ANA[j] = subData[38+j];
93 kusanagi 2.3 }
94    
95 kusanagi 1.1 } else {
96 kusanagi 1.4 stringstream oss;
97 kusanagi 2.1 oss.str("");
98 kusanagi 1.4 oss << "Wrong CRC on Subpacket int TMTC Packet starting at position"
99     << start;
100     logger->warn(oss.str().c_str());
101 kusanagi 1.1 }
102     }
103     InputFile->read(eventCRC, sizeof(eventCRC));
104     readCRC = (((UINT16)(eventCRC[0]<<8))&0xFF00) + (((UINT16)eventCRC[1])&0x00FF);
105 kusanagi 2.1 if(partialCRC != readCRC) throw WrongCRCException(" Wrong Global CRC for TMTC Packet ");
106 kusanagi 1.1 }
107    
108 kusanagi 2.3 /*
109 kusanagi 1.1 float TmtcReader::convert_th(int TH) {
110     float a,q,deltax,deltay;
111     static int chiama_fun=0;
112     float gradi[22],grado=-1;
113     int adc[22]={4095, 4036,2976,2213,1662,1259,983,742,576,450,
114     354, 281,224,179,145, 117 ,95, 77, 64, 52,
115     43, 35};
116     int maxpos=-1,minpos=-1,i;
117    
118     chiama_fun++;
119     for (i=0;i<22;i++)
120     {
121     gradi[i]=-35+(i*5);
122     }
123     if (TH==4095)
124     {
125     grado=-35.;
126     }
127     else
128     {
129    
130     for (i=0;i<22;i++)
131     {
132     if (TH>=adc[i])
133     {
134     minpos=i;
135     maxpos=i-1;
136     break;
137     }
138     }
139     // grado=gradi[maxpos]-1./(adc[maxpos]-adc[minpos])*((float)TH-(float)adc[maxpos]) ;
140    
141     deltax=adc[maxpos]-adc[minpos];
142     deltay=gradi[maxpos]-gradi[minpos];
143     a=deltay/deltax;
144     q=gradi[maxpos]-a*adc[maxpos];
145     grado=a*TH+q;
146     }
147     return (grado);
148     }
149 kusanagi 2.7 */

  ViewVC Help
Powered by ViewVC 1.1.23