1 |
/** @file |
/** @file |
2 |
* $Source: /home/cvspamela/yoda/techmodel/PhysicsReader.cpp,v $ |
* $Source: /afs/ba.infn.it/user/pamela/src/CVS/yoda/techmodel/PhysicsReader.cpp,v $ |
3 |
* $Id: PhysicsReader.cpp,v 1.1 2004/06/09 23:18:20 nagni Exp $ |
* $Id: PhysicsReader.cpp,v 6.3 2006/09/29 10:19:25 mocchiut Exp $ |
4 |
* $Author: nagni $ |
* $Author: mocchiut $ |
5 |
* |
* |
6 |
* Implementation of the LogReader class. |
* Implementation of the LogReader class. |
7 |
* ToBeDone: |
* ToBeDone: |
11 |
#define UINT unsigned int |
#define UINT unsigned int |
12 |
#define BYTE unsigned char |
#define BYTE unsigned char |
13 |
#include <string> |
#include <string> |
14 |
#include <log4cpp/Category.hh> |
#include <log4cxx/logger.h> |
15 |
extern "C" { |
extern "C" { |
16 |
#include <sys/time.h> |
#include <sys/time.h> |
17 |
#include "CRC.h" |
#include "CRC.h" |
21 |
#include "stdio.h" |
#include "stdio.h" |
22 |
#include "ReaderAlgorithms.h" |
#include "ReaderAlgorithms.h" |
23 |
|
|
|
//#include "event/CalibTrgEvent.h" |
|
24 |
|
|
25 |
using namespace pamela; |
using namespace pamela; |
26 |
using namespace pamela::techmodel; |
using namespace pamela::techmodel; |
27 |
using namespace pamela::tracker; |
using namespace pamela::tracker; |
28 |
|
using namespace pamela::anticounter; |
29 |
|
using namespace pamela::calorimeter; |
30 |
|
using namespace pamela::neutron; |
31 |
|
using namespace pamela::S4; |
32 |
|
using namespace pamela::tof; |
33 |
|
using namespace pamela::trigger; |
34 |
|
|
35 |
static log4cpp::Category& cat = log4cpp::Category::getInstance("pamela.techmodel.PhysicsReader"); |
static log4cxx::LoggerPtr logger = log4cxx::Logger::getLogger(_T("pamela.techmodel.PhysicsReader")); |
36 |
|
|
37 |
/** |
/** |
38 |
* Constructor. |
* Constructor. |
39 |
*/ |
*/ |
40 |
PhysicsReader::PhysicsReader(void): |
PhysicsReader::PhysicsReader(void): |
41 |
TechmodelAlgorithm(PacketType::Log, "TechmodelPhysicsReader") { |
TechmodelAlgorithm(PacketType::Physics, "TechmodelPhysicsReader") { |
42 |
cat << log4cpp::Priority::DEBUG |
logger->debug(_T("Constructor")); |
43 |
<< "Constructor " |
trackerReader = new TrackerReader; |
44 |
<< "\n " << log4cpp::CategoryStream::ENDLINE; |
anticounterReader = new AnticounterReader; |
45 |
trackerReader = new TrackerReader(); |
calorimeterReader = new CalorimeterReader; |
46 |
|
neutronReader = new NeutronDetectorReader; |
47 |
|
s4Reader = new S4Reader; |
48 |
|
tofReader = new TofReader; |
49 |
|
triggerReader = new TriggerReader; |
50 |
} |
} |
51 |
|
|
52 |
/** |
/** |
54 |
*/ |
*/ |
55 |
std::string PhysicsReader::GetVersionInfo(void) const { |
std::string PhysicsReader::GetVersionInfo(void) const { |
56 |
return |
return |
57 |
"$Header: /home/cvspamela/yoda/techmodel/PhysicsReader.cpp,v 1.1 2004/06/09 23:18:20 nagni Exp $\n"; |
"$Header: /afs/ba.infn.it/user/pamela/src/CVS/yoda/techmodel/PhysicsReader.cpp,v 6.3 2006/09/29 10:19:25 mocchiut Exp $\n"; |
58 |
} |
} |
59 |
|
|
60 |
/** |
/** |
62 |
* event reader routines for all packet types. |
* event reader routines for all packet types. |
63 |
*/ |
*/ |
64 |
void PhysicsReader::Init(PamelaRun *run) { |
void PhysicsReader::Init(PamelaRun *run) { |
65 |
SetInputStream(run); |
SetInputStream(run); |
66 |
trackerReader->Init(run); |
trackerReader->Init(run); |
67 |
|
anticounterReader->Init(run); |
68 |
|
calorimeterReader->Init(run); |
69 |
|
neutronReader->Init(run); |
70 |
|
s4Reader->Init(run); |
71 |
|
tofReader->Init(run); |
72 |
|
triggerReader->Init(run); |
73 |
//run->WriteSubPacket(this, &physicsEvent, physicsEvent->Class()); |
//run->WriteSubPacket(this, &physicsEvent, physicsEvent->Class()); |
74 |
|
logger->debug(_T("Initialize")); |
75 |
} |
} |
76 |
|
|
77 |
/** |
/** |
78 |
* Unpack the Physics event from an input file. |
* Unpack the Physics event from an input file. |
79 |
*/ |
*/ |
80 |
void PhysicsReader::RunEvent(int EventNumber, long int length) { |
void PhysicsReader::RunEvent(int EventNumber, long int dataLenght) throw (Exception){ |
81 |
|
char *subData = new char[dataLenght]; |
82 |
|
memset(subData, 0, dataLenght*sizeof(char)); |
83 |
|
InputFile->read(subData, sizeof(unsigned char)*dataLenght); |
84 |
|
|
|
/*UINT16 CRCread; //CRC read from the end of the subpacket |
|
|
UINT16 CRCsum; //CRC of the data |
|
|
char packetData[length-2]; |
|
|
char CRCevent[2]; |
|
|
long int dataLength; |
|
|
|
|
|
InputFile->read(packetData, sizeof(packetData)); |
|
|
InputFile->read(CRCevent, sizeof(CRCevent)); |
|
|
|
|
|
CRCsum = CM_Compute_CRC16(0, (BYTE*)packetData, length -(long int)2 ); |
|
|
CRCread = ((UINT16)(CRCevent[0]<<8)) + ((UINT16)CRCevent[1]); |
|
|
InputFile->seekg(-(length), std::ios::cur); |
|
|
|
|
|
if (CRCread == CRCsum){ |
|
|
|
|
|
//passo packetData a tutti i reader dei vari rivelatori |
|
|
} else { |
|
|
cat << log4cpp::Priority::ERROR |
|
|
<< "The test of calculated CRC with one wrote on file FAILED!!" |
|
|
<< "\n " << log4cpp::CategoryStream::ENDLINE; |
|
|
}*/ |
|
|
|
|
|
char packetData[length-2]; |
|
|
int ERROR; |
|
|
|
|
|
InputFile->read(packetData, sizeof(packetData)); |
|
|
//Skip the last two crc bytes already checked in UnpackPscu |
|
|
//This part have to be refactored!!!! too bad...... |
|
|
//InputFile->seekg((long int)2, std::ios::cur); |
|
|
|
|
85 |
/*-----------------*/ |
/*-----------------*/ |
86 |
//passo packetData a tutti i reader dei vari rivelatori |
//passo packetData a tutti i reader dei vari rivelatori |
87 |
//trackerReader->RunEvent(EventNumber, packetData, length-2); |
triggerReader->RunEvent(EventNumber, subData, dataLenght); |
88 |
|
tofReader->RunEvent(EventNumber, subData, dataLenght); |
89 |
|
trackerReader->RunEvent(EventNumber, subData, dataLenght); |
90 |
|
anticounterReader->RunEvent(EventNumber, subData, dataLenght); |
91 |
|
calorimeterReader->RunEvent(EventNumber, subData, dataLenght); |
92 |
|
s4Reader->RunEvent(EventNumber, subData, dataLenght); |
93 |
|
neutronReader->RunEvent(EventNumber, subData, dataLenght); |
94 |
/*-----------------*/ |
/*-----------------*/ |
95 |
//free(packetData); |
delete [] subData; |
|
|
|
96 |
} |
} |
97 |
|
|