]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/PHOS/AliHLTPHOSRcuTreeMakerComponent.cxx
Coding conventions and minor fixes
[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
20 #include "AliHLTPHOSRcuDigitContainerDataStruct.h"
21
22 #include "AliHLTPHOSRcuTreeMaker.h"
23 #include "AliHLTPHOSRcuProcessor.h"
24 #include "AliHLTPHOSDigitDataStruct.h"
25 #include "TTree.h"
26 #include "TClonesArray.h"
27 #include "TObject.h"
28 #include <fstream>
29 #include "TFile.h"
30 #include <sys/stat.h>
31 #include <sys/types.h>
32
33 const AliHLTComponentDataType AliHLTPHOSRcuTreeMakerComponent::fgkInputDataTypes[]={kAliHLTVoidDataType,{0,"",""}};
34
35 AliHLTPHOSRcuTreeMakerComponent gAliHLTPHOSRcuTreeMakerComponent;
36
37 AliHLTPHOSRcuTreeMakerComponent::AliHLTPHOSRcuTreeMakerComponent() :
38   AliHLTPHOSRcuProcessor(),
39   fDigitTreePtr(0),
40   fTreeMakerPtr(0), 
41   //  fEventCount(0),
42   fWriteInterval(1000)
43 {
44   //comment
45 }
46
47 AliHLTPHOSRcuTreeMakerComponent::~AliHLTPHOSRcuTreeMakerComponent()
48 {
49   //comment
50 }
51
52 int 
53 AliHLTPHOSRcuTreeMakerComponent::Deinit()
54 {
55   //comment
56   //  cout << "Printing file...";
57
58   /*
59   char filename [50];
60   sprintf(filename, "%s/run%d_digitTree_rcuX_%d_rcuZ_%d_%d.root", fDirectory, fRunNb,(fEventCount/fWriteInterval));
61   TFile *outfile = new TFile(filename,"recreate");
62   fDigitTreePtr->Write();
63   delete outfile;
64   outfile = 0;
65   cout << "Done!\n";
66   */
67   
68   Write();
69
70
71   if(fDigitTreePtr) 
72     {
73       delete fDigitTreePtr;
74       fDigitTreePtr = 0;
75     }
76   return 0;
77 }
78
79
80
81 const char*
82 AliHLTPHOSRcuTreeMakerComponent::GetComponentID()
83 {
84   //comment
85   return "PhosRcuTreeMaker";
86 }
87
88 void
89 AliHLTPHOSRcuTreeMakerComponent::GetInputDataTypes(vector<AliHLTComponentDataType>& list)
90
91   //comment
92  //Get datatypes for input
93   const AliHLTComponentDataType* pType=fgkInputDataTypes;
94   while (pType->fID!=0) {
95     list.push_back(*pType); 
96     pType++;
97   }
98 }
99
100 AliHLTComponentDataType 
101 AliHLTPHOSRcuTreeMakerComponent::GetOutputDataType()
102 {
103   //comment
104   return AliHLTPHOSDefinitions::fgkAliHLTRootTreeDataType;
105 }
106
107 void 
108 AliHLTPHOSRcuTreeMakerComponent::GetOutputDataSize(unsigned long& constBase, double& inputMultiplier)
109 {
110   //comment
111   constBase = 30;
112   inputMultiplier = 1;
113 }
114
115 int 
116 AliHLTPHOSRcuTreeMakerComponent::DoEvent(const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks,
117                                         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.
118                                         std::vector<AliHLTComponentBlockData>& /*outputBlocks*/)
119
120 {
121
122   cout << "AliHLTPHOSRcuTreeMakerComponent::DoEvent TP0 " << endl;
123   //Do event
124
125   Bool_t digitEvent;
126   Int_t nDigits = 0;
127   Int_t totalDigits = 0;
128
129   const AliHLTComponentBlockData* iter = 0;
130   unsigned long ndx;
131  cout << "AliHLTPHOSRcuTreeMakerComponent::DoEvent TP0.1 " << endl;
132   for ( ndx = 0; ndx < evtData.fBlockCnt; ndx++ )
133     {
134       iter = blocks + ndx;
135       cout << "AliHLTPHOSRcuTreeMakerComponent::DoEvent TP0.2 " << endl;
136       if ( iter->fDataType == AliHLTPHOSDefinitions::fgkAliHLTDigitDataType )
137
138         {
139            cout << "AliHLTPHOSRcuTreeMakerComponent::DoEvent TP0.2 " << endl;
140            digitEvent = true;
141            cout << "AliHLTPHOSRcuTreeMakerComponent::DoEvent TP0.3 " << endl;
142
143            //      fTreeMakerPtr = new AliHLTPHOSRcuTreeMaker();
144
145            if( iter->fPtr == 0)
146              {
147                cout << "AliHLTPHOSRcuTreeMakerComponent::DoEvent TP0.3.1 " << endl;
148                cout << "ERROR" << endl;
149                cout << "AliHLTPHOSRcuTreeMakerComponent::DoEvent TP0.3.2 " << endl;
150              }
151            else
152              {
153               cout << "AliHLTPHOSRcuTreeMakerComponent::DoEvent TP0.3.3 " << endl;
154               
155               //              fTreeMakerPtr = new AliHLTPHOSRcuTreeMaker();
156               
157               if(fTreeMakerPtr == 0 )
158                 {
159                   //      cout << "FUCK" << endl;
160                 }  
161               else
162                 {
163                   cout << "AliHLTPHOSRcuTreeMakerComponent::DoEvent TP0.3.4, -1 " << endl;
164                   //          nDigits  = fTreeMakerPtr->MakeDigitArray ( reinterpret_cast<AliHLTPHOSRcuDigitContainerDataStruct*> ( iter->fPtr ), totalDigits );
165                   //
166
167                   nDigits  = fTreeMakerPtr->MakeDigitArray ( reinterpret_cast<AliHLTPHOSRcuDigitContainerDataStruct*> ( iter->fPtr ), totalDigits );
168
169                   //      AliHLTPHOSRcuDigitContainerDataStruct *tmp = new  AliHLTPHOSRcuDigitContainerDataStruct();
170                   
171                   //      nDigits  = fTreeMakerPtr->MakeDigitArray(tmp, totalDigits );
172
173                   //  nDigits  = fTreeMakerPtr->MakeDigitArray ( (AliHLTPHOSRcuDigitContainerDataStruct*) ( iter->fPtr ), totalDigits );
174
175                   fTreeMakerPtr->FUCK();
176                   cout << "AliHLTPHOSRcuTreeMakerComponent::DoEvent TP0.3.4 " << endl;
177              
178                 }
179              }
180
181            cout << "AliHLTPHOSRcuTreeMakerComponent::DoEvent TP0.4 " << endl;
182            totalDigits += nDigits;
183            //cout << totalDigits << endl;
184            cout << "AliHLTPHOSRcuTreeMakerComponent::DoEvent TP0.5 " << endl;
185            continue;
186         }
187      
188       if ( iter->fDataType == AliHLTPHOSDefinitions::fgkAliHLTClusterDataType )
189         {
190           cout << "AliHLTPHOSRcuTreeMakerComponent::DoEvent TP0.6 " << endl;
191        //
192         }
193     }
194
195   //  fEventCount++;
196   cout << "AliHLTPHOSRcuTreeMakerComponent::DoEvent TP1 " << endl;
197   fPhosEventCount++;
198
199   fTreeMakerPtr->FillDigitTree();
200   cout << "AliHLTPHOSRcuTreeMakerComponent::DoEvent TP2 " << endl;  
201   //  if(fEventCount%fWriteInterval == 0)
202   if(fPhosEventCount%fWriteInterval == 0)
203     {
204       cout << "AliHLTPHOSRcuTreeMakerComponent::DoEvent TP3 " << endl;
205       Write();
206       cout << "AliHLTPHOSRcuTreeMakerComponent::DoEvent TP4 " << endl;
207       ResetTrees();
208       cout << "AliHLTPHOSRcuTreeMakerComponent::DoEvent TP5 " << endl;
209     }
210   cout << "AliHLTPHOSRcuTreeMakerComponent::DoEvent TP6 " << endl;
211 return 0;
212
213 }
214
215 int
216 AliHLTPHOSRcuTreeMakerComponent::DoInit ( int argc, const char** argv )
217 {
218   //comment
219   fTreeMakerPtr = new AliHLTPHOSRcuTreeMaker();
220   fDigitTreePtr = new TTree ( "digitTree", "Digits tree" );
221   fDirectory = new char[50];
222
223   for ( int i = 0; i < argc; i++ )
224     {
225       if ( !strcmp ( "-path", argv[i] ) )
226         {
227           strcpy ( fDirectory, argv[i+1] );
228         }
229       if ( !strcmp ( "-writeinterval", argv[i] ) )
230         {
231           fWriteInterval = atoi(argv[i+1]);
232         }
233     }
234
235   fTreeMakerPtr->SetDigitTree(fDigitTreePtr);
236     
237   //  fstream runNbFile;
238   //Int_t newRunNb;
239   //  runNbFile.open("/opt/HLT-public/rundir/runNumber.txt");
240   //  runNbFile >> fRunNb;
241   //  runNbFile.close();
242   /*  newRunNb = fRunNb + 1;
243   runNbFile.open("/opt/HLT-public/rundir/runNumber.txt");
244   runNbFile << newRunNb;
245   runNbFile.close();*/
246   
247   cout << endl << "Run number is: " << fRunNumber  << "  -- Check that this is correct!!!\n" << endl;
248
249   return 0;
250   
251 }
252
253
254 AliHLTComponent*
255 AliHLTPHOSRcuTreeMakerComponent::Spawn()
256 {
257   //comment
258   return new AliHLTPHOSRcuTreeMakerComponent();
259 }
260
261 void
262 AliHLTPHOSRcuTreeMakerComponent::Write()
263 {
264   //comment
265   cout << "Writing file...";
266
267   char filename [256];
268   //  sprintf(filename, "%s/run%d_%d_digitTree_mod%d_rcuX%d_rcuZ%d_.root", fDirectory, fRunNb,(fEventCount/fWriteInterval - 1), fModuleID, fRcuX, fRcuZ);
269   sprintf(filename, "%s/run%d_%d_digitTree_mod%d_rcuX%d_rcuZ%d_.root", fDirectory, fRunNumber,(fPhosEventCount/fWriteInterval - 1), fModuleID, fRcuX, fRcuZ);
270   TFile *outfile = new TFile(filename,"recreate");
271   fDigitTreePtr->Write();
272   delete outfile;
273   outfile = 0;
274   cout << "Done!\n";
275
276 }
277
278 void
279 AliHLTPHOSRcuTreeMakerComponent::ResetTrees()
280 {
281   //comment
282   delete fDigitTreePtr;
283   fDigitTreePtr = new TTree("digitTree", "Digits tree");
284   fTreeMakerPtr->SetDigitTree(fDigitTreePtr);
285 }
286   
287
288   
289   
290   
291
292
293