00001 #include <iostream.h>
00002 #include <fstream.h>
00003
00004 void fms_db_ChannelGeometry(char* opt, int year) {
00005
00006 TString option(opt);
00007 std::cout << "Opt =" << opt << "\n";
00008 std::cout << "readdb = " << option.Contains("readdb") << "\n";
00009 std::cout << "writedb = " << option.Contains("writedb") << "\n";
00010 std::cout << "\n";
00011
00012 TString storeTime;
00013 int date,time;
00014 std::cout << "year = " << year << "\n";
00015 if(year==8){
00016 storeTime="2007-11-09 00:00:02";
00017 date = 20080301;
00018 time = 0;
00019 }elseif(year==9){
00020 storeTime="2008-11-09 00:00:01";
00021 date = 20090301;
00022 time = 0;
00023 }else{
00024 std::cout << "Please specify year\n";
00025 exit;
00026 }
00027 std::cout << "storetime =" << storeTime << "\n";
00028 std::cout << "date,time =" << date <<" "<< time << "\n";
00029
00030 gROOT->Macro("LoadLogger.C");
00031 gSystem->Load("St_base.so");
00032 gSystem->Load("libStDb_Tables.so");
00033 gSystem->Load("StDbLib.so");
00034
00035
00036 const Int_t MAXINDEX = 12;
00037 int n=0;
00038
00039
00040 fmsChannelGeometry_st g[MAXINDEX];
00041 memset(g,0,sizeof(g));
00042
00043 gSystem->Load("StChain");
00044 gSystem->Load("StBFChain");
00045 gSystem->Load("StUtilities");
00046 gSystem->Load("StIOMaker");
00047 gSystem->Load("StarClassLibrary");
00048 gSystem->Load("St_Tables");
00049 gSystem->Load("StDbLib");
00050 gSystem->Load("StDbBroker");
00051 gSystem->Load("St_db_Maker");
00052
00053 St_db_Maker *dbMk=new St_db_Maker("db", "MySQL:StarDb", "$STAR/StarDb");
00054 dbMk->SetDebug();
00055 dbMk->SetDateTime(date,time);
00056 dbMk->SetFlavor("ofl");
00057
00058 dbMk->Init();
00059 dbMk->Make();
00060
00061
00062 TDataSet *DB = 0;
00063
00064
00065 DB = dbMk->GetInputDB("Geometry/fms/");
00066 if (!DB) { std::cout << "ERROR: no db maker?" << std::endl; }
00067
00068 if(option.Contains("readdb")){
00069 gSystem->Unsetenv("DB_ACCESS_MODE");
00070 gSystem->Unsetenv("DB_SERVER_LOCAL_CONFIG");
00071 St_fmsChannelGeometry *db = 0;
00072 db = (St_fmsChannelGeometry*) DB->Find("fmsChannelGeometry");
00073
00074 if (db) {
00075 std::cout << "Reading fmsMap table\n";
00076 fmsChannelGeometry_st *table = db->GetTable();
00077 n = db->GetNRows();
00078 memcpy(g,table,sizeof(fmsChannelGeometry_st)*n);
00079 } else {
00080 std::cout << "WARNING: No data in fmsChannelGeometry table (wrong timestamp?). Nothing to return, then.\n";
00081 }
00082 }
00083
00084 if(option.Contains("writedb")) {
00085 gSystem->Setenv("DB_ACCESS_MODE","write");
00086 cout << "DB_ACCESS_MODE="<<gSystem->Getenv("DB_ACCESS_MODE")<<endl;
00087 StDbManager* mgr = StDbManager::Instance();
00088 StDbConfigNode* node = mgr->initConfig("Geometry_fms");
00089 StDbTable* table = node->addDbTable("fmsChannelGeometry");
00090 mgr->setStoreTime(storeTime.Data());
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109 int n=0;
00110 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++;
00111 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++;
00112 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++;
00113 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++;
00114 if(year>=9){
00115 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++;
00116 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++;
00117 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++;
00118 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++;
00119 }
00120 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++;
00121 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++;
00122 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++;
00123 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++;
00124
00125
00126 table->SetTable((char*)&g,n);
00127
00128 mgr->storeDbTable(table);
00129 gSystem->Unsetenv("DB_ACCESS_MODE");
00130 std::cout << "Done with database upload \n";
00131 }
00132
00133 printf("n = %d\n",n);
00134 printf(" Id Typ ew ns nX nY\n");
00135 for(int i=0; i<n; i++){
00136 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);
00137 }
00138 }
00139