sqlfilldb.C

Go to the documentation of this file.
00001 void sqlfilldb(int nfiles = 1000)
00002 {
00003    // Fill run catalog with nfiles entries
00004    
00005    const char *ins = "INSERT INTO runcatalog VALUES ('%s', %d,"
00006       " %d, %d, %d, %10.2f, '%s', '%s', '1997-01-15 20:16:28',"
00007       " '1999-01-15 20:16:28', '%s', '%s')";
00008    
00009    char sql[4096];
00010    char dataset[32];
00011    char rawfile[128];
00012    int  tag, evt = 0;
00013    
00014    // open connection to MySQL server on localhost
00015    TSQLServer *db = TSQLServer::Connect("mysql://localhost/test", "nobody", "");
00016    TSQLResult *res;
00017    
00018    // first clean table of old entries
00019    res = db->Query("DELETE FROM runcatalog");
00020    delete res;
00021 
00022    // start timer
00023    TStopwatch timer;
00024    timer.Start();
00025    
00026    // fill run catalog
00027    for (int i = 0; i < nfiles; i++) {
00028       sprintf(dataset, "testrun_%d", i);
00029       sprintf(rawfile, "/v1/data/lead/test/run_%d.root", i);
00030       tag = int(gRandom->Rndm()*10.);
00031       sprintf(sql, ins, dataset, i, evt, evt+10000, tag, 25.5, "test", "lead",
00032               rawfile, "test run dummy data");
00033       evt += 10000;
00034       res = db->Query(sql);
00035       delete res;
00036       //printf("%s\n", sql);
00037    }
00038    
00039    delete db;
00040 
00041    // stop timer and print results
00042    timer.Stop();
00043    Double_t rtime = timer.RealTime();
00044    Double_t ctime = timer.CpuTime();
00045 
00046    printf("\n%d files in run catalog\n", nfiles);
00047    printf("RealTime=%f seconds, CpuTime=%f seconds\n", rtime, ctime);
00048 }

Generated on Tue Jul 5 15:45:10 2011 for ROOT_528-00b_version by  doxygen 1.5.1