28 #include <CoralBase/Attribute.h>
29 #include <CoralBase/AttributeList.h>
31 #include "RelationalAccess/SchemaException.h"
32 #include "RelationalAccess/ITransaction.h"
33 #include "RelationalAccess/ITable.h"
34 #include "RelationalAccess/ISchema.h"
35 #include "RelationalAccess/ICursor.h"
36 #include "RelationalAccess/IQuery.h"
48 triggerDBSchemaVersion();
55 if(
data.loadCtpcoreFiles() ) retVal &= loadCtpcoreData(
data);
56 if(
data.loadCtpinFiles() ) retVal &= loadCtpinData(
data);
57 if(
data.loadCtpmonFiles() ) retVal &= loadCtpmonData(
data);
65 unique_ptr<coral::IQuery>
query( m_session.nominalSchema().tableHandle(
"L1_MASTER_TABLE").newQuery() );
66 query->setRowCacheSize( 5 );
70 std::string
condition =
"L1MT_ID = :mtId";
71 emptyBindVariableList0.extend<
int>(
"mtId");
72 emptyBindVariableList0[0].data<
int>() = mid;
76 attList.extend<
int>(
"L1MT_TRIGGER_MENU_ID" );
83 throw std::runtime_error(
"CTPFilesLoader" );
86 int menuid =
row[
"L1MT_TRIGGER_MENU_ID"].data<
int>();
90 throw std::runtime_error(
"CTPFilesLoader >> Master_Table not available" );
98 coral::ITable&
table = m_session.nominalSchema().tableHandle(
"L1_TRIGGER_MENU");
100 query->setRowCacheSize( 5 );
104 std::string
condition =
"L1TM_ID = :tmId";
105 emptyBindVariableList0.extend<
int>(
"tmId");
106 emptyBindVariableList0[0].data<
int>() = mid;
110 attList.extend<
int>(
"L1TM_CTP_FILES_ID" );
111 query->defineOutput(attList);
112 query->addToOutputList(
"L1TM_CTP_FILES_ID" );
119 throw std::runtime_error(
"CTPFilesLoader" );
122 return static_cast<long>(
row[
"L1TM_CTP_FILES_ID"].data<
int>());
128 coral::ITable&
table = m_session.nominalSchema().tableHandle(
"L1_TRIGGER_MENU");
130 query->setRowCacheSize( 5 );
134 std::string
condition =
"L1TM_ID = :tmId";
135 emptyBindVariableList0.extend<
int>(
"tmId");
136 emptyBindVariableList0[0].data<
int>() = mid;
140 attList.extend<
int>(
"L1TM_CTP_SMX_ID" );
141 query->defineOutput(attList);
142 query->addToOutputList(
"L1TM_CTP_SMX_ID" );
149 throw std::runtime_error(
"CTPFilesLoader" );
152 return static_cast<long>(
row[
"L1TM_CTP_SMX_ID"].data<
int>());
165 if(ctpFiles.
id() <= 0) {
167 int menuid = getMenuIdFromMaster(l1id);
168 long filesid = getFilesIdFromMenu(menuid);
169 ctpFiles.
setId(filesid);
172 unique_ptr<coral::IQuery>
query( m_session.nominalSchema().tableHandle(
"L1_CTP_FILES").newQuery() );
173 query->setRowCacheSize( 10 );
177 emptyBindVariableList0.extend<
long>(
"fId");
178 emptyBindVariableList0[0].data<
long>() = ctpFiles.
id();
179 query->setCondition(
"L1CF_ID = :fId", emptyBindVariableList0 );
182 attList.extend<std::string>(
"L1CF_NAME" );
183 attList.extend<
int>(
"L1CF_VERSION" );
184 attList.extend<std::string>(
"L1CF_LUT" );
185 attList.extend<std::string>(
"L1CF_CAM" );
193 throw std::runtime_error(
"CTPFilesLoader >> CTPFiles not available" );
197 std::string
name =
row[
"L1CF_NAME"].data<std::string>();
198 int version =
row[
"L1CF_VERSION"].data<
int>();
199 std::string ctpcoreLUT_str =
row[
"L1CF_LUT"].data<std::string>();
200 std::string ctpcoreCAM_str =
row[
"L1CF_CAM"].data<std::string>();
205 throw std::runtime_error(
"CTPFilesLoader >> CTPFiles not available" );
208 std::vector<u_int> lutVec(CTPFiles::ALL_CTPCORELUT_SIZE);
210 parseHexString(lutVec, ctpcoreLUT_str,
true);
212 std::vector<u_int> camVec(CTPFiles::ALL_CTPCORECAM_SIZE);
214 parseHexString(camVec,ctpcoreCAM_str);
223 }
catch(
const coral::Exception&
e ) {
237 if(ctpFiles.
id() <= 0 || ctpFiles.
smxId() <= 0) {
239 int menuid = getMenuIdFromMaster(l1id);
240 if(ctpFiles.
id() <= 0) {
241 long filesid = getFilesIdFromMenu(menuid);
242 ctpFiles.
setId(filesid);
244 if(ctpFiles.
smxId() <= 0) {
245 long id = getSmxIdFromMenu(menuid);
251 unique_ptr<coral::IQuery>
query( m_session.nominalSchema().tableHandle(
"L1_CTP_FILES").newQuery() );
252 query->setRowCacheSize( 13 );
256 std::string
condition =
"L1CF_ID = :fId";
257 emptyBindVariableList0.extend<
long>(
"fId");
258 emptyBindVariableList0[0].data<
long>() = ctpFiles.
id();
262 attList.extend<std::string>(
"L1CF_NAME" );
263 attList.extend<
int>(
"L1CF_VERSION" );
264 attList.extend<std::string>(
"L1CF_MON_SEL_SLOT7" );
265 attList.extend<std::string>(
"L1CF_MON_SEL_SLOT8" );
266 attList.extend<std::string>(
"L1CF_MON_SEL_SLOT9" );
267 attList.extend<std::string>(
"L1CF_MON_DEC_SLOT7" );
268 attList.extend<std::string>(
"L1CF_MON_DEC_SLOT8" );
269 attList.extend<std::string>(
"L1CF_MON_DEC_SLOT9" );
276 throw std::runtime_error(
"CTPFilesLoader >> CTPFiles not available" );
280 std::string
name =
row[
"L1CF_NAME"].data<std::string>();
281 int version =
row[
"L1CF_VERSION"].data<
int>();
282 std::string strMonSel7 =
row[
"L1CF_MON_SEL_SLOT7"].data<std::string>();
283 std::string strMonSel8 =
row[
"L1CF_MON_SEL_SLOT8"].data<std::string>();
284 std::string strMonSel9 =
row[
"L1CF_MON_SEL_SLOT9"].data<std::string>();
285 std::string strMonDec7 =
row[
"L1CF_MON_DEC_SLOT7"].data<std::string>();
286 std::string strMonDec8 =
row[
"L1CF_MON_DEC_SLOT8"].data<std::string>();
287 std::string strMonDec9 =
row[
"L1CF_MON_DEC_SLOT9"].data<std::string>();
292 throw std::runtime_error(
"CTPFilesLoader >> CTPFiles not available" );
295 std::vector<u_int> monDecSlot7(CTPFiles::ALL_CTPINMONDEC_SIZE);
296 TRG_MSG_INFO(
"Loading MON Slot7 of size " << monDecSlot7.size());
297 parseHexString(monDecSlot7,strMonDec7);
298 std::vector<u_int> monDecSlot8(CTPFiles::ALL_CTPINMONDEC_SIZE);
299 TRG_MSG_INFO(
"Loading MON Slot8 of size " << monDecSlot8.size());
300 parseHexString(monDecSlot8,strMonDec8);
301 std::vector<u_int> monDecSlot9(CTPFiles::ALL_CTPINMONDEC_SIZE);
302 TRG_MSG_INFO(
"Loading MON Slot9 of size " << monDecSlot9.size());
303 parseHexString(monDecSlot9,strMonDec9);
305 std::vector<u_int> monSelSlot7(CTPFiles::ALL_CTPINMONSEL_SIZE);
306 TRG_MSG_INFO(
"Loading MON SEL Slot7 of size " << monSelSlot7.size());
307 parseHexString(monSelSlot7,strMonSel7);
308 std::vector<u_int> monSelSlot8(CTPFiles::ALL_CTPINMONSEL_SIZE);
309 TRG_MSG_INFO(
"Loading MON SEL Slot8 of size " << monSelSlot8.size());
310 parseHexString(monSelSlot8,strMonSel8);
311 std::vector<u_int> monSelSlot9(CTPFiles::ALL_CTPINMONSEL_SIZE);
312 TRG_MSG_INFO(
"Loading MON SEL Slot9 of size " << monSelSlot9.size());
313 parseHexString(monSelSlot9,strMonSel9);
327 unique_ptr<coral::IQuery>
query( m_session.nominalSchema().tableHandle(
"L1_CTP_SMX").newQuery() );
328 query->setRowCacheSize( 13 );
332 std::string
condition =
"L1SMX_ID = :sId";
333 emptyBindVariableList0.extend<
long>(
"sId");
334 emptyBindVariableList0[0].data<
long>() = ctpFiles.
smxId();
338 attList.extend<std::string>(
"L1SMX_NAME" );
339 attList.extend<std::string>(
"L1SMX_OUTPUT" );
340 attList.extend<std::string>(
"L1SMX_VHDL_SLOT7" );
341 attList.extend<std::string>(
"L1SMX_VHDL_SLOT8" );
342 attList.extend<std::string>(
"L1SMX_VHDL_SLOT9" );
343 attList.extend<std::string>(
"L1SMX_SVFI_SLOT7" );
344 attList.extend<std::string>(
"L1SMX_SVFI_SLOT8" );
345 attList.extend<std::string>(
"L1SMX_SVFI_SLOT9" );
352 throw std::runtime_error(
"CTPFilesLoader >> CTPFiles not available" );
369 catch(
const coral::Exception&
e ) {
385 if(ctpFiles.
id() <= 0) {
387 int menuid = getMenuIdFromMaster(l1id);
388 long filesid = getFilesIdFromMenu(menuid);
389 ctpFiles.
setId(filesid);
392 unique_ptr<coral::IQuery>
query( m_session.nominalSchema().tableHandle(
"L1_CTP_FILES").newQuery() );
393 query->setRowCacheSize( 13 );
397 std::string
condition =
"L1CF_ID = :fId";
398 emptyBindVariableList0.extend<
long>(
"fId");
399 emptyBindVariableList0[0].data<
long>() = ctpFiles.
id();
403 attList.extend<std::string>(
"L1CF_NAME" );
404 attList.extend<
int>(
"L1CF_VERSION" );
405 attList.extend<std::string>(
"L1CF_MON_SEL_CTPMON" );
406 attList.extend<std::string>(
"L1CF_MON_DEC_CTPMON" );
414 throw std::runtime_error(
"CTPFilesLoader >> CTPFiles not available" );
419 std::string
name =
row[
"L1CF_NAME"].data<std::string>();
420 int version =
row[
"L1CF_VERSION"].data<
int>();
421 std::string ctpmonSelector_str =
row[
"L1CF_MON_SEL_CTPMON"].data<std::string>();
422 std::string ctpmonDecoder_str =
row[
"L1CF_MON_DEC_CTPMON"].data<std::string>();
427 throw std::runtime_error(
"CTPFilesLoader >> CTPFiles not available" );
430 std::vector<u_int> monDecVec(CTPFiles::ALL_CTPMONDECODER_SIZE);
431 TRG_MSG_INFO(
"Loading MON DEC vec of size " << monDecVec.size());
432 parseHexString(monDecVec,ctpmonDecoder_str);
436 std::vector<u_int> monSelVec(CTPFiles::ALL_CTPMONSELECTOR_SIZE);
437 std::stringstream
stream(ctpmonSelector_str);
443 std::string::size_type loc =
val.find(
"0x");
444 if(loc != std::string::npos)
val.replace(loc,2,
"");
445 if(!convert_string<u_int>(
data,
val)) {
448 throw std::runtime_error(
"CTPFilesLoader >> CTPMONSELECTOR conversion failed." );
450 if(
index >= CTPFiles::ALL_CTPMONSELECTOR_SIZE) {
453 throw std::runtime_error(
"CTPFilesLoader >> CTPMONSELECTOR conversion failed." );
467 catch(
const coral::Exception&
e ) {
478 const static u_int significantBits = 8;
479 const static u_int preFix = 2;
480 const static u_int postFix = 1;
481 const static u_int wordsize = (preFix + significantBits + postFix);
483 if(
str.size() != 0) {
484 if(
str.size() != wordsize *
vec.size()) {
485 TRG_MSG_ERROR(
"File content from DB of size " <<
str.size() <<
", but expects " << wordsize *
vec.size() <<
" [11 * " <<
vec.size() <<
"]");
486 throw std::runtime_error(
"CTPFilesLoader: file of unexpected size" );
489 TRG_MSG_INFO(
"DB File content is 0, which is expected for MC, Reprocessing, and ATN databases");
493 for(u_int
i=0;
i <
vec.size(); ++
i) {
494 if( ! convert_hex_string<u_int>(
data,
str.substr(
i*wordsize+preFix,significantBits))) {
497 throw std::runtime_error(
"CTPFilesLoader >> Conversion failed." );