| 1 |
pamelats |
1.1 |
#include <sstream> |
| 2 |
|
|
#include <fstream> |
| 3 |
|
|
#include <stdlib.h> |
| 4 |
|
|
#include <stdio.h> |
| 5 |
|
|
#include <string.h> |
| 6 |
|
|
#include <ctype.h> |
| 7 |
|
|
#include <time.h> |
| 8 |
|
|
#include "Riostream.h" |
| 9 |
|
|
#include "TFile.h" |
| 10 |
|
|
#include "TDirectory.h" |
| 11 |
|
|
#include "TTree.h" |
| 12 |
|
|
#include "TLeafI.h" |
| 13 |
|
|
#include "TH1.h" |
| 14 |
|
|
#include "TH2.h" |
| 15 |
|
|
#include "TF1.h" |
| 16 |
|
|
#include "TMath.h" |
| 17 |
|
|
#include "TRandom.h" |
| 18 |
|
|
#include "TSQLServer.h" |
| 19 |
|
|
#include "TSystem.h" |
| 20 |
|
|
#include "CalibTrk1Event.h" |
| 21 |
|
|
#include "CalibTrk2Event.h" |
| 22 |
|
|
// |
| 23 |
|
|
#include "Digitizer.h" |
| 24 |
|
|
#include "CRC.h" |
| 25 |
|
|
// |
| 26 |
|
|
#include <PamelaRun.h> |
| 27 |
|
|
#include <physics/calorimeter/CalorimeterEvent.h> |
| 28 |
|
|
#include <CalibCalPedEvent.h> |
| 29 |
|
|
#include "GLTables.h" |
| 30 |
|
|
|
| 31 |
|
|
void Digitizer::DigitizeRunHeader(){ |
| 32 |
|
|
const Int_t lenRH = fRunHeaderbuffer*2; |
| 33 |
|
|
UChar_t buffRH[lenRH]; |
| 34 |
|
|
UShort_t buffPSCU[8]; |
| 35 |
|
|
UChar_t *p; |
| 36 |
|
|
p=buffRH; |
| 37 |
|
|
|
| 38 |
|
|
// header: 16 bytes |
| 39 |
|
|
DigitizePSCU(fRunHeaderbuffer*2,0x20,buffPSCU); |
| 40 |
|
|
memcpy(p,buffPSCU,16*sizeof(UChar_t)); |
| 41 |
|
|
p+=16; |
| 42 |
|
|
|
| 43 |
|
|
// time stamp (uint32): 0x82569c97 |
| 44 |
|
|
*(p++) = 0x82; |
| 45 |
|
|
*(p++) = 0x56; |
| 46 |
|
|
*(p++) = 0x9C; |
| 47 |
|
|
*(p++) = 0x97; |
| 48 |
|
|
|
| 49 |
|
|
// acq_setting_mode (uint8) |
| 50 |
|
|
*(p++) = 2; |
| 51 |
|
|
|
| 52 |
|
|
// obt (uint32) |
| 53 |
|
|
ULong64_t obt = fOBT + 30LL; |
| 54 |
|
|
while ( obt > 4294967295LL ) |
| 55 |
|
|
obt -= 4294967295LL; |
| 56 |
|
|
fOBT = (UInt_t)obt; |
| 57 |
|
|
// |
| 58 |
|
|
*(p++) = (UChar_t)(fOBT >> 24); |
| 59 |
|
|
*(p++) = (UChar_t)(fOBT >> 16); |
| 60 |
|
|
*(p++) = (UChar_t)(fOBT >> 8); |
| 61 |
|
|
*(p++) = (UChar_t)fOBT; |
| 62 |
|
|
|
| 63 |
|
|
// last time_sync_info (uint32) (from file 000_001_00110) |
| 64 |
|
|
*(p++) = 0x00; |
| 65 |
|
|
*(p++) = 0x08; |
| 66 |
|
|
*(p++) = 0x68; |
| 67 |
|
|
*(p++) = 0xEF; |
| 68 |
|
|
|
| 69 |
|
|
// fav. working schedule (uint8) |
| 70 |
|
|
*(p++) = 0; |
| 71 |
|
|
|
| 72 |
|
|
// eff. working schedule (uint8) |
| 73 |
|
|
*(p++) = 0; |
| 74 |
|
|
|
| 75 |
|
|
// trigger_mode_A (uint32) |
| 76 |
|
|
*(p++) = 0; |
| 77 |
|
|
*(p++) = 0; |
| 78 |
|
|
*(p++) = 0; |
| 79 |
|
|
*(p++) = 0x01; |
| 80 |
|
|
|
| 81 |
|
|
// trigger_mode_B (uint32) |
| 82 |
|
|
*(p++) = 0; |
| 83 |
|
|
*(p++) = 0; |
| 84 |
|
|
*(p++) = 0; |
| 85 |
|
|
*(p++) = 0x03; |
| 86 |
|
|
|
| 87 |
|
|
// acq_after_calib (0,1) (uint8) |
| 88 |
|
|
*(p++) = 0; |
| 89 |
|
|
|
| 90 |
|
|
// trk_calib_used (uint32) |
| 91 |
|
|
*(p++) = 0; |
| 92 |
|
|
*(p++) = 0; |
| 93 |
|
|
*(p++) = 0; |
| 94 |
|
|
*(p++) = 0x68; |
| 95 |
|
|
|
| 96 |
|
|
// acq_build_info (4 zero bits + 28 1's) (uint32) |
| 97 |
|
|
*(p++) = 0x3F; |
| 98 |
|
|
*(p++) = 0xFF; |
| 99 |
|
|
*(p++) = 0xFF; |
| 100 |
|
|
*(p++) = 0xFF; |
| 101 |
|
|
|
| 102 |
|
|
// acq_var_info (11 bits) (uint16) |
| 103 |
|
|
*(p++) = 0x23; |
| 104 |
|
|
*(p++) = 0x7F; |
| 105 |
|
|
|
| 106 |
|
|
// cal_dsp_mask (uint8) |
| 107 |
|
|
*(p++) = 0; |
| 108 |
|
|
|
| 109 |
|
|
// crc (uint16) |
| 110 |
|
|
UShort_t crcRH = (UShort_t)CM_Compute_CRC16((UINT16)0, (BYTE*)&buffRH, (UINT32)(fRunHeaderbuffer*2-2)); |
| 111 |
|
|
*(p++) = (UChar_t)(crcRH << 8); |
| 112 |
|
|
*p = (UChar_t)crcRH; |
| 113 |
|
|
|
| 114 |
|
|
memcpy(fDataRunHeader,buffRH,fRunHeaderbuffer*sizeof(UShort_t)); |
| 115 |
|
|
}; |
| 116 |
|
|
|
| 117 |
|
|
void Digitizer::DigitizeRunTrailer(){ |
| 118 |
|
|
UChar_t buffRT[fRunTrailerbuffer*2]; |
| 119 |
|
|
UShort_t buffPSCU[8]; |
| 120 |
|
|
UChar_t *p; |
| 121 |
|
|
p=buffRT; |
| 122 |
|
|
|
| 123 |
|
|
// header: 16 bytes |
| 124 |
|
|
DigitizePSCU(fRunHeaderbuffer*2,0x21,buffPSCU); |
| 125 |
|
|
memcpy(p,buffPSCU,16*sizeof(UChar_t)); |
| 126 |
|
|
p+=16; |
| 127 |
|
|
|
| 128 |
|
|
// pkt_counter (uint32) |
| 129 |
|
|
fCounterPhys++; |
| 130 |
|
|
fCounter++; |
| 131 |
|
|
while ( fCounterPhys > 16777215 ) |
| 132 |
|
|
fCounterPhys -= 16777215; |
| 133 |
|
|
// |
| 134 |
|
|
*(p++) = (UChar_t)(fCounterPhys >> 24); |
| 135 |
|
|
*(p++) = (UChar_t)(fCounterPhys >> 16); |
| 136 |
|
|
*(p++) = (UChar_t)(fCounterPhys >> 8); |
| 137 |
|
|
*(p++) = (UChar_t)fCounterPhys; |
| 138 |
|
|
|
| 139 |
|
|
// pkt_readyCounter: valid packets in the run (uint32) |
| 140 |
|
|
*(p++) = 0; |
| 141 |
|
|
*(p++) = 0; |
| 142 |
|
|
*(p++) = 0; |
| 143 |
|
|
*(p++) = 0; |
| 144 |
|
|
|
| 145 |
|
|
// obt (uint32) |
| 146 |
|
|
ULong64_t obt = fOBT + 30LL; |
| 147 |
|
|
while ( obt > 4294967295LL ) |
| 148 |
|
|
obt -= 4294967295LL; |
| 149 |
|
|
fOBT = (UInt_t)obt; |
| 150 |
|
|
// |
| 151 |
|
|
*(p++) = (UChar_t)(fOBT >> 24); |
| 152 |
|
|
*(p++) = (UChar_t)(fOBT >> 16); |
| 153 |
|
|
*(p++) = (UChar_t)(fOBT >> 8); |
| 154 |
|
|
*(p++) = (UChar_t)fOBT; |
| 155 |
|
|
|
| 156 |
|
|
// last time_sync_info (uint32) |
| 157 |
|
|
*(p++) = 0; |
| 158 |
|
|
*(p++) = 0; |
| 159 |
|
|
*(p++) = 0; |
| 160 |
|
|
*(p++) = 0; |
| 161 |
|
|
|
| 162 |
|
|
// crc (uint16) |
| 163 |
|
|
UShort_t crcRT = (UShort_t)CM_Compute_CRC16((UINT16)0, (BYTE*)(buffRT), (UINT32)(fRunTrailerbuffer*2-2)); |
| 164 |
|
|
*(p++) = (UChar_t)(crcRT << 8); |
| 165 |
|
|
*p = (UChar_t)crcRT; |
| 166 |
|
|
|
| 167 |
|
|
memcpy(fDataRunTrailer,buffRT,fRunTrailerbuffer*sizeof(UShort_t)); |
| 168 |
|
|
}; |
| 169 |
|
|
|
| 170 |
|
|
void Digitizer::AddPadding(){ |
| 171 |
|
|
// |
| 172 |
|
|
Float_t pd0 = (fLen+16)/64.; |
| 173 |
|
|
Float_t pd1 = pd0 - (Float_t)int(pd0); |
| 174 |
|
|
Float_t padfrac = 64. - pd1 * 64.; |
| 175 |
|
|
// |
| 176 |
|
|
UInt_t padbytes = (UInt_t)padfrac; |
| 177 |
|
|
if ( padbytes > 0 && padbytes < 64 ){ |
| 178 |
|
|
// |
| 179 |
|
|
// here the padding length |
| 180 |
|
|
// |
| 181 |
|
|
fPadding = padbytes+64; |
| 182 |
|
|
// |
| 183 |
|
|
// random padding bytes |
| 184 |
|
|
// |
| 185 |
|
|
for (Int_t ur=0; ur<32; ur++){ |
| 186 |
|
|
fDataPadding[ur] = (UShort_t)rand(); |
| 187 |
|
|
}; |
| 188 |
|
|
}; |
| 189 |
|
|
}; |
| 190 |
|
|
|
| 191 |
|
|
|
| 192 |
|
|
void Digitizer::DigitizePSCU(UInt_t length, UChar_t type, UShort_t *pPSCU) { |
| 193 |
|
|
// |
| 194 |
|
|
UChar_t buff[16]; |
| 195 |
|
|
// |
| 196 |
|
|
// CPU signature |
| 197 |
|
|
// |
| 198 |
|
|
buff[0] = 0xFA; |
| 199 |
|
|
buff[1] = 0xFE; |
| 200 |
|
|
buff[2] = 0xDE; |
| 201 |
|
|
// |
| 202 |
|
|
// packet type (twice) |
| 203 |
|
|
// |
| 204 |
|
|
buff[3] = type; |
| 205 |
|
|
buff[4] = type; |
| 206 |
|
|
// |
| 207 |
|
|
// counter |
| 208 |
|
|
// |
| 209 |
|
|
fCounter++; |
| 210 |
|
|
while ( fCounter > 16777215 ){ |
| 211 |
|
|
fCounter -= 16777215; |
| 212 |
|
|
}; |
| 213 |
|
|
// |
| 214 |
|
|
buff[5] = (UChar_t)(fCounter >> 16); |
| 215 |
|
|
buff[6] = (UChar_t)(fCounter >> 8); |
| 216 |
|
|
buff[7] = (UChar_t)fCounter; |
| 217 |
|
|
// |
| 218 |
|
|
// on board time |
| 219 |
|
|
// |
| 220 |
|
|
ULong64_t obt = fOBT + 30LL; |
| 221 |
|
|
// |
| 222 |
|
|
while ( obt > 4294967295LL ){ |
| 223 |
|
|
obt -= 4294967295LL; |
| 224 |
|
|
}; |
| 225 |
|
|
fOBT = (UInt_t)obt; |
| 226 |
|
|
// |
| 227 |
|
|
buff[8] = (UChar_t)(fOBT >> 24); |
| 228 |
|
|
buff[9] = (UChar_t)(fOBT >> 16); |
| 229 |
|
|
buff[10] = (UChar_t)(fOBT >> 8); |
| 230 |
|
|
buff[11] = (UChar_t)fOBT; |
| 231 |
|
|
// |
| 232 |
|
|
// Packet length |
| 233 |
|
|
// |
| 234 |
|
|
fLen = length; |
| 235 |
|
|
// |
| 236 |
|
|
buff[12] = (UChar_t)(fLen >> 16); |
| 237 |
|
|
buff[13] = (UChar_t)(fLen >> 8); |
| 238 |
|
|
buff[14] = (UChar_t)fLen; |
| 239 |
|
|
// |
| 240 |
|
|
// CPU header CRC |
| 241 |
|
|
// |
| 242 |
|
|
buff[15] = (BYTE)CM_Compute_CRC16((UINT16)0, (BYTE*)&buff, (UINT32)15); |
| 243 |
|
|
// |
| 244 |
|
|
//memcpy(fDataPSCU,buff,16*sizeof(UChar_t)); |
| 245 |
|
|
memcpy(pPSCU,buff,16*sizeof(UChar_t)); |
| 246 |
|
|
// |
| 247 |
|
|
}; |