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 "AliHLTTPCDigitReader32Bit.h"
36 #include "AliHLTTPCDefinitions.h"
38 /** ROOT macro for the implementation of ROOT specific class methods */
39 ClassImp(AliHLTTPCDigitDumpComponent)
41 AliHLTTPCDigitDumpComponent::AliHLTTPCDigitDumpComponent()
44 fDigitReaderType(kDigitReader32Bit),
51 // see header file for class documentation
53 // refer to README to build package
55 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
58 AliHLTTPCDigitDumpComponent::~AliHLTTPCDigitDumpComponent()
60 // see header file for class documentation
63 const char* AliHLTTPCDigitDumpComponent::GetComponentID()
65 // see header file for class documentation
66 return "TPCDigitDump";
69 void AliHLTTPCDigitDumpComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list)
71 // see header file for class documentation
73 list.push_back(kAliHLTAnyDataType);
76 AliHLTComponent* AliHLTTPCDigitDumpComponent::Spawn()
78 // see header file for class documentation
79 return new AliHLTTPCDigitDumpComponent;
82 int AliHLTTPCDigitDumpComponent::InitWriter()
84 // see header file for class documentation
86 switch (fDigitReaderType) {
87 case kDigitReaderUnpacked:
88 HLTInfo("create DigitReaderUnpacked");
89 fpReader=new AliHLTTPCDigitReaderUnpacked;
91 case kDigitReader32Bit:
92 HLTInfo("create DigitReader32Bit");
93 fpReader=new AliHLTTPCDigitReader32Bit();
98 HLTError("can not create digit reader of type %d", fDigitReaderType);
101 fpReader->SetUnsorted(fUnsorted);
106 int AliHLTTPCDigitDumpComponent::ScanArgument(int argc, const char** argv)
108 // see header file for class documentation
111 bool bMissingParam=0;
114 if (i>=argc || (argument=argv[i]).IsNull()) continue;
117 if (argument.CompareTo("-rawreadermode")==0) {
118 if ((bMissingParam=(++i>=argc))) break;
119 HLTWarning("argument '-rawreadermode' deprecated");
124 if (argument.CompareTo("-digitreader")==0) {
125 if ((bMissingParam=(++i>=argc))) break;
126 TString param=argv[i];
127 if (param.CompareTo("unpacked", TString::kIgnoreCase)==0) {
128 fDigitReaderType=kDigitReaderUnpacked;
129 } else if (param.CompareTo("packed", TString::kIgnoreCase)==0) {
130 HLTWarning("argument 'packed' is deprecated, falling back to DigitReader32Bit");
131 fDigitReaderType=kDigitReader32Bit;
132 } else if (param.CompareTo("raw", TString::kIgnoreCase)==0) {
133 HLTWarning("argument 'raw' is deprecated, falling back to DigitReader32Bit");
134 fDigitReaderType=kDigitReader32Bit;
135 } else if (param.CompareTo("decoder", TString::kIgnoreCase)==0) {
136 HLTWarning("argument 'decoder' is deprecated, falling back to DigitReader32Bit");
137 fDigitReaderType=kDigitReader32Bit;
138 } else if (param.CompareTo("32bit", TString::kIgnoreCase)==0) {
139 fDigitReaderType=kDigitReader32Bit;
141 HLTError("unknown digit reader type %s", param.Data());
149 if (argument.CompareTo("-rcutrailersize")==0) {
150 if ((bMissingParam=(++i>=argc))) break;
152 fRcuTrailerSize=strtoul(argv[i], &endptr, 0);
153 if (/*endptr ||*/ fRcuTrailerSize<1) {
154 HLTError("invalid parameter '%s', %s", argv[i], endptr==NULL?"number >= 1 expected":"can not convert string to number");
161 if (argument.CompareTo("-unsorted")==0) {
167 if (argument.CompareTo("-sorted")==0) {
173 if (argument.CompareTo("-bulk")==0) {
179 if (argument.CompareTo("-stream")==0) {
183 } while (0); // just use the do/while here to have the option of breaking
185 if (bMissingParam) iResult=-EPROTO;
186 else if (iResult>=0) iResult=i;
191 int AliHLTTPCDigitDumpComponent::CloseWriter()
193 // see header file for class documentation
194 if (fpReader) delete fpReader;
199 int AliHLTTPCDigitDumpComponent::DumpEvent( const AliHLTComponentEventData& evtData,
200 const AliHLTComponentBlockData* /*blocks*/,
201 AliHLTComponentTriggerData& /*trigData*/ )
203 // see header file for class documentation
205 int iPrintedSlice=-1;
208 const AliHLTComponentBlockData* pDesc=NULL;
210 AliHLTTPCDigitReader* pReader=fpReader;
211 if (!pReader) return -ENODEV;
213 for (pDesc=GetFirstInputBlock(kAliHLTAnyDataType); pDesc!=NULL; pDesc=GetNextInputBlock(), blockno++) {
214 HLTDebug("event %Lu block %d: %s 0x%08x size %d", evtData.fEventID, blockno, DataType2Text(pDesc->fDataType).c_str(), pDesc->fSpecification, pDesc->fSize);
216 if (fDigitReaderType==kDigitReaderUnpacked && pDesc->fDataType!=AliHLTTPCDefinitions::fgkUnpackedRawDataType) continue;
217 else if (fDigitReaderType!=kDigitReaderUnpacked && pDesc->fDataType!=(kAliHLTDataTypeDDLRaw|kAliHLTDataOriginTPC)) continue;
220 iResult=BuildFileName(evtData.fEventID, blockno, pDesc->fDataType, pDesc->fSpecification, filename);
221 ios::openmode filemode=(ios::openmode)0;
222 if (fCurrentFileName.CompareTo(filename)==0) {
223 // append to the file
226 // store the file for the next block
227 fCurrentFileName=filename;
230 ofstream dump(filename.Data(), filemode);
232 int part=AliHLTTPCDefinitions::GetMinPatchNr(*pDesc);
233 assert(part==AliHLTTPCDefinitions::GetMaxPatchNr(*pDesc));
234 int slice=AliHLTTPCDefinitions::GetMinSliceNr(*pDesc);
235 assert(slice==AliHLTTPCDefinitions::GetMaxSliceNr(*pDesc));
236 int firstRow=AliHLTTPCTransform::GetFirstRow(part);
237 int lastRow=AliHLTTPCTransform::GetLastRow(part);
239 iResult=pReader->InitBlock(pDesc->fPtr,pDesc->fSize,firstRow,lastRow,part,slice);
245 while (pReader->NextChannel()) {
246 if (PrintHeaders(slice, iPrintedSlice, part, iPrintedPart, pReader, iPrintedRow, iPrintedPad, dump)) {
249 while (pReader->NextBunch()) {
250 int bunchLength=pReader->GetBunchSize();
252 // Kenneth: 20-04-09. The following if have been added because of inconsistency in the 40 bit decoder and the 32 bit decoder.
253 // GetSignals() in the 40 bit decoder returns an array of UInt_t while the 32 bit one returns UShort_t
254 if(f32BitFormat == kTRUE){
255 const UShort_t* bunchData=pReader->GetSignalsShort();
257 // bunch data is printed in 'reverse' order in order to produce
258 // the same output as in stream reading mode
259 dump << " Time " << pReader->GetTime()+bunchLength-1 << ": ";
260 for (int bin=bunchLength-1; bin>=0; bin--) {
261 dump << " " << bunchData[bin];
263 dump << " -> Time: " << pReader->GetTime() << endl;
266 const UInt_t* bunchData=pReader->GetSignals();
267 dump << " Time " << pReader->GetTime()+bunchLength-1 << ": ";
268 for (int bin=0; bin<bunchLength; bin++) {
269 dump << " " << bunchData[bin];
271 dump << " -> Time: " << pReader->GetTime() << endl;
277 while (pReader->Next()) {
278 if ((iPrintedSlice!=-1 && iLastTime!=-1 && iLastTime!=pReader->GetTime()+1 && iLastTime!=pReader->GetTime()-1)) {
279 dump << " -> Time: " << iLastTime << endl;
280 } else if ((iPrintedPad!=-1 && iPrintedPad!=pReader->GetPad()) ||
281 (iPrintedRow!=-1 && iPrintedRow!=pReader->GetRow())) {
282 dump << " -> Time: " << iLastTime << endl;
286 if (PrintHeaders(slice, iPrintedSlice, part, iPrintedPart, pReader, iPrintedRow, iPrintedPad, dump)) {
289 if (iLastTime==-1 || (iLastTime!=pReader->GetTime()+1 && iLastTime!=pReader->GetTime()-1)) {
290 dump << " Time " << pReader->GetTime() << ": ";
292 iLastTime=pReader->GetTime();
293 dump << " " << pReader->GetSignal();
295 if (iLastTime>=0) dump << " -> Time: " << iLastTime << endl << endl;
298 HLTError("can not open file %s for writing", filename.Data());
308 int AliHLTTPCDigitDumpComponent::PrintHeaders(int slice, int &iPrintedSlice,
309 int part, int &iPrintedPart,
310 AliHLTTPCDigitReader* pReader,
311 int &iPrintedRow, int &iPrintedPad,
312 ofstream &dump) const
314 // see header file for class documentation
317 if (iPrintedSlice!=slice || iPrintedPart!=part) {
320 dump << "====================================================================" << endl;
321 dump << " Slice: " << iPrintedSlice << " Partition: " << iPrintedPart << endl;
324 if (iPrintedRow!=pReader->GetRow()) {
325 iPrintedRow=pReader->GetRow();
326 dump << "--------------------------------------------------------------------" << endl;
327 dump << "Row: " << iPrintedRow << endl;
330 if (iPrintedPad!=pReader->GetPad()) {
331 iPrintedPad=pReader->GetPad();
332 dump << "Row: " << iPrintedRow << " Pad: " << iPrintedPad << " HW address: " << pReader->GetAltroBlockHWaddr() << endl;