BOSS 7.1.2
BESIII Offline Software System
Loading...
Searching...
No Matches
VData.cxx
Go to the documentation of this file.
1/**
2 * @file VData.cxx
3 * @author zhangzeheng ([email protected])
4 * @brief provides definitions of functions to handle our cached hv info.
5 * @version 0.1
6 * @date 2022-01-19
7 *
8 * @copyright Copyright (c) 2022
9 *
10 */
11
12#include <MdcHvDropSvc/VData.h>
13#include <algorithm>
14#include <iostream>
15//#include "GaudiKernel/MsgStream.h"
16
18 time+=time_offset;
19 if (time > Boundary_time_High || time < Boundary_time_Low) {
20 return false;
21 }
22 std::vector<Time_t>::const_iterator iter = std::upper_bound(timeVector.begin(), timeVector.end(), time);
23 int index2 = iter - timeVector.begin();
24 Time_t time2 = timeVector[index2], time1 = timeVector[index2 - 1];
25 if (abs(time - time2) > 10 && abs(time - time1) > 10){
26 return false;
27 }
28 return true;
29}
30
32 VDataItem voltage;
33 time+=time_offset;
34 if (time > Boundary_time_High || time < Boundary_time_Low) {
35 //MsgStream log(messageService(), name());
36 //log << MSG::INFO << "MdcHvDropSvc::initialize()" << endreq;
37 std::cerr << "Error! time exceeds boundary. up:down"<<getUpperBoundaryEventTime()<<":"<<getLowerBoundaryEventTime()<<std::endl;
38 std::cerr<< "this should not happen. check your code that matters with VData"<<std::endl;
39 //if (Boundary_time_High==Boundary_time_Low && Boundary_time_Low==0){
40 // std::cerr << "you need to call updateBoundary() after inserting items.";
41 //}
42 //std::cerr << std::endl;
43 return voltage;
44 }
45 std::vector<Time_t>::iterator iter = std::upper_bound(timeVector.begin(), timeVector.end(), time);
46 int index2 = iter - timeVector.begin();
47 Time_t time2 = timeVector[index2], time1 = timeVector[index2 - 1];
48
49 VDataItem &voltage2 = VdataVector[index2], &voltage1 = VdataVector[index2 - 1];
50 for (size_t i = 0; i < voltage.size(); i++) {
51 voltage[i] = voltage1[i] + ((double)(time - time1)) / (time2 - time1) * (voltage2[i] - voltage1[i]);
52 }
53 return voltage;
54}
56 double a[]={
57 1871.65, 1988.291667, 2016.875, 2017.791667, 2044.25, 2029.25, 2016.75, 1986.5, 2111, 2199,
58 2187.5, 2226, 2214.75, 2233, 2216, 2222.75, 2199.5, 2217.75, 2189.25, 2142.75,
59 2119.5, 2192.25, 2209.5, 2218, 2201, 2211.25, 2227, 2226, 2186.25, 2201.5,
60 2217, 2211.5, 2177, 2191.25, 2192.25, 2135.75, 2133.25, 2200.75, 2218.75, 2204.25,
61 2137.5, 2139.75, 2059.5,
62 };
63 voltagesStd=VDataItem::fromArray(a);
64 time_offset=6;
65 Boundary_time_High=0;
66 Boundary_time_Low=0;
67}
68
69/**
70 * @brief throw all cached data. next time you might have to prepare cache again..
71 *
72 */
74 Boundary_time_High=0;
75 Boundary_time_Low=0;
76 timeVector.clear();
77 VdataVector.clear();
78}
79
80
82 VDataItem voltTripPerc;
83 VDataItem voltage=getVoltage(time);
84 for (size_t i=0; i<voltage.size(); i++){
85 voltTripPerc[i]=(voltagesStd[i]-voltage[i])/voltagesStd[i];
86 }
87 return voltTripPerc;
88}
90 VDataItem voltTripPerc=getDrop(time);
91 double totalDropPerc=0;
92 for (size_t i=0; i<voltTripPerc.size(); i++) totalDropPerc+=voltTripPerc[i];
93 return totalDropPerc/voltTripPerc.size();
94}
96 VDataItem voltTripPerc=getDrop(time);
97 double totalDropPerc=0;
98 for (size_t i=0; i<20; i++) totalDropPerc+=voltTripPerc[i];
99 for (size_t i=25-1; i<voltTripPerc.size(); i++) totalDropPerc+=voltTripPerc[i];
100
101 return totalDropPerc/(voltTripPerc.size()-4);
102}
103/**
104 * @brief add a entry to our cache. the entry has to be pushed back in ascending order,
105 * with no gap. inserting a item that is within timeboundary will fail and do nothing.
106 *
107 * @param time_HV_SLOWCTRL a time in database time; not event time
108 * @param data
109 */
110void VData::push_back_sorted(Time_t time_HV_SLOWCTRL, const VDataItem &data) {
111 if (time_HV_SLOWCTRL <= Boundary_time_High){ // first check if time is in boundary
112 // std::vector<Time_t>::iterator iter = std::upper_bound(timeVector.begin(), timeVector.end(), time_HV_SLOWCTRL);
113 // if (! (iter == timeVector.end())) {return;} //if found time in vector
114 return;
115 }
116 timeVector.push_back(time_HV_SLOWCTRL);
117 VdataVector.push_back(data);
119}
120
121VDataItem VDataItem::fromArray(const double* item){
122 VDataItem out;
123 for (size_t i=0; i<VDataItem::size(); i++){
124 out[i]=item[i];
125 }
126 return out;
127}
128
TTree * data
Double_t time
EvtStreamInputIterator< typename Generator::result_type > iter(Generator gen, int N=0)
class defination for our cached hv info.
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
void push_back_sorted(Time_t time_HV_SLOWCTRL, const VDataItem &data)
add a entry to our cache. the entry has to be pushed back in ascending order, with no gap....
Definition VData.cxx:110
double getAvgDropButVeryDrop(Time_t time)
Definition VData.cxx:95
VDataItem getVoltage(Time_t time)
Definition VData.cxx:31
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
void updateBoundary()
Definition VData.h:48
VDataItem getDrop(Time_t time)
Definition VData.cxx:81
VData()
Definition VData.cxx:55
static VDataItem fromArray(const double *item)
Definition VData.cxx:121
static size_t size()
Definition VData.h:23