Exemplo n.º 1
0
def dqm_get_json_hist(server, run, dataset, folder, histoName, rootContent=False):
    postfix = "?rootcontent=1" if rootContent else ""
    datareq = urllib2.Request(('%s/data/json/archive/%s/%s/%s%s') % (server, run, dataset, folder, postfix))
    datareq.add_header('User-agent', ident)
    # Get data
    data = eval(re.sub(r"\bnan\b", "0", urllib2.build_opener(X509CertOpen()).open(datareq).read()),
               { "__builtins__": None }, {})
    histoOut=None
    if rootContent:
        # Now convert into real ROOT histograms   
        #print "Now convert into real ROOT histograms 1"  
        for idx,item in enumerate(data['contents']):
            #print "Now convert into real ROOT histograms 2"  
            if 'obj' in item.keys():
               #print "Now convert into real ROOT histograms 3"
               if item['obj']==histoName:  
                   if 'rootobj' in item.keys(): 
                       #print "Now convert into real ROOT histograms 4"  
                       a = array('B')
                       #print "Now convert into real ROOT histograms 5"  
                       a.fromstring(item['rootobj'].decode('hex'))
                       #print "Now convert into real ROOT histograms 6"  
                       t = TBufferFile(TBufferFile.kRead, len(a), a, False)
                       #print "Now convert into real ROOT histograms 7"  
                       rootType = item['properties']['type']
                       #print "Now convert into real ROOT histograms 8"  
                       if rootType == 'TPROF': rootType = 'TProfile'
                       #print "Now convert into real ROOT histograms 9"  
                       if rootType == 'TPROF2D': rootType = 'TProfile'
		       #print "Now convert into real ROOT histograms 10"
                       #data['contents'][idx]['rootobj'] = t.ReadObject(eval(rootType+'.Class()'))
                       histoOut = t.ReadObject(eval(rootType+'.Class()'))
		       #print "Now convert into real ROOT histograms 11"
                
    return histoOut
Exemplo n.º 2
0
def dqm_get_json(server, run, dataset, folder, rootContent=False):
#    datareq = urllib2.Request(('%s/data/json/archive/%s/Global/%s%s') % (server, run, dataset, folder, postfix))
#    datareq = urllib2.Request(('%s/data/json/archive/%s/%s/%s?rootcontent=1') % (server, run, dataset, folder)) #- offline?
    if(run==0):
        datareq = urllib2.Request(('%s/data/json/live/%s/Global/%s/%s?rootcontent=1') % (server, run, dataset, folder))
    else:
        datareq = urllib2.Request(('%s/data/json/archive/%s/Global/%s/%s?rootcontent=1') % (server, run, dataset, folder))
#    print '%s/data/json/archive/%s/%s/%s%s' % (server, run, dataset, folder, postfix)
    datareq.add_header('User-agent', ident)
    # Get data
    data = eval(re.sub(r"\bnan\b", "0", urllib2.build_opener(X509CertOpen()).open(datareq).read()),
              { "__builtins__": None }, {})
    #dump/read data in pickle for tests
    #pickle.dump(data, open('data.json', 'wb'))
    #data = pickle.load(open('data.json', 'rb'))
    if rootContent:
        # Now convert into real ROOT histograms
        for idx,item in enumerate(data['contents']):
            if 'obj' in item.keys():
                if 'rootobj' in item.keys():
                    a = array('B')
                    a.fromstring(item['rootobj'].decode('hex'))
                    t = TBufferFile(TBufferFile.kRead, len(a), a, False)
                    rootType = item['properties']['type']
                    if rootType == 'TPROF': rootType = 'TProfile'
                    if rootType == 'TPROF2D': rootType = 'TProfile2D'
                    data['contents'][idx]['rootobj'] = t.ReadObject(eval(rootType+'.Class()'))
    return dict( [ (x['obj'], x) for x in data['contents'][1:] if 'obj' in x] )
Exemplo n.º 3
0
def dqm_get_json(server, run, dataset, folder, rootContent=False, ident=None):
    datareq = urllib2.Request(('%s/data/json/archive/%s/%s/%s?rootcontent=1') %
                              (server, run, dataset, folder))

    if ident:
        datareq.add_header('User-agent', ident)
    # Get data
    data = eval(
        re.sub(r"\bnan\b", "0",
               urllib2.build_opener(X509CertOpen()).open(datareq).read()),
        {"__builtins__": None}, {})

    if rootContent:
        # Now convert into real ROOT histograms
        for idx, item in enumerate(data['contents']):
            if 'obj' in item.keys():
                if 'rootobj' in item.keys():
                    a = array.array('B')
                    a.fromstring(item['rootobj'].decode('hex'))
                    t = TBufferFile(TBufferFile.kRead, len(a), a, False)
                    rootType = item['properties']['type']
                    if rootType == 'TPROF':
                        rootType = 'TProfile'
                    data['contents'][idx]['rootobj'] = t.ReadObject(
                        eval(rootType + '.Class()'))

    return dict([(x['obj'], x) for x in data['contents'][1:] if 'obj' in x])
Exemplo n.º 4
0
    def test2TBufferCheck(self):
        """Test that a TBufferFile can be pickled"""

        # the following does not assert anything, but if there is a failure, the
        # ROOT I/O layer will print an error message
        f1 = TBufferFile(TBuffer.kWrite)
        f2 = pickle.loads(pickle.dumps(f1))
Exemplo n.º 5
0
def convert_json_to_root(json_data):
    from ROOT import TBufferFile, TH1F, TProfile, TProfile2D, TH1F, TH2F, TH1
    return_dict = {}
    for idx, item in enumerate(json_data['contents']):
        if "obj" in item.keys() and "rootobj" in item.keys():
            bit_array = array('B')
            bit_array.fromstring(bytes.fromhex(item['rootobj']))
            tbuffer = TBufferFile(TBufferFile.kRead, len(bit_array), bit_array,
                                  False)
            rootType = item['properties']['type']
            if rootType == 'TPROF':
                rootType = 'TProfile'
            elif rootType == 'TPROF2D':
                rootType = 'TProfile2D'
            return_dict[item["obj"]] = tbuffer.ReadObject(
                eval(rootType + '.Class()'))
    return return_dict
Exemplo n.º 6
0
def get_root_objects(run, server, dataset, folder, force_download=False):
    from ROOT import TBufferFile, TH1F, TProfile, TProfile2D, TH1F, TH2F, TH1
    cached_path = get_dqm_file_cachepath(run, server, dataset, folder)
    if not os.path.file_exists(cached_path) or force_download:
        download_dqm_file(run, server, dataset, folder)
    dqm_data = pickle.load(open(cached_path, 'r'))
    for idx, item in enumerate(data['contents']):
        if 'obj' in item.keys() and 'rootobj' in item.keys():
            a = array('B')
            a.fromstring(item['rootobj'].decode('hex'))
            t = TBufferFile(TBufferFile.kRead, len(a), a, False)
            rootType = item['properties']['type']
            if rootType == 'TPROF': rootType = 'TProfile'
            if rootType == 'TPROF2D': rootType = 'TProfile'
            data['contents'][idx]['rootobj'] = t.ReadObject(
                eval(rootType + '.Class()'))
    return dict([(x['obj'], x) for x in data['contents'][1:] if 'obj' in x])