]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/TPCLib/AliHLTTPCClusterDumpComponent.cxx
use common FileWriter functionality for generation of file names, updated macro in...
[u/mrichter/AliRoot.git] / HLT / TPCLib / AliHLTTPCClusterDumpComponent.cxx
1 // $Id$
2 //**************************************************************************
3 //* This file is property of and copyright by the ALICE HLT Project        * 
4 //* ALICE Experiment at CERN, All rights reserved.                         *
5 //*                                                                        *
6 //* Primary Authors: Kenneth Aamodt <Kenneth.Aamodt@cern.ch>               *
7 //*                  for The ALICE HLT Project.                            *
8 //*                                                                        *
9 //* Permission to use, copy, modify and distribute this software and its   *
10 //* documentation strictly for non-commercial purposes is hereby granted   *
11 //* without fee, provided that the above copyright notice appears in all   *
12 //* copies and that both the copyright notice and this permission notice   *
13 //* appear in the supporting documentation. The authors make no claims     *
14 //* about the suitability of this software for any purpose. It is          *
15 //* provided "as is" without express or implied warranty.                  *
16 //**************************************************************************
17
18 /** @file   AliHLTTPCClusterDumpComponent.cxx
19     @author Kenneth Aamodt
20     @date   
21     @brief  Special file writer converting TPC clusters input to readable
22             ASCII format. 
23 */
24
25 #include <cassert>
26 #include "AliHLTTPCClusterDumpComponent.h"
27 #include "AliHLTTPCDefinitions.h"
28 #include "AliHLTTPCSpacePointData.h"
29 #include "AliHLTTPCClusterDataFormat.h"
30 #include "AliHLTTPCTransform.h"
31
32 /** ROOT macro for the implementation of ROOT specific class methods */
33 ClassImp(AliHLTTPCClusterDumpComponent)
34
35   AliHLTTPCClusterDumpComponent::AliHLTTPCClusterDumpComponent()
36     :
37     AliHLTFileWriter()
38 //fSlice(-1)
39 {
40   // see header file for class documentation
41   // or
42   // refer to README to build package
43   // or
44   // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
45 }
46
47 AliHLTTPCClusterDumpComponent::~AliHLTTPCClusterDumpComponent()
48 {
49   // see header file for class documentation
50 }
51
52 const char* AliHLTTPCClusterDumpComponent::GetComponentID()
53 {
54   // see header file for class documentation
55   return "TPCClusterDump";
56 }
57
58 void AliHLTTPCClusterDumpComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list)
59 {
60   // see header file for class documentation
61   list.clear();
62   list.push_back(AliHLTTPCDefinitions::fgkClustersDataType);
63 }
64
65 AliHLTComponent* AliHLTTPCClusterDumpComponent::Spawn()
66 {
67   // see header file for class documentation
68   return new AliHLTTPCClusterDumpComponent;
69 }
70
71 int AliHLTTPCClusterDumpComponent::InitWriter()
72 {
73   // see header file for class documentation
74   return 0;
75 }
76
77 int AliHLTTPCClusterDumpComponent::ScanArgument(int argc, const char** argv)
78 {
79   // see header file for class documentation
80   int iResult=0;
81   TString argument="";
82   bool bMissingParam=0;
83   int i=0;
84   
85   if (bMissingParam) iResult=-EPROTO;
86   else if (iResult>=0) iResult=i;
87   
88   return iResult;
89 }
90
91 int AliHLTTPCClusterDumpComponent::CloseWriter()
92 {
93   // see header file for class documentation
94   return 0;
95 }
96
97 int AliHLTTPCClusterDumpComponent::DumpEvent( const AliHLTComponentEventData& evtData,
98                                               AliHLTComponentTriggerData& /*trigData*/ )
99 {
100   // see header file for class documentation
101
102   HLTDebug("Entering DumpEvent");
103
104   int iResult=0;
105   int blockno=0;
106   const AliHLTComponentBlockData* pDesc=NULL;
107
108   if ( GetFirstInputBlock( kAliHLTDataTypeSOR ) || GetFirstInputBlock( kAliHLTDataTypeEOR ) )
109     return 0;
110
111   Int_t spacePointCounter=0;
112   
113   for (pDesc=GetFirstInputBlock(AliHLTTPCDefinitions::fgkClustersDataType); pDesc!=NULL; pDesc=GetNextInputBlock(), blockno++) {
114     TString filename;
115     iResult=BuildFileName(evtData.fEventID, 0, pDesc->fDataType, 0, filename);
116     ios::openmode filemode=(ios::openmode)0;
117     if (fCurrentFileName.CompareTo(filename)==0) {
118       filemode=ios::app;
119     } else {
120       fCurrentFileName=filename;
121     }
122     
123     if (iResult>=0) {
124       ofstream dump(fCurrentFileName.Data(), filemode);
125       if (dump.good()) {
126         
127         if(pDesc->fDataType!=AliHLTTPCDefinitions::fgkClustersDataType){continue;}
128         
129         //if (dump.good() || 1) {//the || 1 is there since dump.good() will return false( EOF )
130         iResult=1;
131         const AliHLTTPCClusterData* clusterData = (const AliHLTTPCClusterData*) pDesc->fPtr;
132         Int_t nSpacepoints = (Int_t) clusterData->fSpacePointCnt;
133         AliHLTTPCSpacePointData *clusters = (AliHLTTPCSpacePointData*) &clusterData->fSpacePoints;
134         
135         for(int i=0;i<nSpacepoints;i++){
136           UInt_t idCluster = clusters[i].fID;
137           Int_t slice = (idCluster>>25) & 0x7f;
138           Int_t patch = (idCluster>>22) & 0x7;
139           
140           dump << "" << endl;
141           dump << "ClusterNumber: " << spacePointCounter << endl;
142           dump << "Slice:         " << slice << endl;
143           dump << "Partition:     " << patch << endl;
144           dump << "[X,Y,Z]:       [" << clusters[i].fX<<" , "<<clusters[i].fY<<" , "<<clusters[i].fZ <<"]"<< endl;
145           Float_t xyz[3]={clusters[i].fX,clusters[i].fY,clusters[i].fZ};
146           AliHLTTPCTransform::LocHLT2Raw(xyz,(Int_t)(clusters[i].fID/10),(Int_t)(clusters[i].fID%10));
147           dump << "[R,P,T]:       [" << xyz[0]<<" , "<<xyz[1]<<" , "<<xyz[2] <<"]"<< endl;
148           dump << "Total Charge:  " << clusters[i].fCharge         << endl;
149           dump << "Q Max:         " << clusters[i].fQMax           << endl;
150           spacePointCounter++;
151         }
152       }
153       else {
154         HLTError("can not open file %s for writing", fCurrentFileName.Data());
155         iResult=-EBADF;
156       }
157       dump.close();
158     }
159   }
160   return iResult;
161 }