1 |
/** @file |
2 |
* $Source: /home/cvspamela/yoda/techmodel/PhysicsReader.cpp,v $ |
3 |
* $Id: PhysicsReader.cpp,v 1.1 2004/06/09 23:18:20 nagni Exp $ |
4 |
* $Author: nagni $ |
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 |
#include <sys/time.h> |
17 |
#include "CRC.h" |
18 |
} |
19 |
|
20 |
#include <fstream> |
21 |
#include "stdio.h" |
22 |
#include "ReaderAlgorithms.h" |
23 |
|
24 |
//#include "event/CalibTrgEvent.h" |
25 |
|
26 |
using namespace pamela; |
27 |
using namespace pamela::techmodel; |
28 |
using namespace pamela::tracker; |
29 |
|
30 |
static log4cpp::Category& cat = log4cpp::Category::getInstance("pamela.techmodel.PhysicsReader"); |
31 |
|
32 |
/** |
33 |
* Constructor. |
34 |
*/ |
35 |
PhysicsReader::PhysicsReader(void): |
36 |
TechmodelAlgorithm(PacketType::Log, "TechmodelPhysicsReader") { |
37 |
cat << log4cpp::Priority::DEBUG |
38 |
<< "Constructor " |
39 |
<< "\n " << log4cpp::CategoryStream::ENDLINE; |
40 |
trackerReader = new TrackerReader(); |
41 |
} |
42 |
|
43 |
/** |
44 |
* Get a string with the version info of the algorithm. |
45 |
*/ |
46 |
std::string PhysicsReader::GetVersionInfo(void) const { |
47 |
return |
48 |
"$Header: /home/cvspamela/yoda/techmodel/PhysicsReader.cpp,v 1.1 2004/06/09 23:18:20 nagni Exp $\n"; |
49 |
} |
50 |
|
51 |
/** |
52 |
* Initialize the algorithm with a special run. This will initialize the |
53 |
* event reader routines for all packet types. |
54 |
*/ |
55 |
void PhysicsReader::Init(PamelaRun *run) { |
56 |
SetInputStream(run); |
57 |
trackerReader->Init(run); |
58 |
//run->WriteSubPacket(this, &physicsEvent, physicsEvent->Class()); |
59 |
} |
60 |
|
61 |
/** |
62 |
* Unpack the Physics event from an input file. |
63 |
*/ |
64 |
void PhysicsReader::RunEvent(int EventNumber, long int length) { |
65 |
|
66 |
/*UINT16 CRCread; //CRC read from the end of the subpacket |
67 |
UINT16 CRCsum; //CRC of the data |
68 |
char packetData[length-2]; |
69 |
char CRCevent[2]; |
70 |
long int dataLength; |
71 |
|
72 |
InputFile->read(packetData, sizeof(packetData)); |
73 |
InputFile->read(CRCevent, sizeof(CRCevent)); |
74 |
|
75 |
CRCsum = CM_Compute_CRC16(0, (BYTE*)packetData, length -(long int)2 ); |
76 |
CRCread = ((UINT16)(CRCevent[0]<<8)) + ((UINT16)CRCevent[1]); |
77 |
InputFile->seekg(-(length), std::ios::cur); |
78 |
|
79 |
if (CRCread == CRCsum){ |
80 |
|
81 |
//passo packetData a tutti i reader dei vari rivelatori |
82 |
} else { |
83 |
cat << log4cpp::Priority::ERROR |
84 |
<< "The test of calculated CRC with one wrote on file FAILED!!" |
85 |
<< "\n " << log4cpp::CategoryStream::ENDLINE; |
86 |
}*/ |
87 |
|
88 |
char packetData[length-2]; |
89 |
int ERROR; |
90 |
|
91 |
InputFile->read(packetData, sizeof(packetData)); |
92 |
//Skip the last two crc bytes already checked in UnpackPscu |
93 |
//This part have to be refactored!!!! too bad...... |
94 |
//InputFile->seekg((long int)2, std::ios::cur); |
95 |
|
96 |
/*-----------------*/ |
97 |
//passo packetData a tutti i reader dei vari rivelatori |
98 |
//trackerReader->RunEvent(EventNumber, packetData, length-2); |
99 |
/*-----------------*/ |
100 |
//free(packetData); |
101 |
|
102 |
} |
103 |
|