ATLAS Offline Software
TrigDBJobOptionsLoader.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include "./TrigDBHelper.h"
7 
9  TrigDBLoader("TrigDBJobOptionsLoader", connection)
10 {
11  { // query for schema version 1
12  auto & q = m_queries[1];
13  // tables
14  q.addToTableList ( "SUPER_MASTER_TABLE", "SMT" );
15  q.addToTableList ( "JO_MASTER_TABLE", "JOMT" );
16  // bind vars
17  q.extendBinding<int>("smk");
18  // conditions
19  q.extendCondition("SMT.SMT_ID = :smk");
20  q.extendCondition(" AND SMT.SMT_JO_MASTER_TABLE_ID = JOMT.JO_ID");
21  // attributes
22  q.extendOutput<std::string>( "SMT.SMT_NAME" );
23  q.extendOutput<int> ( "SMT.SMT_JO_MASTER_TABLE_ID" );
24  q.extendOutput<coral::Blob>( "JOMT.JO_CONTENT" );
25  // the field with the data
26  q.setDataName("JOMT.JO_CONTENT");
27  }
28  { // query for schema version 2
29  auto & q = m_queries[2];
30  // tables
31  q.addToTableList ( "SUPER_MASTER_TABLE", "SMT" );
32  q.addToTableList ( "HLT_JOBOPTIONS", "HJO" );
33  // bind vars
34  q.extendBinding<int>("smk");
35  // conditions
36  q.extendCondition("SMT.SMT_ID = :smk");
37  q.extendCondition("AND HJO.HJO_ID=SMT.SMT_HLT_JOBOPTIONS_ID");
38  // attributes
39  q.extendOutput<std::string>( "SMT.SMT_NAME" );
40  q.extendOutput<int> ( "SMT.SMT_HLT_JOBOPTIONS_ID" );
41  q.extendOutput<coral::Blob>( "HJO.HJO_DATA" );
42  // the field with the data
43  q.setDataName("HJO.HJO_DATA");
44  }
45 }
46 
47 // Destructor defined here because QueryDefinition is an incomplete type in the header
49 
50 bool
53  const std::string & outFileName ) const
54 {
55  auto session = createDBSession();
56  session->transaction().start( /*bool readonly=*/ true);
57  const size_t sv = schemaVersion(session.get());
58  QueryDefinition qdef = getQueryDefinition(sv, m_queries);
59  try {
60  qdef.setBoundValue<int>("smk", smk);
61  auto q = qdef.createQuery( session.get() );
62  auto & cursor = q->execute();
63  if ( ! cursor.next() ) {
64  TRG_MSG_ERROR("Tried reading HLT job options, but SuperMasterKey " << smk << " is not available" );
65  throw TrigConf::NoSMKException("TrigDBJobOptionsLoader: SMK " + std::to_string(smk) + " not available");
66  }
67  const coral::AttributeList& row = cursor.currentRow();
68  const coral::Blob& dataBlob = row[qdef.dataName()].data<coral::Blob>();
69  writeRawFile( dataBlob, outFileName );
70  blobToPtree( dataBlob, jobOptions );
71  }
72  catch(coral::QueryException & ex) {
73  TRG_MSG_ERROR("When reading HLT job options for SMK " << smk << " a coral::QueryException was caught ( " << ex.what() <<" )" );
74  throw TrigConf::QueryException("TrigDBJobOptionsLoader: " + std::string(ex.what()));
75  }
76  return true;
77 }
78 
79 
80 bool
83  const std::string & outFileName ) const
84 {
85 
86  boost::property_tree::ptree ptJobOptions;
87  loadJobOptions( smk, ptJobOptions, outFileName );
88  try {
89  jobOptions.setData(std::move(ptJobOptions));
90  }
91  catch(std::exception & ex) {
92  jobOptions.clear();
93  TRG_MSG_ERROR("When reading HLT job options for SMK " << smk << " a parsing error occured ( " << ex.what() <<" )" );
94  throw TrigConf::ParsingException("TrigDBJobOptionsLoader: parsing error " + std::string(ex.what()));
95  }
96  return true;
97 }
98 
TRG_MSG_ERROR
#define TRG_MSG_ERROR(x)
Definition: Trigger/TrigConfiguration/TrigConfBase/TrigConfBase/MsgStreamMacros.h:29
query_example.row
row
Definition: query_example.py:24
RunEBWeightsComputation.smk
smk
Definition: RunEBWeightsComputation.py:87
TrigConf::NoSMKException
Definition: Trigger/TrigConfiguration/TrigConfIO/TrigConfIO/Exceptions.h:31
TrigDBJobOptionsLoader.h
Loader class for Trigger configuration from the Trigger DB.
TrigConf::TrigDBLoader
Loader of trigger configurations from Json files.
Definition: TrigDBLoader.h:33
TrigConf::TrigDBJobOptionsLoader::m_queries
std::map< size_t, QueryDefinition > m_queries
Definition: TrigDBJobOptionsLoader.h:55
python.subdetectors.tile.Blob
Blob
Definition: tile.py:17
python.PyKernel.AttributeList
AttributeList
Definition: PyKernel.py:36
TrigConf::QueryDefinition
Definition: TrigDBHelper.h:28
TrigConf::QueryDefinition::setBoundValue
void setBoundValue(const std::string &fieldName, const T &value)
Definition: TrigDBHelper.h:75
jobOptions
Definition: jobOptions.CompareGeomDBSources.py:1
DumpGeoConfig.outFileName
string outFileName
Definition: DumpGeoConfig.py:252
calibdata.exception
exception
Definition: calibdata.py:496
TrigConf::QueryDefinition::createQuery
std::unique_ptr< coral::IQuery > createQuery(coral::ISessionProxy *session)
Definition: TrigDBHelper.cxx:10
TrigConf::TrigDBJobOptionsLoader::TrigDBJobOptionsLoader
TrigDBJobOptionsLoader(const std::string &connection)
Constructor.
Definition: TrigDBJobOptionsLoader.cxx:8
TrigConf::ParsingException
Definition: Trigger/TrigConfiguration/TrigConfIO/TrigConfIO/Exceptions.h:51
ptree
boost::property_tree::ptree ptree
Definition: JsonFileLoader.cxx:16
TrigConf::QueryException
Definition: Trigger/TrigConfiguration/TrigConfIO/TrigConfIO/Exceptions.h:21
ActsTrk::to_string
std::string to_string(const DetectorType &type)
Definition: GeometryDefs.h:34
TrigConf::DataStructure
Base class for Trigger configuration data and wrapper around underlying representation.
Definition: DataStructure.h:37
query_example.cursor
cursor
Definition: query_example.py:21
TrigConf::TrigDBJobOptionsLoader::~TrigDBJobOptionsLoader
virtual ~TrigDBJobOptionsLoader() override
Destructor - cannot be defined here because QueryDefinition is an incomplete type.
TrigConf::blobToPtree
void blobToPtree(const coral::Blob &blob, boost::property_tree::ptree &pt)
Definition: TrigDBHelper.cxx:58
TrigConf::TrigDBJobOptionsLoader::loadJobOptions
bool loadJobOptions(unsigned int smk, boost::property_tree::ptree &jobOptions, const std::string &outFileName="") const
Load content from the Trigger DB into two ptrees for a given SuperMasterKey (SMK)
Definition: TrigDBJobOptionsLoader.cxx:51
LArCellConditions.sv
bool sv
Definition: LArCellConditions.py:45
extractSporadic.q
list q
Definition: extractSporadic.py:98
TrigDBHelper.h
TrigConf::QueryDefinition::dataName
const std::string & dataName()
Definition: TrigDBHelper.h:51