Bug fix: When moving from C style pointer based strings to the C++ string
[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
4df5dd10 37AliHLTPHOSFileWriterComponent::AliHLTPHOSFileWriterComponent():AliHLTDataSink(), fCellEnergiesFileWriterPtr(0), fDDLPackedFileWriterPtr(0), fDirectory(""),fFilename(""), fEventCount(0)
38 //AliHLTPHOSFileWriterComponent::AliHLTPHOSFileWriterComponent():AliHLTDataSink()
acd526ae 39{
f4d27262 40 for(int i=0; i<N_DATATYPES; i++)
41 {
42 fDataTypesToFile[i] = kAliHLTVoidDataType;
43 }
44
45 fCellEnergiesFileWriterPtr = new AliHLTPHOSCellEnergiesFileWriter();
46 fDDLPackedFileWriterPtr = new AliHLTPHOSDDLPackedFileWriter();
acd526ae 47
f4d27262 48}
acd526ae 49
50AliHLTPHOSFileWriterComponent::~AliHLTPHOSFileWriterComponent()
51{
f4d27262 52 delete fCellEnergiesFileWriterPtr;
53 delete fDDLPackedFileWriterPtr;
54}
55
56
4df5dd10 57AliHLTPHOSFileWriterComponent::AliHLTPHOSFileWriterComponent(const AliHLTPHOSFileWriterComponent & ):AliHLTDataSink(), fCellEnergiesFileWriterPtr(0), fDDLPackedFileWriterPtr(0), fDirectory(""),fFilename(""), fEventCount(0)
58 //AliHLTPHOSFileWriterComponent::AliHLTPHOSFileWriterComponent(const AliHLTPHOSFileWriterComponent & ):AliHLTDataSink()
f4d27262 59{
60
61}
acd526ae 62
f4d27262 63int
64AliHLTPHOSFileWriterComponent::AddDataType(string dataType)
65{
66 int ret = -1;
67 int tmpCnt = 0;
68 for(int i=0; i< N_DATATYPES; i++)
69 {
70 if( fDataTypesToFile[i] != kAliHLTVoidDataType)
71 {
72 tmpCnt ++;
73 }
74 }
75
76 string cmpString("gkCellEnergyDataType");
77
78 if(dataType.compare("gkCellEnergyDataType") == 0)
79 {
80 cout << "!!!!!!!!!!!!!!AliHLTPHOSFileWriterComponent::AddDataType"<< dataType << endl;
81 // fDataTypesToFilePtr[N_DATATYPES] = new AliHLTPHOSDefinitions::gkCellEnergyDataType;
82 fDataTypesToFile[tmpCnt] = AliHLTPHOSDefinitions::gkCellEnergyDataType;
83 cout <<"regsitring dataType for filewriting: fDataTypesToFile[" << tmpCnt <<"]"<<endl;
84 }
85 else if(dataType.compare("gkDDLPackedRawDataType") == 0)
86 {
87 fDataTypesToFile[tmpCnt] = AliHLTPHOSDefinitions::gkDDLPackedRawDataType;
88 }
89
90 cout << "dataType.compare(cmpString) = " <<dataType.compare(cmpString)<<endl;
91 return ret;
92}
93
94
95
96
97int
98AliHLTPHOSFileWriterComponent::Deinit()
99{
100 return 0;
101}
102
103int
104AliHLTPHOSFileWriterComponent::DoDeinit()
105{
106 Logging(kHLTLogInfo, "HLT", "PHOS", ",AliHLTPHOSFileWriterComponen DoDeinit");
107 return 0;
acd526ae 108}
109
110const char*
111AliHLTPHOSFileWriterComponent::GetComponentID()
112{
acd526ae 113 return "PhosFileWriter";
114}
115
f4d27262 116AliHLTComponent*
117AliHLTPHOSFileWriterComponent::Spawn()
acd526ae 118{
acd526ae 119 return new AliHLTPHOSFileWriterComponent;
120}
121
f4d27262 122
123void
124AliHLTPHOSFileWriterComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list)
125{
126 const AliHLTComponentDataType* pType=fInputDataTypes;
127 while (pType->fID!=0) {
128 list.push_back(*pType);
129 pType++;
130 }
131}
132
133AliHLTComponentDataType
134AliHLTPHOSFileWriterComponent::GetOutputDataType()
135{
136 return AliHLTPHOSDefinitions::gkCellEnergyDataType;
137}
138
139void
140AliHLTPHOSFileWriterComponent::GetOutputDataSize(unsigned long& constBase, double& inputMultiplier )
141
142{
143 constBase = 30;
144 inputMultiplier = 0.1;
145}
146
acd526ae 147int
f4d27262 148AliHLTPHOSFileWriterComponent::DumpEvent( const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks, AliHLTComponentTriggerData& trigData )
149{
150 UInt_t mysize = 0;
151 UInt_t tSize = 0;
152 Int_t tmpChannelCnt = 0;
153 UInt_t offset = 0;
154 const AliHLTComponentDataType *tmpDataType;
155 const AliHLTComponentBlockData* iter = NULL;
156 unsigned long ndx;
157 AliHLTPHOSDataHeaderStruct dataHeader;
158
159 dataHeader.fSize = sizeof(dataHeader);
160 dataHeader.fEventID = evtData.fEventID;
161 cout << "analyzing event: " << fEventCount << endl;
162
163 for( ndx = 0; ndx < evtData.fBlockCnt; ndx++ )
164 {
165 iter = blocks+ndx;
166 mysize = 0;
167 offset = tSize;
168 tmpDataType = &(iter->fDataType);
169
170 if(IsRegisteredDataType(*tmpDataType))
171 {
172 if(*tmpDataType == AliHLTPHOSDefinitions::gkCellEnergyDataType)
173 {
174
175 fCellEnergiesFileWriterPtr->WriteFile(evtData, blocks, trigData, fEventCount);
176 cout <<"AliHLTPHOSFileWriterComponen: data type = is gkCellEnergyDataType. block index = "<< ndx\
177 <<" EventCount =" << fEventCount << "Event ID"<<evtData.fEventID << endl;
178 }
179 else if(*tmpDataType == AliHLTPHOSDefinitions::gkDDLPackedRawDataType)
180 {
181
182 fDDLPackedFileWriterPtr->WriteFile(evtData, blocks, trigData, fEventCount);
183 }
184 }
185
186 // cout <<"AliHLTPHOSFileWriterComponen: data type = is gkCellEnergyDataType. block index = "<< ndx\
187 // <<" EventCount =" << fEventCount << "Event ID"<<evtData.fEventID << endl;
188
189 fEventCount++;
190 }
191 return 0;
192}//end DumpEvent
193
194
195int
acd526ae 196AliHLTPHOSFileWriterComponent::DoInit( int argc, const char** argv )
197{
f4d27262 198 int iResult=0;
199 TString argument="";
200 Bool_t dirSet = kFALSE;
201 Bool_t dataSet = kFALSE;
202 string dataType="";
203 int bMissingParam=0;
204
4df5dd10 205
f4d27262 206 fFilename.assign(256,0);
207
208 for(int i=0; i<argc; i++)
209 {
210 argument=argv[i];
211
212 if(argument.CompareTo("-directory")==0)
213 {
214 if ((bMissingParam=(++i>=argc)))
215 {
216 break;
217 }
218 fDirectory.assign(argv[i]);
219 fCellEnergiesFileWriterPtr->SetDirectory(fDirectory);
220 fDDLPackedFileWriterPtr->SetDirectory(fDirectory) ;
acd526ae 221
f4d27262 222 fFilename.insert(0, fDirectory);
223 dirSet = kTRUE;
224
225 cout << "fDirectory=" << fDirectory << endl;
226 }
227
228 if(argument.CompareTo("-datatype")==0)
229 {
230 if ((bMissingParam=(++i>=argc))) break;
231 cout << "datatype = " << argv[i] << endl;
232 dataType = argv[i];
233
234 AddDataType(dataType);
235 dataSet = kTRUE;
236 }
237
238 cout << "argv[" << i <<"] = " << argv[i] << endl;
239
240 }
241
242 /*
243 * We dont start the component if we don know what data to write
244 * or where to store it
245 */
246 if((dataSet != kTRUE || dataSet != kTRUE))
247 {
248 iResult = -1;
249 HLTFatal(" either direcory or datatype is not set, usage -datatype <datatype> -driectory <directory>");
250 }
251 else
252 {
253 iResult = 0;
254 }
255 return iResult;
acd526ae 256}
257
258
f4d27262 259Bool_t
260AliHLTPHOSFileWriterComponent::IsRegisteredDataType(const AliHLTComponentDataType& dataType)
261{
262 Bool_t tmp = kFALSE;
263 for(int i =0; i<N_DATATYPES; i++)
264 {
265 if((fDataTypesToFile[i] == dataType) && (dataType != kAliHLTVoidDataType))
266 {
267 tmp = kTRUE;
268 }
269 }
270
271 return tmp;
272}
273