BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
DTag.cxx
Go to the documentation of this file.
1#include "GaudiKernel/IDataManagerSvc.h"
2#include "GaudiKernel/IDataProviderSvc.h"
3#include "GaudiKernel/ISvcLocator.h"
4#include "GaudiKernel/MsgStream.h"
5#include "GaudiKernel/SmartDataPtr.h"
6#include "GaudiKernel/SmartIF.h"
7#include <vector>
8
9#include "EventModel/EventModel.h"
10#include "EvtRecEvent/EvtRecDTag.h"
11#include "EvtRecEvent/EvtRecEvent.h"
12
13#include "DTag.h"
14
16//**************************************************************************************
17DTag::DTag( const std::string& name, ISvcLocator* pSvcLocator )
18 : Gaudi::Sequence( name, pSvcLocator ) {
19 // Declare the properties
20 declareProperty( "NeutralDReconstruction", m_recD0 = true );
21 declareProperty( "ChargedDReconstruction", m_recDp = true );
22 declareProperty( "DsReconstruction", m_recDs = true );
23 declareProperty( "LambdaCReconstruction", m_recLc = true );
24 // declareProperty("RawDstOnly", m_rawdstonly = true);
25}
26
27// ***********************************************************************************
28StatusCode DTag::initialize() {
29
30 MsgStream log( msgSvc(), name() );
31
32 log << MSG::INFO << "creating DTag sub Algorithm" << endmsg;
33
34 StatusCode sc;
35
36 if ( m_recD0 )
37 {
38 sc = createSubAlgorithm( "NeutralDReconstruction", "NeutralDReconstruction",
39 m_NeutralDReconstruction );
40 if ( sc.isFailure() )
41 {
42 log << MSG::ERROR << "Error while creating D0Reconstruction" << endmsg;
43 return StatusCode::FAILURE;
44 }
45 }
46
47 if ( m_recDp )
48 {
49 sc = createSubAlgorithm( "ChargedDReconstruction", "ChargedDReconstruction",
50 m_ChargedDReconstruction );
51 if ( sc.isFailure() )
52 {
53 log << MSG::ERROR << "Error while creating D+Reconstruction" << endmsg;
54 return StatusCode::FAILURE;
55 }
56 }
57
58 if ( m_recDs )
59 {
60 sc = createSubAlgorithm( "DsReconstruction", "DsReconstruction", m_DsReconstruction );
61 if ( sc.isFailure() )
62 {
63 log << MSG::ERROR << "Error while creating DsReconstruction" << endmsg;
64 return StatusCode::FAILURE;
65 }
66 }
67
68 if ( m_recLc )
69 {
70 sc = createSubAlgorithm( "LambdaCReconstruction", "LambdaCReconstruction",
71 m_LambdaCReconstruction );
72 if ( sc.isFailure() )
73 {
74 log << MSG::ERROR << "Error while creating LcReconstruction" << endmsg;
75 return StatusCode::FAILURE;
76 }
77 }
78
79 log << MSG::INFO << "Calling Sequence::initialize()" << endmsg;
80 return Gaudi::Sequence::initialize();
81}
82
83StatusCode DTag::registerParent( MsgStream& log ) const {
84 DataObject* aEvtRecEvent;
85 eventSvc()->findObject( "/Event/EvtRec", aEvtRecEvent ).ignore();
86 if ( aEvtRecEvent == NULL )
87 {
88 aEvtRecEvent = new EvtRecEvent();
89 StatusCode sc = eventSvc()->registerObject( "/Event/EvtRec", aEvtRecEvent );
90 if ( sc != StatusCode::SUCCESS )
91 {
92 log << MSG::FATAL << "Could not register EvtRecEvent" << endmsg;
93 return StatusCode::FAILURE;
94 }
95 }
96 return StatusCode::SUCCESS;
97}
98
99StatusCode DTag::clearEvtRecDTagCol( MsgStream& log ) const {
100 StatusCode sc = registerParent( log );
101 if ( sc != StatusCode::SUCCESS ) { return sc; }
102
103 DataObject* aEvtRecDTagCol;
104 eventSvc()->findObject( "/Event/EvtRec/EvtRecDTagCol", aEvtRecDTagCol ).ignore();
105 if ( aEvtRecDTagCol )
106 {
107 // IDataManagerSvc* dataManSvc = dynamic_cast<IDataManagerSvc*>(eventSvc());
108 SmartIF<IDataManagerSvc> dataManSvc( eventSvc() );
109 dataManSvc->clearSubTree( "/Event/EvtRec/EvtRecDTagCol" ).ignore();
110 eventSvc()->unregisterObject( "/Event/EvtRec/EvtRecDTagCol" ).ignore();
111 }
112
113 SmartDataPtr<EvtRecDTagCol> evtRecDTagCol( eventSvc(), EventModel::EvtRec::EvtRecDTagCol );
114 if ( evtRecDTagCol )
115 {
116 // IDataManagerSvc* dataManSvc = dynamic_cast<IDataManagerSvc*>(eventSvc());
117 SmartIF<IDataManagerSvc> dataManSvc( eventSvc() );
118 dataManSvc->clearSubTree( "/Event/EvtRec/EvtRecDTagCol" ).ignore();
119 eventSvc()->unregisterObject( "/Event/EvtRec/EvtRecDTagCol" ).ignore();
120 }
121
122 return StatusCode::SUCCESS;
123}
124
125void DTag::registerEvtRecDTagCol( MsgStream& log ) const {
126 EvtRecDTagCol* aNewEvtRecDTagCol = new EvtRecDTagCol;
127 StatusCode sc =
128 eventSvc()->registerObject( "/Event/EvtRec/EvtRecDTagCol", aNewEvtRecDTagCol );
129 if ( sc != StatusCode::SUCCESS )
130 { log << MSG::FATAL << "Could not register EvtRecDTagCol in TDS!" << endmsg; }
131}
132
133// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
134StatusCode DTag::execute( const EventContext& ctx ) const {
135
136 // check if DTagList exists
137 // if true, will exit the program
138 SmartDataPtr<EvtRecDTagCol> evtRecDTagCol( eventSvc(), EventModel::EvtRec::EvtRecDTagCol );
139 if ( evtRecDTagCol )
140 {
141 if ( evtRecDTagCol->size() > 0 )
142 {
143 cout << "************************************************" << endl;
144 cout << "EvtRecDTagCol already exists in this file!" << endl;
145 cout << " Please run this program on a raw dst file!" << endl;
146 cout << " *** This job is now being killed. ***" << endl;
147 cout << "************************************************" << endl;
148 return StatusCode::FAILURE;
149 } /// End of "evtRecDTagCol->size()>0" IF
150 } /// End of "evtRecDTagCol != NULL" IF
151
152 MsgStream log( msgSvc(), name() );
153 StatusCode sc = clearEvtRecDTagCol( log );
154 if ( sc != StatusCode::SUCCESS ) { return sc; }
155
156 DataObject* aEvtRecDTagCol;
157 eventSvc()->findObject( "/Event/EvtRec/EvtRecDTagCol", aEvtRecDTagCol ).ignore();
158 if ( aEvtRecDTagCol == NULL ) { registerEvtRecDTagCol( log ); }
159
160 std::vector<Algorithm*>::const_iterator it = subAlgorithms()->begin();
161 std::vector<Algorithm*>::const_iterator end = subAlgorithms()->end();
162 for ( ; it != end; it++ )
163 {
164 sc = ( *it )->execute( ctx );
165 if ( sc.isFailure() ) { log << "Error executing selection " << ( *it )->name() << endmsg; }
166 }
167
168 return StatusCode::SUCCESS;
169}
170
171// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
172StatusCode DTag::finalize() {
173
174 MsgStream log( msgSvc(), name() );
175 log << MSG::INFO << "in finalize()" << endmsg;
176 return Gaudi::Sequence::finalize();
177}
DECLARE_COMPONENT(BesBdkRc)
ObjectVector< EvtRecDTag > EvtRecDTagCol
IMessageSvc * msgSvc()
Definition DTag.h:6
StatusCode finalize()
Definition DTag.cxx:172
DTag(const std::string &name, ISvcLocator *pSvcLocator)
Definition DTag.cxx:17
StatusCode execute(const EventContext &ctx) const
Definition DTag.cxx:134
StatusCode initialize()
Definition DTag.cxx:28