BOSS 8.0.0
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 79 of file digiRootReaderAlg.h.

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

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

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

◆ finalize()

StatusCode digiRootReaderAlg::finalize ( )

Closes the ROOT file and cleans up.

Definition at line 306 of file digiRootReaderAlg.h.

306 {
307 close();
308
309 StatusCode sc = StatusCode::SUCCESS;
310 return sc;
311}

◆ initialize()

StatusCode digiRootReaderAlg::initialize ( )

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

Definition at line 94 of file digiRootReaderAlg.h.

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