BOSS 7.1.2
BESIII Offline Software System
Loading...
Searching...
No Matches
MdcHvDropSvc Class Reference

#include <MdcHvDropSvc.h>

+ Inheritance diagram for MdcHvDropSvc:

Public Member Functions

 MdcHvDropSvc (const std::string &name, ISvcLocator *svcloc)
 
 ~MdcHvDropSvc ()
 
virtual StatusCode queryInterface (const InterfaceID &riid, void **ppvUnknown)
 
virtual StatusCode initialize ()
 
virtual StatusCode finalize ()
 
void handle (const Incident &)
 
virtual double queryRelativeHvDrop ()
 
virtual void setRelativeHvDropThreshold (double threshold)
 
virtual bool queryIsHvDrop ()
 
- Public Member Functions inherited from IMdcHvDropSvc

Additional Inherited Members

- Static Public Member Functions inherited from IMdcHvDropSvc
static const InterfaceID & interfaceID ()
 

Detailed Description

Definition at line 32 of file MdcHvDropSvc.h.

Constructor & Destructor Documentation

◆ MdcHvDropSvc()

MdcHvDropSvc::MdcHvDropSvc ( const std::string & name,
ISvcLocator * svcloc )

Definition at line 49 of file MdcHvDropSvc.cxx.

49 : Service(name, svcloc) {
50 // declare properties
51 declareProperty("Host", m_host = std::string("202.122.33.123"));
52 declareProperty("DbName", m_dbName = std::string("tof40t_linux"));
53 declareProperty("TableName", m_table = std::string("MDCLayerVmon"));
54 declareProperty("UserName", m_userName = std::string("guest"));
55 declareProperty("Password", m_password = std::string("guestpass"));
56 declareProperty("Port", m_port=6175);
57 declareProperty("IgnoreLayer_21_24",m_ignoreLayer_21_24=true);
58 declareProperty("RelativeHvDropThreshold",m_relativeHvDropThreshold=0.007);
59 declareProperty("FetchHvDataLengthInSeconds",m_fetchLength=5*3600);
60 declareProperty("UseEtsT1",m_useEtsT1=0); // whether to use EtsT1, if not, use time().
61 declareProperty("EtsT1OffSet",m_etsT1Offset=0);// if is 0, and UseEtsT1, will be treated as using database time from database..
62 // else, acts as calculating time_override=etsT1+etsT1Offset;
63
64 declareProperty("Host2", m_host2 = std::string("bes3db2.ihep.ac.cn"));
65 declareProperty("DbName2", m_dbName2 = std::string("run"));
66 declareProperty("TableName2", m_table2 = std::string("RunParams"));
67 declareProperty("UserName2", m_userName2 = std::string("guest"));
68 declareProperty("Password2", m_password2 = std::string("guestpass"));
69 declareProperty("Port2", m_port2=3306);//3306 is default port for mysql
70}

◆ ~MdcHvDropSvc()

MdcHvDropSvc::~MdcHvDropSvc ( )

Definition at line 72 of file MdcHvDropSvc.cxx.

72 {
73}

Member Function Documentation

◆ finalize()

StatusCode MdcHvDropSvc::finalize ( )
virtual

Definition at line 119 of file MdcHvDropSvc.cxx.

119 {
120 MsgStream log(messageService(), name());
121 log << MSG::INFO << "MdcHvDropSvc::finalize()" << endreq;
122 // if(m_connect_offline) delete m_connect_offline;
123 return StatusCode::SUCCESS;
124}

◆ handle()

void MdcHvDropSvc::handle ( const Incident & inc)

Definition at line 126 of file MdcHvDropSvc.cxx.

