]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/TPCLib/AliHLTTPCDigitDumpComponent.cxx
- abandon TPCLib backward compatibility check for AliRoot releases < v4-03
[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 "AliHLTTPCDefinitions.h"
38
39 #define DefaultRawreaderMode 0
40
41 /** ROOT macro for the implementation of ROOT specific class methods */
42 ClassImp(AliHLTTPCDigitDumpComponent)
43
44 AliHLTTPCDigitDumpComponent::AliHLTTPCDigitDumpComponent()
45   :
46   AliHLTFileWriter(),
47   fRawreaderMode(DefaultRawreaderMode),
48   fDigitReaderType(kDigitReaderRaw)
49 {
50   // see header file for class documentation
51   // or
52   // refer to README to build package
53   // or
54   // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
55 }
56
57 AliHLTTPCDigitDumpComponent::~AliHLTTPCDigitDumpComponent()
58 {
59   // see header file for class documentation
60 }
61
62 const char* AliHLTTPCDigitDumpComponent::GetComponentID()
63 {
64   // see header file for class documentation
65   return "TPCDigitDump";
66 }
67
68 void AliHLTTPCDigitDumpComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list)
69 {
70   // see header file for class documentation
71   list.clear();
72   list.push_back(kAliHLTAnyDataType);
73 }
74
75 AliHLTComponent* AliHLTTPCDigitDumpComponent::Spawn()
76 {
77   // see header file for class documentation
78   return new AliHLTTPCDigitDumpComponent;
79 }
80
81 int AliHLTTPCDigitDumpComponent::InitWriter()
82 {
83   // see header file for class documentation
84   return 0;
85 }
86
87 int AliHLTTPCDigitDumpComponent::ScanArgument(int argc, const char** argv)
88 {
89   // see header file for class documentation
90   int iResult=0;
91   TString argument="";
92   bool bMissingParam=0;
93   int i=0;
94   do {
95     if (i>=argc || (argument=argv[i]).IsNull()) continue;
96
97     // -rawreadermode
98     if (argument.CompareTo("-rawreadermode")==0) {
99       if ((bMissingParam=(++i>=argc))) break;
100       int mode=AliHLTTPCDigitReaderRaw::DecodeMode(argv[i]);
101       if (mode<0) {
102         HLTError("invalid rawreadermode specifier '%s'", argv[i]);
103         iResult=-EINVAL;
104       } else {
105         fRawreaderMode=static_cast<unsigned>(mode);
106       }
107       break;
108     }
109
110     // -digitreader
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;
120       } else {
121         HLTError("unknown digit reader type %s", param.Data());
122         iResult=-EINVAL;
123       }
124
125       if (fDigitReaderType!=kDigitReaderRaw && fRawreaderMode!=DefaultRawreaderMode && iResult>=0) {
126         HLTWarning("the selected digit reader does not support the option \'-rawreadermode\'");
127       }
128
129       break;
130     }
131
132   } while (0); // just use the do/while here to have the option of breaking
133
134   if (bMissingParam) iResult=-EPROTO;
135   else if (iResult>=0) iResult=i;
136
137   return iResult;
138 }
139
140 int AliHLTTPCDigitDumpComponent::CloseWriter()
141 {
142   // see header file for class documentation
143   return 0;
144 }
145
146 int AliHLTTPCDigitDumpComponent::DumpEvent( const AliHLTComponentEventData& evtData,
147                                             const AliHLTComponentBlockData* blocks, 
148                                             AliHLTComponentTriggerData& /*trigData*/ )
149 {
150   // see header file for class documentation
151   int iResult=0;
152   int iPrintedSlice=-1;
153   int iPrintedPart=-1;
154   int blockno=0;
155   const AliHLTComponentBlockData* pDesc=NULL;
156
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);
159
160     if (fDigitReaderType==kDigitReaderUnpacked && pDesc->fDataType!=AliHLTTPCDefinitions::fgkUnpackedRawDataType) continue;
161     else if (fDigitReaderType!=kDigitReaderUnpacked && pDesc->fDataType!=(kAliHLTDataTypeDDLRaw|kAliHLTDataOriginTPC)) continue;
162
163     TString filename;
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
168       filemode=ios::app;
169     } else {
170       // store the file for the next block
171       fCurrentFileName=filename;
172     }
173     if (iResult>=0) {
174       ofstream dump(filename.Data(), filemode);
175       if (dump.good()) {
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; 
187           break;
188         case kDigitReaderPacked:
189           HLTInfo("create DigitReaderPacked");
190           pReader=new AliHLTTPCDigitReaderPacked; 
191           break;
192         case kDigitReaderRaw:
193           HLTInfo("create DigitReaderRaw");
194           pReader=new AliHLTTPCDigitReaderRaw(fRawreaderMode);
195           break;
196         }
197         if (!pReader) {
198           HLTError("can not create digit reader of type %d", fDigitReaderType);
199           iResult=-EFAULT;
200           break;
201         }
202         iResult=pReader->InitBlock(pDesc->fPtr,pDesc->fSize,firstRow,lastRow,part,slice);
203
204         int iPrintedRow=-1;
205         int iPrintedPad=-1;
206         int iLastTime=-1;
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())) {
211             dump << endl;
212           }
213           if (iPrintedSlice!=slice || iPrintedPart!=part) {
214             iPrintedSlice=slice;
215             iPrintedPart=part;
216             dump << "====================================================================" << endl;
217             dump << "    Slice: " << iPrintedSlice << "   Partition: " << iPrintedPart << endl;
218             iPrintedRow=-1;
219           }
220           if (iPrintedRow!=pReader->GetRow()) {
221             iPrintedRow=pReader->GetRow();
222             dump << "--------------------------------------------------------------------" << endl;
223             dump << "Row: " << iPrintedRow << endl;
224             iPrintedPad=-1;
225           }
226           if (iPrintedPad!=pReader->GetPad()) {
227             iPrintedPad=pReader->GetPad();
228             dump << "Row: " << iPrintedRow << "  Pad: " << iPrintedPad << endl;
229             iLastTime=-1;
230           }
231           if (iLastTime!=pReader->GetTime()+1 && iLastTime!=pReader->GetTime()-1 ) {
232             dump << "                     Time " << pReader->GetTime() << ":  ";
233           }
234           iLastTime=pReader->GetTime();
235           dump << "  " << pReader->GetSignal();
236         }
237         dump << endl << endl;
238         delete pReader;
239         pReader=NULL;
240       } else {
241         HLTError("can not open file %s for writing", filename.Data());
242         iResult=-EBADF;
243       }
244       dump.close();
245     }
246   }
247   return iResult;
248 }