ATLAS Offline Software
Loading...
Searching...
No Matches
LutCamLoader.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2017 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
89 u_int lut_int[LutCam::ALL_LUT_SIZE];
90 u_int significantBits = 8; // eight hex digits
91 u_int preFix = 2; // 0x
92 u_int postFix = 1; // termination
93 u_int wordsize = (preFix + significantBits + postFix);
94 for(u_int i=0; i<LutCam::ALL_LUT_SIZE; i++) {
95
96 u_int tmp_data;
97
98 // // this loop is extremely slow!!
99 // std::sscanf(lut_str.substr(i*wordsize,wordsize).c_str(),"%x",&data);
100 // lut_int[i]=data;
101
102 // this loop is even slower (about 20%), but at least type safe!
103 if(!convert_hex_string<u_int>(tmp_data, lut_str.substr(i*wordsize+preFix,significantBits))) {
104 msg() << "LutCamLoader>> Conversion of LUT no" << i << " failed! Read string " << lut_str.substr(i*wordsize+preFix,significantBits) << std::endl;
105 msg() << "TEST: substr(0,24): " << lut_str.substr(0,24) << " - substr(14,8): " << lut_str.substr(14,8) << " cc : " << (i*wordsize+preFix) << std::endl;
107 throw std::runtime_error( "LutCamLoader >> LUT conversion failed." );
108 }
109 lut_int[i] = tmp_data;
110 }
111 u_int cam_int[LutCam::ALL_CAM_SIZE] = {90, 90, 90, 90, 90, 90};
112 for(u_int i=0; i<LutCam::ALL_CAM_SIZE; i++) {
113
114 u_int tmp_data;
115
116 // std::sscanf(cam_str.substr(i*wordsize,wordsize).c_str(),"%x",&data);
117
118 if(!convert_hex_string<u_int>(tmp_data, cam_str.substr(i*wordsize+preFix,significantBits))) {
119 msg() << "LutCamLoader>> Conversion of CAM no" << i << " failed!" << std::endl;
121 throw std::runtime_error( "LutCamLoader >> CAM conversion failed." );
122 }
123 cam_int[i]=tmp_data;
124 }
125
126 // Fill the object with data
127 lTarget.setName( name );
128 lTarget.setVersion( version );
129 lTarget.setLut(lut_int, LutCam::ALL_LUT_SIZE);
130 lTarget.setCam(cam_int, LutCam:: ALL_CAM_SIZE);
131
132 delete query;
134 return true;
135 }
136 catch( const coral::SchemaException& e )
137 {
138 msg() << "LutCamLoader >> SchemaException: "
139 << e.what() << std::endl;
141 return false;
142 }
143 catch( const std::exception& e )
144 {
145 msg() << "LutCamLoader >> Standard C++ exception: " << e.what() << std::endl;
147 return false;
148 }
149 catch( ... )
150 {
151 msg() << "LutCamLoader >> unknown C++ exception" << std::endl;
153 return false;
154 }
155}
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
void startSession()
start session if not already active
Definition DBLoader.cxx:35
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