/**
 * Populate a map of <label name, <workspace name, <parameter, value>>>
 * from the given map of workspaces by label
 * @param workspacesByLabel :: [input] map of label to list of workspace names
 * @returns :: map of <label name, <workspace name, <parameter, value>>>
 */
QMap<QString, WSParameterList>
MuonAnalysisResultTableCreator::getParametersByLabel(
    const std::map<QString, std::vector<std::string>> &workspacesByLabel)
    const {
  QMap<QString, WSParameterList> wsParamsByLabel;
  for (const auto &labelToWsNames : workspacesByLabel) {
    WSParameterList wsParamsList;
    // labelToWsNames is a pair of <label name -> workspace names>
    for (const auto &wsName : labelToWsNames.second) {
      QMap<QString, double> paramsList;
      const auto &paramWS = tableFromWorkspace(wsName);
      TableRow paramRow = paramWS->getFirstRow();
      // Loop over all rows and get values and errors
      do {
        std::string key;
        double value;
        double error;
        paramRow >> key >> value >> error;
        paramsList[QString::fromStdString(key)] = value;
        paramsList[QString::fromStdString(key + "Error")] = error;
      } while (paramRow.next());
      wsParamsList[QString::fromStdString(wsName)] = paramsList;
    }
    wsParamsByLabel[labelToWsNames.first] = wsParamsList;
  }
  return wsParamsByLabel;
}
예제 #2
0
void RunnerDB::refreshClubTableData(Table &table) {
  for (size_t k = 0; k<cdb.size(); k++){
    if (!cdb[k].isRemoved()) {
      TableRow *row = table.getRowById(cdb[k].getTableId());
      if (row)
        row->setObject(cdb[k]);
    }
  }
}
예제 #3
0
void RunnerDB::refreshRunnerTableData(Table &table) {
  for (size_t k = 0; k<oRDB.size(); k++){
    if (!oRDB[k].isRemoved()) {
      TableRow *row = table.getRowById(oRDB[k].getIndex() + 1);
      if (row)
        row->setObject(oRDB[k]);
    }
  }
}
예제 #4
0
TEST(TestObNbAccessor, QueryRes)
{
  ObNbAccessor accessor;
  QueryRes res;

  gen_scanner(*(res.get_scanner()));

  ASSERT_EQ(OB_SUCCESS, res.init(SC("name")("value")));

  int err = OB_SUCCESS;

  while(true)
  {
    ObCellInfo* cell = NULL;
    int64_t tmp = -1;
    ObString str;
    TableRow* iter = NULL;

    err = res.next_row();
    if(OB_SUCCESS == err)
    {
      break;
    }
    res.get_row(&iter);

    cell = iter->get_cell_info("name");
    ASSERT_TRUE(NULL != cell);
    tmp = -1;
    cell->value_.get_int(tmp);
    ASSERT_EQ(3, tmp);
    
    cell = iter->get_cell_info("value");
    ASSERT_TRUE(NULL != cell);
    cell->value_.get_varchar(str);
    ASSERT_TRUE(ObString(0, static_cast<int32_t>(strlen(value_str)), (char*)value_str) == str);

    cell = iter->get_cell_info((int64_t)0);
    ASSERT_TRUE(NULL != cell);
    tmp = 0;
    cell->value_.get_int(tmp);
    ASSERT_EQ(3, tmp);

    cell = iter->get_cell_info((int64_t)1);
    ASSERT_TRUE(NULL != cell);
    cell->value_.get_varchar(str);
    ASSERT_TRUE(ObString(0, static_cast<int32_t>(strlen(value_str)), (char*)value_str) == str);

  }

}
예제 #5
0
//------------------------------------------------------------------------------
// build() -- build the table in our components list
//------------------------------------------------------------------------------
void Table::build()
{
   Basic::PairStream* newList = 0;

   if (rows > 0 && columns != 0) {

      newList = new Basic::PairStream();

      // For each row: create a TableRow containing all the items in 'columns'
      for (unsigned int i = 1; i <= rows; i++) {

         // new row
         TableRow* row = new TableRow(); 
         row->container(this);

         const Basic::List::Item* item = columns->getFirstItem();
         while (item != 0) {
            const Basic::Pair* pair = static_cast<const Basic::Pair*>(item->getValue());
            const Basic::Object* obj = pair->object();
            if (obj->isClassType(typeid(BasicGL::Graphic))) {
               Basic::Pair* pp = pair->clone();
               BasicGL::Graphic* gobj = static_cast<BasicGL::Graphic*>(pp->object());
               gobj->container(row);
               row->put(pp);
               pp->unref();
            }

            item = item->getNext();
         }

         // put the row on our components list with a slotname equal to its row number
         {
            char cbuf[8];
            sprintf(cbuf,"%d",i);
            Basic::Pair* pp = new Basic::Pair(cbuf,row);
            newList->put(pp);
            pp->unref();
         }

         row->unref();
      }

      // Position our subcomponents
      position();
   }

   // These are new our subcomponents ...
   processComponents(newList,typeid(Basic::Component));
   if (newList != 0) newList->unref();
}
예제 #6
0
int Classifier::validateRecord(TableRow record) // private
{
	int required_num_of_attributes = relation_obj.getNumOfAttributes();

	if (record.size() != required_num_of_attributes)
		return RECORD_SIZE_ERROR;

	for (int i = 0; i < required_num_of_attributes; i++)

		if (relation_obj[i].type == AttributeType::NUMERIC)
		{
			try 
			{
				stof(record[i]); // parse number
			}
			catch (invalid_argument e) {
				return ATTRIBUTE_TYPE_MISMATCH_ERROR;
			}
		}
		else if (relation_obj[i].type == AttributeType::DATE)
		{
			// implement
		}

	return 0;
}
예제 #7
0
void Str2BoolMap::AddIntoMap(const char *filename, int col)
{
	FILE *fp;
	char str[MaxLineSize+1];

	if(	( fp = fopen(filename, "r") ) == NULL )	return;

	while(1)
	{
		TableRow theRow;
		if( theRow.Get(fp) == false )
			break;
		theRow.ColCopy(str, col);

		themap[str] = true;
	}	
}
예제 #8
0
// get user prompts for table fields and add a new row
// to a table, with an auto-incremented id. 
void CreateInTable(TableDefinition Def, char* Table, char* key){
	
	string name, val;
	
	DB.UseTableDefinition(Def);
	//cout << "key: " << key;

	TableRow Columns = DB.GetColumnsForTable(Table); // get all the columns
	TableDataSet NewDataSet;

	for(unsigned int i=0; i<Columns.size(); i++){

		if(Columns[i] == key){
		 
			 int maxID = DB.GetMaxField(Table, key);
			 int newID = maxID+1;

			 stringstream ID("");
			 ID << newID;

			 NewDataSet.push_back(make_pair(key, (char*)ID.str().c_str()));
		}
		else{

			cout << Columns[i] << ": ";
		
			getline(cin, val);
		
			FieldDefinition WorkingFieldDefinition = DB.GetFieldDefinition((char*)Columns[i].c_str());

			if((WorkingFieldDefinition.getLength() > 0) && (WorkingFieldDefinition.Validate((char*)val.c_str()))){
				NewDataSet.push_back(make_pair(Columns[i],val));
			}
			else{
				cout << "validation failed for the field " << WorkingFieldDefinition.getName();
				return;
			}
		}
	}

	DB.Create(Table, NewDataSet);
	DB.ShowTable(Table, NewDataSet);
	return;
}
예제 #9
0
int main(int argc, char **argv)
{
	FILE *fp;
	char str[MaxLineSize+1];
	char str1[MaxLineSize+1] = "", str2[MaxLineSize+1] = "";
	int count;

	if(argc < 3)	{	PrintUsage();	return 1;	}
	
	if( !IsSorted(argv[1], (atoi(argv[2])-1), 'S') )
	{
		SortTable(argv[1], atoi(argv[2]), 'S', "CountName.temp");
		if(	( fp = fopen("CountName.temp", "r") ) == NULL )	{	ErrMsg("Error: fopen failed.\n");	return false;	}
	}
	else
		if(	( fp = fopen(argv[1], "r") ) == NULL )	{	ErrMsg("Error: fopen failed.\n");	return false;	}

	count = 1;

	for( TableRow theRow; theRow.Get(fp); )
	{
		ColCpy( str2, theRow.Column(atoi(argv[2])-1) );

		if( strcmp(str2, "") == 0 )
			continue;

		if( strcmp(str1, str2) == 0 )
			count++;
		else if( strcmp(str1, "") != 0 )
		{
			printf("%s\t%d\n", str1, count );
			count = 1;
		}
		
		strcpy( str1, str2 );	
	}
	if( strcmp(str1, "") != 0 )
		printf("%s\t%d\n", str1, count );

	fclose(fp);
	remove("CountName.temp");

	return 0;
}
예제 #10
0
int PoldiFitPeaks1D2::getBestChebyshevPolynomialDegree(
    const Workspace2D_sptr &dataWorkspace, const RefinedRange_sptr &range) {
  double chiSquareMin = 1e10;
  int nMin = -1;

  try {
    int n = 0;

    while ((n < 3)) {
      IAlgorithm_sptr fit = getFitAlgorithm(dataWorkspace, range, n);
      bool fitSuccess = fit->execute();

      if (fitSuccess) {
        ITableWorkspace_sptr fitCharacteristics =
            fit->getProperty("OutputParameters");
        TableRow row =
            fitCharacteristics->getRow(fitCharacteristics->rowCount() - 1);

        double chiSquare = row.Double(1);

        if (fabs(chiSquare - 1) < fabs(chiSquareMin - 1)) {
          chiSquareMin = chiSquare;
          nMin = n;
        }
      }

      ++n;
    }
  } catch (std::runtime_error) {
    nMin = -1;
  }

  if (nMin == -1) {
    g_log.information() << "Range [" << range->getXStart() << " - "
                        << range->getXEnd() << "] is excluded.";
  } else {
    g_log.information() << "Chi^2 for range [" << range->getXStart() << " - "
                        << range->getXEnd() << "] is minimal at n = " << nMin
                        << " with Chi^2 = " << chiSquareMin << std::endl;
  }

  return nMin;
}
예제 #11
0
void SaveDiffFittingAscii::writeData(const API::ITableWorkspace_sptr workspace,
                                     std::ofstream &file,
                                     const size_t columnSize) {

  for (size_t rowIndex = 0; rowIndex < workspace->rowCount(); ++rowIndex) {
    TableRow row = workspace->getRow(rowIndex);
    for (size_t columnIndex = 0; columnIndex < columnSize; columnIndex++) {

      const auto row_str =
          boost::lexical_cast<std::string>(row.Double(columnIndex));
      g_log.debug() << row_str << std::endl;

      if (columnIndex == columnSize - 1)
        writeVal(row_str, file, true);
      else
        writeVal(row_str, file, false);
    }
  }
}
예제 #12
0
int main(int argc, char **argv)
{
	Str2BoolMap theMap;
	char str[MaxLineSize+1];

	if(argc != 4)
	{	PrintUsage();	return 1;	}	

	theMap.AddIntoMap( argv[2], atoi(argv[3])-1 );

	for( TableRow theRow; theRow.Get(); )
	{
		ColCpy( str, theRow.Column(atoi(argv[1])-1) );		

		if( theMap.IsInMap(str) == true )
			theRow.Print();
	}

	return 0;
}
예제 #13
0
int main(int argc, char **argv)
{
	Str2StrMap theMap;
	char str[MaxLineSize+1];
	char buf[MaxLineSize+1];
	char *token = NULL;

	if(argc < 5 || argc > 6)
	{	PrintUsage();	return 1;	}	

	theMap.AddIntoMap( argv[2], atoi(argv[3])-1, atoi(argv[4])-1);
		
	for( TableRow theRow; theRow.Get(); )
	{
		ColCpy( str, theRow.Column(atoi(argv[1])-1) );		

		token = strtok( str, ",; " );
		while(token != NULL)
		{
			theMap.At(token, buf);	
			if( buf[0] != '\0' )
			{
				theRow.PrintWithoutNewline();
				printf("\t%s\n", buf);
				
				break;
			}
			else if( argc == 6 )
			{
				theRow.PrintWithoutNewline();
				printf("\t%s\n", argv[5]);
			}
			
			token = strtok(NULL, ",; ");
		}
		token = NULL;
	}

	return 0;
}
예제 #14
0
//------------------------------------------------------------------------------
// position() -- position the rows in this table
//------------------------------------------------------------------------------
void Table::position()
{
   Basic::PairStream* subcomponents = getComponents();
   if (subcomponents != 0) {
   
      int ln = line();
      int cp = column();

      // Position our subcomponents, which are all TableRow objects (see build())
      Basic::List::Item* item = subcomponents->getFirstItem();
      while (item != 0) {
         Basic::Pair* pair = static_cast<Basic::Pair*>(item->getValue());
         TableRow* row = static_cast<TableRow*>(pair->object());

         row->line(ln);
         row->column(cp);
         ln += spacing;

         item = item->getNext();
      }
      subcomponents->unref();
      subcomponents = 0;
   }
}
예제 #15
0
void Table::append_record(const TableRow& new_record) {
    if ( new_record.size() != m_headers.size() ) {
        throw TableMismatchedRecordLength(std::to_string(new_record.size()));
    }
    m_records.push_back(new_record);
}
// using namespace std;
int main(){
    
    Table linkListTable(10,10);
    using namespace std;
    
    char choice;
    char filename[MAX_SIZE];
    int sizeOfFile;
    TableRow row;
    
	while( true){
		
		cout << "\nChoose a Command (i, d, f, s, x)"
			 << "\ni--> Insert"
			 << "\nd--> Display"
			 << "\nf--> Format Disk"
			 << "\ns--> Search File"
			 << "\nr--> Delete File"
			 << "\nx--> exit"
			 << endl << endl;
		
		cin >> choice;   
		try{
			switch(choice){
				case 'I':
				case 'i' :
					cout << "Enter filename:\t";
					fflush(stdin);
					cin.get(filename, MAX_SIZE, '\n');
					cout << "Enter Sizeof File:\t";
					cin >> sizeOfFile;
					linkListTable.insert(filename, sizeOfFile);
					break;
				case 'D':
				case 'd':
					linkListTable.display();
					break;
				case 'F':
				case 'f':
					char c;
					cout << "\nAre you sure you want to FORMAT:(y/n)\t";
					cin >> c;
					if(c != 'y' && c != 'Y')
						break;
					linkListTable.reset();
					break;
				case 'S':
				case 's':
					cout << "\nEnter Filename to SEARCH:\t";
					fflush(stdin);
					cin.get(filename, MAX_SIZE, '\n');
					row = linkListTable.getRow(filename);
					row.display();
					break;
				case 'R':
				case 'r':
					cout << "\nEnter Filename to DELETE:\t";
					fflush(stdin);
					cin.get(filename, MAX_SIZE, '\n');
					linkListTable.deleteRecord(filename);
					break;
				case 'X':
				case 'x':
					break;
				default:
					cerr << "\nCommand Not Found";
			}
		} catch( Table::FileAlreadyPresentException exp){
		       std::cerr << "\nException : File Already Present\n";                                                      
		} catch( Table ::  DiskFullException) {
			   std::cerr << "\nException : Disk Full\n";
		} catch( Table ::  IllegalException) {
		  		 std::cerr << "\nException : Illegal Exception\n";	 
	 	} catch ( Table ::  FillBlocksException) {
		  		std::cerr << "\nException : Some programming mistake Fill Blocks Exception\n";	
		} catch ( Table ::  FileNotFoundException) {
		  		std::cerr << "\nException : File Not Present\n";	
		}
		if(choice == 'x' || choice == 'X')
			break;  
	}    
	return 0;  
}
예제 #17
0
Table::Table(const TableRow& headers) :
    m_headers(headers), m_records(), m_quoted(headers.size()) {
    for ( size_t i = 0; i < m_quoted.size(); ++i ) {
        m_quoted[0] = true;
    }
}
예제 #18
0
void InheritanceTable::extract(ATCollection &trees) {

	MapAll::VectorOfChain myVector;
	MapAll::VectorOfTrigger myTrigger;

	ConcreteTableColumn columnDescendent(std::string("DescendentId"),true);
	ConcreteTableColumn columnParent(std::string("ParentId"),true);
	ConcreteTableColumn columnAttribute(std::string("Attribute"),true);
	ConcreteTableColumn columnDit(std::string("Depth"),true);

	InheritanceRelation iCondition;
	myTrigger.push_back(&iCondition);

	InheritanceDescendent columnDescExtractor0(NULL,&columnDescendent,&iCondition,types);
	
	InheritanceParent columnParentExtractor0(NULL,&columnParent,&iCondition,types);

	InheritanceAccess columnAttributeExtractor0(NULL,&columnAttribute,&iCondition);

	InheritanceDepth columnDitExtractor0(NULL,&columnDit,&iCondition);

	myVector.push_back(&columnDescExtractor0);
	myVector.push_back(&columnParentExtractor0);
	myVector.push_back(&columnAttributeExtractor0);
	myVector.push_back(&columnDitExtractor0);

	MapAll element(trees,&myVector,&myTrigger);
	element.accept(this);

	int i,j,k;
	int **matrix;
	TableRow *row;
	TableColumn *col;
	std::string parent,child,value;
	char buff[12];

	//Matrix allocation
	matrix = new int*[vertex_index.size()];
	for(i = 0; i < vertex_index.size(); i++) {
		matrix[i] = new int[vertex_index.size()];
		for(j = 0; j < vertex_index.size(); j++) {
			matrix[i][j] =  INT_MAX / 4;
		}
	}

	//Matrix initialisation
	IdMapper::iterator it;
	std::string parentId = "ParentId";
	std::string descendentId = "DescendentId";
	for(it=iMapper.begin();it != iMapper.end(); ++it) {
		row = (*it).second;
		parent = row->getValue(col_id[parentId]);
		child  = row->getValue(col_id[descendentId]);
		if(parent == "<ERROR>" || child == "<ERROR>") continue;
		matrix[vertex_index[child]][vertex_index[parent]] = -1;
	}
	
	//Running algorithm
	for(k = 0; k < vertex_index.size(); k++)
		for(i = 0; i < vertex_index.size(); i++)
			for(j = 0; j < vertex_index.size(); j++) {
				if(i != j && 
				   matrix[i][k] != INT_MAX / 4 && matrix[k][j] != INT_MAX / 4 && 
				   matrix[i][j] > matrix[i][k] + matrix[k][j])
					matrix[i][j] = matrix[i][k] + matrix[k][j];
			}

	//Register results
	for(i = 0; i < vertex_index.size(); i++)
		for(j = 0; j < vertex_index.size(); j++)
			if(matrix[i][j] < -1 && matrix[i][j] != INT_MAX / 4) {
				row = new TableRow();
				col = new ConcreteTableColumn(std::string("DescendentId"),true);
				child = index_vertex[i];
				col->init(child,true);
				row->add(col);
				col = new ConcreteTableColumn(std::string("ParentId"),true);
				parent = index_vertex[j];
				col->init(parent,true);
				row->add(col);
				col = new ConcreteTableColumn(std::string("Attribute"),true);
				value = "NULL";
				col->init(value,false,-1 * matrix[i][j],TableColumn::MergeByCopy);
				row->add(col);
				col = new ConcreteTableColumn(std::string("Depth"),true);
				sprintf(buff,"%d",-1 * matrix[i][j]);
				value = buff;
				col->init(value,false,-1 * matrix[i][j],TableColumn::MergeByCopy);
				row->add(col);
				Table::insertRow(row);
			}

	//Deallocation
	for(i = 0; i < vertex_index.size(); i++)
		delete matrix[i];
	delete matrix;

	finalize();
}