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);
}
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);
}
Esempio n. 3
0
//---------------------------------------------------------------------
//---------------------------------------------------------------------
//---------------------------------------------------------------------
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; 
} 
Esempio n. 4
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);
  }
}
Esempio n. 5
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
Esempio n. 6
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);
  }
}
Esempio n. 7
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);
  }
}