Example #1
0
 def setUp(self):
     dbname = 'dqis_%s' % self.id().split('.')[-1].lower()
     
     couch = CouchServer(dburl='admin:password@localhost:5984')
     if dbname not in couch.listDatabases():
         couch.createDatabase(dbname)
     couch.connectDatabase(dbname)
     self.db = Database(dbname, couch.url)
 
     #insert 5 known records
     self.db.queue({
            "_id": "1234-1-f28ca5a7388b8f6ade71b43c4f4b7669",
            "bfield": 4000,
            "map": {
                "dt_shift_online": True,
                "hlt_shift_online": True,
                "_meta": {
                    "timestamp": "2010-04-14 18:04:58.087723",
                    "user": "******"
                }
            },
            "run": 1234,
            "map_history": [
            ],
            "dataset": [
                "Cosmics",
                "Commissioning09-MuAlStandAloneCosmics-v2",
                "ALCARECO"
            ],
            "lumi": 1
         })
     self.db.queue({
            "_id": "1234-2-f28ca5a7388b8f6ade71b43c4f4b7669",
            "bfield": 4000,
            "map": {
                "dt_shift_online": True,
                "hlt_shift_online": False,
                "_meta": {
                    "timestamp": "2010-04-14 18:04:58.087723",
                    "user": "******"
                }
            },
            "run": 1234,
            "map_history": [
            ],
            "dataset": [
                "Cosmics",
                "Commissioning09-MuAlStandAloneCosmics-v2",
                "ALCARECO"
            ],
            "lumi": 2
         })
     self.db.queue({
            "_id": "1234-3-f28ca5a7388b8f6ade71b43c4f4b7669",
            "bfield": 2000,
            "map": {
                "dt_shift_online": True,
                "hlt_shift_online": True,
                "_meta": {
                    "timestamp": "2010-04-14 18:04:58.087723",
                    "user": "******"
                }
            },
            "run": 1234,
            "map_history": [
            ],
            "dataset": [
                "Cosmics",
                "Commissioning09-MuAlStandAloneCosmics-v2",
                "ALCARECO"
            ],
            "lumi": 3
         })      
     self.db.queue({
            "_id": "5678-2-f28ca5a7388b8f6ade71b43c4f4b7669",
            "bfield": 2000,
            "map": {
                "dt_shift_online": False,
                "hlt_shift_online": True,
                "_meta": {
                    "timestamp": "2010-04-14 18:04:58.087723",
                    "user": "******"
                }
            },
            "run": 5678,
            "map_history": [
            ],
            "dataset": [
                "Cosmics",
                "Commissioning09-MuAlStandAloneCosmics-v2",
                "ALCARECO"
            ],
            "lumi": 2
         })
     self.db.queue({
            "_id": "5678-1-f28ca5a7388b8f6ade71b43c4f4b7669",
            "bfield": 4000,
            "map": {
                "dt_shift_online": True,
                "hlt_shift_online": True,
                "_meta": {
                    "timestamp": "2010-04-14 18:04:58.087723",
                    "user": "******"
                }
            },
            "run": 5678,
            "map_history": [
            ],
            "dataset": [
                "Cosmics",
                "Commissioning09-MuAlStandAloneCosmics-v2",
                "ALCARECO"
            ],
            "lumi": 1
         })
       
     self.db.commit()
     
     cmd = "couchapp push ../../../../src/couchapp/dqis/. http://admin:password@localhost:5984/%s" % dbname
     commands.getstatusoutput(cmd)
Example #2
0
                  type="string",    
                  action="store",
                  dest="doc_id", 
                  help="Document ID",) #TODO: validate
    
    op.add_option("--crab",
                  "-c",
                  action="store_true", 
                  dest='crab',
                  help='Create a CRAB lumi.json file in the current directory.',
                  default=False)
    
    return op.parse_args()


options, args = do_options()
db = Database(dbname = options.db_name, url = options.db_address, size = 1000)

map = {}
for k,v  in options.keys:
    map[k] = bool(v)

if options.crab:
    data = db.crab(options.start_run, options.end_run, map, options.bfield)
    f = open('lumi.json', 'w')
    json.dump(data, f)
    f.close()
elif options.doc_id:
    print db.getDoc(doc_id)
else:
    print db.search(options.start_run, options.end_run, map, options.bfield)
