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 "AliHLTTPCDefinitions.h"
39 /** ROOT macro for the implementation of ROOT specific class methods */
40 ClassImp(AliHLTTPCDigitDumpComponent)
42 AliHLTTPCDigitDumpComponent::AliHLTTPCDigitDumpComponent()
45 fDigitReaderType(kDigitReaderDecoder),
49 // see header file for class documentation
51 // refer to README to build package
53 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
56 AliHLTTPCDigitDumpComponent::~AliHLTTPCDigitDumpComponent()
58 // see header file for class documentation
61 const char* AliHLTTPCDigitDumpComponent::GetComponentID()
63 // see header file for class documentation
64 return "TPCDigitDump";
67 void AliHLTTPCDigitDumpComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list)
69 // see header file for class documentation
71 list.push_back(kAliHLTAnyDataType);
74 AliHLTComponent* AliHLTTPCDigitDumpComponent::Spawn()
76 // see header file for class documentation
77 return new AliHLTTPCDigitDumpComponent;
80 int AliHLTTPCDigitDumpComponent::InitWriter()
82 // see header file for class documentation
86 int AliHLTTPCDigitDumpComponent::ScanArgument(int argc, const char** argv)
88 // see header file for class documentation
94 if (i>=argc || (argument=argv[i]).IsNull()) continue;
97 if (argument.CompareTo("-rawreadermode")==0) {
98 if ((bMissingParam=(++i>=argc))) break;
99 HLTWarning("argument '-rawreadermode' deprecated");
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;
113 } else if (param.CompareTo("decoder", TString::kIgnoreCase)==0) {
114 fDigitReaderType=kDigitReaderDecoder;
116 HLTError("unknown digit reader type %s", param.Data());
124 if (argument.CompareTo("-rcutrailersize")==0) {
125 if ((bMissingParam=(++i>=argc))) break;
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");
136 if (argument.CompareTo("-unsorted")==0) {
142 if (argument.CompareTo("-sorted")==0) {
146 } while (0); // just use the do/while here to have the option of breaking
148 if (bMissingParam) iResult=-EPROTO;
149 else if (iResult>=0) iResult=i;
154 int AliHLTTPCDigitDumpComponent::CloseWriter()
156 // see header file for class documentation
160 int AliHLTTPCDigitDumpComponent::DumpEvent( const AliHLTComponentEventData& evtData,
161 const AliHLTComponentBlockData* /*blocks*/,
162 AliHLTComponentTriggerData& /*trigData*/ )
164 // see header file for class documentation
166 int iPrintedSlice=-1;
169 const AliHLTComponentBlockData* pDesc=NULL;
171 for (pDesc=GetFirstInputBlock(kAliHLTAnyDataType); pDesc!=NULL; pDesc=GetNextInputBlock(), blockno++) {
172 HLTDebug("event %Lu block %d: %s 0x%08x size %d", evtData.fEventID, blockno, DataType2Text(pDesc->fDataType).c_str(), pDesc->fSpecification, pDesc->fSize);
174 if (fDigitReaderType==kDigitReaderUnpacked && pDesc->fDataType!=AliHLTTPCDefinitions::fgkUnpackedRawDataType) continue;
175 else if (fDigitReaderType!=kDigitReaderUnpacked && pDesc->fDataType!=(kAliHLTDataTypeDDLRaw|kAliHLTDataOriginTPC)) continue;
178 iResult=BuildFileName(evtData.fEventID, blockno, pDesc->fDataType, pDesc->fSpecification, filename);
179 ios::openmode filemode=(ios::openmode)0;
180 if (fCurrentFileName.CompareTo(filename)==0) {
181 // append to the file
184 // store the file for the next block
185 fCurrentFileName=filename;
188 ofstream dump(filename.Data(), filemode);
190 int part=AliHLTTPCDefinitions::GetMinPatchNr(*pDesc);
191 assert(part==AliHLTTPCDefinitions::GetMaxPatchNr(*pDesc));
192 int slice=AliHLTTPCDefinitions::GetMinSliceNr(*pDesc);
193 assert(slice==AliHLTTPCDefinitions::GetMaxSliceNr(*pDesc));
194 int firstRow=AliHLTTPCTransform::GetFirstRow(part);
195 int lastRow=AliHLTTPCTransform::GetLastRow(part);
196 AliHLTTPCDigitReader* pReader=NULL;
197 switch (fDigitReaderType) {
198 case kDigitReaderUnpacked:
199 HLTInfo("create DigitReaderUnpacked");
200 pReader=new AliHLTTPCDigitReaderUnpacked;
202 case kDigitReaderPacked:
203 HLTInfo("create DigitReaderPacked");
204 pReader=new AliHLTTPCDigitReaderPacked;
205 if (pReader && fRcuTrailerSize==1) {
206 pReader->SetOldRCUFormat(true);
209 case kDigitReaderRaw:
210 HLTWarning("DigitReaderRaw deprecated, falling back to DigitReaderDecoder");
211 case kDigitReaderDecoder:
212 HLTInfo("create DigitReaderDecoder");
213 pReader=new AliHLTTPCDigitReaderDecoder();
217 HLTError("can not create digit reader of type %d", fDigitReaderType);
221 pReader->SetUnsorted(fUnsorted);
222 iResult=pReader->InitBlock(pDesc->fPtr,pDesc->fSize,firstRow,lastRow,part,slice);
227 while (pReader->Next()) {
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())) {
235 if (iPrintedSlice!=slice || iPrintedPart!=part) {
238 dump << "====================================================================" << endl;
239 dump << " Slice: " << iPrintedSlice << " Partition: " << iPrintedPart << endl;
242 if (iPrintedRow!=pReader->GetRow()) {
243 iPrintedRow=pReader->GetRow();
244 dump << "--------------------------------------------------------------------" << endl;
245 dump << "Row: " << iPrintedRow << endl;
248 if (iPrintedPad!=pReader->GetPad()) {
249 iPrintedPad=pReader->GetPad();
250 dump << "Row: " << iPrintedRow << " Pad: " << iPrintedPad << " HW address: " << pReader->GetAltroBlockHWaddr() << endl;
253 if (iLastTime!=pReader->GetTime()+1 && iLastTime!=pReader->GetTime()-1 ) {
254 dump << " Time " << pReader->GetTime() << ": ";
256 iLastTime=pReader->GetTime();
257 dump << " " << pReader->GetSignal();
259 dump << endl << endl;
263 HLTError("can not open file %s for writing", filename.Data());