ATLAS Offline Software
MCKLoader.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 #include <CoralBase/Attribute.h>
7 #include <CoralBase/AttributeList.h>
8 
9 #include <string>
10 #include "./DBHelper.h"
11 
12 using namespace std;
13 
15  DBLoader("MCKLoader", sm, sm.sessionMgr().createSession())
16 {}
17 
18 bool
19 TrigConf::MCKLoader::loadMCKlinkedToSMK(unsigned int smk, unsigned int & mck)
20 {
21 
22  unique_ptr< coral::IQuery > q;
23 
24  startSession();
25 
26  try {
27  unique_ptr< coral::IQuery > qtmp( m_session.nominalSchema().tableHandle( "MCK_TO_SMK_LINK").newQuery() );
28  q = std::move(qtmp);
29  }
30  catch(coral::TableNotExistingException & ex) {
31  TRG_MSG_WARNING("MAM tables not found in this trigger database");
32  return false;
33  }
34 
35  std::string theCondition = "SMK_LINK_SMK = :smId";
36  theCondition += string( " AND SMK_LINK_ACTIVE_MCK = 1" );
37 
38  coral::AttributeList bindings;
39  bindings.extend<int>("smId");
40  bindings[0].data<int>() = smk;
41 
42  q->setCondition( theCondition, bindings );
43 
44  coral::AttributeList attList;
45  attList.extend<int>( "SMK_LINK_MCK" );
46 
47  fillQuery(q.get(), attList);
48 
49  coral::ICursor& cursor = q->execute();
50 
51  int nFound(0);
52  while (cursor.next()) {
53  ++nFound;
54  const coral::AttributeList& row = cursor.currentRow();
55  mck = row["SMK_LINK_MCK"].data<int>();
56  }
57  commitSession();
58 
59  if(nFound>1) {
60  TRG_MSG_ERROR("Found more than one active MCKs for SMK " << smk);
61  } else if(nFound==1) {
62  TRG_MSG_INFO("Found active MCK " << mck << " for SMK " << smk);
63  } else {
64  TRG_MSG_INFO("Found no active MCK for SMK " << smk);
65  }
66  return nFound==1;
67 }
68 
69 bool
70 TrigConf::MCKLoader::loadReleaseLinkedToMCK(unsigned int mck, std::string & mck_release)
71 {
72  //load athena release (when MCK!=0)
73 
74  if ( mck == 0 ){
75  TRG_MSG_ERROR("No release exists for MCK 0");
76  return false;
77  }
78 
79  startSession();
80 
81  unique_ptr< coral::IQuery > q;
82 
83  try {
84  unique_ptr< coral::IQuery > qtmp( m_session.nominalSchema().tableHandle( "MCK_TABLE").newQuery() );
85  q = std::move(qtmp);
86  }
87  catch(coral::TableNotExistingException & ex) {
88  TRG_MSG_WARNING("MAM tables not found in this trigger database");
89  return false;
90  }
91 
92  coral::AttributeList bindings;
93  bindings.extend<int>("mck");
94  bindings[0].data<int>() = mck;
95 
96  q->setCondition( "MCK_ID = :mck", bindings );
97 
98  coral::AttributeList attList;
99  attList.extend<std::string> ( "MCK_ATHENA_VERSION" );
100 
101  fillQuery(q.get(), attList);
102 
103  coral::ICursor& cursor = q->execute();
104 
105  int nFound(0);
106  while (cursor.next()) {
107  ++nFound;
108  const coral::AttributeList& row = cursor.currentRow();
109  mck_release = row["MCK_ATHENA_VERSION"].data<std::string>();
110  }
111  commitSession();
112 
113  if(nFound>1) {
114  TRG_MSG_ERROR("Found more than one release for MCK " << mck);
115  } else if(nFound==1) {
116  TRG_MSG_INFO("Found release " << mck_release << " for MCK " << mck);
117  } else {
118  TRG_MSG_INFO("Found no release for MCK " << mck);
119  }
120  return nFound==1;
121 
122 }
123 
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
TrigConf::MCKLoader::loadReleaseLinkedToMCK
bool loadReleaseLinkedToMCK(unsigned int mck, std::string &mck_release)
Definition: MCKLoader.cxx:70
RunEBWeightsComputation.smk
smk
Definition: RunEBWeightsComputation.py:87
DBHelper.h
TrigConf::fillQuery
void fillQuery(coral::IQuery *q, coral::AttributeList &attList)
Definition: DBHelper.cxx:13
python.PyKernel.AttributeList
AttributeList
Definition: PyKernel.py:36
TrigConf::StorageMgr
Database Storage Manager, controls the database session and the different loader classes for DB acces...
Definition: StorageMgr.h:23
TrigConf::DBLoader
Base class for loaders of configurations from the TriggerDB.
Definition: DBLoader.h:20
MCKLoader.h
TRG_MSG_INFO
#define TRG_MSG_INFO(x)
Definition: Trigger/TrigConfiguration/TrigConfBase/TrigConfBase/MsgStreamMacros.h:27
TRG_MSG_WARNING
#define TRG_MSG_WARNING(x)
Definition: Trigger/TrigConfiguration/TrigConfBase/TrigConfBase/MsgStreamMacros.h:28
query_example.cursor
cursor
Definition: query_example.py:21
TrigConf::MCKLoader::MCKLoader
MCKLoader(StorageMgr &sm)
Definition: MCKLoader.cxx:14
extractSporadic.q
list q
Definition: extractSporadic.py:98
TrigConf::MCKLoader::loadMCKlinkedToSMK
bool loadMCKlinkedToSMK(unsigned int smk, unsigned int &mck)
Definition: MCKLoader.cxx:19