]>
Commit | Line | Data |
---|---|---|
3e6ec852 | 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 | ||
e1440dab | 30 | #include <cassert> |
3e6ec852 | 31 | #include "AliHLTTPCDigitDumpComponent.h" |
e1440dab | 32 | #include "AliHLTTPCTransform.h" |
8c27b00a | 33 | #include "AliHLTTPCDigitReader.h" |
34 | #include "AliHLTTPCDigitReaderUnpacked.h" | |
deba5d85 | 35 | #include "AliHLTTPCDigitReader32Bit.h" |
e1440dab | 36 | #include "AliHLTTPCDefinitions.h" |
3e6ec852 | 37 | |
38 | /** ROOT macro for the implementation of ROOT specific class methods */ | |
39 | ClassImp(AliHLTTPCDigitDumpComponent) | |
40 | ||
41 | AliHLTTPCDigitDumpComponent::AliHLTTPCDigitDumpComponent() | |
42 | : | |
e1440dab | 43 | AliHLTFileWriter(), |
993b0a0c | 44 | fDigitReaderType(kDigitReader32Bit), |
70d0b23e | 45 | fRcuTrailerSize(2), |
7e1566e3 | 46 | fUnsorted(true), |
47 | fbBulkMode(true), | |
deba5d85 | 48 | fpReader(NULL), |
49 | f32BitFormat(kFALSE) | |
3e6ec852 | 50 | { |
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 | } | |
57 | ||
58 | AliHLTTPCDigitDumpComponent::~AliHLTTPCDigitDumpComponent() | |
59 | { | |
60 | // see header file for class documentation | |
61 | } | |
62 | ||
63 | const char* AliHLTTPCDigitDumpComponent::GetComponentID() | |
64 | { | |
65 | // see header file for class documentation | |
66 | return "TPCDigitDump"; | |
67 | } | |
68 | ||
69 | void AliHLTTPCDigitDumpComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list) | |
70 | { | |
71 | // see header file for class documentation | |
72 | list.clear(); | |
73 | list.push_back(kAliHLTAnyDataType); | |
74 | } | |
75 | ||
76 | AliHLTComponent* AliHLTTPCDigitDumpComponent::Spawn() | |
77 | { | |
78 | // see header file for class documentation | |
79 | return new AliHLTTPCDigitDumpComponent; | |
80 | } | |
81 | ||
82 | int AliHLTTPCDigitDumpComponent::InitWriter() | |
83 | { | |
84 | // see header file for class documentation | |
7e1566e3 | 85 | int iResult=0; |
86 | switch (fDigitReaderType) { | |
87 | case kDigitReaderUnpacked: | |
88 | HLTInfo("create DigitReaderUnpacked"); | |
89 | fpReader=new AliHLTTPCDigitReaderUnpacked; | |
90 | break; | |
deba5d85 | 91 | case kDigitReader32Bit: |
92 | HLTInfo("create DigitReader32Bit"); | |
93 | fpReader=new AliHLTTPCDigitReader32Bit(); | |
94 | f32BitFormat = kTRUE; | |
95 | break; | |
7e1566e3 | 96 | } |
97 | if (!fpReader) { | |
98 | HLTError("can not create digit reader of type %d", fDigitReaderType); | |
99 | iResult=-EFAULT; | |
100 | } else { | |
101 | fpReader->SetUnsorted(fUnsorted); | |
102 | } | |
103 | return iResult; | |
3e6ec852 | 104 | } |
105 | ||
106 | int AliHLTTPCDigitDumpComponent::ScanArgument(int argc, const char** argv) | |
107 | { | |
108 | // see header file for class documentation | |
109 | int iResult=0; | |
110 | TString argument=""; | |
e1440dab | 111 | bool bMissingParam=0; |
112 | int i=0; | |
3c835b25 | 113 | do { |
114 | if (i>=argc || (argument=argv[i]).IsNull()) continue; | |
3e6ec852 | 115 | |
e1440dab | 116 | // -rawreadermode |
117 | if (argument.CompareTo("-rawreadermode")==0) { | |
118 | if ((bMissingParam=(++i>=argc))) break; | |
51b88d1e | 119 | HLTWarning("argument '-rawreadermode' deprecated"); |
8c27b00a | 120 | break; |
3e6ec852 | 121 | } |
8c27b00a | 122 | |
123 | // -digitreader | |
124 | if (argument.CompareTo("-digitreader")==0) { | |
125 | if ((bMissingParam=(++i>=argc))) break; | |
126 | TString param=argv[i]; | |
127 | if (param.CompareTo("unpacked", TString::kIgnoreCase)==0) { | |
128 | fDigitReaderType=kDigitReaderUnpacked; | |
129 | } else if (param.CompareTo("packed", TString::kIgnoreCase)==0) { | |
993b0a0c | 130 | HLTWarning("argument 'packed' is deprecated, falling back to DigitReader32Bit"); |
131 | fDigitReaderType=kDigitReader32Bit; | |
8c27b00a | 132 | } else if (param.CompareTo("raw", TString::kIgnoreCase)==0) { |
993b0a0c | 133 | HLTWarning("argument 'raw' is deprecated, falling back to DigitReader32Bit"); |
134 | fDigitReaderType=kDigitReader32Bit; | |
7c9a4e09 | 135 | } else if (param.CompareTo("decoder", TString::kIgnoreCase)==0) { |
993b0a0c | 136 | HLTWarning("argument 'decoder' is deprecated, falling back to DigitReader32Bit"); |
137 | fDigitReaderType=kDigitReader32Bit; | |
deba5d85 | 138 | } else if (param.CompareTo("32bit", TString::kIgnoreCase)==0) { |
139 | fDigitReaderType=kDigitReader32Bit; | |
8c27b00a | 140 | } else { |
141 | HLTError("unknown digit reader type %s", param.Data()); | |
142 | iResult=-EINVAL; | |
143 | } | |
144 | ||
8c27b00a | 145 | break; |
146 | } | |
147 | ||
70d0b23e | 148 | // -rcutrailersize |
149 | if (argument.CompareTo("-rcutrailersize")==0) { | |
150 | if ((bMissingParam=(++i>=argc))) break; | |
151 | char *endptr=NULL; | |
152 | fRcuTrailerSize=strtoul(argv[i], &endptr, 0); | |
153 | if (/*endptr ||*/ fRcuTrailerSize<1) { | |
154 | HLTError("invalid parameter '%s', %s", argv[i], endptr==NULL?"number >= 1 expected":"can not convert string to number"); | |
155 | iResult=-EINVAL; | |
156 | } | |
157 | break; | |
158 | } | |
159 | ||
160 | // -unsorted | |
161 | if (argument.CompareTo("-unsorted")==0) { | |
162 | fUnsorted=true; | |
163 | break; | |
164 | } | |
165 | ||
166 | // -sorted | |
167 | if (argument.CompareTo("-sorted")==0) { | |
168 | fUnsorted=false; | |
169 | break; | |
170 | } | |
7e1566e3 | 171 | |
172 | // -bulk | |
173 | if (argument.CompareTo("-bulk")==0) { | |
174 | fbBulkMode=true; | |
175 | break; | |
176 | } | |
177 | ||
178 | // -stream | |
179 | if (argument.CompareTo("-stream")==0) { | |
180 | fbBulkMode=false; | |
181 | break; | |
182 | } | |
3c835b25 | 183 | } while (0); // just use the do/while here to have the option of breaking |
3e6ec852 | 184 | |
3c835b25 | 185 | if (bMissingParam) iResult=-EPROTO; |
186 | else if (iResult>=0) iResult=i; | |
e1440dab | 187 | |
3e6ec852 | 188 | return iResult; |
189 | } | |
190 | ||
191 | int AliHLTTPCDigitDumpComponent::CloseWriter() | |
192 | { | |
193 | // see header file for class documentation | |
7e1566e3 | 194 | if (fpReader) delete fpReader; |
195 | fpReader=NULL; | |
3e6ec852 | 196 | return 0; |
197 | } | |
198 | ||
199 | int AliHLTTPCDigitDumpComponent::DumpEvent( const AliHLTComponentEventData& evtData, | |
a74855c2 | 200 | const AliHLTComponentBlockData* /*blocks*/, |
00b50bfa | 201 | AliHLTComponentTriggerData& /*trigData*/ ) |
3e6ec852 | 202 | { |
203 | // see header file for class documentation | |
204 | int iResult=0; | |
e1440dab | 205 | int iPrintedSlice=-1; |
206 | int iPrintedPart=-1; | |
207 | int blockno=0; | |
00b50bfa | 208 | const AliHLTComponentBlockData* pDesc=NULL; |
209 | ||
7e1566e3 | 210 | AliHLTTPCDigitReader* pReader=fpReader; |
211 | if (!pReader) return -ENODEV; | |
212 | ||
8c27b00a | 213 | for (pDesc=GetFirstInputBlock(kAliHLTAnyDataType); pDesc!=NULL; pDesc=GetNextInputBlock(), blockno++) { |
32a35f9f | 214 | HLTDebug("event %Lu block %d: %s 0x%08x size %d", evtData.fEventID, blockno, DataType2Text(pDesc->fDataType).c_str(), pDesc->fSpecification, pDesc->fSize); |
8c27b00a | 215 | |
216 | if (fDigitReaderType==kDigitReaderUnpacked && pDesc->fDataType!=AliHLTTPCDefinitions::fgkUnpackedRawDataType) continue; | |
217 | else if (fDigitReaderType!=kDigitReaderUnpacked && pDesc->fDataType!=(kAliHLTDataTypeDDLRaw|kAliHLTDataOriginTPC)) continue; | |
218 | ||
e1440dab | 219 | TString filename; |
00b50bfa | 220 | iResult=BuildFileName(evtData.fEventID, blockno, pDesc->fDataType, pDesc->fSpecification, filename); |
e1440dab | 221 | ios::openmode filemode=(ios::openmode)0; |
222 | if (fCurrentFileName.CompareTo(filename)==0) { | |
223 | // append to the file | |
224 | filemode=ios::app; | |
225 | } else { | |
226 | // store the file for the next block | |
227 | fCurrentFileName=filename; | |
228 | } | |
229 | if (iResult>=0) { | |
230 | ofstream dump(filename.Data(), filemode); | |
231 | if (dump.good()) { | |
00b50bfa | 232 | int part=AliHLTTPCDefinitions::GetMinPatchNr(*pDesc); |
233 | assert(part==AliHLTTPCDefinitions::GetMaxPatchNr(*pDesc)); | |
234 | int slice=AliHLTTPCDefinitions::GetMinSliceNr(*pDesc); | |
235 | assert(slice==AliHLTTPCDefinitions::GetMaxSliceNr(*pDesc)); | |
e1440dab | 236 | int firstRow=AliHLTTPCTransform::GetFirstRow(part); |
237 | int lastRow=AliHLTTPCTransform::GetLastRow(part); | |
7e1566e3 | 238 | |
8c27b00a | 239 | iResult=pReader->InitBlock(pDesc->fPtr,pDesc->fSize,firstRow,lastRow,part,slice); |
e1440dab | 240 | |
241 | int iPrintedRow=-1; | |
242 | int iPrintedPad=-1; | |
243 | int iLastTime=-1; | |
7e1566e3 | 244 | if (fbBulkMode) { |
245 | while (pReader->NextChannel()) { | |
246 | if (PrintHeaders(slice, iPrintedSlice, part, iPrintedPart, pReader, iPrintedRow, iPrintedPad, dump)) { | |
247 | iLastTime=-1; | |
248 | } | |
249 | while (pReader->NextBunch()) { | |
250 | int bunchLength=pReader->GetBunchSize(); | |
deba5d85 | 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 | if(f32BitFormat == kTRUE){ | |
255 | 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 | dump << " Time " << pReader->GetTime()+bunchLength-1 << ": "; | |
260 | for (int bin=bunchLength-1; bin>=0; bin--) { | |
261 | dump << " " << bunchData[bin]; | |
262 | } | |
263 | dump << " -> Time: " << pReader->GetTime() << endl; | |
264 | } | |
265 | else{ | |
266 | const UInt_t* bunchData=pReader->GetSignals(); | |
deba5d85 | 267 | dump << " Time " << pReader->GetTime()+bunchLength-1 << ": "; |
256769f4 | 268 | for (int bin=0; bin<bunchLength; bin++) { |
deba5d85 | 269 | dump << " " << bunchData[bin]; |
270 | } | |
271 | dump << " -> Time: " << pReader->GetTime() << endl; | |
7e1566e3 | 272 | } |
7e1566e3 | 273 | } |
274 | } | |
275 | dump << endl; | |
276 | } else { | |
8c27b00a | 277 | while (pReader->Next()) { |
7c9a4e09 | 278 | if ((iPrintedSlice!=-1 && iLastTime!=-1 && iLastTime!=pReader->GetTime()+1 && iLastTime!=pReader->GetTime()-1)) { |
279 | dump << " -> Time: " << iLastTime << endl; | |
280 | } else if ((iPrintedPad!=-1 && iPrintedPad!=pReader->GetPad()) || | |
281 | (iPrintedRow!=-1 && iPrintedRow!=pReader->GetRow())) { | |
7e1566e3 | 282 | dump << " -> Time: " << iLastTime << endl; |
283 | //dump << endl; | |
32a35f9f | 284 | } |
7c9a4e09 | 285 | |
7e1566e3 | 286 | if (PrintHeaders(slice, iPrintedSlice, part, iPrintedPart, pReader, iPrintedRow, iPrintedPad, dump)) { |
32a35f9f | 287 | iLastTime=-1; |
e1440dab | 288 | } |
7e1566e3 | 289 | if (iLastTime==-1 || (iLastTime!=pReader->GetTime()+1 && iLastTime!=pReader->GetTime()-1)) { |
8c27b00a | 290 | dump << " Time " << pReader->GetTime() << ": "; |
e1440dab | 291 | } |
8c27b00a | 292 | iLastTime=pReader->GetTime(); |
293 | dump << " " << pReader->GetSignal(); | |
e1440dab | 294 | } |
7e1566e3 | 295 | if (iLastTime>=0) dump << " -> Time: " << iLastTime << endl << endl; |
296 | } | |
e1440dab | 297 | } else { |
298 | HLTError("can not open file %s for writing", filename.Data()); | |
299 | iResult=-EBADF; | |
300 | } | |
301 | dump.close(); | |
302 | } | |
7e1566e3 | 303 | pReader->Reset(); |
304 | } | |
305 | return iResult; | |
306 | } | |
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 | assert(pReader); | |
317 | if (iPrintedSlice!=slice || iPrintedPart!=part) { | |
318 | iPrintedSlice=slice; | |
319 | iPrintedPart=part; | |
320 | dump << "====================================================================" << endl; | |
321 | dump << " Slice: " << iPrintedSlice << " Partition: " << iPrintedPart << endl; | |
322 | iPrintedRow=-1; | |
323 | } | |
324 | if (iPrintedRow!=pReader->GetRow()) { | |
325 | iPrintedRow=pReader->GetRow(); | |
326 | dump << "--------------------------------------------------------------------" << endl; | |
327 | dump << "Row: " << iPrintedRow << endl; | |
328 | iPrintedPad=-1; | |
e1440dab | 329 | } |
7e1566e3 | 330 | if (iPrintedPad!=pReader->GetPad()) { |
331 | iPrintedPad=pReader->GetPad(); | |
332 | dump << "Row: " << iPrintedRow << " Pad: " << iPrintedPad << " HW address: " << pReader->GetAltroBlockHWaddr() << endl; | |
333 | iResult=1; | |
334 | } | |
335 | ||
3e6ec852 | 336 | return iResult; |
337 | } |