3 __author__ =
'mborodin'
9 from PyCool
import cool
11 FOLDER_NAME =
'/TRT/Calib/PID_vector'
12 TAG_NAME =
'TRTCalibPID_vector_Data15_noArCFs_noZR_00-01'
20 logging.basicConfig(level=logging.DEBUG)
21 _logger = logging.getLogger(
'createPIDTool')
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)
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,
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>',
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]
53 vector = cool.IRecordVector()
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()
65 Read data from input txt file in awful format
66 :param input_file_name: input file path
69 with open(input_file_name,
'r')
as input_file:
70 for line
in input_file:
73 line = line.replace(
"\n",
'')
74 if line
and (line.find(
'#')==-1):
76 elements = line.split()
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]
89 output_list.append(( ChannelName ,map(float,elements[5:])))
91 print "SIZE OF THE LINE ODD. CHECK!!! "
98 if len(sys.argv) != 3:
99 print "Usage: %s input_file connection_string" % sys.argv[0]
103 connect_string = sys.argv[2]
104 _logger.info(
"data from file: %s" % values_dict)
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 )
113 _logger.error(
"Problem with database: %s" % e)
118 if __name__==
'__main__':