00001 #include "RecoLuminosity/ROOTSchema/interface/ROOTFileMerger.h" 00002 00003 #include <iostream> 00004 #include <iomanip> 00005 #include <cstdio> 00006 00007 #include <TFile.h> 00008 #include <TChain.h> 00009 00010 HCAL_HLX::ROOTFileMerger::ROOTFileMerger(){ 00011 #ifdef DEBUG 00012 std::cout << "Begin " << __PRETTY_FUNCTION__ << std::endl; 00013 #endif 00014 00015 minSectionNumber = 99999999; 00016 00017 #ifdef DEBUG 00018 std::cout << "End " << __PRETTY_FUNCTION__ << std::endl; 00019 #endif 00020 } 00021 00022 HCAL_HLX::ROOTFileMerger::~ROOTFileMerger(){ 00023 #ifdef DEBUG 00024 std::cout << "Begin " << __PRETTY_FUNCTION__ << std::endl; 00025 #endif 00026 00027 #ifdef DEBUG 00028 std::cout << "End " << __PRETTY_FUNCTION__ << std::endl; 00029 #endif 00030 } 00031 00032 void HCAL_HLX::ROOTFileMerger::Merge(const unsigned int runNumber, bool bCMSLive){ 00033 #ifdef DEBUG 00034 std::cout << "Begin " << __PRETTY_FUNCTION__ << std::endl; 00035 #endif 00036 // TChain::Merge and TTree::CloneTree leak because we used TTree::Bronch to create the tree. 00037 00038 HCAL_HLX::LUMI_SECTION lumiSection; 00039 00040 ROOTFileReader RFR; 00041 RFR.ReplaceFile(CreateInputFileName(runNumber)); 00042 00043 SetFileName(CreateRunFileName(runNumber, 0)); 00044 CreateTree(lumiSection); 00045 00046 int nentries = RFR.GetNumEntries(); 00047 00048 for(int i = 0; i < nentries; i++){ 00049 RFR.GetEntry(i); 00050 RFR.GetLumiSection(lumiSection); 00051 if( minSectionNumber > lumiSection.hdr.sectionNumber ){ 00052 std::cout << minSectionNumber << ":" << lumiSection.hdr.sectionNumber << std::endl; 00053 minSectionNumber = lumiSection.hdr.sectionNumber; 00054 } 00055 00056 // Must fill Threshold eventually right now it contains fake data. 00057 FillTree(lumiSection); 00058 } 00059 00060 CloseTree(); 00061 00062 // Rename file so that it includes the minimum lumi section number. 00063 rename( CreateRunFileName(runNumber, 0).c_str(), CreateRunFileName(runNumber, minSectionNumber).c_str() ); 00064 00065 #ifdef DEBUG 00066 std::cout << "End " << __PRETTY_FUNCTION__ << std::endl; 00067 #endif 00068 } 00069 00070 std::string HCAL_HLX::ROOTFileMerger::CreateInputFileName(const unsigned int runNumber){ 00071 #ifdef DEBUG 00072 std::cout << "Begin " << __PRETTY_FUNCTION__ << std::endl; 00073 #endif 00074 00075 std::ostringstream outputString; 00076 00077 outputString << outputDir_ 00078 << "/" 00079 << TimeStampYYYYMM() 00080 << "/" 00081 << std::setfill('0') << std::setw(9) << runNumber 00082 << "/" 00083 << outputFilePrefix_ 00084 << "_" 00085 << TimeStampYYYYMMDD() 00086 << "_" 00087 << std::setfill('0') << std::setw(9) << runNumber 00088 << "_*.root"; 00089 00090 #ifdef DEBUG 00091 std::cout << "Input file name: " << outputString.str() << std::endl; 00092 std::cout << "End " << __PRETTY_FUNCTION__ << std::endl; 00093 #endif 00094 return outputString.str(); 00095 } 00096