void write_pstOnIds_ideal()
{
    gSystem->Setenv("DB_ACCESS_MODE", "write");
    // Load all required libraries
    gROOT->Macro("LoadLogger.C");
    gSystem->Load("St_base.so");
    gSystem->Load("libStDb_Tables.so");
    gSystem->Load("StDbLib.so");
    
    // Initialize db manager
    StDbManager* mgr = StDbManager::Instance();
    StDbConfigNode* node = mgr->initConfig("Geometry_ist");
    StDbTable* dbtable = node->addDbTable("pstOnIds");
    TString storeTime = "2013-12-15 00:00:00"; // beginTime timestamp in MySQL format: "YYYY-MM-DD HH:mm:ss"
    mgr->setStoreTime(storeTime.Data());
    
    // Create your c-struct
    Survey_st table = {1, 1,0,0, 0,1,0, 0,0,1, 0,0,0,.0001,.0001,.0001,.0001,.0001,.0001,"ideal geometry"};
    
    // Store data to the StDbTable
    dbtable->SetTable((char*)&table, 1);
    
    // uncomment next line to set "sim" flavor. "ofl" flavor is set by default, no need to set it.
    dbtable->setFlavor("sim");
    
    // Store table to database
    mgr->storeDbTable(dbtable);
}
예제 #2
0
void storetofGeomAlign()
//int main(int argc, char *argv[])

