BOSS 7.0.4
BESIII Offline Software System
Loading...
Searching...
No Matches
RecEmcClusterCnv.cxx
Go to the documentation of this file.
1#ifndef RecEmcClusterCnv_CXX
2#define RecEmcClusterCnv_CXX 1
3
4#include "GaudiKernel/MsgStream.h"
5#include "GaudiKernel/DataObject.h"
6#include "GaudiKernel/ObjectVector.h"
7#include "GaudiKernel/IDataProviderSvc.h"
8#include "GaudiKernel/Bootstrap.h"
9
10#include "TClonesArray.h"
11
12#include "EventModel/EventModel.h"
13
14#include "ReconEvent/ReconEvent.h"
15#include "EmcRecEventModel/RecEmcCluster.h"
16
17#include "RootEventData/TRecEmcCluster.h" // standard root object
18#include "RootEventData/TRecTrackEvent.h"
19
20#include "RootCnvSvc/Rec/RecTrackCnv.h"
21#include "RootCnvSvc/Rec/RecEmcClusterCnv.h"
22#include "RootCnvSvc/RootAddress.h"
23
24#include <vector>
25
26using namespace std;
27
28// Instantiation of a static factory class used by clients to create
29// instances of this service
30//static CnvFactory<RecEmcClusterCnv> s_factory;
31//const ICnvFactory& RecEmcClusterCnvFactory = s_factory;
32
34: RootEventBaseCnv(classID(), svc)
35{
36 //cout<<"in RecEmcClusterCnv::constructor: clusterid= "<<aCluster->clID()<<endl;
37
38 // Here we associate this converter with the /Event path on the TDS.
39 MsgStream log(msgSvc(), "RecEmcClusterCnv");
40 //log << MSG::DEBUG << "Constructor called for " << objType() << endreq;
41 //m_rootTreename ="Rec";
42 m_rootBranchname ="m_recEmcClusterCol";
43 //declareObject(EventModel::Recon::RecEmcClusterCol, objType(), m_rootTreename, m_rootBranchname);
44 m_adresses.push_back(&m_recEmcClusterCol);
45 m_recEmcClusterCol=0;
46}
47
48StatusCode RecEmcClusterCnv::TObjectToDataObject(DataObject*& refpObject) {
49 // creation of TDS object from root object
50 MsgStream log(msgSvc(), "RecEmcClusterCnv");
51 log << MSG::DEBUG << "RecEmcClusterCnv::TObjectToDataObject" << endreq;
52 //cout << "RecEmcClusterCnv::TObjectToDataObject" << endl;
53 StatusCode sc=StatusCode::SUCCESS;
54
55 IDataProviderSvc* eventSvc;
56 Gaudi::svcLocator()->service("EventDataSvc", eventSvc);
57
58 SmartDataPtr<RecEmcHitCol> emcRecHitCol(eventSvc,
60 if(!emcRecHitCol) log << MSG::INFO << "can't retrieve RecEmcHitCol" << endreq;
61
62 // create the TDS location for the RecEmcCluster Collection
63 RecEmcClusterCol* emcClusterTdsCol = new RecEmcClusterCol;
64 refpObject=emcClusterTdsCol;
65
66 // now convert
67 if (!m_recEmcClusterCol) return sc;
68 TIter emcClusterIter(m_recEmcClusterCol);
69 TRecEmcCluster *emcClusterRoot = 0;
70 while ((emcClusterRoot = (TRecEmcCluster*)emcClusterIter.Next())) {
71 RecEmcID clusterId(emcClusterRoot->clusterId());
72
73 RecEmcCluster *emcClusterTds = new RecEmcCluster();
74 m_common.m_rootRecEmcClusterMap[emcClusterRoot] = emcClusterTds;
75
76 emcClusterTds->ClusterId(clusterId);
77
78 vector<int> vecShowers = emcClusterRoot->vecShowers();
79 vector<int>::iterator iVecShower;
80 vector<RecEmcID> vecShowerId;
81 for(iVecShower=vecShowers.begin();
82 iVecShower!=vecShowers.end();
83 iVecShower++) {
84 RecEmcID id(*iVecShower);
85 vecShowerId.push_back(id);
86 }
87 emcClusterTds->ShowerIdVec(vecShowerId);
88
89 if(emcRecHitCol) {
90 vector<Int_t> vecHits = emcClusterRoot->vecHits();
91 vector<Int_t> vecSeeds = emcClusterRoot->vecSeeds();
92 vector<Int_t>::iterator iVecHit;
93
94 //put hit map into cluster
95 for(iVecHit=vecHits.begin();
96 iVecHit!=vecHits.end();
97 iVecHit++) {
98
99 RecEmcID id(*iVecHit);
100
101 RecEmcHitCol::iterator iHit;
102 for(iHit=emcRecHitCol->begin();
103 iHit!=emcRecHitCol->end();
104 iHit++) {
105
106 RecEmcID idHit((*iHit)->getCellId());
107
108 if(id==idHit) {
109 //RecEmcFraction frac(*(*iHit));
110 //frac.Fraction(iHit->second);
111 emcClusterTds->Insert(*(*iHit));
112 break;
113 }
114 } //RecEmcHitCol
115 } //VecHit
116
117 //put seed map into cluster
118 for(iVecHit=vecSeeds.begin();
119 iVecHit!=vecSeeds.end();
120 iVecHit++) {
121
122 RecEmcID id(*iVecHit);
123
124 RecEmcHitCol::iterator iHit;
125 for(iHit=emcRecHitCol->begin();
126 iHit!=emcRecHitCol->end();
127 iHit++) {
128
129 RecEmcID idHit((*iHit)->getCellId());
130
131 if(id==idHit) {
132 //RecEmcFraction frac(*(*iHit));
133 //frac.Fraction(iHit->second);
134 emcClusterTds->InsertSeed(*(*iHit));
135 break;
136 }
137 } //RecEmcHitCol
138 } //VecHit
139
140 }
141
142 emcClusterTdsCol->push_back(emcClusterTds);
143 }
144
145
146 return StatusCode::SUCCESS;
147}
148
149StatusCode RecEmcClusterCnv::DataObjectToTObject(DataObject* obj,RootAddress* rootaddr) {
150
151 MsgStream log(msgSvc(), "RecEmcClusterCnv");
152 log << MSG::DEBUG << "RecEmcClusterCnv::DataObjectToTObject" << endreq;
153 //cout<<"RecEmcClusterCnv::DataObjectToTObject"<<endl;
154 StatusCode sc=StatusCode::SUCCESS;
155
156 RecEmcClusterCol * emcClusterColTds=dynamic_cast<RecEmcClusterCol *> (obj);
157 if (!emcClusterColTds) {
158 log << MSG::ERROR << "Could not downcast to RecEmcClusterCol" << endreq;
159 return StatusCode::FAILURE;
160 }
161
162 DataObject *evt;
163 m_eds->findObject(EventModel::Recon::Event,evt);
164 if (evt==NULL) {
165 log << MSG::ERROR << "Could not get RecEvent in TDS " << endreq;
166 return StatusCode::FAILURE;
167 }
168 ReconEvent * devtTds=dynamic_cast<ReconEvent *> (evt);
169 if (!devtTds) {
170 log << MSG::ERROR << "RecEmcClusterCnv:Could not downcast to TDS DstEvent" << endreq;
171 }
172 IOpaqueAddress *addr;
173
174 m_cnvSvc->getRecTrackCnv()->createRep(evt,addr);
176
177 const TObjArray *m_emcClusterCol = recEvt->getEmcClusterCol();
178 if (!m_emcClusterCol) return sc;
179
180 //necessary in case there is I/O at the same time since array is static
181 recEvt->clearEmcClusterCol();
182
183 RecEmcClusterCol::const_iterator emcClusterTds;
184
185 for(emcClusterTds = emcClusterColTds->begin();
186 emcClusterTds != emcClusterColTds->end();
187 emcClusterTds++) {
188 Int_t clusterId = (*emcClusterTds)->getClusterId();
189
190 vector<Int_t> vecHits;
191 RecEmcHitMap::const_iterator iHitMap;
192 for(iHitMap=(*emcClusterTds)->Begin();
193 iHitMap!=(*emcClusterTds)->End();
194 iHitMap++) {
195 vecHits.push_back(iHitMap->first);
196 }
197
198 vector<Int_t> vecSeeds;
199 RecEmcHitMap::const_iterator iSeedMap;
200 for(iSeedMap=(*emcClusterTds)->BeginSeed();
201 iSeedMap!=(*emcClusterTds)->EndSeed();
202 iSeedMap++) {
203 vecSeeds.push_back(iSeedMap->first);
204 }
205
206 vector<RecEmcID> vecShowerId=(*emcClusterTds)->getShowerIdVec();
207 vector<RecEmcID>::iterator iShowerId;
208 vector<Int_t> vecShowers;
209 for(iShowerId=vecShowerId.begin();
210 iShowerId!=vecShowerId.end();
211 iShowerId++) {
212 vecShowers.push_back(*iShowerId);
213 }
214
215 //cout<<"clusterId="<<RecEmcID(clusterId)<<endl;
216
217 TRecEmcCluster *emcClusterRoot = new TRecEmcCluster();
218 //m_common.m_recEmcClusterMap[(*emcClusterTds)] = emcClusterRoot;
219
220 emcClusterRoot->setClusterId(clusterId);
221 emcClusterRoot->setVecHits(vecHits);
222 emcClusterRoot->setVecSeeds(vecSeeds);
223 emcClusterRoot->setVecShowers(vecShowers);
224
225 recEvt->addEmcCluster(emcClusterRoot);
226 }
227
228 return StatusCode::SUCCESS;
229}
230#endif
virtual StatusCode TObjectToDataObject(DataObject *&obj)
transformation from root
virtual StatusCode DataObjectToTObject(DataObject *obj, RootAddress *addr)
transformation to root
RecEmcClusterCnv(ISvcLocator *svc)
void Insert(const RecEmcHit &aHit)
void InsertSeed(const RecEmcHit &aSeed)
void ClusterId(const RecEmcID id)
static TRecTrackEvent * getWriteObject()
returns object to be written (maintained here for all DIGI-converters)
Definition of a Root address, derived from IOpaqueAddress.
IDataProviderSvc * m_eds
pointer to eventdataservice
std::vector< void * > m_adresses
each converter knows the corresponding adresses
std::string m_rootBranchname
root branchname (may be concatenated of severals)
virtual StatusCode createRep(DataObject *pObject, IOpaqueAddress *&refpAddress)
Convert the transient object to the requested representation.
void addEmcCluster(TRecEmcCluster *Track)
Add a TkrTrack into the Emc data collection *‍/.
const TObjArray * getEmcClusterCol() const
retrieve the whole TObjArray of EmcCluster Data
void clearEmcClusterCol()
clear the whole array (necessary because of the consts-s) *‍/
static std::map< const TObject *, const RecEmcCluster * > m_rootRecEmcClusterMap