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