| 1 |
kusanagi |
1.1 |
/** @file |
| 2 |
kusanagi |
1.2 |
* $Source: /home/cvsmanager/yoda/techmodel/CalibTrk2Reader.cpp,v $ |
| 3 |
|
|
* $Id: CalibTrk2Reader.cpp,v 1.1 2004/07/06 12:31:55 kusanagi Exp $ |
| 4 |
kusanagi |
1.1 |
* $Author: kusanagi $ |
| 5 |
|
|
* |
| 6 |
|
|
* Implementation of the LogReader class. |
| 7 |
|
|
* ToBeDone: |
| 8 |
|
|
* Control the CRC for the entire data Packet not just for single records |
| 9 |
|
|
*/ |
| 10 |
|
|
|
| 11 |
|
|
#define UINT unsigned int |
| 12 |
|
|
#define BYTE unsigned char |
| 13 |
|
|
#include <string> |
| 14 |
|
|
#include <log4cpp/Category.hh> |
| 15 |
|
|
extern "C" { |
| 16 |
|
|
//Passo il path verso la il file temporaneo |
| 17 |
|
|
extern void trkcalibpkt_(int*, char*); |
| 18 |
|
|
|
| 19 |
|
|
//Struct per il passaggio di dati da e verso la chiamata fortran |
| 20 |
|
|
extern struct { |
| 21 |
|
|
int DAQmode[6]; |
| 22 |
|
|
int DSPnumber[6]; |
| 23 |
|
|
int calibnumber[6]; |
| 24 |
|
|
int ncalib_event[6]; |
| 25 |
|
|
int ped_l1[6]; |
| 26 |
|
|
int ped_l2[6]; |
| 27 |
|
|
int ped_l3[6]; |
| 28 |
|
|
int sig_l1[6]; |
| 29 |
|
|
int sig_l2[6]; |
| 30 |
|
|
int sig_l3[6]; |
| 31 |
|
|
int nbad_l1[6]; |
| 32 |
|
|
int nbad_l2[6]; |
| 33 |
|
|
int nbad_l3[6]; |
| 34 |
|
|
int cal_flag[6]; |
| 35 |
|
|
int checksum[6]; |
| 36 |
|
|
int DSPbad_par[6][3072]; |
| 37 |
|
|
float DSPped_par[6][3072]; |
| 38 |
|
|
float DSPsig_par[6][3072]; |
| 39 |
|
|
} trkcalib_; |
| 40 |
|
|
|
| 41 |
|
|
#include <dirent.h> |
| 42 |
|
|
} |
| 43 |
|
|
|
| 44 |
|
|
#include <fstream> |
| 45 |
|
|
#include "stdio.h" |
| 46 |
|
|
#include "ReaderAlgorithms.h" |
| 47 |
|
|
|
| 48 |
kusanagi |
1.2 |
#include "event/CalibTrk2Event.h" |
| 49 |
kusanagi |
1.1 |
|
| 50 |
|
|
using namespace pamela; |
| 51 |
|
|
using namespace pamela::techmodel; |
| 52 |
|
|
|
| 53 |
kusanagi |
1.2 |
static log4cpp::Category& cat = log4cpp::Category::getInstance("pamela.techmodel.CalibTrk2Reader"); |
| 54 |
kusanagi |
1.1 |
|
| 55 |
|
|
/** |
| 56 |
|
|
* Constructor. |
| 57 |
|
|
*/ |
| 58 |
kusanagi |
1.2 |
CalibTrk2Reader::CalibTrk2Reader(void): |
| 59 |
|
|
TechmodelAlgorithm(PacketType::CalibTrk2, "TechmodelCalibTrk2Reader") { |
| 60 |
kusanagi |
1.1 |
cat << log4cpp::Priority::DEBUG |
| 61 |
|
|
<< "Constructor " |
| 62 |
|
|
<< "\n " << log4cpp::CategoryStream::ENDLINE; |
| 63 |
kusanagi |
1.2 |
calibTrk2 = new CalibTrk2Event(); |
| 64 |
kusanagi |
1.1 |
} |
| 65 |
|
|
|
| 66 |
|
|
/** |
| 67 |
|
|
* Get a string with the version info of the algorithm. |
| 68 |
|
|
*/ |
| 69 |
kusanagi |
1.2 |
std::string CalibTrk2Reader::GetVersionInfo(void) const { |
| 70 |
kusanagi |
1.1 |
return |
| 71 |
kusanagi |
1.2 |
"$Header: /home/cvsmanager/yoda/techmodel/CalibTrk2Reader.cpp,v 1.1 2004/07/06 12:31:55 kusanagi Exp $\n"; |
| 72 |
kusanagi |
1.1 |
} |
| 73 |
|
|
|
| 74 |
|
|
/** |
| 75 |
|
|
* Initialize the algorithm with a special run. This will initialize the |
| 76 |
|
|
* event reader routines for all packet types. |
| 77 |
|
|
*/ |
| 78 |
kusanagi |
1.2 |
void CalibTrk2Reader::Init(PamelaRun *run) { |
| 79 |
kusanagi |
1.1 |
SetInputStream(run); |
| 80 |
kusanagi |
1.2 |
run->WriteSubPacket(this, &calibTrk2, calibTrk2->Class()); |
| 81 |
kusanagi |
1.1 |
} |
| 82 |
|
|
|
| 83 |
|
|
/** |
| 84 |
kusanagi |
1.2 |
* Unpack the CalibTrk2 event from an input file. |
| 85 |
kusanagi |
1.1 |
*/ |
| 86 |
kusanagi |
1.2 |
void CalibTrk2Reader::RunEvent(int EventNumber, long int length) { |
| 87 |
kusanagi |
1.1 |
int ERROR; |
| 88 |
|
|
|
| 89 |
|
|
//the 2 bytes subtracted belong to the final event CRC bytes |
| 90 |
|
|
long int dataLength = length;// - (long int)2; |
| 91 |
|
|
|
| 92 |
|
|
char *subData = new char[dataLength]; |
| 93 |
|
|
InputFile->read(subData, sizeof(unsigned char)*dataLength); |
| 94 |
|
|
|
| 95 |
|
|
//Skip the last two crc bytes already checked in UnpackPscu |
| 96 |
|
|
//This part have to be refactored!!!! too bad...... |
| 97 |
|
|
InputFile->seekg((long int)2, std::ios::cur); |
| 98 |
|
|
|
| 99 |
|
|
//Scrivo un file temporaneo per passarlo alla routine |
| 100 |
|
|
//Speriamo di cambiare la routine per passargli un buffer..... |
| 101 |
|
|
DIR *dirp; |
| 102 |
|
|
std::string pathDir((char*)getenv("YODA_DATA")); |
| 103 |
|
|
pathDir = pathDir + "/"; |
| 104 |
|
|
pathDir = pathDir + PamelaRun::GetRunName(EventNumber) + "/todatemp.dat"; |
| 105 |
|
|
FILE *pfile; |
| 106 |
|
|
pfile = fopen((char*)pathDir.c_str(), "wb"); |
| 107 |
|
|
fwrite(subData, 1, dataLength, pfile); |
| 108 |
|
|
fclose(pfile); |
| 109 |
|
|
|
| 110 |
|
|
//Call to the FORTRAN routin that unpack tracker events |
| 111 |
|
|
trkcalibpkt_(&ERROR, (char*)pathDir.c_str()); |
| 112 |
|
|
|
| 113 |
|
|
remove((char*)pathDir.c_str()); |
| 114 |
|
|
|
| 115 |
|
|
//Store the unpacked data |
| 116 |
kusanagi |
1.2 |
memcpy(calibTrk2->DAQmode, trkcalib_.DAQmode, sizeof(calibTrk2->DAQmode)); |
| 117 |
|
|
memcpy(calibTrk2->DSPnumber, trkcalib_.DSPnumber, sizeof(calibTrk2->DSPnumber)); |
| 118 |
|
|
memcpy(calibTrk2->calibnumber, trkcalib_.calibnumber, sizeof(calibTrk2->calibnumber)); |
| 119 |
|
|
memcpy(calibTrk2->DSPnumber, trkcalib_.ncalib_event, sizeof(calibTrk2->ncalib_event)); |
| 120 |
|
|
memcpy(calibTrk2->ped_l1, trkcalib_.ped_l1, sizeof(calibTrk2->ped_l1)); |
| 121 |
|
|
memcpy(calibTrk2->ped_l2, trkcalib_.ped_l2, sizeof(calibTrk2->ped_l2)); |
| 122 |
|
|
memcpy(calibTrk2->ped_l3, trkcalib_.ped_l3, sizeof(calibTrk2->ped_l3)); |
| 123 |
|
|
memcpy(calibTrk2->sig_l1, trkcalib_.sig_l1, sizeof(calibTrk2->sig_l1)); |
| 124 |
|
|
memcpy(calibTrk2->sig_l2, trkcalib_.sig_l2, sizeof(calibTrk2->sig_l2)); |
| 125 |
|
|
memcpy(calibTrk2->sig_l3, trkcalib_.sig_l3, sizeof(calibTrk2->sig_l3)); |
| 126 |
|
|
memcpy(calibTrk2->nbad_l1, trkcalib_.nbad_l1, sizeof(calibTrk2->nbad_l1)); |
| 127 |
|
|
memcpy(calibTrk2->nbad_l2, trkcalib_.nbad_l2, sizeof(calibTrk2->nbad_l2)); |
| 128 |
|
|
memcpy(calibTrk2->nbad_l3, trkcalib_.nbad_l3, sizeof(calibTrk2->nbad_l3)); |
| 129 |
|
|
memcpy(calibTrk2->cal_flag, trkcalib_.cal_flag, sizeof(calibTrk2->cal_flag)); |
| 130 |
|
|
memcpy(calibTrk2->checksum, trkcalib_.checksum, sizeof(calibTrk2->checksum)); |
| 131 |
|
|
memcpy(calibTrk2->DSPbad_par,trkcalib_.DSPbad_par, sizeof(calibTrk2->DSPbad_par)); |
| 132 |
|
|
memcpy(calibTrk2->DSPped_par,trkcalib_.DSPped_par, sizeof(calibTrk2->DSPped_par)); |
| 133 |
|
|
memcpy(calibTrk2->DSPsig_par,trkcalib_.DSPsig_par, sizeof(calibTrk2->DSPsig_par)); |
| 134 |
kusanagi |
1.1 |
|
| 135 |
|
|
cat << log4cpp::Priority::ERROR |
| 136 |
|
|
<< "Fortran77 function trkcalibpkt error code = " << ERROR |
| 137 |
|
|
<< "\n " << log4cpp::CategoryStream::ENDLINE; |
| 138 |
|
|
free(subData); |
| 139 |
|
|
|
| 140 |
|
|
} |
| 141 |
|
|
|