StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
bfcread_hist_prefixes_add.C
1 // $Id: bfcread_hist_prefixes_add.C,v 3.6 2018/03/21 02:53:12 genevb Exp $
2 // $Log: bfcread_hist_prefixes_add.C,v $
3 // Revision 3.6 2018/03/21 02:53:12 genevb
4 // Improper use of endl corrected
5 //
6 // Revision 3.5 2017/02/27 21:41:36 genevb
7 // StEvent.so now depends on StBichsel.so
8 //
9 // Revision 3.4 2013/03/14 17:28:31 genevb
10 // StTpcDb.so now depends on StEvent.so
11 //
12 // Revision 3.3 2011/06/03 00:09:21 genevb
13 // Calling CopyHist twice was dangerous, AddHist handles copying if not found after first CopyHist
14 //
15 // Revision 3.2 2010/03/16 16:23:08 fisyak
16 // StTpcDb requires StDetectorDbMaker
17 //
18 // Revision 3.1 2008/05/28 05:16:07 genevb
19 // Allow summing over (ignoring) histogram prefixes
20 //
21 //
22 
23 //=======================================================================
24 // author: G. Van Buren (BNL)
25 //
26 // bfcread_hist_prefixes_add.C
27 //
28 // (based loosely on bfcread_hist_files_add.C)
29 //
30 // what it does:
31 // - reads in a hist.root file produced from a chain
32 // (such as bfc)
33 // - adds contents of histograms with same name, but different prefix,
34 // according to the list of prefixes kept in StHistUtil
35 // - outputs a new "summed" version of the same hist.root file
36 //
37 // inputs:
38 // fileName - hist.root file from bfc output
39 // outHistFile - output .hist.root file
40 // TopDirTree - top level directory tree in your input hist file
41 // (this is 3rd argument of constructor for StTreeMaker that
42 // you probably used to write the *.hist.root file)
43 // NOTE: if you ran bfc, then the TopDirTree = bfcTree !!
44 //
45 //======================================================================
46 
47 
48 void bfcread_hist_prefixes_add(
49  const Char_t *fileName="",
50  const Char_t *outHistFile="summed",
51  const Char_t *TopDirTree="bfcTree")
52 {
53  cout << "bfcread_hist_prefixes_add.C, input file = "
54  << fileName << endl;
55  cout << "bfcread_hist_prefixes_add.C, output file = "
56  << outHistFile << endl;
57  cout << "bfcread_hist_prefixes_add.C, top level directory in hist file = "
58  << TopDirTree << endl;
59 
60  gSystem->Load("St_base");
61  gSystem->Load("StChain");
62  gSystem->Load("StIOMaker");
63  gSystem->Load("StUtilities");
64  gSystem->Load("StAnalysisUtilities");
65  gSystem->Load("libglobal_Tables");
66  gSystem->Load("libtpc_Tables");
67  gSystem->Load("libStDb_Tables.so");
68  gSystem->Load("StDetectorDbMaker");
69  gSystem->Load("StBichsel");
70  gSystem->Load("StEvent");
71  gSystem->Load("StTpcDb");
72  gSystem->Load("StPmdUtil");
73  gSystem->Load("St_QA_Maker");
74  gSystem->Load("StTreeMaker");
75 
76 // set up write chain which knows about hist and tree makers
77  StChain* chainW = new StChain("writeChain");
78  char *MakerHistDir= new char[256];
79 
80 // set up output file structure
81  StTreeMaker* treeMk = new StTreeMaker("outTree",outHistFile,TopDirTree);
82  treeMk->SetIOMode("w");
83  treeMk->SetBranch("histBranch");
84  treeMk->Init();
85 
86 // loop over files:
87  Int_t istat=0;
88  Int_t hCCount=0;
89 
90  StIOMaker *IOMk = new StIOMaker("IO","r",fileName,TopDirTree);
91  IOMk->SetIOMode("r");
92  IOMk->SetBranch("*",0,"0"); //deactivate all branches
93  IOMk->SetBranch("histBranch",0,"r"); //activate hist Branch
94  IOMk->Init();
95 // we DON'T want IOMaker in the write chain
96  IOMk->Shunt();
97 
98 // create arrays for histmakers, histutils for multiple branches/files
99  StHistMaker* HM[128];
100  StHistUtil* HU[128];
101  int nbranch=0;
102 
103 
104 
105 // --- each file contains only histograms (1 "event" == 1 Make call)
106 
107  IOMk->Clear();
108  istat = IOMk->Open();
109  istat = IOMk->Make();
110  // from list_all macro
111  Event = IOMk->GetDataSet("hist");
112  if (!Event) {
113  cout << " No histogram branch found in file!" << endl;
114  }
115 
116  // loop over all branches in the file
117  TDataSetIter nextHistList(Event);
118  St_ObjectSet *histContainer = 0;
119 
120  TList *dirList = 0;
121  while (histContainer = (St_ObjectSet *)nextHistList.Next()) {
122  dirList = (TList *) histContainer->GetObject();
123  strcpy(MakerHistDir,histContainer->GetName());
124  MakerHistDir[strlen(MakerHistDir)-4] = 0;
125  //if (strcmp(MakerHistDir,"IO")==0 || strcmp(MakerHistDir,"IO_Root")==0) {
126  // cout << " --- Skipping " << MakerHistDir << endl;
127  // continue;
128  //}
129  cout << "\n --- MakerHistDir : " << MakerHistDir << endl;
130 
131  HU[nbranch] = new StHistUtil();
132  HU[nbranch]->SetPntrToMaker(IOMk);
133  HU[nbranch]->IgnorePrefixes();
134  HM[nbranch]=0;
135 
136  int prefixNum;
137  int nPrefixes = HU[nbranch]->GetNumOfPosPrefixes();
138  Bool_t firstSet = kTRUE;
139  for (prefixNum=0; prefixNum < nPrefixes; prefixNum++) {
140 
141 // get the TList pointer to the histograms for this branch:
142  dirList = HU[nbranch]->FindHists(MakerHistDir,HU[nbranch]->GetPrefix(prefixNum));
143  if (dirList->GetSize()) {
144 
145  if (firstSet) {
146  firstSet = kFALSE;
147 
148 // now make a copy of all histograms into the new histograms!
149  hCCount = HU[nbranch]->CopyHists(dirList);
150  cout << "bfcread_hist_prefixes_add.C, # histograms copied with prefix " <<
151  HU[nbranch]->GetPrefix(prefixNum) << " = " << hCCount << endl;
152 
153  if (HM[nbranch]==0) {
154  HM[nbranch] = new StHistMaker(MakerHistDir);
155  HM[nbranch]->Init();
156  }
157  HM[nbranch]->SetHArraySize(HU[nbranch]->getNewHistSize());
158  HM[nbranch]->SetHArray(HU[nbranch]->getNewHist());
159  HM[nbranch]->Make();
160  } else { // first set or not
161  hCCount = HU[nbranch]->AddHists(dirList);
162  cout << "bfcread_hist_prefixes_add.C, # histograms added with prefix " <<
163  HU[nbranch]->GetPrefix(prefixNum) << " = " << hCCount << endl;
164  } // first set or not
165  } // found hists
166  HU[nbranch]->Clear();
167 
168  } // loop over prefixes
169 
170  nbranch++;
171 
172  } // end while loop over branches
173  istat = IOMk->Close();
174 
175  treeMk->Make();
176  treeMk->Finish();
177  IOMk->Finish();
178 } // end of the macro!
virtual Int_t Finish()
virtual Int_t Make()
Definition: StHistMaker.cxx:34
virtual void Clear(Option_t *opt)
User defined functions.
Definition: StIOMaker.cxx:252
virtual void SetIOMode(Option_t *iomode="w")
number of transactions
Definition: StIOInterFace.h:35
virtual Int_t Make()
virtual Int_t Finish()
Definition: StIOMaker.cxx:231
virtual Int_t Make()
Definition: StIOMaker.cxx:183
virtual TDataSet * Next() const
Definition: TDataSet.cxx:447
Definition: AgUStep.h:26
virtual void Shunt(TDataSet *newParent=0)
Definition: TDataSet.cxx:810
virtual TObject * GetObject() const
The depricated method (left here for the sake of the backward compatibility)
Definition: TObjectSet.h:56