126 {
127 MsgStream log(messageService(), name());
128 log << MSG::DEBUG << "handle: " << inc.type() << endreq;
129 // so currently we do nothing.
130 //if (inc.type() == "NewRun") {
131 // log << MSG::DEBUG << "NewRun" << endreq;
132 //
133 // SmartDataPtr<Event::EventHeader> eventHeader(m_eventSvc, "/Event/EventHeader");
134 // int run = eventHeader->runNumber();
135 // //cout<<"&&&&&&&&&&&&&&:&&&&&&&&&&&&&&&&&&&& MdcHvDropSvc handle,run="<<run<<endl;
136 // if (run < 0) run = -run;
137 // log << MSG::DEBUG << "handle: "
138 // << "Run in handle is: " << run << endreq;
139 // cout << "-------------in MdcHvDropSvc in the following-----------" << endl;
140 // cout << "handle: "
141 // << "Run in handle is: " << run << endl;
142
143 //if (run >= m_RunFrom && run <= m_RunTo && m_ReadPar == true) {
144 // cout << "do not read the database repeatly in EmcShEnCalibConst" << endl;
145 // cout << "run,RunFrom,runTo=" << run << "," << m_RunFrom << "," << m_RunTo << endl;
146 //} else {
147 //
148 // //cout<<"read the database in EmcShEnCalibConst"<<endl;
149 // if (!getMdcHvDropSvcInfo()) {
150 // log << MSG::ERROR << "can not initilize Shower energy Calib Constants" << endreq;
151 // } else {
152 // m_ReadPar = true;
153 // std::cout << "in handle of MdcHvDropSvc getPi0CalibFile()= " << getPi0CalibFile() << std::endl;
154 // std::cout << "getSingleGammaCalibFile()= " << getSingleGammaCalibFile() << std::endl;
155 // }
156 //}
157 //}
158}

◆ initialize()

StatusCode MdcHvDropSvc::initialize ( )
virtual

Definition at line 84 of file MdcHvDropSvc.cxx.

84 {
85 MsgStream log(messageService(), name());
86 log << MSG::INFO << "MdcHvDropSvc::initialize()" << endreq;
87
88 StatusCode sc = Service::initialize();
89 if (sc.isFailure()) return sc;
90
91 IIncidentSvc *incsvc;
92 sc = service("IncidentSvc", incsvc);
93 int priority = 100;
94 if (sc.isSuccess()) {
95 incsvc->addListener(this, "NewRun", priority);
96 }
97
98 //sc = serviceLocator()->service("DatabaseSvc", m_dbsvc, true);
99 //if (sc.isFailure()) {
100 // log << MSG::ERROR << "Unable to find DatabaseSvc " << endreq;
101 // return sc;
102 //}
103//
104 sc = serviceLocator()->service("EventDataSvc", m_eventSvc, true);
105 if (sc.isFailure()) {
106 log << MSG::ERROR << "Unable to find EventDataSvc " << endreq;
107 return sc;
108 }
109
110 sc = initMySql();
111 if (sc.isFailure()){
112 log << MSG::ERROR << "Unable to initialize mysql " << endreq;
113 return sc;
114 }
115
116 return StatusCode::SUCCESS;
117}

◆ queryInterface()

StatusCode MdcHvDropSvc::queryInterface ( const InterfaceID & riid,
void ** ppvUnknown )
virtual

Definition at line 75 of file MdcHvDropSvc.cxx.

75 {
76 if (IID_IMdcHvDropSvc.versionMatch(riid)) {
77 *ppvInterface = static_cast<IMdcHvDropSvc *>(this);
78 } else {
79 return Service::queryInterface(riid, ppvInterface);
80 }
81 return StatusCode::SUCCESS;
82}

◆ queryIsHvDrop()

virtual bool MdcHvDropSvc::queryIsHvDrop ( )
inlinevirtual

Implements IMdcHvDropSvc.

Definition at line 53 of file MdcHvDropSvc.h.

53 {
54 return queryRelativeHvDrop() >= m_relativeHvDropThreshold;
55 }
virtual double queryRelativeHvDrop()

◆ queryRelativeHvDrop()

double MdcHvDropSvc::queryRelativeHvDrop ( )
virtual

Implements IMdcHvDropSvc.

Definition at line 413 of file MdcHvDropSvc.cxx.

