StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StStrangeCuts.cc
1 /***********************************************************************
2  *
3  * $Id: StStrangeCuts.cc,v 3.6 2009/09/02 19:39:44 genevb Exp $
4  *
5  * Author: Gene Van Buren, UCLA, 26-May-2000
6  *
7  ***********************************************************************
8  *
9  * Description: handling of cuts for strangeness micro DST
10  *
11  ***********************************************************************
12  *
13  * $Log: StStrangeCuts.cc,v $
14  * Revision 3.6 2009/09/02 19:39:44 genevb
15  * Fixes to pointer and string conversions (RT ticket 1612), prep for 64-bit
16  *
17  * Revision 3.5 2009/08/28 16:37:53 fine
18  * fix the compilation issues under SL5_64_bits gcc 4.3.2
19  *
20  * Revision 3.4 2003/02/10 15:59:20 genevb
21  * Fix bug with adding new cuts
22  *
23  * Revision 3.3 2002/05/10 20:57:06 genevb
24  * Minor update
25  *
26  * Revision 3.2 2002/04/30 16:02:47 genevb
27  * Common muDst, improved MC code, better kinks, StrangeCuts now a branch
28  *
29  * Revision 3.1 2001/01/30 04:06:45 genevb
30  * Better handling of file switches
31  *
32  * Revision 3.0 2000/07/14 12:56:49 genevb
33  * Revision 3 has event multiplicities and dedx information for vertex tracks
34  *
35  * Revision 2.0 2000/06/05 05:19:42 genevb
36  * New version of Strangeness micro DST package
37  *
38  *
39  ***********************************************************************/
40 #include "TDataSet.h"
41 #include "TTable.h"
42 #include "TClass.h"
43 #include "TDataMember.h"
44 #include "TDataType.h"
45 #include "TString.h"
46 #include "TClonesArray.h"
47 #include "StStrangeCuts.hh"
48 #include "StMessMgr.h"
49 
50 static const TCut unknownCut("NO or UNKNOWN cuts!","");
51 
52 ClassImp(StStrangeCuts)
53 //_____________________________________________________________________________
54 StStrangeCuts::StStrangeCuts() : TOrdCollection(0) {
55  additionals = 0;
56  lastResetCuts = 0;
57  update = kFALSE;
58  SetOwner(kTRUE);
59  TCut::Class()->IgnoreTObjectStreamer();
60 }
61 //_____________________________________________________________________________
62 StStrangeCuts::~StStrangeCuts() {
63 }
64 //_____________________________________________________________________________
65 void StStrangeCuts::Fill(const char* prefix, TDataSet* cutSet) {
66  // Fill cuts from tables
67  TTable* cutTable = dynamic_cast<TTable*> (cutSet);
68  if (!cutTable) return;
69  TString colName;
70  Char_t buf[16];
71  Int_t nrows = cutTable->GetNRows();
72  TClass* rowClass = cutTable->GetRowClass();
73  for (Int_t row = 0; row<nrows; row++) {
74  for (UInt_t col = 0; col<cutTable->GetNumberOfColumns(); col++) {
75  const Char_t* colBaseName = cutTable->GetColumnName(col);
76  ((colName = prefix) += ".") += colBaseName;
77  if (nrows>1) {
78  sprintf(buf,":%d",row);
79  colName += buf;
80  }
81  Long_t colOffset = (Long_t) (cutTable->GetOffset(col));
82  void* colValue = (void*) (((Long_t) ((*cutTable)[row])) + colOffset);
83  TDataType* colType = rowClass->GetDataMember(colBaseName)->GetDataType();
84  Add(colName.Data(),colType->AsString(colValue));
85  }
86  }
87 }
88 //_____________________________________________________________________________
89 void StStrangeCuts::Append(const TOrdCollection* oldCuts) {
90  // Add any new cuts to any old cuts
91  if (oldCuts) {
92  for (Int_t i=(oldCuts->GetSize() - 1); i>=0; i--) {
93  AddIfNew((TCut*) oldCuts->At(i), kTRUE);
94  }
95  } else {
96  gMessMgr->Warning() << "StStrangeCuts: no StrangeCuts to read in.\n "
97  << " Creating new one." << endm;
98  }
99 }
100 //_____________________________________________________________________________
101 void StStrangeCuts::Reset(const TSeqCollection* oldCuts) {
102  // Check to see if cuts need replaced
103  Int_t cutsSize;
104  if (oldCuts->IsA() == TClonesArray::Class()) {
105  cutsSize = ((TClonesArray*) oldCuts)->GetEntriesFast();
106  } else {
107  cutsSize = oldCuts->GetSize();
108  }
109  Int_t i = 0;
110  StStrangeCuts* theCuts = this;
111  if (additionals) theCuts = lastResetCuts;
112 
113  Bool_t reset = (cutsSize != theCuts->GetSize());
114  while ((!reset) && (i<cutsSize)) {
115  reset = theCuts->NewCut((TCut*) oldCuts->At(i++));
116  }
117 
118  if (reset) {
119  Clear();
120  if (additionals) lastResetCuts->Clear();
121  for (i=0; i<cutsSize; i++) {
122  TCut* oldCutI = (TCut*) (oldCuts->At(i));
123  Add(oldCutI);
124  if (additionals) lastResetCuts->Add(oldCutI);
125  }
126  if (additionals) {
127  for (i=0; i<additionals->GetSize(); i++) {
128  Add((TCut*) (additionals->At(i)));
129  }
130  }
131  }
132 }
133 //_____________________________________________________________________________
134 Bool_t StStrangeCuts::Contains(const TObject* aCut) {
135  for (Int_t i=0; i<GetSize(); i++) {
136  TObject* bCut = At(i);
137  if (!(bCut->Compare(aCut))) {
138  if (!(strcmp(bCut->GetTitle(),aCut->GetTitle())))
139  return kTRUE;
140  }
141  }
142  return kFALSE;
143 }
144 //_____________________________________________________________________________
145 void StStrangeCuts::AddIfNew(TCut* aCut, Bool_t reverse) {
146  if (NewCut(aCut)) {
147  if (reverse) AddFirst(aCut);
148  else AddLast(aCut);
149  ForceUpdateArray();
150  } else {
151  delete aCut;
152  aCut = 0;
153  }
154 }
155 //_____________________________________________________________________________
156 void StStrangeCuts::UpdateArray(TClonesArray* cutsArray) {
157  if (update) {
158  Int_t cutsSize = GetSize();
159  cutsArray->Expand(cutsSize);
160  for (Int_t i=0; i<cutsSize; i++) {
161  new((*cutsArray)[i]) TCut(* CutAt(i));
162  }
163  update = kFALSE;
164  }
165 }
166 //_____________________________________________________________________________
167 void StStrangeCuts::UnknownCuts() {
168  Clear();
169  Add(unknownCut);
170 }
171 //_____________________________________________________________________________
172 void StStrangeCuts::Init() {
173  if (GetSize()) {
174  if (additionals) {
175  additionals->Clear();
176  lastResetCuts->Clear();
177  } else {
178  additionals = new StStrangeCuts();
179  lastResetCuts = new StStrangeCuts();
180  }
181  SetOwner(kFALSE);
182  additionals->AddAll(this);
183  Clear();
184  SetOwner(kTRUE);
185  }
186 }
187 
virtual TClass * GetRowClass() const
to be documented
Definition: TTable.cxx:1375
virtual Long_t GetNRows() const
Returns the number of the used rows for the wrapped table.
Definition: TTable.cxx:1388
Definition: TTable.h:48