ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
InnerDetector
InDetDetDescr
SCT_Cabling
src
SCT_CablingUtilities.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
/*
6
* SCT_CablingUtilities.cxx
7
* SCT_Cabling
8
*
9
* Created by sroe on 14/11/2008.
10
*
11
*/
12
#include <iostream>
13
#include <sstream>
14
#include <string>
15
#include <cstdlib>
// to include 'getenv'
16
17
namespace
SCT_Cabling
{
18
20
int
stringToInt
(
const
std::string &hexOrDecString){
21
std::istringstream istrm(hexOrDecString);
22
int
result(-1);
23
//enable exceptions for a badly formatted string
24
istrm.exceptions(std::ios_base::badbit|std::ios_base::failbit);
25
//do conversion if the string is not empty
26
if
(not hexOrDecString.empty()){
27
try
{
28
bool
numberIsHex = (hexOrDecString.find(
'x'
) not_eq std::string::npos) or (hexOrDecString.find(
'X'
) not_eq std::string::npos);
29
if
(numberIsHex){
30
istrm>>std::hex>>result;
31
}
else
{
32
istrm>>std::dec>>result;
33
}
34
}
catch
(
const
std::ios_base::failure&){
//bad conversion to int
35
result=-1;
36
//need to throw here
37
std::cerr<<
"stringToInt failed to convert a string to an integer in InDetCabling/SCT_CablingUtilities"
<<std::endl;
38
throw
(std::ios_base::failure(
"stringToInt failure in SCT_CablingUtilities"
));
39
}
40
}
41
return
result;
42
}
43
45
bool
inRange
(
const
int
value,
const
int
lowerBound,
const
int
upperBound,
const
std::string & valueName){
46
bool
bad
= ( (value > upperBound) or (value<lowerBound) );
47
if
(
bad
){
48
std::string name = valueName.empty()?
"The value"
:valueName;
49
std::cerr<<name<<
" = "
<<value<<
" is out of the allowable range."
<<std::endl;
50
}
51
return
(not
bad
);
52
}
53
55
int
calculateLink
(
const
int
MURorder,
const
int
ModID,
const
int
theSide,
const
bool
isSwapped =
false
){
56
return
isSwapped?(MURorder*12 + (5 - ModID) * 2 + (theSide)):(MURorder*12 + ModID * 2 + theSide);
57
}
58
59
//End of utility functions
60
61
namespace
CoveritySafe
{
63
std::string
getenv
(
const
std::string & variableName){
64
std::string result(
""
);
65
const
char
* pChar=std::getenv(variableName.c_str());
66
if
(pChar) result=pChar;
67
return
result;
68
}
69
}
70
}
71
72
bad
@ bad
Definition
SUSYToolsTester.cxx:95
SCT_Cabling::CoveritySafe
Definition
SCT_CablingUtilities.cxx:61
SCT_Cabling::CoveritySafe::getenv
std::string getenv(const std::string &variableName)
get an environment variable
Definition
SCT_CablingUtilities.cxx:63
SCT_Cabling
Definition
SCT_CablingUtilities.cxx:17
SCT_Cabling::calculateLink
int calculateLink(const int MURorder, const int ModID, const int theSide, const bool isSwapped=false)
calculate link, normal and swapped (from Kondo)
Definition
SCT_CablingUtilities.cxx:55
SCT_Cabling::stringToInt
int stringToInt(const std::string &hexOrDecString)
Convert a string (decimal or hex) to an int; -1 indicates an error.
Definition
SCT_CablingUtilities.cxx:20
SCT_Cabling::inRange
bool inRange(const int value, const int lowerBound, const int upperBound, const std::string &valueName)
Check range and give error if out of range.
Definition
SCT_CablingUtilities.cxx:45
Generated on
for ATLAS Offline Software by
1.17.0