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