BOSS 7.0.2
BESIII Offline Software System
Loading...
Searching...
No Matches
TofDigiCnv.cxx
Go to the documentation of this file.
1#ifndef TofDigiCnv_CXX
2#define TofDigiCnv_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 "TofRawEvent/TofDigi.h" //TDS object
13#include "RootEventData/TTofDigi.h" // standard root object
14#include "RootEventData/TDigiEvent.h"
15#include "RootCnvSvc/Digi/DigiCnv.h"
16#include "RootCnvSvc/Digi/TofDigiCnv.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<TofDigiCnv> s_factory;
23//const ICnvFactory& TofDigiCnvFactory = s_factory;
24
25TofDigiCnv::TofDigiCnv(ISvcLocator* svc)
26: RootEventBaseCnv(classID(), svc)
27{
28 // Here we associate this converter with the /Event path on the TDS.
29 MsgStream log(msgSvc(), "TofDigiCnv");
30 //log << MSG::DEBUG << "Constructor called for " << objType() << endreq;
31 m_rootBranchname ="m_tofDigiCol";
32 //declareObject(EventModel::Digi::TofDigiCol, objType(), m_rootTreename, m_rootBranchname);
33 m_adresses.push_back(&m_tofDigiCol);
34 m_tofDigiCol=0;
35}
36
37StatusCode TofDigiCnv::TObjectToDataObject(DataObject*& refpObject) {
38 // creation of TDS object from root object
39
40 MsgStream log(msgSvc(), "TofDigiCnv");
41 log << MSG::DEBUG << "TofDigiCnv::TObjectToDataObject" << endreq;
42 StatusCode sc=StatusCode::SUCCESS;
43
44 // create the TDS location for the TofDigi Collection
45 TofDigiCol* tofDigiTdsCol = new TofDigiCol;
46 refpObject=tofDigiTdsCol;
47
48
49 // now convert
50 if (!m_tofDigiCol) return sc;
51 TIter tofDigiIter(m_tofDigiCol);
52 TTofDigi *tofDigiRoot = 0;
53 while ((tofDigiRoot = (TTofDigi*)tofDigiIter.Next())) {
54 unsigned int id = tofDigiRoot->getIntId();
55 unsigned int time = tofDigiRoot->getTimeChannel();
56 unsigned int charge = tofDigiRoot->getChargeChannel();
57 unsigned int overflow = tofDigiRoot->getOverflow();
58 int trackIndex = tofDigiRoot->getTrackIndex();
59
60 TofDigi *tofDigiTds = new TofDigi(id);
61 m_common.m_rootTofDigiMap[tofDigiRoot] = tofDigiTds;
62
63 tofDigiTds->setTimeChannel(time);
64 tofDigiTds->setChargeChannel(charge);
65 tofDigiTds->setOverflow(overflow);
66 tofDigiTds->setTrackIndex(trackIndex);
67
68 tofDigiTdsCol->push_back(tofDigiTds);
69 }
70 //m_tofDigiCol->Delete(); // wensp add 2005/12/30
71 delete m_tofDigiCol;
72 m_tofDigiCol = 0;
73 return StatusCode::SUCCESS;
74}
75
76StatusCode TofDigiCnv::DataObjectToTObject(DataObject* obj,RootAddress* rootaddr) {
77
78 MsgStream log(msgSvc(), "TofDigiCnv");
79 log << MSG::DEBUG << "TofDigiCnv::DataObjectToTObject" << endreq;
80 StatusCode sc=StatusCode::SUCCESS;
81
82 TofDigiCol * tofDigiColTds=dynamic_cast<TofDigiCol *> (obj);
83 if (!tofDigiColTds) {
84 log << MSG::ERROR << "Could not downcast to TofDigiCol" << endreq;
85 return StatusCode::FAILURE;
86 }
87
88 DataObject *evt;
89 m_eds->findObject(EventModel::Digi::Event,evt);
90 if (evt==NULL) {
91 log << MSG::ERROR << "Could not get DigiEvent in TDS " << endreq;
92 return StatusCode::FAILURE;
93 }
94 DigiEvent * devtTds=dynamic_cast<DigiEvent *> (evt);
95 if (!devtTds) {
96 log << MSG::ERROR << "TofDigiCnv:Could not downcast to TDS DigiEvent" << endreq;
97 }
98 IOpaqueAddress *addr;
99
100 m_cnvSvc->getDigiCnv()->createRep(evt,addr);
101
103
104 const TObjArray *m_tofDigiCol = recEvt->getTofDigiCol();
105 if (!m_tofDigiCol) return sc;
106 recEvt->clearTofDigiCol(); //necessary in case there is I/O at the same time since array is static
107 TofDigiCol::const_iterator tofDigiTds;
108
109 for (tofDigiTds = tofDigiColTds->begin(); tofDigiTds != tofDigiColTds->end(); tofDigiTds++) {
110 UInt_t overflow = (*tofDigiTds)->getOverflow();
111 UInt_t time = (*tofDigiTds)->getTimeChannel();
112 UInt_t charge = (*tofDigiTds)->getChargeChannel();
113 UInt_t id = (*tofDigiTds)->getIntId();
114 Int_t trackIndex = (*tofDigiTds)->getTrackIndex();
115
116 TTofDigi *tofDigiRoot = new TTofDigi();
117 //m_common.m_tofDigiMap[(*tofDigiTds)] = tofDigiRoot;
118
119 tofDigiRoot->initialize(id, time ,charge);
120 tofDigiRoot->setOverflow(overflow);
121 tofDigiRoot->setTrackIndex(trackIndex);
122
123 recEvt->addTofDigi(tofDigiRoot);
124 }
125
126 return StatusCode::SUCCESS;
127}
128#endif
129
130
131
132
133
134
135
136
137
138
Double_t time
ObjectVector< TofDigi > TofDigiCol
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.
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 addTofDigi(TTofDigi *digi)
Add a TofDigi into the TOF Data collection.
Definition: TDigiEvent.cxx:141
const TObjArray * getTofDigiCol() const
retrieve the whole TObjArray of TofDigi Data
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
UInt_t getOverflow() const
Definition: TTofDigi.cxx:42
void setOverflow(const UInt_t overflow)
Definition: TTofDigi.cxx:36
virtual StatusCode DataObjectToTObject(DataObject *obj, RootAddress *addr)
transformation to root
Definition: TofDigiCnv.cxx:76
TofDigiCnv(ISvcLocator *svc)
Definition: TofDigiCnv.cxx:25
virtual StatusCode TObjectToDataObject(DataObject *&obj)
transformation from root
Definition: TofDigiCnv.cxx:37
void setOverflow(const unsigned int overflow)
static std::map< const TObject *, const TofDigi * > m_rootTofDigiMap