BOSS 7.0.7
BESIII Offline Software System
Loading...
Searching...
No Matches
digiRootReaderAlg Class Reference

Reads Digitization data from a persistent ROOT file and stores the the data in the TDS. Based on digiRootReaderAlg of Glast. More...

#include <digiRootReaderAlg.h>

+ Inheritance diagram for digiRootReaderAlg:

Public Member Functions

 digiRootReaderAlg (const std::string &name, ISvcLocator *pSvcLocator)
 
StatusCode initialize ()
 Handles setup by opening ROOT file in read mode and creating a new TTree.
 
StatusCode execute ()
 Orchastrates reading from ROOT file and storing the data on the TDS for each event.
 
StatusCode finalize ()
 Closes the ROOT file and cleans up.
 

Detailed Description

Reads Digitization data from a persistent ROOT file and stores the the data in the TDS. Based on digiRootReaderAlg of Glast.

Definition at line 34 of file digiRootReaderAlg.h.

Constructor & Destructor Documentation

◆ digiRootReaderAlg()

digiRootReaderAlg::digiRootReaderAlg ( const std::string &  name,
ISvcLocator *  pSvcLocator 
)

Definition at line 85 of file digiRootReaderAlg.h.

85 :
86Algorithm(name, pSvcLocator)
87{
88 // Input pararmeters that may be set via the jobOptions file
89 // Input ROOT file name
90 declareProperty("digiRootFile",m_fileName="");
91 StringArrayProperty initList;
92 std::vector<std::string> initVec;
93 initVec.push_back("digicopy.root");
94 initList.setValue(initVec);
95 declareProperty("digiRootFileList",m_fileList=initList);
96 // Input TTree name
97 initVec.clear();
98 declareProperty("digiTreeName", m_treeName="Rec");// wensp midify for test 2005/05/14
99
100}

Member Function Documentation

◆ execute()

StatusCode digiRootReaderAlg::execute ( )

Orchastrates reading from ROOT file and storing the data on the TDS for each event.

Definition at line 175 of file digiRootReaderAlg.h.

176{
177 // Purpose and Method: Called once per event. This method calls
178 // the appropriate methods to read data from the ROOT file and store
179 // data on the TDS.
180
181 MsgStream log(msgSvc(), name());
182
183 StatusCode sc = StatusCode::SUCCESS;
184
185 if (m_digiEvt) m_digiEvt->Clear();
186
187 static Int_t evtId = 0;
188 int readInd, numBytes;
189 std::pair<int,int> runEventPair = (m_rootIoSvc) ? m_rootIoSvc->runEventPair() : std::pair<int,int>(-1,-1);
190
191 if ((m_rootIoSvc) && (m_rootIoSvc->index() >= 0)) {
192 readInd = m_rootIoSvc->index();
193 } else if ((m_rootIoSvc) && (runEventPair.first != -1) && (runEventPair.second != -1)) {
194 int run = runEventPair.first;
195 int evt = runEventPair.second;
196 readInd = m_digiTree->GetEntryNumberWithIndex(run, evt);
197 } else {
198 readInd = evtId;
199 }
200
201 if (readInd >= m_numEvents) {
202 log << MSG::WARNING << "Requested index is out of bounds - no digi data loaded" << endreq;
203 return StatusCode::SUCCESS;
204 }
205
206 numBytes = m_digiTree->GetEvent(readInd);
207
208 if ((numBytes <= 0) || (!m_digiEvt)) {
209 log << MSG::WARNING << "Failed to load digi event" << endreq;
210 return StatusCode::SUCCESS;
211 }
212
213
214 sc = readDigiEvent();
215 if (sc.isFailure()) {
216 log << MSG::ERROR << "Failed to read top level DigiEvent" << endreq;
217 return sc;
218 }
219
220 sc = readMdcDigi();
221 if (sc.isFailure()) {
222 log << MSG::ERROR << "Failed to load MdcDigi" << endreq;
223 return sc;
224 }
225
226 evtId = readInd+1;
227 return sc;
228}
IMessageSvc * msgSvc()
virtual int index()=0
virtual std::pair< int, int > runEventPair()=0

