3 /**************************************************************************
4 * This file is property of and copyright by the ALICE HLT Project *
5 * ALICE Experiment at CERN, All rights reserved. *
7 * Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no> *
8 * for The ALICE HLT Project. *
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 **************************************************************************/
19 /** @file AliHLTTPCDigitDumpComponent.cxx
20 @author Matthias Richter
22 @brief Special file writer converting TPC digit input to ASCII. */
24 // see header file for class documentation
26 // refer to README to build package
28 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
31 #include "AliHLTTPCDigitDumpComponent.h"
32 #include "AliHLTTPCTransform.h"
33 #include "AliHLTTPCDigitReader.h"
34 #include "AliHLTTPCDigitReaderUnpacked.h"
35 #include "AliHLTTPCDigitReaderPacked.h"
36 #include "AliHLTTPCDigitReaderRaw.h"
37 #include "AliHLTTPCDigitReaderDecoder.h"
38 #include "AliHLTTPCDefinitions.h"
40 #define DefaultRawreaderMode 0
42 /** ROOT macro for the implementation of ROOT specific class methods */
43 ClassImp(AliHLTTPCDigitDumpComponent)
45 AliHLTTPCDigitDumpComponent::AliHLTTPCDigitDumpComponent()
48 fRawreaderMode(DefaultRawreaderMode),
49 fDigitReaderType(kDigitReaderDecoder),
53 // see header file for class documentation
55 // refer to README to build package
57 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
60 AliHLTTPCDigitDumpComponent::~AliHLTTPCDigitDumpComponent()
62 // see header file for class documentation
65 const char* AliHLTTPCDigitDumpComponent::GetComponentID()
67 // see header file for class documentation
68 return "TPCDigitDump";
71 void AliHLTTPCDigitDumpComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list)
73 // see header file for class documentation
75 list.push_back(kAliHLTAnyDataType);
78 AliHLTComponent* AliHLTTPCDigitDumpComponent::Spawn()
80 // see header file for class documentation
81 return new AliHLTTPCDigitDumpComponent;
84 int AliHLTTPCDigitDumpComponent::InitWriter()
86 // see header file for class documentation
90 int AliHLTTPCDigitDumpComponent::ScanArgument(int argc, const char** argv)
92 // see header file for class documentation
98 if (i>=argc || (argument=argv[i]).IsNull()) continue;
101 if (argument.CompareTo("-rawreadermode")==0) {
102 if ((bMissingParam=(++i>=argc))) break;
103 int mode=AliHLTTPCDigitReaderRaw::DecodeMode(argv[i]);
105 HLTError("invalid rawreadermode specifier '%s'", argv[i]);
108 fRawreaderMode=static_cast<unsigned>(mode);
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;
123 } else if (param.CompareTo("decoder", TString::kIgnoreCase)==0) {
124 fDigitReaderType=kDigitReaderDecoder;
126 HLTError("unknown digit reader type %s", param.Data());
130 if (fDigitReaderType!=kDigitReaderRaw && fRawreaderMode!=DefaultRawreaderMode && iResult>=0) {
131 HLTWarning("the selected digit reader does not support the option \'-rawreadermode\'");
138 if (argument.CompareTo("-rcutrailersize")==0) {
139 if ((bMissingParam=(++i>=argc))) break;
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");
150 if (argument.CompareTo("-unsorted")==0) {
156 if (argument.CompareTo("-sorted")==0) {
160 } while (0); // just use the do/while here to have the option of breaking
162 if (bMissingParam) iResult=-EPROTO;
163 else if (iResult>=0) iResult=i;
168 int AliHLTTPCDigitDumpComponent::CloseWriter()
170 // see header file for class documentation
174 int AliHLTTPCDigitDumpComponent::DumpEvent( const AliHLTComponentEventData& evtData,
175 const AliHLTComponentBlockData* /*blocks*/,
176 AliHLTComponentTriggerData& /*trigData*/ )
178 // see header file for class documentation
180 int iPrintedSlice=-1;
183 const AliHLTComponentBlockData* pDesc=NULL;
185 for (pDesc=GetFirstInputBlock(kAliHLTAnyDataType); pDesc!=NULL; pDesc=GetNextInputBlock(), blockno++) {
186 HLTDebug("event %Lu block %d: %s 0x%08x size %d", evtData.fEventID, blockno, DataType2Text(pDesc->fDataType).c_str(), pDesc->fSpecification, pDesc->fSize);
188 if (fDigitReaderType==kDigitReaderUnpacked && pDesc->fDataType!=AliHLTTPCDefinitions::fgkUnpackedRawDataType) continue;
189 else if (fDigitReaderType!=kDigitReaderUnpacked && pDesc->fDataType!=(kAliHLTDataTypeDDLRaw|kAliHLTDataOriginTPC)) continue;
192 iResult=BuildFileName(evtData.fEventID, blockno, pDesc->fDataType, pDesc->fSpecification, filename);
193 ios::openmode filemode=(ios::openmode)0;
194 if (fCurrentFileName.CompareTo(filename)==0) {
195 // append to the file
198 // store the file for the next block
199 fCurrentFileName=filename;
202 ofstream dump(filename.Data(), filemode);
204 int part=AliHLTTPCDefinitions::GetMinPatchNr(*pDesc);
205 assert(part==AliHLTTPCDefinitions::GetMaxPatchNr(*pDesc));
206 int slice=AliHLTTPCDefinitions::GetMinSliceNr(*pDesc);
207 assert(slice==AliHLTTPCDefinitions::GetMaxSliceNr(*pDesc));
208 int firstRow=AliHLTTPCTransform::GetFirstRow(part);
209 int lastRow=AliHLTTPCTransform::GetLastRow(part);
210 AliHLTTPCDigitReader* pReader=NULL;
211 switch (fDigitReaderType) {
212 case kDigitReaderUnpacked:
213 HLTInfo("create DigitReaderUnpacked");
214 pReader=new AliHLTTPCDigitReaderUnpacked;
216 case kDigitReaderPacked:
217 HLTInfo("create DigitReaderPacked");
218 pReader=new AliHLTTPCDigitReaderPacked;
219 if (pReader && fRcuTrailerSize==1) {
220 pReader->SetOldRCUFormat(true);
223 case kDigitReaderRaw:
224 HLTInfo("create DigitReaderRaw");
225 pReader=new AliHLTTPCDigitReaderRaw(fRawreaderMode);
227 case kDigitReaderDecoder:
228 HLTInfo("create DigitReaderDecoder");
229 pReader=new AliHLTTPCDigitReaderDecoder();
233 HLTError("can not create digit reader of type %d", fDigitReaderType);
237 pReader->SetUnsorted(fUnsorted);
238 iResult=pReader->InitBlock(pDesc->fPtr,pDesc->fSize,firstRow,lastRow,part,slice);
243 while (pReader->Next()) {
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())) {
251 if (iPrintedSlice!=slice || iPrintedPart!=part) {
254 dump << "====================================================================" << endl;
255 dump << " Slice: " << iPrintedSlice << " Partition: " << iPrintedPart << endl;
258 if (iPrintedRow!=pReader->GetRow()) {
259 iPrintedRow=pReader->GetRow();
260 dump << "--------------------------------------------------------------------" << endl;
261 dump << "Row: " << iPrintedRow << endl;
264 if (iPrintedPad!=pReader->GetPad()) {
265 iPrintedPad=pReader->GetPad();
266 dump << "Row: " << iPrintedRow << " Pad: " << iPrintedPad << " HW address: " << pReader->GetAltroBlockHWaddr() << endl;
269 if (iLastTime!=pReader->GetTime()+1 && iLastTime!=pReader->GetTime()-1 ) {
270 dump << " Time " << pReader->GetTime() << ": ";
272 iLastTime=pReader->GetTime();
273 dump << " " << pReader->GetSignal();
275 dump << endl << endl;
279 HLTError("can not open file %s for writing", filename.Data());