]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/TPCLib/AliHLTTPCDigitDumpComponent.cxx
changes by Kenneth
[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 "AliHLTTPCDigitReaderRaw.h"
37 #include "AliHLTTPCDigitReaderDecoder.h"
38 #include "AliHLTTPCDefinitions.h"
39
40 #define DefaultRawreaderMode 0
41
42 /** ROOT macro for the implementation of ROOT specific class methods */
43 ClassImp(AliHLTTPCDigitDumpComponent)
44
45 AliHLTTPCDigitDumpComponent::AliHLTTPCDigitDumpComponent()
46   :
47   AliHLTFileWriter(),
48   fRawreaderMode(DefaultRawreaderMode),
49   fDigitReaderType(kDigitReaderDecoder),
50   fRcuTrailerSize(2),
51   fUnsorted(false)
52 {
53   // see header file for class documentation
54   // or
55   // refer to README to build package
56   // or
57   // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
58 }
59
60 AliHLTTPCDigitDumpComponent::~AliHLTTPCDigitDumpComponent()
61 {
62   // see header file for class documentation
63 }
64
65 const char* AliHLTTPCDigitDumpComponent::GetComponentID()
66 {
67   // see header file for class documentation
68   return "TPCDigitDump";
69 }
70
71 void AliHLTTPCDigitDumpComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list)
72 {
73   // see header file for class documentation
74   list.clear();
75   list.push_back(kAliHLTAnyDataType);
76 }
77
78 AliHLTComponent* AliHLTTPCDigitDumpComponent::Spawn()
79 {
80   // see header file for class documentation
81   return new AliHLTTPCDigitDumpComponent;
82 }
83
84 int AliHLTTPCDigitDumpComponent::InitWriter()
85 {
86   // see header file for class documentation
87   return 0;
88 }
89
90 int AliHLTTPCDigitDumpComponent::ScanArgument(int argc, const char** argv)
91 {
92   // see header file for class documentation
93   int iResult=0;
94   TString argument="";
95   bool bMissingParam=0;
96   int i=0;
97   do {
98     if (i>=argc || (argument=argv[i]).IsNull()) continue;
99
100     // -rawreadermode
101     if (argument.CompareTo("-rawreadermode")==0) {
102       if ((bMissingParam=(++i>=argc))) break;
103       int mode=AliHLTTPCDigitReaderRaw::DecodeMode(argv[i]);
104       if (mode<0) {
105         HLTError("invalid rawreadermode specifier '%s'", argv[i]);
106         iResult=-EINVAL;
107       } else {
108         fRawreaderMode=static_cast<unsigned>(mode);
109       }
110       break;
111     }
112
113     // -digitreader
114     if (argument.CompareTo("-digitreader")==0) {
115       if ((bMissingParam=(++i>=argc))) break;
116       TString param=argv[i];
117       if (param.CompareTo("unpacked", TString::kIgnoreCase)==0) {
118         fDigitReaderType=kDigitReaderUnpacked;
119       } else if (param.CompareTo("packed", TString::kIgnoreCase)==0) {
120         fDigitReaderType=kDigitReaderPacked;
121       } else if (param.CompareTo("raw", TString::kIgnoreCase)==0) {
122         fDigitReaderType=kDigitReaderRaw;
123       } else if (param.CompareTo("decoder", TString::kIgnoreCase)==0) {
124         fDigitReaderType=kDigitReaderDecoder;
125       } else {
126         HLTError("unknown digit reader type %s", param.Data());
127         iResult=-EINVAL;
128       }
129
130       if (fDigitReaderType!=kDigitReaderRaw && fRawreaderMode!=DefaultRawreaderMode && iResult>=0) {
131         HLTWarning("the selected digit reader does not support the option \'-rawreadermode\'");
132       }
133
134       break;
135     }
136
137     // -rcutrailersize
138     if (argument.CompareTo("-rcutrailersize")==0) {
139       if ((bMissingParam=(++i>=argc))) break;
140       char *endptr=NULL;
141       fRcuTrailerSize=strtoul(argv[i], &endptr, 0);
142       if (/*endptr ||*/ fRcuTrailerSize<1) {
143         HLTError("invalid parameter '%s', %s", argv[i], endptr==NULL?"number >= 1 expected":"can not convert string to number");
144         iResult=-EINVAL;
145       }
146       break;
147     }
148
149     // -unsorted
150     if (argument.CompareTo("-unsorted")==0) {
151       fUnsorted=true;
152       break;
153     }
154
155     // -sorted
156     if (argument.CompareTo("-sorted")==0) {
157       fUnsorted=false;
158       break;
159     }
160   } while (0); // just use the do/while here to have the option of breaking
161
162   if (bMissingParam) iResult=-EPROTO;
163   else if (iResult>=0) iResult=i;
164
165   return iResult;
166 }
167
168 int AliHLTTPCDigitDumpComponent::CloseWriter()
169 {
170   // see header file for class documentation
171   return 0;
172 }
173
174 int AliHLTTPCDigitDumpComponent::DumpEvent( const AliHLTComponentEventData& evtData,
175                                             const AliHLTComponentBlockData* /*blocks*/, 
176                                             AliHLTComponentTriggerData& /*trigData*/ )
177 {
178   // see header file for class documentation
179   int iResult=0;
180   int iPrintedSlice=-1;
181   int iPrintedPart=-1;
182   int blockno=0;
183   const AliHLTComponentBlockData* pDesc=NULL;
184
185   for (pDesc=GetFirstInputBlock(kAliHLTAnyDataType); pDesc!=NULL; pDesc=GetNextInputBlock(), blockno++) {
186     HLTDebug("event %Lu block %d: %s 0x%08x size %d", evtData.fEventID, blockno, DataType2Text(pDesc->fDataType).c_str(), pDesc->fSpecification, pDesc->fSize);
187
188     if (fDigitReaderType==kDigitReaderUnpacked && pDesc->fDataType!=AliHLTTPCDefinitions::fgkUnpackedRawDataType) continue;
189     else if (fDigitReaderType!=kDigitReaderUnpacked && pDesc->fDataType!=(kAliHLTDataTypeDDLRaw|kAliHLTDataOriginTPC)) continue;
190
191     TString filename;
192     iResult=BuildFileName(evtData.fEventID, blockno, pDesc->fDataType, pDesc->fSpecification, filename);
193     ios::openmode filemode=(ios::openmode)0;
194     if (fCurrentFileName.CompareTo(filename)==0) {
195       // append to the file
196       filemode=ios::app;
197     } else {
198       // store the file for the next block
199       fCurrentFileName=filename;
200     }
201     if (iResult>=0) {
202       ofstream dump(filename.Data(), filemode);
203       if (dump.good()) {
204         int part=AliHLTTPCDefinitions::GetMinPatchNr(*pDesc);
205         assert(part==AliHLTTPCDefinitions::GetMaxPatchNr(*pDesc));
206         int slice=AliHLTTPCDefinitions::GetMinSliceNr(*pDesc);
207         assert(slice==AliHLTTPCDefinitions::GetMaxSliceNr(*pDesc));
208         int firstRow=AliHLTTPCTransform::GetFirstRow(part);
209         int lastRow=AliHLTTPCTransform::GetLastRow(part);
210         AliHLTTPCDigitReader* pReader=NULL;
211         switch (fDigitReaderType) {
212         case kDigitReaderUnpacked:
213           HLTInfo("create DigitReaderUnpacked");
214           pReader=new AliHLTTPCDigitReaderUnpacked; 
215           break;
216         case kDigitReaderPacked:
217           HLTInfo("create DigitReaderPacked");
218           pReader=new AliHLTTPCDigitReaderPacked; 
219           if (pReader && fRcuTrailerSize==1) {
220             pReader->SetOldRCUFormat(true);
221           }
222           break;
223         case kDigitReaderRaw:
224           HLTInfo("create DigitReaderRaw");
225           pReader=new AliHLTTPCDigitReaderRaw(fRawreaderMode);
226           break;
227         case kDigitReaderDecoder:
228           HLTInfo("create DigitReaderDecoder");
229           pReader=new AliHLTTPCDigitReaderDecoder();
230           break;
231         }
232         if (!pReader) {
233           HLTError("can not create digit reader of type %d", fDigitReaderType);
234           iResult=-EFAULT;
235           break;
236         }
237         pReader->SetUnsorted(fUnsorted);
238         iResult=pReader->InitBlock(pDesc->fPtr,pDesc->fSize,firstRow,lastRow,part,slice);
239
240         int iPrintedRow=-1;
241         int iPrintedPad=-1;
242         int iLastTime=-1;
243         while (pReader->Next()) {
244           if ((iPrintedSlice!=-1 && iLastTime!=-1 && iLastTime!=pReader->GetTime()+1 && iLastTime!=pReader->GetTime()-1)) {
245             dump << "    -> Time: " << iLastTime << endl;
246           } else if ((iPrintedPad!=-1 && iPrintedPad!=pReader->GetPad()) ||
247                      (iPrintedRow!=-1 && iPrintedRow!=pReader->GetRow())) {
248             dump << endl;
249           }
250
251           if (iPrintedSlice!=slice || iPrintedPart!=part) {
252             iPrintedSlice=slice;
253             iPrintedPart=part;
254             dump << "====================================================================" << endl;
255             dump << "    Slice: " << iPrintedSlice << "   Partition: " << iPrintedPart << endl;
256             iPrintedRow=-1;
257           }
258           if (iPrintedRow!=pReader->GetRow()) {
259             iPrintedRow=pReader->GetRow();
260             dump << "--------------------------------------------------------------------" << endl;
261             dump << "Row: " << iPrintedRow << endl;
262             iPrintedPad=-1;
263           }
264           if (iPrintedPad!=pReader->GetPad()) {
265             iPrintedPad=pReader->GetPad();
266             dump << "Row: " << iPrintedRow << "  Pad: " << iPrintedPad << "  HW address: " << pReader->GetAltroBlockHWaddr() << endl;
267             iLastTime=-1;
268           }
269           if (iLastTime!=pReader->GetTime()+1 && iLastTime!=pReader->GetTime()-1 ) {
270             dump << "                     Time " << pReader->GetTime() << ":  ";
271           }
272           iLastTime=pReader->GetTime();
273           dump << "  " << pReader->GetSignal();
274         }
275         dump << endl << endl;
276         delete pReader;
277         pReader=NULL;
278       } else {
279         HLTError("can not open file %s for writing", filename.Data());
280         iResult=-EBADF;
281       }
282       dump.close();
283     }
284   }
285   return iResult;
286 }