ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
InnerDetector
InDetRecTools
TRT_ElectronPidTools
DatabaseTools
createTRTPIDTool.py
Go to the documentation of this file.
1
# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
2
3
__author__ =
'mborodin'
4
5
# python createTRTPIDTool.py infile.txt 'sqlite://;schema=TRTPID.db;dbname=CONDBR2'
6
7
import
sys
8
import
logging
9
from
PyCool
import
cool
10
11
FOLDER_NAME =
'/TRT/Calib/PID_vector'
12
TAG_NAME =
'TRTCalibPID_vector_Data15_noArCFs_noZR_00-01'
13
# python createTRTPIDTool.py CorrectionFactors_HRformat_Jared_Data.txt 'sqlite://;schema=TRTPIDData.db;dbname=CONDBR2'
14
15
16
#TAG_NAME = 'TRTCalibPID_vector_MC_OnSetMC_CorrMC_00-01'
17
# python createTRTPIDTool.py CorrectionFactors_HRformat_Jared_MC.txt 'sqlite://;schema=TRTPIDMC.db;dbname=CONDBR2'
18
19
20
logging.basicConfig(level=logging.DEBUG)
21
_logger = logging.getLogger(
'createPIDTool'
)
22
23
24
25
26
27
def
store_PID_to_folder
(db,values_list):
28
"""
29
Function to create folder FOLDER_NAME in db with channels and input data from values_list with tag TAG_NAME
30
:param db: Open cool db
31
:param values_list: list of tuples ('channel name', valus array)
32
33
"""
34
spec = cool.RecordSpecification()
35
spec.extend(
'array_value'
,cool.StorageType.Float)
36
_logger.info(
'Create folder %s'
% FOLDER_NAME)
37
folder_spec = cool.FolderSpecification(cool.FolderVersioning.MULTI_VERSION,
38
spec,
39
cool.PayloadMode.VECTORPAYLOAD)
40
folder = db.createFolder(FOLDER_NAME, folder_spec,
41
' <timeStamp>run-lumi</timeStamp><addrHeader><address_header service_type="71" clid="55403898"/></addrHeader><typeName>CondAttrListVec</typeName>'
,
42
True
)
43
44
for
index, channel_name
in
enumerate(values_list):
45
folder.createChannel(index,channel_name[0])
46
print
'%i - %s'
% (index, channel_name[0])
47
folder.setupStorageBuffer()
48
for
index, channel_values
in
enumerate(values_list):
49
_logger.info(
'Store data from %s'
% channel_values[0])
50
values = channel_values[1]
51
# print channel_values[0]
52
# print channel_values[1]
53
vector = cool.IRecordVector()
54
for
value
in
values:
55
# print value
56
data = cool.PyCool.Helpers.IRecordPtr(spec)
57
data.get()[
'array_value'
] = value
58
vector.push_back(data)
59
folder.storeObject(0,cool.ValidityKeyMax, vector, index, TAG_NAME )
60
folder.flushStorageBuffer()
61
62
63
def
read_PID_txt
(input_file_name):
64
"""
65
Read data from input txt file in awful format
66
:param input_file_name: input file path
67
"""
68
output_list=[]
69
with
open(input_file_name,
'r'
)
as
input_file:
70
for
line
in
input_file:
71
# print line
72
#line = line.replace(' ','').replace("\n",'')
73
line = line.replace(
"\n"
,
''
)
74
if
line
and
(line.find(
'#'
)==-1):
75
#elements = line.split(',')
76
elements = line.split()
77
print
elements
78
79
if
len(elements) > 5:
80
#Why?!
81
barrel_or_endcap = elements[2].
replace
(
'EndcapWheels'
,
'EW'
)
82
electrons = elements[3].
replace
(
'Electrons'
,
'Elecs'
)
83
ChannelName = elements[4] +
'_'
+elements[1] +
'_'
+ elements[2] +
'_'
+elements[0] +
'_'
+ elements[3]
84
#ChannelName = elements[4] + '_' + elements[2] + '_' +elements[1] + '_' +elements[0] + '_' + elements[3]
85
#output_list.append(((elements[1]+'_'+barrel_or_endcap+'_'+electrons),map(float,elements[8:])))
86
print
elements[0:4]
87
print
ChannelName
88
# print elements[5:]
89
output_list.append(( ChannelName ,
map
(float,elements[5:])))
90
else
:
91
print
"SIZE OF THE LINE ODD. CHECK!!! "
92
print
line
93
return
output_list
94
95
96
def
main
():
97
98
if
len(sys.argv) != 3:
99
print
"Usage: %s input_file connection_string"
% sys.argv[0]
100
return
-1
101
values_dict =
read_PID_txt
(sys.argv[1])
102
print
"\nREAD OVER"
103
connect_string = sys.argv[2]
104
_logger.info(
"data from file: %s"
% values_dict)
105
#print values_dict
106
try
:
107
dbSvc = cool.DatabaseSvcFactory.databaseService()
108
_logger.debug(
'dropping database %s'
% connect_string)
109
dbSvc.dropDatabase( connect_string )
110
_logger.debug(
'creating database'
)
111
db = dbSvc.createDatabase( connect_string )
112
except
Exception,e:
113
_logger.error(
"Problem with database: %s"
% e)
114
return
-1
115
store_PID_to_folder
(db, values_dict)
116
db.closeDatabase()
117
118
if
__name__==
'__main__'
:
119
main
()
map
STL class.
replace
std::string replace(std::string s, const std::string &s2, const std::string &s3)
Definition
hcg.cxx:312
createTRTPIDTool.main
main()
Definition
createTRTPIDTool.py:96
createTRTPIDTool.read_PID_txt
read_PID_txt(input_file_name)
Definition
createTRTPIDTool.py:63
createTRTPIDTool.store_PID_to_folder
store_PID_to_folder(db, values_list)
Definition
createTRTPIDTool.py:27
Generated on
for ATLAS Offline Software by
1.17.0