Example #3
0
class TestDatabase(unittest.TestCase):
    def setUp(self):
        dbname = 'dqis_%s' % self.id().split('.')[-1].lower()
        
        couch = CouchServer(dburl='admin:password@localhost:5984')
        if dbname not in couch.listDatabases():
            couch.createDatabase(dbname)
        couch.connectDatabase(dbname)
        self.db = Database(dbname, couch.url)
    
        #insert 5 known records
        self.db.queue({
               "_id": "1234-1-f28ca5a7388b8f6ade71b43c4f4b7669",
               "bfield": 4000,
               "map": {
                   "dt_shift_online": True,
                   "hlt_shift_online": True,
                   "_meta": {
                       "timestamp": "2010-04-14 18:04:58.087723",
                       "user": "******"
                   }
               },
               "run": 1234,
               "map_history": [
               ],
               "dataset": [
                   "Cosmics",
                   "Commissioning09-MuAlStandAloneCosmics-v2",
                   "ALCARECO"
               ],
               "lumi": 1
            })
        self.db.queue({
               "_id": "1234-2-f28ca5a7388b8f6ade71b43c4f4b7669",
               "bfield": 4000,
               "map": {
                   "dt_shift_online": True,
                   "hlt_shift_online": False,
                   "_meta": {
                       "timestamp": "2010-04-14 18:04:58.087723",
                       "user": "******"
                   }
               },
               "run": 1234,
               "map_history": [
               ],
               "dataset": [
                   "Cosmics",
                   "Commissioning09-MuAlStandAloneCosmics-v2",
                   "ALCARECO"
               ],
               "lumi": 2
            })
        self.db.queue({
               "_id": "1234-3-f28ca5a7388b8f6ade71b43c4f4b7669",
               "bfield": 2000,
               "map": {
                   "dt_shift_online": True,
                   "hlt_shift_online": True,
                   "_meta": {
                       "timestamp": "2010-04-14 18:04:58.087723",
                       "user": "******"
                   }
               },
               "run": 1234,
               "map_history": [
               ],
               "dataset": [
                   "Cosmics",
                   "Commissioning09-MuAlStandAloneCosmics-v2",
                   "ALCARECO"
               ],
               "lumi": 3
            })      
        self.db.queue({
               "_id": "5678-2-f28ca5a7388b8f6ade71b43c4f4b7669",
               "bfield": 2000,
               "map": {
                   "dt_shift_online": False,
                   "hlt_shift_online": True,
                   "_meta": {
                       "timestamp": "2010-04-14 18:04:58.087723",
                       "user": "******"
                   }
               },
               "run": 5678,
               "map_history": [
               ],
               "dataset": [
                   "Cosmics",
                   "Commissioning09-MuAlStandAloneCosmics-v2",
                   "ALCARECO"
               ],
               "lumi": 2
            })
        self.db.queue({
               "_id": "5678-1-f28ca5a7388b8f6ade71b43c4f4b7669",
               "bfield": 4000,
               "map": {
                   "dt_shift_online": True,
                   "hlt_shift_online": True,
                   "_meta": {
                       "timestamp": "2010-04-14 18:04:58.087723",
                       "user": "******"
                   }
               },
               "run": 5678,
               "map_history": [
               ],
               "dataset": [
                   "Cosmics",
                   "Commissioning09-MuAlStandAloneCosmics-v2",
                   "ALCARECO"
               ],
               "lumi": 1
            })
          
        self.db.commit()
        
        cmd = "couchapp push ../../../../src/couchapp/dqis/. http://admin:password@localhost:5984/%s" % dbname
        commands.getstatusoutput(cmd)
                
    def tearDown(self):
        if self._exc_info()[0] == None:
            testname = self.id().split('.')[-1].lower()
            CouchServer(dburl='admin:password@localhost:5984').deleteDatabase('dqis_%s' % testname)
    
    def testWriteDoc(self):
        d = Document(1, 2, '/foo/bar/baz', 'metson', 3990, {'ecal': True})
        self.db.queue(d)
        self.db.commit()
        
        d_from_db = self.db.document(d['_id'])
        for k, v in d_from_db.iteritems():
            if k != '_rev':
                assert d[k] == v, 'Failed for %s: %s != %s' % (k, v, d[k])
        
    def testCRABSearch(self):
        dbname = 'dqis_%s' % self.id().split('.')[-1].lower()
        uri = '/%s/_design/dqis/_list/crab/run_lumi/' % dbname
        
        data = {'bfield': 4000}
        
        crab_list = self.db.post(uri, data)
        
        assert len(crab_list['1234']) == 2, 'wrong number of records returned'

    def testBFieldSearch(self):
        dbname = 'dqis_%s' % self.id().split('.')[-1].lower()
        uri = '/%s/_design/dqis/_list/search/run_lumi/' % dbname
        
        data = {'bfield': 2000}
        
        search_list = self.db.post(uri, data)
        
        assert len(search_list) == 2, 'wrong number of records returned'
        for doc in search_list:
             assert doc['value']['bfield'] == data['bfield'], 'wrong records returned'
    
    def testMapSearch(self):
        dbname = 'dqis_%s' % self.id().split('.')[-1].lower()
        uri = '/%s/_design/dqis/_list/search/run_lumi/' % dbname
        
        data = {'map':{"dt_shift_online": True, "hlt_shift_online": True}}
        
        search_list = self.db.post(uri, data)
        
        for record in search_list:
            for key in data['map'].keys():
                assert record["value"]["map"][key] == data['map'][key], "key didn't match query" 
            
    def testCombinedSearch(self):
        dbname = 'dqis_%s' % self.id().split('.')[-1].lower()
        uri = '/%s/_design/dqis/_list/search/run_lumi/' % dbname
        
        data = {'bfield': 4000, 
                'map':{"dt_shift_online": True, "hlt_shift_online": True}}
        
        search_list = self.db.post(uri, data)
        
        for record in search_list:
            assert record["value"]["bfield"] == data['bfield'], "bfield didn't match query"
            for key in data['map'].keys():
                assert record["value"]["map"][key] == data['map'][key], "key didn't match query" 
            
    def testSearchRunLimit(self):
        dbname = 'dqis_%s' % self.id().split('.')[-1].lower()
        uri = '/%s/_design/dqis/_list/search/run_lumi/?startkey=1234&endkey=1236' % dbname
        
        data = {'bfield': 4000, 
                'map':{"dt_shift_online": True, "hlt_shift_online": True}}
        
        search_list = self.db.post(uri, data)
        
        for record in search_list:
            # this next one is really a test of CouchDB not this code...
            assert record["value"]["run"] == record["key"]
            assert 1234 <= record["value"]["run"] <= 1236
            assert record["value"]["bfield"] == data['bfield'], "bfield didn't match query"
            for key in data['map'].keys():
                assert record["value"]["map"][key] == data['map'][key], "key didn't match query"