EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PndTrackArrayMerger.cxx
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file PndTrackArrayMerger.cxx
1 //
2 // This class COPIES PndTrack objects from all specified input branches
3 // into one output branch. Linking is still to be done...
4 //
5 // Aurthor: R.Kliemt, May 2011
6 
7 #include "PndTrackArrayMerger.h"
8 #include "PndTrackCand.h"
9 #include "PndTrack.h"
10 #include <iostream>
11 
12 
14 :fPersistance(kTRUE), fOutputBranch("ALLTracks"), fOutputArray(), fInputArrayList(), fInputBranchList()
15 {}
16 
18 :fPersistance(kTRUE), fOutputBranch(s), fOutputArray(), fInputArrayList(), fInputBranchList()
19 {}
20 
22 {}
23 
25 {return;}
26 
28 {return kSUCCESS;}
29 
30 
32 {
34  if ( ! ioman )
35  {
36  std::cout << "-E- PndSdsStripHitProducer::Init: "
37  << "RootManager not instantiated!" << std::endl;
38  return kFATAL;
39  }
40 
41  //setup input arrays
42  TClonesArray* tmparray;
43  for(std::vector<TString>::iterator iter = fInputBranchList.begin(); iter!=fInputBranchList.end();++iter)
44  {
45  tmparray = (TClonesArray*) ioman->GetObject((*iter).Data());
46  if ( ! tmparray )
47  {
48  Error("Init()","No %s array! Skipping that name.",(*iter).Data());
49  continue;
50  }
51  TString namebuff = (TString) tmparray->GetClass()->GetName();
52  if(namebuff == "PndTrack"){
53  fInputArrayList.push_back(tmparray);
54  }
55  }
56 
57  //setup output array
58  fOutputArray = ioman->Register(fOutputBranch, "PndTrack", "AllTracks", fPersistance);
59  //fOutputArray = new TClonesArray("PndTrack");
60  // ioman->Register(fOutputBranch, "AllTracks", fOutputArray, fPersistance);
61 
62  return kSUCCESS;
63 }
64 
65 void PndTrackArrayMerger::Exec(Option_t* opt)
66 {
67  fOutputArray->Clear();
68  // copy data from input arrays to output array
69  TClonesArray* tmparray;
70  PndTrack* tmptrk;
71  Int_t namenum=0;
72  TString brname;
73  Int_t entries=0;
74 
75 
76  for(std::vector<TClonesArray*>::iterator iter = fInputArrayList.begin(); iter!=fInputArrayList.end();++iter)
77  {
78  tmparray=*iter;
79 #if ROOT_VERSION_CODE >= ROOT_VERSION(5,29,1)
80  // MOVES References into a new TCA
81  // Just from root 5.29.02
82  if (tmparray != 0) {
83  fOutputArray->AbsorbObjects(tmparray, 0, tmparray->GetEntries() - 1);
84  }
85 #else
86  brname=fInputBranchList[namenum];
87  for ( Int_t i=0;i<tmparray->GetEntriesFast();i++)
88  {
89  tmptrk=(PndTrack*)tmparray->At(i);
90  entries=fOutputArray->GetEntriesFast();
91  PndTrack* mynewtrack = new ((*fOutputArray)[entries])
92  PndTrack(tmptrk->GetParamFirst(),tmptrk->GetParamLast(),*(tmptrk->GetTrackCandPtr()),
93  tmptrk->GetFlag(), tmptrk->GetChi2(), tmptrk->GetNDF(),
94  tmptrk->GetPidHypo(),-1,-1);
95  mynewtrack->Reset(); //resetting links
96  for(int nlin=0;nlin<tmptrk->GetNLinks();nlin++)
97  {
98  mynewtrack->AddLink(tmptrk->GetLink(nlin));
99  }
100  }
101  namenum++;
102 #endif
103  }
104 
105  return;
106 }
107 
109 {
110  // called after all Tasks did their Exex() and the data is copied to the file
111 // fOutputArray->Clear();
112  FinishEvents();
113 }
114 
116