StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StTagFilterMaker.cxx
1 /*
2  * StTagFilterMaker
3  *
4  * Base class to skip production of events using
5  * criteria stored in a .pretags.root Tag TTree
6  *
7  * Derived classes should implement SkipEvent()
8  * to determine whether events should be skipped or not.
9  *
10  * SetVarList() can be used to provide a colon-separated
11  * list of variables (formulas) which will automatically
12  * be evaluated for use in SkipEvent().
13  * Individual variable values will be available as GetVal(0),GetVal(1) ...
14  * Individual variable names will be available as GetVar(0),GetVar(1) ...
15  *
16  * Otherwise, derived classes can access the Tag TTree
17  * as they wish, without needing selection criteria, as
18  * a TEventList is applied to select the run and event.
19  *
20  */
21 
22 
23 #include "StTagFilterMaker.h"
24 #include "StMessMgr.h"
25 #include "StEvtHddr.h"
26 #include "TFile.h"
27 #include "TTree.h"
28 #include "TEntryList.h"
29 #include "TTreeFormula.h"
30 
31 
32 ClassImp(StTagFilterMaker)
33 
34 //____________________________________________________________________________________________________
35 StTagFilterMaker::StTagFilterMaker(const Char_t *name) : StMaker(name)
36 {
37  mTagFile = "";
38  mVarList = "";
39  mSkippedEventCounter = 0;
40  mFile = 0;
41  mTree = 0;
42  mEntryList = new TEntryList(Form("%s_EList",name),Form("Entry list for %s",name));
43 }
44 //____________________________________________________________________________________________________
45 StTagFilterMaker::~StTagFilterMaker()
46 {
47  SafeDelete(mFile);
48  delete mEntryList;
49 }
50 //____________________________________________________________________________________________________
51 Int_t StTagFilterMaker::Init()
52 {
53  SetAttr(".Privilege", 1);
54 
55  return StMaker::Init();
56 }
57 //____________________________________________________________________________________________________
58 Int_t StTagFilterMaker::InitRun(const int runnum)
59 {
60 
67 
68  if (mTagFile.IsWhitespace()){
69  mTagFile = GetTFile()->GetName();
70  mTagFile.ReplaceAll(".tags.root",".pretags.root");
71  }
72 
73  // Open the .pretags.root file
74  mFile = TFile::Open(mTagFile);
75  if (! mFile ) {
76  LOG_ERROR << "Input TagFile : " << mTagFile << " cannot be opened" << endm;
77  return kStErr;
78  }
79  LOG_INFO << "Input TagFile : " << mTagFile << " opened" << endm;
80  mEntryList->SetDirectory(mFile); // mEntryList's directory must not be an output file
81 
82 
83  // Get the Tag tree
84  mTree = static_cast<TTree*>(mFile->Get("Tag"));
85  if (! mTree ) {
86  LOG_ERROR << "In TagFile : " << mTagFile << " cannot find TTree \"Tag\"" << endm;
87  return kStErr;
88  }
89 
90  return kStOK;
91 }
92 //____________________________________________________________________________________________________
94 {
96  StEvtHddr* EvtHddr = static_cast<StEvtHddr*>(GetDataSet("EvtHddr"));
97  if (! EvtHddr) {
98  LOG_ERROR << "EvtHddr has not been found" << endm;
99  return kStErr;
100  }
102  mEntryList->GetDirectory()->cd(); // must be in mEntryList's directory before TTree::Draw()
103  int nFound = mTree->Draw(Form(">>%s",mEntryList->GetName()),
104  Form("mRunNumber==%i&&mEventNumber==%i",
105  EvtHddr->GetRunNumber(),EvtHddr->GetEventNumber()),
106  "entrylist");
108  mTree->SetEntryList(mEntryList);
109  if (nFound != 1) {
110  LOG_ERROR << "Run/Event = " << EvtHddr->GetRunNumber() << "/" << EvtHddr->GetEventNumber()
111  << " has been found in tag file " << nFound << " times" << endm;
112  return kStErr;
113  }
114 
116  if (mVarList.Length()) EvalVarList();
117 
119  if (SkipEvent()) {
121  return kStSKIP;
122  }
123 
124  return StMaker::Make();
125 }
126 //____________________________________________________________________________________________________
127 void StTagFilterMaker::EvalVarList(const char* varList)
128 {
130  mTree->Draw((varList ? varList : mVarList.Data()),0,"goff");
131 }
132 //____________________________________________________________________________________________________
133 Double_t StTagFilterMaker::GetVal(int i, int idx)
134 {
136  return (mTree->GetVal(i))[idx];
137 }
138 //____________________________________________________________________________________________________
139 const char* StTagFilterMaker::GetVar(int i)
140 {
142  return mTree->GetVar(i)->GetTitle();
143 }
144 //____________________________________________________________________________________________________
145 void StTagFilterMaker::Clear(const Option_t*)
146 {
147  if (mTree) mTree->SetEntryList(0);
148  StMaker::Clear();
149 }
150 
151 /* -------------------------------------------------------------------------
152  * $Id: StTagFilterMaker.cxx,v 1.3 2015/05/06 18:10:22 genevb Exp $
153  * $Log: StTagFilterMaker.cxx,v $
154  * Revision 1.3 2015/05/06 18:10:22 genevb
155  * Avoid letting TEntryList and histogram from TTree::Draw() getting into output files
156  *
157  * Revision 1.2 2015/05/05 20:23:42 genevb
158  * pre.tags.root => pretags.root
159  *
160  * Revision 1.1 2015/05/01 21:25:50 jeromel
161  * First version of the DataFiler + one imp: MTD. Code from GVB reviewed & closed (VP+JL))
162  *
163  *
164  * -------------------------------------------------------------------------
165  */
166 
TString mVarList
List of colon-separated variables of interest.
const char * GetVar(int i)
TEntryList * mEntryList
Selection of run and event.
Definition: Stypes.h:48
virtual void Clear(Option_t *option="")
User defined functions.
Definition: StMaker.cxx:634
Skip events using criteria in .pretags.root.
TFile * mFile
Pointer to the .pretags.root input file.
virtual Int_t Make()
Definition: StMaker.cxx:898
int mSkippedEventCounter
Number of events skipped.
virtual Int_t Make()
void EvalVarList(const Char_t *varList=0)
Double_t GetVal(int i, int idx=0)
TString mTagFile
Tags input file name, ending in .pretags.root by default.
Definition: Stypes.h:40
TTree * mTree
Pointer to the Tags TTree.
Definition: Stypes.h:44
virtual Int_t InitRun(const int runnum)