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