Esempio n. 1
0
    def __init__(self, files, tree_name, options=None):
        from DataFormats.FWLite import Events as FWLiteEvents
        #TODO not sure we still need the stuff below
        from ROOT import gROOT, gSystem, AutoLibraryLoader

        print "Loading FW Lite"
        gSystem.Load("libFWCoreFWLite")
        gROOT.ProcessLine('FWLiteEnabler::enable();')

        gSystem.Load("libFWCoreFWLite")
        gSystem.Load("libDataFormatsPatCandidates")

        from ROOT import gInterpreter
        gInterpreter.ProcessLine("using namespace reco;")
        gInterpreter.ProcessLine("using edm::refhelper::FindUsingAdvance;")
        if options is not None:
            if not hasattr(options, "inputFiles"):
                options.inputFiles = files
            if not hasattr(options, "maxEvents"):
                options.maxEvents = 0
            if not hasattr(options, "secondaryInputFiles"):
                options.secondaryInputFiles = []
            self.events = FWLiteEvents(options=options)
        else:
            self.events = FWLiteEvents(files)
Esempio n. 2
0
 def __init__(self, files, tree_name, options=None):
     if options is not None:
         if not hasattr(options, "inputFiles"):
             options.inputFiles = files
         if not hasattr(options, "maxEvents"):
             options.maxEvents = 0
         if not hasattr(options, "secondaryInputFiles"):
             options.secondaryInputFiles = []
         self.events = FWLiteEvents(options=options)
     else:
         self.events = FWLiteEvents(files)
Esempio n. 3
0
 def __init__(self, files, tree_name, options=None):
     logging.info('opening input files:')
     logging.info(pprint.pformat(files))
     if options is not None:
         if not hasattr(options, "inputFiles"):
             options.inputFiles = files
         if not hasattr(options, "maxEvents"):
             options.maxEvents = 0
         if not hasattr(options, "secondaryInputFiles"):
             options.secondaryInputFiles = []
         self.events = FWLiteEvents(options=options)
     else:
         self.events = FWLiteEvents(files)
     logging.info('done')
Esempio n. 4
0
 def __getitem__(self, iEv):
     if self._fileindex == -1 or not(self._files[self._fileindex][1] <= iEv and iEv < self._files[self._fileindex][2]):
         self.events = None # so it's closed
         if self._localCopy:
             print "Removing local cache file %s" % self._localCopy
             os.remove(self._localCopy)
         for i,(fname,first,last) in enumerate(self._files):
             if first <= iEv and iEv < last:
                 print "For event range [ %d, %d ) will use file %r " % (first,last,fname)
                 self._fileindex = i
                 if fname.startswith("root://eoscms"):
                     if not self.isLocal(fname):
                         tmpdir = os.environ['TMPDIR'] if 'TMPDIR' in os.environ else "/tmp"
                         rndchars  = "".join([hex(ord(i))[2:] for i in os.urandom(8)])
                         localfile = "%s/%s-%s.root" % (tmpdir, os.path.basename(fname).replace(".root",""), rndchars)
                         try:
                             print "Filename %s is remote (geotag >= 9000), will do a copy to local path %s " % (fname,localfile)
                             subprocess.check_output(["xrdcp","-f",fname,localfile])
                             self._localCopy = localfile
                             fname = localfile
                         except:
                             print "Could not save file locally, will run from remote"
                             if os.path.exists(localfile): os.remove(localfile) # delete in case of incomplete transfer
                 print "Will run from "+fname
                 self.events = FWLiteEvents([fname])
                 break
     self.events.to(iEv)
     return self
 def __getitem__(self, iEv):
     if self._fileindex == -1 or not (
             self._files[self._fileindex][1] <= iEv
             and iEv < self._files[self._fileindex][2]):
         self.events = None  # so it's closed
         if self._localCopy:
             print "Removing local cache file %s" % self._localCopy
             try:
                 os.remove(self._localCopy)
             except:
                 pass
             self._localCopy = None
         for i, (fname, first, last) in enumerate(self._files):
             if first <= iEv and iEv < last:
                 print "For event range [ %d, %d ) will use file %r " % (
                     first, last, fname)
                 self._fileindex = i
                 if fname.startswith("root://eoscms") or (
                         self.aggressive >= 2
                         and fname.startswith("root://")):
                     if not self.isLocal(fname):
                         tmpdir = os.environ[
                             'TMPDIR'] if 'TMPDIR' in os.environ else "/tmp"
                         rndchars = "".join(
                             [hex(ord(i))[2:] for i in os.urandom(8)]
                         ) if not self.long_cache else "long_cache-id%d-%s" % (
                             os.getuid(), hashlib.sha1(fname).hexdigest())
                         localfile = "%s/%s-%s.root" % (
                             tmpdir, os.path.basename(fname).replace(
                                 ".root", ""), rndchars)
                         if self.long_cache and os.path.exists(localfile):
                             print "Filename %s is already available in local path %s " % (
                                 fname, localfile)
                             fname = localfile
                         else:
                             try:
                                 print "Filename %s is remote (geotag >= 9000), will do a copy to local path %s " % (
                                     fname, localfile)
                                 start = timeit.default_timer()
                                 subprocess.check_output([
                                     "xrdcp", "-f", "-N", fname, localfile
                                 ])
                                 print "Time used for transferring the file locally: %s s" % (
                                     timeit.default_timer() - start)
                                 if not self.long_cache:
                                     self._localCopy = localfile
                                 fname = localfile
                             except:
                                 print "Could not save file locally, will run from remote"
                                 if os.path.exists(localfile):
                                     os.remove(
                                         localfile
                                     )  # delete in case of incomplete transfer
                 print "Will run from " + fname
                 self.events = FWLiteEvents([fname])
                 break
     self.events.to(iEv - self._files[self._fileindex][1])
     return self
Esempio n. 6
0
    def __init__(self, files, tree_name,  options=None):
        logging.info(
            'opening input files:\n{}'.format(pprint.pformat(files))
            )
        if options is not None :
            if not hasattr(options,"inputFiles"):
                options.inputFiles=files
            if not hasattr(options,"maxEvents"):
                options.maxEvents = 0	
            if not hasattr(options,"secondaryInputFiles"):
                options.secondaryInputFiles = []
            elif options.secondaryInputFiles: # only if it's a non-empty list
                logging.info('using secondary input files:\n{}'.format(
                        pprint.pformat(options.secondaryInputFiles)
                        ))
            self.events = FWLiteEvents(options=options)
	else :
            self.events = FWLiteEvents(files)
        logging.info('done')
Esempio n. 7
0
 def __init__(self, files, tree_name):
     self.events = FWLiteEvents(files)