BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
MucDigiCnv.cxx
Go to the documentation of this file.
1#ifndef MucDigiCnv_CXX
2#define MucDigiCnv_CXX 1
3
4#include "GaudiKernel/DataObject.h"
5#include "GaudiKernel/MsgStream.h"
6#include "GaudiKernel/ObjectVector.h"
7
8#include "TClonesArray.h"
9
10#include "EventModel/EventModel.h"
11#include "MucRawEvent/MucDigi.h" //TDS object
12#include "RawEvent/DigiEvent.h" //TDS object
13#include "RootCnvSvc/Digi/DigiCnv.h"
14#include "RootCnvSvc/Digi/MucDigiCnv.h"
15#include "RootCnvSvc/RootAddress.h"
16#include "RootEventData/TDigiEvent.h"
17#include "RootEventData/TMucDigi.h" // standard root object
18
19// Instantiation of a static factory class used by clients to create
20// instances of this service
21// static CnvFactory<MucDigiCnv> s_factory;
22// const ICnvFactory& MucDigiCnvFactory = s_factory;
23
24MucDigiCnv::MucDigiCnv( ISvcLocator* svc ) : RootEventBaseCnv( classID(), svc ) {
25 // Here we associate this converter with the /Event path on the TDS.
26 MsgStream log( msgSvc(), "MucDigiCnv" );
27 // log << MSG::DEBUG << "Constructor called for " << objType() << endmsg;
28 m_rootBranchname = "m_mucDigiCol";
29 // declareObject(EventModel::Digi::MucDigiCol, objType(), m_rootTreename, m_rootBranchname);
30 m_adresses.push_back( &m_mucDigiCol );
31 m_mucDigiCol = 0;
32}
33
34StatusCode MucDigiCnv::TObjectToDataObject( DataObject*& refpObject ) {
35 // creation of TDS object from root object
36
37 MsgStream log( msgSvc(), "MucDigiCnv" );
38 log << MSG::DEBUG << "MucDigiCnv::TObjectToDataObject" << endmsg;
39 StatusCode sc = StatusCode::SUCCESS;
40
41 // create the TDS location for the MucDigi Collection
42 MucDigiCol* mucDigiTdsCol = new MucDigiCol;
43 refpObject = mucDigiTdsCol;
44
45 // now convert
46 if ( !m_mucDigiCol ) return sc;
47 TIter mucDigiIter( m_mucDigiCol );
48 TMucDigi* mucDigiRoot = 0;
49 while ( ( mucDigiRoot = (TMucDigi*)mucDigiIter.Next() ) )
50 {
51 unsigned int id = mucDigiRoot->getIntId();
52 unsigned int time = mucDigiRoot->getTimeChannel();
53 unsigned int charge = mucDigiRoot->getChargeChannel();
54 int trackIndex = mucDigiRoot->getTrackIndex();
55
56 MucDigi* mucDigiTds = new MucDigi( id );
57 m_common.m_rootMucDigiMap[mucDigiRoot] = mucDigiTds;
58
59 mucDigiTds->setTimeChannel( time );
60 mucDigiTds->setChargeChannel( charge );
61 mucDigiTds->setTrackIndex( trackIndex );
62 mucDigiTdsCol->push_back( mucDigiTds );
63 }
64 // m_mucDigiCol->Delete(); // wensp add 2005/12/30
65 delete m_mucDigiCol;
66 m_mucDigiCol = 0;
67 return StatusCode::SUCCESS;
68}
69
70StatusCode MucDigiCnv::DataObjectToTObject( DataObject* obj, RootAddress* rootaddr ) {
71
72 MsgStream log( msgSvc(), "MucDigiCnv" );
73 log << MSG::DEBUG << "MucDigiCnv::DataObjectToTObject" << endmsg;
74 StatusCode sc = StatusCode::SUCCESS;
75
76 MucDigiCol* mucDigiColTds = dynamic_cast<MucDigiCol*>( obj );
77 if ( !mucDigiColTds )
78 {
79 log << MSG::ERROR << "Could not downcast to MucDigiCol" << endmsg;
80 return StatusCode::FAILURE;
81 }
82
83 DataObject* evt;
84 m_eds->findObject( EventModel::Digi::Event, evt );
85 if ( evt == NULL )
86 {
87 log << MSG::ERROR << "Could not get DigiEvent in TDS " << endmsg;
88 return StatusCode::FAILURE;
89 }
90 DigiEvent* devtTds = dynamic_cast<DigiEvent*>( evt );
91 if ( !devtTds )
92 { log << MSG::ERROR << "MucDigiCnv:Could not downcast to TDS DigiEvent" << endmsg; }
93 IOpaqueAddress* addr;
94
95 m_cnvSvc->getDigiCnv()->createRep( evt, addr );
96 TDigiEvent* recEvt = m_cnvSvc->getDigiCnv()->getWriteObject();
97
98 const TObjArray* m_mucDigiCol = recEvt->getMucDigiCol();
99 if ( !m_mucDigiCol ) return sc;
100 recEvt->clearMucDigiCol(); // necessary in case there is I/O at the same time since array is
101 // static
102 MucDigiCol::const_iterator mucDigiTds;
103
104 for ( mucDigiTds = mucDigiColTds->begin(); mucDigiTds != mucDigiColTds->end(); mucDigiTds++ )
105 {
106 UInt_t time = ( *mucDigiTds )->getTimeChannel();
107 UInt_t charge = ( *mucDigiTds )->getChargeChannel();
108 UInt_t id = ( *mucDigiTds )->getIntId();
109 Int_t trackIndex = ( *mucDigiTds )->getTrackIndex();
110
111 TMucDigi* mucDigiRoot = new TMucDigi();
112 // m_common.m_mucDigiMap[(*mucDigiTds)] = mucDigiRoot;
113
114 mucDigiRoot->initialize( id, time, charge );
115 mucDigiRoot->setTrackIndex( trackIndex );
116 recEvt->addMucDigi( mucDigiRoot );
117 }
118
119 return StatusCode::SUCCESS;
120}
121#endif
Double_t time
IMessageSvc * msgSvc()
MucDigiCnv(ISvcLocator *svc)
virtual StatusCode TObjectToDataObject(DataObject *&obj)
transformation from root
virtual StatusCode DataObjectToTObject(DataObject *obj, RootAddress *addr)
transformation to root
void setTrackIndex(const int trackIndex)
Definition RawData.cxx:29
void setChargeChannel(const unsigned int chargeChannel)
Definition RawData.cxx:24
void setTimeChannel(const unsigned int timeChannel)
Definition RawData.cxx:21
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)
RootEventBaseCnv(const CLID &clid, ISvcLocator *svc)
const TObjArray * getMucDigiCol() const
retrieve the whole TObjArray of MucDigi Data
void addMucDigi(TMucDigi *digi)
Add a MucDigi into the MUC Data collection.
void initialize(UInt_t id, UInt_t time=0, UInt_t charge=0)
Definition TRawData.cxx:30
UInt_t getIntId() const
Definition TRawData.cxx:42
void setTrackIndex(const int trackIndex)
Definition TRawData.cxx:37
int getTrackIndex() const
Definition TRawData.cxx:39
UInt_t getChargeChannel() const
Definition TRawData.cxx:48
UInt_t getTimeChannel() const
Definition TRawData.cxx:45