CGEM BOSS 6.6.5.f
BESIII Offline Software System
Loading...
Searching...
No Matches
RootCnvSvc-04-01-15/src/Digi/CgemDigiCnv.cxx
Go to the documentation of this file.
1#ifndef CgemDigiCnv_CXX
2#define CgemDigiCnv_CXX 1
3
4#include "GaudiKernel/MsgStream.h"
5#include "GaudiKernel/DataObject.h"
6#include "GaudiKernel/ObjectVector.h"
7
8#include "TClonesArray.h"
9
10#include "EventModel/EventModel.h"
11#include "RawEvent/DigiEvent.h" //TDS object
12#include "CgemRawEvent/CgemDigi.h" //TDS object
13#include "RootEventData/TCgemDigi.h" // standard root object
14#include "RootEventData/TDigiEvent.h"
15#include "RootCnvSvc/Digi/DigiCnv.h"
16#include "RootCnvSvc/Digi/CgemDigiCnv.h"
17#include "RootCnvSvc/RootAddress.h"
18
19
20// Instantiation of a static factory class used by clients to create
21// instances of this service
22//static CnvFactory<CgemDigiCnv> s_factory;
23//const ICnvFactory& CgemDigiCnvFactory = s_factory;
24
25CgemDigiCnv::CgemDigiCnv(ISvcLocator* svc)
26: RootEventBaseCnv(classID(), svc)
27{
28 // Here we associate this converter with the /Event path on the TDS.
29 MsgStream log(msgSvc(), "CgemDigiCnv");
30//myModify
31 log << MSG::INFO << "My Message::CgemDigiCnv:RootEventBaseCnv" << endreq;
32
33 //log << MSG::DEBUG << "Constructor called for " << objType() << endreq;
34 m_rootBranchname ="m_cgemDigiCol";
35 //declareObject(EventModel::Digi::CgemDigiCol, objType(), m_rootTreename, m_rootBranchname);
36 m_adresses.push_back(&m_cgemDigiCol);
37 m_cgemDigiCol=0;
38
39//myModify
40 log << MSG::INFO << "My Message::CgemDigiCnv:RootEventBaseCnv-finished" << endreq;
41
42}
43
44StatusCode CgemDigiCnv::TObjectToDataObject(DataObject*& refpObject) {
45 // creation of TDS object from root object
46
47 MsgStream log(msgSvc(), "CgemDigiCnv");
48//myModify
49 log << MSG::INFO << "My Message::CgemDigiCnv::TObjectToDataObject()" << endreq;
50
51 log << MSG::DEBUG << "CgemDigiCnv::TObjectToDataObject" << endreq;
52 StatusCode sc=StatusCode::SUCCESS;
53
54 // create the TDS location for the CgemDigi Collection
55 CgemDigiCol* cgemDigiTdsCol = new CgemDigiCol;
56 refpObject=cgemDigiTdsCol;
57// sc = m_eds->registerObject(EventModel::Digi::CgemDigiCol, cgemDigiTdsCol);
58// if (sc.isFailure()) {
59// log << "Failed to register CgemDigi Collection" << endreq;
60// return StatusCode::FAILURE;
61// }
62
63 // now convert
64 if (!m_cgemDigiCol) return sc;
65 TIter cgemDigiIter(m_cgemDigiCol);
66 TCgemDigi *cgemDigiRoot = 0;
67 while ((cgemDigiRoot = (TCgemDigi*)cgemDigiIter.Next()))
68 {
69 unsigned int id = cgemDigiRoot->getIntId();
70 unsigned int time = cgemDigiRoot->getTimeChannel();
71 unsigned int charge = cgemDigiRoot->getChargeChannel();
72 unsigned int overflow = cgemDigiRoot->getOverflow();
73 unsigned int trackIndex = cgemDigiRoot->getTrackIndex();
74 double time_ns = cgemDigiRoot->getTime_ns();
75 double charge_fC = cgemDigiRoot->getCharge_fc();
76
77 CgemDigi *cgemDigiTds = new CgemDigi(id);
78 m_common.m_rootCgemDigiMap[cgemDigiRoot] = cgemDigiTds;
79
80 //myModify
81 log << MSG::INFO << "My Message::CgemDigiCnv::TObjectToDataObject: "
82 << "id=" << id
83 << ",time=" << time
84 << ",charge=" << charge
85 << ",overflow=" << overflow << endreq;
86
87 cgemDigiTds->setTimeChannel(time);
88 cgemDigiTds->setChargeChannel(charge);
89 cgemDigiTds->setOverflow(overflow);
90 cgemDigiTds->setTrackIndex(trackIndex);
91 cgemDigiTds->setTime_ns(time_ns);
92 cgemDigiTds->setCharge_fc(charge_fC);
93
94 cgemDigiTdsCol->push_back(cgemDigiTds);
95 }
96 //m_cgemDigiCol->Delete(); // wensp add 2005/12/30
97 delete m_cgemDigiCol;
98 m_cgemDigiCol = 0;
99
100 //myModify
101 log << MSG::INFO << "My Message::CgemDigiCnv::TObjectToDataObject()-finished" << endreq;
102
103 return StatusCode::SUCCESS;
104}
105
106StatusCode CgemDigiCnv::DataObjectToTObject(DataObject* obj,RootAddress* rootaddr) {
107
108 MsgStream log(msgSvc(), "CgemDigiCnv");
109 //myModify
110 log << MSG::INFO << "My Message::CgemDigiCnv::DataObjectToTObject()" << endreq;
111
112 log << MSG::DEBUG << "CgemDigiCnv::DataObjectToTObject" << endreq;
113 StatusCode sc=StatusCode::SUCCESS;
114
115 CgemDigiCol * cgemDigiColTds=dynamic_cast<CgemDigiCol *> (obj);
116 if (!cgemDigiColTds) {
117 log << MSG::ERROR << "Could not downcast to CgemDigiCol" << endreq;
118 //myModify
119 log << MSG::INFO << "My Message::CgemDigiCnv::DataObjectToTObject()-finished" << endreq;
120
121 return StatusCode::FAILURE;
122 }
123
124 DataObject *evt;
125 m_eds->findObject(EventModel::Digi::Event,evt);
126 if (evt==NULL) {
127 log << MSG::ERROR << "Could not get DigiEvent in TDS " << endreq;
128//myModify
129 log << MSG::INFO << "My Message::CgemDigiCnv::DataObjectToTObject()-finished" << endreq;
130
131 return StatusCode::FAILURE;
132 }
133 DigiEvent * devtTds=dynamic_cast<DigiEvent *> (evt);
134 if (!devtTds) {
135//myModify
136 log << MSG::INFO << "My Message::CgemDigiCnv::DataObjectToTObject()-finished" << endreq;
137
138 log << MSG::ERROR << "CgemDigiCnv:Could not downcast to TDS DigiEvent" << endreq;
139 }
140
141 IOpaqueAddress *addr;
142
143
144 m_cnvSvc->getDigiCnv()->createRep(evt,addr);
145
146 //createRep(evt,addr);
147
149
150 const TObjArray *m_cgemDigiCol = recEvt->getCgemDigiCol();
151 if (!m_cgemDigiCol) return sc;
152 recEvt->clearCgemDigiCol(); //necessary in case there is I/O at the same time since array is static
153 CgemDigiCol::const_iterator cgemDigiTds;
154
155 for (cgemDigiTds=cgemDigiColTds->begin(); cgemDigiTds!=cgemDigiColTds->end(); cgemDigiTds++)
156 {
157 UInt_t overflow = (*cgemDigiTds)->getOverflow();
158 UInt_t time = (*cgemDigiTds)->getTimeChannel();
159 UInt_t charge = (*cgemDigiTds)->getChargeChannel();
160 UInt_t id = (*cgemDigiTds)->getIntId();
161 Int_t trackIndex = (*cgemDigiTds)->getTrackIndex();
162 Double_t time_ns = (*cgemDigiTds)->getTime_ns();
163 Double_t charge_fC= (*cgemDigiTds)->getCharge_fc();
164
165
166 TCgemDigi *cgemDigiRoot = new TCgemDigi();
167 //m_common.m_cgemDigiMap[(*cgemDigiTds)] = cgemDigiRoot;
168 //myModify
169 log << MSG::INFO << "My Message::CgemDigiCnv::DataObjectToTObject: "
170 << "id=" << id
171 << ",time=" << time
172 << ",charge=" << charge
173 << ",overflow=" << overflow << endreq;
174
175 cgemDigiRoot->initialize(id, time ,charge);
176 cgemDigiRoot->setOverflow(overflow);
177 cgemDigiRoot->setTrackIndex(trackIndex);
178 cgemDigiRoot->setTime_ns(time_ns);
179 cgemDigiRoot->setCharge_fc(charge_fC);
180 recEvt->addCgemDigi(cgemDigiRoot);
181 }
182
183 //myModify
184 log << MSG::INFO << "My Message::CgemDigiCnv::DataObjectToTObject()-finished" << endreq;
185
186 return StatusCode::SUCCESS;
187}
188
189#endif
Double_t time
virtual StatusCode DataObjectToTObject(DataObject *obj, RootAddress *addr)
transformation to root
virtual StatusCode TObjectToDataObject(DataObject *&obj)
transformation from root
static TDigiEvent * getWriteObject()
returns object to be written (maintained here for all DIGI-converters)
void setTrackIndex(const int trackIndex)
Definition: RawData.cxx:35
void setChargeChannel(const unsigned int chargeChannel)
Definition: RawData.cxx:30
void setTimeChannel(const unsigned int timeChannel)
Definition: RawData.cxx:25
Definition of a Root address, derived from IOpaqueAddress.
virtual StatusCode createRep(DataObject *pObject, IOpaqueAddress *&refpAddress)
Convert the transient object to the requested representation.
void setOverflow(const UInt_t overflow)
void clearCgemDigiCol()
clear the whole array (necessary because of the consts-s)
const TObjArray * getCgemDigiCol() const
retrieve the whole TObjArray of TkrDigi Data
void addCgemDigi(TCgemDigi *digi)
Add a TkrDigi into the TKR data collection.
void initialize(UInt_t id, UInt_t time=0, UInt_t charge=0)
void setTrackIndex(const int trackIndex)
static std::map< const TObject *, const CgemDigi * > m_rootCgemDigiMap