StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
bfc.C
1 // //
3 // Macro for running chain with different inputs //
4 // owner: Yuri Fisyak //
5 // Modifications by J. Lauret, V, Prevotchikov, G.V. Buren, L. Didenko //
6 // and V. Fine //
7 // //
8 // $Id: bfc.C,v 1.194 2020/04/12 20:24:18 perev Exp $
10 class StBFChain;
11 class StMessMgr;
12 
13 #pragma cling load("StarRoot")
14 #pragma cling load("St_base")
15 #pragma cling load("StChain")
16 #pragma cling load("StUtilities")
17 #pragma cling load("StBFChain")
18 
19 #if !(defined(__CINT__) || defined(__CLING__)) || defined(__MAKECINT__)
20 
21 #include "Stiostream.h"
22 #include "TSystem.h"
23 #include "TClassTable.h"
24 #include "TApplication.h"
25 #include "TInterpreter.h"
26 #include "StBFChain.h"
27 #include "StMessMgr.h"
28 #include "TROOT.h"
29 #include "TAttr.h"
30 #include "Rtypes.h"
31 #endif
32 
33 #if !defined(__CINT__) || defined(__CLING__)
34 // 'chain' is defined in StBFChain library (see StRoot/StBFChain.cxx)
35 extern StBFChain* chain;
36 #else
37 StBFChain* chain = 0;
38 #endif
39 
40 //_____________________________________________________________________
41 //_________________ Prototypes _______________________________________________
42 void Usage();
43 void Load(const Char_t *options="");
44 //TString defChain("y2010,gstar,Test.default.Fast.ITTF,NosvtIT,NossdIT,-sfs,-ssdFast");
45 TString defChain("y2010,gstar,Test.default.ITTF,NosvtIT,NossdIT,-sfs,-ssdFast,sdt20100107.110000");
46 void bfc(Int_t First, Int_t Last,const Char_t *Chain = defChain + ",Display",
47  const Char_t *infile=0, const Char_t *outfile=0, const Char_t *TreeFile=0);
48 // const Char_t *Chain="gstar,y2005h,MakeEvent,trs,sss,svt,ssd,fss,bbcSim,emcY2,tpcI,fcf,ftpc,SvtCL,svtDb,ssdDb,svtIT,ssdIT,ITTF,genvtx,Idst,event,analysis,EventQA,tags,Tree,EvOut,McEvOut,GeantOut,IdTruth,miniMcMk,StarMagField,FieldOn,McAna,Display",//,,NoSimuDb, display, //McQa,
49 void bfc(Int_t Last, const Char_t *Chain = defChain,
50  const Char_t *infile=0, const Char_t *outfile=0, const Char_t *TreeFile=0);
51  // const Char_t *Chain="gstar,y2005h,tpcDb,trs,tpc,Physics,Cdst,Kalman,tags,Tree,EvOut,McEvOut,IdTruth,miniMcMk,StarMagField,FieldOn,McAna", // McQA
52 //_____________________________________________________________________
53 void Load(const Char_t *options)
54 {
55  cout << "Load system libraries\t";
56  int nodefault = TString(options).Contains("nodefault",TString::kIgnoreCase);
57 
58 
59  if ( TString(gProgName)!="root4star") { // ! root4star
60  if (!nodefault || TString(options).Contains("pgf77",TString::kIgnoreCase)) {
61  const Char_t *pgf77 = "libpgf77VMC";
62  if (gSystem->DynamicPathName(pgf77,kTRUE) ) {
63  gSystem->Load(pgf77); cout << " " << pgf77 << " + ";
64  }
65  }
66  if (!nodefault || TString(options).Contains("cern" ,TString::kIgnoreCase)) {
67  gSystem->Load("libStarMiniCern");
68  cout << "libStarMiniCern" ;
69  }
70 
71 
72  if (!nodefault || TString(options).Contains("mysql",TString::kIgnoreCase)) {
73  const Char_t *mysql = "libmysqlclient";
74  //Char_t *mysql = "libmimerS"; // just to test it picks from OPTSTAR
75 
76  //
77  // May use USE_64BITS - the x8664 work fine too
78  //
79  const Char_t *libsLocal[]= {"",
80  "$OPTSTAR/lib/",
81  "$OPTSTAR/lib/mysql/",
82  "/usr/lib/",
83  "/usr/lib/mysql/",
84  "/usr/mysql/lib/",
85  NULL};
86  const Char_t *libsGlbal[]= {"",
87  "/usr/lib/",
88  "/usr/lib/mysql/",
89  "/usr/mysql/lib/",
90  "$OPTSTAR/lib/",
91  "$OPTSTAR/lib/mysql/",
92  NULL};
93 
94  const Char_t **libs;
95 
96  if ( gSystem->Getenv("USE_LOCAL_MYSQL") ){
97  libs = libsLocal;
98  } else {
99  libs = libsGlbal;
100  }
101 
102 
103  TString Arch( gSystem->GetBuildArch() );
104  Bool_t i64 = kFALSE;
105  if ( gSystem->Getenv("USE_64BITS") || Arch.Contains("x8664")) i64 = kTRUE;
106 
107  Int_t i = 0;
108  while ((libs[i])) {
109  TString lib(libs[i]);
110  //cout << "Found " << lib << endl;
111  if (i64) lib.ReplaceAll("/lib","/lib64");
112  lib += mysql;
113  lib = gSystem->ExpandPathName(lib.Data());
114  if (gSystem->DynamicPathName(lib,kTRUE)) {
115  gSystem->Load(lib.Data());
116  cout << " + " << mysql << " from " << lib.Data();
117  break;
118  }
119  i++;
120  }
121  }
122  cout << endl;
123  }
124  gSystem->Load("libSt_base"); // StMemStat::PrintMem("load St_base");
125  // Look up for the logger option
126  if (gSystem->Load("liblog4cxx.so") >= 0) { // StMemStat::PrintMem("load log4cxx");
127  cout << " + liblog4cxx.so";
128  if(gSystem->Load("libStStarLogger.so") >= 0) { // StMemStat::PrintMem("load log4cxx");
129  cout << " + libStStarLogger.so";
130  gROOT->ProcessLine("StLoggerManager::StarLoggerInit();");
131  }
132  }
133  // gSystem->Load("libHtml");
134  gSystem->Load("libStChain"); // StMemStat::PrintMem("load StChain");
135  gSystem->Load("libStUtilities"); // StMemStat::PrintMem("load StUtilities");
136  gSystem->Load("libStBFChain"); // StMemStat::PrintMem("load StBFChain");
137  cout << endl;
138 }
139 //_____________________________________________________________________
140 void bfc(Int_t First, Int_t Last,
141  const Char_t *Chain,
142  const Char_t *infile,
143  const Char_t *outfile,
144  const Char_t *TreeFile)
145 { // Chain variable define the chain configuration
146  // All symbols are significant (regardless of case)
147  // "-" sign before requiest means that this option is disallowed
148  // Chain = "gstar" run GEANT on flight with 10 muons in range |eta| < 1 amd pT = 1GeV/c (default)
149  // Dynamically link some shared libs
150  Load(Chain);
151  chain = new StBFChain(); cout << "Create chain " << chain->GetName() << endl;
152  TString tChain(Chain);
153  chain->cd();
154  chain->SetDebug(1);
155  if (Last < -3) return;
156  chain->SetFlags(Chain);
157  if (tChain == "" || ! tChain.CompareTo("ittf",TString::kIgnoreCase)) Usage();
158  gMessMgr->QAInfo() << Form("Process [First=%6i/Last=%6i/Total=%6i] Events",First,Last,Last-First+1) << endm;
159  if (Last < -2) return;
160  if (chain->Load() > kStOk) {
161  gMessMgr->Error() << "Problems with loading of shared library(ies)" << endm;
162  gSystem->Exit(1);
163  }
164  chain->Set_IO_Files(infile,outfile);
165  if (TreeFile) chain->SetTFile(new TFile(TreeFile,"RECREATE"));
166 
167  if (Last < -1) return;
168  if (chain->Instantiate() > kStOk) {
169  gMessMgr->Error() << "Problems with instantiation of Maker(s)" << endm;
170  gSystem->Exit(1);
171  }
172  StMaker::lsMakers(chain);
173  if (Last < 0) return;
174  StMaker *dbMk = chain->GetMaker("db");
175  if (dbMk) dbMk->SetDebug(1);
176 #if 0
177  // Insert your maker before "tpc_hits"
178  Char_t *myMaker = "St_TLA_Maker";
179  if (gClassTable->GetID(myMaker) < 0) {
180  gSystem->Load(myMaker);// TString ts("load "; ts+=myMaker; StMemStat::PrintMem(ts.Data());
181  }
182  StMaker *myMk = chain->GetMaker(myMaker);
183  if (myMk) delete myMk;
184  myMk = chain->New(myMaker,"before");
185  if (myMk) {
186  Char_t *before = "tpc_hits";
187  StMaker *tclmk = chain->GetMaker(before);
188  if (tclmk) chain->AddBefore(before,myMk);
189  }
190  // Insert your maker after "tpc_hits"
191  myMk = chain->New(myMaker,"after");
192  if (myMk) {
193  Char_t *after = "tpc_hits";
194  StMaker *tclmk = chain->GetMaker(after);
195  if (tclmk) chain->AddAfter(after,myMk);
196  }
197  // this block is meant as an example ONLY
198  // The default values are set in StRoot/StPass0CalibMaker/ StTpcT0Maker
199  // constructor and are suitable for production. You can change it here
200  // for test purposes.
201  if (chain->GetOption("TpcT0")) {
202  StTpcT0Maker *t0mk = (StTpcT0Maker *) chain->GetMaker("TpcT0");
203  if (t0mk) t0mk->SetDesiredEntries(10);
204  }
205 #endif
206  {
207  TDatime t;
208  gMessMgr->QAInfo() << Form("Run is started at Date/Time %i/%i",t.GetDate(),t.GetTime()) << endm;
209  }
210  gMessMgr->QAInfo() << Form("Run on %s in %s",gSystem->HostName(),gSystem->WorkingDirectory()) << endm;
211  gMessMgr->QAInfo() << Form("with %s", chain->GetCVS()) << endm;
212  // Init the chain and all its makers
213  TAttr::SetDebug(0);
214  chain->SetAttr(".Privilege",0,"*" ); //All makers are NOT priviliged
215  chain->SetAttr(".Privilege",1,"StIOInterFace::*" ); //All IO makers are priviliged
216  chain->SetAttr(".Privilege",1,"St_geant_Maker::*"); //It is also IO maker
217  chain->SetAttr(".Privilege",1,"StTpcDbMaker::*"); //It is also TpcDb maker to catch trips
218  chain->SetAttr(".Privilege",1,"*::tpc_hits"); //May be allowed to act upon excessive events
219  chain->SetAttr(".Privilege",1,"*::tpx_hits"); //May be allowed to act upon excessive events
220  chain->SetAttr(".Privilege",1,"StTpcHitMover::*"); //May be allowed to act upon corrupt events
221  chain->SetAttr(".Privilege",1,"*::tpcChain"); //May pass on messages from sub-makers
222  chain->SetAttr(".Privilege",1,"StTriggerDataMaker::*"); //TriggerData could reject event based on corrupt triggers
223  chain->SetAttr(".Privilege",1,"StEventMaker::*"); //May be allowed to act upon trigger IDs (filtering)
224  Int_t iInit = chain->Init();
225  if (iInit >= kStEOF) {chain->FatalErr(iInit,"on init"); return;}
226  if (Last == 0) return;
227  StEvtHddr *hd = (StEvtHddr*)chain->GetDataSet("EvtHddr");
228  if (hd) hd->SetRunNumber(-2); // to be sure that InitRun calls at least once
229  // skip if any
230  chain->EventLoop(First,Last,0);
231  gMessMgr->QAInfo() << "Run completed " << endm;
232 }
233 //_____________________________________________________________________
234 void bfc(Int_t Last,
235  const Char_t *Chain,
236  const Char_t *infile,
237  const Char_t *outfile,
238  const Char_t *TreeFile) {
239  bfc(1,Last,Chain,infile,outfile,TreeFile);
240 }
241 //____________________________________________________________
242 void Usage() {
243  printf ("============= \t U S A G E =============\n");
244  printf ("bfc(Int_t First,Int_t Last,const Char_t *Chain,const Char_t *infile,const Char_t *outfile,const Char_t *TreeFile)\n");
245  printf ("bfc(Int_t Last,const Char_t *Chain,const Char_t *infile,const Char_t *outfile,const Char_t *TreeFile)\n");
246  printf ("bfc(const Char_t *ChainShort,Int_t Last,const Char_t *infile,const Char_t *outfile)\n");
247  printf ("where\n");
248  printf (" First \t- First event to process\t(Default = 1)\n");
249  printf (" Last \t- Last event to process\t(Default = 1)\n");
250  printf (" Chain \t- Chain specification \t(without First & Last: Default is \"\" which gives this message)\n");
251  printf (" \t \t with First || Last: Default is \"gstar tfs\")\n");
252  printf (" infile \t- Name of Input file \t(Default = 0, i.e. use preset file names depending on Chain)\n");
253  printf (" outfile \t- Name of Output file \t(Default = 0, i.e. define Output file name from Input one)\n");
254  printf (" outfile \t- Name of Tree File \t(Default = 0, i.e. define Output file name from Input one (tags TNtuple))\n");
255  printf (" ChainShort\t- Short cut for chain \t(Default = \"\" -> print out of this message)\n");
256  gSystem->Exit(1);
257 }
258 //_____________________________________________________________________
259 void bfc(const Char_t *Chain="ittf") {
260  bfc(-2,Chain);
261 }
virtual Int_t Instantiate()
Maker-instantiation handler.
Definition: StBFChain.cxx:214
void SetFlags(const Char_t *Chain="gstar tfs")
Scan all flags, check if they are correct, manipulate the comment if necessary.
Definition: StBFChain.cxx:1513
Definition: Stypes.h:43
virtual const char * GetName() const
special overload
Definition: StMaker.cxx:237
virtual Int_t Load()
Routine handling library loading depending on chain options.
Definition: StBFChain.cxx:117
Definition: Stypes.h:41