BOSS 7.1.1
BESIII Offline Software System
Loading...
Searching...
No Matches
OfflineRevise.cxx
Go to the documentation of this file.
3#include <fstream>
4#include <iostream>
5
7 : m_lastRun(-1),
8 m_lastFlag(true)
9{
10 const SniperJSON& c1 = json["Ets1MissingSecond"];
11 for (SniperJSON::vec_iterator it = c1["RunRanges"].vec_begin();
12 it != c1["RunRanges"].vec_end();
13 ++it)
14 {
15 m_runRanges.push_back(std::make_pair(
16 (*it)["From"].get<int>(),
17 (*it)["To"].get<int>() ));
18 }
19
20 m_runs = c1["Runs"].get<std::vector<int> >();
21
22 //for ( std::vector<std::pair<int, int> >::iterator it = m_runRanges.begin();
23 // it != m_runRanges.end(); ++it) {
24 // std::cout << "RunRange: " << it->first << ", " << it->second << std::endl;
25 //}
26 //for (std::vector<int>::iterator it = m_runs.begin();
27 // it != m_runs.end(); ++it) {
28 // std::cout << "Run: " << *it << std::endl;
29 //}
30
31 m_tRoundSwitch = json["TimeRoundSwitch"].get<int>();
32}
33
37
39{
40 bool goodFlag = true;
41 int run = header->runNumber();
42
43 if ( run == m_lastRun ) {
44 goodFlag = m_lastFlag;
45 }
46 else {
47 for ( std::vector<std::pair<int, int> >::iterator it = m_runRanges.begin();
48 it != m_runRanges.end();
49 ++it)
50 {
51 if ( run >= it->first && run <= it->second ) {
52 goodFlag = false;
53 break;
54 }
55 }
56
57 if ( goodFlag && std::find(m_runs.begin(), m_runs.end(), run) != m_runs.end() ) {
58 goodFlag = false;
59 }
60
61 m_lastFlag = goodFlag;
62 m_lastRun = run;
63 m_lastEvent = header->eventNumber();
64 m_t0Sec = header->time();
65 m_t0NanoShift0 = -1;
66 m_t0NanoShift1 = -1;
67 m_lastEts1 = 0;
68 m_lastEts2Old = 0;
69 m_lastEts2New = 0;
70 }
71
72 if ( ! goodFlag ) {
73 fixEts1(header);
74 fixEts2(header);
75 }
76}
77
78void OfflineRevise::fixEts1(Event::EventHeader* header)
79{
80 long tNow = header->time() - m_t0Sec;
81 unsigned long _ets1 = header->etsT1();
82 long ets1NanoSec = _ets1 % 2000000;
83
84 if ( tNow == 0 ) {
85 long _shift0 = ets1NanoSec % 2000000;
86 if ( _shift0 > m_t0NanoShift0 ) {
87 m_t0NanoShift0 = _shift0;
88 }
89 }
90 else if ( tNow == 1 ) {
91 if ( m_t0NanoShift1 == -1 ) {
92 if ( ets1NanoSec > m_t0NanoShift0 ) {
93 m_t0NanoShift1 = ets1NanoSec;
94 //std::cout << "Shift " << m_t0NanoShift0 << " " << m_t0NanoShift1 << std::endl;
95 }
96 }
97 }
98
99 if ( m_t0NanoShift1 > 0 && ets1NanoSec >= m_t0NanoShift1 ) {
100 --tNow;
101 }
102
103 unsigned long ets1 = tNow*2000000 + ets1NanoSec;
104
105 int evtDiff = header->eventNumber() - m_lastEvent;
106
107 if ( labs(ets1-m_lastEts1) < 1000000 && abs(evtDiff) < 100 ) {
108 //m_lastEts1 = ets1;
109 }
110 else {
111 if ( ets1NanoSec > m_t0NanoShift0-200000 ) {
112 long tDiff = ets1NanoSec - m_lastEts1%2000000;
113 if ( tDiff > 1000000 ) {
114 if ( evtDiff < 100 ) {
115 tNow = m_lastEts1/2000000 - 1;
116 }
117 }
118 else if ( tDiff < -1000000 ) {
119 if ( evtDiff > 100 ) {
120 tNow = m_lastEts1/2000000 + 1;
121 }
122 }
123 else {
124 tNow = m_lastEts1/2000000;
125 }
126 ets1 = tNow*2000000 + ets1NanoSec;
127 }
128 }
129
130 header->setEtsT1(ets1);
131 m_lastEvent = header->eventNumber();
132 if ( abs(evtDiff) < 100 ) {
133 m_lastEts1 = ets1;
134 }
135}
136
137void OfflineRevise::fixEts2(Event::EventHeader* header)
138{
139 unsigned long _ets2 = header->etsT2();
140
141 if ( _ets2 != 0 ) {
142 if ( _ets2 == m_lastEts2Old ) {
143 header->setEtsT2(m_lastEts2New);
144 }
145 else {
146 unsigned long ets1 = header->etsT1();
147 long ets1NanoSec = ets1%2000000;
148 long tNow = ets1/2000000;
149
150 long ets2NanoSec = _ets2 % 2000000;
151
152 long tDiff = ets2NanoSec - ets1NanoSec;
153 if ( tDiff > 1000000 ) {
154 --tNow;
155 }
156 else if ( tDiff < -1000000 ) {
157 ++tNow;
158 }
159
160 unsigned long ets2 = tNow*2000000 + ets2NanoSec;
161
162 header->setEtsT2(ets2);
163 m_lastEts2Old = _ets2;
164 m_lastEts2New = ets2;
165 }
166 }
167}
int eventNumber() const
Retrieve event number.
Definition EventHeader.h:37
int runNumber() const
Retrieve run number.
Definition EventHeader.h:42
unsigned long etsT2()
Definition EventHeader.h:65
unsigned int time() const
Definition EventHeader.h:46
void setEtsT2(unsigned long value)
Definition EventHeader.h:71
void setEtsT1(unsigned long value)
Update ETS.
Definition EventHeader.h:69
unsigned long etsT1()
Retrieve ETS.
Definition EventHeader.h:63
virtual ~OfflineRevise()
OfflineRevise(const SniperJSON &json)
void fixHeader(Event::EventHeader *header)
T get() const
Definition SniperJSON.h:142
std::vector< SniperJSON >::const_iterator vec_iterator
Definition SniperJSON.h:11
vec_iterator vec_end() const
Definition SniperJSON.h:52