BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
EventWriterTool Class Reference

#include <EventWriterTool.h>

Inheritance diagram for EventWriterTool:

Public Member Functions

StatusCode write () override
StatusCode initialize () override
 Overriding initialize / finalize.
StatusCode finalize () override

Detailed Description

Definition at line 17 of file EventWriterTool.h.

Member Function Documentation

◆ finalize()

StatusCode EventWriterTool::finalize ( )
override

Definition at line 197 of file EventWriterTool.cxx.

197 {
198 info() << "In finalize()" << endmsg;
199
200 if ( m_mode == 2 )
201 {
202 char* bossVer = getenv( "BES_RELEASE" );
203 info() << "fill boss version: " << bossVer << endmsg;
204
205 /* Get jobOptions */
206 std::string path;
207 auto mgrProp = SmartIF<IProperty>( Gaudi::createApplicationMgr() );
208 mgrProp->getProperty( "JobOptionsPath", path ).ignore();
209
210 info() << "JobOptions file for current job: " << path << endmsg;
211
212 ifstream fin( path.c_str() );
213 string jobOptions;
214 string tempString;
215 while ( getline( fin, tempString ) )
216 {
217 if ( tempString.size() > 0 && tempString.find( "//" ) > tempString.size() )
218 {
219 jobOptions += tempString;
220 jobOptions += "\n";
221 }
222 }
223 // info() << "JobOptions: " << endmsg << jobOptions << endmsg;
224
225 vector<string> jobOptionsVec = { jobOptions };
226
227 auto jobInfoSvc = service<IDataInfoSvc>( "DataInfoSvc" );
228 string decayOptions;
229 if ( !jobInfoSvc ) warning() << "Could not get DataInfoSvc" << endmsg;
230 else
231 {
232 decayOptions = jobInfoSvc->getDecayOptions();
233 info() << "Get decay options: " << decayOptions << endmsg;
234 }
235
236 m_jobInfo->setBossVer( bossVer );
237 m_jobInfo->setJobOptions( jobOptionsVec );
238 m_jobInfo->setDecayOptions( decayOptions );
239
240 m_jobInfoTree->Fill();
241
242 m_st = m_outputFile->Write();
243 if ( m_st == 0 )
244 {
245 error() << "Can not write to the file " << m_dofileName << endmsg;
246 return StatusCode::FAILURE;
247 }
248 m_outputFile->Close();
249
250 delete m_outputFile;
251 delete m_jobInfo;
252
253 m_outputFile = nullptr;
254 m_outputTree = nullptr;
255 }
256
257 if ( m_mode == 3 )
258 {
259 error() << "The DistBossMode has been deprecated!" << endmsg;
260 return StatusCode::FAILURE;
261 }
262
263 return StatusCode::SUCCESS;
264}

◆ initialize()

StatusCode EventWriterTool::initialize ( )
override

Overriding initialize / finalize.

Definition at line 15 of file EventWriterTool.cxx.

15 {
16 info() << "In initialize()" << endmsg;
17
18 StatusCode sc = service( "RootCnvSvc", m_cnvSvc, false );
19 if ( !sc.isSuccess() ) sc = service( "EventCnvSvc", m_cnvSvc, true );
20 if ( !sc.isSuccess() )
21 {
22 error() << "Unable to locate IRootCnvSvc interface" << endmsg;
23 return sc;
24 }
25
26 sc = service( "EventDataSvc", m_pDataProvider, true );
27 if ( !sc.isSuccess() )
28 {
29 error() << "Unable to locate IDataProviderSvc interface" << endmsg;
30 return sc;
31 }
32
33 if ( m_mode == 2 )
34 { // Offline
35 m_outputFile = new TFile( m_dofileName.value().c_str(), "RECREATE" );
36 if ( m_outputFile->IsZombie() || !m_outputFile->IsWritable() )
37 {
38 error() << "Can't open file " << m_dofileName.value() << endmsg;
39 return StatusCode::FAILURE;
40 }
41
42 m_outputTree = new TTree( "Event", "Event" );
43 m_jobInfoTree = new TTree( "JobInfoTree", "Job info" );
44 m_jobInfo = new TJobInfo;
45 }
46 else if ( m_mode == 3 )
47 {
48 error() << "The DistBossMode has been abandoned!" << endmsg;
49 return StatusCode::FAILURE;
50 }
51 else
52 {
53 error() << "Invalid RunMode @ initialize(): " << m_mode << endmsg;
54 return StatusCode::FAILURE;
55 }
56
57 // get services
58 if ( m_itemNames.empty() )
59 {
60 error() << "no ItemList from the jobOption" << endmsg;
61 return StatusCode::FAILURE;
62 }
63
64 // clear items
65 for ( auto& item : m_itemLists ) { delete item; }
66 m_itemLists.clear();
67
68 // add items
69 for ( const auto& item : m_itemNames ) { addItem( m_itemLists, item ); }
70
71 // reset status
72 m_st = 0;
73
74 return StatusCode::SUCCESS;
75}

