BOSS 7.0.7
BESIII Offline Software System
Loading...
Searching...
No Matches
MdcDigiCnv.cxx
Go to the documentation of this file.
1#ifndef MdcDigiCnv_CXX
2#define MdcDigiCnv_CXX 1
3
4#include "GaudiKernel/MsgStream.h"
5#include "GaudiKernel/DataObject.h"
6#include "GaudiKernel/ObjectVector.h"
7
8#include "TClonesArray.h"
9
11#include "RawEvent/DigiEvent.h" //TDS object
12#include "MdcRawEvent/MdcDigi.h" //TDS object
13#include "RootEventData/TMdcDigi.h" // standard root object
18
19
20// Instantiation of a static factory class used by clients to create
21// instances of this service
22//static CnvFactory<MdcDigiCnv> s_factory;
23//const ICnvFactory& MdcDigiCnvFactory = s_factory;
24
25MdcDigiCnv::MdcDigiCnv(ISvcLocator* svc)
26: RootEventBaseCnv(classID(), svc)
27{
28 // Here we associate this converter with the /Event path on the TDS.
29 MsgStream log(msgSvc(), "MdcDigiCnv");
30 //log << MSG::DEBUG << "Constructor called for " << objType() << endreq;
31 m_rootBranchname ="m_mdcDigiCol";
32 //declareObject(EventModel::Digi::MdcDigiCol, objType(), m_rootTreename, m_rootBranchname);
33 m_adresses.push_back(&m_mdcDigiCol);
34 m_mdcDigiCol=0;
35
36}
37
38StatusCode MdcDigiCnv::TObjectToDataObject(DataObject*& refpObject) {
39 // creation of TDS object from root object
40
41 MsgStream log(msgSvc(), "MdcDigiCnv");
42 log << MSG::DEBUG << "MdcDigiCnv::TObjectToDataObject" << endreq;
43 StatusCode sc=StatusCode::SUCCESS;
44
45 // create the TDS location for the MdcDigi Collection
46 MdcDigiCol* mdcDigiTdsCol = new MdcDigiCol;
47 refpObject=mdcDigiTdsCol;
48// sc = m_eds->registerObject(EventModel::Digi::MdcDigiCol, mdcDigiTdsCol);
49// if (sc.isFailure()) {
50// log << "Failed to register MdcDigi Collection" << endreq;
51// return StatusCode::FAILURE;
52// }
53
54
55 // now convert
56 if (!m_mdcDigiCol) return sc;
57 TIter mdcDigiIter(m_mdcDigiCol);
58 TMdcDigi *mdcDigiRoot = 0;
59 while ((mdcDigiRoot = (TMdcDigi*)mdcDigiIter.Next())) {
60 unsigned int id = mdcDigiRoot->getIntId();
61 unsigned int time = mdcDigiRoot->getTimeChannel();
62 unsigned int charge = mdcDigiRoot->getChargeChannel();
63 unsigned int overflow = mdcDigiRoot->getOverflow();
64 int trackIndex = mdcDigiRoot->getTrackIndex();
65
66 MdcDigi *mdcDigiTds = new MdcDigi(id);
67 m_common.m_rootMdcDigiMap[mdcDigiRoot] = mdcDigiTds;
68
69 mdcDigiTds->setTimeChannel(time);
70 mdcDigiTds->setChargeChannel(charge);
71 mdcDigiTds->setOverflow(overflow);
72 mdcDigiTds->setTrackIndex(trackIndex);
73
74 mdcDigiTdsCol->push_back(mdcDigiTds);
75 }
76 //m_mdcDigiCol->Delete(); // wensp add 2005/12/30
77 delete m_mdcDigiCol;
78 m_mdcDigiCol = 0;
79 return StatusCode::SUCCESS;
80}
81
82StatusCode MdcDigiCnv::DataObjectToTObject(DataObject* obj,RootAddress* rootaddr) {
83
84 MsgStream log(msgSvc(), "MdcDigiCnv");
85 log << MSG::DEBUG << "MdcDigiCnv::DataObjectToTObject" << endreq;
86 StatusCode sc=StatusCode::SUCCESS;
87
88 MdcDigiCol * mdcDigiColTds=dynamic_cast<MdcDigiCol *> (obj);
89 if (!mdcDigiColTds) {
90 log << MSG::ERROR << "Could not downcast to MdcDigiCol" << endreq;
91 return StatusCode::FAILURE;
92 }
93
94 DataObject *evt;
95 m_eds->findObject(EventModel::Digi::Event,evt);
96 if (evt==NULL) {
97 log << MSG::ERROR << "Could not get DigiEvent in TDS " << endreq;
98 return StatusCode::FAILURE;
99 }
100 DigiEvent * devtTds=dynamic_cast<DigiEvent *> (evt);
101 if (!devtTds) {
102 log << MSG::ERROR << "MdcDigiCnv:Could not downcast to TDS DigiEvent" << endreq;
103 }
104
105 IOpaqueAddress *addr;
106
107
108 m_cnvSvc->getDigiCnv()->createRep(evt,addr);
109
110 //createRep(evt,addr);
111
113
114 const TObjArray *m_mdcDigiCol = recEvt->getMdcDigiCol();
115 if (!m_mdcDigiCol) return sc;
116 recEvt->clearMdcDigiCol(); //necessary in case there is I/O at the same time since array is static
117 MdcDigiCol::const_iterator mdcDigiTds;
118
119 for (mdcDigiTds = mdcDigiColTds->begin(); mdcDigiTds != mdcDigiColTds->end(); mdcDigiTds++) {
120 UInt_t overflow = (*mdcDigiTds)->getOverflow();
121 UInt_t time = (*mdcDigiTds)->getTimeChannel();
122 UInt_t charge = (*mdcDigiTds)->getChargeChannel();
123 UInt_t id = (*mdcDigiTds)->getIntId();
124 Int_t trackIndex = (*mdcDigiTds)->getTrackIndex();
125
126 TMdcDigi *mdcDigiRoot = new TMdcDigi();
127 //m_common.m_mdcDigiMap[(*mdcDigiTds)] = mdcDigiRoot;
128
129 mdcDigiRoot->initialize(id, time ,charge);
130 mdcDigiRoot->setOverflow(overflow);
131 mdcDigiRoot->setTrackIndex(trackIndex);
132 recEvt->addMdcDigi(mdcDigiRoot);
133 }
134
135 return StatusCode::SUCCESS;
136}
137
138#endif
139
140
141
142
143
144
145
146
147
148
ObjectVector< MdcDigi > MdcDigiCol
Definition: MdcDigi.h:39
IMessageSvc * msgSvc()
static TDigiEvent * getWriteObject()
returns object to be written (maintained here for all DIGI-converters)
Definition: DigiCnv.h:35
virtual StatusCode TObjectToDataObject(DataObject *&obj)
transformation from root
Definition: MdcDigiCnv.cxx:38
virtual StatusCode DataObjectToTObject(DataObject *obj, RootAddress *addr)
transformation to root
Definition: MdcDigiCnv.cxx:82
MdcDigiCnv(ISvcLocator *svc)
Definition: MdcDigiCnv.cxx:25
void setOverflow(const unsigned int overflow)
Definition: MdcDigi.h:23
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.
Definition: RootAddress.h:21
DigiCnv * getDigiCnv()
Definition: RootCnvSvc.h:154
Base class for all Root Converters.
std::vector< void * > m_adresses
each converter knows the corresponding adresses
RootCnvSvc * m_cnvSvc
IDataProviderSvc * m_eds
pointer to eventdataservice
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 clearMdcDigiCol()
clear the whole array (necessary because of the consts-s)
Definition: TDigiEvent.h:40
const TObjArray * getMdcDigiCol() const
retrieve the whole TObjArray of TkrDigi Data
Definition: TDigiEvent.h:31
void addMdcDigi(TMdcDigi *digi)
Add a TkrDigi into the TKR data collection.
Definition: TDigiEvent.cxx:120
void setOverflow(const UInt_t overflow)
Definition: TMdcDigi.cxx:36
UInt_t getOverflow() const
Definition: TMdcDigi.cxx:42
void initialize(UInt_t id, UInt_t time=0, UInt_t charge=0)
Definition: TRawData.cxx:34
UInt_t getIntId() const
Definition: TRawData.cxx:50
void setTrackIndex(const int trackIndex)
Definition: TRawData.cxx:41
int getTrackIndex() const
Definition: TRawData.cxx:45
UInt_t getChargeChannel() const
Definition: TRawData.cxx:60
UInt_t getTimeChannel() const
Definition: TRawData.cxx:55
static std::map< const TObject *, const MdcDigi * > m_rootMdcDigiMap
Create a set of maps between ROOT Digi objects and TDS Digi data.
Definition: commonData.h:121
_EXTERN_ std::string Event
Definition: EventModel.h:56
float charge