{

// year8
//  const Int_t NTRAY = 5;
// year9
  const Int_t NTRAY = 94;
  const Int_t NVPDTRAY = 2;
  const Int_t NMAX = 120;

  //-- load dBase and Table definition libraries
  gSystem->Load("St_base");
  gSystem->Load("StChain");
  gSystem->Load("StUtilities");
  gSystem->Load("St_Tables.so");

  gSystem->Load("StDbLib.so");
  gSystem->Load("libStDb_Tables.so");

  //-- get the singleton manager
  StDbManager* dbManager = StDbManager::Instance();

  //-- connect to the db & get an empty container
  StDbConfigNode* configNode = dbManager->initConfig("Calibrations_tof");

  //----------------------------------------
  TString ZStoreTime = "2007-11-01 00:00:00";
//  TString ZStoreTime = "2008-11-01 00:00:00";

  //-- add table to the container with descriptor given by Database
  StDbTable* tofGeomAlign = configNode->addDbTable("tofGeomAlign");

  //-- fill structures & store times
  tofGeomAlign_st *tofAlign = new tofGeomAlign_st[NMAX];

// year8
  for(int i=0;i<NMAX;i++) {
    int trayId = i+1;
    tofAlign[i].x0 = 0.;
    tofAlign[i].phi0 = 0.;
    tofAlign[i].z0 = 0.;
    tofAlign[i].angle0 = 0.;
    if(trayId<76||trayId>80) continue;
    tofAlign[i].z0 = -0.5;
  }

// year9

  tofGeomAlign->SetTable((char*)tofAlign, NMAX);
  //- set store time
  dbManager->setStoreTime(ZStoreTime.Data());
  //- store table in dBase
  cout<<" here "<<endl;
  dbManager->storeDbTable(tofGeomAlign);
  cout<<"uploaded"<<endl;
      //    return 0;
}
예제 #3
0
write_fgtSimuParams()
{
    gSystem->Setenv("DB_ACCESS_MODE", "write"); //jb add
    // Load all required libraries
    gROOT->Macro("LoadLogger.C");
    gSystem->Load("St_base.so");
    gSystem->Load("libStDb_Tables.so");
    gSystem->Load("StDbLib.so");

    // Initialize db manager
    StDbManager* mgr = StDbManager::Instance();
    StDbConfigNode* node = mgr->initConfig("Calibrations_fgt");
    StDbTable* dbtable = node->addDbTable("fgtSimuParams");
    TString storeTime = "2011-11-11 11:11:12"; // beginTime timestamp in MySQL format: "YYYY-MM-DD HH:mm:ss"
    mgr->setStoreTime(storeTime.Data());

    // Create your c-struct
    fgtSimuParams_st table;
    memset(table.param,0, sizeof(table.param));

    // Fill structure with data

    /* description of the parameters */
    strncpy(table.comment," reasonable fgt-slow-simu parametrization, ver=102, by Jan",192);

    table.param[0] =102;// fgt-simu-setup version #

    // analog signal propagation
    table.param[1] = 9992; // meLossTab[9993-10000]=5.0E+03 to 6.0E+06 (too high) are cut off. They are replaced by meLossTab[9992]=4.78E+03 in simulation.
    table.param[2] = 40. ; //( ions/cm) # of primary pairs produced per cm of path
    table.param[3] = 80.e-9; //  (seconds) track ignored by FGT slow sim
    table.param[4] = 0.035 ; // cm, for 2D gauss smearing, default=0.035 for FNAL
    table.param[5] = 0.005; // (GeV) track ignored by FGT slow sim
    table.param[6] = 0.017; //  (cm per 1 cm of path)
    table.param[7] = 6; // # of bins in 2D distribution to store 2D gauss
    table.param[8] = -1008; // not used
    table.param[9] = -1009; // not used

    // digitalization
    table.param[10] = 5.0;  //  drop strips below it
    table.param[11] = 1000; // in a.u. used in simu
    table.param[12] = 2.0;  // a factor making simulated ADCs comparable to 2012 pp510 data
    table.param[13] = 0.45; // divide charge between P/R plane

    table.param[14] =  -1014; // not used
    table.param[15] =  -1015; // not used


    // Store data to the StDbTable
    dbtable->SetTable((char*)&table, 1);

    // uncomment next line to set "sim" flavor. "ofl" flavor is set by default, no need to set it.
    // dbtable->setFlavor("sim");

    // Store table to database
    mgr->storeDbTable(dbtable);
}
void write_ladderOnIst_survey()
{
    // Load all required libraries
    gROOT->Macro("LoadLogger.C");
    gSystem->Load("St_base.so");
    gSystem->Load("libStDb_Tables.so");
    gSystem->Load("StDbLib.so");
    
    // Initialize db manager
    StDbManager* mgr = StDbManager::Instance();
    StDbConfigNode* node = mgr->initConfig("Geometry_ist");
    StDbTable* dbtable = node->addDbTable("istLadderOnIst");
    TString storeTime = "2013-06-03 00:00:01"; // beginTime timestamp in MySQL format: "YYYY-MM-DD HH:mm:ss"
    mgr->setStoreTime(storeTime.Data());
    
    // Create your c-struct
    const Int_t MAX_DB_INDEX = 24;
    Survey_st table[MAX_DB_INDEX] = {
{    1,  -0.9386546,-0.3448588, 0.0000009,   0.3448588,-0.9386545,-0.0003118,   0.0001084,-0.0002923, 1.0000000,     1.83780,  13.83121,  -0.01799,     0.10000,   0.10000,   0.10000,   0.10000,   0.10000,   0.10000},
{    2,  -0.8170987,-0.5764977,-0.0001980,   0.5764978,-0.8170987,-0.0003131,   0.0000188,-0.0003700, 0.9999999,     5.36082,  12.88690,  -0.01596,     0.10000,   0.10000,   0.10000,   0.10000,   0.10000,   0.10000},
{    3,  -0.6372711,-0.7706397,-0.0002151,   0.7706397,-0.6372710,-0.0002916,   0.0000877,-0.0003515, 0.9999999,     8.54139,  11.07079,  -0.01330,     0.10000,   0.10000,   0.10000,   0.10000,   0.10000,   0.10000},
{    4,  -0.4170311,-0.9088921,-0.0004269,   0.9088922,-0.4170310,-0.0002802,   0.0000767,-0.0005048, 0.9999999,    11.11433,   8.48280,  -0.02203,     0.10000,   0.10000,   0.10000,   0.10000,   0.10000,   0.10000},
{    5,  -0.1689406,-0.9856262,-0.0002718,   0.9856262,-0.1689406,-0.0001018,   0.0000544,-0.0002851, 1.0000000,    12.91422,   5.35331,  -0.01499,     0.10000,   0.10000,   0.10000,   0.10000,   0.10000,   0.10000},
{    6,   0.0914116,-0.9958132,-0.0000459,   0.9958132, 0.0914116,-0.0001400,   0.0001436,-0.0000329, 1.0000000,    13.86773,   1.78726,  -0.03505,     0.10000,   0.10000,   0.10000,   0.10000,   0.10000,   0.10000},
{    7,   0.3452967,-0.9384935,-0.0003753,   0.9384936, 0.3452967, 0.0000412,   0.0000909,-0.0003665, 0.9999999,    13.89027,  -1.82003,   0.01606,     0.10000,   0.10000,   0.10000,   0.10000,   0.10000,   0.10000},
{    8,   0.5746139,-0.8184245,-0.0003054,   0.8184246, 0.5746140,-0.0000066,   0.0001809,-0.0002462, 1.0000000,    12.92665,  -5.37841,  -0.01333,     0.10000,   0.10000,   0.10000,   0.10000,   0.10000,   0.10000},
{    9,   0.7675071,-0.6410404,-0.0002264,   0.6410404, 0.7675071, 0.0002353,   0.0000229,-0.0003257, 0.9999999,    11.10859,  -8.56426,  -0.01598,     0.10000,   0.10000,   0.10000,   0.10000,   0.10000,   0.10000},
{   10,   0.9063875,-0.4224469,-0.0005581,   0.4224470, 0.9063876, 0.0001256,   0.0004528,-0.0003496, 0.9999998,     8.55075, -11.14552,  -0.00835,     0.10000,   0.10000,   0.10000,   0.10000,   0.10000,   0.10000},
{   11,   0.9859601,-0.1669812,-0.0001645,   0.1669812, 0.9859601,-0.0000114,   0.0001641,-0.0000162, 1.0000000,     5.37389, -12.96024,  -0.02056,     0.10000,   0.10000,   0.10000,   0.10000,   0.10000,   0.10000},
{   12,   0.9957131, 0.0924956,-0.0000016,  -0.0924956, 0.9957131, 0.0001454,   0.0000151,-0.0001447, 1.0000000,     1.83205, -13.89920,  -0.02511,     0.10000,   0.10000,   0.10000,   0.10000,   0.10000,   0.10000},
{   13,   0.9385940, 0.3450235, 0.0000198,  -0.3450235, 0.9385940, 0.0000047,  -0.0000170,-0.0000112, 1.0000000,    -1.85094, -13.90029,  -0.04640,     0.10000,   0.10000,   0.10000,   0.10000,   0.10000,   0.10000},
{   14,   0.8180840, 0.5750986, 0.0002226,  -0.5750986, 0.8180841,-0.0000189,  -0.0001929,-0.0001125, 1.0000000,    -5.34669, -12.95588,  -0.01968,     0.10000,   0.10000,   0.10000,   0.10000,   0.10000,   0.10000},
{   15,   0.6409497, 0.7675829, 0.0001197,  -0.7675829, 0.6409497, 0.0000099,  -0.0000692,-0.0000982, 1.0000000,    -8.49320, -11.14405,  -0.03080,     0.10000,   0.10000,   0.10000,   0.10000,   0.10000,   0.10000},
{   16,   0.4206865, 0.9072061, 0.0001822,  -0.9072060, 0.4206866,-0.0002080,  -0.0002653,-0.0000777, 1.0000000,   -11.11106,  -8.54055,  -0.02871,     0.10000,   0.10000,   0.10000,   0.10000,   0.10000,   0.10000},
{   17,   0.1731180, 0.9849011, 0.0000271,  -0.9849010, 0.1731180,-0.0003385,  -0.0003381, 0.0000319, 0.9999999,   -12.92415,  -5.39332,  -0.02656,     0.10000,   0.10000,   0.10000,   0.10000,   0.10000,   0.10000},
{   18,  -0.0897271, 0.9959664, 0.0001105,  -0.9959664,-0.0897271,-0.0002499,  -0.0002389,-0.0001325, 1.0000000,   -13.89895,  -1.84630,  -0.03826,     0.10000,   0.10000,   0.10000,   0.10000,   0.10000,   0.10000},
{   19,  -0.3455522, 0.9383995, 0.0001560,  -0.9383995,-0.3455520,-0.0004925,  -0.0004083,-0.0003166, 0.9999999,   -13.87018,   1.79885,  -0.01763,     0.10000,   0.10000,   0.10000,   0.10000,   0.10000,   0.10000},
{   20,  -0.5773508, 0.8164962, 0.0000804,  -0.8164961,-0.5773508,-0.0003765,  -0.0002610,-0.0002831, 0.9999999,   -12.96108,   5.28454,  -0.02804,     0.10000,   0.10000,   0.10000,   0.10000,   0.10000,   0.10000},
{   21,  -0.7690576, 0.6391795,-0.0000004,  -0.6391795,-0.7690575,-0.0004490,  -0.0002873,-0.0003451, 0.9999999,   -11.10397,   8.50236,  -0.04087,     0.10000,   0.10000,   0.10000,   0.10000,   0.10000,   0.10000},
{   22,  -0.9079711, 0.4190329,-0.0001319,  -0.4190328,-0.9079710,-0.0003280,  -0.0002572,-0.0002425, 0.9999999,    -8.56630,  11.06194,  -0.02271,     0.10000,   0.10000,   0.10000,   0.10000,   0.10000,   0.10000},
{   23,  -0.9855546, 0.1693579, 0.0001766,  -0.1693579,-0.9855546,-0.0001757,   0.0001443,-0.0002031, 1.0000000,    -5.36303,  12.89607,  -0.01069,     0.10000,   0.10000,   0.10000,   0.10000,   0.10000,   0.10000},
{   24,  -0.9958436,-0.0910796,-0.0000773,   0.0910796,-0.9958436,-0.0002430,  -0.0000549,-0.0002491, 1.0000000,    -1.81861,  13.85204,  -0.01834,     0.10000,   0.10000,   0.10000,   0.10000,   0.10000,   0.10000}
    };
    
    // Store data to the StDbTable
    dbtable->SetTable((char*)&table, MAX_DB_INDEX);
    
    // uncomment next line to set "sim" flavor. "ofl" flavor is set by default, no need to set it.
    dbtable->setFlavor("ofl");
    
    // Store table to database
    mgr->storeDbTable(dbtable);
}
예제 #5
0
void storetofTrgWindow() {

// year8
//  const Int_t NTRAY = 5;
// year9
//  const Int_t NTRAY = 94;
// year10+
  const Int_t NTRAY = 120;
  const Int_t NVPDTRAY = 2;
  const Int_t NMAX = 120;
  const Int_t NMTD = 2; //there is only one MTD, but it has ID=124 (and is only used in Run 10)

  //-- load dBase and Table definition libraries
  gSystem->Load("St_base");
  gSystem->Load("StChain");
  gSystem->Load("StUtilities");
  gSystem->Load("St_Tables.so");
  gSystem->Load("StDbLib.so");
  gSystem->Load("libStDb_Tables.so");

  //-- get the singleton manager
  StDbManager* dbManager = StDbManager::Instance();

  //-- connect to the db & get an empty container
  StDbConfigNode* configNode = dbManager->initConfig("Calibrations_tof");

//----------------------------------------
// History of time stamps (in GMT)
//----------------------------------------
//  TString ZStoreTime = "2007-11-01 00:00:01";
//  TString ZStoreTime = "2009-02-01 00:00:00";  // y9 1st version very loose
//  TString ZStoreTime = "2009-02-01 00:00:01";  // y9 2st version  
//  TString ZStoreTime = "2009-03-26 00:00:00";  // y9 500GeV day 85-92
//  TString ZStoreTime = "2009-04-23 21:00:00";  // 10113066-10146091
//  TString ZStoreTime = "2009-05-27 00:00:00";  // 10147124-10149036
//  TString ZStoreTime = "2009-05-29 14:00:00";  // 10149077-10150023
//  TString ZStoreTime = "2009-05-30 15:30:00";  // 10150024-10152010
//  TString ZStoreTime = "2009-06-03 16:00:00";  // 10154045-...
//
//  TString ZStoreTime = "2009-11-01 00:00:00"; // run 10 preliminary
//  TString ZStoreTime = "2009-11-01 00:01:00"; // updated version, includes MTD
//  TString ZStoreTime = "2009-11-01 00:01:01"; // updated version, (2nd attempt)includes MTD
//  TString ZStoreTime = "2010-12-10 00:00:00"; // run 11 new timing (TOCK)
//  TString ZStoreTime = "2011-12-20 00:00:01"; // run 12 new timing
//  TString ZStoreTime = "2012-03-21 19:50:00"; // run 12 new VPD timing (effective from run 13081013)
//  TString ZStoreTime = "2012-03-21 19:50:01"; // run 12 new VPD timing (corrected, effective from run 13081013)
//  TString ZStoreTime = "2012-12-20 00:00:01"; // run 13 new timing
//  TString ZStoreTime = "2013-12-20 00:00:01"; // run 14 new timing ([email protected])
  TString ZStoreTime = "2014-03-14 00:00:00"; // run 14 new timing (Au+Au@200GeV)


  //-- add table to the container with descriptor given by Database
  StDbTable* tofTrgWindow = configNode->addDbTable("tofTrgWindow");

  //-- fill structures & store times
  tofTrgWindow_st *trg = new tofTrgWindow_st[NMAX+NVPDTRAY+NMTD];

// year 10
// unsigned short cutlow[124]={
// 2828,2825,2826,2826,2832,2831,2835,2831,2836,2832,2832,2829,2833,2830,2833,
// 2831,2824,2826,2825,2824,2827,2836,2833,2830,2829,2831,2838,2833,2837,2838,
// 2836,2838,2850,2841,2847,2845,2845,2846,2843,2838,2837,2836,2835,2835,2829,
// 2824,2830,2829,2828,2827,2806,2807,2807,2814,2815,2818,2813,2821,2826,2828,
// 2891,2901,2891,2894,2891,2897,2894,2900,2899,2899,2898,2904,2905,2904,2898,
// 2904,2907,2912,2916,2916,2908,2914,2908,2914,2903,2902,2907,2901,2901,2898,
// 2895,2894,2897,2896,2896,2906,2903,2908,2907,2914,2911,2698,2913,2915,2915,
// 2916,2914,2913,2913,2912,2914,2909,2905,2908,2902,2898,2902,2895,2899,2899,
// 2857,2921,0,2900};
// unsigned short cuthi[124]={
// 2903,2900,2901,2901,2907,2906,2910,2906,2911,2907,2907,2904,2908,2905,2908,
// 2906,2899,2901,2900,2899,2902,2911,2908,2905,2904,2906,2913,2908,2912,2913,
// 2911,2913,2925,2916,2922,2920,2920,2921,2918,2913,2912,2911,2910,2910,2904,
// 2899,2905,2904,2903,2902,2881,2882,2882,2889,2890,2893,2888,2896,2901,2903,
// 2966,2976,2966,2969,2966,2972,2969,2975,2974,2974,2973,2979,2980,2979,2973,
// 2979,2982,2987,2991,2991,2983,2989,2983,2989,2978,2977,2982,2976,2976,2973,
// 2970,2969,2972,2971,2971,2981,2978,2983,2982,2989,2986,2773,2988,2990,2990,
// 2991,2989,2988,2988,2987,2989,2984,2980,2983,2977,2973,2977,2970,2974,2974,
// 2932,2996,0,2975};

// year 11
//unsigned short cutlow[124]={
//2816,2817,2813,2817,2820,2822,2820,2823,2823,2813,2820,2824,2820,2817,2825,
//2824,2815,2813,2810,2816,2824,2824,2823,2825,2698,2820,2831,2832,2828,2829,
//2830,2837,2839,2835,2840,2837,2840,2838,2840,2834,2836,2824,2826,2830,2822,
//2808,2822,2823,2824,2823,2799,2800,2799,2798,2809,2811,2810,2793,2803,2816,
//2890,2892,2886,2885,2879,2889,2886,2887,2891,2892,2883,2892,2895,2883,2897,
//2884,2904,2904,2902,2889,2901,2904,2904,2902,2884,2897,2895,2892,2895,2889,
//2885,2881,2887,2890,2886,2898,2900,2901,2902,2908,2910,2698,2907,2909,2910,
//2907,2908,2907,2906,2901,2909,2898,2901,2898,2895,2899,2900,2887,2888,2887,
//2850,2913, 0,0};
//unsigned short cuthi[124]={
//2901,2902,2898,2902,2905,2907,2905,2908,2908,2898,2905,2909,2905,2902,2910,
//2909,2900,2898,2895,2901,2909,2909,2908,2910,2783,2905,2916,2917,2913,2914,
//2915,2922,2924,2920,2925,2922,2925,2923,2925,2919,2921,2909,2911,2915,2907,
//2893,2907,2908,2909,2908,2884,2885,2884,2883,2894,2896,2895,2878,2888,2901,
//2975,2977,2971,2970,2964,2974,2971,2972,2976,2977,2968,2977,2980,2968,2982,
//2969,2989,2989,2987,2974,2986,2989,2989,2987,2969,2982,2980,2977,2980,2974,
//2970,2966,2972,2975,2971,2983,2985,2986,2987,2993,2995,2783,2992,2994,2995,
//2992,2993,2992,2991,2986,2994,2983,2986,2983,2980,2984,2985,2972,2973,2972,
//2935,2998,0,0};

// year 12
// unsigned short cutlow[124]={
// 2881,2873,2873,2873,2893,2876,2882,2878,2888,2881,2885,2878,2884,2876,2887,
// 2886,2877,2876,2880,2865,2804,2802,2799,2802,2798,2800,2810,2811,2807,2813,
// 2817,2812,2796,2806,2815,2812,2808,2809,2815,2807,2805,2811,2805,2803,2799,
// 2790,2801,2801,2804,2807,2860,2862,2862,2868,2871,2865,2870,2867,2872,2871,
// 2872,2864,2866,2864,2863,2868,2865,2871,2871,2862,2861,2867,2875,2871,2873,
// 2871,2878,2880,2888,2883,2883,2872,2884,2882,2874,2873,2874,2871,2867,2860,
// 2861,2866,2863,2863,2698,2876,2880,2879,2881,2878,2877,2698,2891,2890,2887,
// 2880,2891,2892,2881,2887,2885,2874,2877,2878,2874,2877,2888,2876,2874,2865,
// 2826,2889,0,0};
// unsigned short cuthi[124]={
// 2966,2958,2958,2958,2978,2961,2967,2963,2973,2966,2970,2963,2969,2961,2972,
// 2971,2962,2961,2965,2950,2889,2887,2884,2887,2883,2885,2895,2896,2892,2898,
// 2902,2897,2881,2891,2900,2897,2893,2894,2900,2892,2890,2896,2890,2888,2884,
// 2875,2886,2886,2889,2892,2945,2947,2947,2953,2956,2950,2955,2952,2957,2956,
// 2957,2949,2951,2949,2948,2953,2950,2956,2956,2947,2946,2952,2960,2956,2958,
// 2956,2963,2965,2973,2968,2968,2957,2969,2967,2959,2958,2959,2956,2952,2945,
// 2946,2951,2948,2948,2783,2961,2965,2964,2966,2963,2962,2783,2976,2975,2972,
// 2965,2976,2977,2966,2972,2970,2959,2962,2963,2959,2962,2973,2961,2959,2950,
// 2911,2974,0,0};
// 
// // year 12 - updated VPD window to lower TOF deadtime (pp500 -- March 22, 2012)
// //  cutlow[120]= 230 ; cuthi[120]= 290;  // VPD West
// //  cutlow[121]= 245 ; cuthi[121]= 305;  // VPD East
// // year 12 - correct updated VPD window to lower TOF deadtime (pp500 -- March 22, 2012, [5/1'12])
//   cutlow[120]= 2834 ; cuthi[120]= 2919;  // VPD West
//   cutlow[121]= 2896 ; cuthi[121]= 2981;  // VPD East


// year 13
// notes: trays 46, 102, and 106 are interpolated values (trays are dead)
// double cutlow[122]={
// 2815,2814,2815,2815,2822,2821,2824,2823,2821,2824,2822,2821,2821,2820,2823,
// 2822,2814,2816,2815,2814,2740,2741,2742,2740,2739,2741,2746,2749,2746,2746,
// 2745,2754,2755,2754,2756,2754,2756,2753,2755,2750,2750,2748,2749,2745,2738,
// 2738,2739,2739,2741,2738,2796,2801,2795,2804,2806,2807,2807,2807,2814,2814,
// 2808,2808,2801,2803,2802,2806,2803,2806,2804,2806,2806,2811,2814,2810,2814,
// 2810,2819,2820,2822,2820,2820,2819,2818,2820,2810,2812,2810,2811,2810,2804,
// 2804,2804,2804,2804,2805,2817,2816,2817,2817,2825,2826,2825,2825,2825,2825,
// 2825,2826,2826,2825,2824,2825,2816,2818,2817,2816,2818,2816,2807,2808,2808,
// 2764,2827};
// double cuthi[122]={
// 2900,2899,2900,2900,2907,2906,2909,2908,2906,2909,2907,2906,2906,2905,2908,
// 2907,2899,2901,2900,2899,2825,2826,2827,2825,2824,2826,2831,2834,2831,2831,
// 2830,2839,2840,2839,2841,2839,2841,2838,2840,2835,2835,2833,2834,2830,2823,
// 2823,2824,2824,2826,2823,2881,2886,2880,2889,2891,2892,2892,2892,2899,2899,
// 2893,2893,2886,2888,2887,2891,2888,2891,2889,2891,2891,2896,2899,2895,2899,
// 2895,2904,2905,2907,2905,2905,2904,2903,2905,2895,2897,2895,2896,2895,2889,
// 2889,2889,2889,2889,2890,2902,2901,2902,2902,2910,2911,2910,2910,2910,2910,
// 2910,2911,2911,2910,2909,2910,2901,2903,2902,2901,2903,2901,2892,2893,2893,
// 2849,2912};


// year 14 -- [email protected] initial
// double cutlow[122]={
// 2909,2910,2910,2911,2918,2917,2916,2917,2916,2917,2917,2916,2915,2916,2918,
// 2918,2909,2910,2910,2911,2836,2852,2837,2836,2834,2834,2842,2845,2841,2841,
// 2841,2850,2851,2850,-23,2850,2851,2849,2851,2843,2843,2844,2844,2841,2834,
// 2834,2835,2836,2837,2834,2892,2894,2892,2900,2900,2903,2903,2902,2909,2909,
// 2906,2906,2898,2898,2899,2903,2901,2902,2901,2903,2903,2908,2911,2907,2910,
// 2908,2915,2918,2918,2916,2916,2916,2916,2916,2907,2907,2907,2907,2907,2900,
// 2901,2902,2902,2901,2902,2914,2914,2914,2914,2923,2922,-23,-23,2922,2922,
// 2922,2921,2923,2922,2922,2922,2914,2916,2913,2913,2914,2913,2906,2906,2905,
// 2859,2921};
// double cuthi[122]={
// 2994,2995,2995,2996,3003,3002,3001,3002,3001,3002,3002,3001,3000,3001,3003,
// 3003,2994,2995,2995,2996,2921,2937,2922,2921,2919,2919,2927,2930,2926,2926,
// 2926,2935,2936,2935,62,2935,2936,2934,2936,2928,2928,2929,2929,2926,2919,
// 2919,2920,2921,2922,2919,2977,2979,2977,2985,2985,2988,2988,2987,2994,2994,
// 2991,2991,2983,2983,2984,2988,2986,2987,2986,2988,2988,2993,2996,2992,2995,
// 2993,3000,3003,3003,3001,3001,3001,3001,3001,2992,2992,2992,2992,2992,2985,
// 2986,2987,2987,2986,2987,2999,2999,2999,2999,3008,3007,62,62,3007,3007,
// 3007,3006,3008,3007,3007,3007,2999,3001,2998,2998,2999,2998,2991,2991,2990,
// 2944,3006};


// year 14 -- Au+Au@200GeV
double cutlow[122]={
2927,2927,2927,2927,2933,2934,2933,2934,2933,2934,2933,2934,2932,2932,2935,
2934,2927,2927,2927,-23,2853,-23,2854,2853,2852,2852,2859,2861,2858,2858,
2858,2866,2868,2866,-23,2866,2868,2866,2868,2861,2861,2861,2861,2858,2851,
2852,2853,2853,2854,2852,2908,2912,2908,2916,2917,2919,2919,2919,2927,2927,
2922,2922,2914,2914,2914,2918,2916,2918,2916,2918,2918,2924,2927,2923,2926,
2923,2931,2933,2933,2931,2931,2931,2931,2931,2923,2924,2923,2923,2923,2916,
2916,2916,2917,2916,2917,2930,2930,2930,2930,2938,2938,-23,-23,2938,2937,
2937,2937,2938,2938,2937,2937,2929,2931,2929,2929,2929,2929,2921,2921,2922,
2877,2937};
double cuthi[122]={
3012,3012,3012,3012,3018,3019,3018,3019,3018,3019,3018,3019,3017,3017,3020,
3019,3012,3012,3012,62,2938,62,2939,2938,2937,2937,2944,2946,2943,2943,
2943,2951,2953,2951,62,2951,2953,2951,2953,2946,2946,2946,2946,2943,2936,
2937,2938,2938,2939,2937,2993,2997,2993,3001,3002,3004,3004,3004,3012,3012,
3007,3007,2999,2999,2999,3003,3001,3003,3001,3003,3003,3009,3012,3008,3011,
3008,3016,3018,3018,3016,3016,3016,3016,3016,3008,3009,3008,3008,3008,3001,
3001,3001,3002,3001,3002,3015,3015,3015,3015,3023,3023,62,62,3023,3022,
3022,3022,3023,3023,3022,3022,3014,3016,3014,3014,3014,3014,3006,3006,3007,
2962,3022};



// ---------------------------------------------
//- Prepare table
  for(int i=0;i<NMAX+NVPDTRAY;i++) {
    trg[i].trgWindow_Min = cutlow[i];
    trg[i].trgWindow_Max = cuthi[i];
    cout << " tray = " << i+1 << " min = " << trg[i].trgWindow_Min << " max = " << trg[i].trgWindow_Max << endl;
  }

// Store data in table
  tofTrgWindow->SetTable((char*)trg, NMAX+NVPDTRAY);
//- set store time
  dbManager->setStoreTime(ZStoreTime.Data());
// Store table in dBase
  cout<<" here "<<endl;
  dbManager->storeDbTable(tofTrgWindow);
  cout<<"uploaded"<<endl;
}
예제 #6
0
void storetofINLSCorr()
//int main(int argc, char *argv[])

