ATLAS Offline Software
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 
30 #include "TrigConfL1Data/LutCam.h"
31 
32 #include <stdexcept>
33 #include <typeinfo>
34 
35 bool
37 
38  msg() << "LutCamLoader started loading data via ID. ID = " << lTarget.id() << std::endl;
39  try {
40  startSession();
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;
65  commitSession();
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;
83  commitSession();
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;
106  commitSession();
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;
120  commitSession();
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;
133  commitSession();
134  return true;
135  }
136  catch( const coral::SchemaException& e )
137  {
138  msg() << "LutCamLoader >> SchemaException: "
139  << e.what() << std::endl;
140  commitSession();
141  return false;
142  }
143  catch( const std::exception& e )
144  {
145  msg() << "LutCamLoader >> Standard C++ exception: " << e.what() << std::endl;
146  commitSession();
147  return false;
148  }
149  catch( ... )
150  {
151  msg() << "LutCamLoader >> unknown C++ exception" << std::endl;
152  commitSession();
153  return false;
154  }
155 }
TrigConf::TrigConfData::setName
void setName(const std::string &name)
Definition: TrigConfData.h:30
query_example.row
row
Definition: query_example.py:24
LutCam.h
TrigConf::LutCam::ALL_LUT_SIZE
static const u_int ALL_LUT_SIZE
Definition: LutCam.h:20
LArG4GenerateShowerLib.condition
condition
Definition: LArG4GenerateShowerLib.py:19
python.PyKernel.AttributeList
AttributeList
Definition: PyKernel.py:36
TrigConf::DBLoader::m_session
coral::ISessionProxy & m_session
CORAL interface to database session.
Definition: DBLoader.h:68
TrigConf::LutCam::setLut
void setLut(const u_int l[], const int size)
Definition: LutCam.cxx:24
query
Definition: query.py:1
lumiFormat.i
int i
Definition: lumiFormat.py:92
TrigConf::LutCam::ALL_CAM_SIZE
static const u_int ALL_CAM_SIZE
Definition: LutCam.h:21
TrigConf::TrigConfMessaging::msg
MsgStreamTC & msg() const
The standard message stream.
Definition: TrigConfMessaging.h:81
calibdata.exception
exception
Definition: calibdata.py:496
query_example.query
query
Definition: query_example.py:15
TrigConf::name
Definition: HLTChainList.h:35
TrigConf::TrigConfData::id
unsigned int id() const
Definition: TrigConfData.h:21
python.ext.table_printer.table
list table
Definition: table_printer.py:81
TrigConf::LutCam::setCam
void setCam(const u_int c[], const int size)
Definition: LutCam.cxx:35
TrigConf::DBLoader::commitSession
void commitSession()
commit session if not already done
Definition: DBLoader.cxx:45
get_generator_info.version
version
Definition: get_generator_info.py:33
DiTauMassTools::MaxHistStrategyV2::e
e
Definition: PhysicsAnalysis/TauID/DiTauMassTools/DiTauMassTools/HelperFunctions.h:26
query_example.cursor
cursor
Definition: query_example.py:21
LutCamLoader.h
TrigConf::TrigConfData::setVersion
void setVersion(unsigned int version)
Definition: TrigConfData.h:31
TrigConf::DBLoader::startSession
void startSession()
start session if not already active
Definition: DBLoader.cxx:35
TrigConf::LutCam
Definition: LutCam.h:16
TrigConf::LutCamLoader::load
virtual bool load(LutCam &data) override
Definition: LutCamLoader.cxx:36