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