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 "AliHLTTPCDigitReaderDecoder.h"
37 #include "AliHLTTPCDigitReader32Bit.h"
38 #include "AliHLTTPCDefinitions.h"
40 /** ROOT macro for the implementation of ROOT specific class methods */
41 ClassImp(AliHLTTPCDigitDumpComponent)
43 AliHLTTPCDigitDumpComponent::AliHLTTPCDigitDumpComponent()
46 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
88 switch (fDigitReaderType) {
89 case kDigitReaderUnpacked:
90 HLTInfo("create DigitReaderUnpacked");
91 fpReader=new AliHLTTPCDigitReaderUnpacked;
93 case kDigitReaderPacked:
94 HLTInfo("create DigitReaderPacked");
95 fpReader=new AliHLTTPCDigitReaderPacked;
96 if (fpReader && fRcuTrailerSize==1) {
97 fpReader->SetOldRCUFormat(true);
100 case kDigitReaderRaw:
101 HLTWarning("DigitReaderRaw deprecated, falling back to DigitReaderDecoder");
102 case kDigitReaderDecoder:
103 HLTInfo("create DigitReaderDecoder");
104 fpReader=new AliHLTTPCDigitReaderDecoder();
106 case kDigitReader32Bit:
107 HLTInfo("create DigitReader32Bit");
108 fpReader=new AliHLTTPCDigitReader32Bit();
109 f32BitFormat = kTRUE;
113 HLTError("can not create digit reader of type %d", fDigitReaderType);
116 fpReader->SetUnsorted(fUnsorted);
121 int AliHLTTPCDigitDumpComponent::ScanArgument(int argc, const char** argv)
123 // see header file for class documentation
126 bool bMissingParam=0;
129 if (i>=argc || (argument=argv[i]).IsNull()) continue;
132 if (argument.CompareTo("-rawreadermode")==0) {
133 if ((bMissingParam=(++i>=argc))) break;
134 HLTWarning("argument '-rawreadermode' deprecated");
139 if (argument.CompareTo("-digitreader")==0) {
140 if ((bMissingParam=(++i>=argc))) break;
141 TString param=argv[i];
142 if (param.CompareTo("unpacked", TString::kIgnoreCase)==0) {
143 fDigitReaderType=kDigitReaderUnpacked;
144 } else if (param.CompareTo("packed", TString::kIgnoreCase)==0) {
145 fDigitReaderType=kDigitReaderPacked;
146 } else if (param.CompareTo("raw", TString::kIgnoreCase)==0) {
147 fDigitReaderType=kDigitReaderRaw;
148 } else if (param.CompareTo("decoder", TString::kIgnoreCase)==0) {
149 fDigitReaderType=kDigitReaderDecoder;
150 } else if (param.CompareTo("32bit", TString::kIgnoreCase)==0) {
151 fDigitReaderType=kDigitReader32Bit;
153 HLTError("unknown digit reader type %s", param.Data());
161 if (argument.CompareTo("-rcutrailersize")==0) {
162 if ((bMissingParam=(++i>=argc))) break;
164 fRcuTrailerSize=strtoul(argv[i], &endptr, 0);
165 if (/*endptr ||*/ fRcuTrailerSize<1) {
166 HLTError("invalid parameter '%s', %s", argv[i], endptr==NULL?"number >= 1 expected":"can not convert string to number");
173 if (argument.CompareTo("-unsorted")==0) {
179 if (argument.CompareTo("-sorted")==0) {
185 if (argument.CompareTo("-bulk")==0) {
191 if (argument.CompareTo("-stream")==0) {
195 } while (0); // just use the do/while here to have the option of breaking
197 if (bMissingParam) iResult=-EPROTO;
198 else if (iResult>=0) iResult=i;
203 int AliHLTTPCDigitDumpComponent::CloseWriter()
205 // see header file for class documentation
206 if (fpReader) delete fpReader;
211 int AliHLTTPCDigitDumpComponent::DumpEvent( const AliHLTComponentEventData& evtData,
212 const AliHLTComponentBlockData* /*blocks*/,
213 AliHLTComponentTriggerData& /*trigData*/ )
215 // see header file for class documentation
217 int iPrintedSlice=-1;
220 const AliHLTComponentBlockData* pDesc=NULL;
222 AliHLTTPCDigitReader* pReader=fpReader;
223 if (!pReader) return -ENODEV;
225 for (pDesc=GetFirstInputBlock(kAliHLTAnyDataType); pDesc!=NULL; pDesc=GetNextInputBlock(), blockno++) {
226 HLTDebug("event %Lu block %d: %s 0x%08x size %d", evtData.fEventID, blockno, DataType2Text(pDesc->fDataType).c_str(), pDesc->fSpecification, pDesc->fSize);
228 if (fDigitReaderType==kDigitReaderUnpacked && pDesc->fDataType!=AliHLTTPCDefinitions::fgkUnpackedRawDataType) continue;
229 else if (fDigitReaderType!=kDigitReaderUnpacked && pDesc->fDataType!=(kAliHLTDataTypeDDLRaw|kAliHLTDataOriginTPC)) continue;
232 iResult=BuildFileName(evtData.fEventID, blockno, pDesc->fDataType, pDesc->fSpecification, filename);
233 ios::openmode filemode=(ios::openmode)0;
234 if (fCurrentFileName.CompareTo(filename)==0) {
235 // append to the file
238 // store the file for the next block
239 fCurrentFileName=filename;
242 ofstream dump(filename.Data(), filemode);
244 int part=AliHLTTPCDefinitions::GetMinPatchNr(*pDesc);
245 assert(part==AliHLTTPCDefinitions::GetMaxPatchNr(*pDesc));
246 int slice=AliHLTTPCDefinitions::GetMinSliceNr(*pDesc);
247 assert(slice==AliHLTTPCDefinitions::GetMaxSliceNr(*pDesc));
248 int firstRow=AliHLTTPCTransform::GetFirstRow(part);
249 int lastRow=AliHLTTPCTransform::GetLastRow(part);
251 iResult=pReader->InitBlock(pDesc->fPtr,pDesc->fSize,firstRow,lastRow,part,slice);
257 while (pReader->NextChannel()) {
258 if (PrintHeaders(slice, iPrintedSlice, part, iPrintedPart, pReader, iPrintedRow, iPrintedPad, dump)) {
261 while (pReader->NextBunch()) {
262 int bunchLength=pReader->GetBunchSize();
264 // Kenneth: 20-04-09. The following if have been added because of inconsistency in the 40 bit decoder and the 32 bit decoder.
265 // GetSignals() in the 40 bit decoder returns an array of UInt_t while the 32 bit one returns UShort_t
266 if(f32BitFormat == kTRUE){
267 const UShort_t* bunchData=pReader->GetSignalsShort();
269 // bunch data is printed in 'reverse' order in order to produce
270 // the same output as in stream reading mode
271 dump << " Time " << pReader->GetTime()+bunchLength-1 << ": ";
272 for (int bin=bunchLength-1; bin>=0; bin--) {
273 dump << " " << bunchData[bin];
275 dump << " -> Time: " << pReader->GetTime() << endl;
278 const UInt_t* bunchData=pReader->GetSignals();
279 dump << " Time " << pReader->GetTime()+bunchLength-1 << ": ";
280 for (int bin=0; bin<bunchLength; bin++) {
281 dump << " " << bunchData[bin];
283 dump << " -> Time: " << pReader->GetTime() << endl;
289 while (pReader->Next()) {
290 if ((iPrintedSlice!=-1 && iLastTime!=-1 && iLastTime!=pReader->GetTime()+1 && iLastTime!=pReader->GetTime()-1)) {
291 dump << " -> Time: " << iLastTime << endl;
292 } else if ((iPrintedPad!=-1 && iPrintedPad!=pReader->GetPad()) ||
293 (iPrintedRow!=-1 && iPrintedRow!=pReader->GetRow())) {
294 dump << " -> Time: " << iLastTime << endl;
298 if (PrintHeaders(slice, iPrintedSlice, part, iPrintedPart, pReader, iPrintedRow, iPrintedPad, dump)) {
301 if (iLastTime==-1 || (iLastTime!=pReader->GetTime()+1 && iLastTime!=pReader->GetTime()-1)) {
302 dump << " Time " << pReader->GetTime() << ": ";
304 iLastTime=pReader->GetTime();
305 dump << " " << pReader->GetSignal();
307 if (iLastTime>=0) dump << " -> Time: " << iLastTime << endl << endl;
310 HLTError("can not open file %s for writing", filename.Data());
320 int AliHLTTPCDigitDumpComponent::PrintHeaders(int slice, int &iPrintedSlice,
321 int part, int &iPrintedPart,
322 AliHLTTPCDigitReader* pReader,
323 int &iPrintedRow, int &iPrintedPad,
324 ofstream &dump) const
326 // see header file for class documentation
329 if (iPrintedSlice!=slice || iPrintedPart!=part) {
332 dump << "====================================================================" << endl;
333 dump << " Slice: " << iPrintedSlice << " Partition: " << iPrintedPart << endl;
336 if (iPrintedRow!=pReader->GetRow()) {
337 iPrintedRow=pReader->GetRow();
338 dump << "--------------------------------------------------------------------" << endl;
339 dump << "Row: " << iPrintedRow << endl;
342 if (iPrintedPad!=pReader->GetPad()) {
343 iPrintedPad=pReader->GetPad();
344 dump << "Row: " << iPrintedRow << " Pad: " << iPrintedPad << " HW address: " << pReader->GetAltroBlockHWaddr() << endl;