Go to the documentation of this file.00001 #include "RecoLuminosity/ROOTSchema/interface/ROOTFileReader.h"
00002 #include "RecoLuminosity/TCPReceiver/interface/LumiStructures.hh"
00003
00004
00005 #include <cstring>
00006
00007
00008 #include <iomanip>
00009 #include <sstream>
00010 #include <algorithm>
00011
00012
00013 #include <dirent.h>
00014
00015
00016 #include <TROOT.h>
00017 #include <TFile.h>
00018 #include <TChain.h>
00019
00020 HCAL_HLX::ROOTFileReader::ROOTFileReader(){
00021
00022 mChain_ = new TChain("LumiTree");
00023 Init();
00024 }
00025
00026 HCAL_HLX::ROOTFileReader::~ROOTFileReader(){
00027
00028 CleanUp();
00029 delete mChain_;
00030 }
00031
00032 int HCAL_HLX::ROOTFileReader::CreateFileNameList(){
00033
00034
00035 DIR *dp;
00036 struct dirent *dirp;
00037 std::string tempFileName;
00038
00039 std::vector< std::string > fileNames;
00040 fileNames.clear();
00041
00042 if( dirName_ == ""){
00043 return false;
00044 }
00045
00046
00047 if( ( dp = opendir( dirName_.c_str() ) ) == NULL ){
00048 closedir(dp);
00049 return false;
00050 }
00051
00052 while( (dirp = readdir(dp)) != NULL ){
00053 tempFileName = dirp->d_name;
00054 if(tempFileName.substr(0,8) == "CMS_LUMI" ){
00055 fileNames.push_back( dirName_ + tempFileName);
00056 }
00057 }
00058 closedir(dp);
00059
00060 if( fileNames.size() == 0 ){
00061 return false;
00062 }
00063
00064 sort(fileNames.begin(), fileNames.end());
00065 return ReplaceFile( fileNames );
00066 }
00067
00068 int HCAL_HLX::ROOTFileReader::SetFileName(const std::string &fileName){
00069
00070 std::vector< std::string > tempVecOfStrings;
00071
00072 tempVecOfStrings.clear();
00073 tempVecOfStrings.push_back( dirName_ + fileName);
00074
00075 return ReplaceFile( tempVecOfStrings );
00076 }
00077
00078 int HCAL_HLX::ROOTFileReader::ReplaceFile(const std::vector< std::string> &fileNames){
00079
00080
00081 delete mChain_;
00082 mChain_ = new TChain("LumiTree");
00083
00084 for( std::vector< std::string >::const_iterator VoS = fileNames.begin();
00085 VoS != fileNames.end();
00086 ++VoS){
00087 mChain_->Add((*VoS).c_str());
00088 }
00089
00090 CreateTree();
00091
00092 return mChain_->GetEntries();
00093 }
00094
00095 void HCAL_HLX::ROOTFileReader::CreateTree(){
00096
00097 Header_ = &(lumiSection_->hdr);
00098 Summary_ = &(lumiSection_->lumiSummary);
00099 Detail_ = &(lumiSection_->lumiDetail);
00100
00101 mChain_->SetBranchAddress("Header.", &Header_, &b_Header);
00102
00103 if( !bEtSumOnly_ ){
00104 mChain_->SetBranchAddress("Summary.", &Summary_, &b_Summary);
00105 mChain_->SetBranchAddress("Detail.", &Detail_, &b_Detail);
00106 }
00107
00108 for(unsigned int iHLX = 0; iHLX < 36; ++iHLX){
00109 std::stringstream branchName;
00110
00111 EtSumPtr_[iHLX] = &(lumiSection_->etSum[iHLX]);
00112 branchName.str(std::string());
00113 branchName << "ETSum" << std::setw(2) << std::setfill('0') << iHLX << ".";
00114 mChain_->SetBranchAddress(branchName.str().c_str(), &EtSumPtr_[iHLX], &b_ETSum[iHLX]);
00115
00116 if( !bEtSumOnly_ ){
00117 OccupancyPtr_[iHLX] = &(lumiSection_->occupancy[iHLX]);
00118 branchName.str(std::string());
00119 branchName << "Occupancy" << std::setw(2) << std::setfill('0') << iHLX << ".";
00120 mChain_->SetBranchAddress(branchName.str().c_str(), &OccupancyPtr_[iHLX], &b_Occupancy[iHLX]);
00121
00122 LHCPtr_[iHLX] = &(lumiSection_->lhc[iHLX]);
00123 branchName.str(std::string());
00124 branchName << "LHC" << std::setw(2) << std::setfill('0') << iHLX << ".";
00125 mChain_->SetBranchAddress(branchName.str().c_str(), &LHCPtr_[iHLX], &b_LHC[iHLX]);
00126 }
00127
00128 }
00129
00130 }
00131
00132 unsigned int HCAL_HLX::ROOTFileReader::GetEntries(){
00133
00134 return mChain_->GetEntries();
00135 }
00136
00137 int HCAL_HLX::ROOTFileReader::GetEntry( int entry ){
00138
00139 int bytes = mChain_->GetEntry(entry);
00140 return bytes;
00141 }
00142
00143 int HCAL_HLX::ROOTFileReader::GetLumiSection( HCAL_HLX::LUMI_SECTION& localSection){
00144
00145 memcpy(&localSection, lumiSection_, sizeof(HCAL_HLX::LUMI_SECTION));
00146 return 0;
00147 }