1 |
kusanagi |
1.1 |
|
2 |
|
|
// Implementation of the EventTrkReader class. |
3 |
|
|
|
4 |
|
|
|
5 |
kusanagi |
2.4 |
|
6 |
kusanagi |
1.2 |
#include <log4cxx/logger.h> |
7 |
kusanagi |
1.1 |
|
8 |
|
|
#include <fstream> |
9 |
|
|
#include "ReaderAlgorithms.h" |
10 |
|
|
|
11 |
|
|
#include "event/EventTrkEvent.h" |
12 |
|
|
|
13 |
kusanagi |
2.3 |
extern "C" { |
14 |
|
|
//Passo il path verso la il file temporaneo |
15 |
|
|
extern void trkeventpkt_(int*, char*); |
16 |
|
|
//Struct per il passaggio di dati da e verso la chiamata fortran |
17 |
|
|
extern struct { |
18 |
|
|
int good0; |
19 |
|
|
int nev0; |
20 |
|
|
int DAQmode[12]; |
21 |
|
|
int DSPnumber[12]; |
22 |
|
|
int DATAlength[12]; |
23 |
|
|
int eventn[12]; |
24 |
|
|
int nclust[12]; |
25 |
|
|
int cutc[12]; |
26 |
|
|
int cutcl[12]; |
27 |
|
|
int addrcluster[12][3]; |
28 |
|
|
int signcluster[12][3]; |
29 |
|
|
int fc[12]; |
30 |
|
|
int compressiontime[12]; |
31 |
|
|
int fl5[12]; |
32 |
|
|
int fl4[12]; |
33 |
|
|
int fl3[12]; |
34 |
|
|
int fl2[12]; |
35 |
|
|
int fl1[12]; |
36 |
|
|
int fl6[12]; |
37 |
kusanagi |
2.4 |
int checksum[12]; |
38 |
|
|
int TOTDATAlength; |
39 |
|
|
int datatracker[49152]; |
40 |
kusanagi |
2.3 |
int pnum[12]; |
41 |
|
|
int cmdnum[12]; |
42 |
|
|
int bid[12]; |
43 |
|
|
int alarm[12]; |
44 |
|
|
int aswr[12]; |
45 |
|
|
} level0_; |
46 |
|
|
#include <dirent.h> |
47 |
|
|
} |
48 |
|
|
|
49 |
kusanagi |
1.1 |
using namespace pamela; |
50 |
|
|
using namespace pamela::techmodel; |
51 |
|
|
|
52 |
kusanagi |
1.2 |
static log4cxx::LoggerPtr logger = log4cxx::Logger::getLogger(_T("pamela.techmodel.EventTrkReader")); |
53 |
kusanagi |
1.1 |
|
54 |
|
|
/** |
55 |
|
|
* Constructor. |
56 |
|
|
*/ |
57 |
|
|
EventTrkReader::EventTrkReader(void): |
58 |
|
|
TechmodelAlgorithm(PacketType::EventTrk, "TechmodelEventTrkReader") { |
59 |
kusanagi |
1.2 |
logger->debug(_T("Constructor")); |
60 |
kusanagi |
1.1 |
eventTrk = new EventTrkEvent(); |
61 |
|
|
} |
62 |
|
|
|
63 |
|
|
/** |
64 |
|
|
* Get a string with the version info of the algorithm. |
65 |
|
|
*/ |
66 |
|
|
std::string EventTrkReader::GetVersionInfo(void) const { |
67 |
|
|
return |
68 |
|
|
"$Trailer: /home/cvsmanager/yoda/techmodel/EventTrkReader.cpp,v 1.1.1.1 2004/07/06 12:20:23 kusanagi Exp $\n"; |
69 |
|
|
} |
70 |
|
|
|
71 |
|
|
/** |
72 |
|
|
* Initialize the algorithm with a special run. This will initialize the |
73 |
|
|
* event reader routines for all packet types. |
74 |
|
|
*/ |
75 |
|
|
void EventTrkReader::Init(PamelaRun *run) { |
76 |
kusanagi |
1.2 |
logger->debug(_T("Initialize")); |
77 |
kusanagi |
1.1 |
SetInputStream(run); |
78 |
|
|
run->WriteSubPacket(this, &eventTrk, eventTrk->Class()); |
79 |
|
|
} |
80 |
|
|
|
81 |
|
|
/** |
82 |
|
|
* Unpack the EventTrk event from an input file. |
83 |
|
|
*/ |
84 |
kusanagi |
2.1 |
void EventTrkReader::RunEvent(int EventNumber, long int length) throw (Exception){ |
85 |
kusanagi |
2.3 |
int ERROR; |
86 |
|
|
|
87 |
|
|
//Scrivo un file temporaneo per passarlo alla routine |
88 |
|
|
//Speriamo di cambiare la routine per passargli un buffer..... |
89 |
|
|
//DIR *dirp; |
90 |
|
|
|
91 |
|
|
//std::string pathDir((char*)getenv("YODA_DATA")); |
92 |
|
|
|
93 |
|
|
//pathDir = pathDir + "/todatemp.dat"; |
94 |
|
|
char *subData; |
95 |
|
|
subData = new char[length]; |
96 |
|
|
InputFile->read(subData, sizeof(unsigned char)*length); |
97 |
|
|
|
98 |
|
|
stringstream oss; |
99 |
|
|
oss.str(""); |
100 |
|
|
oss << getenv("YODA_DATA") << "/" << time(NULL) << "evtrk.dat"; |
101 |
|
|
FILE *pfile; |
102 |
|
|
pfile = fopen(oss.str().c_str(), "wb"); |
103 |
|
|
fwrite(subData, 1, length, pfile); |
104 |
|
|
fclose(pfile); |
105 |
|
|
|
106 |
|
|
//Call to the FORTRAN routin that unpack tracker events |
107 |
|
|
trkeventpkt_(&ERROR, (char*)oss.str().c_str()); |
108 |
|
|
|
109 |
|
|
remove(oss.str().c_str()); |
110 |
|
|
|
111 |
|
|
/*if (ERROR != 0) { |
112 |
|
|
char *errmsg; |
113 |
|
|
switch (ERROR){ |
114 |
|
|
case 1: errmsg = "---------------------"; |
115 |
|
|
} |
116 |
|
|
} else {*/ |
117 |
|
|
//Store the unpacked data |
118 |
kusanagi |
2.4 |
eventTrk->unpackError = ERROR; |
119 |
|
|
eventTrk->good0 = level0_.good0; |
120 |
|
|
eventTrk->nev0 = level0_.nev0; |
121 |
kusanagi |
2.3 |
memcpy(eventTrk->DAQmode, level0_.DAQmode, sizeof(eventTrk->DAQmode)); |
122 |
|
|
memcpy(eventTrk->DSPnumber, level0_.DSPnumber, sizeof(eventTrk->DSPnumber)); |
123 |
|
|
memcpy(eventTrk->DATAlength, level0_.DATAlength, sizeof(eventTrk->DATAlength)); |
124 |
|
|
memcpy(eventTrk->eventn, level0_.eventn, sizeof(eventTrk->eventn)); |
125 |
|
|
memcpy(eventTrk->nclust, level0_.nclust, sizeof(eventTrk->nclust)); |
126 |
|
|
memcpy(eventTrk->cutc, level0_.cutc, sizeof(eventTrk->cutc)); |
127 |
|
|
memcpy(eventTrk->cutcl, level0_.cutcl, sizeof(eventTrk->cutcl)); |
128 |
|
|
// memcpy(eventTrk->addrcluster, (level0_.addrcluster), sizeof(eventTrk->addrcluster)); |
129 |
|
|
// memcpy(eventTrk->signcluster, (level0_.signcluster), sizeof(eventTrk->signcluster)); |
130 |
|
|
//--------have to invert array because of FORTRAN <-> C different management of the indexes |
131 |
|
|
int tempAddr[3][12]; |
132 |
|
|
int tempSign[3][12]; |
133 |
|
|
memcpy(tempAddr, (level0_.addrcluster), sizeof(tempAddr)); |
134 |
|
|
memcpy(tempSign, (level0_.signcluster), sizeof(tempSign)); |
135 |
kusanagi |
2.4 |
for (int j = 0; j < 12; j++){ |
136 |
|
|
for (int i = 0; i < 3; i++){ |
137 |
kusanagi |
2.3 |
eventTrk->addrcluster[j][i] = tempAddr[i][j]; |
138 |
|
|
eventTrk->signcluster[j][i] = tempSign[i][j]; |
139 |
|
|
} |
140 |
|
|
} |
141 |
|
|
//----------------------------------------------------------------------------------------- |
142 |
kusanagi |
1.1 |
|
143 |
kusanagi |
2.3 |
memcpy(eventTrk->fc, level0_.fc, sizeof(eventTrk->fc)); |
144 |
|
|
memcpy(eventTrk->compressiontime, level0_.compressiontime, sizeof(eventTrk->compressiontime)); |
145 |
|
|
memcpy(eventTrk->fl1, level0_.fl1, sizeof(eventTrk->fl1)); |
146 |
|
|
memcpy(eventTrk->fl2, level0_.fl2, sizeof(eventTrk->fl2)); |
147 |
|
|
memcpy(eventTrk->fl3, level0_.fl3, sizeof(eventTrk->fl3)); |
148 |
|
|
memcpy(eventTrk->fl4, level0_.fl4, sizeof(eventTrk->fl4)); |
149 |
|
|
memcpy(eventTrk->fl5, level0_.fl5, sizeof(eventTrk->fl5)); |
150 |
|
|
memcpy(eventTrk->fl6, level0_.fl6, sizeof(eventTrk->fl6)); |
151 |
|
|
memcpy(eventTrk->pnum, level0_.pnum, sizeof(eventTrk->pnum)); |
152 |
|
|
memcpy(eventTrk->cmdnum, level0_.cmdnum, sizeof(eventTrk->cmdnum)); |
153 |
|
|
memcpy(eventTrk->bid, level0_.bid, sizeof(eventTrk->bid)); |
154 |
|
|
memcpy(eventTrk->alarm, level0_.alarm, sizeof(eventTrk->alarm)); |
155 |
|
|
memcpy(eventTrk->aswr, level0_.aswr, sizeof(eventTrk->aswr)); |
156 |
|
|
eventTrk->TOTDATAlength = level0_.TOTDATAlength; |
157 |
|
|
|
158 |
|
|
eventTrk->TrackerData = new TArrayI(level0_.TOTDATAlength, level0_.datatracker); |
159 |
|
|
//memcpy(eventTrk->datatracker, level0_.datatracker, sizeof(eventTrk->datatracker)); |
160 |
|
|
//} |
161 |
kusanagi |
1.1 |
} |
162 |
|
|
|