]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/TRD/AliHLTTRDEsdWriterComponent.cxx
HLTcalo module
[u/mrichter/AliRoot.git] / HLT / TRD / AliHLTTRDEsdWriterComponent.cxx
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"
24 #include "AliHLTTRDDefinitions.h"
25 #include "AliHLTTRDUtils.h"
26 #include "AliHLTCTPData.h"
27 #include "AliESDEvent.h"
28 #include "AliESDfriend.h"
29 #include "AliESDtrack.h"
30 #include "AliTRDtrackV1.h"
31 #include "TTree.h"
32 #include "TFile.h"
33
34 /** ROOT macro for the implementation of ROOT specific class methods */
35 ClassImp(AliHLTTRDEsdWriterComponent)
36
37 AliHLTTRDEsdWriterComponent::AliHLTTRDEsdWriterComponent()
38 :AliHLTRootFileWriterComponent()
39   ,fTree(NULL)
40   ,fFrTree(NULL)
41   ,fESD(NULL)
42   ,fESDfriend(NULL)
43   ,fFile(NULL)
44   ,fFrFile(NULL)
45   ,fTracksArray(NULL)
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
54 AliHLTTRDEsdWriterComponent::AliHLTTRDEsdWriterComponent(const AliHLTTRDEsdWriterComponent&)
55   :AliHLTRootFileWriterComponent()
56   ,fTree(NULL)
57   ,fFrTree(NULL)
58   ,fESD(NULL)
59   ,fESDfriend(NULL)
60   ,fFile(NULL)
61   ,fFrFile(NULL)
62   ,fTracksArray(NULL)
63 {
64 }
65
66 void 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).
70   list.push_back( AliHLTTRDDefinitions::fgkTracksDataType );
71   list.push_back( AliHLTTRDDefinitions::fgkHiLvlTracksDataType );
72 }
73
74 AliHLTTRDEsdWriterComponent::~AliHLTTRDEsdWriterComponent()
75 {
76   // see header file for class documentation
77 }
78
79 int AliHLTTRDEsdWriterComponent::InitWriter()
80 {
81   // see header file for class documentation
82   
83   fFile = new TFile("AliHLTTRDESDs.root", "recreate");
84   fESD = new AliESDEvent;
85   fESD->CreateStdContent();
86   fTree = new TTree("esdTree", "Tree with HLT::TRD ESD objects");
87   fESD->WriteToTree(fTree);
88   fFrFile = new TFile("AliHLTTRDESDfriends.root", "recreate");
89   fESDfriend = new AliESDfriend();
90   fFrTree = new TTree("esdFriendTree", "Tree with HLT::TRD ESD Friend objects");
91   fFrTree->Branch("ESDfriend.","AliESDfriend", &fESDfriend);
92   fESD->AddObject(fESDfriend);
93   fFile->cd();
94   fTree->GetUserInfo()->Add(fESD);
95   fTracksArray = new TClonesArray("AliTRDtrackV1");
96
97   SetupCTPData();
98
99   return 0;
100 }
101
102 int AliHLTTRDEsdWriterComponent::CloseWriter()
103 {
104   // see header file for class documentation
105
106   //fTree->Print();
107   fFile->cd();
108   fTree->Write(fTree->GetName(),TObject::kOverwrite);
109   fFile->Write();
110   fFile->Close();
111   fFrFile->cd();
112   fFrTree->Write(fFrTree->GetName(),TObject::kOverwrite);
113   fFrFile->Write();
114   fFrFile->Close();
115   delete fFile; fFile=0;
116   delete fFrFile; fFrFile=0;
117   //delete fTree;
118   delete fTracksArray; fTracksArray=0;
119
120   return AliHLTRootFileWriterComponent::CloseWriter();
121 }
122
123 int AliHLTTRDEsdWriterComponent::DumpEvent( const AliHLTComponentEventData& /*evtData*/,
124                                             const AliHLTComponentBlockData* /*blocks*/, 
125                                             AliHLTComponentTriggerData& trigData )
126 {
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;
130
131   for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(AliHLTTRDDefinitions::fgkTracksDataType); pBlock; pBlock=GetNextInputBlock()) 
132     {
133       TCAarray[0] = fTracksArray;
134       AliHLTTRDUtils::ReadTracks(TCAarray[0], pBlock->fPtr, pBlock->fSize);
135       usedEntries = 1;
136       blockOrObject = -1;
137     }
138
139   for(const TObject *iter = GetFirstInputObject(AliHLTTRDDefinitions::fgkHiLvlTracksDataType); iter; iter = GetNextInputObject()) 
140     {
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;
150     }
151
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());
162   fESD->SetEventType(7);
163
164   const AliHLTCTPData* pCTPData=CTPData();
165   if (pCTPData) {
166     AliHLTTriggerMask_t mask=pCTPData->ActiveTriggers(trigData);
167     for (int index=0; index<gkNCTPTriggerClasses; index++) {
168       if ((mask&(AliHLTTriggerMask_t(0x1)<<index)) == 0) continue;
169       fESD->SetTriggerClass(pCTPData->Name(index), index);
170     }
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     */
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;
194     }
195   }
196   
197   fESD->GetESDfriend(fESDfriend);
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);
202   fESD->Reset();
203   fESDfriend->~AliESDfriend();
204   new (fESDfriend) AliESDfriend();
205
206   if(blockOrObject<0){
207     TCAarray[0]->Delete();
208   }
209
210   return 0;
211 }