ATLAS Offline Software
NSWAGDDTool.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 "NSWAGDDTool.h"
6 
7 #include "MuonAGDDToolHelper.h"
14 
15 #include <fstream>
16 
17 using namespace MuonGM;
18 
19 NSWAGDDTool::NSWAGDDTool(const std::string& type, const std::string& name, const IInterface* parent) :
21  m_outFileInName(""),
22  m_outPREsqlName("") {
23 }
24 
26 {
28  ATH_MSG_INFO("NSWAGDDTool::initialize");
29 
30  if( m_xmlFiles.size() == 1 && m_writeDBfile )
31  {
32  std::size_t found = m_xmlFiles[0].find_last_of('/');
33  m_outFileInName = m_xmlFiles[0].substr(found+1);
34  }
35  else if ( m_writeDBfile ) ATH_MSG_ERROR("writing data base files currently only supported if just a single input XML is given!");
36 
37  m_outFileName = "Out.AmdcOracle.AM." + m_outFileType + "temp.data";
38  m_outPREsqlName = "Out.AmdcOracle.AM." + m_outFileType + ".PREsql";
39 
40  if (m_DBFileName.empty()) {
41  m_DBFileName = "Generated_" + m_outFileType + "_pool.txt";
42  }
43 
44  static std::once_flag init;
45  std::call_once (init, [&]()
46  {
47  MuonAGDDToolHelper theHelper;
48  theHelper.setAGDDtoGeoSvcName(m_agdd2GeoSvcName);
49  theHelper.SetNSWComponents();
50  });
51 
52  ATH_CHECK(construct());
53  return StatusCode::SUCCESS;
54 }
55 
56 // Base class method is also marked not thread-safe.
57 // Uses unsafe function UseGeoModelDetector
58 StatusCode NSWAGDDTool::construct ATLAS_NOT_THREAD_SAFE ()
59 {
60  ATH_MSG_INFO(name()<<"::construct()");
61 
62  IAGDDtoGeoSvc::LockedController controller = m_svc->getController();
63  MuonAGDDToolHelper theHelper;
64  theHelper.setAGDDtoGeoSvcName(m_agdd2GeoSvcName);
65  if (!m_readAGDD)
66  {
67  ATH_MSG_INFO(" trying to parse files ");
68  controller->ParseFiles();
69  }
70  else
71  {
72  ATH_MSG_INFO(" trying to parse data base content ");
73  std::string AGDDfile = theHelper.GetAGDD(m_dumpAGDD, m_outFileType, m_DBFileName);
74  controller->ParseString(AGDDfile);
75  }
76 
77  if (m_printSections)
78  {
79  ATH_MSG_INFO("\t Printing all sections ");
80  controller->PrintSections();
81  }
82 
83  controller->UseGeoModelDetector("Muon");
84  controller->BuildAll();
85 
86  // part needed to build the NSW RO geometry
87 
88  ATH_MSG_INFO("\t Building NSW Readout Geometry ");
90  if (!testRet)
91  {
92  ATH_MSG_ERROR("something went wrong building the RO geometry!!! ");
93  return StatusCode::FAILURE;
94  }
95 
96  if(m_writeDBfile)
97  {
98  // build model before writing blob - if Athena crashes the XML is not good and should not become a blob
99  ATH_MSG_INFO("\t-- attempting to write output to "<< m_outFileName );
100  if( !m_outFileName.empty() )
101  {
102  if(!controller->WriteAGDDtoDBFile( m_outFileName ))
103  {
104  ATH_MSG_ERROR("\t-- something went wrong during writing AGDD file - crashing" );
105  return StatusCode::FAILURE;
106  }
107  else {
108  ATH_MSG_INFO("\t-- AGDD successfully dumped to "<< m_outFileName);
109  }
110  if( !WritePREsqlFile() )
111  {
112  ATH_MSG_ERROR("\t-- something went wrong during writing PREsql file - crashing" );
113  return StatusCode::FAILURE;
114  }
115  else {
116  ATH_MSG_INFO("\t-- AGDD successfully wrote PREsql file "<< m_outPREsqlName);
117  }
118  }
119  else {
120  ATH_MSG_ERROR("\t-- no output file name provided - crashing " );
121  return StatusCode::FAILURE;
122  }
123  }
124 
125  controller->Clean();
126 
127  return StatusCode::SUCCESS;
128 }
129 
131 {
132 
133  std::ifstream outfile(m_outFileName.value().c_str(), std::ifstream::in | std::ifstream::binary);
134 
135  std::vector<std::string> newoutfilelines;
136  std::string outfileline;
137  while( getline(outfile, outfileline) )
138  if( outfileline != "\n" && outfileline != "\r" && !outfileline.empty() )
139  {
140  const auto strBegin = outfileline.find_first_not_of(" \t");
141  const auto strEnd = outfileline.find_last_not_of(" \t");
142  const auto strRange = strEnd - strBegin + 1;
143  if (strBegin != std::string::npos) outfileline = outfileline.substr(strBegin, strRange);
144  newoutfilelines.push_back(outfileline);
145  }
146  outfile.close();
147 
148  std::ofstream newoutfile(m_outFileName.value().c_str(), std::ofstream::out | std::ofstream::trunc);
149  for(auto it = newoutfilelines.begin(); it != newoutfilelines.end(); ++it)
150  {
151  if(it != newoutfilelines.begin()) newoutfile << "\n";
152  newoutfile << *it;
153  }
154  newoutfile.close();
155  outfile.open(m_outFileName.value().c_str(), std::ifstream::in | std::ifstream::binary);
156 
157  int fileSize = 0;
158  if(outfile.is_open())
159  {
160  outfile.seekg(0, std::ios::end);
161  fileSize = outfile.tellg();
162  outfile.close();
163  }
164  else {
165  ATH_MSG_ERROR("\t-- cannot get size of file " << m_outFileName );
166  return false;
167  }
168 
169  std::ofstream prefile;
170  prefile.open (m_outPREsqlName.c_str());
171  prefile << "insert into NSWD_data (\n";
172  prefile << "NSWD_data_id,\n";
173  prefile << "ACTVERS,\n";
174  prefile << "ACTVNAME,\n";
175  prefile << "ALGVERS,\n";
176  prefile << "ALGVNAME,\n";
177  prefile << "PASVERS,\n";
178  prefile << "PASVNAME,\n";
179  prefile << "FORMAT,\n";
180  prefile << "FNAME,\n";
181  prefile << "LENNSW,\n";
182  prefile << "NLINE,\n";
183  prefile << "data\n";
184  prefile << ") values (XXX_DATA_ID_KOUNTER,\n";
185  prefile << m_outFileActV << ",'" << m_outFileActN << "',";
186  prefile << m_outFileAlgV << ",'" << m_outFileAlgN << "',";
187  prefile << m_outFilePasV << ",'" << m_outFilePasN << "',\n";
188  prefile << "'" << m_outFileForm <<"','" << m_outFileInName << "',"<< fileSize-1 << ","<< int( (fileSize + 2) / 4 )<<",\n";
189  prefile << "empty_clob()\n";
190  prefile << ");\n";
191  prefile << "insert into NSWD_data2tag values (XXX_DATA2TAG_KOUNTER,XXX_DATA_ID_KOUNTER);\n";
192  prefile << "DECLARE\n";
193  prefile << " lobloc CLOB;\n";
194  prefile << " req utl_http.req;\n";
195  prefile << " resp utl_http.resp;\n";
196  prefile << " text VARCHAR2(32767);\n";
197  prefile << " amount INTEGER(10) := 0;\n";
198  prefile << " offset INTEGER(10) := 0;\n";
199  prefile << " TRUE BOOLEAN;\n";
200  prefile << "BEGIN\n";
201  prefile << " SELECT data INTO lobloc\n";
202  prefile << " FROM NSWD_data\n";
203  prefile << " WHERE NSWD_data_id = XXX_DATA_ID_KOUNTER FOR UPDATE;\n";
204  prefile << " offset := DBMS_LOB.GETLENGTH(lobloc)+2;\n";
205  prefile << " req := utl_http.begin_request(\n";
206  prefile << " 'WEB_ADDRESS_FOR_TEMP_DATA_FILENSWDtemp.data');\n";
207  prefile << " resp := utl_http.get_response(req);\n";
208  prefile << " LOOP\n";
209  prefile << " text := ' ';\n";
210  prefile << " UTL_HTTP.READ_TEXT(resp, text, NULL);\n";
211  prefile << " /* DBMS_OUTPUT.PUT_LINE(text); */\n";
212  prefile << " amount := length(text);\n";
213  prefile << " DBMS_LOB.WRITEAPPEND(lobloc,amount,text);\n";
214  prefile << " END LOOP;\n";
215  prefile << " utl_http.end_response(resp);\n";
216  prefile << " EXCEPTION\n";
217  prefile << " WHEN utl_http.end_of_body\n";
218  prefile << " THEN utl_http.end_response(resp);\n";
219  prefile << "END;\n";
220  prefile << "/\n";
221  prefile.close();
222 
223  return true;
224 
225 }
226 
227 
228 
AGDDController.h
AGDDDetectorStore.h
AGDDToolBase
Definition: AGDDToolBase.h:17
MuonGM
Ensure that the Athena extensions are properly loaded.
Definition: GeoMuonHits.h:27
ATLAS_NOT_THREAD_SAFE
StatusCode NSWAGDDTool::initialize ATLAS_NOT_THREAD_SAFE()
Install fatal handler with default options.
Definition: NSWAGDDTool.cxx:25
AGDDToolBase::m_outFileName
Gaudi::Property< std::string > m_outFileName
Definition: AGDDToolBase.h:40
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
NSWAGDDTool::m_outFilePasV
Gaudi::Property< int > m_outFilePasV
Definition: NSWAGDDTool.h:21
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
CxxUtils::LockedPointer
A pointer together with a movable lock.
Definition: LockedPointer.h:35
NSWAGDDTool::m_outFileActN
Gaudi::Property< std::string > m_outFileActN
Definition: NSWAGDDTool.h:23
initialize
void initialize()
Definition: run_EoverP.cxx:894
skel.it
it
Definition: skel.GENtoEVGEN.py:396
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:71
AGDDParameterStore.h
NSWAGDDTool::m_outFileInName
std::string m_outFileInName
Definition: NSWAGDDTool.h:29
mergePhysValFiles.end
end
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:93
NSWAGDDTool::m_outFileAlgV
Gaudi::Property< int > m_outFileAlgV
Definition: NSWAGDDTool.h:20
NSWAGDDTool.h
MuonAGDDToolHelper::GetAGDD
std::string GetAGDD(const bool dumpIt, const std::string &tableName, const std::string &outFileName)
Definition: MuonAGDDToolHelper.cxx:86
MuonAGDDToolHelper.h
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
MuonAGDDToolHelper::SetNSWComponents
void SetNSWComponents()
Definition: MuonAGDDToolHelper.cxx:128
NSWAGDDTool::m_outFileForm
Gaudi::Property< std::string > m_outFileForm
Definition: NSWAGDDTool.h:26
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
test_pyathena.parent
parent
Definition: test_pyathena.py:15
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
MuonAGDDToolHelper::BuildMScomponents
static bool BuildMScomponents()
Definition: MuonAGDDToolHelper.cxx:118
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
NSWAGDDTool::m_outFileActV
Gaudi::Property< int > m_outFileActV
Definition: NSWAGDDTool.h:19
MuonAGDDToolHelper
Definition: MuonAGDDToolHelper.h:20
python.PyKernel.init
def init(v_theApp, v_rootStream=None)
Definition: PyKernel.py:45
NSWAGDDTool::m_outFileAlgN
Gaudi::Property< std::string > m_outFileAlgN
Definition: NSWAGDDTool.h:24
AGDDDetector.h
AGDD2GeoModelBuilder.h
IAGDD2GeoSvc.h
NSWAGDDTool::m_outPREsqlName
std::string m_outPREsqlName
Definition: NSWAGDDTool.h:30
MuonAGDDToolHelper::setAGDDtoGeoSvcName
void setAGDDtoGeoSvcName(const std::string &name)
Definition: MuonAGDDToolHelper.cxx:148
NSWAGDDTool::NSWAGDDTool
NSWAGDDTool(const std::string &type, const std::string &name, const IInterface *parent)
Definition: NSWAGDDTool.cxx:19
CondAlgsOpts.found
int found
Definition: CondAlgsOpts.py:101
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
NSWAGDDTool::WritePREsqlFile
bool WritePREsqlFile() const
Definition: NSWAGDDTool.cxx:130
NSWAGDDTool::m_outFilePasN
Gaudi::Property< std::string > m_outFilePasN
Definition: NSWAGDDTool.h:25
PrepareReferenceFile.outfile
outfile
Definition: PrepareReferenceFile.py:42