ATLAS Offline Software
Loading...
Searching...
No Matches
TriggerThresholdLoader.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
7#include "./DBHelper.h"
9
19
20#include <sstream>
21#include <iostream>
22#include <stdexcept>
23#include <typeinfo>
24
25using namespace std;
26
27bool
29
30 const unsigned int schema_version_with_zb_fields = 9;
31
32 TRG_MSG_DEBUG("TriggerThresholdLoader loading threshold with ID = "
33 << ttTarget.id() << " for MenuId = "
34 << m_MenuId << ": ")
35 unsigned int schema_version = triggerDBSchemaVersion();
36
37 try {
39
40 {
41 unique_ptr<coral::IQuery> query(m_session.nominalSchema().tableHandle( "L1_TRIGGER_THRESHOLD").newQuery());
42 query->setRowCacheSize( 5 );
43
44 //Bind list
45 coral::AttributeList bindList;
46 bindList.extend<long>("ttId");
47 std::string cond= "L1TT_ID = :ttId";
48 bindList[0].data<long>() = ttTarget.id();
49 query->setCondition( cond, bindList );
50
51 //Output data and types
52 coral::AttributeList attList;
53 attList.extend<std::string>( "L1TT_NAME" );
54 attList.extend<int>( "L1TT_VERSION" );
55 attList.extend<std::string>( "L1TT_TYPE" );
56 attList.extend<int>( "L1TT_ACTIVE" );
57 attList.extend<int>( "L1TT_MAPPING" );
58 if( (isRun1() && schema_version >= schema_version_with_zb_fields) || isRun2() ) {
59 attList.extend<int>( "L1TT_BCDELAY" );
60 attList.extend<std::string>( "L1TT_SEED" );
61 attList.extend<int>( "L1TT_SEED_MULTI" );
62 }
63 fillQuery(query.get(),attList);
64
65 coral::ICursor& cursor = query->execute();
66
67 if ( ! cursor.next() ) {
68 TRG_MSG_ERROR("No TriggerThreshold exists with ID " << ttTarget.id());
70 throw std::runtime_error( "TriggerThresholdLoader >> TriggerThreshold not available" );
71 }
72
73 const coral::AttributeList& row = cursor.currentRow();
74
75 std::string name = row["L1TT_NAME"].data<std::string>();
76 int version = row["L1TT_VERSION"].data<int>();
77 std::string type = row["L1TT_TYPE"].data<std::string>();
78 int active = row["L1TT_ACTIVE"].data<int>();
79 int mapping = row["L1TT_MAPPING"].data<int>();
80
81 // zero bias related
82 int bcdelay(-1), seed_multi(-1);
83 std::string seed("");
84 if( (isRun1() && schema_version >= schema_version_with_zb_fields) || isRun2() ) {
85 bcdelay = row["L1TT_BCDELAY"].data<int>();
86 seed = row["L1TT_SEED"].data<std::string>();
87 seed_multi = row["L1TT_SEED_MULTI"].data<int>();
88 }
89
90 TRG_MSG_DEBUG(name << " " << version << " " << type << " " << active << " " << mapping);
91
92 // Fill the object with data
93 ttTarget.setName ( name );
94 ttTarget.setVersion( version );
95 ttTarget.setType ( type );
96 ttTarget.setInput ( (type=="TOPO" || type=="ALFA") ? "ctpcore" : "ctpin" );
97 ttTarget.setActive ( active );
98
99 ttTarget.setZBSeedingThresholdName(seed);
100 ttTarget.setZBSeedingThresholdMulti(seed_multi);
101 ttTarget.setBCDelay(bcdelay);
102
103 if(ttTarget.isInternal()) {
104 string::size_type pos = name.find_first_of("0123456789");
105 mapping = std::stoi(name.substr(pos));
106 }
107 ttTarget.setMapping( mapping );
108 }
109
110
111 //==================================================
112 // now get the cable info from TM_TT
113 if(loadCableInfo()) {
114
115 unique_ptr<coral::IQuery> query(m_session.nominalSchema().tableHandle( "L1_TM_TO_TT").newQuery());
116 query->setRowCacheSize( 5 );
117
118 //Bind list
119 coral::AttributeList bindList;
120 std::string cond = "L1TM2TT_TRIGGER_THRESHOLD_ID = :ttId";
121 cond += " AND L1TM2TT_TRIGGER_MENU_ID = :menuId";
122 bindList.extend<long>("ttId");
123 bindList.extend<int>("menuId");
124 bindList[0].data<long>() = ttTarget.id();
125 bindList[1].data<int>() = m_MenuId;
126 query->setCondition( cond, bindList );
127
128 //Define the data types
129 coral::AttributeList attList;
130 attList.extend<std::string>( "L1TM2TT_CABLE_NAME" );
131 attList.extend<std::string>( "L1TM2TT_CABLE_CTPIN" );
132 attList.extend<std::string>( "L1TM2TT_CABLE_CONNECTOR" );
133 attList.extend<int>( "L1TM2TT_CABLE_START" );
134 attList.extend<int>( "L1TM2TT_CABLE_END" );
135 fillQuery(query.get(),attList);
136
137 coral::ICursor& cursor = query->execute();
138
139 if ( ! cursor.next() ) {
140 TRG_MSG_ERROR("No such combination in L1_TM_TO_TT: TT ID "<< ttTarget.id() << ", menu ID " << m_MenuId);
142 throw std::runtime_error( "TriggerThresholdLoader >> "
143 "TMTI combination not availbale in TM_TT" );
144 }
145
146 const coral::AttributeList& row = cursor.currentRow();
147 std::string cable_name = row["L1TM2TT_CABLE_NAME"].data<std::string>();
148 std::string cable_ctpin = row["L1TM2TT_CABLE_CTPIN"].data<std::string>();
149 std::string cable_connector = row["L1TM2TT_CABLE_CONNECTOR"].data<std::string>();
150 int cable_start = row["L1TM2TT_CABLE_START"].data<int>();
151 int cable_end = row["L1TM2TT_CABLE_END"].data<int>();
152
153 ttTarget.setCableName(cable_name);
154 ttTarget.setCableCtpin(cable_ctpin);
155 ttTarget.setCableConnector(cable_connector);
156 ttTarget.setCableStart(cable_start);
157 ttTarget.setCableEnd(cable_end);
158
159 }
160
161 if( ! ttTarget.isInternal() ) { // no trigger threshold values exist for internal triggers
162
163 //=================================================================
164 // now get the TTVs from TT_TTV:
165 coral::ITable& table = m_session.nominalSchema().tableHandle( "L1_TT_TO_TTV");
166 coral::IQuery* query = table.newQuery();
167 query->setRowCacheSize(5);
168
169 //Bind list
170 coral::AttributeList bindList;
171 bindList.extend<long>("ttId");
172 std::string cond = "L1TT2TTV_TRIGGER_THRESHOLD_ID = :ttId";
173 bindList[0].data<long>() = ttTarget.id();
174 query->setCondition( cond, bindList );
175
176 //Output data and types
177 coral::AttributeList attList;
178 attList.extend<long>( "L1TT2TTV_TRIG_THRES_VALUE_ID" );
179 query->defineOutput(attList);
180 query->addToOutputList( "L1TT2TTV_TRIG_THRES_VALUE_ID" );
181
182 coral::ICursor& cursor = query->execute();
183
184 std::vector<long> vec_ttv_id;
185 while( cursor.next() ) {
186 const coral::AttributeList& row = cursor.currentRow();
187 vec_ttv_id.push_back((long)row["L1TT2TTV_TRIG_THRES_VALUE_ID"].data<long>());
188 }
189
190 unsigned int numberofvalues = vec_ttv_id.size();
191
193 ((dynamic_cast<StorageMgr&>(m_storageMgr)).triggerThresholdValueLoader());
194 ttvldr.setVerbose(verbose());
195 for (unsigned int i=0; i<numberofvalues; ++i) {
196 TriggerThresholdValue* ttv = 0;
197 if (ttTarget.type() == L1DataDef::typeAsString(L1DataDef::MUON)) {
198 ttv = new MuonThresholdValue();
199 } else if (ttTarget.type() == L1DataDef::typeAsString(L1DataDef::EM) ||
201 ttv = new ClusterThresholdValue();
202 } else if (ttTarget.type() == L1DataDef::typeAsString(L1DataDef::JET) ||
205 ttv = new JetThresholdValue();
206 } else if (ttTarget.type() == L1DataDef::typeAsString(L1DataDef::XE) ||
209 ttv = new EtThresholdValue();
210 } else if (ttTarget.type() == L1DataDef::typeAsString(L1DataDef::XS)) {
211 ttv = new XsThresholdValue();
212 } else if (ttTarget.type() == L1DataDef::typeAsString(L1DataDef::NIM) ||
222 ttv = new NimThresholdValue();
223 } else {
224 msg() << "TriggerThresholdLoader: not supported type "
225 << ttTarget.id() << " type is " << ttTarget.type() << std::endl;
226 delete query;
227 delete ttv;
229 throw std::runtime_error("TriggerThresholdLoader: not supported type" );
230 }
231 ttv->setId(vec_ttv_id[i]);
232 if ( !ttvldr.load( *ttv ) ) {
233 msg() << "TriggerThresholdLoader: Error loading TriggerThreshodValue "
234 << ttv->id() << std::endl;
235 delete ttv;
236 ttv = 0;
237 delete query;
239 throw std::runtime_error("TriggerThresholdLoader: Error loading TriggerThreshodValue " );
240 } else {
241 // fill the vector
242 ttTarget.addThresholdValue(ttv);
243 }
244 }
245 }
246
248 return true;
249 } catch( const coral::SchemaException& e ) {
250 msg() << "TriggerThresholdLoader: SchemaException: "
251 << e.what() << std::endl;
252 m_session.transaction().rollback();
253 return false;
254 } catch( const std::exception& e ) {
255 msg() << "TriggerThresholdLoader >> Standard C++ exception: " << e.what() << std::endl;
256
257 m_session.transaction().rollback();
258 return false;
259 } catch( ... ) {
260 msg() << "TriggerThresholdLoader >> unknown C++ exception" << std::endl;
261
262 m_session.transaction().rollback();
263 return false;
264 }
265}
266
267void
271
272int
276
char data[hepevt_bytes_allocation_ATLAS]
Definition HepEvt.cxx:11
virtual int verbose() const override
Definition DBLoader.h:57
StorageMgr & m_storageMgr
reference to the storage manager
Definition DBLoader.h:67
virtual void setVerbose(int v) override
Definition DBLoader.h:58
void commitSession()
commit session if not already done
Definition DBLoader.cxx:45
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
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
unsigned int id() const
void setId(unsigned int id)
void setName(const std::string &name)
void setVersion(unsigned int version)
MsgStreamTC & msg() const
The standard message stream.
virtual bool load(TriggerThreshold &data) override
virtual bool load(TriggerThresholdValue &data) override
void setZBSeedingThresholdMulti(int seedmulti)
void setType(L1DataDef::TriggerType type)
void addThresholdValue(TriggerThresholdValue *value)
void setZBSeedingThresholdName(const std::string &seed)
const std::string & type() const
void setCableName(const std::string &cablename)
void setInput(const std::string &input)
void setCableConnector(const std::string &connector)
void setCableCtpin(const std::string &cablectpin)
void fillQuery(coral::IQuery *q, coral::AttributeList &attList)
Definition DBHelper.cxx:13
Definition query.py:1
STL namespace.