StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StStrangeControllerBase.cxx
1 // $Id: StStrangeControllerBase.cxx,v 3.18 2010/03/08 21:16:16 fine Exp $
2 // $Log: StStrangeControllerBase.cxx,v $
3 // Revision 3.18 2010/03/08 21:16:16 fine
4 // remove ROOT 3.x related workaround. RT #1869. Thanks Jeff
5 //
6 // Revision 3.17 2004/08/19 19:55:52 perev
7 // Replace Delete to THack:ClearClone
8 //
9 // Revision 3.16 2003/11/13 02:57:08 perev
10 // LeakOff TClonesArray::Clear() ==> Delete()
11 //
12 // Revision 3.15 2003/05/30 21:20:19 genevb
13 // doxygen savvy, encoding of FTPC mults, change virtual funcs
14 //
15 // Revision 3.14 2003/05/15 21:14:06 jones
16 // Added Copy() function to player, fixed ControllerBase to handle common MuDst names, didn't do it right first time.
17 //
18 // Revision 3.13 2003/04/11 08:06:03 jones
19 // Fix to read in Mc branch(es) of common MuDst
20 //
21 // Revision 3.12 2003/02/10 16:02:24 genevb
22 // Now read files using TChains; no splitting of MuDst file
23 //
24 // Revision 3.11 2002/05/20 21:37:12 genevb
25 // Fixed problem with file names for branches
26 //
27 // Revision 3.10 2002/05/10 20:59:31 genevb
28 // Fixed bug with branch status and changed cuts split level
29 //
30 // Revision 3.9 2002/04/30 16:02:47 genevb
31 // Common muDst, improved MC code, better kinks, StrangeCuts now a branch
32 //
33 // Revision 3.8 2001/11/06 19:45:03 genevb
34 // Prepare for bug fix in Root 3.02/02
35 //
36 // Revision 3.7 2001/11/05 23:41:06 genevb
37 // Add more dEdx, B field info, careful of changes to TTree unrolling
38 //
39 // Revision 3.6 2001/09/14 21:39:02 genevb
40 // Adjustments to not depend on order in which maker Clear() is called
41 //
42 // Revision 3.5 2001/08/23 13:20:53 genevb
43 // Many bug workarounds...
44 //
45 // Revision 3.3 2000/12/18 21:35:18 genevb
46 // Introduced variable buffer-sizing
47 //
48 // Revision 3.2 2000/07/18 15:58:04 genevb
49 // Increased buffer size
50 //
51 // Revision 3.1 2000/07/17 20:28:40 genevb
52 // File size limitation workaround, some under the hood improvements
53 //
54 // Revision 3.0 2000/07/14 12:56:48 genevb
55 // Revision 3 has event multiplicities and dedx information for vertex tracks
56 //
57 // Revision 2.1 2000/06/09 22:17:10 genevb
58 // Allow MC data to be copied between DSTs, other small improvements
59 //
60 // Revision 2.0 2000/06/05 05:19:41 genevb
61 // New version of Strangeness micro DST package
62 //
63 //
65 // //
66 // StStrangeControllerBase strangeness micro DST controller base class //
67 // //
69 #include "StStrangeControllerInclude.h"
70 #include "StStrangeMuDst.hh"
71 #include "TROOT.h"
72 #include "TTree.h"
73 #include "TBranch.h"
74 #include "THack.h"
75 
76 StStrangeMuDstMaker* StStrangeControllerBase::currentMaker = 0;
77 
79 //_____________________________________________________________________________
81 TNamed(strTypeNames[type],"StStrangeController") {
82  dstType = type;
83  masterMaker = currentMaker;
84  doMc = masterMaker->GetDoMc();
85  if ((dstMaker = masterMaker->GetSubDst())) {
86  if (doMc) dstMaker->DoMc();
87  dstMaker->Do(dstType);
88  }
89 
90  increment = 500;
91  max = 1000;
92  bsize=1024000;
93 
94  tree = 0;
95  file = 0;
96  selections = 0;
97  keepers = 0;
98  tempArray = 0;
99  mcName = GetName();
100  mcName += "Mc";
101  assocName = GetName();
102  assocName += "Assoc";
103 
104  TString str;
105  ((str = "St") += GetName()) += "MuDst";
106  dataClass = gROOT->GetClass(str.Data());
107  (str = "St") += mcName;
108  mcClass = gROOT->GetClass(str.Data());
109  assocClass = gROOT->GetClass("StStrangeAssoc");
110 
111  dataArray = new TClonesArray(dataClass->GetName(),max);
112  if (doMc && !(dstMaker)) {
113  mcArray = new TClonesArray(mcClass->GetName(),max);
114  assocArray = new TClonesArray(assocClass->GetName(),max);
115  assocMaker =
116  (StAssociationMaker*) (masterMaker->GetMaker("StAssociationMaker"));
117  } else {
118  mcArray = 0;
119  assocArray = 0;
120  assocMaker = 0;
121  }
122  nEntries = 0;
123  entries = 0;
124  mcEntries = 0;
125  assocEntries = 0;
126 }
127 //_____________________________________________________________________________
128 StStrangeControllerBase::~StStrangeControllerBase() {
129  delete dataArray; dataArray = 0;
130  delete mcArray; mcArray = 0;
131  delete assocArray; assocArray = 0;
132  delete selections; selections = 0;
133  delete keepers; keepers = 0;
134 }
135 //_____________________________________________________________________________
136 StStrangeControllerBase* StStrangeControllerBase::Instantiate(Int_t type){
137  TString nom = strTypeNames[type];
138  TString first = nom;
139  first.Remove(1).ToUpper();
140  nom.Replace(0,1,first);
141  nom.Prepend("St").Append("Controller");
142  TClass* controlClass = gROOT->GetClass(nom.Data());
143  return (StStrangeControllerBase*) ((controlClass) ? controlClass->New() : 0);
144 }
145 //_____________________________________________________________________________
146 void StStrangeControllerBase::InitReadDst() {
147  tree = masterMaker->GetTree();
148  TString statName;
149  (statName = GetName()) += ".*";
150  tree->SetBranchStatus(statName.Data(),1);
151  tree->SetBranchAddress(GetName(),&dataArray);
152  if (doMc) {
153  if (!tree->GetBranch(mcName.Data()))
154  // Common MuDst stores the MC under a different name
155  (mcName = "Mc") += GetName();
156  if (!tree->GetBranch(mcName.Data())) {
157  gMessMgr->Warning() << IsA()->GetName() <<
158  ": No MC data available, continuing without." << endm;
159  doMc = kFALSE;
160  } else {
161  (statName = mcName) += ".*";
162  tree->SetBranchStatus(statName.Data(),1);
163  (statName = assocName) += ".*";
164  tree->SetBranchStatus(statName.Data(),1);
165  tree->SetBranchAddress(mcName.Data(),&mcArray);
166  tree->SetBranchAddress(assocName.Data(),&assocArray);
167  }
168  }
169 }
170 //_____________________________________________________________________________
171 void StStrangeControllerBase::InitCreateDst() {
172  tree = masterMaker->GetTree();
173  file = masterMaker->GetFile();
174  AssignBranch(GetName(),&dataArray);
175  if (doMc && !(dstMaker)) {
176  AssignBranch(GetMcName(),&mcArray);
177  AssignBranch(GetAssocName(),&assocArray);
178  }
179 }
180 //_____________________________________________________________________________
181 void StStrangeControllerBase::InitCreateSubDst() {
182  selections = new TArrayI(max);
183  keepers = new TArrayS(max);
184  StStrangeControllerBase* dstController = GetDstController();
185  tempArray = dstController->GetDataArray();
186  if (doMc) {
187  if (!dstMaker->GetTree()->GetBranch(mcName.Data()))
188  // Common MuDst stores the MC under a different name
189  (mcName = "Mc") += GetName();
190  if (!dstMaker->GetTree()->GetBranch(mcName.Data())) {
191  gMessMgr->Warning() << IsA()->GetName() <<
192  ": No MC data available, continuing without." << endm;
193  doMc = kFALSE;
194  } else {
195  mcArray = dstController->GetMcArray();
196  assocArray = dstController->GetAssocArray();
197  AssignBranch(GetMcName(),&mcArray);
198  AssignBranch(GetAssocName(),&assocArray);
199  }
200  }
201 }
202 //_____________________________________________________________________________
203 TBranch* StStrangeControllerBase::AssignBranch(const char* name,
204  TClonesArray** address) {
205 
206  static Int_t split=99;
207  TBranch* branch = tree->Branch(name,address,bsize,split);
208  return branch;
209 }
210 //_____________________________________________________________________________
211 Int_t StStrangeControllerBase::MakeCreateSubDst() {
212  // If no entries to copy, skip data and association copying
213  if (!entries) {
214  if (doMc) THack::ClearClonesArray(assocArray);
215  return kStOK;
216  }
217 
218  // Must reassign associations with MC vertices
219  if (doMc && (selections->At(0) >= 0)) {
220  for (Int_t j=0;j<GetNAssoc(); j++) {
221  StStrangeAssoc* assocEntry = GetAssoc(j);
222  Int_t inReAr = assocEntry->indexRecoArray();
223  if (keepers->At(inReAr)) {
224  Int_t k=0;
225  while (selections->At(k) != inReAr) { k++; }
226  assocEntry->setIndexRecoArray(k);
227  } else {
228  assocArray->RemoveAt(j);
229  }
230  }
231  assocArray->Compress();
232  }
233 
234  Int_t classSize = dataClass->Size();
235  // Event info copied directly from dstMaker.
236  if (selections->At(0) < 0) { // Copy all from the event
237  tree->SetBranchAddress(GetName(),&tempArray);
238  } else if (entries) { // Copy selected from the event
239  Int_t asize = dataArray->GetSize();
240  if (entries > asize) dataArray->Expand(entries+increment);
241  StStrangeControllerBase* dstController = GetDstController();
242  for (Int_t k=0; k<entries; k++) {
243 // Replacing the following standard allocation with faster memcpy
244 // new((*dataArray)[k]) StV0MuDst(*((StV0MuDst*)
245 // (GetDstController()->Get((*selections)[k]))));
246  memcpy((*dataArray)[k],dstController->Get(selections->At(k)),classSize);
247  }
248  }
249  PrintNumCand("copying",entries);
250  nEntries += entries;
251 
252  return kStOK;
253 }
254 //_____________________________________________________________________________
255 void StStrangeControllerBase::Clear(Option_t* opt) {
256  if (dstMaker) { // Making a subDST
257  if (selections) {
258  selections->Reset();
259  keepers->Reset();
260  }
261  if (tree->GetBranch(GetName())->GetAddress() != (char*) &dataArray) {
262  tree->SetBranchAddress(GetName(),&dataArray);
263  }
264  }
265  if (dataArray) {
266  THack::ClearClonesArray(dataArray);
267  entries = 0;
268  if (doMc) {
269  THack::ClearClonesArray(mcArray);
270  mcEntries = 0;
271  THack::ClearClonesArray(assocArray);
272  assocEntries = 0;
273  }
274  }
275 }
276 //_____________________________________________________________________________
277 void StStrangeControllerBase::Finish() {
278  TString fin = "Total ";
279  if (masterMaker->GetMode() == StrangeRead) fin += "read:";
280  else fin += "kept:";
281  PrintNumCand(fin.Data(),nEntries);
282 }
283 //_____________________________________________________________________________
284 void StStrangeControllerBase::Select(Int_t i) {
285  if ((!selections) || (!dstMaker) || (selections->At(0) < 0)) return;
286  Int_t ent = GetDstController()->GetN();
287  if (i < 0) {
288  selections->Reset();
289  selections->AddAt(i,0);
290  keepers->Reset(1);
291  entries = ent;
292  } else if (i < ent) {
293  if (ent > selections->GetSize()) selections->Set(ent+increment);
294  if (ent > keepers->GetSize()) keepers->Set(ent);
295  if (!(keepers->At(i))) {
296  selections->AddAt(i,entries++);
297  keepers->AddAt(1,i);
298  }
299  }
300 }
301 //_____________________________________________________________________________
302 void StStrangeControllerBase::Unselect(Int_t i) {
303  if ((!selections) || (!dstMaker) || (!entries)) return;
304  if (i<0) {
305  entries = 0;
306  selections->AddAt(0,0);
307  keepers->Reset();
308  return;
309  }
310  Int_t ent = GetDstController()->GetN();
311  if (i >= ent) return;
312  if (selections->At(0) < 0) {
313  // If entire event selected, set to none and select each individual entry
314  Unselect(-1);
315  for (Int_t entry=0; entry<ent; entry++) {
316  if (i != entry) Select(entry);
317  }
318  } else {
319  keepers->AddAt(0,i);
320  for (Int_t entry=(entries-1); entry>=0; entry--) {
321  if (i == selections->At(entry)) {
322  entries--;
323  // Cheap and fast step: move last entry to the unselected one
324  // Cost: order of selection is lost
325  if (entries) selections->AddAt(selections->At(entries),entry);
326  return;
327  }
328  }
329  }
330 }
331 //_____________________________________________________________________________
332 void StStrangeControllerBase::PrintNumMc() {
333  gMessMgr->Info("","O-") << IsA()->GetName() << ": found " <<
334  mcEntries << " Monte Carlo " << GetName() << "s" << endm;
335  gMessMgr->Info("","O-") << IsA()->GetName() << ": found " <<
336  assocEntries << " " << GetName() << " associations" << endm;
337 }
338 //_____________________________________________________________________________
339 TClonesArray* StStrangeControllerBase::GetArray(Int_t branchType) {
340  switch (branchType) {
341  case (dataBranch) : return dataArray;
342  case (mcBranch) : return mcArray;
343  case (assocBranch) : return assocArray;
344  default : {}
345  }
346  return 0;
347 }
348 
virtual const char * GetName() const
special overload
Definition: StMaker.cxx:237
Definition: Stypes.h:40