135
136 parser = argparse.ArgumentParser(description='Check status of datasets based on DSIDs and AMI tags. Written by C. Ohm & M. Tripiana')
137 parser.add_argument('-p', '--projectTag', type=str, nargs='?', help='Project tag, defaults to "mc15_13TeV"', default='mc15_13TeV')
138 parser.add_argument('-d', '--dsids', type=str, nargs='?', help='Text file(s) containing DSIDs', default='')
139 parser.add_argument('-f', '--format', type=str, help='Format: DAOD_SUSY1 (default), DAOD_SUSY2, ...', default='DAOD_SUSY1')
140 parser.add_argument('-v', '--verbose', action='store_true', default=False, help='Verbose mode, more detailed output and commands, etc')
141 parser.add_argument('-o', '--outfile', nargs='?', type=argparse.FileType('w'), help='Save the dict holding the sample info to a pickle file')
142 parser.add_argument('-i', '--infile', nargs='?', type=argparse.FileType('r'), help='Open a pickle file containing a dict from a previous session')
143
144 args = parser.parse_args()
145 if args.verbose:
146 print args
147
148 if args.infile:
149 with args.infile as handle:
150 samples = pickle.load(handle)
151 printSamplesDict(samples)
152 sys.exit()
153
154 if not args.dsids:
155
156 parser.print_help()
157 sys.exit()
158
159 f = open(args.dsids)
160 dsids = [line.rstrip('\n') for line in f]
161
162 samples = {}
163
164 for dsid in dsids:
165 if not dsid or dsid.startswith('#'):
166 continue
167
168 print "Checking DSID %s..." % dsid
169 samples[dsid] = getSamplesFromPattern(dsid.strip(), args.projectTag, defaultSimTags, defaultRecoTags, args.verbose, args.format, defaultDerivationTags)
170
171 if args.verbose:
172 print "These samples were found:"
173 for dsid in samples:
174 print "DSID: %s" % dsid
175 for ds in samples[dsid]:
176 print " %s: %s" % (ds, samples[dsid][ds])
177
178
179 for dsid in samples:
180 for ds in samples[dsid].keys():
181 if ds == " N/A ":
182 samples[dsid][ds+"status"] = " N/A "
183 samples[dsid][ds+"status"] = getAmiStatus(samples[dsid][ds], args.verbose)
184
185 print "Done, here is the status of your samples"
186 if args.verbose:
187 print "Here's the dict holding all the extracted info:"
188 print samples
189
190 if args.outfile:
191 with args.outfile as handle:
192 pickle.dump(samples, handle)
193 print "Python dict with sample info saved to %s - you can read it in with the -i option" % args.outfile.name
194
195 printSamplesDict(samples)
196