00001 #include "NtpFile.h"
00002
00003 #include "MessageService/MsgService.h"
00004 #include "BeamDataNtuple/NtpBDLiteRecord.h"
00005 #include "CandNtupleSR/NtpSREvent.h"
00006 #include "CandNtupleSR/NtpSRTrack.h"
00007 #include "CandNtupleSR/NtpSRShower.h"
00008 #include "CandNtupleSR/NtpSRSlice.h"
00009 #include "CandNtupleSR/NtpSRStrip.h"
00010 #include "StandardNtuple/NtpStRecord.h"
00011
00012 #include "MuonRemoval/NtpMRRecord.h"
00013
00014 #include "TChain.h"
00015
00016 CVSID("$Id: NtpFile.cxx,v 1.1 2009/03/23 09:28:27 rbpatter Exp $");
00017
00018 NtpFile::NtpFile(){
00019 MSG("NtpAna", Msg::kWarning) << "Assuming DATA" <<endl;
00020 fIsMC = false;
00021 fCCChain = new TChain("NtpSt");
00022 fBDChain = new TChain("NtpBDLite");
00023 fMRChain = new TChain("NtpMR");
00024 fCCRecord = new NtpStRecord();
00025 fBDRecord = new NtpBDLiteRecord();
00026 fMRRecord = new NtpMRRecord();
00027
00028 iCCEvent = -1;
00029 }
00030
00031 NtpFile::NtpFile(bool isMC, bool isMRCC){
00032 fIsMC = isMC;
00033 fIsMRCC = isMRCC;
00034 fCCChain = new TChain("NtpSt");
00035 fBDChain = new TChain("NtpBDLite");
00036 fMRChain = new TChain("NtpMR");
00037 fOldChain = new TChain("NtpOld");
00038 fCCRecord = new NtpStRecord();
00039 fBDRecord = new NtpBDLiteRecord();
00040 fMRRecord = new NtpMRRecord();
00041 fOldRecord = new NtpStRecord();
00042
00043 iCCEvent = -1;
00044 }
00045
00046 NtpFile::~NtpFile(){
00047 fCCRecord->Clear();
00048 fBDRecord->Clear();
00049 fMRRecord->Clear();
00050 fOldRecord->Clear();
00051 delete fCCChain;
00052 delete fCCRecord;
00053 delete fBDRecord;
00054 delete fBDChain;
00055 delete fMRRecord;
00056 delete fMRChain;
00057 delete fOldRecord;
00058 delete fOldChain;
00059 }
00060
00061
00062 bool NtpFile::Init(){
00063 iCCEvent = 0;
00064 fCCChain->SetBranchAddress("NtpStRecord", &fCCRecord);
00065 if(!fIsMC)
00066 fBDChain->SetBranchAddress("NtpBDLiteRecord", &fBDRecord);
00067 if(fIsMRCC){
00068 fMRChain->SetBranchAddress("NtpMRRecord", &fMRRecord);
00069 fOldChain->SetBranchAddress("NtpStRecord", &fOldRecord);
00070 fOldChain->SetBranchStatus("stp.*", false);
00071 }
00072 return true;
00073 }
00074
00075 int NtpFile::AddFiles(const char* filesnames){
00076 return (fCCChain->Add(filesnames) + fBDChain->Add(filesnames) + fMRChain->Add(filesnames) + fOldChain->Add(filesnames) );
00077 }
00078
00079 bool NtpFile::GetNextRecord(){
00080 if(iCCEvent<0){
00081 MSG("NtpAna", Msg::kWarning) << "The files have not been inited... doning it now" <<endl;
00082 this->Init();
00083 }
00084 fCCRecord->Clear();
00085 fBDRecord->Clear();
00086 fMRRecord->Clear();
00087 fOldRecord->Clear();
00088 const int rc1 = fCCChain->GetEntry(iCCEvent);
00089 if(rc1<0){
00090 cout << "*** Failed to get next record " <<endl;
00091 return 0;
00092 }else if(rc1==0){
00093 cout << "End of Records " <<endl;
00094 return 0;
00095 }
00096 const int rc2 = ((fIsMC==false)? fBDChain->GetEntry(iCCEvent) : 1 );
00097 if(rc2<=0){
00098 cout << "*** Failed to get beam record " <<endl;
00099 return 0;
00100 }
00101 const int rc3 = ((fIsMRCC==true)? fMRChain->GetEntry(iCCEvent) : 1 );
00102 if(rc3<=0){
00103 cout << "*** Failed to get mr record " <<endl;
00104 return 0;
00105 }
00106 const int rc4 = ((fIsMRCC==true)? fOldChain->GetEntry(iCCEvent) : 1 );
00107 if(rc4<=0){
00108 cout << "*** Failed to get mrold record " <<endl;
00109 return 0;
00110 }
00111
00112 iCCEvent++;
00113 return true;
00114 }
00115
00116
00117 bool NtpFile::ReloadRecord(){
00118 if(iCCEvent<0){
00119 MSG("NtpAna", Msg::kWarning) << "The files have not been inited... doning it now" <<endl;
00120 this->Init();
00121 }
00122 fCCRecord->Clear();
00123 fBDRecord->Clear();
00124 const int rc1 = fCCChain->GetEntry(iCCEvent-1);
00125 if(rc1<0){
00126 cout << "*** Failed to get next record " <<endl;
00127 return 0;
00128 }else if(rc1==0){
00129 cout << "End of Records " <<endl;
00130 return 0;
00131 }
00132 const int rc2 = ((fIsMC==false)? fBDChain->GetEntry(iCCEvent-1) : 1 );
00133 if(rc2<=0){
00134 cout << "*** Failed to get beam record " <<endl;
00135 return 0;
00136 }
00137 const int rc3 = ((fIsMRCC==true)? fMRChain->GetEntry(iCCEvent-1) : 1 );
00138 if(rc3<=0){
00139 cout << "*** Failed to get mr record " <<endl;
00140 return 0;
00141 }
00142
00143
00144 return true;
00145 }
00146
00147