{

  const Int_t NMAX = 1200;
  const Int_t NTDC = 3;  // # of tdcs per board
  const Int_t NCHAN = 8;  // # of channels per tdc

  //-- load dBase and Table definition libraries
  gSystem->Load("St_base");
  gSystem->Load("StChain");
  gSystem->Load("StUtilities");
  gSystem->Load("St_Tables.so");

  gSystem->Load("StDbLib.so");
  gSystem->Load("libStDb_Tables.so");

  //-- get the singleton manager
  StDbManager* dbManager = StDbManager::Instance();

  //-- connect to the db & get an empty container
  StDbConfigNode* configNode = dbManager->initConfig("Calibrations_tof");

  //----------------------------------------
  TString ZStoreTime = "2008-11-01 00:00:00";

  //-- add table to the container with descriptor given by Database
  StDbTable* tofINLSCorr = configNode->addDbTable("tofINLSCorr");

  //-- fill structures & store times
  tofINLSCorr_st *inlcorr= new tofINLSCorr_st[NMAX*NTDC*NCHAN];

  Int_t NFILL = 0;
  Int_t NBOARD = 0;
  // read in inltable file by file.

  TH1S *hINLSCorr[NMAX][NTDC][NCHAN];
  Bool_t *hFlag[NMAX];
  for(int i=0;i<NMAX;i++) hFlag[i] = false;

  TFile *f = new TFile("INL_test.root");

  for(int iboard=0;iboard<NMAX;iboard++) {    
    if(iboard%100==0) cout << " Processing board Id = " << iboard << endl;

    for(int itdc=0;itdc<NTDC;itdc++){
      for(int ichan=0;ichan<NCHAN;ichan++) {

	char hisname[512];
	sprintf(hisname,"b_%d_tdc_%d_chan_%d",iboard,itdc,ichan);

        hINLSCorr[iboard][itdc][ichan] = (TH1S *)f->Get(hisname);

        if(!hINLSCorr[iboard][itdc][ichan]) {
//          cout << " Histogram board " << iboard << " itdc " << itdc << " ichan " << ichan << " doesn't exist!" << endl;
          continue;
        }

	inlcorr[NFILL].tdigId = (Short_t)iboard;
	inlcorr[NFILL].tdcChanId = (Short_t)(itdc*NCHAN+ichan);	
	
	for(int j=0;j<1024;j++) {
	  inlcorr[NFILL].INLCorr[j]=(Short_t)(hINLSCorr[iboard][itdc][ichan]->GetBinContent(j+1));
	}
      

	NFILL++;
      } // end of loop channel
    }  // end of loop TDC

    NBOARD++;
    hFlag[iboard] = true;

  } // end of loop board
  cout<<" prepare to upload data to DB NFILL="<<NFILL<<" NBOARD="<<NBOARD<<endl;

/*
  char rootname[100];
  sprintf(rootname,"INL_test.root");
  TFile *fout = new TFile(rootname,"recreate");
  int index = 0;
  for(int iboard=0;iboard<NMAX;iboard++) {
    if(!hFlag[iboard]) continue;

    for(int itdc=0;itdc<NTDC;itdc++){
      for(int ichan=0;ichan<NCHAN;ichan++) {
	if(!hINLSCorr[iboard][itdc][ichan]) continue;
	hINLSCorr[iboard][itdc][ichan]->Write();

	cout << " Ids = " << iboard << " " << itdc << " " << ichan << endl;
	cout << " IN Ids = " << inlcorr[index].tdigId << " " << inlcorr[index].tdcChanId << endl;
	for(int j=0;j<1024;j++) {
	  if(j%100==0)
	    cout << " INL j = " << j << " " << inlcorr[index].INLCorr[j] << endl;
	}
	index++;
      }
    }    
  }
  fout->Close();
*/

  //- store data in table
  tofINLSCorr->SetTable((char*)inlcorr, NFILL);
  //- set store time
  dbManager->setStoreTime(ZStoreTime.Data());
  //- store table in dBase
  cout<<" here "<<endl;
  dbManager->storeDbTable(tofINLSCorr);
  cout<<"uploaded"<<endl;
      //    return 0;
}
예제 #7
0
void fms_db_ChannelGeometry(char* opt="readdb", int year = 15) {

  TString option(opt);
  std::cout << "Opt =" << opt << "\n";
  std::cout << "readdb = " << option.Contains("readdb")    << "\n";
  std::cout << "writedb = " << option.Contains("writedb")   << "\n";
  std::cout << "\n";  

  TString storeTime; // storetime is begin time for validity range for WRITING DB
  int date,time;     // time for READING DB
  std::cout << "year = " << year << "\n";
  if(year==8){
    storeTime="2007-11-09 00:00:02";
    date = 20080301;
    time = 0;
  }else if(year==9){
    storeTime="2008-11-09 00:00:01";
    date = 20090301;
    time = 0;
  }else if(year=15){
    storeTime="2014-12-20 00:00:00";
    date = 20141220;
//    date = 20140222;
    time = 0;
  }
  else{
    std::cout << "Please specify year\n";
    exit;
  }
  std::cout << "storetime =" << storeTime << "\n";
  std::cout << "date,time =" << date <<" "<< time << "\n";
  
  gROOT->Macro("LoadLogger.C");
  gSystem->Load("St_base.so");
  gSystem->Load("libStDb_Tables.so");
  gSystem->Load("StDbLib.so");

  // max index dimensions
  const Int_t MAXINDEX = 12;
  int n=0;

  // structure to fill up
  fmsChannelGeometry_st g[MAXINDEX];
  memset(g,0,sizeof(g));

  gSystem->Load("StChain");
  gSystem->Load("StBFChain");
  gSystem->Load("StUtilities");
  gSystem->Load("StIOMaker");
  gSystem->Load("StarClassLibrary");
  gSystem->Load("St_Tables");
  gSystem->Load("StDbLib");
  gSystem->Load("StDbBroker");
  gSystem->Load("St_db_Maker");
  
  St_db_Maker *dbMk=new St_db_Maker("db", "MySQL:StarDb", "$STAR/StarDb");
  dbMk->SetDebug();
  dbMk->SetDateTime(date,time);
  dbMk->SetFlavor("ofl"); // for offline calibrations/mapping
  // dbMk->SetFlavor("simu"); // for simulations
  dbMk->Init();
  dbMk->Make();
  
  // this is done inside ::Make method
  TDataSet *DB = 0;
  // "dbMk->" will NOT be needed. 
  //  if done inside your FmsDbMaker. Simply use DB = GetInputDb("Geometry/fms")
  DB = dbMk->GetInputDB("Geometry/fms/");
  if (!DB) { std::cout << "ERROR: no db maker?" << std::endl; }
  
  if(option.Contains("readdb")){
    gSystem->Unsetenv("DB_ACCESS_MODE");
    gSystem->Unsetenv("DB_SERVER_LOCAL_CONFIG");
    St_fmsChannelGeometry *db = 0;
    db = (St_fmsChannelGeometry*) DB->Find("fmsChannelGeometry");
    // fetch data and place it to appropriate structure
    if (db) {
      std::cout << "Reading fmsMap table\n";
      fmsChannelGeometry_st *table = db->GetTable();
      n = db->GetNRows();
      memcpy(g,table,sizeof(fmsChannelGeometry_st)*n);
    } else {
      std::cout << "WARNING: No data in fmsChannelGeometry table (wrong timestamp?). Nothing to return, then.\n";
    }
  }
 
 if(option.Contains("writedb")) {
    gSystem->Setenv("DB_ACCESS_MODE","write");
    cout << "DB_ACCESS_MODE="<<gSystem->Getenv("DB_ACCESS_MODE")<<endl;
    StDbManager* mgr = StDbManager::Instance();
    StDbConfigNode* node = mgr->initConfig("Geometry_fms");
    StDbTable* wtable = node->addDbTable("fmsChannelGeometry");	  
    mgr->setStoreTime(storeTime.Data());

    // input data
    /* Detector Name   detectorId  ew  ns  type   nX   nY  */
    /* FPD-North            0       0   0   0      7    7  */
    /* FPD-South            1       0   1   0      7    7  */
    /* FPD-North-Pres       2       0   0   1      7    1  */
    /* FPD-South-Pres       3       0   1   1      7    1  */
    /* FPD-North-SMDV       4       0   0   2     48    1  */
    /* FPD-South-SMDV       5       0   1   2     48    1  */
    /* FPD-North-SMDH       6       0   0   3      1   48  */
    /* FPD-South-SMDH       7       0   1   3      1   48  */
    /* FMS-North-Large      8       1   0   4     17   34  */
    /* FMS-South-Large      9       1   1   4     17   34  */
    /* FMS-North-Small     10       1   0   0     12   24  */
    /* FMS-South-Small     11       1   1   0     12   24  */
    /* FHC-North           12       1   0   5      9   12  */
    /* FHC-South           13       1   1   5      9   12  */

    int n=0;
    g[n].detectorId = 0; g[n].type=0; g[n].ew=0; g[n].ns=0; g[n].nX= 7; g[n].nY= 7;    n++;
    g[n].detectorId = 1; g[n].type=0; g[n].ew=0; g[n].ns=1; g[n].nX= 7; g[n].nY= 7;    n++;
    g[n].detectorId = 2; g[n].type=1; g[n].ew=0; g[n].ns=0; g[n].nX= 7; g[n].nY= 1;    n++;
    g[n].detectorId = 3; g[n].type=1; g[n].ew=0; g[n].ns=1; g[n].nX= 7; g[n].nY= 1;    n++;
    if(year>=9){								       	   
      g[n].detectorId = 4; g[n].type=2; g[n].ew=0; g[n].ns=0; g[n].nX=48; g[n].nY= 1;  n++;
      g[n].detectorId = 5; g[n].type=2; g[n].ew=0; g[n].ns=1; g[n].nX=48; g[n].nY= 1;  n++;
      g[n].detectorId = 6; g[n].type=3; g[n].ew=0; g[n].ns=0; g[n].nX= 1; g[n].nY=48;  n++;
      g[n].detectorId = 7; g[n].type=3; g[n].ew=0; g[n].ns=1; g[n].nX= 1; g[n].nY=48;  n++;
    }										       	   
    g[n].detectorId = 8; g[n].type=4; g[n].ew=1; g[n].ns=0; g[n].nX=17; g[n].nY=34;    n++;
    g[n].detectorId = 9; g[n].type=4; g[n].ew=1; g[n].ns=1; g[n].nX=17; g[n].nY=34;    n++;
    g[n].detectorId =10; g[n].type=0; g[n].ew=1; g[n].ns=0; g[n].nX=12; g[n].nY=24;    n++;
    g[n].detectorId =11; g[n].type=0; g[n].ew=1; g[n].ns=1; g[n].nX=12; g[n].nY=24;    n++;
    
    // store data in the table
    wtable->SetTable((char*)&g,n);
    // store table in dBase
    mgr->storeDbTable(wtable); 
    gSystem->Unsetenv("DB_ACCESS_MODE");
    std::cout << "Done with database upload \n";
 }
 
 printf("n = %d\n",n);
 printf(" Id Typ  ew  ns  nX  nY\n");
 for(int i=0; i<n; i++){
   printf("%3d %3d %3d %3d %3d %3d\n",g[i].detectorId,g[i].type,g[i].ew,g[i].ns,g[i].nX,g[i].nY);
 }
}
예제 #8
0
파일: eemcDb.C 프로젝트: star-bnl/star-emc
//---------------------------------------------------------------------
//---------------------------------------------------------------------
//---------------------------------------------------------------------
int 
main(int argc, char *argv[]) 
{
  extern char *optarg;
  int    optInd   = 0;
  char   optChar  = 0;  

  static struct option optLong[] = {
    { "database"   , 1 , 0           , 'D' },
    { "path"       , 1 , 0           , 'p' },
    { "time"       , 1 , 0           , 't' },
    { "expiration" , 1 , 0           , 'x' },
    { "flavor"     , 1 , 0           , 'F' },
    { "file"       , 1 , 0           , 'f' },
    { "get"        , 0 , (int *)&action ,  GetDB  },
    { "read"       , 0 , (int *)&action ,  GetDB  },
    { "set"        , 0 , (int *)&action ,  SetDB  },
    { "write"      , 0 , (int *)&action ,  SetDB  },
    { "tree"       , 0 , (int *)&action ,  PrintTree },
    { "history"    , 0 , (int *)&action ,  PrintHistory },
    { "config"     , 0 , (int *)&action ,  PrintConfig },
    { "comment"    , 1 , 0              , 'c' },
    { "verbose"    , 0 , &verboseMode   , true},
    { "quiet"      , 0 , &verboseMode   , false},
    { "dataonly"   , 0 , &dataOnlyMode  , true},
    { "debug"      , 0 , &debugMode     , true},
    { "help"       , 0 , 0              , 'h' },
    { 0, 0, 0, 0}
  };


  //   cout << indexFromString("05TB01" )  << endl;
  //   cout << indexFromString("P05TB01")  << endl;
  //   cout << indexFromString("05P1" ,kEEmcMaxSect*kEEmcMaxBox)  << endl;
  //   cout << indexFromString("E05TB",kEEmcMaxSect*kEEmcMaxBox)  << endl;
  //   cout << indexFromString("12TB13" )  << endl;
  //   cout << indexFromString("V12TB13")  << endl;
  //   cout << indexFromString("13TG"  ,kEEmcMaxSect*kEEmcMaxBox) << endl;
  //   cout << indexFromString("A13TG" ,kEEmcMaxSect*kEEmcMaxBox) << endl;
  //   exit(0);

  // arguments and init
  argv0 = strrchr(argv[0],'/');
  argv0 = ( argv0 == NULL )  ? argv[0] : ++argv0 ;

  while((optChar = getopt_long(argc,argv,"D:p:t:x:F:f:c:grswTHCdvqh",optLong,&optInd)) != EOF) {
    switch(optChar) {
    case  0  : break;
    case 'D' : dbName      = optarg;       break;
    case 'p' : dbPath      = optarg;       break;
    case 't' : dbTime      = optarg;       break;
    case 'x' : dbExpTime   = optarg;       break;
    case 'F' : dbFlavor    = optarg;       break; 
    case 'f' : dbFile      = optarg;       break; 
    case 'r' : // same as g
    case 'g' : action      = GetDB;        break;
    case 'w' : // same as s
    case 's' : action      = SetDB;        break;
    case 'T' : action      = PrintTree;    break;
    case 'H' : action      = PrintHistory; break;
    case 'C' : action      = PrintConfig;  break;
    case 'c' : dbComment   = optarg;       break;  
    case 'd' : dataOnlyMode= true;         break;
    case 'v' : verboseMode = true;         break;
    case 'q' : quietMode   = true;         break;
    case 'h' : usage(); return(0);         break;
    default  : usage("unknown option");    break;
    };
  }
  if(!dbPath  && action!=PrintConfig ) usage("database path missing");


  // 
  StDbManager    *mgr    = StDbManager::Instance();
  StDbConfigNode *dbNode = NULL;
  StDbTable      *dbTab  = NULL;
  char           *node   = NULL;
  FILE           *file   = NULL;

  mgr->setVerbose(verboseMode);
  mgr->setQuiet(quietMode);

  // sanity check 
  if( ! mgr->findDefaultServer() ) {
    fprintf(stderr,"cannot find the default DB server\n");
    return(-1);
  }

  if(dbFile) { 
    file = fopen(dbFile,(action==SetDB) ? "r" : "w");
    if(!file) { 
      fprintf(stderr,"%s: fopen '%s' failed, %s\n",argv0,dbFile,strerror(errno)); 
      return(-1); 
    }
  } else {
    file = (action==SetDB) ? stdin : stdout;
  }

  switch(action) {
  case PrintTree:
    node   = node=strsep(&dbPath,"/");
    if(node) { 
      dbNode = mgr->initConfig(dbName,node);
      if(dbNode) { 
	if(verboseMode || !quietMode) 
	  fprintf  (file,"DATABASE TREE:\n");
	fprintf  (file,"%s/\n",node);
	if(printTree(file,dbNode)<=0) {
	  fprintf  (stderr,"config %s is empty\n",node);
	}
      }
    }
    return 0;
    break;
  case PrintConfig:
    if(verboseMode || !quietMode) 
     fprintf(file,"DATABASE VERSIONS:\n");
    printConfig(file,mgr);
    return 0;
  default:
    break;
  }


  // parse database path 
  char *preNode="";
  while( (node=strsep(&dbPath,"/")) != NULL ) {
    StDbConfigNode *tn = (dbNode==NULL) ? 
      mgr->initConfig(dbName,node) : dbNode->findConfigNode(node);
    if(!tn) break; // assume the last token is a db table
    dbNode = tn;
    printf("found database node: %s\n",node);
    preNode=node;
  }

  if(!node) usage("invalid path");

  dbTab = dbNode->findTable(node);
  if(!dbTab) { fprintf(stderr,"%s: table %s not found\n",argv0,node); return (-1); }

  dprintf("found table: %s\n",node);

  int nrows=dbTab->GetNRows();
  int ndata=0;
  
  EEmcDbIOBase *dbIO = getDbIO(preNode,node,nrows);
  if(dbIO==NULL) return(-1);

  char keyLine[EEmcDbMaxDbPathLen];
  //char keyFile[EEmcDbMaxKeyLength];
  char keyBase[EEmcDbMaxKeyLength];
  time_t tUnix    =                     getTimeStamp(dbTimeFormat,dbTime);
  time_t tExpUnix = (dbExpTime!=NULL) ? getTimeStamp(dbTimeFormat,dbExpTime) : 0;

  dbTab->setFlavor(dbFlavor);
  switch(action) {
  case PrintHistory:
    printHistory(file,mgr,dbTab,dbIO); 
    return 0; 
    break;
  case SetDB:
    fgets (keyLine,EEmcDbMaxDbPathLen-1,file);
    sprintf(keyBase,EEmcDbKeyFormat,dbNode->printName(),node);
    printf("AAA=%s=\n",keyBase);
    if(strstr(keyLine,keyBase)==0 &&  strcmp(keyLine,keyToEverything) ) {
      fprintf(stderr,"signature mismatch: data file key '%s', required '%s'\n",
	      keyLine,keyBase);
      return (-1);
    }

    dbIO->setComment(dbComment);

    ndata = dbIO->read(file);
    if(ndata<=0) {
      fprintf(stderr,"%s: reading file %s failed\n",argv0,dbFile);
      return(-1);
    }
    if(nrows>1) { 
      dbTab->SetTable(dbIO->getData(),ndata, dbIO->getIndices());
    } else {
      dbTab->SetTable(dbIO->getData(),ndata);
    }
    if(tExpUnix>0) { 
      dbTab->setEndStoreTime(tExpUnix);
      fprintf(stderr,"%s: setting end time %ld\n",argv0,tExpUnix);
    }

    //mgr->setStoreTime(getTimeStamp(dbTimeFormat,dbTime));
    mgr->setStoreTime(tUnix);
    if(! mgr->storeDbTable(dbTab) ) {
      fprintf(stderr,"%s: storing table %s failed\n",argv0,node);
      return(-1);
    }
  
    break;
  case GetDB:
    mgr  ->setRequestTime(tUnix);
    if( ! mgr->fetchDbTable(dbTab) ) {
      fprintf(stderr,"%s: problem with fetch for time stamp %ld / %s",argv0,tUnix,ctime(&tUnix));
      fprintf(stderr," There is no record for this table over the time period :\n");
      fprintf(stderr," BeginDate     = %s\t",dbTab->getBeginDateTime());
      fprintf(stderr,"   EndDate     = %s\n",dbTab->getEndDateTime());
      fprintf(stderr," BeginTimeUnix = %d\t",dbTab->getBeginTime());
      fprintf(stderr,"   EndTimeUnix = %d\n",dbTab->getEndTime());
      return(-1);
    }
    if(! dbTab->GetTable() ) {
      fprintf(stderr,"no data found in table %s\n",node);
      return(-1);
    } 
    dbIO->setData(dbTab->GetTable());

    if(verboseMode || !quietMode)
    fprintf(stderr,"BNL Time Stamp Range  from: %s   to:    %s \n",
	    fmtSqlTime(dbTab->getBeginDateTime()),fmtSqlTime(dbTab->getEndDateTime()));
    if(!dataOnlyMode) {
      fprintf(file,EEmcDbKeyFormat,dbNode->printName(),node);
      fprintf(file,"\n");
    }
    ndata     = dbIO->write(file);
    dbComment = dbIO->getComment();
    if(verboseMode || !quietMode)
      fprintf(stderr,"COMMENT: %s\n",dbComment);
    break;
  default:
    break;
  } 

  if(ndata>0) {  
    dprintf("database access successful %d\n",ndata);
  } else { 
    fprintf(stderr,"%s: table %s access failed\n",argv0,node); 
  }
    

  fclose(file);
  return 0; 
} 
예제 #9
0
void fpsGain_db(char* opt="", char* year="15sim") {
  TString option(opt), yr(year);  
  TString storeTime; // storetime is begin time for validity range for WRITING DB
  int date,time;     // time for READING DB
  std::cout << "year = " << year << "\n";
  if(yr.Contains("15ofl")){
    storeTime="2014-12-20 00:00:01";
    date = 20141225; time = 0;
  }else if(yr.Contains("15sim")){
    storeTime="2014-12-10 00:00:02";
    date = 20141215; time = 0;
  }else{
    std::cout << "Please specify valid year tag\n"; exit;
  }
  std::cout << "Opt =" << opt << "\n";
  std::cout << "write = " << option.Contains("writedb")   << "\n";
  std::cout << "storetime =" << storeTime << "\n";
  std::cout << "date,time =" << date <<" "<< time << "\n";
  
  gROOT->Macro("loadlib.C");
  
  const Int_t MAX_DB_INDEX = 252;
  fpsGain_st table[MAX_DB_INDEX];

  if(option.Contains("writedb")) {
    gSystem->Setenv("DB_ACCESS_MODE","write");
    StDbManager* mgr = StDbManager::Instance();
    StDbConfigNode* node = mgr->initConfig("Calibrations_fps");
    StDbTable* dbtable = node->addDbTable("fpsGain");
    mgr->setStoreTime(storeTime.Data());
    
    int id=0;
    for (Int_t q = 1; q <= 4; q++) {
      for (Int_t l = 1; l <= 3; l++) {
	for (Int_t s = 1; s <= 21; s++) {
	  table[id].slatid = id; 
	  int flag=0;
	  if(q==2 || q==4){
	    if(s>=20) flag=1;
	  }	    
	  float mip=100.0;
	  if(l==3) mip=50.0;
	  if(flag==0){table[id].slatid = id; table[id].MIP=mip;} 
	  else       {table[id].slatid = id; table[id].MIP=0;} 
	  printf("id=%3d Q%1dL%1dS%2d mip=%f\n",id,q,l,s,table[id].MIP);
	  id++;
	}
      }
    }

    dbtable->SetTable((char*)&table, MAX_DB_INDEX);
    if(yr.Contains("sim")) dbtable->setFlavor("sim");
    mgr->storeDbTable(dbtable);    
    std::cout << "INFO: table saved to database" << std::endl;
  }

  std::cout << "INFO: Reading database" << std::endl;  
  gSystem->Unsetenv("DB_ACCESS_MODE");
  //gSystem->Unsetenv("DB_SERVER_LOCAL_CONFIG");
  St_db_Maker *dbMk=new St_db_Maker("db", "MySQL:StarDb", "$STAR/StarDb");
  dbMk->SetDebug();
  dbMk->SetDateTime(date,time); // event or run start time, set to your liking
  if(yr.Contains("ofl"))      {dbMk->SetFlavor("ofl");}
  else if(yr.Contains("sim")) {dbMk->SetFlavor("sim");}
  dbMk->Init();
  dbMk->Make();
  TDataSet *DB = 0;
  DB = dbMk->GetDataBase("Calibrations/fps/fpsGain");
  if (!DB) std::cout << "ERROR: no table found in db, or malformed local db config" << std::endl;
  St_fpsGain *dataset = 0;
  dataset = (St_fpsGain*) DB->Find("fpsGain");
  if (!dataset) {
    td::cout << "ERROR: dataset does not contain requested table" << std::endl;
    return;
  }
  Int_t rows = dataset->GetNRows();
  if (rows > 1) {
    std::cout << "INFO: found INDEXED table with " << rows << " rows" << std::endl;
  }
  TDatime val[2];
  dbMk->GetValidity((TTable*)dataset,val);
  std::cout << "Dataset validity range: [ " << val[0].GetDate() << "." << val[0].GetTime() << " - " 
	    << val[1].GetDate() << "." << val[1].GetTime() << " ] "
	    << std::endl;    
  fpsGain_st *tbl = dataset->GetTable();
  for (Int_t i = 0; i < rows; i++) {
    std::cout << Form("Row=%4d slatid=%3d MIP=%8.4f\n",i,
		      tbl[i].slatid,tbl[i].MIP);
  }
}
예제 #10
0
int write_trigger_thresholds(int runNumber = 13078009)
{

  // Load all required libraries
  gROOT->Macro("loadMuDst.C");
  gROOT->Macro("LoadLogger.C");
  gSystem->Load("St_base.so");
  gSystem->Load("libStDb_Tables.so");
  gSystem->Load("StDbLib.so");

  gSystem->Load("StEmcRawMaker");
  gSystem->Load("StEmcADCtoEMaker");
  gSystem->Load("StEEmcUtil");
  gSystem->Load("StEEmcDbMaker");
  gSystem->Load("StTriggerUtilities");
  //******//
  gSystem->Setenv("DB_ACCESS_MODE","write");
  //******//  
  // Initialize db manager
  ///*
  StDbManager* mgr = StDbManager::Instance();
  StDbConfigNode* node = mgr->initConfig("Calibrations_trg");
  StDbTable* dbtable = node->addDbTable("triggerThreshold");
  // beginTime timestamp in MySQL format: "YYYY-MM-DD HH:mm:ss"
  ifstream intime(Form("beginTimes/%d.beginTimes.txt", runNumber));
  if(!intime){
    cout<<"can't open beginTime file"<<endl;
    return 0;
  }
  char date[10];
  char time[8];
  intime >> date >> time;
  TString storeTime(Form("%s %s", date, time));
  //******//
  //time stamp 2012-07-30 00:00:0X for test purposes
  //TString storeTime("2012-07-30 00:00:02");
  //******//
  mgr->setStoreTime(storeTime.Data());
 // */
  // Create your c-struct
  triggerThreshold_st table;
  
  // Fill structure with data 
  // sample setup for a single channel, please add more channels!
  strcpy(table.comments, Form("run%d triggerThreshold uploaded by zchang", runNumber)); 
  cout<<"comments set to "<<table.comments<<endl;

  TObjArray objarr = readOnline(runNumber);
  TBufferFile buf(TBuffer::kWrite);
  buf << &objarr;
  objarr.Delete();

  cout<<"Buffer size: "<<buf.BufferSize()<<endl;

  memset(table.trigthr, 0, buf.BufferSize());
  memcpy(table.trigthr, buf.Buffer(), buf.BufferSize());
  table.size = buf.BufferSize();

  //******//
  // Store data to the StDbTable
  dbtable->SetTable((char*)&table, 1);
  
  // uncomment next line to set "sim" flavor. "ofl" flavor is set by default, no need to set it.
  // dbtable->setFlavor("sim");
  
  // Store table to database
  cout<<"Storing Db table: "<< mgr->storeDbTable(dbtable) << endl;
  //******//

  ofstream out(Form("buffer/%d.trigthr.buffer.out", runNumber));
  assert(out);
  out.write(buf.Buffer(),buf.BufferSize());
  out.close();

  return 1;
}
예제 #11
0
void fPostStatus_db(
		const char* opt   = "",
		const char* year  = "17sim",
		const char* input = "fPostStatus.txt",
		int readdate = 0,
		int readtime = 0)
{
    // storeTime is beginning time for validity range in case of WRITING DB
    TString option(opt), yr(year), storeTime;
    int date, time; // time for READING DB
    
    std::cout <<"year = " <<year <<std::endl;
    if (yr.Contains("17sim"))
	{
	    storeTime = "2016-12-10 00:00:00";
	    date = 20161210;
	    time = 0;
	}
    else if (yr.Contains("17ofl"))
	{
	    storeTime = "2016-12-20 00:00:00";
	    date = 20161220;
	    time = 0;
	}
    else { std::cout << "Please specify valid year tag\n"; exit; }

	if (readdate > 0) date = readdate;
	if (readtime > 0) time = readtime;

    std::cout << "Opt ="         << opt << "\n";
    std::cout << "write = "      << option.Contains("writedb") << "\n";
    std::cout << "storetime = "  << storeTime << "\n";
    std::cout << "date, time = " << date <<" "<< time << "\n";
    
    gROOT->Macro("./loadlib.C");
    
    //-------------------------------------------
    
    const Int_t MAX_DB_INDEX = 241;
    fpostStatus_st in[MAX_DB_INDEX];
    
    FILE *FP = fopen(input, "r");
    if (!FP) { printf("Could not open %s\n", input); exit; }
    printf("\nReading %s\n", input);
    
    char line[1000];
    int n = 0;
    while (fgets(line, 1000, FP) != NULL)
    {	
        sscanf(line,"%hu %hu", &in[n].slatid, &in[n].status);
        printf("slatId=%3d status=%1d\n", in[n].slatid, in[n].status);
        n++;
    }
    printf("Found %d entries\n", n);
    fclose(FP);
    printf("File Closed\n", n);
    
    //-------------------------------------------
    
	#if 1
    if (option.Contains("writedb"))
	{
	    gSystem->Setenv("DB_ACCESS_MODE", "write");
	    StDbManager*    mgr     = StDbManager::Instance();
	    StDbConfigNode* node    = mgr->initConfig("Calibrations_fps");
	    StDbTable*      dbtable = node->addDbTable("fpostStatus");
	    mgr->setStoreTime(storeTime.Data());
	    dbtable->SetTable((char*)&in, MAX_DB_INDEX);
	    if (yr.Contains("sim")) dbtable->setFlavor("sim");
	    mgr->storeDbTable(dbtable);
	    std::cout << "INFO: table saved to database" << std::endl;
	}

	//-------------------------------------------

    if (option.Contains("readdb"))
	{
	    std::cout << "INFO: Reading database" << std::endl;
	    gSystem->Unsetenv("DB_ACCESS_MODE");
	    //gSystem->Unsetenv("DB_SERVER_LOCAL_CONFIG");
	    
	    St_db_Maker* dbMk = new St_db_Maker("db", "MySQL:StarDb", "$STAR/StarDb");
	    dbMk->SetDebug();
	    dbMk->SetDateTime(date, time); // event or run start time, set to your liking
	    if      (yr.Contains("ofl")) { dbMk->SetFlavor("ofl"); }
	    else if (yr.Contains("sim")) { dbMk->SetFlavor("sim"); }
	    dbMk->Init();
	    dbMk->Make();
	    
	    TDataSet *DB = 0;
	    DB = dbMk->GetDataBase("Calibrations/fps/fpostStatus");
	    if (!DB) std::cout << "ERROR: no table found in db, or malformed local db config" << std::endl;
	    
	    St_fpostStatus *dataset = 0;
	    dataset = (St_fpostStatus*) DB->Find("fpostStatus");
	    if (!dataset) { std::cout << "ERROR: dataset does not contain requested table" << std::endl; return; }
	    Int_t rows = dataset->GetNRows();
	    if (rows > 1) std::cout << "INFO: found INDEXED table with " << rows << " rows" << std::endl;
	    
	    TDatime val[2];
	    dbMk->GetValidity((TTable*)dataset, val);
	    std::cout << "Dataset validity range: [ " << val[0].GetDate() << "." << val[0].GetTime() << " - "
		      << val[1].GetDate() << "." << val[1].GetTime() << " ] " << std::endl;
	    
	    fpostStatus_st *table = (fpostStatus_st*)dataset->GetTable();
	    for (Int_t i = 0; i < rows; i++)
		{
		    std::cout << Form("Row=%3d slatid=%3d status=%1d\n", i, table[i].slatid, table[i].status);
		}
	}
	#endif

    return;
}//Main
예제 #12
0
void fpsMap_db(char* opt="", char* year="15sim", char* input="fpsmap.txt") {
  TString option(opt), yr(year);  
  TString storeTime; // storetime is begin time for validity range for WRITING DB
  int date,time;     // time for READING DB
  std::cout << "year = " << year << "\n";
  if(yr.Contains("15ofl")){
    storeTime="2014-12-20 00:00:3";
    date = 20141221; time = 0;
  }else if(yr.Contains("15sim")){
    storeTime="2014-12-10 00:00:01";
    date = 20141210; time = 1;
  }else if(yr.Contains("17ofl")){
      storeTime="2016-12-20 00:00:00";
      date = 20161220; time = 0;
  }else if(yr.Contains("17sim")){
      storeTime="2016-12-10 00:00:00";
      date = 20161210; time = 0;
  }else{
    std::cout << "Please specify valid year tag\n"; exit;
  }
  std::cout << "Opt =" << opt << "\n";
  std::cout << "write = " << option.Contains("writedb")   << "\n";
  std::cout << "storetime =" << storeTime << "\n";
  std::cout << "date,time =" << date <<" "<< time << "\n";
  
  gROOT->Macro("./loadlib.C");
  
  const Int_t MAX_DB_INDEX = 252;
  fpsMap_st in[MAX_DB_INDEX];
  for(int i=0; i<MAX_DB_INDEX; i++){
    in[i].slatid=i;
    in[i].QTaddr=-1;
    in[i].QTch=-1;
  }
  
  FILE *FP = fopen(input,"r");
  if(!FP) { printf("Could not open %s\n",input); exit;}
  printf("Reading %s\n",input);
  char line[1000], nw[10], dc[10], posi[10];
  int id,q,l,s,sipm,sipmbd,feebd,tbox,tgrp,qtaddr,qtch,cbl;
  int n=0;
  while(fgets(line,1000,FP)!=NULL){
    sscanf(line,"%d %d %d %d %d %s %d %d %d %d",
	   &id,&q,&l,&s,
	   &sipm,nw,
	   &tbox,&tgrp,
	   &qtaddr,&qtch);
    //printf("Id=%3d Q=%3d L=%3d S=%3d QTaddr=%1d QTch=%2d\n",id,q,l,s,qtaddr,qtch);
    in[id].QTaddr=qtaddr;
    in[id].QTch=qtch;
    n++;
  }    
  for(int i=0; i<MAX_DB_INDEX; i++){
    printf("Id=%3d QTaddr=%1d QTch=%2d\n",in[i].slatid,in[i].QTaddr,in[i].QTch);
  }
  printf("Found %d entries\n",n);
  
  if(option.Contains("writedb")) {
    gSystem->Setenv("DB_ACCESS_MODE","write");
    StDbManager* mgr = StDbManager::Instance();
    StDbConfigNode* node = mgr->initConfig("Geometry_fps");
    StDbTable* dbtable = node->addDbTable("fpsMap");
    mgr->setStoreTime(storeTime.Data());    
    dbtable->SetTable((char*)&in, MAX_DB_INDEX);
    if(yr.Contains("sim")) dbtable->setFlavor("sim");
    mgr->storeDbTable(dbtable);    
    std::cout << "INFO: table saved to database" << std::endl;
  }
  
  std::cout << "INFO: Reading database" << std::endl;  
  gSystem->Unsetenv("DB_ACCESS_MODE");
  //gSystem->Unsetenv("DB_SERVER_LOCAL_CONFIG");
  St_db_Maker *dbMk=new St_db_Maker("db", "MySQL:StarDb", "$STAR/StarDb");
  dbMk->SetDebug();
  dbMk->SetDateTime(date,time); // event or run start time, set to your liking
  if(yr.Contains("ofl"))      {dbMk->SetFlavor("ofl");}
  else if(yr.Contains("sim")) {dbMk->SetFlavor("sim");}
  dbMk->Init();
  dbMk->Make();
  TDataSet *DB = 0;
  DB = dbMk->GetDataBase("Geometry/fps/fpsMap");
  if (!DB) std::cout << "ERROR: no table found in db, or malformed local db config" << std::endl;
  St_fpsMap *dataset = 0;
  dataset = (St_fpsMap*) DB->Find("fpsMap");
  if (!dataset) {
    td::cout << "ERROR: dataset does not contain requested table" << std::endl;
    return;
  }
  Int_t rows = dataset->GetNRows();
  if (rows > 1) {
    std::cout << "INFO: found INDEXED table with " << rows << " rows" << std::endl;
  }
  TDatime val[2];
  dbMk->GetValidity((TTable*)dataset,val);
  std::cout << "Dataset validity range: [ " << val[0].GetDate() << "." << val[0].GetTime() << " - " 
	    << val[1].GetDate() << "." << val[1].GetTime() << " ] "
	    << std::endl;    
  fpsMap_st *table = dataset->GetTable();
  for (Int_t i = 0; i < rows; i++) {
    std::cout << Form("Row=%4d slatid=%3d QTaddr=%2d QTch=%2d\n",i,
		      table[i].slatid,
		      table[i].QTaddr,table[i].QTch);
  }
}
예제 #13
0
void write_ist_pednoise() {
	gSystem->Setenv("DB_ACCESS_MODE", "write");
  	gROOT->Macro("LoadLogger.C");
  	gSystem->Load("St_base.so");
  	gSystem->Load("libStDb_Tables.so");
  	gSystem->Load("StDbLib.so");

	std::ifstream fPDlist("/star/u/ypwang/disk01/offline_hft/DB/pedNoiseTable4DB/pedNoiseFiles_Corr/pedRunList_Corr.txt");
        if(!fPDlist.is_open())
        {
                std::cout << " There is no corrected pedRunList file! " << endl;
                exit(0);
        }

        while(!fPDlist.eof()) {
                TString  sPDfile;
                fPDlist >> sPDfile;

                int found = sPDfile.Last('_');
                if(found >= 0)
                        sPDfile.Replace(0, found + 1, "");

                found = sPDfile.Last('.');
                if(found >= 0)
                        sPDfile.Replace(found, sPDfile.Length(), "");

                int runnumb = sPDfile.Atoi();
                if(runnumb)
                        pedRunNumVec.push_back(runnumb);
        }
        fPDlist.close();
	const int nPedRuns = pedRunNumVec.size();
	cout << nPedRuns << " good pedestal runs recorded! " << endl;
        if(debug) {
                for(int i=0; i<nPedRuns; i++)
                        cout << i << "th pedestal run: " << pedRunNumVec[i] << endl;
        }


  	std::ifstream fCosmicRunList("/star/u/ypwang/disk01/offline_hft/DB/pedNoiseTable4DB/cmNoise_cosmic/cosmicRunlist.txt");
        if(!fCosmicRunList.is_open())
        {
                std::cout << " There is no cosmicRunList file! " << endl;
                exit(0);
        }

        while(!fCosmicRunList.eof()) {
                TString  sCMNfile;
                fCosmicRunList >> sCMNfile;

                int found = sCMNfile.First('.');
                if(found >= 0)
                        sCMNfile.Replace(found, sCMNfile.Length(), "");

                int runnumb = sCMNfile.Atoi();
                if(runnumb)
                        cosmicRunNumVec.push_back(runnumb);
        }
        fCosmicRunList.close();
	const int nCosmicRuns = cosmicRunNumVec.size();
	cout << nCosmicRuns << " good cosmic runs recorded! " << endl;
        if(debug) {
                for(int i=0; i<nCosmicRuns; i++)
                        cout << i << "th cosmic run: " << cosmicRunNumVec[i] << endl;
        }

	Int_t   isBadChannel[110592];
        Int_t   isBadChip[864];
	//loop pedestal runs
	for(int iRun=0; iRun<nPedRuns; iRun++)
        {
                int runNumber = pedRunNumVec[iRun];
		//below only for testing
		//if(runNumber<15065020) continue;

                int TbinPD = PDTBin(runNumber);
		cout << "Reading pedestal run " << runNumber << " with " << TbinPD << " time bins! " << endl;
		
		//retrieve time stamp information
		char cmd[256];
            	sprintf(cmd, "/usr/bin/mysql -h dbbak.starp.bnl.gov --port=3413 -e \"SELECT FROM_UNIXTIME(startRunTime) as beginTime_human FROM RunLog.runDescriptor WHERE runNumber = %d\" >timeStamp_tmp", runNumber);
            	system(cmd);

            	TString mTimeStamp;
            	FILE *inR = fopen("timeStamp_tmp","r");
            	while(!feof(inR)) {
                	char buff[64];
                	if(fgets(buff,sizeof(buff),inR) == 0) continue ;
                	switch(buff[0]) {
                    		case 'b' : //beginTime_human
                        		continue ;
                	}
                	mTimeStamp = Form(buff);
            	}
            	fclose(inR);

            	sprintf(cmd, "/bin/rm timeStamp_tmp");
            	system(cmd);

		int found = 19;
            	mTimeStamp.Replace(found, mTimeStamp.Length(), "");
            	cout << iRun << ": \t" << runNumber << "\t" << mTimeStamp << endl;
	
		//find the closest cosmic run to match, and using its common-mode noise
		int diffRun = 15000000, miniDiffRun = 15000000;
		int matchedCosmicRunNumber = 15032029;
		for(int iCosmic=0; iCosmic<nCosmicRuns; iCosmic++) {
			diffRun = cosmicRunNumVec[iCosmic] - runNumber;
			if(diffRun < miniDiffRun && diffRun > 0) { //corresponding cosmic run should come after the pedestal run
				miniDiffRun = diffRun;
				matchedCosmicRunNumber = cosmicRunNumVec[iCosmic];
			}
		}
		if(runNumber>=15158006) matchedCosmicRunNumber = 15157002; //if no later cosmic runs found, then use the last one
		int TbinCMN = CMTBin(matchedCosmicRunNumber);
		cout << "Matched cosmic run " << matchedCosmicRunNumber << " with " << TbinCMN << " time bins! " << endl;
		
		StDbManager* mgr = StDbManager::Instance();
  		StDbConfigNode* node = mgr->initConfig("Calibrations_ist");
  		StDbTable* dbtable = node->addDbTable("istPedNoise");
  		mgr->setStoreTime(mTimeStamp.Data());
		
		//open matched CMN DB file
		std::ifstream inCMN(Form("/star/u/ypwang/disk01/offline_hft/DB/pedNoiseTable4DB/cmNoise_cosmic/%d.istCmNoise.dat", matchedCosmicRunNumber));
    		if (!inCMN.is_open()) {
    			std::cout << " There is no CMN DB file  " << end ;
    			exit(0);
    		}

		//open corrected pedestal/RMS DB file
		std::ifstream inPD(Form("/star/u/ypwang/disk01/offline_hft/DB/pedNoiseTable4DB/pedNoiseFiles_Corr/IST_pedestals_%d.txt", runNumber));
    		if (!inPD.is_open()) {
    			std::cout << " There is no PED/RMS DB file  " << end ;
    			exit(0);
    		}
	
		//retreive online masking chip/channel and offline channel masking
		for(int i=0; i<110592; i++) {
                    isBadChannel[i] = 0;
                }

		for(int i=0; i<864; i++) {
                    isBadChip[i] = 0;
                }
		
		//online masking-out chips
		int tem_Run, tem_Rdo, tem_Arm, tem_Group, tem_Apv, tem_Status, ChipEID;
		int deadChipsInRun14 = 31, deadChipCounter=0;
                if(runNumber<15181030) {
                    std::ifstream deadChipList("/star/u/ypwang/disk01/offline_hft/DB/pedNoiseTable4DB/ist_apv_dead.txt");
                }
                else {
                    std::ifstream deadChipList("/star/u/ypwang/disk01/offline_hft/DB/pedNoiseTable4DB/ist_apv_dead_AuHe3.txt");
                    deadChipsInRun14 = 29; //since run 15174075 (June 23, 2014), two chips (566/567) were taken out of online mask-out chip list
                }
		if(!deadChipList.is_open()) 
		{
                        cout << "ist_apv_dead file was NOT found " << endl;
                        exit(0);
                }

		int deadChipId = -1;
                while(!deadChipList.eof() && deadChipCounter<deadChipsInRun14) {
                    deadChipList >> tem_Rdo >> tem_Arm >> tem_Apv;
                    deadChipId = (tem_Rdo-1)*6*24 + tem_Arm*24 + tem_Apv; //electronics ID
                    if(deadChipId<0 || deadChipId>=864) continue;

		    int deadChipGeomIdx = elecIdToGeomId(deadChipId);
                    isBadChip[deadChipGeomIdx-1] = 1; //dead chip
                    deadChipCounter++;
                }
                deadChipList.close();
		cout << "Number of online masking-out chips: " << deadChipCounter << endl;

		//mis-configured chips
                std::ifstream misConfigChiplist("/star/u/ypwang/disk01/offline_hft/DB/pedNoiseTable4DB/ist_apv_bad.txt");
                if(!misConfigChiplist.is_open())
                {
                        cout << "ist_apv_bad file was NOT found " << endl;
                        exit(0);
                }
		
		int badChipCounter = 0;
		while(!misConfigChiplist.eof()) //mis-configured chips recorded since 15065020
                {
                        misConfigChiplist >> tem_Run >> tem_Rdo >> tem_Arm >> tem_Group >> tem_Apv >> tem_Status;
                        if(tem_Run == matchedCosmicRunNumber)
                        {
                                ChipEID = (tem_Rdo - 1) * 6 * 24 + tem_Arm * 24 + tem_Group * 12 + tem_Apv;
                                if(ChipEID<0 || ChipEID>=864) continue;

				int badChipGeomIdx = elecIdToGeomId(ChipEID);
                                isBadChip[badChipGeomIdx-1] = 2; //mis-configured chip
                                badChipCounter++;
                        }
                }
                misConfigChiplist.close();
		cout << "Number of offine masking-out chips: " << badChipCounter << endl;

		//online masking-out channel list
		Int_t   rdoIndex = -1, armIndex = -1, apvIndex = -1, chanIndex = -1;
                Int_t   channelId = -1;

		std::ifstream badChannelListOnline("/star/u/ypwang/disk01/offline_hft/DB/pedNoiseTable4DB/channelMaskingList_ist_online.txt"); //179 bad channels masked out online
		if(!badChannelListOnline.is_open()) 
		{
                        cout << "channelMaskingList_ist_online file was NOT found " << endl;
                        exit(0);
                }

		int deadChannelCounter = 0;
                while(!badChannelListOnline.eof()) {
                        badChannelListOnline >> rdoIndex >> armIndex >> apvIndex >> chanIndex;
                        channelId = (rdoIndex-1)*6*24 + armIndex*24 + apvIndex*128 + chanIndex;
                        isBadChannel[channelId] = 1;
			deadChannelCounter++;
                }
                badChannelListOnline.close();
		cout << "Number of online masking-out channels: " << deadChannelCounter << endl;

		//offline masking-out channel list
                std::ifstream badChannelListOfflineB("/star/u/ypwang/disk01/offline_hft/DB/pedNoiseTable4DB/ChannelMaskList.20140601.txt"); //336 bad channels masked out offline
		if(!badChannelListOfflineB.is_open())
		{
			cout << "ChannelMaskList.20140601 file was NOT found " << endl;
                        exit(0);
		}

		int badChannelCounter = 0;
                while(!badChannelListOfflineB.eof()) {
                        badChannelListOfflineB >> channelId;
                        isBadChannel[channelId] = 2;
			badChannelCounter++;
                }
                badChannelListOfflineB.close();
		cout << "Number of offline masking-out channels: " << badChannelCounter << endl;

		istPedNoise_st table;
		for (int i = 0; i < 110592; i++) {
    			table.pedestal[i] = 0;
    			table.rmsNoise[i] = 0;
  		}

  		for (int i = 0; i < 864; i++) {
    			table.cmNoise[i] = 0;
  		}

		//Pedestal and RMS Noise
		Float_t pedestalT, rmsT;
		Float_t averagePed = 0., averageRms = 0.;
		Int_t timebin = -1;
		channelId = -1;
		for (int counter=0; counter<110592*TbinPD; counter++){
			inPD >> rdoIndex >> armIndex >> apvIndex >> chanIndex >> timebin >> pedestalT >> rmsT;
			channelId = (rdoIndex - 1) * 6 * 24 * 128 + armIndex * 24 * 128 + apvIndex * 128 + chanIndex;
			if(channelId<0 || channelId>=110592) continue;
    			averagePed += pedestalT/TbinPD;
    			averageRms += rmsT/TbinPD;

    			if(((timebin+1)/TbinPD) && ((counter+1)/TbinPD)) {
        			//cout << counter/TbinPD << ": channelId = " << channelId<<"\t pedestal = "<<averagePed<<"\t rms = "<<averageRms<<endl;

        			table.pedestal[channelId] = (int)averagePed;
        			table.rmsNoise[channelId] = (int)(averageRms*100);
				//masking-out online/offline bad channels
				if(isBadChannel[channelId]) 
					table.rmsNoise[channelId] = 10000;
				if(debug)
					cout << counter/TbinPD << ": channelId = " << channelId << "\t pedestal = " << table.pedestal[channelId] << "\t rms = " << table.rmsNoise[channelId] <<endl;
        			averagePed = 0.;
        			averageRms = 0.;
    			}
  		}
  		inPD.close();

		//Common Mode Noise
		Float_t cmNoiseT;
		Float_t averageCmNoise = 0.;
		Int_t chipId;
		Int_t numTimeBins = 9; //IST CMN DB files output 9 time bins format in default
		for(int counter=0; counter<864*numTimeBins; counter++){
    			inCMN >> chipId >> timebin >> cmNoiseT;
    			averageCmNoise += cmNoiseT/TbinCMN;

    			if(((timebin+1)/numTimeBins) && ((counter+1)/numTimeBins)) {
        			//cout << counter/numTimeBins << ": chipId = " << chipId << " cmNoiseT = " << averageCmNoise << endl;
        			table.cmNoise[chipId] = (int)(averageCmNoise*100);
				//masking-out online/offline bad chips
				if(isBadChip[chipId])
					table.cmNoise[chipId] = 10000;
				if(debug)
					cout << counter/numTimeBins << ": chipId = " << chipId << " cmNoiseT = " << table.cmNoise[chipId] << endl;
        			averageCmNoise = 0.;
    			}
  		}
  		inCMN.close();

		// Please comment out below lines if you do testing, or it will write the DB!!!!
		// Store data to the StDbTable
		dbtable->SetTable((char*)&table, 1);

		// Store table to database
		mgr->storeDbTable(dbtable);

		//exit(0); //only for testing
	}
};
예제 #14
0
void fpsChannelGeometry_db(char* opt="", char* year="15sim") {
  TString option(opt), yr(year);  
  TString storeTime; // storetime is begin time for validity range for WRITING DB
  int date,time;     // time for READING DB
  std::cout << "year = " << year << "\n";
  if(yr.Contains("15ofl")){
    storeTime="2014-12-20 00:00:01";
    date = 20141220; time = 1;
  }else if(yr.Contains("15sim")){
    storeTime="2014-12-10 00:00:01";
    date = 20141210; time = 1;
  }else if (yr.Contains("17ofl")){      
      storeTime="2016-12-20 00:00:00";
      date = 20161220; time = 0;
  }else if(yr.Contains("17sim")){
      storeTime="2016-12-10 00:00:00";
      date = 20161210; time = 0;      
  }else{
    std::cout << "Please specify valid year tag\n"; exit;
  }
  std::cout << "Opt =" << opt << "\n";
  std::cout << "write = " << option.Contains("writedb")   << "\n";
  std::cout << "storetime =" << storeTime << "\n";
  std::cout << "date,time =" << date <<" "<< time << "\n";
  
  gROOT->Macro("loadlib.C");
  
  const Int_t MAX_DB_INDEX = 12;
  fpsChannelGeometry_st table[MAX_DB_INDEX];

  if(option.Contains("writedb")) {
    gSystem->Setenv("DB_ACCESS_MODE","write");
    StDbManager* mgr = StDbManager::Instance();
    StDbConfigNode* node = mgr->initConfig("Geometry_fps");
    StDbTable* dbtable = node->addDbTable("fpsChannelGeometry");
    mgr->setStoreTime(storeTime.Data());

    table[ 0].quad = 1; table[ 0].layer = 1; table[ 0].nslat = 21; 
    table[ 1].quad = 1; table[ 1].layer = 2; table[ 1].nslat = 21; 
    table[ 2].quad = 1; table[ 2].layer = 3; table[ 2].nslat = 21; 
    table[ 3].quad = 2; table[ 3].layer = 1; table[ 3].nslat = 19; 
    table[ 4].quad = 2; table[ 4].layer = 2; table[ 4].nslat = 19; 
    table[ 5].quad = 2; table[ 5].layer = 3; table[ 5].nslat = 19; 
    table[ 6].quad = 3; table[ 6].layer = 1; table[ 6].nslat = 21; 
    table[ 7].quad = 3; table[ 7].layer = 2; table[ 7].nslat = 21; 
    table[ 8].quad = 3; table[ 8].layer = 3; table[ 8].nslat = 21; 
    table[ 9].quad = 4; table[ 9].layer = 1; table[ 9].nslat = 19; 
    table[10].quad = 4; table[10].layer = 2; table[10].nslat = 19; 
    table[11].quad = 4; table[11].layer = 3; table[11].nslat = 19; 

    dbtable->SetTable((char*)&table, MAX_DB_INDEX);
    if(yr.Contains("sim")) dbtable->setFlavor("sim");
    mgr->storeDbTable(dbtable);    
    std::cout << "INFO: table saved to database" << std::endl;
  }

  std::cout << "INFO: Reading database" << std::endl;  
  gSystem->Unsetenv("DB_ACCESS_MODE");
  //gSystem->Unsetenv("DB_SERVER_LOCAL_CONFIG");
  St_db_Maker *dbMk=new St_db_Maker("db", "MySQL:StarDb", "$STAR/StarDb");
  dbMk->SetDebug();
  dbMk->SetDateTime(date,time); // event or run start time, set to your liking
  if(yr.Contains("ofl"))      {dbMk->SetFlavor("ofl");}
  else if(yr.Contains("sim")) {dbMk->SetFlavor("sim");}
  dbMk->Init();
  dbMk->Make();
  TDataSet *DB = 0;
  DB = dbMk->GetDataBase("Geometry/fps/fpsChannelGeometry");
  if (!DB) std::cout << "ERROR: no table found in db, or malformed local db config" << std::endl;
  St_fpsChannelGeometry *dataset = 0;
  dataset = (St_fpsChannelGeometry*) DB->Find("fpsChannelGeometry");
  if (!dataset) {
    td::cout << "ERROR: dataset does not contain requested table" << std::endl;
    return;
  }
  Int_t rows = dataset->GetNRows();
  if (rows > 1) {
    std::cout << "INFO: found INDEXED table with " << rows << " rows" << std::endl;
  }
  TDatime val[2];
  dbMk->GetValidity((TTable*)dataset,val);
  std::cout << "Dataset validity range: [ " << val[0].GetDate() << "." << val[0].GetTime() << " - " 
	    << val[1].GetDate() << "." << val[1].GetTime() << " ] "
	    << std::endl;    
  fpsChannelGeometry_st *tbl = dataset->GetTable();
  for (Int_t i = 0; i < rows; i++) {
    std::cout << Form("Row=%4d quad=%1d layer=%1d nslat=%2d\n",i,
		      tbl[i].quad,tbl[i].layer,tbl[i].nslat);
  }
}
예제 #15
0
void storetofTDIGOnTray() {
  const Bool_t Debug = kFALSE;
  const Int_t NBOARD = 8;
//-- year8
  // const Int_t NTRAY = 5;
//-- year9
  //  const Int_t NTRAY = 94;
  //  const Int_t NVPDTRAY = 2;
  //  const Int_t NMAX = 120;
//-- year10/year11
  const Int_t NTRAY = 120;
  const Int_t NVPDTRAY = 2;
  const Int_t NMAX = 300; //123;

//-- load dBase and Table definition libraries
  gSystem->Load("St_base");
  gSystem->Load("StChain");
  gSystem->Load("StUtilities");
  gSystem->Load("St_Tables.so");

  gSystem->Load("StDbLib.so");
  gSystem->Load("libStDb_Tables.so");

//-- get the singleton manager
  StDbManager* dbManager = StDbManager::Instance();

//-- connect to the db & get an empty container
  StDbConfigNode* configNode = dbManager->initConfig("Calibrations_tof");

//----------------------------------------
  //  TString ZStoreTime = "2007-11-01 00:00:03";
  //  TString ZStoreTime = "2008-11-01 00:00:00";
  //  TString ZStoreTime = "2009-11-01 00:00:00";
  //  TString ZStoreTime = "2010-12-20 00:00:01";
  //  TString ZStoreTime = "2011-04-20 00:00:00";
  //  TString ZStoreTime = "2011-12-20 00:00:00";
  TString ZStoreTime = "2012-12-20 00:00:00";

//-- add table to the container with descriptor given by Database
  StDbTable* tofTDIGOnTray = configNode->addDbTable("tofTDIGOnTray");

//-- fill structures & store times
  tofTDIGOnTray_st *tdig = new tofTDIGOnTray_st[NMAX+NVPDTRAY];

//-- year8
  //  Short_t trayId[NTRAY+NVPDTRAY] = {76, 77, 78, 79, 80, 121, 122};
  //  Short_t tdigId[NTRAY+NVPDTRAY][NBOARD] = {
  //    36, 26, 27, 29, 25, 23, 22, 21,
  //    30, 31, 33, 35, 28, 32, 34, 37,
  //    74, 63, 49, 72, 64, 53, 59, 52,
  //    70, 51, 75, 65, 66, 50, 71, 68,
  //    46, 62, 72, 69, 61, 58, 42, 43,
  //    89, 91,  0,  0, 84, 82,  0,  0,
  //    85, 79,  0,  0, 80, 83,  0,  0
  //  };
// ------------------------------
//-- year10
  //  Short_t trayId[NMAX] = { 68, 58, 63,  6,106, 67, 61, 50, 57, 60,
  //                           47, 46, 87,133, 64, 72, 62, 42, 14, 11,
  //                           28,  7, 25, 33, 19, 17, 37, 21, 30, 35,
  //                            8, 20, 31, 27, 12,  9, 10, 29, 34, 13,
  //                           16, 77, 89, 36, 39, 23, 32, 15, 24, 18,
  //                           59, 66, 70, 38, 41, 45, 52, 54, 53, 55,
  //                           84,105, 94, 91, 95, 48, 44, 22, 26, 49,
  //                            5,  2, 75, 40,117,  4,121, 99,120,122,
  //                          111,116,118,119,109,101,100,107, 98, 56,
  //                           88,115,102,108,112,110,113,114,123, 90,
  //                           93, 65, 51, 73, 76, 83, 69, 80, 82, 74,
  //                           97, 79, 43, 86, 85,132,104, 92, 96,103};
  //                              // B-132;  C-133  renamed
// ------------------------------
//-- year11
  // ifstream infile("data/run11/INL/tdigs_01122011.txt");
// VPD boards until April 2011
  //  Short_t tdigId_Vpd[NVPDTRAY][NBOARD] = { 89, 91, 1102, 0, 885, 82, 0, 0,
  //                                           85, 79, 1101, 0,  80, 83, 0, 0};
  //  
  //  Short_t trayId[NMAX] = { 68, 58, 63,  6,106, 67, 61, 50, 57, 71,
  //                           47, 46, 87,133, 64, 72, 62, 42, 14, 11,
  //                           28,  7, 25, 33, 19, 17, 37, 21, 30, 35,
  //                            8, 20, 31, 27, 12,  9, 10, 29, 34, 13,
  //                           16, 77, 89, 36, 39, 23, 32, 15, 24, 18,
  //                           59, 66, 70, 38, 41, 45, 52, 54, 53, 55,
  //                           84,105, 94, 91, 95, 48, 44, 22, 26, 49,
  //                            5,  2, 75, 40,117,  4,121, 99,120,122,
  //                          111,116,118,119,109,101,100,107, 98, 56,
  //                           88,115,102,108,112,110,113,114,123, 90,
  //                           93, 65, 51, 73, 76, 83, 69, 80, 82, 74,
  //                           97, 79, 43, 86, 85,132,104, 92, 96,103};
  //                              // B-132;  C-133  renamed
// ------------------------------
//-- year12
//  changed trays at W8, W23, E93
//  ifstream infile("data/run12/INL/tdigs_120106.txt");
//  Short_t trayId[NTRAY] = { 68, 58, 63,  6,106, 67, 61, 81, 57, 71,
//			    47, 46, 87,133, 64, 72, 62, 42, 14, 11,
//			    28,  7,  3, 33, 19, 17, 37, 21, 30, 35,
//			     8, 20, 31, 27, 12,  9, 10, 29, 34, 13,
//			    16, 77, 89, 36, 39, 23, 32, 15, 24, 18,
//			    59, 66, 70, 38, 41, 45, 52, 54, 53, 55,
//			    84,105, 94, 91, 95, 48, 44, 22, 26, 49,
//			     5,  2, 75, 40,117,  4,121, 99,120,122,
//			   111,116,118,119,109,101,100,107, 98, 56,
//			    88,115, 78,108,112,110,113,114,123, 90,
//			    93, 65, 51, 73, 76, 83, 69, 60, 82, 74,
//			    97, 79, 43, 86, 85,132,104, 92, 96,103};
//                            // B-132;  C-133  renamed
// ------------------------------
//-- year13
//  changed trays at W8, W23, W38, E93, E95, E109
// see http://www.star.bnl.gov/HyperNews-star/protected/get/startof/2675.html
  ifstream infile("data/run13/INL/tdigs_20130115.txt");
  Short_t trayId[NTRAY] = { 68, 58, 63,  6,106, 67, 61, 50, 57, 71,
			    47, 46, 87,133, 64, 72, 62, 42, 14, 11,
			    28,  7, 25, 33, 19, 17, 37, 21, 30, 35,
			     8, 20, 31, 27, 12,  9, 10,  3, 34, 13,
			    16, 77, 89, 36, 39, 23, 32, 15, 24, 18,
			    59, 66, 70, 38, 41, 45, 52, 54, 53, 55,
			    84,105, 94, 91, 95, 48, 44, 22, 26, 49,
			     5,  2, 75, 40,117,  4,121, 99,120,122,
			   111,116,118,119,109,101,100,107, 98, 56,
			    88,115,102,108, 81,110,113,114,123, 90,
			    93, 65, 51, 73, 76, 83, 69, 80, 82, 74,
			    97, 79, 43, 86, 85,132,104, 92, 96,103};
                            // B-132;  C-133  renamed
// ------------------------------
  Short_t tdigId[NTRAY][NBOARD];

//-- run 11 AuAu@18GeV, run 12, run 13
  Short_t tdigId_Vpd[NVPDTRAY][NBOARD] = { 89, 91,  495, 0, 885, 82, 0, 0,
                                           85, 79, 1101, 0,  80, 83, 0, 0};

  Short_t tId[NMAX], boardId[NMAX][NBOARD];  // two additional trays
  int i(0),j(0);  // clear counters
  int trayNum, oldTrayNum, iboard, boardNum;

  cout << "Reading UT-Austin database info ... "  << endl;
  if (infile) {
    // read first entry
    infile >> trayNum >> iboard >> boardNum;
    tId[i] = (Short_t)trayNum;
    boardId[i][iboard-1] = (Short_t)boardNum;      
    oldTrayNum = trayNum;
    // increment general counter (total# of TDIGs, only for debugging) and dump data
    if (Debug) cout << j++ << " " << i << "  " << trayNum << " "<< iboard << "  " << boardNum << endl;

    // loop in the remaining entries
    while ( infile >> trayNum >> iboard >> boardNum ) {
      // increment i only when trayNum incrememts ...
      if (trayNum != oldTrayNum) {
	tId[++i] = (Short_t)trayNum;
	oldTrayNum = trayNum;
      }
      // increment general counter (total# of TDIGs, only for debugging) and dump data
      if (Debug) cout << j++ << " " << i << "  " << trayNum << " "<< iboard << "  " << boardNum << endl;

      boardId[i][iboard-1] = (Short_t)boardNum;
    }
  }
  infile.close();
  cout << "... done reading database info" << endl;

  for(int i=0;i<NTRAY;i++) {
    for(int j=0;j<NBOARD;j++) { tdigId[i][j] = 0; }

    Short_t thisTray = trayId[i];
    int index = -1;
    for(int j=0;j<NMAX;j++) {
      if(thisTray==tId[j]) {
        index = j;
        break;
      }
    }
    if (Debug) cout << "pos = " << i+1 << " tray = " << thisTray << " index = " << index << " : ";
    if(index<0||index>=NMAX) { cout<< "ERROR: unexpected index "<< index << endl; continue;}
    for(int j=0;j<NBOARD;j++) {
      tdigId[i][j] = boardId[index][j];
      if (Debug) cout << tdigId[i][j] << " ";
    }
    if (Debug) cout << endl;
  }

/*
  {
    89, 91,  0,  0, 84, 82,  0,  0,
    85, 79,  0,  0, 80, 83,  0,  0
  };
*/
//-- include the VPD TDIG mapping 
  for(int i=0;i<NTRAY+NVPDTRAY;i++) {
    tdig[i].trayId = i+1;
    for(int j=0;j<NBOARD;j++) {
      if(i<NTRAY) {
        tdig[i].tdigId[j] = tdigId[i][j];
      } else {
        tdig[i].tdigId[j] = tdigId_Vpd[i-NTRAY][j];
      }
    }
  }

//-- create output file for test/verification purposes
  ofstream outData("testTDIGMap.dat");
  for(int i=0;i<NTRAY+NVPDTRAY;i++) {
    for(int j=0;j<NBOARD;j++) {
      outData << setw(5) << tdig[i].tdigId[j];
    }
    outData << endl;
  }
  outData.close();

//-- store data in table
  tofTDIGOnTray->SetTable((char*)tdig, NTRAY+NVPDTRAY);
//- set store time
  dbManager->setStoreTime(ZStoreTime.Data());
//- store table in dBase
  cout<<"Preparing to upload ... "<<endl;
  dbManager->storeDbTable(tofTDIGOnTray);
  cout << "... done" << endl;
}
예제 #16
0
void write_ist_mapping() {
 
  gSystem->Setenv("DB_ACCESS_MODE", "write");
  gROOT->Macro("LoadLogger.C");
  gSystem->Load("St_base.so");
  gSystem->Load("libStDb_Tables.so");
  gSystem->Load("StDbLib.so");

  TString storeTime = "2014-01-29 00:00:01";
  cout <<"The RTS Start date and time is " << storeTime<<endl;  

  StDbManager* mgr = StDbManager::Instance();
  StDbConfigNode* node = mgr->initConfig("Calibrations_ist");
  StDbTable* dbtable = node->addDbTable("istMapping");
  mgr->setStoreTime(storeTime.Data());
 
  Int_t elecId=-1, ladder=-1, sensor=-1, column=-1, row=-1;
  istMapping_st table;
 
  for (int i = 0; i < 110592; i++) {
    table.mapping[i] = i+1;
  }
 
  for(int rdo=1; rdo<=6; rdo++) {
        for(int arm=0; arm<6; arm++) {
            for(int apv=0; apv<24; apv++) {
                for(int chan=0; chan<128; chan++) {
                    elecId = (rdo-1)*6*24*128+arm*24*128+apv*128+chan;

		    // the following mapping refered from IST readout channel datasheet
                    if(elecId<101376)
                        ladder = 22 - elecId/4608;
                    else
                        ladder = 46 - elecId/4608;

		    //sections B and C swapped on ladder 13
		    if(elecId>=43008 && elecId<44544) //section C
                        sensor = 4 - (elecId%4608)/768;
                    else if(elecId>=44544 && elecId<46080) //section B
                        sensor = 8 - (elecId%4608)/768;
                    else
                    	sensor = 6 - (elecId%4608)/768;

                    Int_t pad = (elecId%4608)%768;
                    column = 12 - pad/64;
                    if(column%2)
                        row = 64 - pad%64;
                    else
                        row = 1 + pad%64;

                    table.mapping[elecId] = (ladder-1)*4608 + (sensor-1)*768 + (column-1)*64 + row;
                }
            }
        }
  } 
   
  // Store data to the StDbTable
  dbtable->SetTable((char*)&table, 1);
  
  // Store table to database
  mgr->storeDbTable(dbtable);
  

};