CMS 3D CMS Logo

/data/git/CMSSW_5_3_11_patch5/src/RecoLuminosity/ROOTSchema/src/ROOTFileMerger.cc

Go to the documentation of this file.
00001 #include "RecoLuminosity/ROOTSchema/interface/ROOTFileMerger.h"
00002 #include "RecoLuminosity/ROOTSchema/interface/ROOTFileWriter.h"
00003 #include "RecoLuminosity/ROOTSchema/interface/ROOTFileReader.h"
00004 
00005 #include "RecoLuminosity/TCPReceiver/interface/LumiStructures.hh"
00006  
00007 #include <iomanip>
00008 #include <cstdio>
00009 
00010 #include <TFile.h>
00011 #include <TChain.h>
00012 
00013 HCAL_HLX::ROOTFileMerger::ROOTFileMerger():minSectionNumber_(99999)
00014 {
00015 
00016   RFWriter_    = NULL;
00017   RFReader_    = NULL;
00018   lumiSection_ = NULL;
00019 
00020   RFWriter_ = new ROOTFileWriter;
00021   if( RFWriter_ == 0 ){
00022     // Could not allocate memory.
00023     // Do something.
00024   }
00025 
00026   RFReader_ = new ROOTFileReader; 
00027   if( RFReader_ == 0 ){
00028     // Could not allocate memory.
00029     // Do something.
00030   }
00031 
00032   lumiSection_ = new HCAL_HLX::LUMI_SECTION;
00033   if( lumiSection_ == 0 ){
00034     // Could not allocate memory.
00035     // Do something.
00036   }
00037 
00038   RFWriter_->SetMerge(true);
00039 }
00040 
00041 HCAL_HLX::ROOTFileMerger::~ROOTFileMerger(){
00042 
00043   if( RFWriter_ != 0){
00044     delete RFWriter_;
00045   }
00046   
00047   if( RFReader_ != 0){
00048     delete RFReader_;
00049   }
00050 
00051   if( lumiSection_ !=0 ){
00052     delete lumiSection_;
00053   }
00054 }
00055 
00056 bool HCAL_HLX::ROOTFileMerger::Merge(const unsigned int runNumber, const unsigned int minSectionNumber ){
00057 
00058     /*
00059       TChain::Merge and TTree::CloneTree leak because we used TTree::Bronch to create the tree.
00060     */
00061   
00062   RFReader_->CreateFileNameList();
00063   
00064   // RFWriter_->SetFileName(runNumber, firstSectionNumber);
00065   RFWriter_->OpenFile(runNumber, minSectionNumber);
00066   
00067   unsigned int nentries = RFReader_->GetEntries();
00068   if( nentries == 0 ){
00069     RFWriter_->CloseFile();
00070     return false;
00071   }
00072   
00073   for(unsigned int iEntry = 0; iEntry < nentries; ++iEntry ){
00074     memset( lumiSection_, 0, sizeof(LUMI_SECTION));
00075     RFReader_->GetEntry(iEntry);
00076     RFReader_->GetLumiSection(*lumiSection_);
00077     
00078     // Must fill Threshold eventually  right now it contains fake data.
00079     RFWriter_->FillTree(*lumiSection_);
00080   }
00081   
00082   return RFWriter_->CloseFile();
00083 }
00084 
00085 void HCAL_HLX::ROOTFileMerger::SetInputDir( const std::string &dirName){
00086 
00087   RFReader_->SetDir(dirName);
00088 }
00089 
00090 void HCAL_HLX::ROOTFileMerger::SetOutputDir(const std::string &dirName){
00091 
00092   RFWriter_->SetDir(dirName);
00093 }
00094 
00095 std::string HCAL_HLX::ROOTFileMerger::GetOutputFileName(){
00096 
00097   return RFWriter_->GetFileName();
00098 }
00099 
00100 void HCAL_HLX::ROOTFileMerger::SetEtSumOnly(bool bEtSumOnly){
00101 
00102   RFWriter_->SetEtSumOnly(bEtSumOnly);
00103   RFReader_->SetEtSumOnly(bEtSumOnly);
00104 }
00105 
00106 void HCAL_HLX::ROOTFileMerger::SetFileType( const std::string &fileType ){
00107 
00108   RFWriter_->SetFileType( fileType );
00109   RFReader_->SetFileType( fileType );
00110 }
00111 
00112 void HCAL_HLX::ROOTFileMerger::SetDate( const std::string &date ){
00113   
00114   RFWriter_->SetDate( date );
00115   RFReader_->SetDate( date );
00116 }