CGEM BOSS 6.6.5.h
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 35 of file digiRootReaderAlg.h.

Constructor & Destructor Documentation

◆ digiRootReaderAlg()

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

Definition at line 87 of file digiRootReaderAlg.h.

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

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 177 of file digiRootReaderAlg.h.

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

344{
345 close();
346
347 StatusCode sc = StatusCode::SUCCESS;
348 return sc;
349}

◆ initialize()

StatusCode digiRootReaderAlg::initialize ( )

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

Definition at line 104 of file digiRootReaderAlg.h.

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

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