]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/TPCLib/AliHLTTPCDigitDumpComponent.cxx
minor cosmetics
[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   for (; i<argc && iResult>=0; i++) {
89     argument=argv[i];
90     if (argument.IsNull()) continue;
91
92     // -rawreadermode
93     if (argument.CompareTo("-rawreadermode")==0) {
94       if ((bMissingParam=(++i>=argc))) break;
95       int mode=AliHLTTPCDigitReaderRaw::DecodeMode(argv[i]);
96       if (mode<0) {
97         HLTError("invalid rawreadermode specifier '%s'", argv[i]);
98         iResult=-EINVAL;
99       } else {
100         fRawreaderMode=static_cast<unsigned>(mode);
101       }
102       break;
103     }
104   }
105
106   if (bMissingParam) {
107     iResult=-EPROTO;
108   }
109   if (iResult>=0) iResult=i+1;
110
111   return iResult;
112 }
113
114 int AliHLTTPCDigitDumpComponent::CloseWriter()
115 {
116   // see header file for class documentation
117   return 0;
118 }
119
120 int AliHLTTPCDigitDumpComponent::DumpEvent( const AliHLTComponentEventData& evtData,
121                                             const AliHLTComponentBlockData* blocks, 
122                                             AliHLTComponentTriggerData& /*trigData*/ )
123 {
124   // see header file for class documentation
125   int iResult=0;
126   int iPrintedSlice=-1;
127   int iPrintedPart=-1;
128   int blockno=0;
129   const AliHLTComponentBlockData* pDesc=NULL;
130
131   for (pDesc=GetFirstInputBlock(kAliHLTDataTypeDDLRaw|kAliHLTDataOriginTPC); pDesc!=NULL; pDesc=GetNextInputBlock(), blockno++) {
132     HLTDebug("event %Lu block %d: %s 0x%08x size %d", evtData.fEventID, blockno, DataType2Text(pDesc->fDataType).c_str(), pDesc->fSpecification, pDesc->fSize);
133     TString filename;
134     iResult=BuildFileName(evtData.fEventID, blockno, pDesc->fDataType, pDesc->fSpecification, filename);
135     ios::openmode filemode=(ios::openmode)0;
136     if (fCurrentFileName.CompareTo(filename)==0) {
137       // append to the file
138       filemode=ios::app;
139     } else {
140       // store the file for the next block
141       fCurrentFileName=filename;
142     }
143     if (iResult>=0) {
144       ofstream dump(filename.Data(), filemode);
145       if (dump.good()) {
146         int part=AliHLTTPCDefinitions::GetMinPatchNr(*pDesc);
147         assert(part==AliHLTTPCDefinitions::GetMaxPatchNr(*pDesc));
148         int slice=AliHLTTPCDefinitions::GetMinSliceNr(*pDesc);
149         assert(slice==AliHLTTPCDefinitions::GetMaxSliceNr(*pDesc));
150         int firstRow=AliHLTTPCTransform::GetFirstRow(part);
151         int lastRow=AliHLTTPCTransform::GetLastRow(part);
152         AliHLTTPCDigitReaderRaw reader(fRawreaderMode);
153         reader.InitBlock(pDesc->fPtr,pDesc->fSize,firstRow,lastRow,part,slice);
154
155         int iPrintedRow=-1;
156         int iPrintedPad=-1;
157         int iLastTime=-1;
158         while (reader.Next()) {
159           if ((iPrintedSlice!=-1 && iLastTime!=reader.GetTime()+1 && iLastTime!=reader.GetTime()-1) ||
160               (iPrintedPad!=-1 && iPrintedPad!=reader.GetPad()) ||
161               (iPrintedRow!=-1 && iPrintedRow!=reader.GetRow())) {
162             dump << endl;
163           }
164           if (iPrintedSlice!=slice || iPrintedPart!=part) {
165             iPrintedSlice=slice;
166             iPrintedPart=part;
167             dump << "====================================================================" << endl;
168             dump << "    Slice: " << iPrintedSlice << "   Partition: " << iPrintedPart << endl;
169             iPrintedRow=-1;
170           }
171           if (iPrintedRow!=reader.GetRow()) {
172             iPrintedRow=reader.GetRow();
173             dump << "--------------------------------------------------------------------" << endl;
174             dump << "Row: " << iPrintedRow << endl;
175             iPrintedPad=-1;
176           }
177           if (iPrintedPad!=reader.GetPad()) {
178             iPrintedPad=reader.GetPad();
179             dump << "Row: " << iPrintedRow << "  Pad: " << iPrintedPad << endl;
180             iLastTime=-1;
181           }
182           if (iLastTime!=reader.GetTime()+1 && iLastTime!=reader.GetTime()-1 ) {
183             dump << "                     Time " << reader.GetTime() << ":  ";
184           }
185           iLastTime=reader.GetTime();
186           dump << "  " << reader.GetSignal();
187         }
188         dump << endl << endl;
189       } else {
190         HLTError("can not open file %s for writing", filename.Data());
191         iResult=-EBADF;
192       }
193       dump.close();
194     }
195   }
196   return iResult;
197 }