◆ finalize()

StatusCode digiRootReaderAlg::finalize ( )

Closes the ROOT file and cleans up.

Definition at line 308 of file digiRootReaderAlg.h.

309{
310 close();
311
312 StatusCode sc = StatusCode::SUCCESS;
313 return sc;
314}

◆ initialize()

StatusCode digiRootReaderAlg::initialize ( )

Handles setup by opening ROOT file in read mode and creating a new TTree.

Definition at line 102 of file digiRootReaderAlg.h.

103{
104 // Purpose and Method: Called once before the run begins. This method
105 // opens a new ROOT file and prepares for reading.
106
107 StatusCode sc = StatusCode::SUCCESS;
108 MsgStream log(msgSvc(), name());
109
110 // Use the Job options service to set the Algorithm's parameters
111 // This will retrieve parameters set in the job options file
112 setProperties();
113
114 if ( service("RootIoSvc", m_rootIoSvc, true).isFailure() ){
115 log << MSG::INFO << "Couldn't find the RootIoSvc!" << endreq;
116 log << MSG::INFO << "Event loop will not terminate gracefully" << endreq;
117 m_rootIoSvc = 0;
118 //return StatusCode::FAILURE;
119 }
120
122
123 // Save the current directory for the ntuple writer service
124 TDirectory *saveDir = gDirectory;
125
126 m_digiTree = new TChain(m_treeName.c_str());
127
128 std::string emptyStr("");
129 if (m_fileName.compare(emptyStr) != 0) {
130 TFile f(m_fileName.c_str());
131 if (!f.IsOpen()) {
132 log << MSG::ERROR << "ROOT file " << m_fileName.c_str()
133 << " could not be opened for reading." << endreq;
134 return StatusCode::FAILURE;
135 }
136 f.Close();
137 m_digiTree->Add(m_fileName.c_str());
138 log << MSG::INFO << "Opened file: " << m_fileName.c_str() << endreq;
139 } else {
140 const std::vector<std::string> fileList = m_fileList.value( );
141 std::vector<std::string>::const_iterator it;
142 std::vector<std::string>::const_iterator itend = fileList.end( );
143 for (it = fileList.begin(); it != itend; it++) {
144 std::string theFile = (*it);
145 TFile f(theFile.c_str());
146 if (!f.IsOpen()) {
147 log << MSG::ERROR << "ROOT file " << theFile.c_str()
148 << " could not be opened for reading." << endreq;
149 return StatusCode::FAILURE;
150 }
151 f.Close();
152 m_digiTree->Add(theFile.c_str());
153 log << MSG::INFO << "Opened file: " << theFile.c_str() << endreq;
154 }
155 }
156
157
158 m_digiEvt = 0;
159 m_digiTree->SetBranchAddress("DigiEvent", &m_digiEvt);
160 //m_common.m_digiEvt = m_digiEvt;
161 m_numEvents = m_digiTree->GetEntries();
162
163 if (m_rootIoSvc) {
164 m_rootIoSvc->setRootEvtMax(m_numEvents);
165 if (!m_digiTree->GetIndex()) m_digiTree->BuildIndex("m_runId", "m_eventId");
166 m_rootIoSvc->registerRootTree(m_digiTree);
167 }
168
169
170 saveDir->cd();
171 return sc;
172
173}
virtual void registerRootTree(TChain *ch)=0
virtual void setRootEvtMax(unsigned int max)=0
static int expandEnvVar(std::string *toExpand, const std::string &openDel=std::string("$("), const std::string &closeDel=std::string(")"))
TFile f("ana_bhabha660a_dqa_mcPat_zy_old.root")

The documentation for this class was generated from the following file: