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  closedir(dp);
49  return false;
50  }
51 
52  while( (dirp = readdir(dp)) != NULL ){
53  tempFileName = dirp->d_name;
54  if(tempFileName.substr(0,8) == "CMS_LUMI" ){
55  fileNames.push_back( dirName_ + tempFileName);
56  }
57  }
58  closedir(dp);
59 
60  if( fileNames.size() == 0 ){
61  return false;
62  }
63 
64  sort(fileNames.begin(), fileNames.end());
65  return ReplaceFile( fileNames );
66 }
67 
69 
70  std::vector< std::string > tempVecOfStrings;
71 
72  tempVecOfStrings.clear();
73  tempVecOfStrings.push_back( dirName_ + fileName);
74 
75  return ReplaceFile( tempVecOfStrings );
76 }
77 
78 int HCAL_HLX::ROOTFileReader::ReplaceFile(const std::vector< std::string> &fileNames){
79  // ReplaceFile is called by either SetFileName or CreateFileNameList.
80 
81  delete mChain_;
82  mChain_ = new TChain("LumiTree");
83 
84  for( std::vector< std::string >::const_iterator VoS = fileNames.begin();
85  VoS != fileNames.end();
86  ++VoS){
87  mChain_->Add((*VoS).c_str());
88  }
89 
90  CreateTree();
91 
92  return mChain_->GetEntries();
93 }
94 
96 
97  Header_ = &(lumiSection_->hdr);
98  Summary_ = &(lumiSection_->lumiSummary);
99  Detail_ = &(lumiSection_->lumiDetail);
100 
101  mChain_->SetBranchAddress("Header.", &Header_, &b_Header);
102 
103  if( !bEtSumOnly_ ){
104  mChain_->SetBranchAddress("Summary.", &Summary_, &b_Summary);
105  mChain_->SetBranchAddress("Detail.", &Detail_, &b_Detail);
106  }
107 
108  for(unsigned int iHLX = 0; iHLX < 36; ++iHLX){
109  std::stringstream branchName;
110 
111  EtSumPtr_[iHLX] = &(lumiSection_->etSum[iHLX]);
112  branchName.str(std::string());
113  branchName << "ETSum" << std::setw(2) << std::setfill('0') << iHLX << ".";
114  mChain_->SetBranchAddress(branchName.str().c_str(), &EtSumPtr_[iHLX], &b_ETSum[iHLX]);
115 
116  if( !bEtSumOnly_ ){
117  OccupancyPtr_[iHLX] = &(lumiSection_->occupancy[iHLX]);
118  branchName.str(std::string());
119  branchName << "Occupancy" << std::setw(2) << std::setfill('0') << iHLX << ".";
120  mChain_->SetBranchAddress(branchName.str().c_str(), &OccupancyPtr_[iHLX], &b_Occupancy[iHLX]);
121 
122  LHCPtr_[iHLX] = &(lumiSection_->lhc[iHLX]);
123  branchName.str(std::string());
124  branchName << "LHC" << std::setw(2) << std::setfill('0') << iHLX << ".";
125  mChain_->SetBranchAddress(branchName.str().c_str(), &LHCPtr_[iHLX], &b_LHC[iHLX]);
126  }
127 
128  }
129 
130 }
131 
133 
134  return mChain_->GetEntries();
135 }
136 
138 
139  int bytes = mChain_->GetEntry(entry);
140  return bytes;
141 }
142 
144 
145  memcpy(&localSection, lumiSection_, sizeof(HCAL_HLX::LUMI_SECTION));
146  return 0;
147 }
tuple fileNames
Definition: align_tpl.py:17
#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)