]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/PHOS/AliHLTPHOSTreeMakerComponent.cxx
coding conventions (Oystein/Per Thomas)
[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 const AliHLTComponentDataType AliHLTPHOSTreeMakerComponent::fgkInputDataTypes[]={kAliHLTVoidDataType,{0,"",""}};
31
32 AliHLTPHOSTreeMakerComponent gAliHLTPHOSTreeMakerComponent;
33
34 AliHLTPHOSTreeMakerComponent::AliHLTPHOSTreeMakerComponent() :
35   AliHLTPHOSProcessor(),
36   fDigitTreePtr(0),
37   fEventCount(0),
38   fWriteInterval(1000)
39 {
40   //comment
41 }
42
43 AliHLTPHOSTreeMakerComponent::~AliHLTPHOSTreeMakerComponent()
44 {
45   //comment
46 }
47
48 int 
49 AliHLTPHOSTreeMakerComponent::Deinit()
50 {
51   //comment
52   cout << "Printing file...";
53   char filename [50];
54   sprintf(filename, "%s/run%d_digitTree_%d.root", fDirectory, fRunNb,(fEventCount/fWriteInterval));
55   TFile *outfile = new TFile(filename,"recreate");
56   fDigitTreePtr->Write();
57   delete outfile;
58   outfile = 0;
59   cout << "Done!\n";
60   if(fDigitTreePtr) 
61     {
62       delete fDigitTreePtr;
63       fDigitTreePtr = 0;
64     }
65   return 0;
66 }
67
68
69
70 const char*
71 AliHLTPHOSTreeMakerComponent::GetComponentID()
72 {
73   //comment
74   return "PhosTreeMaker";
75 }
76
77 void
78 AliHLTPHOSTreeMakerComponent::GetInputDataTypes(vector<AliHLTComponentDataType>& list)
79
80   //comment
81  //Get datatypes for input
82   const AliHLTComponentDataType* pType=fgkInputDataTypes;
83   while (pType->fID!=0) {
84     list.push_back(*pType); 
85     pType++;
86   }
87 }
88
89 AliHLTComponentDataType 
90 AliHLTPHOSTreeMakerComponent::GetOutputDataType()
91 {
92   //comment
93   return AliHLTPHOSDefinitions::fgkAliHLTRootTreeDataType;
94 }
95
96 void 
97 AliHLTPHOSTreeMakerComponent::GetOutputDataSize(unsigned long& constBase, double& inputMultiplier)
98 {
99   //comment
100   constBase = 30;
101   inputMultiplier = 1;
102 }
103
104 int 
105 AliHLTPHOSTreeMakerComponent::DoEvent(const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks,
106                                         AliHLTComponentTriggerData& /*trigData*/, AliHLTUInt8_t* outputPtr, AliHLTUInt32_t& size,
107                                         std::vector<AliHLTComponentBlockData>& outputBlocks)
108
109 {
110   //Do event
111
112   Bool_t digitEvent;
113   Int_t nDigits = 0;
114   Int_t totalDigits = 0;
115
116   const AliHLTComponentBlockData* iter = 0;
117   unsigned long ndx;
118
119   for ( ndx = 0; ndx < evtData.fBlockCnt; ndx++ )
120     {
121       iter = blocks + ndx;
122
123       if ( iter->fDataType == AliHLTPHOSDefinitions::fgkAliHLTDigitDataType )
124
125         {
126           digitEvent == true;
127           nDigits  = fTreeMakerPtr->MakeDigitArray ( reinterpret_cast<AliHLTPHOSDigitContainerDataStruct*> ( iter->fPtr ), totalDigits );
128           totalDigits += nDigits;
129           //cout << totalDigits << endl;
130           continue;
131         }
132       if ( iter->fDataType == AliHLTPHOSDefinitions::fgkAliHLTClusterDataType )
133         {
134           //
135         }
136     }
137   fEventCount++;
138   fTreeMakerPtr->FillDigitTree();
139   
140   if(fEventCount%fWriteInterval == 0)
141     {
142       Write();
143       ResetTrees();
144     }
145
146 return 0;
147
148 }
149
150 int
151 AliHLTPHOSTreeMakerComponent::DoInit ( int argc, const char** argv )
152 {
153   //comment
154   fTreeMakerPtr = new AliHLTPHOSTreeMaker();
155   fDigitTreePtr = new TTree ( "digitTree", "Digits tree" );
156   fDirectory = new char[50];
157
158   for ( int i = 0; i < argc; i++ )
159     {
160       if ( !strcmp ( "-path", argv[i] ) )
161         {
162           strcpy ( fDirectory, argv[i+1] );
163         }
164       if ( !strcmp ( "-writeinterval", argv[i] ) )
165         {
166           fWriteInterval = atoi(argv[i+1]);
167         }
168     }
169
170   fTreeMakerPtr->SetDigitTree(fDigitTreePtr);
171     
172   fstream runNbFile;
173   Int_t newRunNb;
174   runNbFile.open("/opt/HLT-public/rundir/runNumber.txt");
175   runNbFile >> fRunNb;
176   runNbFile.close();
177   /*  newRunNb = fRunNb + 1;
178   runNbFile.open("/opt/HLT-public/rundir/runNumber.txt");
179   runNbFile << newRunNb;
180   runNbFile.close();*/
181   
182   cout << endl << "Run number is: " << fRunNb  << "  -- Check that this is correct!!!\n";
183
184   return 0;
185   
186 }
187
188
189 AliHLTComponent*
190 AliHLTPHOSTreeMakerComponent::Spawn()
191 {
192   //comment
193   return new AliHLTPHOSTreeMakerComponent();
194 }
195
196 void
197 AliHLTPHOSTreeMakerComponent::Write()
198 {
199   //comment
200   cout << "Writing file...";
201   char filename [256];
202   sprintf(filename, "%s/run%d_digitTree_%d.root", fDirectory, fRunNb,(fEventCount/fWriteInterval - 1));
203   TFile *outfile = new TFile(filename,"recreate");
204   fDigitTreePtr->Write();
205   delete outfile;
206   outfile = 0;
207   cout << "Done!\n";
208 }
209
210 void
211 AliHLTPHOSTreeMakerComponent::ResetTrees()
212 {
213   //comment
214   delete fDigitTreePtr;
215   fDigitTreePtr = new TTree("digitTree", "Digits tree");
216   fTreeMakerPtr->SetDigitTree(fDigitTreePtr);
217 }
218   
219   
220   
221   
222   
223   
224   
225
226
227