ATLAS Offline Software
Loading...
Searching...
No Matches
ThresholdConfigLoader.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
9#include "./CaloInfoLoader.h"
10#include "./DBHelper.h"
12
13#include <CoralBase/Attribute.h>
14#include <CoralBase/AttributeList.h>
15
16#include "RelationalAccess/SchemaException.h"
17#include "RelationalAccess/ITransaction.h"
18#include "RelationalAccess/ITable.h"
19#include "RelationalAccess/ISchema.h"
20#include "RelationalAccess/ICursor.h"
21#include "RelationalAccess/IQuery.h"
22
30
31
33
34#include <sstream>
35#include <iostream>
36#include <stdexcept>
37#include <typeinfo>
38
39using namespace std;
40
42
43 const unsigned int schema_version_with_zb_fields = 9;
44
45 TRG_MSG_DEBUG("Loading ThresholdConfig object attached to Lvl1 master ID " << thrConfig.lvl1MasterTableId());
46 TRG_MSG_DEBUG("Current number of thresholds: " << thrConfig.size());
47
48 long caloinfoid = 0;
49
50 try {
52 // get menu id and caloinfo id from thrConfig.m_MasterTableId and the table L1_MASTER_TABLE
53 int menuid = 0;
54
55 unique_ptr<coral::IQuery> query0(m_session.nominalSchema().tableHandle( "L1_MASTER_TABLE").newQuery());
56 query0->setRowCacheSize( 5 );
57
58 //Bind list
59 coral::AttributeList bindList0;
60 bindList0.extend<int>("mtId");
61 std::string cond0 = "L1MT_ID = :mtId";
62 bindList0[0].data<int>() = thrConfig.lvl1MasterTableId();
63 query0->setCondition( cond0, bindList0 );
64
65 //Output and types
66 coral::AttributeList attList0;
67 attList0.extend<int>( "L1MT_TRIGGER_MENU_ID" );
68 attList0.extend<long>( "L1MT_CALO_INFO_ID" );
69 query0->defineOutput(attList0);
70 query0->addToOutputList( "L1MT_TRIGGER_MENU_ID" );
71 query0->addToOutputList( "L1MT_CALO_INFO_ID" );
72 coral::ICursor& cursor0 = query0->execute();
73
74 if ( ! cursor0.next() ) {
75 TRG_MSG_ERROR("ThresholdConfigLoader >> No such Master_Table exists " << thrConfig.lvl1MasterTableId());
77 throw std::runtime_error( "ThresholdConfigLoader >> ThresholdConfig not available" );
78 }
79
80 const coral::AttributeList& row0 = cursor0.currentRow();
81 menuid = row0["L1MT_TRIGGER_MENU_ID"].data<int>();
82 caloinfoid = row0["L1MT_CALO_INFO_ID"].data<long>();
83
84 if ( cursor0.next() ) {
85
86 TRG_MSG_ERROR("ThresholdConfigLoader >> More than one Master_Table exists "
87 << thrConfig.lvl1MasterTableId());
89 throw std::runtime_error( "ThresholdConfigLoader >> Master_Table not available" );
90 }
91
92 //=====================================================
93 // get Thresholds WITH trigger threshold values
94
95 coral::AttributeList emptyBindVariableList;
96
97 unique_ptr<coral::IQuery> query(m_session.nominalSchema().newQuery());
98
99 // Set the tables that are used
100 query->addToTableList ( "L1_TM_TO_TT", "TM2TT" );
101 query->addToTableList ( "L1_TRIGGER_THRESHOLD", "TT" );
102 query->addToTableList ( "L1_TT_TO_TTV", "TT2TTV" );
103 query->addToTableList ( "L1_TRIGGER_THRESHOLD_VALUE", "TTV" );
104
105 // Bind list
106 coral::AttributeList bindList;
107 bindList.extend<int>("menuId");
108 bindList[0].data<int>() = menuid;
109 std::string theCondition = "";
110 theCondition += std::string( " TM2TT.L1TM2TT_TRIGGER_MENU_ID = :menuId" );
111 theCondition += std::string( " AND TM2TT.L1TM2TT_TRIGGER_THRESHOLD_ID = TT.L1TT_ID" );
112 theCondition += std::string( " AND TT2TTV.L1TT2TTV_TRIGGER_THRESHOLD_ID = TT.L1TT_ID" );
113 theCondition += std::string( " AND TT2TTV.L1TT2TTV_TRIG_THRES_VALUE_ID = TTV.L1TTV_ID" );
114 query->setCondition( theCondition, bindList );
115
116 // Output data and types
117 coral::AttributeList attList;
118 attList.extend<std::string>( "TM2TT.L1TM2TT_CABLE_NAME" );
119 attList.extend<std::string>( "TM2TT.L1TM2TT_CABLE_CTPIN" );
120 attList.extend<std::string>( "TM2TT.L1TM2TT_CABLE_CONNECTOR" );
121 attList.extend<int> ( "TM2TT.L1TM2TT_CABLE_START" );
122 attList.extend<int> ( "TM2TT.L1TM2TT_CABLE_END" );
123 if(isRun2()) {
124 attList.extend<int> ( "TM2TT.L1TM2TT_CABLE_CLOCK" );
125 }
126 attList.extend<int> ( "TT.L1TT_ID" );
127 attList.extend<std::string>( "TT.L1TT_NAME" );
128 attList.extend<int> ( "TT.L1TT_VERSION" );
129 attList.extend<std::string>( "TT.L1TT_TYPE" );
130 attList.extend<int> ( "TT.L1TT_ACTIVE" );
131 attList.extend<int> ( "TT.L1TT_MAPPING" );
132 attList.extend<int> ( "TT.L1TT_BITNUM" );
133 attList.extend<int> ( "TTV.L1TTV_ID" );
134 attList.extend<std::string>( "TTV.L1TTV_NAME" );
135 attList.extend<int> ( "TTV.L1TTV_VERSION" );
136 attList.extend<std::string>( "TTV.L1TTV_TYPE" );
137 attList.extend<std::string>( "TTV.L1TTV_PT_CUT" );
138 attList.extend<int> ( "TTV.L1TTV_ETA_MIN" );
139 attList.extend<int> ( "TTV.L1TTV_ETA_MAX" );
140 attList.extend<int> ( "TTV.L1TTV_PHI_MIN" );
141 attList.extend<int> ( "TTV.L1TTV_PHI_MAX" );
142 attList.extend<std::string>( "TTV.L1TTV_EM_ISOLATION" );
143 attList.extend<std::string>( "TTV.L1TTV_HAD_ISOLATION" );
144 attList.extend<std::string>( "TTV.L1TTV_HAD_VETO" );
145 attList.extend<int> ( "TTV.L1TTV_WINDOW" );
146 attList.extend<std::string>( "TTV.L1TTV_PRIORITY" );
147 fillQuery(query.get(), attList);
148
149 // the ordering
150 std::string theOrder = "";
151 theOrder += " TT.L1TT_MAPPING ASC";
152 theOrder += ", TT.L1TT_ID ASC";
153 theOrder += ", TTV.L1TTV_PRIORITY ASC";
154 theOrder += ", TTV.L1TTV_ETA_MAX ASC";
155 query->addToOrderList( theOrder );
156
157 //query->setRowCacheSize(1000);
158 query->setRowCacheSize(500);
159
160 coral::ICursor& cursor = query->execute();
161
162 unsigned int schema_version = triggerDBSchemaVersion();
163 //unsigned int numberofvalues = 0;
164 TriggerThreshold* tt = 0;
165 int nRowsLoop1 = -2009;
166 int nRowsLoop2 = -2010;
167
168 while (cursor.next()) {
169
170 const coral::AttributeList& row = cursor.currentRow();
171
172 nRowsLoop1 = row["TT.L1TT_ID"].data<int>();
173 if (nRowsLoop1 != nRowsLoop2) {
174
175 if (tt != 0) {
176 // trigger thresholds sorted by type
177 thrConfig.addTriggerThreshold(tt);
178 tt = new TriggerThreshold();
179 //numberofvalues = 0;
180 } else {
181 tt = new TriggerThreshold();
182 //numberofvalues = 0;
183 }
184
185 //==================================================
186 // now get the cable info from TM_TT
187
188 string cableName = row["TM2TT.L1TM2TT_CABLE_NAME"].data<std::string>();
189 tt->setCableName (cableName);
190 tt->setCableCtpin (row["TM2TT.L1TM2TT_CABLE_CTPIN"].data<std::string>());
191 tt->setCableConnector(row["TM2TT.L1TM2TT_CABLE_CONNECTOR"].data<std::string>());
192 tt->setCableStart (row["TM2TT.L1TM2TT_CABLE_START"].data<int>());
193 tt->setCableEnd (row["TM2TT.L1TM2TT_CABLE_END"].data<int>());
194
195 int clock = 0;
196 if(isRun2()) {
197 clock = row["TM2TT.L1TM2TT_CABLE_CLOCK"].data<int>();
198 }
199 if(clock >= 0) {
200 tt->setClock(clock);
201 }
202 tt->setId (row["TT.L1TT_ID"].data<int>());
203 tt->setName (row["TT.L1TT_NAME"].data<std::string>());
204 tt->setVersion(row["TT.L1TT_VERSION"].data<int>());
205 string thrtype(row["TT.L1TT_TYPE"].data<std::string>());
206 tt->setType (thrtype);
207 tt->setActive (row["TT.L1TT_ACTIVE"].data<int>());
208 tt->setMapping(row["TT.L1TT_MAPPING"].data<int>());
209 tt->setBitnum(row["TT.L1TT_BITNUM"].data<int>());
210 tt->setInput ( (thrtype=="TOPO" || thrtype=="ALFA") ? "ctpcore" : "ctpin" );
211
212 TRG_MSG_VERBOSE("ThresholdConfigLoader loading threshold with ID = " << tt->id() << " for MenuId = " << menuid << ": ");
213 }
214
215 if(tt->type() == L1DataDef::typeAsString(L1DataDef::RNDM) ||
218 } else {
219
220 TriggerThresholdValue* ttv = tt->createThresholdValue(row["TT.L1TT_TYPE"].data<std::string>());
221
222 ttv->setId (row["TTV.L1TTV_ID"].data<int>());
223
224 // Fill the value common for all threshold_value
225 ttv->setName (row["TTV.L1TTV_NAME"].data<std::string>());
226 ttv->setVersion (row["TTV.L1TTV_VERSION"].data<int>());
227 ttv->setType (row["TTV.L1TTV_TYPE"].data<std::string>());
228 float ptcut = std::stof(row["TTV.L1TTV_PT_CUT"].data<std::string>());
229 string emisolation = row["TTV.L1TTV_EM_ISOLATION"].data<std::string>();
230 string hadisolation = row["TTV.L1TTV_HAD_ISOLATION"].data<std::string>();
231 string hadveto = row["TTV.L1TTV_HAD_VETO"].data<std::string>();
232 float priority = std::stof(row["TTV.L1TTV_PRIORITY"].data<std::string>());
233 ttv->setPtcut (ptcut);
234 ttv->setPriority (priority);
235
236 //is it a cluster_threshold_value?
237 try {
238 ClusterThresholdValue& ctv = dynamic_cast<ClusterThresholdValue&>(*ttv);
241 msg() << "ThresholdConfigLoader >> No type match for ttv_id = "
242 << ctv.id() << " " << ttv->type() << std::endl;
243 throw std::runtime_error( "ThresholdConfigLoader >> ClusterThresholdValue not available" );
244 }
245
246 if(hadveto=="USEISOBITS" || std::stoi(hadveto)==99 ) {
247 ctv.setEmIsolation( 63 );
248 ctv.setHadIsolation( 63 );
249 ctv.setHadVeto( 99 );
250 ctv.setIsolationMask( TrigConf::bin2uint(emisolation) );
252 } else {
253 ctv.setEmIsolation( std::stof(emisolation) );
254 ctv.setHadIsolation( std::stof(hadisolation) );
255 ctv.setHadVeto( std::stof(hadveto) );
256 ctv.setUseIsolationMask( false );
257 }
258
259 } catch (std::bad_cast& ex) { }
260
261 //is it a jet_threshold_value?
262 try {
263 JetThresholdValue& jtv = dynamic_cast<JetThresholdValue&>(*ttv);
267 TRG_MSG_ERROR("No type match for ttv_id = " << jtv.id() << ttv->type());
268 throw std::runtime_error( "ThresholdConfigLoader >> TriggerThresholdValue not available" );
269 }
270 // jtv.setPhiMin(row["TTV.L1TTV_PHI_MIN"].data<int>());
271 // jtv.setPhiMax(row["TTV.L1TTV_PHI_MAX"].data<int>());
272 // jtv.setEtaMin(row["TTV.L1TTV_ETA_MIN"].data<int>());
273 // jtv.setEtaMax(row["TTV.L1TTV_ETA_MAX"].data<int>());
274 // jtv.setWindow(row["TTV.L1TTV_WINDOW"].data<int>());
275 } catch (std::bad_cast& ex) { }
276
277 ttv->setPhiMin(row["TTV.L1TTV_PHI_MIN"].data<int>());
278 ttv->setPhiMax(row["TTV.L1TTV_PHI_MAX"].data<int>());
279 ttv->setEtaMin(row["TTV.L1TTV_ETA_MIN"].data<int>());
280 ttv->setEtaMax(row["TTV.L1TTV_ETA_MAX"].data<int>());
281 ttv->setWindow(row["TTV.L1TTV_WINDOW"].data<int>());
282 tt->addThresholdValue(ttv);
283 //++numberofvalues;
284 TRG_MSG_DEBUG("ThresholdConfigLoader loading thresholdvalue with ID = " << ttv->id() << ": " << ttv->name());
285 }
286
287 nRowsLoop2 = row["TT.L1TT_ID"].data<int>();
288
289 }
290
291 // trigger thresholds sorted by type
292 thrConfig.addTriggerThreshold(tt);
293
294 //===========================================
295 // now get the Thresholds WITHOUT trigger threshold values
296 // we are aware that some code is duplicated below
297 // it is done this way because most Thresholds are WITH trigger threshold values
298
299 if (!m_session.transaction().isActive()) m_session.transaction().start();
300 unique_ptr<coral::IQuery> query1(m_session.nominalSchema().newQuery());
301
302 // Set the tables that are used
303 query1->addToTableList ( "L1_TM_TO_TT", "TM2TT" );
304 query1->addToTableList ( "L1_TRIGGER_THRESHOLD", "TT" );
305
306 // Bind list
307 coral::AttributeList bindList1;
308 bindList1.extend<int>("menuId");
309 bindList1[0].data<int>() = menuid;
310 std::string theCondition1 = "";
311 theCondition1 += std::string( " TM2TT.L1TM2TT_TRIGGER_MENU_ID = :menuId" );
312 theCondition1 += std::string( " AND TM2TT.L1TM2TT_TRIGGER_THRESHOLD_ID = TT.L1TT_ID" );
313 query1->setCondition( theCondition1, bindList1 );
314
315 // Output data and types
316 coral::AttributeList attList1;
317 attList1.extend<std::string>( "TM2TT.L1TM2TT_CABLE_NAME" );
318 attList1.extend<std::string>( "TM2TT.L1TM2TT_CABLE_CTPIN" );
319 attList1.extend<std::string>( "TM2TT.L1TM2TT_CABLE_CONNECTOR" );
320 attList1.extend<int> ( "TM2TT.L1TM2TT_CABLE_START" );
321 attList1.extend<int> ( "TM2TT.L1TM2TT_CABLE_END" );
322 if(isRun2()) {
323 attList1.extend<int> ( "TM2TT.L1TM2TT_CABLE_CLOCK" );
324 }
325 attList1.extend<int> ( "TT.L1TT_ID" );
326 attList1.extend<std::string>( "TT.L1TT_NAME" );
327 attList1.extend<int> ( "TT.L1TT_VERSION" );
328 attList1.extend<std::string>( "TT.L1TT_TYPE" );
329 attList1.extend<int> ( "TT.L1TT_ACTIVE" );
330 attList1.extend<int> ( "TT.L1TT_MAPPING" );
331 if( isRun2() || (schema_version >= schema_version_with_zb_fields) ) {
332 attList1.extend<int> ( "TT.L1TT_BCDELAY" );
333 attList1.extend<std::string>( "TT.L1TT_SEED" );
334 attList1.extend<int> ( "TT.L1TT_SEED_MULTI" );
335 }
336 fillQuery(query1.get(), attList1);
337
338 // the ordering
339 std::string theOrder1 = "";
340 theOrder1 += " TT.L1TT_ID ASC";
341 query1->addToOrderList( theOrder1 );
342
343 //query->setRowCacheSize(1000);
344 query1->setRowCacheSize(500);
345
346 coral::ICursor& cursor1 = query1->execute();
347
348 //numberofvalues = 0;
349 tt = 0;
350 nRowsLoop1 = -2009;
351 nRowsLoop2 = -2010;
352
353 while (cursor1.next()) {
354
355 const coral::AttributeList& row = cursor1.currentRow();
356
357 nRowsLoop1 = row["TT.L1TT_ID"].data<int>();
358 tt = thrConfig.findTriggerThreshold(nRowsLoop1);
359 if (tt) continue;
360 if (nRowsLoop1 != nRowsLoop2) {
361
362 if (tt != 0) {
363 //tt->setNumberofValues(numberofvalues);
364 // trigger thresholds sorted by type
365 thrConfig.addTriggerThreshold(tt);
366 tt = new TriggerThreshold();
367 //numberofvalues = 0;
368 } else {
369 tt = new TriggerThreshold();
370 //numberofvalues = 0;
371 }
372
373 //==================================================
374 // now get the cable info from TM_TT
375
376 // ttldr.setLoadCableInfo(true); will be moved from tt to thrcfg loader
377
378 string cableName = row["TM2TT.L1TM2TT_CABLE_NAME"].data<std::string>();
379 tt->setCableName(cableName);
380 tt->setCableCtpin (row["TM2TT.L1TM2TT_CABLE_CTPIN"].data<std::string>());
381 tt->setCableConnector(row["TM2TT.L1TM2TT_CABLE_CONNECTOR"].data<std::string>());
382 tt->setCableStart (row["TM2TT.L1TM2TT_CABLE_START"].data<int>());
383 tt->setCableEnd (row["TM2TT.L1TM2TT_CABLE_END"].data<int>());
384
385 int clock = 0;
386 if(isRun2()) {
387 clock = row["TM2TT.L1TM2TT_CABLE_CLOCK"].data<int>();
388 }
389 if(clock >= 0) {
390 tt->setClock(clock);
391 }
392 tt->setId (row["TT.L1TT_ID"].data<int>());
393 tt->setName (row["TT.L1TT_NAME"].data<std::string>());
394 tt->setVersion(row["TT.L1TT_VERSION"].data<int>());
395 string thrtype(row["TT.L1TT_TYPE"].data<std::string>());
396 tt->setType (thrtype);
397 tt->setActive (row["TT.L1TT_ACTIVE"].data<int>());
398 tt->setMapping(row["TT.L1TT_MAPPING"].data<int>());
399 tt->setInput ( (thrtype=="TOPO" || thrtype=="ALFA") ? "ctpcore" : "ctpin" );
400
401
402 // zero bias related
403 int bcdelay(-1), seed_multi(-1);
404 std::string seed("");
405 if( isRun2() || (schema_version >= schema_version_with_zb_fields) ) {
406 bcdelay = row["TT.L1TT_BCDELAY"].data<int>();
407 seed = row["TT.L1TT_SEED"].data<std::string>();
408 seed_multi = row["TT.L1TT_SEED_MULTI"].data<int>();
409 }
410 tt->setBCDelay (bcdelay);
411 tt->setZBSeedingThresholdName (seed);
412 tt->setZBSeedingThresholdMulti(seed_multi);
413
414 TRG_MSG_VERBOSE("ThresholdConfigLoader loading threshold with ID = " << tt->id() << " for MenuId = " << menuid << ": ");
415 //tt->setNumberofValues(numberofvalues);
416 // trigger thresholds sorted by type
417 thrConfig.addTriggerThreshold(tt);
418 tt = nullptr;
419 }
420
421 nRowsLoop2 = row["TT.L1TT_ID"].data<int>();
422
423 }
425 }
426 catch( const coral::Exception& e ) {
427 TRG_MSG_ERROR("Caught coral exception: " << e.what() );
428 throw;
429 }
430 catch( const std::exception& e ) {
431 TRG_MSG_ERROR("Caught standard exception: " << e.what() );
432 throw;
433 }
434
435 loadCaloInfo(thrConfig, caloinfoid);
436
437 // create TIPs from TOPO and ALFA TriggerThresholds
438
439 return true;
440
441}
442
443
444
445void
447 //============================================
448 // get CaloInfo
449 //============================================
450 try {
451 startSession();
452 CaloInfoLoader& cildr = dynamic_cast<CaloInfoLoader&>
453 ((dynamic_cast<StorageMgr&>(m_storageMgr)).caloInfoLoader());
454 cildr.setLevel(outputLevel());
455 CaloInfo ci;
456 ci.setId(caloInfoId);
457 if ( !cildr.load( ci )) {
458 TRG_MSG_ERROR("loading CaloInfo " << ci.id());
459 throw runtime_error( "ThresholdConfigLoader: Error loading CaloInfo" );
460 }
461 thrConfig.setCaloInfo(ci);
464 }
465 catch( const coral::Exception& e ) {
466 TRG_MSG_ERROR("Caught coral exception: " << e.what() );
467 throw;
468 }
469 catch( const std::exception& e ) {
470 TRG_MSG_ERROR("Caught standard exception: " << e.what() );
471 throw;
472 }
473}
474
475
char data[hepevt_bytes_allocation_ATLAS]
Definition HepEvt.cxx:11
TriggerDB loader of the LVL1 calorimeter trigger configuration.
virtual bool load(CaloInfo &data) override
StorageMgr & m_storageMgr
reference to the storage manager
Definition DBLoader.h:67
virtual MSGTC::Level outputLevel() const override
Definition DBLoader.h:40
void commitSession()
commit session if not already done
Definition DBLoader.cxx:45
virtual void setLevel(MSGTC::Level lvl) override
access to output stream
Definition DBLoader.cxx:60
coral::ISessionProxy & m_session
CORAL interface to database session.
Definition DBLoader.h:68
unsigned int triggerDBSchemaVersion()
Definition DBLoader.cxx:76
void startSession()
start session if not already active
Definition DBLoader.cxx:35
unsigned int lvl1MasterTableId() const
static std::string & typeAsString(TriggerType tt)
Definition L1DataDef.h:53
Database Storage Manager, controls the database session and the different loader classes for DB acces...
Definition StorageMgr.h:23
void loadCaloInfo(ThresholdConfig &thrConfig, long caloInfoId)
virtual bool load(ThresholdConfig &data) override
void setCaloInfo(const CaloInfo &ci)
TriggerThreshold * findTriggerThreshold(unsigned int id)
bool addTriggerThreshold(TriggerThreshold *value)
unsigned int id() const
void setId(unsigned int id)
void setName(const std::string &name)
const std::string & name() const
void setVersion(unsigned int version)
MsgStreamTC & msg() const
The standard message stream.
void setType(const std::string &type)
const std::string & type() const
static void setCaloInfo(const CaloInfo &ci)
void fillQuery(coral::IQuery *q, coral::AttributeList &attList)
Definition DBHelper.cxx:13
Definition query.py:1
STL namespace.