Referenced by initialize().

◆ write()

StatusCode EventWriterTool::write ( )
override

Definition at line 114 of file EventWriterTool.cxx.

114 {
115 info() << "In write()" << endmsg;
116
117 /* Collect objects */
118 StatusCode sc;
119 for ( const auto& item : m_itemLists )
120 {
121 DataObject* obj = nullptr;
122 IOpaqueAddress* pAddress = nullptr;
123
124 sc = m_pDataProvider->retrieveObject( item->path(), obj );
125 if ( !sc.isSuccess() )
126 { error() << "Cannot write mandatory object(s) (Not found): " << item->path() << endmsg; }
127 else
128 {
129 sc = dynamic_cast<IConversionSvc*>( m_cnvSvc )->createRep( obj, pAddress );
130
131 // Only warn here because old version of `EventWriter` did so.
132 if ( !sc.isSuccess() )
133 warning() << "Failed to create rep for " << item->path() << endmsg;
134 }
135 }
136
137 /* Write to file */
138 if ( m_mode == 2 )
139 {
140 if ( m_st != 1 )
141 {
142 if ( m_commonData.m_rectrackEvt )
143 m_outputTree->Branch( "TRecEvent", "TRecTrackEvent", &m_commonData.m_rectrackEvt,
144 3200000, 1 );
145 if ( m_commonData.m_evtRecObject )
146 m_outputTree->Branch( "TEvtRecObject", "TEvtRecObject", &m_commonData.m_evtRecObject,
147 3200000, 1 );
148 if ( m_commonData.m_dstEvt )
149 m_outputTree->Branch( "TDstEvent", "TDstEvent", &m_commonData.m_dstEvt, 3200000, 1 );
150 if ( m_commonData.m_recEvt )
151 m_outputTree->Branch( "TDigiEvent", "TDigiEvent", &m_commonData.m_recEvt, 3200000, 1 );
152 if ( m_commonData.m_EvtHeader )
153 m_outputTree->Branch( "TEvtHeader", "TEvtHeader", &m_commonData.m_EvtHeader, 3200000,
154 1 );
155 if ( m_commonData.m_EvtNavigator )
156 m_outputTree->Branch( "TEvtNavigator", "TEvtNavigator", &m_commonData.m_EvtNavigator,
157 3200000, 1 );
158 if ( m_commonData.m_hltEvt )
159 m_outputTree->Branch( "THltEvent", "THltEvent", &m_commonData.m_hltEvt, 3200000, 1 );
160 if ( m_commonData.m_mcEvt )
161 m_outputTree->Branch( "TMcEvent", "TMcEvent", &m_commonData.m_mcEvt, 3200000, 1 );
162 if ( m_commonData.m_trigEvt )
163 m_outputTree->Branch( "TTrigEvent", "TTrigEvent", &m_commonData.m_trigEvt, 3200000,
164 1 );
165 m_jobInfoTree->Branch( "JobInfo", &m_jobInfo );
166 m_st = 1;
167 }
168
169 if ( m_outputFile->IsZombie() || !m_outputFile->IsOpen() )
170 {
171 error() << "Can not write to the file " << m_dofileName << endmsg;
172 return StatusCode::FAILURE;
173 }
174
175 int nb = m_outputTree->Fill();
176 if ( nb == -1 )
177 {
178 error() << "Error in fill tree (EventWriter) " << m_outputTree->GetName() << " with "
179 << nb << " bytes" << endmsg;
180 return StatusCode::FAILURE;
181 }
182
183 m_outputFile = m_outputTree->GetCurrentFile();
184 }
185 else if ( m_mode == 3 )
186 {
187 error() << "The DistBossMode has been deprecated!" << endmsg;
188 return StatusCode::FAILURE;
189 }
190
191 m_commonData.clear();
192
193 return StatusCode::SUCCESS;
194}

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