CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ROOTFileWriter.cc
Go to the documentation of this file.
2 #include "RecoLuminosity/TCPReceiver/interface/LumiStructures.hh"
3 
4 #include <sstream>
5 #include <typeinfo>
6 #include <iomanip>
7 #include <vector>
8 #include <ctime>
9 
10 #include <stddef.h>
11 
12 // mkdir
13 #include <sys/types.h>
14 #include <sys/stat.h>
15 
16 #include <TROOT.h>
17 #include <TChain.h>
18 #include <TTree.h>
19 #include <TFile.h>
20 
22 
23  Init(); // ROOTFileBase
24 }
25 
27 
28  CleanUp(); // ROOTFileBase
29 }
30 
32 
33  return OpenFile( localSection.hdr.runNumber,
34  localSection.hdr.sectionNumber);
35 }
36 
38  const unsigned int sectionNumber){
39 
40  SetFileName( runNumber, sectionNumber);
41 
42  m_file = new TFile( (dirName_ + fileName_).c_str(), "RECREATE");
43  if( !m_file ){
44  return false;
45  }
46 
47  m_file->cd();
48  CreateTree();
49 
50  return true;
51 }
52 
54 
55  m_tree = new TTree("LumiTree","");
56 
57  Header_ = &(lumiSection_->hdr);
58  Summary_ = &(lumiSection_->lumiSummary);
59  Detail_ = &(lumiSection_->lumiDetail);
60 
61  m_tree->Bronch("Header.", "HCAL_HLX::LUMI_SECTION_HEADER", &Header_, 1);
62 
63  if( !bEtSumOnly_ ){
64  m_tree->Bronch("Summary.", "HCAL_HLX::LUMI_SUMMARY", &Summary_, 1);
65  m_tree->Bronch("Detail.", "HCAL_HLX::LUMI_DETAIL", &Detail_, 1);
66  }
67 
68  for( unsigned int iHLX = 0; iHLX < 36; ++iHLX ){
69  EtSumPtr_[iHLX] = &( lumiSection_->etSum[iHLX] );
70  MakeBranch(lumiSection_->etSum[iHLX], &EtSumPtr_[iHLX], iHLX);
71 
72  if( !bEtSumOnly_ ){
73  OccupancyPtr_[iHLX] = &(lumiSection_->occupancy[iHLX]);
74  MakeBranch(lumiSection_->occupancy[iHLX], &OccupancyPtr_[iHLX], iHLX);
75 
76  LHCPtr_[iHLX] = &(lumiSection_->lhc[iHLX]);
77  MakeBranch(lumiSection_->lhc[iHLX], &LHCPtr_[iHLX], iHLX);
78  }
79  }
80 }
81 
82 template< class T >
83 void HCAL_HLX::ROOTFileWriter::MakeBranch(const T &in, T **out, const int HLXNum){
84 
85  const std::string typeName = typeid(T).name();
86  std::string className;
87  std::string branchName;
88  std::ostringstream numString;
89 
90  if(typeName == "N8HCAL_HLX11LHC_SECTIONE"){
91  className = "HCAL_HLX::LHC_SECTION";
92  branchName = "LHC";
93  }else if(typeName == "N8HCAL_HLX17OCCUPANCY_SECTIONE"){
94  className = "HCAL_HLX::OCCUPANCY_SECTION";
95  branchName = "Occupancy";
96  }else if(typeName == "N8HCAL_HLX14ET_SUM_SECTIONE"){
97  className = "HCAL_HLX::ET_SUM_SECTION";
98  branchName = "ETSum";
99  }
100 
101  numString << std::setfill('0') << std::setw(2) << HLXNum;
102  branchName = branchName + numString.str() + ".";
103  m_tree->Bronch(branchName.c_str(), className.c_str(), out, 1);
104 }
105 
107 
108  memcpy( lumiSection_, &localSection, sizeof(HCAL_HLX::LUMI_SECTION));
109  m_tree->Fill();
110 }
111 
113 
114  m_tree->Write();
115  m_file->Close();
116 
117  if(m_file != NULL){
118  delete m_file;
119  //delete m_tree; // NO!!! root does this when you delete m_file
120  m_file = NULL;
121  m_tree = NULL;
122  }
123 
124  return true;
125 }
bool OpenFile(const HCAL_HLX::LUMI_SECTION &lumiSection)
#define NULL
Definition: scimark2.h:8
void FillTree(const HCAL_HLX::LUMI_SECTION &localSection)
tuple out
Definition: dbtoconf.py:99
void MakeBranch(const T &in, T **out, int HLXNum)
long double T
std::string className(const T &t)
Definition: ClassName.h:30