ATLAS Offline Software
Loading...
Searching...
No Matches
LutCamLoader.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
6//
7//NAME: LutCamLoader.cpp
8//PACKAGE: TrigConfStorage
9//
10//AUTHOR: J.Haller (CERN) Johannes.Haller@cern.ch
11//CREATED: 16. Dec. 2005
12//
13//PURPOSE: This Loader loads the LutCam Object from realtional DBs
14// using RAL
15//
17
18#include "./LutCamLoader.h"
19
20#include <CoralBase/Attribute.h>
21#include <CoralBase/AttributeList.h>
22
23#include "RelationalAccess/SchemaException.h"
24#include "RelationalAccess/ITransaction.h"
25#include "RelationalAccess/ITable.h"
26#include "RelationalAccess/ISchema.h"
27#include "RelationalAccess/ICursor.h"
28#include "RelationalAccess/IQuery.h"
29
31
32#include <stdexcept>
33#include <typeinfo>
34
35bool
37
38 msg() << "LutCamLoader started loading data via ID. ID = " << lTarget.id() << std::endl;
39 try {
41 msg() << "Loading LutCam " << lTarget.id() << std::endl;
42
43 coral::ITable& table = m_session.nominalSchema().tableHandle( "L1_CTP_FILES");
44 coral::IQuery* query = table.newQuery();
45 query->setRowCacheSize( 5 );
46
47 std::string condition= "L1CF_ID = :l1cfid";
48
49 coral::AttributeList boundvars;
50 boundvars.extend<int>("l1cfid");
51 boundvars[0].data<int>() = lTarget.id();
52
53 query->setCondition( condition, boundvars );
54
55 query->addToOutputList( "L1CF_NAME" );
56 query->addToOutputList( "L1CF_VERSION" );
57 query->addToOutputList( "L1CF_LUT" );
58 query->addToOutputList( "L1CF_CAM" );
59
60 coral::ICursor& cursor = query->execute();
61
62 if ( ! cursor.next() ) {
63 msg() << "LutCamLoader >> No such L1_CTP_Files exists " << lTarget.id() << std::endl;
64 delete query;
66 throw std::runtime_error( "LutCamLoader >> LutCam not available" );
67 }
68
69 const coral::AttributeList& row = cursor.currentRow();
70
71 std::string name = "";
72 name = row["L1CF_NAME"].data<std::string>();
73 int version = 0;
74 version = row["L1CF_VERSION"].data<int>();
75 std::string lut_str ="";
76 lut_str = row["L1CF_LUT"].data<std::string>();
77 std::string cam_str ="";
78 cam_str = row["L1CF_CAM"].data<std::string>();
79
80 if ( cursor.next() ) {
81 msg() << "LutCamLoader >> More than one LutCam exists " << lTarget.id() << std::endl;
82 delete query;
84 throw std::runtime_error( "LutCamLoader >> LutCam not available" );
85 }
86
87 // transform strings to arrays of integers
88 //Local variable lut_int uses 198656 bytes of stack space
89 //coverity[STACK_USE]
90 u_int lut_int[LutCam::ALL_LUT_SIZE];
91 u_int significantBits = 8; // eight hex digits
92 u_int preFix = 2; // 0x
93 u_int postFix = 1; // termination
94 u_int wordsize = (preFix + significantBits + postFix);
95 for(u_int i=0; i<LutCam::ALL_LUT_SIZE; i++) {
96
97 u_int tmp_data;
98
99 // // this loop is extremely slow!!
100 // std::sscanf(lut_str.substr(i*wordsize,wordsize).c_str(),"%x",&data);
101 // lut_int[i]=data;
102
103 // this loop is even slower (about 20%), but at least type safe!
104 if(!convert_hex_string<u_int>(tmp_data, lut_str.substr(i*wordsize+preFix,significantBits))) {
105 msg() << "LutCamLoader>> Conversion of LUT no" << i << " failed! Read string " << lut_str.substr(i*wordsize+preFix,significantBits) << std::endl;
106 msg() << "TEST: substr(0,24): " << lut_str.substr(0,24) << " - substr(14,8): " << lut_str.substr(14,8) << " cc : " << (i*wordsize+preFix) << std::endl;
108 throw std::runtime_error( "LutCamLoader >> LUT conversion failed." );
109 }
110 lut_int[i] = tmp_data;
111 }
112 //coverity[STACK_USE]
113 u_int cam_int[LutCam::ALL_CAM_SIZE] = {90, 90, 90, 90, 90, 90};
114 for(u_int i=0; i<LutCam::ALL_CAM_SIZE; i++) {
115
116 u_int tmp_data;
117
118 // std::sscanf(cam_str.substr(i*wordsize,wordsize).c_str(),"%x",&data);
119
120 if(!convert_hex_string<u_int>(tmp_data, cam_str.substr(i*wordsize+preFix,significantBits))) {
121 msg() << "LutCamLoader>> Conversion of CAM no" << i << " failed!" << std::endl;
123 throw std::runtime_error( "LutCamLoader >> CAM conversion failed." );
124 }
125 cam_int[i]=tmp_data;
126 }
127
128 // Fill the object with data
129 lTarget.setName( name );
130 lTarget.setVersion( version );
131 lTarget.setLut(lut_int, LutCam::ALL_LUT_SIZE);
132 lTarget.setCam(cam_int, LutCam:: ALL_CAM_SIZE);
133
134 delete query;
136 return true;
137 }
138 catch( const coral::SchemaException& e )
139 {
140 msg() << "LutCamLoader >> SchemaException: "
141 << e.what() << std::endl;
143 return false;
144 }
145 catch( const std::exception& e )
146 {
147 msg() << "LutCamLoader >> Standard C++ exception: " << e.what() << std::endl;
149 return false;
150 }
151 catch( ... )
152 {
153 msg() << "LutCamLoader >> unknown C++ exception" << std::endl;
155 return false;
156 }
157}
void commitSession()
commit session if not already done
Definition DBLoader.cxx:45
coral::ISessionProxy & m_session
CORAL interface to database session.
Definition DBLoader.h:67
void startSession()
start session if not already active
Definition DBLoader.cxx:36
virtual bool load(LutCam &data) override
bool convert_hex_string(T &t, const std::string &s)
void setLut(const u_int l[], const int size)
Definition LutCam.cxx:24
static const u_int ALL_CAM_SIZE
Definition LutCam.h:21
static const u_int ALL_LUT_SIZE
Definition LutCam.h:20
void setCam(const u_int c[], const int size)
Definition LutCam.cxx:35
unsigned int id() const
void setName(const std::string &name)
void setVersion(unsigned int version)
MsgStreamTC & msg() const
The standard message stream.
Definition query.py:1