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