BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
HltInfCnv.cxx
Go to the documentation of this file.
1#ifndef HltInfCnv_CXX
2#define HltInfCnv_CXX 1
3
4#include "GaudiKernel/DataObject.h"
5#include "GaudiKernel/MsgStream.h"
6
7#include "TClonesArray.h"
8
9#include "EventModel/EventModel.h"
10#include "HltEvent/HltEvent.h" //TDS object
11#include "HltEvent/HltInf.h" //TDS object
12#include "Identifier/HltID.h"
13#include "RootCnvSvc/Hlt/HltCnv.h"
14#include "RootCnvSvc/Hlt/HltInfCnv.h"
15#include "RootCnvSvc/RootAddress.h"
16#include "RootEventData/THltEvent.h" // standard root object
17#include "RootEventData/THltInf.h" // standard root object
18
19// Instantiation of a static factory class used by clients to create
20// instances of this service
21
22HltInfCnv::HltInfCnv( ISvcLocator* svc ) : RootEventBaseCnv( classID(), svc ), m_old( false ) {
23 // Here we associate this converter with the /Event path on the TDS.
24 MsgStream log( msgSvc(), "HltInfCnv" );
25 // log << MSG::DEBUG << "Constructor called for " << objType() << endmsg;
26 m_rootBranchname = "m_hltInf";
27 // declareObject(EventModel::MC::HltInf, objType(), m_rootTreename, m_rootBranchname);
28 m_adresses.push_back( &m_hltInf );
29 m_hltInf = 0;
30}
31
32StatusCode HltInfCnv::TObjectToDataObject( DataObject*& refpObject ) {
33 // creation of TDS object from root object
34
35 MsgStream log( msgSvc(), "HltInfCnv" );
36 log << MSG::DEBUG << "HltInfCnv::TObjectToDataObject" << endmsg;
37 StatusCode sc = StatusCode::SUCCESS;
38
39 // create the TDS location for the trigger data
40 HltInf* hltInfTds = new HltInf;
41 refpObject = hltInfTds;
42
43 // now convert
44 if ( !m_hltInf ) return sc;
45
46 int evt = m_hltInf->getEventType();
47 int alg = m_hltInf->getAlgProcess();
48 int cri = m_hltInf->getCriteriaTable();
49 int ver = m_hltInf->getVersion();
50 float etot = m_hltInf->getTotalEnergy();
51 hltInfTds->setEventType( evt );
52 hltInfTds->setAlgProcess( alg );
53 hltInfTds->setCriteriaTable( cri );
54 hltInfTds->setVersion( ver );
55 hltInfTds->setTotalEnergy( etot );
56
57 try
58 {
59 uint32_t nsub = m_hltInf->getNumber();
60 uint32_t ncon = m_hltInf->getNCON();
61 uint32_t nmdc = nsub & 0XFF;
62 uint32_t ntof = ( nsub >> 8 ) & 0XFF;
63 uint32_t nemc = ( nsub >> 16 ) & 0XFF;
64 uint32_t nmuc = nsub >> 24;
65 if ( nmuc > HltID::getID_MUC_MAX() + 1 || nemc > HltID::getID_EMC_MAX() + 1 ||
66 ntof > HltID::getID_TOF_MAX() + 1 || nmdc > HltID::getID_MDC_MAX() + 1 )
67 { throw exception(); }
68 hltInfTds->setNumber( nsub );
69 hltInfTds->setNCON( ncon );
70
71 std::vector<Int_t> mdcRoot = m_hltInf->getMdcData();
72 if ( mdcRoot.size() != nmdc ) { throw exception(); }
73 std::vector<Int_t>::iterator it = mdcRoot.begin();
74 for ( ; it != mdcRoot.end(); it++ )
75 {
76 uint32_t data = *it;
77 hltInfTds->push_mdc( data );
78 }
79 std::vector<Int_t> tofRoot = m_hltInf->getTofData();
80 if ( tofRoot.size() != ntof ) { throw exception(); }
81 it = tofRoot.begin();
82 for ( ; it != tofRoot.end(); it++ )
83 {
84 uint32_t data = *it;
85 hltInfTds->push_tof( data );
86 }
87 std::vector<Int_t> emcRoot = m_hltInf->getEmcData();
88 if ( emcRoot.size() != nemc ) { throw exception(); }
89 it = emcRoot.begin();
90 for ( ; it != emcRoot.end(); it++ )
91 {
92 uint32_t data = *it;
93 hltInfTds->push_emc( data );
94 }
95 std::vector<Int_t> mucRoot = m_hltInf->getMucData();
96 if ( mucRoot.size() != nmuc ) { throw exception(); }
97 it = mucRoot.begin();
98 for ( ; it != mucRoot.end(); it++ )
99 {
100 uint32_t data = *it;
101 hltInfTds->push_muc( data );
102 }
103 std::vector<Int_t> conRoot = m_hltInf->getConData();
104 if ( conRoot.size() != ncon ) { throw exception(); }
105 it = conRoot.begin();
106 for ( ; it != conRoot.end(); it++ )
107 {
108 uint32_t data = *it;
109 hltInfTds->push_con( data );
110 }
111 } catch ( ... )
112 {
113 // log << MSG::ERROR << "***********************************************************" <<
114 // endmsg; log << MSG::ERROR << "Input ROOT object is older version, please reconstrut
115 // again" << endmsg; log << MSG::ERROR << " or check out old RootCnvSvc! (mailto:
116 // fucd@ihep.ac.cn)" << endmsg; log << MSG::WARNING << "***** Continuing run may cause a
117 // little memory leakage ****" << endmsg; m_old=true;
118 }
119
120 delete m_hltInf;
121 m_hltInf = 0;
122
123 return StatusCode::SUCCESS;
124}
125
126StatusCode HltInfCnv::DataObjectToTObject( DataObject* obj, RootAddress* rootaddr ) {
127
128 MsgStream log( msgSvc(), "HltInfCnv" );
129 log << MSG::DEBUG << "HltInfCnv::DataObjectToTObject" << endmsg;
130 StatusCode sc = StatusCode::SUCCESS;
131
132 HltInf* hltInfCnvTds = dynamic_cast<HltInf*>( obj );
133 if ( !hltInfCnvTds )
134 {
135 log << MSG::ERROR << "Could not downcast to HltInf" << endmsg;
136 return StatusCode::FAILURE;
137 }
138
139 DataObject* evt;
140 m_eds->findObject( EventModel::Hlt::Event, evt );
141 if ( evt == NULL )
142 {
143 log << MSG::ERROR << "Could not get HltInf in TDS " << endmsg;
144 return StatusCode::FAILURE;
145 }
146
147 HltEvent* devtTds = dynamic_cast<HltEvent*>( evt );
148 if ( !devtTds )
149 { log << MSG::ERROR << "HltInfCnv:Could not downcast to TDS HltInf" << endmsg; }
150
151 IOpaqueAddress* addr;
152 m_cnvSvc->getHltCnv()->createRep( evt, addr );
153
154 THltEvent* hltInf = m_cnvSvc->getHltCnv()->getWriteObject();
155
156 const TObject* tHltInf = hltInf->getHltInf();
157 if ( !tHltInf ) return sc;
158 hltInf->clearHltInf();
159
160 Int_t type = hltInfCnvTds->getEventType();
161 Int_t alg = hltInfCnvTds->getAlgProcess();
162 Int_t cri = hltInfCnvTds->getCriteriaTable();
163 Int_t ver = hltInfCnvTds->getVersion();
164 Double_t etot = hltInfCnvTds->getTotalEnergy();
165 Int_t nsub = hltInfCnvTds->getNumber();
166 Int_t ncon = hltInfCnvTds->getNCON();
167
168 THltInf* hltInfRoot = new THltInf();
169
170 hltInfRoot->setEventType( type );
171 hltInfRoot->setAlgProcess( alg );
172 hltInfRoot->setCriteriaTable( cri );
173 hltInfRoot->setVersion( ver );
174 hltInfRoot->setTotalEnergy( etot );
175 hltInfRoot->setNumber( nsub );
176 hltInfRoot->setNCON( ncon );
177
178 std::vector<uint32_t> mdcTds = hltInfCnvTds->getDataVec( HltID::MDC );
179 std::vector<Int_t> mdcRoot;
180 std::vector<uint32_t>::iterator it = mdcTds.begin();
181 for ( ; it != mdcTds.end(); it++ )
182 {
183 Int_t data = *it;
184 mdcRoot.push_back( data );
185 }
186 hltInfRoot->setMdcData( mdcRoot );
187
188 std::vector<uint32_t> tofTds = hltInfCnvTds->getDataVec( HltID::TOF );
189 std::vector<Int_t> tofRoot;
190 for ( it = tofTds.begin(); it != tofTds.end(); it++ )
191 {
192 Int_t data = *it;
193 tofRoot.push_back( data );
194 }
195 hltInfRoot->setTofData( tofRoot );
196
197 std::vector<uint32_t> emcTds = hltInfCnvTds->getDataVec( HltID::EMC );
198 std::vector<Int_t> emcRoot;
199 for ( it = emcTds.begin(); it != emcTds.end(); it++ )
200 {
201 Int_t data = *it;
202 emcRoot.push_back( data );
203 }
204 hltInfRoot->setEmcData( emcRoot );
205
206 std::vector<uint32_t> mucTds = hltInfCnvTds->getDataVec( HltID::MUC );
207 std::vector<Int_t> mucRoot;
208 for ( it = mucTds.begin(); it != mucTds.end(); it++ )
209 {
210 Int_t data = *it;
211 mucRoot.push_back( data );
212 }
213 hltInfRoot->setMucData( mucRoot );
214
215 std::vector<uint32_t> conTds = hltInfCnvTds->getDataVec( HltID::CON );
216 std::vector<Int_t> conRoot;
217 for ( it = conTds.begin(); it != conTds.end(); it++ )
218 {
219 Int_t data = *it;
220 conRoot.push_back( data );
221 }
222 hltInfRoot->setConData( conRoot );
223
224 hltInf->addHltInf( hltInfRoot );
225
226 return StatusCode::SUCCESS;
227}
228#endif
TTree * data
Double_t etot
IMessageSvc * msgSvc()
void setAlgProcess(const unsigned int i)
void setCriteriaTable(const unsigned int i)
void setNumber(const unsigned int i)
void setNCON(const unsigned int i)
void setEventType(const unsigned int i)
void setTotalEnergy(const float etot)
void setVersion(const unsigned int i)
HltInfCnv(ISvcLocator *svc)
Definition HltInfCnv.cxx:22
virtual StatusCode TObjectToDataObject(DataObject *&obj)
transformation from root
Definition HltInfCnv.cxx:32
virtual StatusCode DataObjectToTObject(DataObject *obj, RootAddress *addr)
transformation to root
virtual void push_muc(uint32_t data)
virtual void push_mdc(uint32_t data)
std::vector< uint32_t > & getDataVec(const Identifier &)
Definition HltInf.cxx:79
virtual void push_tof(uint32_t data)
virtual void push_con(uint32_t data)
virtual void push_emc(uint32_t data)
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 addHltInf(THltInf *hltInf)
Definition THltEvent.cxx:60
const THltInf * getHltInf() const
Definition THltEvent.cxx:61
void setMucData(const vector< Int_t > &vec)
void setMdcData(const vector< Int_t > &vec)
void setTofData(const vector< Int_t > &vec)
void setEmcData(const vector< Int_t > &vec)
void setConData(const vector< Int_t > &vec)