3 import Utilities.General.cmssw_das_client
as das_client
13 """Parse the control line arguments""" 15 parser = argparse.ArgumentParser(description =
"Tool to find which runs are included in files. Used to generate input dataset for JetHT validation tool in case of run based splitting for condor jobs.", formatter_class=argparse.RawTextHelpFormatter)
16 parser.add_argument(
"-i",
"--input", action=
"store", help=
"Name of the input file list. Has one file name in each line.", required=
True)
17 parser.add_argument(
"-o",
"--output", action =
"store", help =
"Name of the output file in which the produced file list is stored", default =
"myFileListWithRuns.txt")
19 return parser.parse_args()
25 """Check if GRID proxy has been initialized.""" 28 with open(os.devnull,
"w")
as dump:
29 subprocess.check_call([
"voms-proxy-info",
"--exists"],
30 stdout = dump, stderr = dump)
31 except subprocess.CalledProcessError:
38 """ Find string from json file. Code copy-pasted from dataset.py """ 40 if isinstance(strings, str):
45 if isinstance(jsondict,dict):
46 if strings[0]
in jsondict:
48 return findInJson(jsondict[strings[0]], strings[1:])
56 except (TypeError, KeyError):
59 raise KeyError(
"Can't find " + strings[0])
64 """ Get data from DAS query. Code copy-pasted from dataset.py """ 67 if isinstance(dasData, str):
68 jsondict = json.loads( dasData )
76 if error
or findInJson(jsondict,
"status") !=
'ok' or "data" not in jsondict:
80 jsonstr =
str(jsondict)
81 if len(jsonstr) > 10000:
82 jsonfile =
"das_query_output_%i.txt" 84 while os.path.lexists(jsonfile % i):
86 jsonfile = jsonfile % i
87 theFile = open( jsonfile,
"w" )
88 theFile.write( jsonstr )
90 msg =
"The DAS query returned an error. The output is very long, and has been stored in:\n" + jsonfile
92 msg =
"The DAS query returned a error. Here is the output\n" + jsonstr
93 msg +=
"\nIt's possible that this was a server error. If so, it may work if you try again later" 104 print(
"Grid proxy is required to connect to DAS. Cannot run the tool without it.")
105 print(
"Please create a proxy via 'voms-proxy-init -voms cms'.")
112 inputFile = open(commandLineArguments.input,
"r") 113 inputFileList = inputFile.readlines() 118 for rawInputFile
in inputFileList:
120 inputFile = rawInputFile.rstrip()
124 for dasInstance
in myData:
125 myRunsArray.append(
findInJson(dasInstance,
"run"))
127 for innerArray
in myRunsArray:
128 for jsonDictionary
in innerArray:
129 runNumber = jsonDictionary[
"run_number"]
130 if runNumber
in runDictionary:
131 runDictionary[runNumber].
append(inputFile)
133 runDictionary[runNumber] = [inputFile]
137 outputFileName = commandLineArguments.output
138 outputFile = open(outputFileName,
"w")
140 for runNumber
in runDictionary:
141 for fileName
in runDictionary[runNumber]:
142 outputFile.write(
"{} {}\n".
format(runNumber, fileName))
147 if __name__ ==
"__main__":
def get_data(host, query, idx, limit, debug, threshold=300, ckey=None, cert=None, capath=None, qcache=0, das_headers=True)
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
def findInJson(jsondict, strings)
def getData(dasQuery, dasLimit=0)