]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/TPCLib/AliHLTTPCDigitDumpComponent.cxx
added test macro for external interface
[u/mrichter/AliRoot.git] / HLT / TPCLib / AliHLTTPCDigitDumpComponent.cxx
1 // $Id$
2
3 /**************************************************************************
4  * This file is property of and copyright by the ALICE HLT Project        * 
5  * ALICE Experiment at CERN, All rights reserved.                         *
6  *                                                                        *
7  * Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no>        *
8  *                  for The ALICE HLT Project.                            *
9  *                                                                        *
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  **************************************************************************/
18
19 /** @file   AliHLTTPCDigitDumpComponent.cxx
20     @author Matthias Richter
21     @date   
22     @brief  Special file writer converting TPC digit input to ASCII. */
23
24 // see header file for class documentation
25 // or
26 // refer to README to build package
27 // or
28 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
29
30 #include <cassert>
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"
38
39 /** ROOT macro for the implementation of ROOT specific class methods */
40 ClassImp(AliHLTTPCDigitDumpComponent)
41
42 AliHLTTPCDigitDumpComponent::AliHLTTPCDigitDumpComponent()
43   :
44   AliHLTFileWriter(),
45   fDigitReaderType(kDigitReaderDecoder),
46   fRcuTrailerSize(2),
47   fUnsorted(false)
48 {
49   // see header file for class documentation
50   // or
51   // refer to README to build package
52   // or
53   // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
54 }
55
56 AliHLTTPCDigitDumpComponent::~AliHLTTPCDigitDumpComponent()
57 {
58   // see header file for class documentation
59 }
60
61 const char* AliHLTTPCDigitDumpComponent::GetComponentID()
62 {
63   // see header file for class documentation
64   return "TPCDigitDump";
65 }
66
67 void AliHLTTPCDigitDumpComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list)
68 {
69   // see header file for class documentation
70   list.clear();
71   list.push_back(kAliHLTAnyDataType);
72 }
73
74 AliHLTComponent* AliHLTTPCDigitDumpComponent::Spawn()
75 {
76   // see header file for class documentation
77   return new AliHLTTPCDigitDumpComponent;
78 }
79
80 int AliHLTTPCDigitDumpComponent::InitWriter()
81 {
82   // see header file for class documentation
83   return 0;
84 }
85
86 int AliHLTTPCDigitDumpComponent::ScanArgument(int argc, const char** argv)
87 {
88   // see header file for class documentation
89   int iResult=0;
90   TString argument="";
91   bool bMissingParam=0;
92   int i=0;
93   do {
94     if (i>=argc || (argument=argv[i]).IsNull()) continue;
95
96     // -rawreadermode
97     if (argument.CompareTo("-rawreadermode")==0) {
98       if ((bMissingParam=(++i>=argc))) break;
99       HLTWarning("argument '-rawreadermode' deprecated");
100       break;
101     }
102
103     // -digitreader
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;
115       } else {
116         HLTError("unknown digit reader type %s", param.Data());
117         iResult=-EINVAL;
118       }
119
120       break;
121     }
122
123     // -rcutrailersize
124     if (argument.CompareTo("-rcutrailersize")==0) {
125       if ((bMissingParam=(++i>=argc))) break;
126       char *endptr=NULL;
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");
130         iResult=-EINVAL;
131       }
132       break;
133     }
134
135     // -unsorted
136     if (argument.CompareTo("-unsorted")==0) {
137       fUnsorted=true;
138       break;
139     }
140
141     // -sorted
142     if (argument.CompareTo("-sorted")==0) {
143       fUnsorted=false;
144       break;
145     }
146   } while (0); // just use the do/while here to have the option of breaking
147
148   if (bMissingParam) iResult=-EPROTO;
149   else if (iResult>=0) iResult=i;
150
151   return iResult;
152 }
153
154 int AliHLTTPCDigitDumpComponent::CloseWriter()
155 {
156   // see header file for class documentation
157   return 0;
158 }
159
160 int AliHLTTPCDigitDumpComponent::DumpEvent( const AliHLTComponentEventData& evtData,
161                                             const AliHLTComponentBlockData* /*blocks*/, 
162                                             AliHLTComponentTriggerData& /*trigData*/ )
163 {
164   // see header file for class documentation
165   int iResult=0;
166   int iPrintedSlice=-1;
167   int iPrintedPart=-1;
168   int blockno=0;
169   const AliHLTComponentBlockData* pDesc=NULL;
170
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);
173
174     if (fDigitReaderType==kDigitReaderUnpacked && pDesc->fDataType!=AliHLTTPCDefinitions::fgkUnpackedRawDataType) continue;
175     else if (fDigitReaderType!=kDigitReaderUnpacked && pDesc->fDataType!=(kAliHLTDataTypeDDLRaw|kAliHLTDataOriginTPC)) continue;
176
177     TString filename;
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
182       filemode=ios::app;
183     } else {
184       // store the file for the next block
185       fCurrentFileName=filename;
186     }
187     if (iResult>=0) {
188       ofstream dump(filename.Data(), filemode);
189       if (dump.good()) {
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; 
201           break;
202         case kDigitReaderPacked:
203           HLTInfo("create DigitReaderPacked");
204           pReader=new AliHLTTPCDigitReaderPacked; 
205           if (pReader && fRcuTrailerSize==1) {
206             pReader->SetOldRCUFormat(true);
207           }
208           break;
209         case kDigitReaderRaw:
210           HLTWarning("DigitReaderRaw deprecated, falling back to DigitReaderDecoder");
211         case kDigitReaderDecoder:
212           HLTInfo("create DigitReaderDecoder");
213           pReader=new AliHLTTPCDigitReaderDecoder();
214           break;
215         }
216         if (!pReader) {
217           HLTError("can not create digit reader of type %d", fDigitReaderType);
218           iResult=-EFAULT;
219           break;
220         }
221         pReader->SetUnsorted(fUnsorted);
222         iResult=pReader->InitBlock(pDesc->fPtr,pDesc->fSize,firstRow,lastRow,part,slice);
223
224         int iPrintedRow=-1;
225         int iPrintedPad=-1;
226         int iLastTime=-1;
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())) {
232             dump << endl;
233           }
234
235           if (iPrintedSlice!=slice || iPrintedPart!=part) {
236             iPrintedSlice=slice;
237             iPrintedPart=part;
238             dump << "====================================================================" << endl;
239             dump << "    Slice: " << iPrintedSlice << "   Partition: " << iPrintedPart << endl;
240             iPrintedRow=-1;
241           }
242           if (iPrintedRow!=pReader->GetRow()) {
243             iPrintedRow=pReader->GetRow();
244             dump << "--------------------------------------------------------------------" << endl;
245             dump << "Row: " << iPrintedRow << endl;
246             iPrintedPad=-1;
247           }
248           if (iPrintedPad!=pReader->GetPad()) {
249             iPrintedPad=pReader->GetPad();
250             dump << "Row: " << iPrintedRow << "  Pad: " << iPrintedPad << "  HW address: " << pReader->GetAltroBlockHWaddr() << endl;
251             iLastTime=-1;
252           }
253           if (iLastTime!=pReader->GetTime()+1 && iLastTime!=pReader->GetTime()-1 ) {
254             dump << "                     Time " << pReader->GetTime() << ":  ";
255           }
256           iLastTime=pReader->GetTime();
257           dump << "  " << pReader->GetSignal();
258         }
259         dump << endl << endl;
260         delete pReader;
261         pReader=NULL;
262       } else {
263         HLTError("can not open file %s for writing", filename.Data());
264         iResult=-EBADF;
265       }
266       dump.close();
267     }
268   }
269   return iResult;
270 }