ATLAS Offline Software
TGCCablingDbTool.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 "TGCCablingDbTool.h"
6 
8 
9 #include "PathResolver/PathResolver.h" // needed for readASD2PP_DIFF_12FromText()
10 #include <fstream> // needed for readASD2PP_DIFF_12FromText()
11 
12 //**********************************************************
13 //* Author Monica Verducci monica.verducci@cern.ch
14 //* Author Susumu Oda Susumu.Oda@cern.ch
15 //*
16 //* Tool to retrieve the TGC Cabling Map from COOL DB
17 //* one callback aganist the class
18 //* retrieving of tables from DB
19 //*********************************************************
20 
22  const std::string& name,
23  const IInterface* parent)
25  m_DataLocation ("keyTGC"),
26  m_ASD2PP_DIFF_12(nullptr)
27 {
28  declareInterface<ITGCCablingDbTool>(this);
29 
30  declareProperty("Folder", m_Folder="/TGC/CABLING/MAP_SCHEMA");
31 
32  // ASD2PP_diff_12.db is the text database for the TGCcabling12 package
33  declareProperty("filename_ASD2PP_DIFF_12", m_filename="ASD2PP_diff_12_ONL.db");
34  declareProperty("readASD2PP_DIFF_12FromText", m_readASD2PP_DIFF_12FromText=true);
35 }
36 
37 
38 //StatusCode TGCCablingDbTool::updateAddress(SG::TransientAddress* tad) {
41  const EventContext& /*ctx*/) {
42  CLID clid = tad->clID();
43  const std::string& key = tad->name();
44  // Need to add the CLID comparison
45  if(/* ==clid && */m_DataLocation==key) {
46  ATH_MSG_DEBUG("updateAddress OK, clid = " << clid << " key = " << key);
47  return StatusCode::SUCCESS;
48  }
49 
50  ATH_MSG_FATAL("updateAddress failed, clid = " << clid << " key = " << key);
51  return StatusCode::FAILURE;
52 }
53 
55  ATH_MSG_INFO("initialize");
56  return StatusCode::SUCCESS;
57 }
58 
60  ATH_MSG_INFO("finalize");
61 
62  // Database is deleted if exists
63  delete m_ASD2PP_DIFF_12;
64  m_ASD2PP_DIFF_12 = nullptr;
65 
66  return StatusCode::SUCCESS;
67 }
68 
69 std::string TGCCablingDbTool::getFolderName() const {
70  return m_Folder;
71 }
72 
73 std::vector<std::string>* TGCCablingDbTool::giveASD2PP_DIFF_12() {
74  ATH_MSG_INFO("giveASD2PP_DIFF_12 (m_ASD2PP_DIFF_12 is " << (!m_ASD2PP_DIFF_12 ? "NULL" : "not NULL") << ")");
75 
76  // If no database found, null pointer is returned.
77  if(!m_ASD2PP_DIFF_12) {
78  return nullptr;
79  }
80 
81  // Copy the database
82  return new std::vector<std::string> (*m_ASD2PP_DIFF_12);
83 }
84 
86  ATH_MSG_INFO("loadParameters from DB");
87 
88  StatusCode sc;
89  std::list<std::string>::const_iterator itr = keys.begin();
90  std::list<std::string>::const_iterator itr_e = keys.end();
91  for(; itr!=itr_e; ++itr) {
92  ATH_MSG_INFO("loadParameters " << (*itr) << " I=" << I << " ");
93  if((*itr)==m_Folder) {
95  }
96  }
97 
98  return sc;
99 }
100 
102  ATH_MSG_INFO("loadTGCMap from DB");
103 
105  ATH_MSG_INFO("m_readASD2PP_DIFF_12FromText is true. readASD2PP_DIFF_12FromText() will be executed with m_filename=" << m_filename.c_str());
107  if(sc.isFailure()) {
108  ATH_MSG_FATAL("could not retreive the CondAttrListCollection from DB folder " << m_Folder);
109  return sc;
110  }
111  return sc;
112  }
113 
114  // CondAttrListCollection is retrieved from COOL database
115  const CondAttrListCollection* atrc;
116  StatusCode sc = detStore()->retrieve(atrc, m_Folder);
117  if(sc.isFailure()) {
118  ATH_MSG_FATAL("could not retreive the CondAttrListCollection from DB folder " << m_Folder);
119  return sc;
120  } else {
121  ATH_MSG_INFO("CondAttrListCollection from DB folder have been obtained with size " << atrc->size());
122  }
123 
124  // Old database is deleted if exists
125  delete m_ASD2PP_DIFF_12;
126  // New database is created
127  m_ASD2PP_DIFF_12 = new std::vector<std::string>;
128 
129  // Database is copied from CondAttrListCollection to m_ASD2PP_DIFF_12
132  for(; itr!=itr_e; ++itr) {
133  const coral::AttributeList& atr=itr->second;
134 
135  std::string string_ASD2PP_DIFF_12;
136  string_ASD2PP_DIFF_12 = *(static_cast<const std::string*>((atr["data"]).addressOfData()));
137  ATH_MSG_DEBUG("Sequence load is \n" << string_ASD2PP_DIFF_12);
138 
139  // string_ASD2PP_DIFF_12 has multiple newlines and will be separated into multiple lines (strings)
140  unsigned int length = string_ASD2PP_DIFF_12.length();
141  while(length>0) {
142  unsigned int newLine = string_ASD2PP_DIFF_12.find('\n');
143  if(length>newLine) {
144  m_ASD2PP_DIFF_12->push_back(string_ASD2PP_DIFF_12.substr(0, newLine));
145  string_ASD2PP_DIFF_12.erase(0, newLine+1);
146  }
147  length = string_ASD2PP_DIFF_12.length();
148  };
149  }
150 
151  return StatusCode::SUCCESS;
152 }
153 
155  ATH_MSG_INFO("readTGCMap from text");
156 
157  // PathResolver finds the full path of the file (default file name is ASD2PP_diff_12.db)
158  std::string location = PathResolver::find_file(m_filename, "DATAPATH");
159  if(location=="") {
160  ATH_MSG_FATAL("Could not find " << m_filename.c_str());
161  return StatusCode::FAILURE;
162  }
163 
164  // ASD2PP_diff_12.db is opened as inASDToPP
165  std::ifstream inASDToPP;
166  inASDToPP.open(location.c_str());
167  if(inASDToPP.bad()) {
168  ATH_MSG_FATAL("Could not open file " << location.c_str());
169  return StatusCode::FAILURE;
170  }
171 
172  ATH_MSG_INFO("readTGCMap found file " << location.c_str());
173 
174  // Old database is deleted if exists
175  delete m_ASD2PP_DIFF_12;
176  // New database is created
177  m_ASD2PP_DIFF_12 = new std::vector<std::string>;
178 
179  unsigned int nLines = 0;
180  std::string buf;
181  // Copy database into m_ASD2PP_DIFF_12
182  while(getline(inASDToPP, buf)){
183  m_ASD2PP_DIFF_12->push_back(buf);
184  ATH_MSG_DEBUG(m_filename.c_str() << " L" << ++nLines << ": " << buf.c_str());
185  }
186 
187  inASDToPP.close();
188  return StatusCode::SUCCESS;
189 }
TGCCablingDbTool::giveASD2PP_DIFF_12
virtual std::vector< std::string > * giveASD2PP_DIFF_12()
Method to provide database.
Definition: TGCCablingDbTool.cxx:73
CondAttrListCollection::end
const_iterator end() const
Definition: CondAttrListCollection.h:315
TGCCablingDbTool::m_Folder
std::string m_Folder
Folder name.
Definition: TGCCablingDbTool.h:49
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
CondAttrListCollection.h
This file defines the class for a collection of AttributeLists where each one is associated with a ch...
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
PathResolver::find_file
static std::string find_file(const std::string &logical_file_name, const std::string &search_path, SearchType search_type=LocalSearch)
Definition: PathResolver.cxx:251
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
TGCCablingDbTool::m_readASD2PP_DIFF_12FromText
bool m_readASD2PP_DIFF_12FromText
Flag for readASD2PP_DIFF_12FromText()
Definition: TGCCablingDbTool.h:55
SG::TransientAddress
Definition: TransientAddress.h:32
CondAttrListCollection::begin
const_iterator begin() const
Access to Chan/AttributeList pairs via iterators.
Definition: CondAttrListCollection.h:309
TGCCablingDbTool::readASD2PP_DIFF_12FromText
virtual StatusCode readASD2PP_DIFF_12FromText()
Load parameters from text database.
Definition: TGCCablingDbTool.cxx:154
TGCCablingDbTool::getFolderName
virtual std::string getFolderName() const
Get the folder name.
Definition: TGCCablingDbTool.cxx:69
IOVSVC_CALLBACK_ARGS_P
#define IOVSVC_CALLBACK_ARGS_P(I, K)
short hand for IOVSvc call back argument list, to be used when access to formal arguments is needed,...
Definition: IOVSvcDefs.h:42
python.PyKernel.AttributeList
AttributeList
Definition: PyKernel.py:36
TGCCablingDbTool::loadParameters
virtual StatusCode loadParameters(IOVSVC_CALLBACK_ARGS)
Load parameters using IOV keys.
Definition: TGCCablingDbTool.cxx:85
CondAttrListCollection
This class is a collection of AttributeLists where each one is associated with a channel number....
Definition: CondAttrListCollection.h:52
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
AthCommonDataStore< AthCommonMsg< AlgTool > >::detStore
const ServiceHandle< StoreGateSvc > & detStore() const
The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:95
TGCCablingDbTool.h
SG::TransientAddress::name
const std::string & name() const
Get the primary (hashed) SG key.
Definition: TransientAddress.h:208
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
TGCCablingDbTool::updateAddress
virtual StatusCode updateAddress(StoreID::type storeID, SG::TransientAddress *tad, const EventContext &ctx)
Required by the IAddressProvider interface.
Definition: TGCCablingDbTool.cxx:39
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
python.sizes.location
string location
Definition: sizes.py:11
SG::TransientAddress::clID
CLID clID() const
Retrieve string key:
Definition: TransientAddress.h:201
TGCCablingDbTool::finalize
virtual StatusCode finalize()
Finalize.
Definition: TGCCablingDbTool.cxx:59
TGCCablingDbTool::TGCCablingDbTool
TGCCablingDbTool(const std::string &type, const std::string &name, const IInterface *parent)
Constructor.
Definition: TGCCablingDbTool.cxx:21
test_pyathena.parent
parent
Definition: test_pyathena.py:15
CLID
uint32_t CLID
The Class ID type.
Definition: Event/xAOD/xAODCore/xAODCore/ClassID_traits.h:47
TGCCablingDbTool::initialize
virtual StatusCode initialize()
Initilize.
Definition: TGCCablingDbTool.cxx:54
PathResolver.h
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:192
CondAttrListCollection::size
size_type size() const
number of Chan/AttributeList pairs
Definition: CondAttrListCollection.h:322
StoreID::type
type
Definition: StoreID.h:24
TGCCablingDbTool::loadASD2PP_DIFF_12
virtual StatusCode loadASD2PP_DIFF_12(IOVSVC_CALLBACK_ARGS)
Load parameters using the folder name.
Definition: TGCCablingDbTool.cxx:101
CondAttrListCollection::const_iterator
ChanAttrListMap::const_iterator const_iterator
Definition: CondAttrListCollection.h:63
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
TGCCablingDbTool::m_ASD2PP_DIFF_12
std::vector< std::string > * m_ASD2PP_DIFF_12
Database as strings.
Definition: TGCCablingDbTool.h:52
TGCCablingDbTool::m_DataLocation
std::string m_DataLocation
Data location.
Definition: TGCCablingDbTool.h:47
python.Bindings.keys
keys
Definition: Control/AthenaPython/python/Bindings.py:790
I
#define I(x, y, z)
Definition: MD5.cxx:116
AthAlgTool
Definition: AthAlgTool.h:26
length
double length(const pvec &v)
Definition: FPGATrackSimLLPDoubletHoughTransformTool.cxx:26
TGCCablingDbTool::m_filename
std::string m_filename
File name of the text database.
Definition: TGCCablingDbTool.h:57
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37