CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ROOTFileReader.cc
Go to the documentation of this file.
2 #include "RecoLuminosity/TCPReceiver/interface/LumiStructures.hh"
3 
4 // C
5 #include <cstring> // memset
6 
7 // STL
8 #include <iomanip>
9 #include <sstream>
10 #include <algorithm>
11 
12 // Unix
13 #include <dirent.h> // opendir
14 
15 // ROOT
16 #include <TROOT.h>
17 #include <TFile.h>
18 #include <TChain.h>
19 
21 
22  mChain_ = new TChain("LumiTree");
23  Init();
24 }
25 
27 
28  CleanUp();
29  delete mChain_;
30 }
31 
33 
34  // Look for files that follow the standard naming convention.
35  DIR *dp;
36  struct dirent *dirp;
37  std::string tempFileName;
38 
39  std::vector< std::string > fileNames;
40  fileNames.clear();
41 
42  if( dirName_ == ""){
43  return false;
44  }
45 
46  // Check directory existance.
47  if( ( dp = opendir( dirName_.c_str() ) ) == NULL ){
48  return false;
49  }
50 
51  while( (dirp = readdir(dp)) != NULL ){
52  tempFileName = dirp->d_name;
53  if(tempFileName.substr(0,8) == "CMS_LUMI" ){
54  fileNames.push_back( dirName_ + tempFileName);
55  }
56  }
57  closedir(dp);
58 
59  if( fileNames.size() == 0 ){
60  return false;
61  }
62 
63  sort(fileNames.begin(), fileNames.end());
64  return ReplaceFile( fileNames );
65 }
66 
68 
69  std::vector< std::string > tempVecOfStrings;
70 
71  tempVecOfStrings.clear();
72  tempVecOfStrings.push_back( dirName_ + fileName);
73 
74  return ReplaceFile( tempVecOfStrings );
75 }
76 
77 int HCAL_HLX::ROOTFileReader::ReplaceFile(const std::vector< std::string> &fileNames){
78  // ReplaceFile is called by either SetFileName or CreateFileNameList.
79 
80  delete mChain_;
81  mChain_ = new TChain("LumiTree");
82 
83  for( std::vector< std::string >::const_iterator VoS = fileNames.begin();
84  VoS != fileNames.end();
85  ++VoS){
86  mChain_->Add((*VoS).c_str());
87  }
88 
89  CreateTree();
90 
91  return mChain_->GetEntries();
92 }
93 
95 
96  Header_ = &(lumiSection_->hdr);
97  Summary_ = &(lumiSection_->lumiSummary);
98  Detail_ = &(lumiSection_->lumiDetail);
99 
100  mChain_->SetBranchAddress("Header.", &Header_, &b_Header);
101 
102  if( !bEtSumOnly_ ){
103  mChain_->SetBranchAddress("Summary.", &Summary_, &b_Summary);
104  mChain_->SetBranchAddress("Detail.", &Detail_, &b_Detail);
105  }
106 
107  for(unsigned int iHLX = 0; iHLX < 36; ++iHLX){
108  std::stringstream branchName;
109 
110  EtSumPtr_[iHLX] = &(lumiSection_->etSum[iHLX]);
111  branchName.str(std::string());
112  branchName << "ETSum" << std::setw(2) << std::setfill('0') << iHLX << ".";
113  mChain_->SetBranchAddress(branchName.str().c_str(), &EtSumPtr_[iHLX], &b_ETSum[iHLX]);
114 
115  if( !bEtSumOnly_ ){
116  OccupancyPtr_[iHLX] = &(lumiSection_->occupancy[iHLX]);
117  branchName.str(std::string());
118  branchName << "Occupancy" << std::setw(2) << std::setfill('0') << iHLX << ".";
119  mChain_->SetBranchAddress(branchName.str().c_str(), &OccupancyPtr_[iHLX], &b_Occupancy[iHLX]);
120 
121  LHCPtr_[iHLX] = &(lumiSection_->lhc[iHLX]);
122  branchName.str(std::string());
123  branchName << "LHC" << std::setw(2) << std::setfill('0') << iHLX << ".";
124  mChain_->SetBranchAddress(branchName.str().c_str(), &LHCPtr_[iHLX], &b_LHC[iHLX]);
125  }
126 
127  }
128 
129 }
130 
132 
133  return mChain_->GetEntries();
134 }
135 
137 
138  int bytes = mChain_->GetEntry(entry);
139  return bytes;
140 }
141 
143 
144  memcpy(&localSection, lumiSection_, sizeof(HCAL_HLX::LUMI_SECTION));
145  return 0;
146 }
#define NULL
Definition: scimark2.h:8
int SetFileName(const std::string &fileName)
std::pair< std::string, MonitorElement * > entry
Definition: ME_MAP.h:8
int GetLumiSection(HCAL_HLX::LUMI_SECTION &section)
int ReplaceFile(const std::vector< std::string > &fileNames)
tuple fileNames
Definition: LaserDQM_cfg.py:34