HLT component to write data to files. The directory where to write the files
[u/mrichter/AliRoot.git] / HLT / PHOS / AliHLTPHOSFileWriterComponent.cxx
CommitLineData
acd526ae 1/**************************************************************************
2 * Copyright(c) 2006, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: Per Thomas Hille for the ALICE HLT Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
15
f4d27262 16//#include "AliHLTPHOSFileWriterComponent.h"
17
18
acd526ae 19#include "AliHLTPHOSFileWriterComponent.h"
f4d27262 20#include <iostream>
21#include "stdio.h"
22#include <TObjString.h>
23
24#include "AliRawReaderMemory.h"
25#include "AliCaloRawStream.h"
26#include <cstdlib>
27#include "AliHLTPHOSRcuCellEnergyDataStruct.h"
28#include "AliHLTPHOSDataHeaderStruct.h"
29#include "AliHLTDataTypes.h"
30
31
32const AliHLTComponentDataType AliHLTPHOSFileWriterComponent::fInputDataTypes[]={kAliHLTVoidDataType,{0,"",""}}; //'zero' terminated array
acd526ae 33
34
35AliHLTPHOSFileWriterComponent gAliHLTPHOSFileWriterComponent;
36
f4d27262 37AliHLTPHOSFileWriterComponent::AliHLTPHOSFileWriterComponent():AliHLTDataSink(), fCellEnergiesFileWriterPtr(0), fDDLPackedFileWriterPtr(0), fDirectory(0),fFilename(0), fEventCount(0)
acd526ae 38{
f4d27262 39 for(int i=0; i<N_DATATYPES; i++)
40 {
41 fDataTypesToFile[i] = kAliHLTVoidDataType;
42 }
43
44 fCellEnergiesFileWriterPtr = new AliHLTPHOSCellEnergiesFileWriter();
45 fDDLPackedFileWriterPtr = new AliHLTPHOSDDLPackedFileWriter();
acd526ae 46
f4d27262 47}
acd526ae 48
49AliHLTPHOSFileWriterComponent::~AliHLTPHOSFileWriterComponent()
50{
f4d27262 51 delete fCellEnergiesFileWriterPtr;
52 delete fDDLPackedFileWriterPtr;
53}
54
55
56AliHLTPHOSFileWriterComponent::AliHLTPHOSFileWriterComponent(const AliHLTPHOSFileWriterComponent & ):AliHLTDataSink(), fCellEnergiesFileWriterPtr(0), fDDLPackedFileWriterPtr(0), fDirectory(0),fFilename(0), fEventCount(0)
57{
58
59}
acd526ae 60
f4d27262 61int
62AliHLTPHOSFileWriterComponent::AddDataType(string dataType)
63{
64 int ret = -1;
65 int tmpCnt = 0;
66 for(int i=0; i< N_DATATYPES; i++)
67 {
68 if( fDataTypesToFile[i] != kAliHLTVoidDataType)
69 {
70 tmpCnt ++;
71 }
72 }
73
74 string cmpString("gkCellEnergyDataType");
75
76 if(dataType.compare("gkCellEnergyDataType") == 0)
77 {
78 cout << "!!!!!!!!!!!!!!AliHLTPHOSFileWriterComponent::AddDataType"<< dataType << endl;
79 // fDataTypesToFilePtr[N_DATATYPES] = new AliHLTPHOSDefinitions::gkCellEnergyDataType;
80 fDataTypesToFile[tmpCnt] = AliHLTPHOSDefinitions::gkCellEnergyDataType;
81 cout <<"regsitring dataType for filewriting: fDataTypesToFile[" << tmpCnt <<"]"<<endl;
82 }
83 else if(dataType.compare("gkDDLPackedRawDataType") == 0)
84 {
85 fDataTypesToFile[tmpCnt] = AliHLTPHOSDefinitions::gkDDLPackedRawDataType;
86 }
87
88 cout << "dataType.compare(cmpString) = " <<dataType.compare(cmpString)<<endl;
89 return ret;
90}
91
92
93
94
95int
96AliHLTPHOSFileWriterComponent::Deinit()
97{
98 return 0;
99}
100
101int
102AliHLTPHOSFileWriterComponent::DoDeinit()
103{
104 Logging(kHLTLogInfo, "HLT", "PHOS", ",AliHLTPHOSFileWriterComponen DoDeinit");
105 return 0;
acd526ae 106}
107
108const char*
109AliHLTPHOSFileWriterComponent::GetComponentID()
110{
acd526ae 111 return "PhosFileWriter";
112}
113
f4d27262 114AliHLTComponent*
115AliHLTPHOSFileWriterComponent::Spawn()
acd526ae 116{
acd526ae 117 return new AliHLTPHOSFileWriterComponent;
118}
119
f4d27262 120
121void
122AliHLTPHOSFileWriterComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list)
123{
124 const AliHLTComponentDataType* pType=fInputDataTypes;
125 while (pType->fID!=0) {
126 list.push_back(*pType);
127 pType++;
128 }
129}
130
131AliHLTComponentDataType
132AliHLTPHOSFileWriterComponent::GetOutputDataType()
133{
134 return AliHLTPHOSDefinitions::gkCellEnergyDataType;
135}
136
137void
138AliHLTPHOSFileWriterComponent::GetOutputDataSize(unsigned long& constBase, double& inputMultiplier )
139
140{
141 constBase = 30;
142 inputMultiplier = 0.1;
143}
144
acd526ae 145int
f4d27262 146AliHLTPHOSFileWriterComponent::DumpEvent( const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks, AliHLTComponentTriggerData& trigData )
147{
148 UInt_t mysize = 0;
149 UInt_t tSize = 0;
150 Int_t tmpChannelCnt = 0;
151 UInt_t offset = 0;
152 const AliHLTComponentDataType *tmpDataType;
153 const AliHLTComponentBlockData* iter = NULL;
154 unsigned long ndx;
155 AliHLTPHOSDataHeaderStruct dataHeader;
156
157 dataHeader.fSize = sizeof(dataHeader);
158 dataHeader.fEventID = evtData.fEventID;
159 cout << "analyzing event: " << fEventCount << endl;
160
161 for( ndx = 0; ndx < evtData.fBlockCnt; ndx++ )
162 {
163 iter = blocks+ndx;
164 mysize = 0;
165 offset = tSize;
166 tmpDataType = &(iter->fDataType);
167
168 if(IsRegisteredDataType(*tmpDataType))
169 {
170 if(*tmpDataType == AliHLTPHOSDefinitions::gkCellEnergyDataType)
171 {
172
173 fCellEnergiesFileWriterPtr->WriteFile(evtData, blocks, trigData, fEventCount);
174 cout <<"AliHLTPHOSFileWriterComponen: data type = is gkCellEnergyDataType. block index = "<< ndx\
175 <<" EventCount =" << fEventCount << "Event ID"<<evtData.fEventID << endl;
176 }
177 else if(*tmpDataType == AliHLTPHOSDefinitions::gkDDLPackedRawDataType)
178 {
179
180 fDDLPackedFileWriterPtr->WriteFile(evtData, blocks, trigData, fEventCount);
181 }
182 }
183
184 // cout <<"AliHLTPHOSFileWriterComponen: data type = is gkCellEnergyDataType. block index = "<< ndx\
185 // <<" EventCount =" << fEventCount << "Event ID"<<evtData.fEventID << endl;
186
187 fEventCount++;
188 }
189 return 0;
190}//end DumpEvent
191
192
193int
acd526ae 194AliHLTPHOSFileWriterComponent::DoInit( int argc, const char** argv )
195{
f4d27262 196 int iResult=0;
197 TString argument="";
198 Bool_t dirSet = kFALSE;
199 Bool_t dataSet = kFALSE;
200 string dataType="";
201 int bMissingParam=0;
202
203 fFilename.assign(256,0);
204
205 for(int i=0; i<argc; i++)
206 {
207 argument=argv[i];
208
209 if(argument.CompareTo("-directory")==0)
210 {
211 if ((bMissingParam=(++i>=argc)))
212 {
213 break;
214 }
215 fDirectory.assign(argv[i]);
216 fCellEnergiesFileWriterPtr->SetDirectory(fDirectory);
217 fDDLPackedFileWriterPtr->SetDirectory(fDirectory) ;
acd526ae 218
f4d27262 219 fFilename.insert(0, fDirectory);
220 dirSet = kTRUE;
221
222 cout << "fDirectory=" << fDirectory << endl;
223 }
224
225 if(argument.CompareTo("-datatype")==0)
226 {
227 if ((bMissingParam=(++i>=argc))) break;
228 cout << "datatype = " << argv[i] << endl;
229 dataType = argv[i];
230
231 AddDataType(dataType);
232 dataSet = kTRUE;
233 }
234
235 cout << "argv[" << i <<"] = " << argv[i] << endl;
236
237 }
238
239 /*
240 * We dont start the component if we don know what data to write
241 * or where to store it
242 */
243 if((dataSet != kTRUE || dataSet != kTRUE))
244 {
245 iResult = -1;
246 HLTFatal(" either direcory or datatype is not set, usage -datatype <datatype> -driectory <directory>");
247 }
248 else
249 {
250 iResult = 0;
251 }
252 return iResult;
acd526ae 253}
254
255
f4d27262 256Bool_t
257AliHLTPHOSFileWriterComponent::IsRegisteredDataType(const AliHLTComponentDataType& dataType)
258{
259 Bool_t tmp = kFALSE;
260 for(int i =0; i<N_DATATYPES; i++)
261 {
262 if((fDataTypesToFile[i] == dataType) && (dataType != kAliHLTVoidDataType))
263 {
264 tmp = kTRUE;
265 }
266 }
267
268 return tmp;
269}
270