ALIROOT-5433 Transition to CDHv3 in HLT
[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)
f9778343 40 ,fFrTree(NULL)
d135ae21 41 ,fESD(NULL)
42 ,fESDfriend(NULL)
43 ,fFile(NULL)
f9778343 44 ,fFrFile(NULL)
d135ae21 45 ,fTracksArray(NULL)
808618f5 46{
47 // see header file for class documentation
48 // or
49 // refer to README to build package
50 // or
51 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
52}
53
54AliHLTTRDEsdWriterComponent::AliHLTTRDEsdWriterComponent(const AliHLTTRDEsdWriterComponent&)
d135ae21 55 :AliHLTRootFileWriterComponent()
56 ,fTree(NULL)
f9778343 57 ,fFrTree(NULL)
d135ae21 58 ,fESD(NULL)
59 ,fESDfriend(NULL)
60 ,fFile(NULL)
6840d0ab 61 ,fFrFile(NULL)
d135ae21 62 ,fTracksArray(NULL)
808618f5 63{
808618f5 64}
65
66void AliHLTTRDEsdWriterComponent::GetInputDataTypes( vector<AliHLTComponent_DataType>& list)
67{
68 // Get the list of input data
69 list.clear(); // We do not have any requirements for our input data type(s).
07f31c0e 70 list.push_back( AliHLTTRDDefinitions::fgkTracksDataType );
d135ae21 71 list.push_back( AliHLTTRDDefinitions::fgkHiLvlTracksDataType );
808618f5 72}
73
74AliHLTTRDEsdWriterComponent::~AliHLTTRDEsdWriterComponent()
75{
76 // see header file for class documentation
77}
78
79int AliHLTTRDEsdWriterComponent::InitWriter()
80{
81 // see header file for class documentation
d135ae21 82
83 fFile = new TFile("AliHLTTRDESDs.root", "recreate");
808618f5 84 fESD = new AliESDEvent;
d135ae21 85 fESD->CreateStdContent();
f9778343 86 fTree = new TTree("esdTree", "Tree with HLT::TRD ESD objects");
d135ae21 87 fESD->WriteToTree(fTree);
f9778343 88 fFrFile = new TFile("AliHLTTRDESDfriends.root", "recreate");
d135ae21 89 fESDfriend = new AliESDfriend();
f9778343 90 fFrTree = new TTree("esdFriendTree", "Tree with HLT::TRD ESD Friend objects");
91 fFrTree->Branch("ESDfriend.","AliESDfriend", &fESDfriend);
d135ae21 92 fESD->AddObject(fESDfriend);
f9778343 93 fFile->cd();
d135ae21 94 fTree->GetUserInfo()->Add(fESD);
95 fTracksArray = new TClonesArray("AliTRDtrackV1");
96
97 SetupCTPData();
98
99 return 0;
808618f5 100}
101
102int AliHLTTRDEsdWriterComponent::CloseWriter()
103{
104 // see header file for class documentation
d135ae21 105
106 //fTree->Print();
f9778343 107 fFile->cd();
108 fTree->Write(fTree->GetName(),TObject::kOverwrite);
d135ae21 109 fFile->Write();
110 fFile->Close();
f9778343 111 fFrFile->cd();
112 fFrTree->Write(fFrTree->GetName(),TObject::kOverwrite);
113 fFrFile->Write();
114 fFrFile->Close();
d135ae21 115 delete fFile; fFile=0;
f9778343 116 delete fFrFile; fFrFile=0;
d135ae21 117 //delete fTree;
118 delete fTracksArray; fTracksArray=0;
119
120 return AliHLTRootFileWriterComponent::CloseWriter();
808618f5 121}
122
d135ae21 123int AliHLTTRDEsdWriterComponent::DumpEvent( const AliHLTComponentEventData& /*evtData*/,
124 const AliHLTComponentBlockData* /*blocks*/,
125 AliHLTComponentTriggerData& trigData )
808618f5 126{
d135ae21 127 TClonesArray* TCAarray[18] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
128 Int_t usedEntries = 0;
129 Int_t blockOrObject = 0;
808618f5 130
d135ae21 131 for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(AliHLTTRDDefinitions::fgkTracksDataType); pBlock; pBlock=GetNextInputBlock())
808618f5 132 {
d135ae21 133 TCAarray[0] = fTracksArray;
134 AliHLTTRDUtils::ReadTracks(TCAarray[0], pBlock->fPtr, pBlock->fSize);
135 usedEntries = 1;
136 blockOrObject = -1;
808618f5 137 }
808618f5 138
d135ae21 139 for(const TObject *iter = GetFirstInputObject(AliHLTTRDDefinitions::fgkHiLvlTracksDataType); iter; iter = GetNextInputObject())
808618f5 140 {
d135ae21 141 if(blockOrObject<0){
142 HLTError("You may not mix high level and low level!");
143 return -1;
144 }
145
146 TCAarray[usedEntries] = dynamic_cast<TClonesArray*>(const_cast<TObject*>(iter));
147 if(!TCAarray[usedEntries])continue;
148 usedEntries++;
149 blockOrObject = 1;
808618f5 150 }
151
d135ae21 152 if(!blockOrObject)
153 return 0;
154
155 fESD->Reset();
156 fESD->SetMagneticField(GetBz());
157 fESD->SetRunNumber(GetRunNo());
158 fESD->SetPeriodNumber(GetPeriodNumber());
159 fESD->SetOrbitNumber(GetOrbitNumber());
160 fESD->SetBunchCrossNumber(GetBunchCrossNumber());
161 fESD->SetTimeStamp(GetTimeStamp());
d9f9c395 162 fESD->SetEventType(7);
d135ae21 163
164 const AliHLTCTPData* pCTPData=CTPData();
165 if (pCTPData) {
16e6f752 166 AliHLTTriggerMask_t mask=pCTPData->ActiveTriggers(trigData);
d135ae21 167 for (int index=0; index<gkNCTPTriggerClasses; index++) {
16e6f752 168 if ((mask&(AliHLTTriggerMask_t(0x1)<<index)) == 0) continue;
d135ae21 169 fESD->SetTriggerClass(pCTPData->Name(index), index);
808618f5 170 }
16e6f752 171 //first 50 triggers
172 AliHLTTriggerMask_t mask50;
173 mask50.set(); // set all bits
174 mask50 >>= 50; // shift 50 right
175 fESD->SetTriggerMask((mask&mask50).to_ulong());
176 /* next 50, to be implemented
177 pESD->SetTriggerMaskNext50((mask>>50).to_ulong());
178 */
d135ae21 179 }
180
181 for(int i=0; i<usedEntries; i++){
182 const TClonesArray* inArr = TCAarray[i];
183 for(int ii=0; ii<inArr->GetEntriesFast(); ii++){
184 AliTRDtrackV1* inV1 = (AliTRDtrackV1*)inArr->UncheckedAt(ii);
185 AliESDtrack *esdTrack = new AliESDtrack();
186 esdTrack->UpdateTrackParams(inV1, AliESDtrack::kTRDout);
187 esdTrack->SetLabel(inV1->GetLabel());
188 inV1->UpdateESDtrack(esdTrack);
189 AliTRDtrackV1 *calibTrack = new AliTRDtrackV1(*inV1);
190 calibTrack->SetOwner();
191 esdTrack->AddCalibObject(calibTrack);
192 fESD->AddTrack(esdTrack);
193 delete esdTrack;
dc2e6604 194 }
d135ae21 195 }
196
197 fESD->GetESDfriend(fESDfriend);
f9778343 198 Int_t nb = fTree->Fill();
199 HLTInfo("Tree filled with %i bytes\n", nb);
200 nb = fFrTree->Fill();
201 HLTInfo("FrTree filled with %i bytes\n", nb);
d135ae21 202 fESD->Reset();
203 fESDfriend->~AliESDfriend();
204 new (fESDfriend) AliESDfriend();
205
206 if(blockOrObject<0){
207 TCAarray[0]->Delete();
208 }
dc2e6604 209
210 return 0;
211}