BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
HltRawCnv.cxx
Go to the documentation of this file.
1#ifndef HltRawCnv_CXX
2#define HltRawCnv_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 "HltEvent/HltEvent.h" //TDS object
12#include "HltEvent/HltRaw.h" //TDS object
13#include "RootCnvSvc/Hlt/HltCnv.h"
14#include "RootCnvSvc/Hlt/HltRawCnv.h"
15#include "RootCnvSvc/RootAddress.h"
16#include "RootEventData/THltEvent.h"
17#include "RootEventData/THltRaw.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<HltRawCnv> s_factory;
22// const ICnvFactory& HltRawCnvFactory = s_factory;
23
24HltRawCnv::HltRawCnv( ISvcLocator* svc ) : RootEventBaseCnv( classID(), svc ) {
25 // Here we associate this converter with the /Event path on the TDS.
26 MsgStream log( msgSvc(), "HltRawCnv" );
27 // log << MSG::DEBUG << "Constructor called for " << objType() << endmsg;
28 m_rootBranchname = "m_hltRawCol";
29 // declareObject(EventModel::Hlt::HltRawCol, objType(), m_rootTreename, m_rootBranchname);
30 m_adresses.push_back( &m_hltRawCol );
31 m_hltRawCol = 0;
32}
33
34StatusCode HltRawCnv::TObjectToDataObject( DataObject*& refpObject ) {
35 // creation of TDS object from root object
36
37 MsgStream log( msgSvc(), "HltRawCnv" );
38 log << MSG::DEBUG << "HltRawCnv::TObjectToDataObject" << endmsg;
39 StatusCode sc = StatusCode::SUCCESS;
40
41 // create the TDS location for the HltRaw Collection
42 HltRawCol* hltRawTdsCol = new HltRawCol;
43 refpObject = hltRawTdsCol;
44 // sc = m_eds->registerObject(EventModel::Hlt::HltRawCol, hltRawTdsCol);
45 // if (sc.isFailure()) {
46 // log << "Failed to register HltRaw Collection" << endmsg;
47 // return StatusCode::FAILURE;
48 // }
49
50 // now convert
51 if ( !m_hltRawCol ) return sc;
52 TIter hltRawIter( m_hltRawCol );
53 THltRaw* hltRawRoot = 0;
54 while ( ( hltRawRoot = (THltRaw*)hltRawIter.Next() ) )
55 {
56 unsigned int id = hltRawRoot->getIntId();
57 unsigned int time = hltRawRoot->getTimeChannel();
58 unsigned int charge = hltRawRoot->getChargeChannel();
59
60 HltRaw* hltRawTds = new HltRaw( id );
61 m_common.m_rootHltRawMap[hltRawRoot] = hltRawTds;
62
63 hltRawTds->setTimeChannel( time );
64 hltRawTds->setChargeChannel( charge );
65
66 hltRawTdsCol->push_back( hltRawTds );
67 }
68 // m_hltRawCol->Delete(); // wensp add 2005/12/30
69 delete m_hltRawCol;
70 m_hltRawCol = 0;
71 return StatusCode::SUCCESS;
72}
73
74StatusCode HltRawCnv::DataObjectToTObject( DataObject* obj, RootAddress* rootaddr ) {
75
76 MsgStream log( msgSvc(), "HltRawCnv" );
77 log << MSG::DEBUG << "HltRawCnv::DataObjectToTObject" << endmsg;
78 StatusCode sc = StatusCode::SUCCESS;
79
80 HltRawCol* hltRawColTds = dynamic_cast<HltRawCol*>( obj );
81 if ( !hltRawColTds )
82 {
83 log << MSG::ERROR << "Could not downcast to HltRawCol" << endmsg;
84 return StatusCode::FAILURE;
85 }
86
87 DataObject* evt;
88 m_eds->findObject( EventModel::Hlt::Event, evt );
89 if ( evt == NULL )
90 {
91 log << MSG::ERROR << "Could not get HltEvent in TDS " << endmsg;
92 return StatusCode::FAILURE;
93 }
94 HltEvent* devtTds = dynamic_cast<HltEvent*>( evt );
95 if ( !devtTds )
96 { log << MSG::ERROR << "HltRawCnv:Could not downcast to TDS HltEvent" << endmsg; }
97
98 IOpaqueAddress* addr;
99
100 m_cnvSvc->getHltCnv()->createRep( evt, addr );
101
102 // createRep(evt,addr);
103
104 THltEvent* recEvt = m_cnvSvc->getHltCnv()->getWriteObject();
105
106 const TObjArray* m_hltRawCol = recEvt->getHltRawCol();
107 if ( !m_hltRawCol ) return sc;
108 recEvt->clearHltRawCol(); // necessary in case there is I/O at the same time since array is
109 // static
110 HltRawCol::const_iterator hltRawTds;
111
112 for ( hltRawTds = hltRawColTds->begin(); hltRawTds != hltRawColTds->end(); hltRawTds++ )
113 {
114 UInt_t time = ( *hltRawTds )->getTimeChannel();
115 UInt_t charge = ( *hltRawTds )->getChargeChannel();
116 UInt_t id = ( *hltRawTds )->getIntId();
117
118 THltRaw* hltRawRoot = new THltRaw();
119 // m_common.m_hltRawMap[(*hltRawTds)] = hltRawRoot;
120
121 hltRawRoot->initialize( id, time, charge );
122 recEvt->addHltRaw( hltRawRoot );
123 }
124
125 return StatusCode::SUCCESS;
126}
127
128#endif
Double_t time
ObjectVector< HltRaw > HltRawCol
IMessageSvc * msgSvc()
HltRawCnv(ISvcLocator *svc)
Definition HltRawCnv.cxx:24
virtual StatusCode DataObjectToTObject(DataObject *obj, RootAddress *addr)
transformation to root
Definition HltRawCnv.cxx:74
virtual StatusCode TObjectToDataObject(DataObject *&obj)
transformation from root
Definition HltRawCnv.cxx:34
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 * getHltRawCol() const
Definition THltEvent.cxx:59
void addHltRaw(THltRaw *hltRaw)
HltRaw.
Definition THltEvent.cxx:54
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
UInt_t getChargeChannel() const
Definition TRawData.cxx:48
UInt_t getTimeChannel() const
Definition TRawData.cxx:45