]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/PHOS/AliHLTPHOSDigitMakerComponent.cxx
New production macros (Yves)
[u/mrichter/AliRoot.git] / HLT / PHOS / AliHLTPHOSDigitMakerComponent.cxx
1 // $Id$
2
3  /**************************************************************************
4  * This file is property of and copyright by the ALICE HLT Project        *
5  * All rights reserved.                                                   *
6  *                                                                        *
7  * Primary Authors: Oystein Djuvsland                                     *
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 #include "AliHLTPHOSDigitMakerComponent.h"
19 #include "AliHLTPHOSDigitMaker.h"
20 #include "TTree.h"
21 #include "AliHLTPHOSProcessor.h"
22 #include "AliHLTPHOSRcuCellEnergyDataStruct.h"
23 #include "AliHLTPHOSDigitDataStruct.h"
24 #include "AliHLTPHOSChannelDataHeaderStruct.h"
25 #include "AliHLTPHOSChannelDataStruct.h"
26 #include "TClonesArray.h"
27 #include "TFile.h"
28 #include <sys/stat.h>
29 #include <sys/types.h>
30
31
32 /** 
33  * @file   AliHLTPHOSDigitMakerComponent.cxx
34  * @author Oystein Djuvsland
35  * @date   
36  * @brief  A digit maker component for PHOS HLT
37 */
38
39 // see below for class documentation
40 // or
41 // refer to README to build package
42 // or
43 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
44
45
46 const AliHLTComponentDataType AliHLTPHOSDigitMakerComponent::fgkInputDataTypes[]={kAliHLTVoidDataType,{0,"",""}};
47
48 AliHLTPHOSDigitMakerComponent gAliHLTPHOSDigitMakerComponent;
49
50 AliHLTPHOSDigitMakerComponent::AliHLTPHOSDigitMakerComponent() :
51   AliHLTPHOSProcessor(),
52   fDigitMakerPtr(0),
53   fDigitContainerPtr(0)
54   //  fEvtCnt(0)
55 {
56   //see header file for documentation
57 }
58
59
60 AliHLTPHOSDigitMakerComponent::~AliHLTPHOSDigitMakerComponent()
61 {
62   //see header file for documentation
63 }
64
65 int 
66 AliHLTPHOSDigitMakerComponent::Deinit()
67
68   //see header file for documentation
69   if(fDigitMakerPtr)
70     {
71       delete fDigitMakerPtr;
72       fDigitMakerPtr = 0;
73     }
74   return 0;
75 }
76
77 const char*
78 AliHLTPHOSDigitMakerComponent::GetComponentID()
79 {
80   //see header file for documentation
81   return "PhosDigitMaker";
82 }
83
84
85 void
86 AliHLTPHOSDigitMakerComponent::GetInputDataTypes(vector<AliHLTComponentDataType>& list)
87
88   //see header file for documentation
89   list.clear();
90   list.push_back(AliHLTPHOSDefinitions::fgkChannelDataType);
91
92 //   const AliHLTComponentDataType* pType=fgkInputDataTypes;
93 //   while (pType->fID!=0) {
94 //     list.push_back(*pType); 
95 //     pType++;
96 //   }
97 }
98
99 AliHLTComponentDataType 
100 AliHLTPHOSDigitMakerComponent::GetOutputDataType()
101 {
102   //see header file for documentation
103   return AliHLTPHOSDefinitions::fgkDigitDataType;
104 }
105
106
107 void 
108 AliHLTPHOSDigitMakerComponent::GetOutputDataSize(unsigned long& constBase, double& inputMultiplier)
109 {
110   //see header file for documentation
111   constBase = 0;
112   inputMultiplier = (float)sizeof(AliHLTPHOSDigitDataStruct)/sizeof(AliHLTPHOSChannelDataStruct) + 1;
113 }
114
115 int 
116 AliHLTPHOSDigitMakerComponent::DoEvent(const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks,
117                                         AliHLTComponentTriggerData& /*trigData*/, AliHLTUInt8_t* outputPtr, AliHLTUInt32_t& size,
118                                         std::vector<AliHLTComponentBlockData>& outputBlocks)
119 {
120   //see header file for documentation
121   UInt_t tSize            = 0;
122   UInt_t offset           = 0; 
123   UInt_t mysize           = 0;
124   Int_t digitCount        = 0;
125   Int_t ret               = 0;
126
127   AliHLTUInt8_t* outBPtr;
128   outBPtr = outputPtr;
129   const AliHLTComponentBlockData* iter = 0; 
130   unsigned long ndx; 
131
132   UInt_t specification = 0;
133   AliHLTPHOSChannelDataHeaderStruct* tmpChannelData = 0;
134   
135   fDigitMakerPtr->SetDigitDataPtr(reinterpret_cast<AliHLTPHOSDigitDataStruct*>(outputPtr));
136
137   for( ndx = 0; ndx < evtData.fBlockCnt; ndx++ )
138     {
139       iter = blocks+ndx;
140       
141       if(iter->fDataType != AliHLTPHOSDefinitions::fgkChannelDataType)
142         {
143           HLTDebug("Data block is not of type fgkChannelDataType");
144           continue;
145         }
146
147       specification |= iter->fSpecification;
148       tmpChannelData = reinterpret_cast<AliHLTPHOSChannelDataHeaderStruct*>(iter->fPtr);
149     
150       ret = fDigitMakerPtr->MakeDigits(tmpChannelData, size-(digitCount*sizeof(AliHLTPHOSDigitDataStruct)));
151       if(ret == -1) 
152         {
153           HLTError("Trying to write over buffer size");
154           return -ENOBUFS;
155         }
156       digitCount += ret; 
157     }
158   
159   mysize = digitCount*sizeof(AliHLTPHOSDigitDataStruct);
160
161   HLTDebug("# of digits: %d, used memory size: %d, available size: %d", digitCount, mysize, size);
162   
163   AliHLTComponentBlockData bd;
164   FillBlockData( bd );
165   bd.fOffset = offset;
166   bd.fSize = mysize;
167   bd.fDataType = AliHLTPHOSDefinitions::fgkDigitDataType;
168   bd.fSpecification = specification;
169   outputBlocks.push_back(bd);
170        
171   if( tSize > size )
172     {
173       Logging( kHLTLogFatal, "HLT::AliHLTPHOSDigitMakerComponent::DoEvent", "Too much data", "Data written over allowed buffer. Amount written: %lu, allowed amount: %lu.", tSize, size );
174       return EMSGSIZE;
175     }
176
177   fDigitMakerPtr->Reset();
178
179   size = mysize; 
180
181   return 0;
182 }
183
184
185 int
186 AliHLTPHOSDigitMakerComponent::DoInit(int argc, const char** argv )
187 {
188   //see header file for documentation
189
190   fDigitMakerPtr = new AliHLTPHOSDigitMaker();
191   
192   for(int i = 0; i < argc; i++)
193     {
194       if(!strcmp("-lowgainfactor", argv[i]))
195         {
196           fDigitMakerPtr->SetGlobalLowGainFactor(atof(argv[i+1]));
197         }
198       if(!strcmp("-highgainfactor", argv[i]))
199         {
200           fDigitMakerPtr->SetGlobalHighGainFactor(atof(argv[i+1]));
201         }
202       if(!strcmp("-reverseorder", argv[i]))
203         {
204           fDigitMakerPtr->SetOrdered(false);
205         }
206     }
207  
208   //fDigitMakerPtr->SetDigitThreshold(2);
209
210   return 0;
211 }
212
213 AliHLTComponent*
214 AliHLTPHOSDigitMakerComponent::Spawn()
215 {
216   //see header file for documentation
217   return new AliHLTPHOSDigitMakerComponent();
218 }