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