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