00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00065
00066
00067
00069 #include "StStrangeControllerInclude.h"
00070 #include "StStrangeMuDst.hh"
00071 #include "TROOT.h"
00072 #include "TTree.h"
00073 #include "TBranch.h"
00074 #include "THack.h"
00075
00076 StStrangeMuDstMaker* StStrangeControllerBase::currentMaker = 0;
00077
00078 ClassImp(StStrangeControllerBase)
00079
00080 StStrangeControllerBase::StStrangeControllerBase(Int_t type) :
00081 TNamed(strTypeNames[type],"StStrangeController") {
00082 dstType = type;
00083 masterMaker = currentMaker;
00084 doMc = masterMaker->GetDoMc();
00085 if ((dstMaker = masterMaker->GetSubDst())) {
00086 if (doMc) dstMaker->DoMc();
00087 dstMaker->Do(dstType);
00088 }
00089
00090 increment = 500;
00091 max = 1000;
00092 bsize=1024000;
00093
00094 tree = 0;
00095 file = 0;
00096 selections = 0;
00097 keepers = 0;
00098 tempArray = 0;
00099 mcName = GetName();
00100 mcName += "Mc";
00101 assocName = GetName();
00102 assocName += "Assoc";
00103
00104 TString str;
00105 ((str = "St") += GetName()) += "MuDst";
00106 dataClass = gROOT->GetClass(str.Data());
00107 (str = "St") += mcName;
00108 mcClass = gROOT->GetClass(str.Data());
00109 assocClass = gROOT->GetClass("StStrangeAssoc");
00110
00111 dataArray = new TClonesArray(dataClass->GetName(),max);
00112 if (doMc && !(dstMaker)) {
00113 mcArray = new TClonesArray(mcClass->GetName(),max);
00114 assocArray = new TClonesArray(assocClass->GetName(),max);
00115 assocMaker =
00116 (StAssociationMaker*) (masterMaker->GetMaker("StAssociationMaker"));
00117 } else {
00118 mcArray = 0;
00119 assocArray = 0;
00120 assocMaker = 0;
00121 }
00122 nEntries = 0;
00123 entries = 0;
00124 mcEntries = 0;
00125 assocEntries = 0;
00126 }
00127
00128 StStrangeControllerBase::~StStrangeControllerBase() {
00129 delete dataArray; dataArray = 0;
00130 delete mcArray; mcArray = 0;
00131 delete assocArray; assocArray = 0;
00132 delete selections; selections = 0;
00133 delete keepers; keepers = 0;
00134 }
00135
00136 StStrangeControllerBase* StStrangeControllerBase::Instantiate(Int_t type){
00137 TString nom = strTypeNames[type];
00138 TString first = nom;
00139 first.Remove(1).ToUpper();
00140 nom.Replace(0,1,first);
00141 nom.Prepend("St").Append("Controller");
00142 TClass* controlClass = gROOT->GetClass(nom.Data());
00143 return (StStrangeControllerBase*) ((controlClass) ? controlClass->New() : 0);
00144 }
00145
00146 void StStrangeControllerBase::InitReadDst() {
00147 tree = masterMaker->GetTree();
00148 TString statName;
00149 (statName = GetName()) += ".*";
00150 tree->SetBranchStatus(statName.Data(),1);
00151 tree->SetBranchAddress(GetName(),&dataArray);
00152 if (doMc) {
00153 if (!tree->GetBranch(mcName.Data()))
00154
00155 (mcName = "Mc") += GetName();
00156 if (!tree->GetBranch(mcName.Data())) {
00157 gMessMgr->Warning() << IsA()->GetName() <<
00158 ": No MC data available, continuing without." << endm;
00159 doMc = kFALSE;
00160 } else {
00161 (statName = mcName) += ".*";
00162 tree->SetBranchStatus(statName.Data(),1);
00163 (statName = assocName) += ".*";
00164 tree->SetBranchStatus(statName.Data(),1);
00165 tree->SetBranchAddress(mcName.Data(),&mcArray);
00166 tree->SetBranchAddress(assocName.Data(),&assocArray);
00167 }
00168 }
00169 }
00170
00171 void StStrangeControllerBase::InitCreateDst() {
00172 tree = masterMaker->GetTree();
00173 file = masterMaker->GetFile();
00174 AssignBranch(GetName(),&dataArray);
00175 if (doMc && !(dstMaker)) {
00176 AssignBranch(GetMcName(),&mcArray);
00177 AssignBranch(GetAssocName(),&assocArray);
00178 }
00179 }
00180
00181 void StStrangeControllerBase::InitCreateSubDst() {
00182 selections = new TArrayI(max);
00183 keepers = new TArrayS(max);
00184 StStrangeControllerBase* dstController = GetDstController();
00185 tempArray = dstController->GetDataArray();
00186 if (doMc) {
00187 if (!dstMaker->GetTree()->GetBranch(mcName.Data()))
00188
00189 (mcName = "Mc") += GetName();
00190 if (!dstMaker->GetTree()->GetBranch(mcName.Data())) {
00191 gMessMgr->Warning() << IsA()->GetName() <<
00192 ": No MC data available, continuing without." << endm;
00193 doMc = kFALSE;
00194 } else {
00195 mcArray = dstController->GetMcArray();
00196 assocArray = dstController->GetAssocArray();
00197 AssignBranch(GetMcName(),&mcArray);
00198 AssignBranch(GetAssocName(),&assocArray);
00199 }
00200 }
00201 }
00202
00203 TBranch* StStrangeControllerBase::AssignBranch(const char* name,
00204 TClonesArray** address) {
00205
00206 static Int_t split=99;
00207 TBranch* branch = tree->Branch(name,address,bsize,split);
00208 return branch;
00209 }
00210
00211 Int_t StStrangeControllerBase::MakeCreateSubDst() {
00212
00213 if (!entries) {
00214 if (doMc) THack::ClearClonesArray(assocArray);
00215 return kStOK;
00216 }
00217
00218
00219 if (doMc && (selections->At(0) >= 0)) {
00220 for (Int_t j=0;j<GetNAssoc(); j++) {
00221 StStrangeAssoc* assocEntry = GetAssoc(j);
00222 Int_t inReAr = assocEntry->indexRecoArray();
00223 if (keepers->At(inReAr)) {
00224 Int_t k=0;
00225 while (selections->At(k) != inReAr) { k++; }
00226 assocEntry->setIndexRecoArray(k);
00227 } else {
00228 assocArray->RemoveAt(j);
00229 }
00230 }
00231 assocArray->Compress();
00232 }
00233
00234 Int_t classSize = dataClass->Size();
00235
00236 if (selections->At(0) < 0) {
00237 tree->SetBranchAddress(GetName(),&tempArray);
00238 } else if (entries) {
00239 Int_t asize = dataArray->GetSize();
00240 if (entries > asize) dataArray->Expand(entries+increment);
00241 StStrangeControllerBase* dstController = GetDstController();
00242 for (Int_t k=0; k<entries; k++) {
00243
00244
00245
00246 memcpy((*dataArray)[k],dstController->Get(selections->At(k)),classSize);
00247 }
00248 }
00249 PrintNumCand("copying",entries);
00250 nEntries += entries;
00251
00252 return kStOK;
00253 }
00254
00255 void StStrangeControllerBase::Clear(Option_t* opt) {
00256 if (dstMaker) {
00257 if (selections) {
00258 selections->Reset();
00259 keepers->Reset();
00260 }
00261 if (tree->GetBranch(GetName())->GetAddress() != (char*) &dataArray) {
00262 tree->SetBranchAddress(GetName(),&dataArray);
00263 }
00264 }
00265 if (dataArray) {
00266 THack::ClearClonesArray(dataArray);
00267 entries = 0;
00268 if (doMc) {
00269 THack::ClearClonesArray(mcArray);
00270 mcEntries = 0;
00271 THack::ClearClonesArray(assocArray);
00272 assocEntries = 0;
00273 }
00274 }
00275 }
00276
00277 void StStrangeControllerBase::Finish() {
00278 TString fin = "Total ";
00279 if (masterMaker->GetMode() == StrangeRead) fin += "read:";
00280 else fin += "kept:";
00281 PrintNumCand(fin.Data(),nEntries);
00282 }
00283
00284 void StStrangeControllerBase::Select(Int_t i) {
00285 if ((!selections) || (!dstMaker) || (selections->At(0) < 0)) return;
00286 Int_t ent = GetDstController()->GetN();
00287 if (i < 0) {
00288 selections->Reset();
00289 selections->AddAt(i,0);
00290 keepers->Reset(1);
00291 entries = ent;
00292 } else if (i < ent) {
00293 if (ent > selections->GetSize()) selections->Set(ent+increment);
00294 if (ent > keepers->GetSize()) keepers->Set(ent);
00295 if (!(keepers->At(i))) {
00296 selections->AddAt(i,entries++);
00297 keepers->AddAt(1,i);
00298 }
00299 }
00300 }
00301
00302 void StStrangeControllerBase::Unselect(Int_t i) {
00303 if ((!selections) || (!dstMaker) || (!entries)) return;
00304 if (i<0) {
00305 entries = 0;
00306 selections->AddAt(0,0);
00307 keepers->Reset();
00308 return;
00309 }
00310 Int_t ent = GetDstController()->GetN();
00311 if (i >= ent) return;
00312 if (selections->At(0) < 0) {
00313
00314 Unselect(-1);
00315 for (Int_t entry=0; entry<ent; entry++) {
00316 if (i != entry) Select(entry);
00317 }
00318 } else {
00319 keepers->AddAt(0,i);
00320 for (Int_t entry=(entries-1); entry>=0; entry--) {
00321 if (i == selections->At(entry)) {
00322 entries--;
00323
00324
00325 if (entries) selections->AddAt(selections->At(entries),entry);
00326 return;
00327 }
00328 }
00329 }
00330 }
00331
00332 void StStrangeControllerBase::PrintNumMc() {
00333 gMessMgr->Info("","O-") << IsA()->GetName() << ": found " <<
00334 mcEntries << " Monte Carlo " << GetName() << "s" << endm;
00335 gMessMgr->Info("","O-") << IsA()->GetName() << ": found " <<
00336 assocEntries << " " << GetName() << " associations" << endm;
00337 }
00338
00339 TClonesArray* StStrangeControllerBase::GetArray(Int_t branchType) {
00340 switch (branchType) {
00341 case (dataBranch) : return dataArray;
00342 case (mcBranch) : return mcArray;
00343 case (assocBranch) : return assocArray;
00344 default : {}
00345 }
00346 return 0;
00347 }
00348