/[PAMELA software]/PamVMC_update/include/PamVMCRawMgr.h
ViewVC logotype

Contents of /PamVMC_update/include/PamVMCRawMgr.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1.1.1 - (show annotations) (download) (vendor branch)
Tue Oct 15 15:52:29 2013 UTC (11 years, 1 month ago) by formato
Branch: MAIN, rel
CVS Tags: reltag, HEAD
Changes since 1.1: +0 -0 lines
File MIME type: text/plain
Error occurred while calculating annotation data.
PamVMC update

1 #ifndef PAMVMCRAWMGR_H
2 #define PAMVMCRAWMGR_H
3 #include "CRC.h"
4 #include <iostream>
5 #include <fstream>
6 #include <vector>
7 #include <stdlib.h>
8 #include <TObject.h>
9 #include <TRandom.h>
10 #include "TString.h"
11
12 using namespace std;
13
14 typedef vector<char> PamVMCBuffer;
15 typedef vector<UChar_t> UCBuffer;
16 typedef vector<UShort_t> USBuffer;
17
18 class PamVMCRawMgr: public TObject {
19
20 private:
21
22 static PamVMCRawMgr * frm;
23
24 UInt_t fCounter;
25 UInt_t fCounterPhys;
26 UInt_t fOBT;
27
28 const char* fFilename;
29 std::ofstream fFile;
30
31
32 UInt_t fLen;
33
34 UCBuffer fEvtDataPSCU; //event
35 UCBuffer fEvtDataPadding;
36 UInt_t fEvtPadding;
37
38 //++++++++++//
39 // BUFFER //
40 //++++++++++//
41
42 PamVMCBuffer* fbuffer;
43
44 protected:
45 PamVMCRawMgr() {
46 fCounter=fCounterPhys=fOBT=0;
47 fbuffer = new PamVMCBuffer(0);
48 };
49
50 public:
51
52 ~PamVMCRawMgr(){
53
54 delete fbuffer;
55 delete fFilename;
56
57 }
58
59 static PamVMCRawMgr * Instance();
60
61 void CreateOutFile(const char* fname){
62 fFilename = fname;
63 cout<<"OUTPUT RAWFILE: "<<fFilename<<endl;
64 fFile.open(fFilename,ios::out | ios::binary);
65 }
66
67 UInt_t GetCounter(){ return fCounter; }
68
69 void AddCounter(){ fCounter++; }
70
71 void SetCounter(UInt_t count){ fCounter = count; }
72
73 void AddCounterPhys(){ fCounterPhys++; }
74
75 UInt_t GetCounterPhys(){ return fCounterPhys; }
76
77 void SetCounterPhys(UInt_t phcount){ fCounterPhys = phcount; }
78
79 UInt_t GetOBT(){ return fOBT; }
80
81 void SetOBT(UInt_t obt){ fOBT = obt; }
82
83 UInt_t GetLen(){ return fLen; }
84
85 void SetLen(UInt_t len){ fLen = len; }
86
87 void WritePSCU(const UCBuffer* b){ CopyUCharToBuff(b); }
88
89 void WritePadding(const UCBuffer* b){ CopyUCharToBuff(b); }
90
91 void WriteEvent(){
92 fEvtPadding = 0;
93 //fLen=fbuffer->size();
94 //AddPadding(fEvtPadding,&fEvtDataPadding);
95 UInt_t length = fbuffer->size()+fEvtPadding; // DATA+Padding size;
96 DigitizePSCU(length, 0x10, &fEvtDataPSCU);
97
98 //cout<<"PADDING "<<fEvtPadding<<" bytes"<<endl;
99 UCBuffer::const_iterator p = fEvtDataPSCU.begin();
100 while( p!=fEvtDataPSCU.end() )
101 {
102 char t = char(*p);
103 fFile.write(&t,sizeof(char));
104 p++;
105 }
106 fEvtDataPSCU.clear();
107
108 WriteToFile(); //WRITE BUFFER CONTENT TO FILE
109
110 if(fEvtPadding){
111 UCBuffer::const_iterator p = fEvtDataPadding.begin();
112 while( p!=fEvtDataPadding.end() )
113 {
114 char t = char(*p);
115 fFile.write(&t,sizeof(char));
116 p++;
117 }
118 fEvtDataPadding.clear();
119 }
120 }
121
122 void WriteToFile(){
123 #ifdef DIG_DEBUG
124 cout<<"BUFFER SIZE: "<<fbuffer->size()<<endl;
125 #endif
126 PamVMCBuffer::const_iterator p = fbuffer->begin();
127 while( p!=fbuffer->end() )
128 {
129 fFile.write(&(*p),sizeof(char));
130 p++;
131 }
132 fbuffer->clear(); //cleaning MAIN buffer
133 }
134
135 void FinishRun(){
136 WriteToFile();
137 Int_t end = EOF;
138 char t = char(end);
139 fFile.write(&t, sizeof(char));
140 fFile.close();
141 }
142
143 void CopyUCharToBuff (const UCBuffer * b){
144 UCBuffer::const_iterator p = b->begin();
145 #ifdef DIG_DEBUG
146 cout<<"size of UChar DATA:"<<b->size()<<endl;
147 #endif
148 while( p!=b->end() )
149 {
150 //cout<<Int_t(*p)<<endl;
151 fbuffer->push_back(char(*p));
152 p++;
153 }
154 }
155
156
157 void CopyUShortToBuff (const USBuffer * b){
158 USBuffer::const_iterator p = b->begin();
159 #ifdef DIG_DEBUG
160 cout<<"size of UShort DATA:"<<b->size()<<endl;
161 #endif
162 UShort_t Data;
163 UChar_t tmp[2];
164 while( p!=b->end() )
165 {
166 Data=(*p);
167 memcpy(tmp,&Data,sizeof(UShort_t));
168 //cout<<Int_t(*p)<<" "<<hex<<tmp[1]<<" "<<hex<<tmp[0]<<endl;
169 fbuffer->push_back(char(tmp[1]));
170 fbuffer->push_back(char(tmp[0]));
171 p++;
172 }
173 }
174
175
176 void AddPadding(UInt_t & pad, UCBuffer * b){
177
178 Float_t pd0 = (fLen+16)/32.;
179 Float_t pd1 = pd0 - (Float_t)Int_t(pd0);
180 Float_t padfrac = 32. - pd1 * 32.;
181
182 UInt_t padbytes = (UInt_t)padfrac;
183 b->clear();
184 if ( padbytes > 0 && padbytes < 32 ){
185 //
186 // here the padding length
187 //
188 pad = padbytes+32;
189 //
190 // random padding bytes
191 //
192 UShort_t Data;
193 UChar_t tmp[2];
194 for (Int_t ur=0; ur<16; ur++){
195 Data=(UShort_t)gRandom->Uniform(0.,RAND_MAX);
196 memcpy(tmp,&Data,sizeof(UShort_t));
197 //cout<<"DATA"<<hex<<Data<<endl;
198 //tmp[1] should be first (swapping bytes)
199 //b->push_back(tmp[1]);
200 //b->push_back(tmp[0]);
201 };
202 };
203
204 }
205
206
207 void DigitizePSCU(UInt_t length, UChar_t type, UCBuffer * b){
208 //
209 UChar_t buff[16];
210 //
211 // CPU signature
212 //
213 buff[0] = 0xFA;
214 buff[1] = 0xFE;
215 buff[2] = 0xDE;
216 //
217 // packet type (twice)
218 //
219 buff[3] = type;
220 buff[4] = type;
221 //
222 // counter
223 //
224 fCounter++;
225 while ( fCounter > 16777215 ){
226 fCounter-=16777215;
227 };
228 //
229 buff[5] = (UChar_t)(fCounter >> 16);
230 buff[6] = (UChar_t)(fCounter >> 8);
231 buff[7] = (UChar_t)fCounter;
232 //
233 // on board time
234 //
235 ULong64_t obt = fOBT + 30LL;
236 //
237 while ( obt > 4294967295LL ){
238 obt -= 4294967295LL;
239 };
240 fOBT = UInt_t(obt);
241 //
242 buff[8] = (UChar_t)(fOBT >> 24);
243 buff[9] = (UChar_t)(fOBT >> 16);
244 buff[10] = (UChar_t)(fOBT >> 8);
245 buff[11] = (UChar_t)fOBT;
246 //
247 // Packet length
248 //
249 fLen = length;
250 //
251 buff[12] = (UChar_t)(fLen >> 16);
252 buff[13] = (UChar_t)(fLen >> 8) ;
253 buff[14] = (UChar_t)fLen;
254 //
255 // CPU header CRC
256 //
257 buff[15] = (BYTE)CM_Compute_CRC16((UINT16)0, (BYTE*)&buff, (UINT32)15);
258
259 #ifdef DIG_DEBUG
260 cout<<"Digitizer::DigitizePSCU... OK " <<endl;
261 #endif
262 b->clear();
263
264 for (Int_t i=0; i<16; i++) b->push_back(buff[i]);
265 }
266
267
268 void PrintBinaryUns(unsigned char val){
269 for(Int_t i =7; i>=0; i--){
270 if(val & (1<<i))
271 cout<<"1";
272 else
273 cout<<"0";
274 };
275 cout<<endl;
276 }
277
278
279 };
280 #endif

  ViewVC Help
Powered by ViewVC 1.1.23