예제 #1
0
void readtofTrgWindow(const char* time = "2011-01-01 00:00:00") {

  const Int_t NTRAY = 120;
  const Int_t NVPDTRAY = 2;
  const Int_t NMAX = 120;
  const Int_t NMTD = 2;

  //-- 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");

  string ZReadTime = time;
  dbManager->setRequestTime(ZReadTime.c_str());

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

  dbManager->fetchDbTable(tofTrgWindow);

  cout << "version : " << tofTrgWindow->getVersion() <<endl;
  //cout << tofTrgWindow->getTableName()<<endl;
  cout << "begin data/time : "<< tofTrgWindow->getBeginDateTime() <<endl;
  cout << "end  data/time : " << tofTrgWindow->getEndDateTime() <<endl;


  tofTrgWindow_st* trg = static_cast<tofTrgWindow_st*>(tofTrgWindow->GetTable());

  if (!trg) {
    cout << " Oops ... no pointer to table. Exiting" << endl;
    erturn;
  }


  Int_t nRows = tofTrgWindow->GetNRows();
  cout << " NRows = " << nRows << endl;
  if(nRows!=(NTRAY+NVPDTRAY+NMTD)) {
    cout << " NRows doesn't match !!! " << endl;
  }

  //unsigned short cutlow[NTRAY+NVPDTRAY];
  //unsigned short cuthi[NTRAY+NVPDTRAY];
  //for (int i=0;i<NTRAY+NVPDTRAY){
  //  cutlo[i]=0;
  //  cuthi[i]=0;
  //}

  cout << "read out from database ..." << endl;
  ofstream outData;
  outData.open("TrgWindow_read.dat");
  for (int i=0;i<NTRAY+NVPDTRAY+NMTD;i++){
    cout << i << " " << trg[i].trgWindow_Min << " "<< trg[i].trgWindow_Max << endl;
    outData << i << " " << trg[i].trgWindow_Min << " "<< trg[i].trgWindow_Max << endl;
  }
 outData.close();


}
예제 #2
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);
  }
}
예제 #3
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
	}
};
예제 #4
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;
}
예제 #5
0
void storetofINLSCorrStep2()
//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 = "2009-09-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 *f1 = new TFile("INL_test_0_300.root");
  TFile *f2 = new TFile("INL_test_300_600.root");
  TFile *f3 = new TFile("INL_test_600_900.root");
  TFile *f4 = new TFile("INL_test_900_1200.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);

        if(iboard<300) {
          hINLSCorr[iboard][itdc][ichan] = (TH1S *)f1->Get(hisname);
        } else if(iboard<600) {
          hINLSCorr[iboard][itdc][ichan] = (TH1S *)f2->Get(hisname);               
        } else if(iboard<900) {
          hINLSCorr[iboard][itdc][ichan] = (TH1S *)f3->Get(hisname);               
        } else {
          hINLSCorr[iboard][itdc][ichan] = (TH1S *)f4->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;
*/
}
예제 #6
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);
  

};
예제 #7
0
void storetofTotbCorr(const Bool_t mTest = 1)
{
  const int mNTray = 120;  // for test
  const int mNTDIG = 8;
  const int mNVPD = 19;
  const int mNMODULE = 32;
  const int mNCELL = 6;
  const int mNMODPERBOARD = 4;

  //-- 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 StoreTime = "2008-02-01 00:00:03";
//  TString StoreTime = "2008-03-04 16:00:01";
//  TString StoreTime = "2009-03-15 00:00:00";
//  TString StoreTime = "2009-11-01 00:00:00";  // 200 GeV preliminary
//  TString StoreTime = "2010-03-18 18:00:00";   // 62 GeV preliminary
//  TString StoreTime = "2010-04-08 15:00:00";   // 39 GeV preliminary
  ifstream inTime;
  inTime.open("input/timestamp");
  string time;
  if (inTime.is_open()) {
    getline(inTime, time);
    inTime.close();
  } else {
    cout << " Unable to open the TimeStamp file! EXIT! " << endl;
    return;
  }
  TString StoreTime = time;
  cout << " Store Time " << StoreTime.Data() << endl;

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

  //-- fill structures & store times
  //tofTotbCorr_st *totcorr= new tofTotbCorr_st[mNTray*mNTDIG];
  tofTotbCorr_st *totcorr= new tofTotbCorr_st[23040];

  //=======================================
  // read in pvpdTot file by file.

  Double_t diff[mNVPD*2];
  Double_t toffset;
  ifstream infile;

  //========================================
  //Double_t X[mNTray][mNTDIG][60];
  //Double_t Y[mNTray][mNTDIG][60];
  Double_t X[mNTray][mNMODULE][mNCELL][60];
  Double_t Y[mNTray][mNMODULE][mNCELL][60];

  infile.open("input/totCali_4DB.dat");
  if (!infile.is_open()){
    cerr <<" unable to open input/totCali_4DB.dat; bailing out ..." << endl;
    exit(-1);
  }

  int calibSize;
  infile >> calibSize;
  cout << "reading in " << calibSize << " calibration records ... " << endl;
  switch (calibSize) {
   case 960 : // TDIG BOARD BASED
    for(int i=0;i<mNTray;i++) {
    for(int j=0;j<mNTDIG;j++) {
      int tray, board, nnn;
      infile >> tray >> board;
      infile >> nnn;
      //cout << " tray = " << tray << " board = " << board << endl;
      for(int k=0;k<60;k++) {
	if(nnn>0&&k<nnn+1) {
	  infile >> X[tray-1][board-1][0][k];
	} else {
	  X[tray-1][board-1][0][k] = 0.0;
	}
      }
      for(int k=0;k<60;k++) {
	if(nnn>0&&k<nnn+1) {
	  infile >> Y[tray-1][board-1][0][k];
	} else {
	  Y[tray-1][board-1][0][k] = 0.0;
	}
      }
예제 #8
0
void fPostSlatId_db(
		const char* opt   = "",
		const char* year  = "17sim",
		const char* input = "fPostSlatId.txt")
{
    // 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:01";
	    date = 20161220;
	    time = 1;
	}
    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 = 241;
    fpostSlatId_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,"%d %d %d %d ",
				&in[n].slatid, &in[n].quad, &in[n].layer, &in[n].slat);
        printf("slatId=%3d quad=%2d layer=%2d slat=%2d\n",
				in[n].slatid, in[n].quad, in[n].layer, in[n].slat);
        n++;
    }
    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("fpostSlatId");
	    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("Geometry/fps/fpostSlatId");
	    if (!DB) std::cout << "ERROR: no table found in db, or malformed local db config" << std::endl;
	    
	    St_fpostSlatId *dataset = 0;
	    dataset = (St_fpostSlatId*) DB->Find("fpostSlatId");
	    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;
	    
	    fpostSlatId_st *table = (fpostSlatId_st*)dataset->GetTable();
	    
	    for (Int_t i = 0; i < rows; i++)
		{
		    std::cout << Form("Row=%3d slatid=%3d quad=%2d layer=%2d slat=%2d\n",
				      i, table[i].slatid, table[i].quad, table[i].layer, table[i].slat);
		}
	}
    return;
}//Main