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