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 "AliHLTTPCDefinitions.h"
39 #define DefaultRawreaderMode 0
41 /** ROOT macro for the implementation of ROOT specific class methods */
42 ClassImp(AliHLTTPCDigitDumpComponent)
44 AliHLTTPCDigitDumpComponent::AliHLTTPCDigitDumpComponent()
47 fRawreaderMode(DefaultRawreaderMode),
48 fDigitReaderType(kDigitReaderRaw)
50 // see header file for class documentation
52 // refer to README to build package
54 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
57 AliHLTTPCDigitDumpComponent::~AliHLTTPCDigitDumpComponent()
59 // see header file for class documentation
62 const char* AliHLTTPCDigitDumpComponent::GetComponentID()
64 // see header file for class documentation
65 return "TPCDigitDump";
68 void AliHLTTPCDigitDumpComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list)
70 // see header file for class documentation
72 list.push_back(kAliHLTAnyDataType);
75 AliHLTComponent* AliHLTTPCDigitDumpComponent::Spawn()
77 // see header file for class documentation
78 return new AliHLTTPCDigitDumpComponent;
81 int AliHLTTPCDigitDumpComponent::InitWriter()
83 // see header file for class documentation
87 int AliHLTTPCDigitDumpComponent::ScanArgument(int argc, const char** argv)
89 // see header file for class documentation
95 if (i>=argc || (argument=argv[i]).IsNull()) continue;
98 if (argument.CompareTo("-rawreadermode")==0) {
99 if ((bMissingParam=(++i>=argc))) break;
100 int mode=AliHLTTPCDigitReaderRaw::DecodeMode(argv[i]);
102 HLTError("invalid rawreadermode specifier '%s'", argv[i]);
105 fRawreaderMode=static_cast<unsigned>(mode);
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;
121 HLTError("unknown digit reader type %s", param.Data());
125 if (fDigitReaderType!=kDigitReaderRaw && fRawreaderMode!=DefaultRawreaderMode && iResult>=0) {
126 HLTWarning("the selected digit reader does not support the option \'-rawreadermode\'");
132 } while (0); // just use the do/while here to have the option of breaking
134 if (bMissingParam) iResult=-EPROTO;
135 else if (iResult>=0) iResult=i;
140 int AliHLTTPCDigitDumpComponent::CloseWriter()
142 // see header file for class documentation
146 int AliHLTTPCDigitDumpComponent::DumpEvent( const AliHLTComponentEventData& evtData,
147 const AliHLTComponentBlockData* blocks,
148 AliHLTComponentTriggerData& /*trigData*/ )
150 // see header file for class documentation
152 int iPrintedSlice=-1;
155 const AliHLTComponentBlockData* pDesc=NULL;
157 for (pDesc=GetFirstInputBlock(kAliHLTAnyDataType); pDesc!=NULL; pDesc=GetNextInputBlock(), blockno++) {
158 HLTDebug("event %Lu block %d: %s 0x%08x size %d", evtData.fEventID, blockno, DataType2Text(pDesc->fDataType).c_str(), pDesc->fSpecification, pDesc->fSize);
160 if (fDigitReaderType==kDigitReaderUnpacked && pDesc->fDataType!=AliHLTTPCDefinitions::fgkUnpackedRawDataType) continue;
161 else if (fDigitReaderType!=kDigitReaderUnpacked && pDesc->fDataType!=(kAliHLTDataTypeDDLRaw|kAliHLTDataOriginTPC)) continue;
164 iResult=BuildFileName(evtData.fEventID, blockno, pDesc->fDataType, pDesc->fSpecification, filename);
165 ios::openmode filemode=(ios::openmode)0;
166 if (fCurrentFileName.CompareTo(filename)==0) {
167 // append to the file
170 // store the file for the next block
171 fCurrentFileName=filename;
174 ofstream dump(filename.Data(), filemode);
176 int part=AliHLTTPCDefinitions::GetMinPatchNr(*pDesc);
177 assert(part==AliHLTTPCDefinitions::GetMaxPatchNr(*pDesc));
178 int slice=AliHLTTPCDefinitions::GetMinSliceNr(*pDesc);
179 assert(slice==AliHLTTPCDefinitions::GetMaxSliceNr(*pDesc));
180 int firstRow=AliHLTTPCTransform::GetFirstRow(part);
181 int lastRow=AliHLTTPCTransform::GetLastRow(part);
182 AliHLTTPCDigitReader* pReader=NULL;
183 switch (fDigitReaderType) {
184 case kDigitReaderUnpacked:
185 HLTInfo("create DigitReaderUnpacked");
186 pReader=new AliHLTTPCDigitReaderUnpacked;
188 case kDigitReaderPacked:
189 HLTInfo("create DigitReaderPacked");
190 pReader=new AliHLTTPCDigitReaderPacked;
192 case kDigitReaderRaw:
193 HLTInfo("create DigitReaderRaw");
194 pReader=new AliHLTTPCDigitReaderRaw(fRawreaderMode);
198 HLTError("can not create digit reader of type %d", fDigitReaderType);
202 iResult=pReader->InitBlock(pDesc->fPtr,pDesc->fSize,firstRow,lastRow,part,slice);
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())) {
213 if (iPrintedSlice!=slice || iPrintedPart!=part) {
216 dump << "====================================================================" << endl;
217 dump << " Slice: " << iPrintedSlice << " Partition: " << iPrintedPart << endl;
220 if (iPrintedRow!=pReader->GetRow()) {
221 iPrintedRow=pReader->GetRow();
222 dump << "--------------------------------------------------------------------" << endl;
223 dump << "Row: " << iPrintedRow << endl;
226 if (iPrintedPad!=pReader->GetPad()) {
227 iPrintedPad=pReader->GetPad();
228 dump << "Row: " << iPrintedRow << " Pad: " << iPrintedPad << endl;
231 if (iLastTime!=pReader->GetTime()+1 && iLastTime!=pReader->GetTime()-1 ) {
232 dump << " Time " << pReader->GetTime() << ": ";
234 iLastTime=pReader->GetTime();
235 dump << " " << pReader->GetSignal();
237 dump << endl << endl;
241 HLTError("can not open file %s for writing", filename.Data());