]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/TPCLib/AliHLTTPCDigitDumpComponent.cxx
minor bugfix in argument scanning
[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 "AliHLTTPCDigitReaderRaw.h"
34 #include "AliHLTTPCDefinitions.h"
35
36 /** ROOT macro for the implementation of ROOT specific class methods */
37 ClassImp(AliHLTTPCDigitDumpComponent)
38
39 AliHLTTPCDigitDumpComponent::AliHLTTPCDigitDumpComponent()
40   :
41   AliHLTFileWriter(),
42   fRawreaderMode(0)
43 {
44   // see header file for class documentation
45   // or
46   // refer to README to build package
47   // or
48   // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
49 }
50
51 AliHLTTPCDigitDumpComponent::~AliHLTTPCDigitDumpComponent()
52 {
53   // see header file for class documentation
54 }
55
56 const char* AliHLTTPCDigitDumpComponent::GetComponentID()
57 {
58   // see header file for class documentation
59   return "TPCDigitDump";
60 }
61
62 void AliHLTTPCDigitDumpComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list)
63 {
64   // see header file for class documentation
65   list.clear();
66   list.push_back(kAliHLTAnyDataType);
67 }
68
69 AliHLTComponent* AliHLTTPCDigitDumpComponent::Spawn()
70 {
71   // see header file for class documentation
72   return new AliHLTTPCDigitDumpComponent;
73 }
74
75 int AliHLTTPCDigitDumpComponent::InitWriter()
76 {
77   // see header file for class documentation
78   return 0;
79 }
80
81 int AliHLTTPCDigitDumpComponent::ScanArgument(int argc, const char** argv)
82 {
83   // see header file for class documentation
84   int iResult=0;
85   TString argument="";
86   bool bMissingParam=0;
87   int i=0;
88   do {
89     if (i>=argc || (argument=argv[i]).IsNull()) continue;
90
91     // -rawreadermode
92     if (argument.CompareTo("-rawreadermode")==0) {
93       if ((bMissingParam=(++i>=argc))) break;
94       int mode=AliHLTTPCDigitReaderRaw::DecodeMode(argv[i]);
95       if (mode<0) {
96         HLTError("invalid rawreadermode specifier '%s'", argv[i]);
97         iResult=-EINVAL;
98       } else {
99         fRawreaderMode=static_cast<unsigned>(mode);
100       }
101     }
102   } while (0); // just use the do/while here to have the option of breaking
103
104   if (bMissingParam) iResult=-EPROTO;
105   else if (iResult>=0) iResult=i;
106
107   return iResult;
108 }
109
110 int AliHLTTPCDigitDumpComponent::CloseWriter()
111 {
112   // see header file for class documentation
113   return 0;
114 }
115
116 int AliHLTTPCDigitDumpComponent::DumpEvent( const AliHLTComponentEventData& evtData,
117                                             const AliHLTComponentBlockData* blocks, 
118                                             AliHLTComponentTriggerData& /*trigData*/ )
119 {
120   // see header file for class documentation
121   int iResult=0;
122   int iPrintedSlice=-1;
123   int iPrintedPart=-1;
124   int blockno=0;
125   const AliHLTComponentBlockData* pDesc=NULL;
126
127   for (pDesc=GetFirstInputBlock(kAliHLTDataTypeDDLRaw|kAliHLTDataOriginTPC); pDesc!=NULL; pDesc=GetNextInputBlock(), blockno++) {
128     HLTDebug("event %Lu block %d: %s 0x%08x size %d", evtData.fEventID, blockno, DataType2Text(pDesc->fDataType).c_str(), pDesc->fSpecification, pDesc->fSize);
129     TString filename;
130     iResult=BuildFileName(evtData.fEventID, blockno, pDesc->fDataType, pDesc->fSpecification, filename);
131     ios::openmode filemode=(ios::openmode)0;
132     if (fCurrentFileName.CompareTo(filename)==0) {
133       // append to the file
134       filemode=ios::app;
135     } else {
136       // store the file for the next block
137       fCurrentFileName=filename;
138     }
139     if (iResult>=0) {
140       ofstream dump(filename.Data(), filemode);
141       if (dump.good()) {
142         int part=AliHLTTPCDefinitions::GetMinPatchNr(*pDesc);
143         assert(part==AliHLTTPCDefinitions::GetMaxPatchNr(*pDesc));
144         int slice=AliHLTTPCDefinitions::GetMinSliceNr(*pDesc);
145         assert(slice==AliHLTTPCDefinitions::GetMaxSliceNr(*pDesc));
146         int firstRow=AliHLTTPCTransform::GetFirstRow(part);
147         int lastRow=AliHLTTPCTransform::GetLastRow(part);
148         AliHLTTPCDigitReaderRaw reader(fRawreaderMode);
149         reader.InitBlock(pDesc->fPtr,pDesc->fSize,firstRow,lastRow,part,slice);
150
151         int iPrintedRow=-1;
152         int iPrintedPad=-1;
153         int iLastTime=-1;
154         while (reader.Next()) {
155           if ((iPrintedSlice!=-1 && iLastTime!=reader.GetTime()+1 && iLastTime!=reader.GetTime()-1) ||
156               (iPrintedPad!=-1 && iPrintedPad!=reader.GetPad()) ||
157               (iPrintedRow!=-1 && iPrintedRow!=reader.GetRow())) {
158             dump << endl;
159           }
160           if (iPrintedSlice!=slice || iPrintedPart!=part) {
161             iPrintedSlice=slice;
162             iPrintedPart=part;
163             dump << "====================================================================" << endl;
164             dump << "    Slice: " << iPrintedSlice << "   Partition: " << iPrintedPart << endl;
165             iPrintedRow=-1;
166           }
167           if (iPrintedRow!=reader.GetRow()) {
168             iPrintedRow=reader.GetRow();
169             dump << "--------------------------------------------------------------------" << endl;
170             dump << "Row: " << iPrintedRow << endl;
171             iPrintedPad=-1;
172           }
173           if (iPrintedPad!=reader.GetPad()) {
174             iPrintedPad=reader.GetPad();
175             dump << "Row: " << iPrintedRow << "  Pad: " << iPrintedPad << endl;
176             iLastTime=-1;
177           }
178           if (iLastTime!=reader.GetTime()+1 && iLastTime!=reader.GetTime()-1 ) {
179             dump << "                     Time " << reader.GetTime() << ":  ";
180           }
181           iLastTime=reader.GetTime();
182           dump << "  " << reader.GetSignal();
183         }
184         dump << endl << endl;
185       } else {
186         HLTError("can not open file %s for writing", filename.Data());
187         iResult=-EBADF;
188       }
189       dump.close();
190     }
191   }
192   return iResult;
193 }