StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StTagsMaker.cxx
1 // $Id: StTagsMaker.cxx,v 1.22 2019/04/23 15:42:11 jeromel Exp $
2 // $Log: StTagsMaker.cxx,v $
3 // Revision 1.22 2019/04/23 15:42:11 jeromel
4 // Sub-version merging to MAIN
5 //
6 // Revision 1.21.16.2 2019/02/23 06:02:31 genevb
7 // Use initial run number consistently
8 //
9 // Revision 1.21.16.1 2019/02/05 02:43:36 genevb
10 // shadow the tags also
11 //
12 // Revision 1.21 2009/11/23 16:47:59 fisyak
13 // Add Primary vertex position errors
14 //
15 // Revision 1.20 2008/07/29 14:43:51 fisyak
16 // Check that StTriggerIdCollection exists
17 //
18 // Revision 1.19 2007/04/26 04:15:40 perev
19 // Remove StBFChain dependency
20 //
21 // Revision 1.18 2007/04/17 05:09:41 perev
22 // GetTFile()==>StMaker. Jerome request
23 //
24 // Revision 1.17 2006/10/17 19:18:39 fisyak
25 // add Check that this chain is BFC one
26 //
27 // Revision 1.16 2006/03/24 14:34:50 fisyak
28 // Remove new TClass(name.Data(),1,StEvtHddr.h,StEvtHddr.h);This new forces to call Notify which cleans up all ROOT interanl pointer and prevent to write into TTRe more than 1 event. This bug found by Victor and Valery
29 //
30 // Revision 1.15 2004/11/24 04:05:26 jeromel
31 // Small leak of one newds fixed
32 //
33 // Revision 1.14 2004/08/17 20:52:11 perev
34 // Replace St_DataSet ==> TDataSet
35 //
36 // Revision 1.13 2004/07/30 20:31:38 fisyak
37 // Remove second i++
38 //
39 // Revision 1.12 2004/07/30 20:15:10 fisyak
40 // Synchronize Pcoll and Global Tags, remove TpcTags fro chain
41 //
42 // Revision 1.11 2004/07/30 14:15:10 fisyak
43 // Back to idl tag definition
44 //
45 // Revision 1.10 2004/07/29 22:56:59 fisyak
46 // Add Global tags
47 //
48 // Revision 1.9 2003/05/14 03:30:17 jeromel
49 // Zombied branch corrected . BugTracking #121
50 //
51 // Revision 1.8 2000/07/28 21:05:36 fisyak
52 // Remove dependence on StChain InitRun
53 //
54 // Revision 1.7 2000/06/17 15:41:56 vanyashi
55 // Comments from idl files are added to tags
56 //
57 // Revision 1.6 2000/06/08 22:21:08 vanyashi
58 // event header tags fixed
59 //
60 // Revision 1.5 2000/06/05 22:06:26 vanyashi
61 // added const needed for tableDescriptor
62 //
63 // Revision 1.4 2000/05/25 15:00:05 vanyashi
64 // save structure names
65 //
66 // Revision 1.3 2000/05/20 01:08:27 vanyashi
67 // Write tags in split mode
68 //
69 // Revision 1.2 2000/02/02 21:20:55 fisyak
70 // Remove user parametes from GetTags
71 //
72 // Revision 1.1.1.1 2000/01/27 18:54:00 fisyak
73 // Initial revision of Tags Maker
74 //
75 
76 #include "StTagsMaker.h"
77 #include "StEvtHddr.h"
78 #include "TROOT.h"
79 #include "TFile.h"
80 #include "TTree.h"
81 #include "TTable.h"
82 #include "TClass.h"
83 #include "TDataMember.h"
84 #include "TDataType.h"
85 #include "tables/St_GlobalTag_Table.h"
86 //#include "St_GlobalTag.h"
87 #include "StEvent.h"
88 #include "StTriggerData.h"
89 #include "StEventUtilities/StuRefMult.hh"
90 #include "StEventUtilities/StuFtpcRefMult.hh"
91 #include "StShadowMaker/StShadowMaker.h"
92 static TClass *tabClass = 0;
93 static TTree *fTree = 0;
94 static TDataSet *fTagsList = new TDataSet("TagList");
95 
96 //TableImpl(GlobalTag);
97 ClassImp(StTagsMaker);
98 //_____________________________________________________________________________
99 StTagsMaker::StTagsMaker(const char *name):StMaker(name){
100 }
101 //_____________________________________________________________________________
102 StTagsMaker::~StTagsMaker(){
103 }
104 //_____________________________________________________________________________
105 Int_t StTagsMaker::Init(){
106  return StMaker::Init();
107 }
108 //_____________________________________________________________________________
110  St_GlobalTag *tagtab= new St_GlobalTag("GlobalTag",1); AddData(tagtab);
111  GlobalTag_st row;
112  memset (&row, 0, sizeof(GlobalTag_st));
113  StEvent* event = dynamic_cast<StEvent*> (GetInputDS("StEvent"));
114  if (event) {
115  StPrimaryVertex *primVertex = event->primaryVertex();
116  if (primVertex) {// Primary vertex (x,y,z), with some flag if not found
117  row.primaryVertexX = primVertex->position().x(); // x-vertex
118  row.primaryVertexY = primVertex->position().y(); // y-vertex
119  row.primaryVertexZ = primVertex->position().z(); // z-vertex
120  const StMatrixF &m = primVertex->covariantMatrix();
121  if (m(1,1) > 0) row.sigmaPVX = TMath::Sqrt(m(1,1)); // x-vertex
122  if (m(2,2) > 0) row.sigmaPVY = TMath::Sqrt(m(2,2)); // y-vertex
123  if (m(3,3) > 0) row.sigmaPVZ = TMath::Sqrt(m(3,3)); // z-vertex
124  } else row.primaryVertexFlag = 99;
125  StTriggerDetectorCollection *theTriggers = event->triggerDetectorCollection();
126  if ( theTriggers){
127  StCtbTriggerDetector &theCtb = theTriggers->ctb();
128 #if 0
129  StZdcTriggerDetector &theZdc = theTriggers->zdc();
130 #endif
131  // Sum all CTB counter
132  float ctbsum = 0;
133  for (unsigned int islat=0; islat<theCtb.numberOfSlats(); islat++)
134  for (unsigned int itray=0; itray<theCtb.numberOfTrays(); itray++)
135  ctbsum += theCtb.mips(itray, islat, 0);
136  row.CTBsum = ctbsum; // CTB sum StCtbTriggerDetector::mMips[mMaxTrays][mMaxSlats][0]
137  }
138  row.uncorrectedNumberOfPrimaries = uncorrectedNumberOfPrimaries(*event);
139  row.uncorrectedNumberOfFtpcEastPrimaries = uncorrectedNumberOfFtpcEastPrimaries(*event);
140  row.uncorrectedNumberOfFtpcWestPrimaries = uncorrectedNumberOfFtpcWestPrimaries(*event);
141  StTriggerData *trigData = event->triggerData();
142  if (trigData)
143  // row.zdcWestHardSum = trigData->zdcAttenuated(west); Jamie said that this is wrong
144  row.zdcHardSum = trigData->zdcAtChannel(10);
145  StTriggerIdCollection *trgcol = event->triggerIdCollection();
146  if (trgcol) {
147 #if 0
148  const StTriggerId *l1 = trgcol->l1();
149  const StTriggerId *l2 = trgcol->l2();
150  const StTriggerId *l3 = trgcol->l3();
151 #endif
152  const StTriggerId *nominal = trgcol->nominal();
153  if(nominal) {
154  vector<unsigned int> nominalVec = nominal->triggerIds();
155  Int_t i = 0;
156  for (vector<unsigned int>::iterator viter = nominalVec.begin();
157  viter != nominalVec.end(); ++viter) {
158  row.TriggerId[i++] = (*viter); // Trigger Id's satisfied by an event
159  }
160  }
161  }
162  tagtab->AddAt(&row); if (Debug()) tagtab->Print(0,1);
163  }
164  if (!fTree) InitTags();
165  if (fTree && fTagsList && tabClass) {
166  TDataSetIter next(fTagsList);
167  TDataSet *set = 0;
168  TClass *cl = 0;
169  void *address = 0;
170  EvtHddr_st fEvtHddr;
171 
172  while ((set = next())) {
173  TDataSet *ds = GetDataSet(set->GetTitle());
174 
175  if (ds) {
176  if (ds->InheritsFrom(tabClass)) {
177  TTable *tabl = (TTable *) ds;
178  TTable &tab = *tabl;
179  address = tab[0];
180  cl = gROOT->GetClass(ds->GetTitle());
181  }
182  else if (strstr(ds->GetName(),"EvtHddr")){
183  StEvtHddr *lEvtHddr = (StEvtHddr *) ds;
184  lEvtHddr->FillTag(&fEvtHddr);
185  address = &fEvtHddr;
186  if (IAttr("shadow")) {
187  fEvtHddr.mRunNumber = StShadowMaker::getRunNumber();
188  if (fEvtHddr.mOldRunNumber>0)
189  fEvtHddr.mOldRunNumber = fEvtHddr.mRunNumber;
190  fEvtHddr.mEventNumber = StShadowMaker::getEventNumber(fEvtHddr.mEventNumber);
191  }
192  cl = gROOT->GetClass("EvtHddr_st");
193  }
194  if (cl) {
195  TIter next(cl->GetListOfDataMembers());
196  TDataMember *member = 0;
197  while ( (member = (TDataMember *) next()) ) {
198  TString branchName=ds->GetName();
199  branchName += ".";
200  branchName += member->GetName();
201  fTree->SetBranchAddress(branchName.Data(),
202  (char*)address+member->GetOffset());
203  }
204  }
205  }
206  }
207  fTree->Fill();
208  }
209  return kStOK;
210 }
211 //_____________________________________________________________________________
212 EDataSetPass StTagsMaker::GetTags (TDataSet* ds)
213 {
214  TString name, leaflist, branchName;
215  TClass *cl = 0;
216  Int_t bufsize= 64000;
217  void *address = 0;
218 
219  const char *Name=ds->GetName();
220 
221  if (!tabClass) tabClass = gROOT->GetClass("TTable");
222  if (ds->InheritsFrom(tabClass) && strstr(Name,"Tag")) {
223  name = TString(ds->GetTitle());
224  TTable &tab = *((TTable *)ds);
225  address = tab[0];
226 
227  } else if (strstr(Name,"EvtHddr")){
228  name = TString("EvtHddr_st");
229  } else {
230  return kContinue;
231  }
232 
233  // create separate branch for each tag (or array of tags)
234  cl = gROOT->GetClass(name.Data());
235  if (cl) {
236  TIter next(cl->GetListOfDataMembers());
237  const Char_t *types;
238  TDataMember *member = 0;
239  while ( (member = (TDataMember *) next()) ) {
240  const Char_t *colName = member->GetName();
241  //prepare name/type description for individual tags or tag arrays
242  leaflist = colName;
243  Int_t nDim = member->GetArrayDim();
244  Char_t buf[64];
245  for (Int_t k=0; k<nDim; k++) {
246  UInt_t indx = member->GetMaxIndex(k);
247  sprintf(buf,"[%d]",indx);
248  leaflist += buf;
249  }
250  //in ROOT everything beyond the '[' in leaf name remains as a title
251  //see TLeaf::TLeaf(const char *name, const char *):TNamed(name,name) {
252  TString Comment = member->GetTitle();
253  Comment=Comment.Strip(TString::kBoth,' ');
254  //these happen for ROOT Streamer
255  Comment.ReplaceAll("!","");
256  if (!Comment.IsNull()) {
257  //these happen due to html restrictions
258  Comment.ReplaceAll("&lt;",'<');
259  Comment.ReplaceAll("&gt;",'>');
260  //these are not allowed by leaflist restrictions
261  Comment.ReplaceAll(":",' ');
262  Comment.ReplaceAll("/",' ');
263  //have to add '[' for non-arrays
264  if (nDim != 0) {
265  //leaflist += '[';
266  //leaflist += Comment;
267  //leaflist += "] ";
268  //}
269  //else {
270  leaflist += " '";
271  leaflist += Comment;
272  leaflist += "' ";
273  }
274  //leafname is limited to char[64] -> cut off lengthy comments
275  if (leaflist.Length()>64) leaflist.Resize(64);
276  }
277  //in ROOT everything before the '/' in leaflist is leafname, see
278  //TBranch::TBranch(const char *name, void *address, const char *leaflist,...
279  leaflist += "/";
280  TDataType *memberType = member->GetDataType();
281  types = memberType->GetTypeName();
282  if (!strcmp("float", types)) leaflist += 'F';
283  else if (!strcmp("int", types)) leaflist += 'I';
284  else if (!strcmp("long", types)) leaflist += 'I';
285  else if (!strcmp("short", types)) leaflist += 'S';
286  else if (!strcmp("double", types)) leaflist += 'D';
287  else if (!strcmp("unsigned int", types)) leaflist += 'i';
288  else if (!strcmp("unsigned long", types)) leaflist += 'i';
289  else if (!strcmp("unsigned short", types))leaflist += 's';
290  else if (!strcmp("unsigned char", types)) leaflist += 'b';
291  //this is used only in EvtHddr->mEventType
292  else if (!strcmp("char", types)) leaflist += 'B';
293 
294  //save name of the structure (e.g. "FlowTag") in the TTree branchName
295  branchName = Name;
296  branchName += ".";
297  branchName += colName;
298  fTree->Branch(branchName.Data(),(char*)address+member->GetOffset(),
299  leaflist.Data(),bufsize);
300  }
301  TDataSet *newds = new TDataSet(Name);
302  newds->SetTitle(ds->Path());
303  fTagsList->Add(newds);
304  }
305  return kContinue;
306 }
307 //_____________________________________________________________________________
308 Int_t StTagsMaker::InitTags() {
309  if (!fTree) {
310  StMaker *chain = GetChain();
311  TFile *f = chain->GetTFile();
312  if (f) {
313  f->cd();
314  fTree = new TTree("Tag","BFC chain Tags");
315  chain->Pass(GetTags);
316  }
317  }
318  return 0;
319 }
320 
321 
322 
323 
324 
325 
326 
327 
virtual Int_t Make()
virtual EDataSetPass Pass(EDataSetPass(*callback)(TDataSet *), Int_t depth=0)
Definition: TDataSet.cxx:689
virtual void AddData(TDataSet *data, const char *dir=".data")
User methods.
Definition: StMaker.cxx:332
Collection of trigger ids as stored in StEvent.
Definition: Stypes.h:40
Definition: TTable.h:48
virtual TString Path() const
return the full path of this data set
Definition: TDataSet.cxx:626