ATLAS Offline Software
TGCCablingDbTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include "TGCCablingDbTool.h"
6 
7 #include "PathResolver/PathResolver.h" // needed for readASD2PP_DIFF_12FromText()
8 #include <fstream> // needed for readASD2PP_DIFF_12FromText()
9 
10 //**********************************************************
11 //* Author Monica Verducci monica.verducci@cern.ch
12 //* Author Susumu Oda Susumu.Oda@cern.ch
13 //*
14 //* Tool to retrieve the TGC Cabling Map from COOL DB
15 //* one callback aganist the class
16 //* retrieving of tables from DB
17 //*********************************************************
18 
20  const std::string& name,
21  const IInterface* parent)
22  : base_class(type, name, parent),
23  m_DataLocation ("keyTGC")
24 {
25  declareProperty("Folder", m_Folder="/TGC/CABLING/MAP_SCHEMA");
26 
27  // ASD2PP_diff_12.db is the text database for the TGCcabling12 package
28  declareProperty("filename_ASD2PP_DIFF_12", m_filename="ASD2PP_diff_12_ONL.db");
29  declareProperty("readASD2PP_DIFF_12FromText", m_readASD2PP_DIFF_12FromText=true);
30 }
31 
33  ATH_MSG_INFO("initialize");
34  return StatusCode::SUCCESS;
35 }
36 
37 std::string TGCCablingDbTool::getFolderName() const {
38  return m_Folder;
39 }
40 
41 std::vector<std::string>* TGCCablingDbTool::giveASD2PP_DIFF_12() {
42  ATH_MSG_INFO("giveASD2PP_DIFF_12 (m_ASD2PP_DIFF_12 is " << (!m_ASD2PP_DIFF_12 ? "NULL" : "not NULL") << ")");
43 
44  // If no database found, null pointer is returned.
45  if(!m_ASD2PP_DIFF_12) {
46  return nullptr;
47  }
48 
49  // Copy the database
50  return new std::vector<std::string> (*m_ASD2PP_DIFF_12);
51 }
52 
54  ATH_MSG_INFO("readTGCMap from text");
55 
56  // PathResolver finds the full path of the file (default file name is ASD2PP_diff_12.db)
57  std::string location = PathResolver::find_file(m_filename, "DATAPATH");
58  if(location.empty()) {
59  ATH_MSG_ERROR("Could not find " << m_filename.c_str());
60  return StatusCode::FAILURE;
61  }
62 
63  // ASD2PP_diff_12.db is opened as inASDToPP
64  std::ifstream inASDToPP;
65  inASDToPP.open(location.c_str());
66  if(inASDToPP.bad()) {
67  ATH_MSG_ERROR("Could not open file " << location.c_str());
68  return StatusCode::FAILURE;
69  }
70 
71  ATH_MSG_INFO("readTGCMap found file " << location.c_str());
72 
73  // New database is created
74  m_ASD2PP_DIFF_12.reset(new std::vector<std::string>);
75 
76  unsigned int nLines = 0;
77  std::string buf;
78  // Copy database into m_ASD2PP_DIFF_12
79  while(getline(inASDToPP, buf)){
80  m_ASD2PP_DIFF_12->push_back(buf);
81  ATH_MSG_DEBUG(m_filename.c_str() << " L" << ++nLines << ": " << buf.c_str());
82  }
83 
84  inASDToPP.close();
85  return StatusCode::SUCCESS;
86 }
TGCCablingDbTool::getFolderName
virtual std::string getFolderName() const override
Get the folder name.
Definition: TGCCablingDbTool.cxx:37
TGCCablingDbTool::m_Folder
std::string m_Folder
Folder name.
Definition: TGCCablingDbTool.h:37
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
TGCCablingDbTool::m_readASD2PP_DIFF_12FromText
bool m_readASD2PP_DIFF_12FromText
Flag for readASD2PP_DIFF_12FromText()
Definition: TGCCablingDbTool.h:43
TGCCablingDbTool::initialize
virtual StatusCode initialize() override
Initilize.
Definition: TGCCablingDbTool.cxx:32
TGCCablingDbTool::m_ASD2PP_DIFF_12
std::unique_ptr< std::vector< std::string > > m_ASD2PP_DIFF_12
Database as strings.
Definition: TGCCablingDbTool.h:40
TGCCablingDbTool.h
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
TGCCablingDbTool::TGCCablingDbTool
TGCCablingDbTool(const std::string &type, const std::string &name, const IInterface *parent)
Constructor.
Definition: TGCCablingDbTool.cxx:19
test_pyathena.parent
parent
Definition: test_pyathena.py:15
TGCCablingDbTool::readASD2PP_DIFF_12FromText
virtual StatusCode readASD2PP_DIFF_12FromText() override
Load parameters from text database.
Definition: TGCCablingDbTool.cxx:53
PathResolver.h
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
TGCCablingDbTool::giveASD2PP_DIFF_12
virtual std::vector< std::string > * giveASD2PP_DIFF_12() override
Method to provide database.
Definition: TGCCablingDbTool.cxx:41
TGCCablingDbTool::m_filename
std::string m_filename
File name of the text database.
Definition: TGCCablingDbTool.h:45