413 {
414 MsgStream log(messageService(), name());
415 //log << MSG::DEBUG << "MdcHvDropSvc::sqlRow2Item()" << endreq;
416 SmartDataPtr<Event::EventHeader> eventHeader(m_eventSvc, "/Event/EventHeader");
417 Time_t time = eventHeader->time();
418 Time_t fetchBeginTime = time;
419 int run = eventHeader->runNumber();
420 unsigned long time_etsT1=eventHeader->etsT1();
421 long time_etsT1_timelike32=((time_etsT1/2000000)&0x00000000ffffffffLU);
422
423 // handle etsT1 logic
424 // declareProperty("UseEtsT1",m_useEtsT1=0); // whether to use EtsT1, if not, use time().
425 //declareProperty("EtsT1OffSet",m_etsT1Offset=0);// if is 0, and UseEtsT1, will be treated as using database time from database..
426 //else, acts as calculating time_override=etsT1+etsT1Offset;
427
428 if(m_useEtsT1){
429
430 if(m_etsT1Offset==0){
431
432 time=time_etsT1_timelike32+getRunBeginTime(run);
433 }
434 else{
435 time=time_etsT1_timelike32+m_etsT1Offset;
436 }
437 }
438
439
440
441 if (run < 0) return 0; // a MC event.
442
443 log << MSG::INFO << "query time " << time << endreq;
444 log << MSG::INFO << "current boundary " << m_vData.getLowerBoundaryEventTime() << " : " << m_vData.getUpperBoundaryEventTime() << endreq;
445
446 if (m_vData.getUpperBoundaryEventTime() < time || time < m_vData.getLowerBoundaryEventTime()) { // not in cache
447 // 1st time.
448 if (m_vData.size() == 0) {
449 char time1str[100];
450 Time_t2str(time, time1str, 100);
451 log << MSG::INFO << "INFO: MdcHvDropSvc time " << time << " aka " << time1str << " is not in cache yet.\n"
452 << "\tfetching HV info for 1h ago" << time - 3600 << " til fetch Length" << time + m_fetchLength - 3600 << endreq;
453 fetchBeginTime = time - 3600;
454 }
455 // 2nd time
456 else {
457 Time_t upTimeCachedDBTime = m_vData.getUpperBoundaryEventTime() + m_vData.getOffsetEvt2Db();
458 char time1str[100];
459 Time_t2str(time, time1str, 100);
460 // time in another fetch interval, thus we choose to fetch new data and append to cache
461 if (m_vData.getLowerBoundaryEventTime() < time && time < m_vData.getUpperBoundaryEventTime() + m_fetchLength) {
462
463 log << MSG::INFO << "INFO:MdcHvDropSvc time " << time << " aka " << time1str << " is not in cache yet.\n"
464 << "\tcurrent upperBoundary is " << m_vData.getUpperBoundaryEventTime() << "\n"
465 << "\tfetching HV info for dbTime " << upTimeCachedDBTime << " to fetch Length later" << upTimeCachedDBTime + m_fetchLength << endreq;
466 fetchBeginTime = upTimeCachedDBTime;
467 }
468 //time not in another fetch interval, and we cannot find a interval to append to cache.
469 else {
470 log << MSG::INFO << "INFO:MdcHvDropSvc time " << time << " aka " << time1str << " is not in cache or canbe fetched in a interval.\n"
471 << "\tcurrent cache boundary is " << m_vData.getLowerBoundaryEventTime() << ":" << m_vData.getUpperBoundaryEventTime() << ".\n"
472 << "\tcurrent fetch interval is " << m_vData.getUpperBoundaryEventTime() << ":" << m_vData.getUpperBoundaryEventTime() + m_fetchLength << endreq;
473 log << MSG::INFO << "aborted cache and fetching new data.\n"
474 << "\tfetching HV info for 1h ago" << time - 3600 << " til fetch Length" << time + m_fetchLength - 3600 << endreq;
475 m_vData.clear();
476 fetchBeginTime = time - 3600;
477 }
478 }
479
480 fetchBeginTime += m_vData.getOffsetEvt2Db(); // now db time
481 Time_t time2 = fetchBeginTime + m_fetchLength;
482 if (!FetchHvInfo(fetchBeginTime - 600, time2) == StatusCode::SUCCESS) {
483 cout << "ERROR: MdcHvDropSvc failed to fetch HV info\n";
484 return -10000;
485 }
486 }
487 if (!m_vData.isValid(time))
488 return -9999;
489 if (m_ignoreLayer_21_24)
490 return m_vData.getAvgDropButVeryDrop(time);
491 else
492 return m_vData.getAvgDrop(time);
493}
Double_t time
long Time_t
Definition VData.h:31
bool isValid(Time_t time) const
Definition VData.cxx:17
double getAvgDrop(Time_t time)
Definition VData.cxx:89
Time_t getUpperBoundaryEventTime()
Definition VData.h:55
double getAvgDropButVeryDrop(Time_t time)
Definition VData.cxx:95
Time_t getLowerBoundaryEventTime()
Definition VData.h:56
void clear()
throw all cached data. next time you might have to prepare cache again..
Definition VData.cxx:73
double getOffsetEvt2Db()
Definition VData.h:64
size_t size()
Definition VData.h:54

Referenced by queryIsHvDrop().

◆ setRelativeHvDropThreshold()

virtual void MdcHvDropSvc::setRelativeHvDropThreshold ( double threshold)
inlinevirtual

Implements IMdcHvDropSvc.

Definition at line 52 of file MdcHvDropSvc.h.

52{ m_relativeHvDropThreshold=threshold;};

The documentation for this class was generated from the following files: