Line data Source code
1 : // $Id$
2 :
3 : /**************************************************************************
4 : * This file is property of and copyright by the ALICE HLT Project *
5 : * ALICE Experiment at CERN, All rights reserved. *
6 : * *
7 : * Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no> *
8 : * for The ALICE HLT Project. *
9 : * *
10 : * Permission to use, copy, modify and distribute this software and its *
11 : * documentation strictly for non-commercial purposes is hereby granted *
12 : * without fee, provided that the above copyright notice appears in all *
13 : * copies and that both the copyright notice and this permission notice *
14 : * appear in the supporting documentation. The authors make no claims *
15 : * about the suitability of this software for any purpose. It is *
16 : * provided "as is" without express or implied warranty. *
17 : **************************************************************************/
18 :
19 : /** @file AliHLTTPCDigitDumpComponent.cxx
20 : @author Matthias Richter
21 : @date
22 : @brief Special file writer converting TPC digit input to ASCII. */
23 :
24 : // see header file for class documentation
25 : // or
26 : // refer to README to build package
27 : // or
28 : // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
29 :
30 : #include <cassert>
31 : #include "AliHLTTPCDigitDumpComponent.h"
32 : #include "AliHLTTPCGeometry.h"
33 : #include "AliHLTTPCDigitReader.h"
34 : #include "AliHLTTPCDigitReaderUnpacked.h"
35 : #include "AliHLTTPCDigitReader32Bit.h"
36 : #include "AliHLTTPCDefinitions.h"
37 :
38 : /** ROOT macro for the implementation of ROOT specific class methods */
39 6 : ClassImp(AliHLTTPCDigitDumpComponent)
40 :
41 : AliHLTTPCDigitDumpComponent::AliHLTTPCDigitDumpComponent()
42 : :
43 3 : AliHLTFileWriter(),
44 3 : fDigitReaderType(kDigitReader32Bit),
45 3 : fRcuTrailerSize(2),
46 3 : fUnsorted(true),
47 3 : fbBulkMode(true),
48 3 : fpReader(NULL),
49 3 : f32BitFormat(kFALSE)
50 15 : {
51 : // see header file for class documentation
52 : // or
53 : // refer to README to build package
54 : // or
55 : // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
56 6 : }
57 :
58 : AliHLTTPCDigitDumpComponent::~AliHLTTPCDigitDumpComponent()
59 12 : {
60 : // see header file for class documentation
61 12 : }
62 :
63 : const char* AliHLTTPCDigitDumpComponent::GetComponentID()
64 : {
65 : // see header file for class documentation
66 486 : return "TPCDigitDump";
67 : }
68 :
69 : void AliHLTTPCDigitDumpComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list)
70 : {
71 : // see header file for class documentation
72 0 : list.clear();
73 0 : list.push_back(kAliHLTAnyDataType);
74 0 : }
75 :
76 : AliHLTComponent* AliHLTTPCDigitDumpComponent::Spawn()
77 : {
78 : // see header file for class documentation
79 0 : return new AliHLTTPCDigitDumpComponent;
80 0 : }
81 :
82 : int AliHLTTPCDigitDumpComponent::InitWriter()
83 : {
84 : // see header file for class documentation
85 : int iResult=0;
86 0 : switch (fDigitReaderType) {
87 : case kDigitReaderUnpacked:
88 0 : HLTInfo("create DigitReaderUnpacked");
89 0 : fpReader=new AliHLTTPCDigitReaderUnpacked;
90 0 : break;
91 : case kDigitReader32Bit:
92 0 : HLTInfo("create DigitReader32Bit");
93 0 : fpReader=new AliHLTTPCDigitReader32Bit();
94 0 : f32BitFormat = kTRUE;
95 0 : break;
96 : }
97 0 : if (!fpReader) {
98 0 : HLTError("can not create digit reader of type %d", fDigitReaderType);
99 : iResult=-EFAULT;
100 0 : } else {
101 0 : fpReader->SetUnsorted(fUnsorted);
102 : }
103 0 : return iResult;
104 0 : }
105 :
106 : int AliHLTTPCDigitDumpComponent::ScanArgument(int argc, const char** argv)
107 : {
108 : // see header file for class documentation
109 : int iResult=0;
110 0 : TString argument="";
111 : bool bMissingParam=0;
112 : int i=0;
113 : do {
114 0 : if (i>=argc || (argument=argv[i]).IsNull()) continue;
115 :
116 : // -rawreadermode
117 0 : if (argument.CompareTo("-rawreadermode")==0) {
118 0 : if ((bMissingParam=(++i>=argc))) break;
119 0 : HLTWarning("argument '-rawreadermode' deprecated");
120 : break;
121 : }
122 :
123 : // -digitreader
124 0 : if (argument.CompareTo("-digitreader")==0) {
125 0 : if ((bMissingParam=(++i>=argc))) break;
126 0 : TString param=argv[i];
127 0 : if (param.CompareTo("unpacked", TString::kIgnoreCase)==0) {
128 0 : fDigitReaderType=kDigitReaderUnpacked;
129 0 : } else if (param.CompareTo("packed", TString::kIgnoreCase)==0) {
130 0 : HLTWarning("argument 'packed' is deprecated, falling back to DigitReader32Bit");
131 0 : fDigitReaderType=kDigitReader32Bit;
132 0 : } else if (param.CompareTo("raw", TString::kIgnoreCase)==0) {
133 0 : HLTWarning("argument 'raw' is deprecated, falling back to DigitReader32Bit");
134 0 : fDigitReaderType=kDigitReader32Bit;
135 0 : } else if (param.CompareTo("decoder", TString::kIgnoreCase)==0) {
136 0 : HLTWarning("argument 'decoder' is deprecated, falling back to DigitReader32Bit");
137 0 : fDigitReaderType=kDigitReader32Bit;
138 0 : } else if (param.CompareTo("32bit", TString::kIgnoreCase)==0) {
139 0 : fDigitReaderType=kDigitReader32Bit;
140 0 : } else {
141 0 : HLTError("unknown digit reader type %s", param.Data());
142 : iResult=-EINVAL;
143 : }
144 :
145 : break;
146 0 : }
147 :
148 : // -rcutrailersize
149 0 : if (argument.CompareTo("-rcutrailersize")==0) {
150 0 : if ((bMissingParam=(++i>=argc))) break;
151 0 : char *endptr=NULL;
152 0 : fRcuTrailerSize=strtoul(argv[i], &endptr, 0);
153 0 : if (/*endptr ||*/ fRcuTrailerSize<1) {
154 0 : HLTError("invalid parameter '%s', %s", argv[i], endptr==NULL?"number >= 1 expected":"can not convert string to number");
155 : iResult=-EINVAL;
156 0 : }
157 : break;
158 0 : }
159 :
160 : // -unsorted
161 0 : if (argument.CompareTo("-unsorted")==0) {
162 0 : fUnsorted=true;
163 0 : break;
164 : }
165 :
166 : // -sorted
167 0 : if (argument.CompareTo("-sorted")==0) {
168 0 : fUnsorted=false;
169 0 : break;
170 : }
171 :
172 : // -bulk
173 0 : if (argument.CompareTo("-bulk")==0) {
174 0 : fbBulkMode=true;
175 0 : break;
176 : }
177 :
178 : // -stream
179 0 : if (argument.CompareTo("-stream")==0) {
180 0 : fbBulkMode=false;
181 0 : break;
182 : }
183 : } while (0); // just use the do/while here to have the option of breaking
184 :
185 0 : if (bMissingParam) iResult=-EPROTO;
186 0 : else if (iResult>=0) iResult=i;
187 :
188 : return iResult;
189 0 : }
190 :
191 : int AliHLTTPCDigitDumpComponent::CloseWriter()
192 : {
193 : // see header file for class documentation
194 0 : if (fpReader) delete fpReader;
195 0 : fpReader=NULL;
196 0 : return 0;
197 : }
198 :
199 : int AliHLTTPCDigitDumpComponent::DumpEvent( const AliHLTComponentEventData& evtData,
200 : const AliHLTComponentBlockData* /*blocks*/,
201 : AliHLTComponentTriggerData& /*trigData*/ )
202 : {
203 : // see header file for class documentation
204 : int iResult=0;
205 0 : int iPrintedSlice=-1;
206 0 : int iPrintedPart=-1;
207 : int blockno=0;
208 : const AliHLTComponentBlockData* pDesc=NULL;
209 :
210 0 : AliHLTTPCDigitReader* pReader=fpReader;
211 0 : if (!pReader) return -ENODEV;
212 :
213 0 : for (pDesc=GetFirstInputBlock(kAliHLTAnyDataType); pDesc!=NULL; pDesc=GetNextInputBlock(), blockno++) {
214 : HLTDebug("event %Lu block %d: %s 0x%08x size %d", evtData.fEventID, blockno, DataType2Text(pDesc->fDataType).c_str(), pDesc->fSpecification, pDesc->fSize);
215 :
216 0 : if (fDigitReaderType==kDigitReaderUnpacked && pDesc->fDataType!=AliHLTTPCDefinitions::fgkUnpackedRawDataType) continue;
217 0 : else if (fDigitReaderType!=kDigitReaderUnpacked && pDesc->fDataType!=(kAliHLTDataTypeDDLRaw|kAliHLTDataOriginTPC)) continue;
218 :
219 0 : TString filename;
220 0 : iResult=BuildFileName(evtData.fEventID, blockno, pDesc->fDataType, pDesc->fSpecification, filename);
221 : ios::openmode filemode=(ios::openmode)0;
222 0 : if (fCurrentFileName.CompareTo(filename)==0) {
223 : // append to the file
224 : filemode=ios::app;
225 0 : } else {
226 : // store the file for the next block
227 0 : fCurrentFileName=filename;
228 : }
229 0 : if (iResult>=0) {
230 0 : ofstream dump(filename.Data(), filemode);
231 0 : if (dump.good()) {
232 0 : int part=AliHLTTPCDefinitions::GetMinPatchNr(*pDesc);
233 0 : assert(part==AliHLTTPCDefinitions::GetMaxPatchNr(*pDesc));
234 0 : int slice=AliHLTTPCDefinitions::GetMinSliceNr(*pDesc);
235 0 : assert(slice==AliHLTTPCDefinitions::GetMaxSliceNr(*pDesc));
236 0 : int firstRow=AliHLTTPCGeometry::GetFirstRow(part);
237 0 : int lastRow=AliHLTTPCGeometry::GetLastRow(part);
238 :
239 0 : iResult=pReader->InitBlock(pDesc->fPtr,pDesc->fSize,firstRow,lastRow,part,slice);
240 :
241 0 : int iPrintedRow=-1;
242 0 : int iPrintedPad=-1;
243 : int iLastTime=-1;
244 0 : if (fbBulkMode) {
245 0 : while (pReader->NextChannel()) {
246 0 : if (PrintHeaders(slice, iPrintedSlice, part, iPrintedPart, pReader, iPrintedRow, iPrintedPad, dump)) {
247 : iLastTime=-1;
248 0 : }
249 0 : while (pReader->NextBunch()) {
250 0 : int bunchLength=pReader->GetBunchSize();
251 :
252 : // Kenneth: 20-04-09. The following if have been added because of inconsistency in the 40 bit decoder and the 32 bit decoder.
253 : // GetSignals() in the 40 bit decoder returns an array of UInt_t while the 32 bit one returns UShort_t
254 0 : if(f32BitFormat == kTRUE){
255 0 : const UShort_t* bunchData=pReader->GetSignalsShort();
256 :
257 : // bunch data is printed in 'reverse' order in order to produce
258 : // the same output as in stream reading mode
259 0 : dump << " Time " << pReader->GetTime()+bunchLength-1 << ": ";
260 0 : for (int bin=bunchLength-1; bin>=0; bin--) {
261 0 : dump << " " << bunchData[bin];
262 : }
263 0 : dump << " -> Time: " << pReader->GetTime() << endl;
264 0 : }
265 : else{
266 0 : const UInt_t* bunchData=pReader->GetSignals();
267 0 : dump << " Time " << pReader->GetTime()+bunchLength-1 << ": ";
268 0 : for (int bin=0; bin<bunchLength; bin++) {
269 0 : dump << " " << bunchData[bin];
270 : }
271 0 : dump << " -> Time: " << pReader->GetTime() << endl;
272 : }
273 : }
274 : }
275 0 : dump << endl;
276 : } else {
277 0 : while (pReader->Next()) {
278 0 : if ((iPrintedSlice!=-1 && iLastTime!=-1 && iLastTime!=pReader->GetTime()+1 && iLastTime!=pReader->GetTime()-1)) {
279 0 : dump << " -> Time: " << iLastTime << endl;
280 0 : } else if ((iPrintedPad!=-1 && iPrintedPad!=pReader->GetPad()) ||
281 0 : (iPrintedRow!=-1 && iPrintedRow!=pReader->GetRow())) {
282 0 : dump << " -> Time: " << iLastTime << endl;
283 : //dump << endl;
284 : }
285 :
286 0 : if (PrintHeaders(slice, iPrintedSlice, part, iPrintedPart, pReader, iPrintedRow, iPrintedPad, dump)) {
287 : iLastTime=-1;
288 0 : }
289 0 : if (iLastTime==-1 || (iLastTime!=pReader->GetTime()+1 && iLastTime!=pReader->GetTime()-1)) {
290 0 : dump << " Time " << pReader->GetTime() << ": ";
291 : }
292 0 : iLastTime=pReader->GetTime();
293 0 : dump << " " << pReader->GetSignal();
294 : }
295 0 : if (iLastTime>=0) dump << " -> Time: " << iLastTime << endl << endl;
296 : }
297 0 : } else {
298 0 : HLTError("can not open file %s for writing", filename.Data());
299 : iResult=-EBADF;
300 : }
301 0 : dump.close();
302 0 : }
303 0 : pReader->Reset();
304 0 : }
305 0 : return iResult;
306 0 : }
307 :
308 : int AliHLTTPCDigitDumpComponent::PrintHeaders(int slice, int &iPrintedSlice,
309 : int part, int &iPrintedPart,
310 : AliHLTTPCDigitReader* pReader,
311 : int &iPrintedRow, int &iPrintedPad,
312 : ofstream &dump) const
313 : {
314 : // see header file for class documentation
315 : int iResult=0;
316 0 : assert(pReader);
317 0 : if (iPrintedSlice!=slice || iPrintedPart!=part) {
318 0 : iPrintedSlice=slice;
319 0 : iPrintedPart=part;
320 0 : dump << "====================================================================" << endl;
321 0 : dump << " Slice: " << iPrintedSlice << " Partition: " << iPrintedPart << endl;
322 0 : iPrintedRow=-1;
323 0 : }
324 0 : if (iPrintedRow!=pReader->GetRow()) {
325 0 : iPrintedRow=pReader->GetRow();
326 0 : dump << "--------------------------------------------------------------------" << endl;
327 0 : dump << "Row: " << iPrintedRow << endl;
328 0 : iPrintedPad=-1;
329 0 : }
330 0 : if (iPrintedPad!=pReader->GetPad()) {
331 0 : iPrintedPad=pReader->GetPad();
332 0 : dump << "Row: " << iPrintedRow << " Pad: " << iPrintedPad << " HW address: " << pReader->GetAltroBlockHWaddr() << endl;
333 : iResult=1;
334 0 : }
335 :
336 0 : return iResult;
337 : }
|