190 {
191 try {
194 ATH_MSG_WARNING(
"Trying to insert data for chamber " <<
id.regionId() <<
" header " << head_id << site_name
195 << " which already exists!" );
197 return false;
198 }
199 coral::ITableDataEditor *editor[] = {&
m_db_conn.GetTableEditor(std::string(
"MDT_TUBE")),
200 &
m_db_conn.GetTableEditor(std::string(
"MDT_TUBE_V")),
201 &
m_db_conn.GetTableEditor(std::string(
"MDT_TUBE_C"))};
202
203 if (validation_flag.size() == 0) {
204 if (!
insertTubes(site_name, head_id,
id,
t0, validation_flag, editor)) {
206 return false;
207 }
209 return true;
210 }
211
212 bool all_new(true), all_good(true);
213 for (int it : validation_flag) {
214 if (it != 0) all_new = false;
215 if (it != 3) all_good = false;
216 if (!all_new && !all_good) break;
217 }
218
219 if (all_new) {
220 if (!
insertTubes(site_name, head_id,
id,
t0, validation_flag, editor)) {
222 return false;
223 }
225 return true;
226 }
227
228 if (all_good) {
231 return false;
232 }
234 return true;
235 }
236
237 std::vector<coral::AttributeList> rowBuffer(3);
238 bool row_buffer_initialized(false);
239 unsigned int nml =
t0->numMultilayers();
240 unsigned int nly =
t0->numLayers();
241 unsigned int ntb =
t0->numTubes();
242 MuonFixedId fixId(0);
243 fixId.setTechnology(0);
244 fixId.setStationName(id.GetStation());
245 fixId.setStationEta(id.GetEta());
246 fixId.setStationPhi(id.GetPhi());
247 for (unsigned int ml = 1; ml <= nml; ml++) {
248 for (unsigned int ly = 1; ly <= nly; ly++) {
249 for (
unsigned int tb = 1;
tb <= ntb;
tb++) {
250 int tb_index = (
tb -1) + ntb * (ly -1) + ntb * nly * (ml -1);
251 if (validation_flag[tb_index] == 3) continue;
252 fixId.setMdtTube(tb);
253 fixId.setMdtTubeLayer(ly);
254 fixId.setMdtMultilayer(ml);
255
256 int rowsUpdated;
257 if (validation_flag[tb_index] == 5)
258 rowsUpdated =
setValidFlag(site_name, head_id, fixId.getIdInt(), 5, *editor[0]);
259 else
260 rowsUpdated =
setValidFlag(site_name, head_id, fixId.getIdInt(), 1, *editor[0]);
261
262 if (rowsUpdated != 1) {
263 ATH_MSG_WARNING(
id.regionId() <<
" tb=" << tb <<
" ly=" << ly <<
" ml=" << ml <<
" head_id=" << head_id
264 << ": " << rowsUpdated << " Rows to be updated! This is wrong! Check database!" );
266 return false;
267 }
268 if (validation_flag[tb_index] != 5) {
269
270 if (!row_buffer_initialized) {
272 row_buffer_initialized = true;
273 }
274
276 rowBuffer[0]["VALIDFLAG"].data<int>() = validation_flag[tb_index];
277
278 for (
unsigned int i = 0;
i < 3;
i++) {
279 rowBuffer[
i][
"CALIBFLAG"].data<
int>() =
static_cast<int>(validation_flag[tb_index] > 3);
280 editor[
i]->insertRow(rowBuffer[i]);
281 }
282 }
283 }
284 }
285 }
286
289 return false;
290 }
292 return true;
293 }
294 catch (coral::SchemaException &e) {
297 return false;
298 }
299 }
bool setValidationFlag(const std::string &site_name, int head_id, const NtupleStationId &id, int from, int to, coral::ITableDataEditor &editor)
bool insertTubes(const std::string &site_name, int head_id, const NtupleStationId &id, const MdtTubeFitContainer *t0, const std::vector< int > &validation_flag, coral::ITableDataEditor *editor[])
bool checkTubesPresent(const int head_id, const std::string &site_name, const NtupleStationId &id, const std::vector< int > &validflag)
bool setValidFlag(const std::string &site_name, const int head_id, const int tube_id, const int new_validflag, coral::ITableDataEditor &editor)