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