| 1 |
/** @file |
| 2 |
* $Source: /afs/ba.infn.it/user/pamela/src/CVS/yoda/techmodel/physics/TofReader.cpp,v $ |
| 3 |
* $Id: TofReader.cpp,v 6.3 2006/09/12 08:56:30 mocchiut Exp $ |
| 4 |
* $Author: mocchiut $ |
| 5 |
* |
| 6 |
* Implementation of the CalorimeterReader class. |
| 7 |
*/ |
| 8 |
|
| 9 |
|
| 10 |
#include <iostream> |
| 11 |
#include <string> |
| 12 |
#include <log4cxx/logger.h> |
| 13 |
#include "TofReader.h" |
| 14 |
|
| 15 |
extern "C" { |
| 16 |
|
| 17 |
|
| 18 |
extern struct { |
| 19 |
int tdcid[12]; |
| 20 |
int evcount[12]; |
| 21 |
int tdcmask[12]; |
| 22 |
int adc[4][12]; |
| 23 |
int tdc[4][12]; |
| 24 |
int temp1[12]; |
| 25 |
int temp2[12]; |
| 26 |
|
| 27 |
} tofvar_; |
| 28 |
|
| 29 |
void tofunpack_(unsigned char[], long int*, int*); |
| 30 |
|
| 31 |
//Struct per il passaggio di dati da e verso la chiamata fortran |
| 32 |
} |
| 33 |
|
| 34 |
using namespace pamela; |
| 35 |
using namespace pamela::tof; |
| 36 |
|
| 37 |
static log4cxx::LoggerPtr logger = log4cxx::Logger::getLogger(_T("pamela.techmodel.tof.TofReader")); |
| 38 |
|
| 39 |
/** |
| 40 |
* Constructor. |
| 41 |
*/ |
| 42 |
TofReader::TofReader(void): |
| 43 |
TechmodelAlgorithm(PacketType::Physics, "TechmodelTofReader") { |
| 44 |
logger->debug(_T("Construnctor")); |
| 45 |
tof = new TofEvent(); |
| 46 |
} |
| 47 |
|
| 48 |
/** |
| 49 |
* Get a string with the version info of the algorithm. |
| 50 |
*/ |
| 51 |
std::string TofReader::GetVersionInfo(void) const { |
| 52 |
return |
| 53 |
"$Header: /afs/ba.infn.it/user/pamela/src/CVS/yoda/techmodel/physics/TofReader.cpp,v 6.3 2006/09/12 08:56:30 mocchiut Exp $"; |
| 54 |
} |
| 55 |
|
| 56 |
/** |
| 57 |
* Initialize the algorithm with a special run. This will initialize the |
| 58 |
* event reader routines for all packet types. |
| 59 |
*/ |
| 60 |
void TofReader::Init(PamelaRun *run) { |
| 61 |
logger->debug(_T("Initialize")); |
| 62 |
SetInputStream(run); |
| 63 |
run->WriteSubPacket(this, &tof, tof->Class()); |
| 64 |
} |
| 65 |
|
| 66 |
/** |
| 67 |
* Unpack the tof event from an input file. |
| 68 |
*/ |
| 69 |
void TofReader::RunEvent(int EventNumber) { |
| 70 |
|
| 71 |
} |
| 72 |
|
| 73 |
/** |
| 74 |
* Unpack the Tof data event from the physical packet. |
| 75 |
*/ |
| 76 |
void TofReader::RunEvent(int EventNumber, const char subData[], long int length) { |
| 77 |
std::stringstream oss; |
| 78 |
char *data = new char[length]; |
| 79 |
memcpy(data, subData, length); |
| 80 |
int ERROR = 0; |
| 81 |
|
| 82 |
/*unsigned short convdata[length]; |
| 83 |
for (int i = 0; i<length; i++){ |
| 84 |
convdata[i] = (unsigned short)((unsigned char)subData[i]&0xFF); |
| 85 |
}*/ |
| 86 |
|
| 87 |
|
| 88 |
//Call to the routine that unpack tof events |
| 89 |
if ( length < 500000 && length >= 0 ){ |
| 90 |
tofunpack_((unsigned char*)data, &length, &ERROR); |
| 91 |
} else { |
| 92 |
ERROR = 1; |
| 93 |
}; |
| 94 |
|
| 95 |
if (ERROR != 0) { |
| 96 |
char *errmsg; |
| 97 |
switch (ERROR){ |
| 98 |
case 1: errmsg = "CRC TOF ERROR"; |
| 99 |
break; |
| 100 |
default: errmsg = "TOF ERROR CODE UNIDENTIFIED"; |
| 101 |
} |
| 102 |
oss.str(""); |
| 103 |
oss << "Fortran77 function tofunpack: " << errmsg; |
| 104 |
logger->debug(oss.str().c_str()); |
| 105 |
} |
| 106 |
// In case of "ERROR != 0" the calunpack will take care to set all |
| 107 |
// parameters to zero |
| 108 |
//} else { |
| 109 |
// only for a variable tof->tof1int = evento_.IEV2; |
| 110 |
// memcpy(tof->tof1int, tofvar_.tof1int, sizeof(tofvar_.tof1int)); |
| 111 |
// printf("tof->tof1int[1] %i \n",tof->tof1int[0]); |
| 112 |
tof->unpackError = (unsigned short)ERROR; |
| 113 |
|
| 114 |
// for (int i = 0; i < 6; i++){ |
| 115 |
// tof->tof1int[i] = tofvar_.tof1int[i]; |
| 116 |
//}; |
| 117 |
// printf("tof->tof1int[2] %i \n",tof->tof1int[1]); |
| 118 |
|
| 119 |
memcpy(tof->tdcid, tofvar_.tdcid, sizeof(tof->tdcid)); |
| 120 |
memcpy(tof->evcount, tofvar_.evcount, sizeof(tof->evcount)); |
| 121 |
memcpy(tof->tdcmask, tofvar_.tdcmask, sizeof(tof->tdcmask)); |
| 122 |
memcpy(tof->temp1, tofvar_.temp1, sizeof(tof->temp1)); |
| 123 |
memcpy(tof->temp2, tofvar_.temp2, sizeof(tof->temp2)); |
| 124 |
|
| 125 |
|
| 126 |
//--------have to invert array because of FORTRAN <-> C different management of the indexes |
| 127 |
|
| 128 |
// int temptofmat[6][12]; |
| 129 |
|
| 130 |
// memcpy(temptofmat, toftest_.tofmat, sizeof(temptofmat)); |
| 131 |
|
| 132 |
// for (int i = 0; i < 6; i++){ |
| 133 |
// for (int j = 0; j < 12; j++){ |
| 134 |
// tof->tofmat[j][i] = temptofmat[i][j]; |
| 135 |
// } |
| 136 |
// } |
| 137 |
|
| 138 |
int tmpadc[12][4]; |
| 139 |
int tmptdc[12][4]; |
| 140 |
|
| 141 |
memcpy(tmpadc, tofvar_.adc, sizeof(tmpadc)); |
| 142 |
memcpy(tmptdc, tofvar_.tdc, sizeof(tmptdc)); |
| 143 |
|
| 144 |
for (int i = 0; i < 12; i++){ |
| 145 |
for (int j = 0; j < 4; j++){ |
| 146 |
tof->adc[j][i] = tmpadc[i][j]; |
| 147 |
tof->tdc[j][i] = tmptdc[i][j]; |
| 148 |
} |
| 149 |
} |
| 150 |
|
| 151 |
delete [] data; |
| 152 |
} |