| 1 |
// Implementation of the PhysEndRunReader class. |
| 2 |
//new version... |
| 3 |
extern "C" { |
| 4 |
#include "CRC.h" |
| 5 |
} |
| 6 |
|
| 7 |
#include "ReaderAlgorithms.h" |
| 8 |
|
| 9 |
using namespace pamela::techmodel; |
| 10 |
|
| 11 |
|
| 12 |
/** |
| 13 |
* Constructor. |
| 14 |
*/ |
| 15 |
PhysEndRunReader::PhysEndRunReader(void): |
| 16 |
TechmodelAlgorithm(PacketType::PhysEndRun, "TechmodelPhysEndRunReader") { |
| 17 |
physEndRun = new PhysEndRunEvent(); |
| 18 |
} |
| 19 |
|
| 20 |
/** |
| 21 |
* Initialize the algorithm with a special run. This will initialize the |
| 22 |
* event reader routines for all packet types. |
| 23 |
*/ |
| 24 |
void PhysEndRunReader::Init(PamelaRun *run) { |
| 25 |
run->WriteSubPacket(this, &physEndRun, physEndRun->Class()); |
| 26 |
} |
| 27 |
|
| 28 |
/** |
| 29 |
* Unpack the PhysEndRun event from an input file. |
| 30 |
* void PhysEndRunReader::PKT_RunEvent(char* subData, long int length) throw (WrongCRCException_PKTUsed){ |
| 31 |
* |
| 32 |
*/ |
| 33 |
void PhysEndRunReader::PKT_RunEvent(char* subData, long int length) throw (Exception){ |
| 34 |
std::stringstream oss; |
| 35 |
string msg; |
| 36 |
|
| 37 |
// baco /gpfs/wizard/flight/production/preRawreader/05510005.pam |
| 38 |
if (length<21) |
| 39 |
{ |
| 40 |
oss.str(""); |
| 41 |
oss<<"Wrong Lenght for PhysEndRun Packet: "<<" length = "<< length<<" too small to be real"; |
| 42 |
msg=oss.str(); |
| 43 |
PamOffLineSW::mainLogUtil->logError(msg); |
| 44 |
//the packet is not good and will be discarded |
| 45 |
throw FatalException(" Wrong Lenght for PhysEndRun Packet "); |
| 46 |
} |
| 47 |
|
| 48 |
long int dataLength = length ; // -2 |
| 49 |
long int tbInitPos = dataLength - 19; // 19 is the length of th TB |
| 50 |
|
| 51 |
//--------------- CALO SECTION------------------------------------ |
| 52 |
long int offset = 0; |
| 53 |
int j = 0; |
| 54 |
// physEndRun->CALO_ENDRUN. |
| 55 |
while(offset < tbInitPos){ |
| 56 |
if ( offset >= length ) return; |
| 57 |
physEndRun->CALO_ENDRUN[j].CALO_BOARD_ID_HK = (((UINT8)subData[offset])&0xFF); |
| 58 |
if ( offset+1 >= length ) return; |
| 59 |
physEndRun->CALO_ENDRUN[j].CALO_BOARD_STATUS_HK = ((UINT8)subData[offset+1]); |
| 60 |
// |
| 61 |
if (!(physEndRun->CALO_ENDRUN[j].CALO_BOARD_STATUS_HK & 0x02)) { |
| 62 |
Int_t kk = 0; |
| 63 |
for(int k = 0; k < 11 ; k++){ |
| 64 |
if ( offset+5+kk >= length ) return; |
| 65 |
physEndRun->CALO_ENDRUN[j].CALO_HK0[k] = (((UINT16)(subData[offset+4+kk]<<8))&0xFF00) + (((UINT16)subData[offset+5+kk])&0x00FF); |
| 66 |
if ( offset+27+kk >= length ) return; |
| 67 |
physEndRun->CALO_ENDRUN[j].CALO_HK1[k] = (((UINT16)(subData[offset+26+kk]<<8))&0xFF00) + (((UINT16)subData[offset+27+kk])&0x00FF); |
| 68 |
kk += 2; |
| 69 |
} |
| 70 |
offset = offset + 50; //CALO_BOARD_ID_HK + CALO_BOARD_STATUS_HK + 2*CALO_HKx + CRC (2Bytes) |
| 71 |
} else offset = offset + 4; //CALO_BOARD_ID_HK + CALO_BOARD_STATUS_HK + CRC (2Bytes) |
| 72 |
// |
| 73 |
for(int k = 0; k < 7 ; k++){ |
| 74 |
// |
| 75 |
// in CALO_BOARD_ID_REG and CALO_BOARD_STATUS_REG we save only the last id and status register of the 7 and we don't save the CRC for each register. |
| 76 |
// |
| 77 |
if ( offset >= length ) return; |
| 78 |
physEndRun->CALO_ENDRUN[j].CALO_BOARD_ID_REG[k] = ((UINT8)(subData[offset])&0xFF); |
| 79 |
offset++; |
| 80 |
if ( offset >= length ) return; |
| 81 |
physEndRun->CALO_ENDRUN[j].CALO_BOARD_STATUS_REG[k] = (UINT8)(subData[offset]); |
| 82 |
offset++; |
| 83 |
offset++; |
| 84 |
offset++; |
| 85 |
if ( offset+1 >= length ) return; |
| 86 |
physEndRun->CALO_ENDRUN[j].CALO_REG[k] = (((UINT16)(subData[offset]<<8))&0xFF00) + (((UINT16)subData[offset+1])&0x00FF); |
| 87 |
offset++; |
| 88 |
// CRC |
| 89 |
offset++; |
| 90 |
offset++; |
| 91 |
offset++; |
| 92 |
// |
| 93 |
}; |
| 94 |
// |
| 95 |
j++; |
| 96 |
} |
| 97 |
// |
| 98 |
if ( offset+2 >= length ) return; |
| 99 |
physEndRun->TB_ENDRUN.TB_ALARM_MASK = (((UINT32)(subData[offset]<<16))&0x00FF0000) + (((UINT32)(subData[offset + 1]<<8))&0x0000FF00) + (((UINT32)(subData[offset + 2]))&0x000000FF); |
| 100 |
offset += 3; |
| 101 |
// |
| 102 |
if ( offset+3 >= length ) return; |
| 103 |
physEndRun->TB_ENDRUN.TB_PMT_MASK_S3S2S12 = (((UINT32)(subData[offset]<<24))&0xFF000000) + (((UINT32)(subData[offset + 1]<<16))&0x00FF0000) + (((UINT32)(subData[offset + 2]<<8))&0x0000FF00) + (((UINT32)(subData[offset + 3]))&0x000000FF); |
| 104 |
offset += 4; |
| 105 |
// |
| 106 |
if ( offset+2 >= length ) return; |
| 107 |
physEndRun->TB_ENDRUN.TB_PMT_MASK_S11CRC = (((UINT32)(subData[offset]<<16))&0x00FF0000) + (((UINT32)(subData[offset + 1]<<8))&0x0000FF00) + (((UINT32)(subData[offset + 2]))&0x000000FF); |
| 108 |
offset += 3; |
| 109 |
// |
| 110 |
if ( offset+1 >= length ) return; |
| 111 |
physEndRun->TB_ENDRUN.TB_S4_CAL_MASK = (((UINT16)(subData[offset]<<8))&0xFF00) + (((UINT16)(subData[offset + 1]))&0x00FF); |
| 112 |
offset += 2; |
| 113 |
// |
| 114 |
if ( offset+3 >= length ) return; |
| 115 |
physEndRun->TB_ENDRUN.TB_BUSY_MASK = (((UINT32)(subData[offset]<<24))&0xFF000000) + (((UINT32)(subData[offset + 1]<<16))&0x00FF0000) + (((UINT32)(subData[offset + 2]<<8))&0x0000FF00) + (((UINT32)(subData[offset + 3]))&0x000000FF); |
| 116 |
offset += 4; |
| 117 |
// |
| 118 |
if ( offset+2 >= length ) return; |
| 119 |
physEndRun->TB_ENDRUN.TB_TRIG_CONF = (((UINT32)(subData[offset]<<16))&0x00FF0000) + (((UINT32)(subData[offset + 1]<<8))&0x0000FF00) + (((UINT32)(subData[offset + 2]))&0x000000FF); |
| 120 |
offset += 3; |
| 121 |
// |
| 122 |
// PHYSENDRUN HAS NOT CRC AT THE END!!! |
| 123 |
// |
| 124 |
} |
| 125 |
|
| 126 |
/** |
| 127 |
* Get a string with the version info of the algorithm. |
| 128 |
*/ |
| 129 |
std::string PhysEndRunReader::GetVersionInfo(void) const { |
| 130 |
return |
| 131 |
"$Header: /afs/ba.infn.it/user/pamela/src/CVS/chewbacca/PamOffLineSW/techmodel/PhysEndRunReader.cpp,v 1.4 2008/10/02 14:37:19 mocchiut Exp $\n"; |
| 132 |
} |