]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/PHOS/AliHLTPHOSTreeMakerComponent.cxx
Coding conventions and removal of obsolete files
[u/mrichter/AliRoot.git] / HLT / PHOS / AliHLTPHOSTreeMakerComponent.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
17  
18 #include "AliHLTPHOSTreeMakerComponent.h"
19 #include "AliHLTPHOSTreeMaker.h"
20 #include "AliHLTPHOSProcessor.h"
21 #include "AliHLTPHOSDigitDataStruct.h"
22 #include "TTree.h"
23 #include "TClonesArray.h"
24 #include "TObject.h"
25 #include <fstream>
26 #include "TFile.h"
27 #include <sys/stat.h>
28 #include <sys/types.h>
29
30 /**
31  * Tree maker component for PHOS HLT
32  *
33  * @file   AliHLTPHOSTreeMakerComponent.cxx
34  * @author Oystein Djuvsland
35  * @date   
36  * @brief  A tree maker component for PHOS HLT
37 */
38
39
40 // see header file for class documentation
41 // or
42 // refer to README to build package
43 // or
44 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
45
46 const AliHLTComponentDataType AliHLTPHOSTreeMakerComponent::fgkInputDataTypes[]={kAliHLTVoidDataType,{0,"",""}};
47
48 AliHLTPHOSTreeMakerComponent gAliHLTPHOSTreeMakerComponent;
49
50 AliHLTPHOSTreeMakerComponent::AliHLTPHOSTreeMakerComponent() :
51   AliHLTPHOSProcessor(),
52   fDigitTreePtr(0),
53   fTreeMakerPtr(0),
54   fDirectory(0),
55   fWriteInterval(1000)
56 {
57   //See header file for documentation
58 }
59
60 AliHLTPHOSTreeMakerComponent::~AliHLTPHOSTreeMakerComponent()
61 {
62   //See header file for documentation
63 }
64
65 int 
66 AliHLTPHOSTreeMakerComponent::Deinit()
67 {
68   //See header file for documentation
69   cout << "Writing file...";
70   char filename [50];
71
72   sprintf(filename, "%s/run%d_digitTree_%d.root", fDirectory, fRunNumber,(fPhosEventCount/fWriteInterval));
73  
74   TFile *outfile = new TFile(filename,"recreate");
75   fDigitTreePtr->Write();
76   delete outfile;
77   outfile = 0;
78   cout << "Done!\n";
79   if(fDigitTreePtr) 
80     {
81       delete fDigitTreePtr;
82       fDigitTreePtr = 0;
83     }
84   return 0;
85 }
86
87
88
89 const char*
90 AliHLTPHOSTreeMakerComponent::GetComponentID()
91 {
92   //See header file for documentation
93   return "PhosTreeMaker";
94 }
95
96 void
97 AliHLTPHOSTreeMakerComponent::GetInputDataTypes(vector<AliHLTComponentDataType>& list)
98
99   //See header file for documentation
100  //Get datatypes for input
101   const AliHLTComponentDataType* pType=fgkInputDataTypes;
102   while (pType->fID!=0) {
103     list.push_back(*pType); 
104     pType++;
105   }
106 }
107
108 AliHLTComponentDataType 
109 AliHLTPHOSTreeMakerComponent::GetOutputDataType()
110 {
111   //See header file for documentation
112   return AliHLTPHOSDefinitions::fgkAliHLTRootTreeDataType;
113 }
114
115 void 
116 AliHLTPHOSTreeMakerComponent::GetOutputDataSize(unsigned long& constBase, double& inputMultiplier)
117 {
118   //See header file for documentation
119   constBase = 30;
120   inputMultiplier = 1;
121 }
122
123 int 
124 AliHLTPHOSTreeMakerComponent::DoEvent(const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks,
125                                         AliHLTComponentTriggerData& /*trigData*/, AliHLTUInt8_t* /*outputPtr*/, AliHLTUInt32_t& /*size*/,  //TODO: I think size should be set to zero when returning from this method if not data was written to the output buffer.
126                                         std::vector<AliHLTComponentBlockData>& /*outputBlocks*/)
127
128 {
129   //Do event
130   //See header file for documentation
131   Bool_t digitEvent;
132   Int_t nDigits = 0;
133   Int_t totalDigits = 0;
134
135   const AliHLTComponentBlockData* iter = 0;
136   unsigned long ndx;
137
138   for ( ndx = 0; ndx < evtData.fBlockCnt; ndx++ )
139     {
140       iter = blocks + ndx;
141
142       if ( iter->fDataType == AliHLTPHOSDefinitions::fgkAliHLTDigitDataType )
143
144         {
145           digitEvent = true;
146           nDigits  = fTreeMakerPtr->MakeDigitArray ( reinterpret_cast<AliHLTPHOSDigitContainerDataStruct*> ( iter->fPtr ), totalDigits );
147           totalDigits += nDigits;
148           //cout << totalDigits << endl;
149           continue;
150         }
151       if ( iter->fDataType == AliHLTPHOSDefinitions::fgkAliHLTClusterDataType )
152         {
153           //
154         }
155     }
156
157   fPhosEventCount++;
158
159   fTreeMakerPtr->FillDigitTree();
160   
161   if( (fPhosEventCount%fWriteInterval == 0 ) && (fPhosEventCount != 0))
162     {
163       Write();
164       ResetTrees();
165     }
166
167 return 0;
168
169 }
170
171 int
172 AliHLTPHOSTreeMakerComponent::DoInit ( int argc, const char** argv )
173 {
174   //See header file for documentation
175   fTreeMakerPtr = new AliHLTPHOSTreeMaker();
176   fDigitTreePtr = new TTree ( "digitTree", "Digits tree" );
177   fDirectory = new char[50];
178
179   for ( int i = 0; i < argc; i++ )
180     {
181       if ( !strcmp ( "-path", argv[i] ) )
182         {
183           strcpy ( fDirectory, argv[i+1] );
184         }
185       if ( !strcmp ( "-writeinterval", argv[i] ) )
186         {
187           fWriteInterval = atoi(argv[i+1]);
188         }
189     }
190
191   fTreeMakerPtr->SetDigitTree(fDigitTreePtr);
192   cout << endl << "Run number is: " <<  fRunNumber  << "  -- Check that this is correct!!!\n" << endl;
193
194   // fRunNumber
195
196   return 0;
197   
198 }
199
200
201 AliHLTComponent*
202 AliHLTPHOSTreeMakerComponent::Spawn()
203 {
204   //See header file for documentation
205   return new AliHLTPHOSTreeMakerComponent();
206 }
207
208 void
209 AliHLTPHOSTreeMakerComponent::Write()
210 {
211   //See header file for documentation
212   cout << "Writing file...";
213   char filename [256];
214
215   sprintf(filename, "%s/run%d_digitTree_%d.root", fDirectory, fRunNumber,(fPhosEventCount/fWriteInterval - 1));
216
217   TFile *outfile = new TFile(filename,"recreate");
218   fDigitTreePtr->Write();
219   delete outfile;
220   outfile = 0;
221   cout << "Done!\n";
222 }
223
224 void
225 AliHLTPHOSTreeMakerComponent::ResetTrees()
226 {
227   //See header file for documentation
228   delete fDigitTreePtr;
229   fDigitTreePtr = new TTree("digitTree", "Digits tree");
230   fTreeMakerPtr->SetDigitTree(fDigitTreePtr);
231 }
232     
233   
234   
235   
236   
237   
238
239
240