StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StjMuDstFileNameMaker.C
1 #include "StMaker.h"
2 
3 
4 #include <StMuDSTMaker/COMMON/StMuDstMaker.h>
5 #include <StMuDSTMaker/COMMON/StMuDst.h>
6 #include <StMuDSTMaker/COMMON/StMuEvent.h>
7 
8 #include <TChain.h>
9 #include <TDirectory.h>
10 
11 #include <libgen.h>
12 
13 #include <string>
14 #include <cstring>
15 
16 using namespace std;
17 
19 
20 public:
21 
22  StjMuDstFileNameMaker(const Char_t *name, TDirectory* file, StMuDstMaker* uDstMaker)
23  : StMaker(name), _file(file), _uDstMaker(uDstMaker)
24  { }
25 
26  virtual ~StjMuDstFileNameMaker() { }
27 
28  const char* GetCVS() const
29  {static const char cvs[]="Tag $Name: $ $Id: StjMuDstFileNameMaker.C,v 1.2 2014/08/06 11:43:24 jeromel Exp $ built " __DATE__ " " __TIME__; return cvs;}
30 
31 private:
32 
33  TDirectory* _file;
34  TTree* _tree;
35 
36  StMuDstMaker* _uDstMaker;
37 
38  Int_t _runNumber;
39  Int_t _eventId;
40  Double_t _vertexZ;
41  Char_t _mudstName[256];
42 
43  string getMuDstFileName()
44  {
45  string filepath(_uDstMaker->chain()->GetFile()->GetName());
46  char *chFilepath = new char[filepath.size() + 1];
47  sprintf(chFilepath, "%s", filepath.c_str());
48  string filename = basename(chFilepath);
49  delete[] chFilepath;
50  return filename;
51  }
52 
53 public:
54 
55  Int_t Init()
56  {
57  _file->cd();
58  _tree = new TTree("mudstName", "mudstName");
59  _tree->Branch("runNumber" , &_runNumber , "runNumber/I" );
60  _tree->Branch("eventId" , &_eventId , "eventId/I" );
61  _tree->Branch("vertexZ" , &_vertexZ , "vertexZ/D" );
62  _tree->Branch("mudstName" , &_mudstName , "mudstName[256]/C" );
63  return kStOk;
64  }
65 
66  Int_t Make()
67  {
68  string finlename = getMuDstFileName();
69  _runNumber = _uDstMaker->muDst()->event()->runId();
70  _eventId = _uDstMaker->muDst()->event()->eventId();
71  _vertexZ = _uDstMaker->muDst()->event()->primaryVertexPosition().z();
72 
73  strcpy(_mudstName, finlename.c_str());
74  _tree->Fill();
75  return kStOk;
76  }
77 
78  Int_t Finish()
79  {
80  _tree->BuildIndex("runNumber", "eventId");
81  return kStOk;
82  }
83  ClassDef(StjMuDstFileNameMaker, 0)
84 };
Definition: Stypes.h:41