BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
Coverage Class Reference

#include <Coverage.h>

Public Member Functions

 Coverage (calibUtil::Metadata *meta, const std::string &instr, const std::string &flavor, const std::string &level, const facilities::Timestamp &ts)
bool expandTypes (std::string &nickname, std::vector< std::string > &types)
 ~Coverage ()
unsigned checkType (std::string calibtype)
void setOverlap (unsigned seconds)

Detailed Description

Check whether calibrations for a particular calibration type (or each in a predefined collection) exist covering full time interval, and whether they overlap.

Definition at line 27 of file Coverage.h.

Constructor & Destructor Documentation

◆ Coverage()

Coverage::Coverage ( calibUtil::Metadata * meta,
const std::string & instr,
const std::string & flavor,
const std::string & level,
const facilities::Timestamp & ts )

Definition at line 45 of file Coverage.cxx.

48 : m_instr( instr ), m_flavor( flavor ), m_level( level ), m_overlap( 300 ) {
49 m_ts = facilities::Timestamp( ts.getClibTime() );
50 m_selects.reserve( 3 );
51 m_selects.push_back( "ser_no" );
52 m_selects.push_back( "vstart" );
53 m_selects.push_back( "vend" );
54
55 m_orderBy.reserve( 1 );
56 m_orderBy.push_back( "vstart asc" );
57
58 m_rdb = meta->getRdb();
59 m_conn = meta->getReadConnection();
60 m_table = meta->getTable();
61}
double meta

◆ ~Coverage()

Coverage::~Coverage ( )
inline

Definition at line 37 of file Coverage.h.

37{};

Member Function Documentation

◆ checkType()

unsigned Coverage::checkType ( std::string calibtype)

Definition at line 84 of file Coverage.cxx.

