BOSS 7.1.2
BESIII Offline Software System
Loading...
Searching...
No Matches
RawDataEvtHeaderCnv.cxx
Go to the documentation of this file.
1#include "GaudiKernel/MsgStream.h"
2// for Mutil-thread by tianhl
3#include "GaudiKernel/ThreadGaudi.h"
4// for Mutil-thread by tianhl
5
13
14extern const CLID& CLID_EventHeader;
15
16static OfflineRevise* _localRevisor = NULL;
17static int _localTimeRound = 0;
18
21{
22 // for Mutil-thread by tianhl
23 //init();
24 // for Mutil-thread by tianhl
25}
26
28{
29 StatusCode sc = RawDataBaseCnv::initialize();
30 if ( sc.isFailure() ) return sc;
31
32 std::string PackedRawDataCnvSvc_Name("PackedRawDataCnvSvc");
33 std::string RawDataInputSvc_Name("RawDataInputSvc");
34 std::string RawDataEvtHeaderCnv_Name("RawDataEvtHeaderCnv");
35
36 // for Mutil-thread by tianhl
37 //ConversionSvc* pCnvSvc = 0;
38 //if (pCnvSvc = dynamic_cast<ConversionSvc*>(conversionSvc())){
39 SmartIF<IService> pCnvSvc(conversionSvc());
40 if (isGaudiThreaded(pCnvSvc->name())){
41 PackedRawDataCnvSvc_Name += getGaudiThreadIDfromName(pCnvSvc->name());
42 RawDataInputSvc_Name += getGaudiThreadIDfromName(pCnvSvc->name());
43 RawDataEvtHeaderCnv_Name += getGaudiThreadIDfromName(pCnvSvc->name());
44 }
45 //}
46 // for Mutil-thread by tianhl
47 MsgStream log(messageService(), RawDataEvtHeaderCnv_Name.c_str());
48
49 IService* svc = 0;
50 sc = serviceLocator()->service(PackedRawDataCnvSvc_Name.c_str(), svc);
51 if ( sc.isFailure() ) {
52 log << MSG::ERROR << "Can't get RawDataAccess interface" << endreq;
53 return StatusCode::FAILURE;
54 }
55
56 m_RawDataAccess = dynamic_cast<PackedRawDataCnvSvc*> (svc);
57 if (m_RawDataAccess == 0 ) {
58 log << MSG::ERROR << "RawDataEvtHeaderCnv: Cant cast to RawDataCnvSvc" << endreq;
59 return StatusCode::FAILURE;
60 }
61
62 sc = serviceLocator()->getService(RawDataInputSvc_Name.c_str(), svc);
63 if ( sc.isFailure() ) {
64 log << MSG::WARNING << "Cant get RawDataInputSvc " << endreq;
65 return sc ;
66 }
67
68 m_inputSvc = dynamic_cast<RawDataInputSvc*> (svc);
69 if ( m_inputSvc == 0 ) {
70 log << MSG::ERROR << "Cant cast to RawDataInputSvc" << endreq;
71 return StatusCode::FAILURE ;
72 }
73
74 _localRevisor = dynamic_cast<RawDataInputSvc*>(m_inputSvc)->offlineRevisor();
75
76 return StatusCode::SUCCESS;
77}
78
80{
81 return CLID_EventHeader;
82}
83
84StatusCode RawDataEvtHeaderCnv::updateObj(IOpaqueAddress* pAddr, DataObject* pObj) {
85 //MsgStream log(msgSvc(), "RawDataEvtHeaderCnv");
86 //log << MSG::DEBUG << "RawDataEvtHeaderCnv::updateObj" << endreq;
87 return Converter::updateObj(pAddr, pObj);
88}
89
90// Create a converted object in the Transient Data Store.
91StatusCode RawDataEvtHeaderCnv::createObj(IOpaqueAddress* pAddr, DataObject*& pObj)
92{
93 StatusCode sc;
94 RawDataAddress *pEFAddr;
95 const RAWEVENT *evt;
96
98 pObj = header;
99
100 //if ( (pEFAddr = dynamic_cast<RawDataAddress*>(pAddr)) ) {
101 evt = m_inputSvc->currentEvent();
102
103 if (evt == NULL) return StatusCode::FAILURE;
104
105 header->setEventNumber(evt->eventHeader().event_number());
106 header->setRunNumber(evt->eventHeader().run_number());
107 header->setTime(evt->eventHeader().time());
108 header->setFlag1( evt->eventHeader().flag1() );
109 //header->setFlag2( evt->eventHeader().flag2() );
110
111 const BufferHolder& rBuf = evt->getEtsBuf();
112 if ( rBuf.nBuf() == 1 ) { // this event has ETS data
113 uint32_t dataLen = rBuf.bufSize(0);
114 uint32_t * dataPtr = rBuf(0);
115 //{ // debug
116 // std::cout << "[ETS]: " << std::hex;
117 // for ( uint32_t i = 0; i < dataLen; ++i ) {
118 // std::cout << " 0x" << std::setw(8) << std::setfill('0') << dataPtr[i];
119 // }
120 // std::cout << std::dec << std::endl;
121 //}
122 // check
123 if ( dataLen > 11 && dataPtr[1] == 0xffffffff ) {
124 uint32_t start = 10;
125 if ( (dataPtr[start] >> 24) == 0xcf ) {
126 _localTimeRound = _localRevisor->timeRound(header->runNumber());
127
128 unsigned long t1 = calEts( dataPtr + start );
129 header->setEtsT1(t1);
130
131 static unsigned long t2 = 0;
132 if ( (start+3) < dataLen && dataPtr[start+2] != 0xf0f0f0f0 ) {
133 if ((dataPtr[start+2]>>24) == 0xd1 ) {
134 t2 = calEts( dataPtr + start + 2 );
135 }
136 else {
137 uint32_t _dataT2[2] = {dataPtr[10], dataPtr[12]};
138 unsigned long _t2 = calEts( _dataT2 );
139 if ( labs(_t2-t2) < 150/*ms*/*2000 ) {
140 t2 = _t2;
141 }
142 else if ( labs(_t2-2000000-t2) < 150*2000 ) {
143 t2 = _t2 - 2000000;
144 }
145 else if ( labs(_t2+2000000-t2) < 150*2000 ) {
146 t2 = _t2 + 2000000;
147 }
148 }
149 }
150 header->setEtsT2(t2);
151
152 //do not revise ets here, move to ResetEtsAlg
153 //_localRevisor->fixHeader(header);
154
155 //if ( header->etsT1() != t1 || header->etsT2() != t2 )
156 //{
157 // std::cout << "event " << header->eventNumber()
158 // << " time " << header->time()
159 // << " new t1 " << header->etsT1()
160 // << " old t1 " << t1
161 // << " new t2 " << header->etsT2()
162 // << " old t2 " << t2
163 // << std::endl;
164 //}
165 }
166 }
167 }
168
169 return StatusCode::SUCCESS;
170 //}
171 //else {
172 // return StatusCode::FAILURE;
173 //}
174
175}
176
177unsigned long RawDataEvtHeaderCnv::calEts(uint32_t* dptr)
178{
179 unsigned int tmp = dptr[0] & 0xffffff;
180 //std::cout << _localTimeRound << " for " << (tmp>>16) << ":" << ((tmp>>8)&0xff) << ":" << (tmp&0xff) << std::endl;
181 unsigned long val = (tmp >> 16 ) * _localTimeRound * _localTimeRound;
182 val += ((tmp >> 8) & 0xff) * _localTimeRound;
183 val += tmp & 0xff;
184 val *= 2000000; // s -> 500ns
185 val += (dptr[1] & 0x3fffff);
186
187 return val;
188}
unsigned const long PACKEDRAWEVENT_StorageType
const CLID & CLID_EventHeader
const CLID & CLID_EventHeader
#define NULL
uint32_t nBuf() const
uint32_t bufSize(int i) const
void setRunNumber(int value)
Update run number.
Definition EventHeader.h:44
void setTime(int value)
Definition EventHeader.h:48
void setFlag1(unsigned int value)
Update flags.
Definition EventHeader.h:59
int runNumber() const
Retrieve run number.
Definition EventHeader.h:42
void setEventNumber(int value)
Update event number.
Definition EventHeader.h:39
void setEtsT2(unsigned long value)
Definition EventHeader.h:71
void setEtsT1(unsigned long value)
Update ETS.
Definition EventHeader.h:69
virtual RAWEVENT * currentEvent()=0
int timeRound(int run)
uint32_t flag1() const
Definition RAWEVENT.h:26
uint32_t run_number() const
Definition RAWEVENT.h:22
uint32_t event_number() const
Definition RAWEVENT.h:23
uint32_t time() const
Definition RAWEVENT.h:24
const BufferHolder & getEtsBuf() const
Definition RAWEVENT.h:103
const RawEventHeader & eventHeader() const
Definition RAWEVENT.h:93
StatusCode initialize()
RawDataEvtHeaderCnv(ISvcLocator *svc)
StatusCode createObj(IOpaqueAddress *pAddr, DataObject *&pObj)
virtual StatusCode updateObj(IOpaqueAddress *, DataObject *)
override the RawDataBaseCnv version
static const CLID & classID()