reactivating TRDEsdWriterComponent to write ESDEvents with Esdfriends (Theodor)
[u/mrichter/AliRoot.git] / HLT / TRD / AliHLTTRDEsdWriterComponent.cxx
CommitLineData
808618f5 1/**************************************************************************
2 * This file is property of and copyright by the ALICE HLT Project *
3 * ALICE Experiment at CERN, All rights reserved. *
4 * *
5 * Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no> *
6 * for The ALICE HLT Project. *
7 * *
8 * Permission to use, copy, modify and distribute this software and its *
9 * documentation strictly for non-commercial purposes is hereby granted *
10 * without fee, provided that the above copyright notice appears in all *
11 * copies and that both the copyright notice and this permission notice *
12 * appear in the supporting documentation. The authors make no claims *
13 * about the suitability of this software for any purpose. It is *
14 * provided "as is" without express or implied warranty. *
15 **************************************************************************/
16
17/** @file AliHLTTRDEsdWriterComponent.cxx
18 @author Mateusz Ploskon
19 @date
20 @brief Writer component to store tracks of the HLT TRD
21
22 */
23#include "AliHLTTRDEsdWriterComponent.h"
d135ae21 24#include "AliHLTTRDDefinitions.h"
25#include "AliHLTTRDUtils.h"
26#include "AliHLTCTPData.h"
808618f5 27#include "AliESDEvent.h"
d135ae21 28#include "AliESDfriend.h"
808618f5 29#include "AliESDtrack.h"
d135ae21 30#include "AliTRDtrackV1.h"
808618f5 31#include "TTree.h"
d135ae21 32#include "TFile.h"
808618f5 33
34/** ROOT macro for the implementation of ROOT specific class methods */
35ClassImp(AliHLTTRDEsdWriterComponent)
36
37AliHLTTRDEsdWriterComponent::AliHLTTRDEsdWriterComponent()
d135ae21 38:AliHLTRootFileWriterComponent()
39 ,fTree(NULL)
40 ,fESD(NULL)
41 ,fESDfriend(NULL)
42 ,fFile(NULL)
43 ,fTracksArray(NULL)
808618f5 44{
45 // see header file for class documentation
46 // or
47 // refer to README to build package
48 // or
49 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
50}
51
52AliHLTTRDEsdWriterComponent::AliHLTTRDEsdWriterComponent(const AliHLTTRDEsdWriterComponent&)
d135ae21 53 :AliHLTRootFileWriterComponent()
54 ,fTree(NULL)
55 ,fESD(NULL)
56 ,fESDfriend(NULL)
57 ,fFile(NULL)
58 ,fTracksArray(NULL)
808618f5 59{
808618f5 60}
61
62void AliHLTTRDEsdWriterComponent::GetInputDataTypes( vector<AliHLTComponent_DataType>& list)
63{
64 // Get the list of input data
65 list.clear(); // We do not have any requirements for our input data type(s).
07f31c0e 66 list.push_back( AliHLTTRDDefinitions::fgkTracksDataType );
d135ae21 67 list.push_back( AliHLTTRDDefinitions::fgkHiLvlTracksDataType );
808618f5 68}
69
70AliHLTTRDEsdWriterComponent::~AliHLTTRDEsdWriterComponent()
71{
72 // see header file for class documentation
73}
74
75int AliHLTTRDEsdWriterComponent::InitWriter()
76{
77 // see header file for class documentation
d135ae21 78
79 fFile = new TFile("AliHLTTRDESDs.root", "recreate");
80 fFile->cd();
808618f5 81 fESD = new AliESDEvent;
d135ae21 82 fESD->CreateStdContent();
83 fTree = new TTree("esdTree", "Tree with HLT ESD objects");
84 fESD->WriteToTree(fTree);
85 fESDfriend = new AliESDfriend();
86 /*TBranch* br=*/fTree->Branch("ESDfriend.","AliESDfriend", &fESDfriend);
87 //br->SetFile("AliHLTTRDESDfriends.root");
88 fESD->AddObject(fESDfriend);
89 fTree->GetUserInfo()->Add(fESD);
90 fTracksArray = new TClonesArray("AliTRDtrackV1");
91
92 SetupCTPData();
93
94 return 0;
808618f5 95}
96
97int AliHLTTRDEsdWriterComponent::CloseWriter()
98{
99 // see header file for class documentation
d135ae21 100
101 //fTree->Print();
102 fFile->Write();
103 fFile->Close();
104 delete fFile; fFile=0;
105 //delete fTree;
106 delete fTracksArray; fTracksArray=0;
107
108 return AliHLTRootFileWriterComponent::CloseWriter();
808618f5 109}
110
d135ae21 111int AliHLTTRDEsdWriterComponent::DumpEvent( const AliHLTComponentEventData& /*evtData*/,
112 const AliHLTComponentBlockData* /*blocks*/,
113 AliHLTComponentTriggerData& trigData )
808618f5 114{
d135ae21 115 TClonesArray* TCAarray[18] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
116 Int_t usedEntries = 0;
117 Int_t blockOrObject = 0;
808618f5 118
d135ae21 119 for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(AliHLTTRDDefinitions::fgkTracksDataType); pBlock; pBlock=GetNextInputBlock())
808618f5 120 {
d135ae21 121 TCAarray[0] = fTracksArray;
122 AliHLTTRDUtils::ReadTracks(TCAarray[0], pBlock->fPtr, pBlock->fSize);
123 usedEntries = 1;
124 blockOrObject = -1;
808618f5 125 }
808618f5 126
d135ae21 127 for(const TObject *iter = GetFirstInputObject(AliHLTTRDDefinitions::fgkHiLvlTracksDataType); iter; iter = GetNextInputObject())
808618f5 128 {
d135ae21 129 if(blockOrObject<0){
130 HLTError("You may not mix high level and low level!");
131 return -1;
132 }
133
134 TCAarray[usedEntries] = dynamic_cast<TClonesArray*>(const_cast<TObject*>(iter));
135 if(!TCAarray[usedEntries])continue;
136 usedEntries++;
137 blockOrObject = 1;
808618f5 138 }
139
d135ae21 140 if(!blockOrObject)
141 return 0;
142
143 fESD->Reset();
144 fESD->SetMagneticField(GetBz());
145 fESD->SetRunNumber(GetRunNo());
146 fESD->SetPeriodNumber(GetPeriodNumber());
147 fESD->SetOrbitNumber(GetOrbitNumber());
148 fESD->SetBunchCrossNumber(GetBunchCrossNumber());
149 fESD->SetTimeStamp(GetTimeStamp());
150
151 const AliHLTCTPData* pCTPData=CTPData();
152 if (pCTPData) {
153 AliHLTUInt64_t mask=pCTPData->ActiveTriggers(trigData);
154 for (int index=0; index<gkNCTPTriggerClasses; index++) {
155 if ((mask&((AliHLTUInt64_t)0x1<<index)) == 0) continue;
156 fESD->SetTriggerClass(pCTPData->Name(index), index);
808618f5 157 }
d135ae21 158 fESD->SetTriggerMask(mask);
159 }
160
161 for(int i=0; i<usedEntries; i++){
162 const TClonesArray* inArr = TCAarray[i];
163 for(int ii=0; ii<inArr->GetEntriesFast(); ii++){
164 AliTRDtrackV1* inV1 = (AliTRDtrackV1*)inArr->UncheckedAt(ii);
165 AliESDtrack *esdTrack = new AliESDtrack();
166 esdTrack->UpdateTrackParams(inV1, AliESDtrack::kTRDout);
167 esdTrack->SetLabel(inV1->GetLabel());
168 inV1->UpdateESDtrack(esdTrack);
169 AliTRDtrackV1 *calibTrack = new AliTRDtrackV1(*inV1);
170 calibTrack->SetOwner();
171 esdTrack->AddCalibObject(calibTrack);
172 fESD->AddTrack(esdTrack);
173 delete esdTrack;
dc2e6604 174 }
d135ae21 175 }
176
177 fESD->GetESDfriend(fESDfriend);
178 Int_t nb = fTree->Fill(); //endless-
179 printf("Tree filled with %i bytes\n", nb);
180 fESD->Reset();
181 fESDfriend->~AliESDfriend();
182 new (fESDfriend) AliESDfriend();
183
184 if(blockOrObject<0){
185 TCAarray[0]->Delete();
186 }
dc2e6604 187
188 return 0;
189}