84 {
85 using namespace rdbModel;
86 using facilities::Timestamp;
87 // Make a query to find all rows matching criteria, ordered ascending
88 // by vstart
89 // match calib_type, flavor, instrument, proc_level
90 // completion = "OK"
91 // vstart >= ts
92 // Ask for return of ser_no, vstart, vend
93
94 std::vector<Assertion::Operator*> conditions;
95 conditions.reserve( 6 );
96
97 Assertion::Operator completeOp( OPTYPEequal, "completion", "OK", FIELDTYPEold,
98 FIELDTYPElit );
99 // false, true);
100 Assertion::Operator instOp( OPTYPEequal, "instrument", m_instr, FIELDTYPEold, FIELDTYPElit );
101 // false, true);
102 Assertion::Operator calibTypeOp( OPTYPEequal, "calib_type", calibtype, FIELDTYPEold,
103 FIELDTYPElit );
104 // false, true);
105 Assertion::Operator flavorOp( OPTYPEequal, "flavor", m_flavor, FIELDTYPEold, FIELDTYPElit );
106 // false, true);
107 Assertion::Operator levelOp( OPTYPEequal, "proc_level", m_level, FIELDTYPEold,
108 FIELDTYPElit );
109 // false, true);
110 Assertion::Operator vstartOp( OPTYPElessThan, m_ts.getString(), "vstart", FIELDTYPElit,
111 FIELDTYPEold );
112 // true, false);
113 conditions.push_back( &calibTypeOp );
114 conditions.push_back( &instOp );
115 conditions.push_back( &flavorOp );
116 conditions.push_back( &levelOp );
117 conditions.push_back( &vstartOp );
118 conditions.push_back( &completeOp );
119 Assertion::Operator* andOp = new Assertion::Operator( OPTYPEand, conditions );
120 Assertion* whereClause = new Assertion( andOp );
121
122 ResultHandle* results = 0;
123
124 try
125 { // make the query
126 results = m_conn->select( m_table, m_selects, m_orderBy, whereClause );
127 } catch ( RdbException ex )
128 {
129 std::cerr << ex.getMsg() << std::endl;
130 std::cerr.flush(); // exit(1);
131 return false;
132 }
133
134 if ( !results )
135 { // Error. Should have ResultHandle even if 0 rows.
136 std::cerr << "Error making query " << std::endl;
137 std::cerr.flush();
138 exit( 1 );
139 }
140
141 // Save returned values
142 std::vector<SelectInfo> info;
143 unsigned nFound = results->getNRows();
144
145 if ( !nFound )
146 {
147 std::cout << "No calibrations found for calib_type '" << calibtype << "'" << std::endl;
148 return true;
149 }
150
151 info.reserve( results->getNRows() );
152
153 unsigned iRow = 0;
154 std::vector<std::string> fields;
155 fields.reserve( 3 );
156
157 bool ok = true;
158 unsigned retCode = 0;
159
160 // 1. For each row store columnes; check if vstart < vend
161 std::cout << std::endl << "Checking for valid timestamps, vstart < vend .. " << std::endl;
162 for ( iRow = 0; iRow < nFound; iRow++ )
163 {
164 results->getRow( fields, iRow );
165 int ser = facilities::Util::stringToInt( fields[0] );
166 try
167 {
168 Timestamp vstart = Timestamp( fields[1] );
169 Timestamp vend = Timestamp( fields[2] );
170 info.push_back( SelectInfo( ser, vstart, vend ) );
171
172 if ( vend.getClibTime() < vstart.getClibTime() )
173 {
174 std::cerr << "vend < vstart for " << info.back();
175 ok = false; // or could discard the row and try to continue
176 retCode = 1;
177 }
178 } catch ( facilities::BadTimeInput ex )
179 {
180 std::cerr << "Bad vstart or vend in row " << ser << std::endl;
181 ok = false;
182 retCode = 1;
183 }
184 }
185 if ( !ok ) return retCode;
186
187 // 2. Check if vend's also increase monotonically
188 std::cout << std::endl << "Checking for vends monotonic.. " << std::endl;
189 for ( iRow = 0; iRow < nFound - 1; iRow++ )
190 {
191 if ( info[iRow].m_vend.getClibTime() > info[iRow + 1].m_vend.getClibTime() )
192 {
193 std::cerr << "Validity interval for row with serial #" << info[iRow + 1].m_ser
194 << " completely contained in interval for row with serial #"
195 << info[iRow].m_ser << std::endl;
196 std::cerr << info[iRow];
197 std::cerr << info[iRow + 1] << std::endl;
198 ok = false;
199 retCode = 2;
200 }
201 }
202 if ( !ok ) return retCode;
203
204 // 3. Look for gaps
205 std::cout << std::endl << "Checking for gaps.. " << std::endl;
206 for ( iRow = 0; iRow < nFound - 1; iRow++ )
207 {
208 if ( info[iRow].m_vend < info[iRow + 1].m_vstart )
209 {
210 std::cerr << "Validity interval gap between calibrations with serial #"
211 << info[iRow].m_ser << " and #" << info[iRow + 1].m_ser << std::endl;
212 std::cerr << info[iRow];
213 std::cerr << info[iRow + 1] << std::endl;
214 ok = false;
215 retCode = 3;
216 }
217 }
218 // 4. Look for overlaps
219 std::cout << std::endl << "Checking for overlaps.. " << std::endl;
220 for ( iRow = 0; iRow < nFound - 1; iRow++ )
221 {
222 if ( ( info[iRow].m_vend ).getClibTime() >
223 ( info[iRow + 1].m_vstart ).getClibTime() + m_overlap )
224 {
225 std::cerr << "Unacceptable overlap between serial #" << info[iRow].m_ser << " and #"
226 << info[iRow + 1].m_ser << std::endl;
227 std::cerr << info[iRow];
228 std::cerr << info[iRow + 1] << std::endl;
229 ok = false;
230 if ( !retCode ) retCode = 4;
231 }
232 }
233 return retCode;
234}
static int stringToInt(const std::string &InStr)
virtual bool getRow(std::vector< std::string > &fields, unsigned int i=0, bool clear=true)=0
virtual unsigned int getNRows() const =0
Return number of rows in results.

Referenced by main().

◆ expandTypes()

bool Coverage::expandTypes ( std::string & nickname,
std::vector< std::string > & types )

The @nickname argument may be a single legal calib_type or may be one of the special wildcard values "CAL" "TKR" "*", in which case it is expanded to a suitable list of calib types (if we have a schema)

Definition at line 64 of file Coverage.cxx.

64 {
65 if ( ( nickname == "CAL" ) || ( nickname == "TKR" ) || ( nickname == "*" ) )
66 {
67 if ( !m_rdb )
68 {
69 std::cerr << "Unable to expand wildcard argument " << nickname
70 << " without schema for metadata dbs " << std::endl;
71 }
72 else
73 {
74 std::cerr << "Wildcard expansion of calib_type argument not yet supported";
75 std::cerr << std::endl << "Have a nice day" << std::endl;
76 }
77 std::cerr.flush();
78 exit( 1 );
79 }
80 types.push_back( nickname );
81 return true;
82}

Referenced by main().

◆ setOverlap()

void Coverage::setOverlap ( unsigned seconds)
inline

Definition at line 44 of file Coverage.h.

44{ m_overlap = seconds; }

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