BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
EmcDigiCnv.cxx
Go to the documentation of this file.
1#ifndef EmcDigiCnv_CXX
2#define EmcDigiCnv_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 "EmcRawEvent/EmcDigi.h" //TDS object
11#include "EventModel/EventModel.h"
12#include "RawEvent/DigiEvent.h" //TDS object
13#include "RootCnvSvc/Digi/DigiCnv.h"
14#include "RootCnvSvc/Digi/EmcDigiCnv.h"
15#include "RootCnvSvc/RootAddress.h"
16#include "RootEventData/TDigiEvent.h"
17#include "RootEventData/TEmcDigi.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<EmcDigiCnv> s_factory;
22// const ICnvFactory& EmcDigiCnvFactory = s_factory;
23
24EmcDigiCnv::EmcDigiCnv( ISvcLocator* svc ) : RootEventBaseCnv( classID(), svc ) {
25 // Here we associate this converter with the /Event path on the TDS.
26 MsgStream log( msgSvc(), "EmcDigiCnv" );
27 // log << MSG::DEBUG << "Constructor called for " << objType() << endmsg;
28 m_rootBranchname = "m_emcDigiCol";
29 // declareObject(EventModel::Digi::EmcDigiCol, objType(), m_rootTreename, m_rootBranchname);
30 m_adresses.push_back( &m_emcDigiCol );
31 m_emcDigiCol = 0;
32}
33
34StatusCode EmcDigiCnv::TObjectToDataObject( DataObject*& refpObject ) {
35 // creation of TDS object from root object
36
37 MsgStream log( msgSvc(), "EmcDigiCnv" );
38 log << MSG::DEBUG << "EmcDigiCnv::TObjectToDataObject" << endmsg;
39 StatusCode sc = StatusCode::SUCCESS;
40
41 // create the TDS location for the MdcDigi Collection
42 EmcDigiCol* emcDigiTdsCol = new EmcDigiCol;
43 refpObject = emcDigiTdsCol;
44
45 // now convert
46 if ( !m_emcDigiCol ) return sc;
47 TIter emcDigiIter( m_emcDigiCol );
48 TEmcDigi* emcDigiRoot = 0;
49 while ( ( emcDigiRoot = (TEmcDigi*)emcDigiIter.Next() ) )
50 {
51 unsigned int id = emcDigiRoot->getIntId();
52 unsigned int time = emcDigiRoot->getTimeChannel();
53 unsigned int charge = emcDigiRoot->getChargeChannel();
54 unsigned int measure = emcDigiRoot->getMeasure();
55 int trackIndex = emcDigiRoot->getTrackIndex();
56
57 EmcDigi* emcDigiTds = new EmcDigi( id );
58 m_common.m_rootEmcDigiMap[emcDigiRoot] = emcDigiTds;
59
60 emcDigiTds->setTimeChannel( time );
61 emcDigiTds->setChargeChannel( charge );
62 emcDigiTds->setMeasure( measure );
63 emcDigiTds->setTrackIndex( trackIndex );
64
65 emcDigiTdsCol->push_back( emcDigiTds );
66 }
67 // m_emcDigiCol->Delete(); // wensp add 2005/12/30
68 delete m_emcDigiCol;
69 m_emcDigiCol = 0;
70 return StatusCode::SUCCESS;
71}
72
73StatusCode EmcDigiCnv::DataObjectToTObject( DataObject* obj, RootAddress* rootaddr ) {
74
75 MsgStream log( msgSvc(), "EmcDigiCnv" );
76 log << MSG::DEBUG << "EmcDigiCnv::DataObjectToTObject" << endmsg;
77 StatusCode sc = StatusCode::SUCCESS;
78
79 EmcDigiCol* emcDigiColTds = dynamic_cast<EmcDigiCol*>( obj );
80 if ( !emcDigiColTds )
81 {
82 log << MSG::ERROR << "Could not downcast to EmcDigiCol" << endmsg;
83 return StatusCode::FAILURE;
84 }
85
86 DataObject* evt;
87 m_eds->findObject( EventModel::Digi::Event, evt );
88 if ( evt == NULL )
89 {
90 log << MSG::ERROR << "Could not get DigiEvent in TDS " << endmsg;
91 return StatusCode::FAILURE;
92 }
93 DigiEvent* devtTds = dynamic_cast<DigiEvent*>( evt );
94 if ( !devtTds )
95 { log << MSG::ERROR << "EmcDigiCnv:Could not downcast to TDS DigiEvent" << endmsg; }
96 IOpaqueAddress* addr;
97
98 m_cnvSvc->getDigiCnv()->createRep( evt, addr );
99 TDigiEvent* recEvt = m_cnvSvc->getDigiCnv()->getWriteObject();
100
101 const TObjArray* m_emcDigiCol = recEvt->getEmcDigiCol();
102 if ( !m_emcDigiCol ) return sc;
103 recEvt->clearEmcDigiCol(); // necessary in case there is I/O at the same time since array is
104 // static
105 EmcDigiCol::const_iterator emcDigiTds;
106
107 for ( emcDigiTds = emcDigiColTds->begin(); emcDigiTds != emcDigiColTds->end(); emcDigiTds++ )
108 {
109 UInt_t measure = ( *emcDigiTds )->getMeasure();
110 UInt_t time = ( *emcDigiTds )->getTimeChannel();
111 UInt_t charge = ( *emcDigiTds )->getChargeChannel();
112 UInt_t id = ( *emcDigiTds )->getIntId();
113 Int_t trackIndex = ( *emcDigiTds )->getTrackIndex();
114
115 TEmcDigi* emcDigiRoot = new TEmcDigi();
116 // m_common.m_emcDigiMap[(*emcDigiTds)] = emcDigiRoot;
117
118 emcDigiRoot->initialize( id, time, charge );
119 emcDigiRoot->setMeasure( measure );
120 emcDigiRoot->setTrackIndex( trackIndex );
121
122 recEvt->addEmcDigi( emcDigiRoot );
123 }
124
125 return StatusCode::SUCCESS;
126}
127#endif
Double_t time
ObjectVector< EmcDigi > EmcDigiCol
IMessageSvc * msgSvc()
EmcDigiCnv(ISvcLocator *svc)
virtual StatusCode DataObjectToTObject(DataObject *obj, RootAddress *addr)
transformation to root
virtual StatusCode TObjectToDataObject(DataObject *&obj)
transformation from root
void setMeasure(const unsigned int measure)
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)
void addEmcDigi(TEmcDigi *digi)
Add a TkrDigi into the TKR data collection.
void clearEmcDigiCol()
clear the whole array (necessary because of the consts-s)
const TObjArray * getEmcDigiCol() const
retrieve the whole TObjArray of TkrDigi Data
UInt_t getMeasure() const
Definition TEmcDigi.cxx:29
void setMeasure(const UInt_t measure)
Definition TEmcDigi.cxx:27
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