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
00064
00065
00066
00067 #include "StTagsMaker.h"
00068 #include "StEvtHddr.h"
00069 #include "TROOT.h"
00070 #include "TFile.h"
00071 #include "TTree.h"
00072 #include "TTable.h"
00073 #include "TClass.h"
00074 #include "TDataMember.h"
00075 #include "TDataType.h"
00076 #include "tables/St_GlobalTag_Table.h"
00077
00078 #include "StEvent.h"
00079 #include "StTriggerData.h"
00080 #include "StEventUtilities/StuRefMult.hh"
00081 #include "StEventUtilities/StuFtpcRefMult.hh"
00082 static TClass *tabClass = 0;
00083 static TTree *fTree = 0;
00084 static TDataSet *fTagsList = new TDataSet("TagList");
00085
00086
00087 ClassImp(StTagsMaker);
00088
00089 StTagsMaker::StTagsMaker(const char *name):StMaker(name){
00090 }
00091
00092 StTagsMaker::~StTagsMaker(){
00093 }
00094
00095 Int_t StTagsMaker::Init(){
00096 return StMaker::Init();
00097 }
00098
00099 Int_t StTagsMaker::Make(){
00100 St_GlobalTag *tagtab= new St_GlobalTag("GlobalTag",1); AddData(tagtab);
00101 GlobalTag_st row;
00102 memset (&row, 0, sizeof(GlobalTag_st));
00103 StEvent* event = dynamic_cast<StEvent*> (GetInputDS("StEvent"));
00104 if (event) {
00105 StPrimaryVertex *primVertex = event->primaryVertex();
00106 if (primVertex) {
00107 row.primaryVertexX = primVertex->position().x();
00108 row.primaryVertexY = primVertex->position().y();
00109 row.primaryVertexZ = primVertex->position().z();
00110 const StMatrixF &m = primVertex->covariantMatrix();
00111 if (m(1,1) > 0) row.sigmaPVX = TMath::Sqrt(m(1,1));
00112 if (m(2,2) > 0) row.sigmaPVY = TMath::Sqrt(m(2,2));
00113 if (m(3,3) > 0) row.sigmaPVZ = TMath::Sqrt(m(3,3));
00114 } else row.primaryVertexFlag = 99;
00115 StTriggerDetectorCollection *theTriggers = event->triggerDetectorCollection();
00116 if ( theTriggers){
00117 StCtbTriggerDetector &theCtb = theTriggers->ctb();
00118 #if 0
00119 StZdcTriggerDetector &theZdc = theTriggers->zdc();
00120 #endif
00121
00122 float ctbsum = 0;
00123 for (unsigned int islat=0; islat<theCtb.numberOfSlats(); islat++)
00124 for (unsigned int itray=0; itray<theCtb.numberOfTrays(); itray++)
00125 ctbsum += theCtb.mips(itray, islat, 0);
00126 row.CTBsum = ctbsum;
00127 }
00128 row.uncorrectedNumberOfPrimaries = uncorrectedNumberOfPrimaries(*event);
00129 row.uncorrectedNumberOfFtpcEastPrimaries = uncorrectedNumberOfFtpcEastPrimaries(*event);
00130 row.uncorrectedNumberOfFtpcWestPrimaries = uncorrectedNumberOfFtpcWestPrimaries(*event);
00131 StTriggerData *trigData = event->triggerData();
00132 if (trigData)
00133
00134 row.zdcHardSum = trigData->zdcAtChannel(10);
00135 StTriggerIdCollection *trgcol = event->triggerIdCollection();
00136 if (trgcol) {
00137 #if 0
00138 const StTriggerId *l1 = trgcol->l1();
00139 const StTriggerId *l2 = trgcol->l2();
00140 const StTriggerId *l3 = trgcol->l3();
00141 #endif
00142 const StTriggerId *nominal = trgcol->nominal();
00143 if(nominal) {
00144 vector<unsigned int> nominalVec = nominal->triggerIds();
00145 Int_t i = 0;
00146 for (vector<unsigned int>::iterator viter = nominalVec.begin();
00147 viter != nominalVec.end(); ++viter) {
00148 row.TriggerId[i++] = (*viter);
00149 }
00150 }
00151 }
00152 tagtab->AddAt(&row); if (Debug()) tagtab->Print(0,1);
00153 }
00154 if (!fTree) InitTags();
00155 if (fTree && fTagsList && tabClass) {
00156 TDataSetIter next(fTagsList);
00157 TDataSet *set = 0;
00158 TClass *cl = 0;
00159 void *address = 0;
00160 EvtHddr_st fEvtHddr;
00161
00162 while ((set = next())) {
00163 TDataSet *ds = GetDataSet(set->GetTitle());
00164
00165 if (ds) {
00166 if (ds->InheritsFrom(tabClass)) {
00167 TTable *tabl = (TTable *) ds;
00168 TTable &tab = *tabl;
00169 address = tab[0];
00170 cl = gROOT->GetClass(ds->GetTitle());
00171 }
00172 else if (strstr(ds->GetName(),"EvtHddr")){
00173 StEvtHddr *lEvtHddr = (StEvtHddr *) ds;
00174 lEvtHddr->FillTag(&fEvtHddr);
00175 address = &fEvtHddr;
00176 cl = gROOT->GetClass("EvtHddr_st");
00177 }
00178 if (cl) {
00179 TIter next(cl->GetListOfDataMembers());
00180 TDataMember *member = 0;
00181 while ( (member = (TDataMember *) next()) ) {
00182 TString branchName=ds->GetName();
00183 branchName += ".";
00184 branchName += member->GetName();
00185 fTree->SetBranchAddress(branchName.Data(),
00186 (char*)address+member->GetOffset());
00187 }
00188 }
00189 }
00190 }
00191 fTree->Fill();
00192 }
00193 return kStOK;
00194 }
00195
00196 EDataSetPass StTagsMaker::GetTags (TDataSet* ds)
00197 {
00198 TString name, leaflist, branchName;
00199 TClass *cl = 0;
00200 Int_t bufsize= 64000;
00201 void *address = 0;
00202
00203 const char *Name=ds->GetName();
00204
00205 if (!tabClass) tabClass = gROOT->GetClass("TTable");
00206 if (ds->InheritsFrom(tabClass) && strstr(Name,"Tag")) {
00207 name = TString(ds->GetTitle());
00208 TTable &tab = *((TTable *)ds);
00209 address = tab[0];
00210
00211 } else if (strstr(Name,"EvtHddr")){
00212 name = TString("EvtHddr_st");
00213 } else {
00214 return kContinue;
00215 }
00216
00217
00218 cl = gROOT->GetClass(name.Data());
00219 if (cl) {
00220 TIter next(cl->GetListOfDataMembers());
00221 const Char_t *types;
00222 TDataMember *member = 0;
00223 while ( (member = (TDataMember *) next()) ) {
00224 const Char_t *colName = member->GetName();
00225
00226 leaflist = colName;
00227 Int_t nDim = member->GetArrayDim();
00228 Char_t buf[64];
00229 for (Int_t k=0; k<nDim; k++) {
00230 UInt_t indx = member->GetMaxIndex(k);
00231 sprintf(buf,"[%d]",indx);
00232 leaflist += buf;
00233 }
00234
00235
00236 TString Comment = member->GetTitle();
00237 Comment=Comment.Strip(TString::kBoth,' ');
00238
00239 Comment.ReplaceAll("!","");
00240 if (!Comment.IsNull()) {
00241
00242 Comment.ReplaceAll("<",'<');
00243 Comment.ReplaceAll(">",'>');
00244
00245 Comment.ReplaceAll(":",' ');
00246 Comment.ReplaceAll("/",' ');
00247
00248 if (nDim != 0) {
00249
00250
00251
00252
00253
00254 leaflist += " '";
00255 leaflist += Comment;
00256 leaflist += "' ";
00257 }
00258
00259 if (leaflist.Length()>64) leaflist.Resize(64);
00260 }
00261
00262
00263 leaflist += "/";
00264 TDataType *memberType = member->GetDataType();
00265 types = memberType->GetTypeName();
00266 if (!strcmp("float", types)) leaflist += 'F';
00267 else if (!strcmp("int", types)) leaflist += 'I';
00268 else if (!strcmp("long", types)) leaflist += 'I';
00269 else if (!strcmp("short", types)) leaflist += 'S';
00270 else if (!strcmp("double", types)) leaflist += 'D';
00271 else if (!strcmp("unsigned int", types)) leaflist += 'i';
00272 else if (!strcmp("unsigned long", types)) leaflist += 'i';
00273 else if (!strcmp("unsigned short", types))leaflist += 's';
00274 else if (!strcmp("unsigned char", types)) leaflist += 'b';
00275
00276 else if (!strcmp("char", types)) leaflist += 'B';
00277
00278
00279 branchName = Name;
00280 branchName += ".";
00281 branchName += colName;
00282 fTree->Branch(branchName.Data(),(char*)address+member->GetOffset(),
00283 leaflist.Data(),bufsize);
00284 }
00285 TDataSet *newds = new TDataSet(Name);
00286 newds->SetTitle(ds->Path());
00287 fTagsList->Add(newds);
00288 }
00289 return kContinue;
00290 }
00291
00292 Int_t StTagsMaker::InitTags() {
00293 if (!fTree) {
00294 StMaker *chain = GetChain();
00295 TFile *f = chain->GetTFile();
00296 if (f) {
00297 f->cd();
00298 fTree = new TTree("Tag","BFC chain Tags");
00299 chain->Pass(GetTags);
00300 }
00301 }
00302 return 0;
00303 }
00304
00305
00306
00307
00308
00309
00310
00311