void NormalInterpolatorNode::update() 
{
	int n;

	float fraction = getFraction();
	int index = -1;
	int nKey = getNKeys();
	for (n=0; n<(nKey-1); n++) {
		if (getKey(n) <= fraction && fraction <= getKey(n+1)) {
			index = n;
			break;
		}
	}
	if (index == -1)
		return;

	float scale = (fraction - getKey(index)) / (getKey(index+1) - getKey(index));

	float vector1[3];
	float vector2[3];
	float vectorOut[3];

	getKeyValue(index, vector1);
	getKeyValue(index+1, vector2);
	for (n=0; n<3; n++)
		vectorOut[n] = vector1[n] + (vector2[n] - vector1[n])*scale;

	setValue(vectorOut);
	sendEvent(getValueField());
}
示例#2
0
 QmKeys::State QmKeysPrivate::getKeyState(QmKeys::Key key) {
     QmKeys::State state = QmKeys::KeyInvalid;
     if (keyMap.find(key) != keyMap.end()) {
         state = keyMap.value(key);
         goto EXIT;
     }
     if (key == QmKeys::Camera) {
         struct input_event query;
         query.type = EV_KEY;
         query.code = KEY_CAMERA_FOCUS;
         int focus = getKeyValue(query);
         query.code = KEY_CAMERA;
         int camera = getKeyValue(query);
         if (focus == 0 && camera == 0) {
             state = QmKeys::KeyUp;
         } else if (focus == 1 && camera == 0) {
             state = QmKeys::KeyHalfDown;
         } else if (focus == 1 && camera == 1) {
             state = QmKeys::KeyDown;
         } else if (focus == 0 && camera == 1) {
             state = QmKeys::KeyDown;
         }
     } else {
         struct input_event query = keyToEvent(key);
         int value = getKeyValue(query);
         if (value == 0) {
             state = QmKeys::KeyUp;
         } else if (value == 1) {
             state = QmKeys::KeyDown;
         }
     }
     EXIT:
     return state;
 }
int	QuaternionInterpolator::getValue( float time, float* value, int size, int hint ) const
{
	assert( keys() > 0 );
	assert( size == channels() );

	// single key?
	int last = keys() - 1;
	if ( 0 == last )
	{
		getKeyValue( last, value, size );
		return last;
	}

	// find key frame and normalize time
	time = getNormalizedTime( time );
	int key = findKey( time, hint );

	// end of animation?
	if ( time >= getKeyTime(last) )
	{
		getKeyValue( last, value, size );
		return last;
	}
	assert( time < getKeyTime(last) );
	assert( key < last );

	// interpolate
	switch ( m_interp )
	{
	case INTERPOLATE_STEPPED:{
		getKeyValue( key, value, size );
		break;}

	case INTERPOLATE_LINEAR:{
		// get keys, ensure acute angle
		const float* p = getKeyValue(key);
		float q[4];
		getKeyValue( key+1, q, 4 );
		if ( Quat::dot(p,q) < 0.f )
			Quat::negate( q, q );

		// interpolate
		float keyInterval = getKeyTime(key+1) - getKeyTime(key);
		assert( keyInterval > Float::MIN_VALUE );
		float u = (time - getKeyTime(key)) / keyInterval;
		assert( u >= 0.f && u <= 1.f );
		Quat::slerp( value, u, p, q );
		Quat::normalize( value, value );
		break;}
	}

	return key;
}
示例#4
0
long long findLowestNumberOfSeconds( char *numString ) {
  
  int currChar = 0 , numChars = 0;
  int highestNumber = 1 ;
  int isZeroAssigned = 0 ;

  char c ;

  /* Iterate through the string and assign the lowest possible
     value for each unique character encountered. This means you
     assign 1 to the first char, 0 to the next, 2, 3, etc. 
  */
  while( c = numString[currChar] ) {
    
    if ( getKeyValue(c) == -1 ) {
      if ( highestNumber > 1 && !isZeroAssigned ) {
	setKeyValue(c, 0) ;
	isZeroAssigned = 1;
      }
      else {
	setKeyValue(c, highestNumber++) ;
      }
    }
    currChar++;
    numChars++;
  }

  return convertAlienToDecimal(numString, numChars, highestNumber ) ;
}
示例#5
0
QString EWAUserAction::getActionValue() const
{
    QEvent::Type eType = m_pEvent->type();
    switch( eType )
    {
        case QEvent::KeyPress:
        case QEvent::KeyRelease: 
        {
            return getKeyValue( m_pEvent );
        }
        case QEvent::MouseButtonPress:
        case QEvent::MouseButtonRelease:
        {
            QPoint resPnt = getClickCoords( m_pEvent );
            QString resStr = QObject::tr( "%1x%2" ).arg( resPnt.x() ).arg( resPnt.y() );
            return resStr;
        }
        default:
        {
            break;
        }
    }
    
    return QString();
}
示例#6
0
void LeafNode::removeKey(int keyIndex, int childIndex) {
	for (int i = keyIndex; i < getKeyNum() - 1; ++i) {
		setKeyValue(i, getKeyValue(i + 1));
		setData(i, getData(i + 1));
	}
	setKeyNum(getKeyNum() - 1);
}
示例#7
0
void ConfigureInput::applyConfiguration() {
    for (int i = 0; i < Settings::NativeInput::NUM_INPUTS; ++i) {
        int value = getKeyValue(input_mapping[Settings::NativeInput::Values(i)]->text());
        Settings::values.input_mappings[Settings::NativeInput::All[i]] = value;
    }
    Settings::Apply();
}
示例#8
0
/* Parse XML string into a hash.  This parses all attributes of all tags
 * into values.  st_kv_database_conf type is stored as conf_type,
 * database tag is stores as db_tag.  This does minimal error checking
 * and is really lame.
 */
static stHash *hackParseXmlString(const char *xmlString) {
    stHash *hash = stHash_construct3(stHash_stringKey, stHash_stringEqualKey, free, free);
    char *toReplace[5] = { "</", "<", "/>", ">", "=" };
    char *cA = stString_replace(xmlString, toReplace[0], " "), *cA2;
    for (int64_t i = 1; i < 5; i++) {
        cA2 = stString_replace(cA, toReplace[i], " ");
        free(cA);
        cA = cA2;
    }
    getExpectedToken(&cA2, "st_kv_database_conf");
    stHash_insert(hash, stString_copy("conf_type"), getKeyValue(&cA2, "type"));
    stHash_insert(hash, stString_copy("db_tag"), getNextToken(&cA2));

    char *key;
    while (((key = getNextToken(&cA2)) != NULL) && !stString_eq(key, "st_kv_database_conf")) {
        char *value = getNextToken(&cA2);
        if (value == NULL) {
            stThrowNew(ST_KV_DATABASE_EXCEPTION_ID, "failed to to get value for key \"%s\"", key);
        }
        if (stHash_search(hash, key) != NULL) {
            stThrowNew(ST_KV_DATABASE_EXCEPTION_ID, "got a duplicate entry in the database conf string \"%s\"", key);
        }
        stHash_insert(hash, key, value);
    }
    if(!stString_eq(key, "st_kv_database_conf")) {
        stThrowNew(ST_KV_DATABASE_EXCEPTION_ID, "got an unexpected final entry \"%s\"", key);
    }
    free(key);
    free(cA);
    return hash;
}
示例#9
0
HEART_EXPORT void HEART_API threadExit() {
    for (auto i=tlsDestructorArray.cbegin(), n=tlsDestructorArray.cend(); i!=n; ++i) {
        if (i->tlsDestructor_) {
            i->tlsDestructor_(getKeyValue(i->tlsSlot_));
        }
    }
}
示例#10
0
/*获得孩子结点的下标*/
int InternalNode::getChildIndex(KeyType key, int keyIndex) const {
	if (key >= getKeyValue(keyIndex)) {
		return keyIndex + 1;
	}
	else {
		return keyIndex;
	}
}
示例#11
0
/**
 * @brief Initializes an ISIS cube converting it into a SPICE segment
 *
 * This method is called to extract the perinent contents of an ISIS cube file
 * and accumulate generic information that is used to create the output SPICE
 * kernel segment.  Other specific kernel types can use this class as its base
 * class and add to it additional elements to complete the needed content for
 * the NAIF kernel.
 *
 * @param cube ISIS cube file to accumulate information from
 */
void SpiceSegment::init(Cube &cube) {

  _kernels.UnLoad();  // Unload all active, owned kernels
  init();            // Init local variables

  _fname = cube.fileName();

  //  Extract ISIS CK blob and transform to CK 3 content
  NaifStatus::CheckErrors();
  try {

    // Order is somewhat important here.  The call to initialize Kernels
    // object checks the NAIF pool for existance.  It logs their NAIF
    // status as loaded which may cause trouble from here on...
    Pvl *label = cube.label();
    _kernels.Init(*label);
    Camera *camera = cube.camera();

    //  Determine segment ID from product ID if it exists, otherwise basename
    if ( _name.isEmpty() ) {
      _name = getKeyValue(*label, "ProductId");
      if (_name.isEmpty() ) {
        _name = FileName(_fname).baseName();
      }
    }

    // Get instrument and target ids
    QString value("");
    value = getKeyValue(*label, "InstrumentId");
    if (!value.isEmpty()) { _instId = value; }
    value = getKeyValue(*label, "TargetName");
    if (!value.isEmpty()) { _target = value; }

    // Get default times for sorting purposes
    setStartTime(camera->cacheStartTime().Et());
    setEndTime(camera->cacheEndTime().Et());

  } catch ( IException &ie  ) {
    ostringstream mess;
    mess << "Failed to construct Spice Segment basics from ISIS file " << _fname;
    throw IException(ie, IException::User, mess.str(), _FILEINFO_);
  }

  return;
}
示例#12
0
void CInternalNode::removeKey(int keyIndex, int childIndex)
{
    for (int i=0; i<getKeyNum()-keyIndex-1; ++i)
    {
        setKeyValue(keyIndex+i, getKeyValue(keyIndex+i+1));
        setChild(childIndex+i, getChild(childIndex+i+1));
    }
    setKeyNum(getKeyNum()-1);
}
示例#13
0
/*删除内部结点的键值*/
void InternalNode::removeKey(int keyIndex, int childIndex) {
	for (int i = 0; i < getKeyNum() - childIndex; i++)
	{
		setChild(childIndex + i, getChild(childIndex + i + 1));
	}
	for (int i = 0; i < getKeyNum() - keyIndex - 1; ++i) {
		setKeyValue(keyIndex + i, getKeyValue(keyIndex + i + 1));
	}//键值对依次向前移动
	setKeyNum(getKeyNum() - 1);
}
示例#14
0
/* So this function converts the given string to decimal using the values
   stored in the map */
long long convertAlienToDecimal( char *numString, int numChars, int base ) {

  int i;
  long long sum = 0 ;

  /* basic conversion */
  for ( i = 0 ; i < numChars ; i++ ) {
    sum = sum * base + getKeyValue( numString[i] ) ;
  }

  return sum ;

}
示例#15
0
/** greebo: Constructor, call this with the filename relative to "games/"
 */
Game::Game(const std::string& path, const std::string& filename) {

	std::string fullPath = path + filename;

	// Load the XML file by constructing an xml::Document object
	// and search for the <game> tag
	xml::Document doc(fullPath);

	if (doc.isValid()) {
		// Check for a toplevel game node
		xml::NodeList list = doc.findXPath("/game");
	    if (list.size() == 0) {
	    	rError()
	    		<< "Couldn't find <game> node in the game description file "
	    		<< fullPath.c_str() << "\n";
		}
		else {
			xml::Node node = list[0];

			// Get the game name
			_name = node.getAttributeValue("name");

			const std::string enginePath =
#if defined(WIN32)
				"enginepath_win32"
#elif defined(__linux__) || defined (__FreeBSD__)
				"enginepath_linux"
#elif defined(__APPLE__)
				"enginepath_macos"
#else
#error "unknown platform"
#endif
			;

			if (!_name.empty()) {
				// Import the game file into the registry
				GlobalRegistry().import(fullPath, "", Registry::treeStandard);

				// Get the engine path
				_enginePath = getKeyValue(enginePath);
			}
		}
	}
	else {
		rError() << "Could not parse XML file: " << fullPath.c_str() << "\n";
	}
}
示例#16
0
/*获得键下标*/
int FatherNode::getKeyIndex(KeyType key) const {
	int left = 0;
	int right = getKeyNum() - 1;
	int current;

	while (left != right) {
		current = (left + right) / 2;
		KeyType currentKey = getKeyValue(current);
		if (key > currentKey) {
			left = current + 1;
		} //折半查找
		else {
			right = current;
		}
	}
	return left;
}
示例#17
0
void LeafNode::borrowFrom(FatherNode* siblingNode, FatherNode* parentNode, int keyIndex, SIBLING_DIRECTION d) {
	switch (d)
	{
	case LEFT: {
		insert(siblingNode->getKeyValue(siblingNode->getKeyNum() - 1), ((LeafNode*)siblingNode)->getData(siblingNode->getKeyNum() - 1));
		siblingNode->removeKey(siblingNode->getKeyNum() - 1, siblingNode->getKeyNum() - 1);
		parentNode->setKeyValue(keyIndex, getKeyValue(0));
	}
		break;
	case RIGHT: {
		insert(siblingNode->getKeyValue(0), ((LeafNode*)siblingNode)->getData(0));
		siblingNode->removeKey(0, 0);
		parentNode->setKeyValue(keyIndex, siblingNode->getKeyValue(0));
	}
		break;
	default:
		break;
	}
}
示例#18
0
bool                                          // returns true if success
processStyleSection(FILE *fp,string& theline, bool& new_section)
{
  vector<string> v_tokens;

  string *sid      = NULL;
  TStyle *thestyle = NULL;

  if (gl_verbose)
    cout << "Processing style section" << endl;

  new_section=false;

  while (getLine(fp,theline,"style")) {
    if (!theline.size()) continue;
    if (theline[0] == '#') continue; // comments are welcome

    if (theline[0] == '[') {
      new_section=true;
      return true;
    }

    string key, value;
    if (!getKeyValue(theline,key,value)) continue;

    if (key == "id") {
      if (sid != NULL) {
	cerr << "no more than one id per style section allowed " << value << endl;
	break;
      }

      sid = new string(value);
      thestyle = new TStyle(*gStyle); // Assume current attributes, let user override specifics
      thestyle->SetNameTitle(sid->c_str(),sid->c_str());
      glmap_id2style.insert(pair<string,TStyle*>(*sid,thestyle));
      continue;
    }
    else if (!sid) {
      // assume the style is the global style
      thestyle = gStyle;
      sid = new string("using global"); // so as to pass this check the next time
      cerr << "No style ID defined, assuming global style" << endl;
      continue;
    }

    if (key == "style") {
      if (value == "TDR")
	setTDRStyle();
      else if (value == "Plain")
	gROOT->SetStyle("Plain");
      else 
	cerr << "unknown style name " << value << endl;
    }
    else if (key == "optstat")  {
      if (gl_verbose) cout << "OptStat = " << thestyle->GetOptStat() << endl;
      thestyle->SetOptStat(value.c_str());
      if (gl_verbose) cout << "OptStat = " << thestyle->GetOptStat() << endl;
    }
    else if (key == "opttitle")  thestyle->SetOptTitle(str2int(value));

    else if (key == "padrightmargin")  thestyle->SetPadRightMargin (str2flt(value));
    else if (key == "padleftmargin")   thestyle->SetPadLeftMargin  (str2flt(value));
    else if (key == "padtopmargin")    thestyle->SetPadTopMargin   (str2flt(value));
    else if (key == "padbottommargin") thestyle->SetPadBottomMargin(str2flt(value));
    else if (key == "padgridx")        thestyle->SetPadGridX       (str2int(value));
    else if (key == "padgridy")        thestyle->SetPadGridY       (str2int(value));

    // Set the position/size of the title box

    else if (key == "titlexndc")    thestyle->SetTitleX(str2flt(value));
    else if (key == "titleyndc")    thestyle->SetTitleY(str2flt(value));
    else if (key == "titlewndc")    thestyle->SetTitleW(str2flt(value));
    else if (key == "titlehndc")    thestyle->SetTitleH(str2flt(value));
    else if (key == "titlefont")    thestyle->SetTitleFont(str2int(value));
    else if (key == "titlebordersize") thestyle->SetTitleBorderSize(str2int(value));

    else if (key == "markercolor")  thestyle->SetMarkerColor(str2int(value));
    else if (key == "markerstyle")  thestyle->SetMarkerStyle(str2int(value));
    else if (key == "markersize")   thestyle->SetMarkerSize(str2int(value));
    else if (key == "linecolor")    thestyle->SetLineColor(str2int(value));
    else if (key == "linestyle")    thestyle->SetLineStyle(str2int(value));
    else if (key == "linewidth")    thestyle->SetLineWidth(str2int(value));
    else if (key == "fillcolor")    thestyle->SetFillColor(str2int(value));
    else if (key == "fillstyle")    thestyle->SetFillStyle(str2int(value));

    // axes
    else if (key == "xtitlesize")   thestyle->SetTitleSize(str2flt(value),"X");
    else if (key == "ytitlesize")   thestyle->SetTitleSize(str2flt(value),"Y");
    else if (key == "ztitlesize")   thestyle->SetTitleSize(str2flt(value),"Z");
    else if (key == "xtitleoffset") thestyle->SetTitleOffset(str2flt(value),"X");
    else if (key == "ytitleoffset") thestyle->SetTitleOffset(str2flt(value),"Y");
    else if (key == "ztitleoffset") thestyle->SetTitleOffset(str2flt(value),"Z");
    else if (key == "xlabeloffset") thestyle->SetLabelOffset(str2flt(value),"X");
    else if (key == "ylabeloffset") thestyle->SetLabelOffset(str2flt(value),"Y");
    else if (key == "zlabeloffset") thestyle->SetLabelOffset(str2flt(value),"Z");
    else if (key == "xtitlefont")   thestyle->SetTitleFont(str2int(value),"X");
    else if (key == "ytitlefont")   thestyle->SetTitleFont(str2int(value),"Y");
    else if (key == "ztitlefont")   thestyle->SetTitleFont(str2int(value),"Z");
    else if (key == "xlabelsize")   thestyle->SetLabelSize(str2flt(value),"X");
    else if (key == "ylabelsize")   thestyle->SetLabelSize(str2flt(value),"Y");
    else if (key == "zlabelsize")   thestyle->SetLabelSize(str2flt(value),"Z");
    else if (key == "xlabelfont")   thestyle->SetLabelFont(str2int(value),"X");
    else if (key == "ylabelfont")   thestyle->SetLabelFont(str2int(value),"Y");
    else if (key == "zlabelfont")   thestyle->SetLabelFont(str2int(value),"Z");
    else if (key == "xndiv")        thestyle->SetNdivisions(str2int(value),"X");
    else if (key == "yndiv")        thestyle->SetNdivisions(str2int(value),"Y");
    else if (key == "zndiv")        thestyle->SetNdivisions(str2int(value),"Z");

    // Set the position of the statbox
    else if (key == "statx2ndc")    thestyle->SetStatX(str2flt(value));
    else if (key == "staty2ndc")    thestyle->SetStatY(str2flt(value));
    else if (key == "statwndc")     thestyle->SetStatW(str2flt(value));
    else if (key == "stathndc")     thestyle->SetStatH(str2flt(value));

    else if (key == "statfont")     thestyle->SetStatFont    (str2int(value));
    else if (key == "statfontsize") thestyle->SetStatFontSize(str2flt(value));
    else if (key == "statformat")   thestyle->SetStatFormat  (value.c_str());
    else if (key == "statstyle")    thestyle->SetStatStyle   (str2int(value.c_str()));

    else if (key == "fitformat")    thestyle->SetFitFormat   (value.c_str());

    else if (key == "painttextfmt") thestyle->SetPaintTextFormat(value.c_str());
    else if (key == "markersize")   thestyle->SetMarkerSize(str2flt(value));

    else if (key == "palette")      thestyle->SetPalette(str2int(value));

    else {
      cerr << "Unknown key " << key << endl;
    }

  } // while loop

  return true;
}                                                 // processStyleSection
示例#19
0
文件: spPad.C 项目: kalanand/UserCode
bool                                        // returns true if success
processPadSection(FILE *fp,string& theline, wPad_t * wpad, bool& new_section)
{
  vector<string> v_tokens;
  float xmin=1e99, xmax=-1e99;
  float ymin=1e99, ymax=-1e99;

  if (gl_verbose)
    cout << "Processing pad section" << endl;

  new_section=false;

  while (getLine(fp,theline,"pad")) {

    if (!theline.size()) continue;
    if (theline[0] == '#') continue; // comments are welcome

    if (theline[0] == '[') {
      new_section=true;
      return true;
    }

    string key, value;
    if (!getKeyValue(theline,key,value)) continue;

    if      (key == "histos") {
      Tokenize(value,wpad->histo_ids," ,"); 
      if (!wpad->histo_ids.size()) wpad->histo_ids.push_back(value);
    }
    else if (key == "stackem") {
      Tokenize(value,wpad->stack_ids," ,");
      if (!wpad->stack_ids.size()) wpad->stack_ids.push_back(value);
    }
    else if (key == "altyhistos") { // histos on an alternate y-axis
      if (!wpad->histo_ids.size()) {
	cerr << "No 'histos' defined yet! Define alternates after them." << endl;
	continue;
      }
      Tokenize(value,wpad->altyh_ids," ,"); 
      if (!wpad->altyh_ids.size()) wpad->altyh_ids.push_back(value);
    }
    else if (key == "graphs") {
      Tokenize(value,wpad->graph_ids,","); 
      if (!wpad->graph_ids.size()) wpad->graph_ids.push_back(value);
    }
    else if (key == "rootmacros") {
      Tokenize(value,wpad->macro_ids,","); 
      if (!wpad->macro_ids.size()) wpad->macro_ids.push_back(value);
    }
    else if (key == "lines") {
      Tokenize(value,wpad->line_ids,","); 
      if (!wpad->line_ids.size()) wpad->line_ids.push_back(value);
    }
    else if (key == "boxes") {
      Tokenize(value,wpad->box_ids,","); 
      if (!wpad->box_ids.size()) wpad->box_ids.push_back(value);
    }
    else if (key == "labels") {
      Tokenize(value,wpad->label_ids," ,"); 
      if (!wpad->label_ids.size())  wpad->label_ids.push_back(value);
    }
    else if (key == "latex") {
      Tokenize(value,wpad->latex_ids," ,"); 
      if (!wpad->latex_ids.size())  wpad->latex_ids.push_back(value);
    }
    else if (key == "title")        wpad->hframe->histo()->SetTitle(value.c_str());
    else if (key == "xtitle")       wpad->hframe->histo()->SetXTitle(value.c_str());
    else if (key == "ytitle")       wpad->hframe->histo()->SetYTitle(value.c_str());
    else if (key == "ztitle")       wpad->hframe->histo()->SetZTitle(value.c_str());
    else if (key == "rightmargin")  wpad->rightmargin  = str2flt(value);
    else if (key == "leftmargin")   wpad->leftmargin   = str2flt(value);
    else if (key == "topmargin")    wpad->topmargin    = str2flt(value);
    else if (key == "bottommargin") wpad->bottommargin = str2flt(value);
    else if (key == "fillcolor")    wpad->fillcolor    = str2int(value);
    else if (key == "legend")       wpad->legid        = value;
    else if (key == "logx")         wpad->logx         = str2int(value);
    else if (key == "logy")         wpad->logy         = str2int(value);
    else if (key == "logz")         wpad->logz         = str2int(value);
    else if (key == "gridx")        wpad->gridx        = str2int(value);
    else if (key == "gridy")        wpad->gridy        = str2int(value);
    else if (key == "xmin") {
      xmin = str2flt(value);
      wpad->hframe->SetXaxis("",false,0,0,0,0,0,xmin,xmax);
    }
    else if (key == "xmax") {
      xmax = str2flt(value);
      wpad->hframe->SetXaxis("",false,0,0,0,0,0,xmin,xmax);
    }
    else if (key == "ymin") {
      ymin = str2flt(value);
      wpad->hframe->SetYaxis("",false,0,0,0,0,0,ymin,ymax);
    }
    else if (key == "ymax") {
      ymax = str2flt(value);
      wpad->hframe->SetYaxis("",false,0,0,0,0,0,ymin,ymax);
    }
    else {
      cerr << "Unknown key " << key << endl;
    }


  } // while loop

  return true;
}                                                   // processPadSection
示例#20
0
bool                              // returns true if success
processMultiHistSection(FILE *fp,
			string& theline,
			bool& new_section)
{
  vector<string> v_tokens;
  vector<std::pair<string, wTH1 *> > v_histos;
  string mhid;

  if (gl_verbose)
    cout << "Processing multihist section" << endl;

  new_section=false;

  while (getLine(fp,theline,"multihist")) {
    if (!theline.size()) continue;
    if (theline[0] == '#') continue; // comments are welcome

    if (theline[0] == '[') {
      new_section=true;
      return true;
    }

    string key, value;
    if (!getKeyValue(theline,key,value)) continue;

    //--------------------
    if (key == "id") {
    //--------------------
      if (mhid.size()) {
	cerr << "no more than one id per histo section allowed " << value << endl;
	break;
      }

      mhid = value;

    //------------------------------
    } else if (key == "pathglob") {
    //------------------------------
      glob_t globbuf;
      
      if (!mhid.size()) {
	cerr << "id key must be defined first in the section" << endl; continue;
      }

      Tokenize(value,v_tokens,":");
      if ((v_tokens.size() != 2) ||
	  (!v_tokens[0].size())  ||
	  (!v_tokens[1].size())    ) {
	cerr << "malformed pathglob 'fileglob:regex' " << value << endl;
	exit(-1);
      }

      // File globbing pattern can select multiple files
      // regular expression pattern can select multiple histos within each file.
      //
      string fileglob = v_tokens[0];
      string stregex  = v_tokens[1];

      int stat = glob (fileglob.c_str(), GLOB_MARK, NULL, &globbuf);
      if (stat) {
	switch (stat) {
	case GLOB_NOMATCH: cerr << "No file matching glob pattern "; break;
	case GLOB_NOSPACE: cerr << "glob ran out of memory "; break;
	case GLOB_ABORTED: cerr << "glob read error "; break;
	default: cerr << "unknown glob error stat=" << stat << " "; break;
	}
	cerr << fileglob << endl;
	exit(-1);
      }
      if (gl_verbose) cout<<globbuf.gl_pathc<<" files match the glob pattern"<<endl;
      for (size_t i=0; i<globbuf.gl_pathc; i++) {
	char *path = globbuf.gl_pathv[i];
	if (!strncmp(&path[strlen(path)-6],".root",5)) {
	  cerr << "non-root file found in glob, skipping: " << path << endl;
	} else {
	  getHistosFromRE(mhid,string(path),stregex, v_histos);
	}
      }
      if (gl_verbose) cout << v_histos.size() << " total matches found." << endl;
      globfree(&globbuf);

      glmap_mobj2size.insert(pair<string,unsigned>(mhid,v_histos.size()));

    //------------------------------
    } else if( key == "fillfromtree" ) { // converts tree array variables into a group of histos
    //------------------------------
      if( !mhid.size() ) {
	cerr << "id key must be defined first in the section" << endl; continue;
      }

      // histo need not be pre-booked, since TTree::Draw can do that

      Tokenize(value,v_tokens,";");
      string treedrawspec=v_tokens[0];

      int ifirst=-1,ilast=-1;
      if (v_tokens.size() == 2) {
	string range=v_tokens[1];
	Tokenize(range,v_tokens,"-");
	if (v_tokens.size()==2) {
	  ifirst=str2int(v_tokens[0]);
	  ilast =str2int(v_tokens[1]);
	}
      }
      //cout << v_tokens.size() << " " << ifirst << " " << ilast << endl;
      if (ifirst<0 || 
	  ilast <0 ||
	  ilast<ifirst ) {
	cerr << "malformed filltree expression drawspec;X-Y, where X-Y is the array index range to plot"<<endl;
	exit(-1);
      }

      for (int i=ifirst; i<=ilast; i++) {
	wTH1   *wth1 = NULL;
	// defined in spTree.C
	void fillHistoFromTreeVar(std::string& drawspec,int index,wTH1 *&wth1);
	fillHistoFromTreeVar(treedrawspec,i,wth1);
	assert(wth1);
	string hidi= mhid+"_"+int2str(i-ifirst);
	v_histos.push_back(std::pair<string,wTH1 *>(hidi,wth1));
	glmap_id2histo.insert(pair<string,wTH1 *>(hidi,wth1));
      }

      glmap_mobj2size.insert(pair<string,unsigned>(mhid,v_histos.size()));

    //-----------------------
    } else if( key == "printf" ) {
    //-----------------------

      Tokenize(value,v_tokens,"\",");
      switch( v_tokens.size() ) {
      case 1: printf (v_tokens[0].c_str()); break;
      case 2: printf (v_tokens[0].c_str(),v_tokens[1].c_str()); break;
      case 3: printf (v_tokens[0].c_str(),
		      v_tokens[1].c_str(),
		      v_tokens[2].c_str()); break;
      case 4: printf (v_tokens[0].c_str(),
		      v_tokens[1].c_str(),
		      v_tokens[2].c_str(),
		      v_tokens[3].c_str()); break;
      default:
	cerr << "Unsupported number of arguments, " << value << endl;
	exit(-1);
      }

    } else if( !v_histos.size() ) {  // all other keys must have "path" defined
      cerr << "histo vector is empty" << endl;
      cerr << "key 'pathglob' or 'vartable' must define nonempty histo set before key " << key << endl;
      break;
    }

    else {
      processCommonHistoParams(key,value,v_histos);
      if( key == "printfstats" )   cout << endl;
    }
  }

  return (v_histos.size());
}                                             // processMultiHistSection
示例#21
0
SDL_Surface *createDialogBox(char *title, char *msg)
{
    char *text, *token, word[MAX_VALUE_LENGTH], *savePtr, *titleText;
    int i, lines, w, h, maxWidth, lineBreak, *lineBreaks;
    SDL_Surface **surface, *tempSurface;
    SDL_Rect dest;

    savePtr = NULL;

    freeDialogBox();

    text = malloc(strlen(msg) + 1);

    if (text == NULL)
    {
        showErrorAndExit("Failed to allocate a whole %d bytes for the Dialog Text", (int)strlen(msg) + 1);
    }

    STRNCPY(text, msg, strlen(msg) + 1);

    titleText = NULL;

    if (title != NULL)
    {
        titleText = malloc(strlen(title) + 1);

        if (titleText == NULL)
        {
            showErrorAndExit("Failed to allocate a whole %d bytes for the Dialog Text", (int)strlen(title) + 1);
        }

        STRNCPY(titleText, title, strlen(title) + 1);
    }

    token = strtok_r(text, " ", &savePtr);

    i = 0;

    while (token != NULL)
    {
        i++;

        token = strtok_r(NULL, " ", &savePtr);
    }

    lines = i;

    if (titleText != NULL)
    {
        token = titleText;

        while (*token != '\0')
        {
            if (*token == '_')
            {
                *token = ' ';
            }

            token++;
        }

        lines++;
    }

    surface = malloc(sizeof(SDL_Surface *) * lines);

    if (surface == NULL)
    {
        showErrorAndExit("Failed to allocate a whole %d bytes for the Dialog Surfaces", (int)sizeof(SDL_Surface *) * lines);
    }

    lineBreaks = malloc(sizeof(int) * lines);

    if (lineBreaks == NULL)
    {
        showErrorAndExit("Failed to allocate a whole %d bytes for the line breaks", (int)sizeof(int) * lines);
    }

    STRNCPY(text, msg, strlen(msg) + 1);

    token = strtok_r(text, " ", &savePtr);

    i = 0;

    maxWidth = w = h = 0;

    if (titleText != NULL)
    {
        surface[i] = generateTextSurface(titleText, game.font, 255, 255, 0, 0, 0, 0);

        h = surface[i]->h + 5;

        maxWidth = surface[i]->w;

        i++;
    }

    while (token != NULL)
    {
        lineBreak = FALSE;

        snprintf(word, sizeof(word), "%d", game.kills);

        token = replaceString(token, "[GAME_KILLS]", word);

        token = replaceString(token, "[HOURS]", getPlayTimeHours());

        snprintf(word, sizeof(word), "%d", game.continues);

        token = replaceString(token, "[CONTINUE_COUNT]", word);

        token = replaceString(token, "[INPUT_LEFT]", getKeyValue(control.button[CONTROL_LEFT]));

        token = replaceString(token, "[INPUT_RIGHT]", getKeyValue(control.button[CONTROL_RIGHT]));

        token = replaceString(token, "[INPUT_JUMP]", getKeyValue(control.button[CONTROL_JUMP]));

        token = replaceString(token, "[INPUT_BLOCK]", getKeyValue(control.button[CONTROL_BLOCK]));

        token = replaceString(token, "[INPUT_ATTACK]", getKeyValue(control.button[CONTROL_ATTACK]));

        token = replaceString(token, "[INPUT_INTERACT]", getKeyValue(control.button[CONTROL_INTERACT]));

        token = replaceString(token, "[INPUT_ACTIVATE]", getKeyValue(control.button[CONTROL_ACTIVATE]));

        token = replaceString(token, "[INPUT_INVENTORY]", getKeyValue(control.button[CONTROL_INVENTORY]));

        token = replaceString(token, "[INPUT_PREVIOUS]", getKeyValue(control.button[CONTROL_PREVIOUS]));

        token = replaceString(token, "[INPUT_NEXT]", getKeyValue(control.button[CONTROL_NEXT]));

        snprintf(word, sizeof(word), "%s ", token);

        if (word[strlen(word) - 2] == '\n')
        {
            lineBreak = TRUE;

            word[strlen(word) - 2] = '\0';
        }

        token = strtok_r(NULL, " ", &savePtr);

        if (token == NULL)
        {
            word[strlen(word) - 1] = '\0';
        }

        surface[i] = generateTextSurface(word, game.font, 255, 255, 255, 0, 0, 0);

        lineBreaks[i] = lineBreak;

        if (h == 0 || (i == 1 && titleText != NULL))
        {
            h += surface[i]->h + 5;
        }

        if (w + surface[i]->w > MAX_DIALOG_WIDTH)
        {
            w = 0;

            h += surface[i]->h + 5;
        }

        w += surface[i]->w;

        if (w > maxWidth)
        {
            maxWidth = w;
        }

        if (lineBreak == TRUE)
        {
            w = 0;

            h += surface[i]->h + 5;
        }

        i++;
    }

    h -= 5;

    tempSurface = createSurface(maxWidth, h);

    w = h = 0;

    for (i=0; i<lines; i++)
    {
        if (w + surface[i]->w > MAX_DIALOG_WIDTH || (titleText != NULL && i == 1))
        {
            w = 0;

            h += surface[i]->h + 5;
        }

        dest.x = w;
        dest.y = h;
        dest.w = surface[i]->w;
        dest.h = surface[i]->h;

        SDL_BlitSurface(surface[i], NULL, tempSurface, &dest);

        w += surface[i]->w;

        SDL_FreeSurface(surface[i]);

        if (lineBreaks[i] == TRUE)
        {
            w = 0;

            h += surface[i]->h + 5;
        }
    }

    tempSurface = addBorder(tempSurface, 255, 255, 255, 0, 0, 0);

    free(surface);

    free(text);

    if (titleText != NULL)
    {
        free(titleText);
    }

    free(lineBreaks);

    return tempSurface;
}
示例#22
0
int
processMacroSection(FILE *fp,
		    string& theline,
		    bool& new_section)
{
  vector<string> v_tokens;
  string *mid = NULL;
  int success = 0;
  bool executenow=false;

  cout << "Processing macro section" << endl;

  new_section=false;

  while (getLine(fp,theline,"macro")) {
    if (!theline.size()) continue;
    if (theline[0] == '#') continue; // comments are welcome
    if (theline[0] == '[') {
      new_section=true;
      break;
    }

    string key, value;
    if (!getKeyValue(theline,key,value)) continue;

    //--------------------
    if (key == "id") {
    //--------------------
      if (mid != NULL) {
	cerr << "no more than one id per graph section allowed " << value << endl;
	break;
      }
      mid = new string(value);

    //------------------------------
    } else if (key == "pathargs") {
    //------------------------------

      if (!mid) {
	cerr << "id key must be defined first in the section" << endl; continue;
      }

      if (executenow) {
	int error;
	cout << "Executing macro " << *mid << " --> " << value << endl;
	gROOT->Macro(value.c_str(), &error, kTRUE); // update current pad
	if (error) {
	  static const char *errorstr[] = {
	    "kNoError","kRecoverable","kDangerous","kFatal","kProcessing" };
	  cerr << "ERROR: error returned from macro: " << errorstr[error] << endl;
	}
      }

      // We're actually using this map in reverse here!
      glmap_objpath2id.insert(pair<string,string>(*mid,value));

      success = 1;

    //------------------------------
    } else if (key == "execfromlib") {
    //------------------------------

      if (!mid) {
	cerr << "id key must be defined first in the section" << endl; continue;
      }
#if 0
      gSystem->Load(value.c_str());

      if (executenow) {
	int error;
	cout << "Executing macro " << *mid << " --> " << value << endl;
	gROOT->Macro(value.c_str(), &error, kTRUE); // update current pad
	if (error) {
	  static const char *errorstr[] = {
	    "kNoError","kRecoverable","kDangerous","kFatal","kProcessing" };
	  cerr << "ERROR: error returned from macro: " << errorstr[error] << endl;
	}
      }
#endif
      // We're actually using this map in reverse here!
      glmap_objpath2id.insert(pair<string,string>(*mid,value));

      success = 1;

    //------------------------------
    } else if (key == "executenow") {
    //------------------------------

      if (!mid) {
	cerr << "id key must be defined first in the section" << endl; continue;
      }

      if (str2int(value))
	executenow=true;

    } else {
      cerr << "unknown key " << key << endl;
    }
  }
  return success;
}                                                 // processGraphSection
示例#23
0
CfgFile::blockMap CfgFile::getBlockMap(const std::string &sBlock)
{
    // first find the block
    if(findBlock(sBlock) != 0)
        throw std::invalid_argument("The Block \""+sBlock+"\" does not exist in the Config File " + sFilename); // block is not there

    // some local variables
    std::string sLine;
    std::string sValue;
    size_t nonEmpty;
    size_t endOfName;
    blockMap resultMap;

    // then get all the keys and values
    while(cfgfile.good())
    {
        getline(cfgfile,sLine);

        // erase comments at the end
        cutAfterFirst(sLine, "#", "\\");
        // the first non whitespace char
        nonEmpty = sLine.find_first_not_of(" \t");

        if(nonEmpty == std::string::npos)
            continue; // ignore empty lines
        if(sLine[nonEmpty] == '[')
            break; // we are done this is the next block

        // we found a key
        // see where the name is
        endOfName = sLine.find_first_of(" =\t", nonEmpty+1);
        if(endOfName == std::string::npos)
        {
            logWARNING << "Syntax error in configuration file! File: " << sFilename <<" Block: " << sBlock << " Key: " << sLine;
            continue; // syntax error, we ignore the block (comment or end of line)
        }

        // get the value
        sValue = sLine;
        if (getKeyValue(sValue, endOfName) != 0)
        {
            logWARNING << "Syntax error in configuration file! File: " << sFilename << " Block: " << sBlock <<
                       " Key: " << sLine;
            continue; // syntax error, we ignore the key
        }


        resultMap[sLine.substr(nonEmpty, endOfName-(nonEmpty))] = sValue;
    }

    if( !cfgfile.good())
    {
        if(!cfgfile.eof())
            throw std::runtime_error("Error reading from config file! Filename: " + sFilename);
        cfgfile.clear();
        cfgfile.seekg(0, cfgfile.beg);
    }

    sCurrentBlock = ""; // we have no idea where we are

    return resultMap;
}
示例#24
0
CfgFile::configList CfgFile::getConfigList()
{
    // some local variables
    std::string sLine;
    std::string sThisBlocksName;
    std::string sValue;
    size_t nonEmpty;
    size_t closingBracket;
    size_t endOfName;
    configList resultVec(blockPositionCache.size());
    blockMap tmpMap;

    // go to the start
    cfgfile.seekg(0, cfgfile.beg);

    // and parse the whole file
    while(cfgfile.good())
    {
        getline(cfgfile,sLine);
        cutAfterFirst(sLine, "#", "\\");

        // the first non whitespace char
        nonEmpty = sLine.find_first_not_of(" \t");

        // check what we got
        if(nonEmpty == std::string::npos) // nothing
            continue;
        else if(sLine[nonEmpty] == '[') // a new block
        {
            // find the closing bracket
            closingBracket = sLine.find("]");
            if( closingBracket == std::string::npos)
            {
                logWARNING << "Syntax error in configuration file! File: " << sFilename <<" Block: " << sLine;
                continue; // syntax error, we ignore the block (comment or end of line)
            }

            // we found the next block
            if( !sThisBlocksName.empty())
            {
                resultVec.push_back(blockPair(sThisBlocksName,tmpMap));
                tmpMap.clear();
            }

            nonEmpty++; // ignore the [
            sThisBlocksName = sLine.substr(nonEmpty, closingBracket-(nonEmpty));
            biggestBlockPosition = cfgfile.tellg();
            blockPositionCache[sThisBlocksName] = biggestBlockPosition;
        }
        else if( !sThisBlocksName.empty()) // a key (ignore keys before first block)
        {
            // add the key to tmpMap

            // find the key name
            endOfName = sLine.find_first_of(" =\t", nonEmpty+1);
            if(endOfName == std::string::npos)
            {
                logWARNING << "Syntax error in configuration file! File: " << sFilename <<" Block: " << sThisBlocksName << " Key: " << sLine;
                continue; // syntax error, we ignore the key
            }

            // get the value
            sValue = sLine;
            if (getKeyValue(sValue, endOfName) != 0)
            {
                logWARNING << "Syntax error in configuration file! File: " << sFilename << " Block: " <<
                           sThisBlocksName << " Key: " << sLine;
                continue; // syntax error, we ignore the key
            }

            tmpMap[sLine.substr(nonEmpty, endOfName-(nonEmpty))] = sValue;
        }
    }

    if(!cfgfile.eof())
        throw std::runtime_error("Error reading from config file! Filename: " + sFilename);

    // put in the last block
    resultVec.push_back(blockPair(sThisBlocksName,tmpMap));

    cfgfile.clear();
    cfgfile.seekg(cfgfile.beg);
    sCurrentBlock = ""; // we are at 0, so in no block

    return resultVec;
}
示例#25
0
QString EWAUserAction::getKeyValue() const
{
    return m_pEvent ? getKeyValue( m_pEvent ) : QString();
}
示例#26
0
TTree *getTreeFromSpec(const string& tid,
		       const string& spec)
{
  TTree  *tree    = NULL;
  TFile *rootfile = NULL;
  vector<string> v_tokens;
  string fullspec;

  if( gl_verbose)
    cout << "processing " << spec << endl;

  string tspec;
  string rootfn;

  fullspec = spec;

  Tokenize(fullspec,v_tokens,":");
  int ntok = (int)v_tokens.size();
  if( ((ntok != 2) &&
       (ntok != 3)   ) ||       //ntok==3 means file specifier is a URL
      (!v_tokens[0].size())  ||
      (!v_tokens[1].size())    ) {
    cerr << "malformed root tree path file:folder/subfolder/.../histo " << fullspec << endl;
    return NULL;
  } else {
    rootfn = (ntok==2) ? v_tokens[0] : v_tokens[0]+":"+v_tokens[1];
    tspec  = (ntok==2) ? v_tokens[1] : v_tokens[2];
  }

#if 0
  map<string,string>::const_iterator it = glmap_objpath2id.find(fullspec);
  if( it != glmap_objpath2id.end() ) {
    // Allow the possibility to run the script a second time in root
    if( gl_verbose)
      cout << "Object " << fullspec << " already read in, here it is" << endl;
    map<string,tree *>::const_iterator hit = glmap_id2histo.find(it->second);
    if( hit == glmap_id2histo.end() ) {
      if( gl_verbose)
	cout << "oops, sorry, I lied." << endl;
      return NULL;
    }
    tree = hit->second;
  } else {
#endif
    rootfile = openRootFile(rootfn);
    if (rootfile) {
      tree = (TTree *)rootfile->Get(tspec.c_str());
      if( !tree) {
	cerr << "couldn't find " << tspec << " in " << rootfn << endl;
      } else {
	// success, record that you read it in.
	if( gl_verbose) cout << "Found " << fullspec << endl;
	glmap_objpath2id.insert(pair<string,string>(fullspec,tid));
	glmap_id2objpath.insert(pair<string,string>(tid,fullspec));
	glmap_id2tree.insert(pair<string,TTree *>(tid,tree));
      }
    }
    //}
  return tree;
}                                                     // getTreeFromSpec

//======================================================================

bool                              // returns true if success
processTreeSection(FILE *fp,
		   string& theline,
		   bool& new_section)
{
  string *tid  = NULL;
  TTree  *t1   = NULL;

  if (gl_verbose)
    cout << "Processing Tree section" << endl;

  new_section=false;

  while (getLine(fp,theline,"Tree")) {
    if (!theline.size()) continue;
    if (theline[0] == '#') continue; // comments are welcome

    if (theline[0] == '[') {
      new_section=true;
      break;
    }

    string key, value;
    if (!getKeyValue(theline,key,value)) continue;

    //--------------------
    if (key == "id") {
    //--------------------
      if (tid != NULL) {
	cerr << "no more than one id per F1 section allowed " << value << endl;
	break;
      }
      tid = new string(value);
      
      map<string, TTree *>::const_iterator tit = glmap_id2tree.find(*tid);
      if (tit != glmap_id2tree.end()) {
	cerr << "Tree id " << *tid << " already defined" << endl;
	break;
      }
    //------------------------------
    } else if( key == "path" ) {
    //------------------------------
      if( !tid ) {
	cerr << "id key must be defined first in the section" << endl; continue;
      }
      if( t1 ) {
	cerr << "histo already defined" << endl; continue;
      }
      t1 = getTreeFromSpec(*tid,value);
      if( !t1 ) continue;
    }
    else {
      cerr << "unknown key " << key << endl;
    }
  }

  if (tid) delete tid;
  return (t1 != NULL);
}                                                  // processTreesection
示例#27
0
文件: spTree.C 项目: pdudero/usercode
bool                              // returns true if success
processTreeSection(FILE *fp,
		   string& theline,
		   bool& new_section)
{
  string *tid  = NULL;
  TChain  *t1   = NULL;
  vector<string> v_tokens;

  string treename;

  if (gl_verbose)
    cout << "Processing Tree section" << endl;

  new_section=false;

  while (getLine(fp,theline,"Tree")) {
    if (!theline.size()) continue;
    if (theline[0] == '#') continue; // comments are welcome

    if (theline[0] == '[') {
      new_section=true;
      break;
    }

    string key, value;
    if (!getKeyValue(theline,key,value)) continue;

    //--------------------
    if (key == "id") {
    //--------------------
      if (tid != NULL) {
	cerr << "no more than one id per F1 section allowed " << value << endl;
	break;
      }
      tid = new string(value);
      
      map<string, TChain *>::const_iterator tit = glmap_id2chain.find(*tid);
      if (tit != glmap_id2chain.end()) {
	cerr << "Tree id " << *tid << " already defined" << endl;
	break;
      }
    //------------------------------
    } else if( key == "treename" ) {
    //------------------------------
      if( !tid ) {
	cerr << "id key must be defined first in the section" << endl; continue;
      }
      if( t1 ) {
	cerr << "Tree already defined" << endl; continue;
      }
      treename = value;

    //------------------------------
    } else if( key == "globslist" ) {
    //------------------------------
      t1 = getChainFromGlobslist(*tid,treename,value);
      if( !t1 )
	exit(-1);

    //------------------------------
    } else if( key == "copytree" ) {
    //------------------------------
      if( !tid ) {
	cerr << "id key must be defined first in the section" << endl; continue;      }
    
      Tokenize(value,v_tokens,",");
      
      if (v_tokens.size() != 2) {
	cerr << "copytree syntax expected: copytree=treeid,cutstring: " << value << endl; continue; }

      TChain *t2 = findChain(v_tokens[0]);
      if (!t2) {
	cerr << "tree " << v_tokens[0] << " must be defined previously" << endl; continue;    }
      if (gl_verbose)
	cout<<"Begin CopyTree of "<<v_tokens[0]<<" with selection "<<v_tokens[1]<<flush;
      
      t1 = (TChain *)(t2->CopyTree(v_tokens[1].c_str()));

      if( !t1 ) {
	cerr << "CopyTree failed" << endl; exit(-1); }

      if (gl_verbose)
	cout<<"...Done."<<endl;

    //------------------------------
    } else if( key == "save2file" ) {
    //------------------------------
      if( !t1 ) {
	cerr << "save2file: must define tree first" << endl; continue; }

      TFile *rootfile = openRootFile(value,"RECREATE");
      
      t1->SetDirectory(rootfile);
      t1->Write();
      rootfile->Flush();

      if (gl_verbose)
	cout << "Tree written to file " << value << endl;

      rootfile->Close();

    //------------------------------
    } else if( key == "unbinnedfit" ) {
    //------------------------------
      if( !tid ) {
	cerr << "id key must be defined first in the section" << endl; continue;      }
      if( !t1 ) {
	cerr << "Tree must already be defined using 'globslist'" << endl; continue;   }

      int fitresult=-99;

      Tokenize(value,v_tokens,",");
      switch(v_tokens.size()) {
      case 2: fitresult = t1->UnbinnedFit(v_tokens[0].c_str(),
					  v_tokens[1].c_str());
	break;
      case 3: fitresult = t1->UnbinnedFit(v_tokens[0].c_str(),
					  v_tokens[1].c_str(),
					  v_tokens[2].c_str()); 
	break;
      case 4: fitresult = t1->UnbinnedFit(v_tokens[0].c_str(),  // funcname
					  v_tokens[1].c_str(),  // varexp
					  v_tokens[2].c_str(),  // selection
					  v_tokens[3].c_str()); // option
	break;
      default:
	cerr << "unbinnedfit: expect 2-4 arguments separated by commas: " << value <<endl;
	exit(-1);
      }
      cout << "fit result returned = " << fitresult << endl;
      cout << "Number of selected entries in the fit = " << t1->GetSelectedRows() << endl;
    }
    else {
      cerr << "unknown key " << key << endl;
    }
  }

  if (tid) delete tid;
  return (t1 != NULL);
}                                                  // processTreesection
示例#28
0
bool                              // returns true if success
processMultiGraphSection(FILE *fp,
			 string& theline,
			 bool& new_section)
{
  vector<string> v_tokens;
  TString  title;
  string   *gid  = NULL;
  TVectorD vx,vy,vz,exl,exh,eyl,eyh;
  float xoffset=0.0,yoffset=0.0, yscale=1.0;
  float xmin=0.,xmax=0.,ymin=0.,ymax=0.,zmin=0.,zmax=0.;
  bool asymerrors = false;
  wGraph_t *wg = NULL;

  char xheader[80],yheader[80];
  xheader[0]=0;
  yheader[0]=0;

  if (gl_verbose) cout << "Processing multigraph section" << endl;

  new_section=false;

  while (getLine(fp,theline,"multigraph")) {
    if (!theline.size()) continue;
    if (theline[0] == '#') continue; // comments are welcome

    if (theline[0] == '[') {
      new_section=true;
      break;
    }

    string key, value;
    if (!getKeyValue(theline,key,value)) continue;

    //--------------------
    if (key == "id") {
    //--------------------
      if (gid != NULL) {
	cerr << "no more than one id per section allowed " << value << endl;
	break;
      }

      gid = new string(value);

    //------------------------------
    } else if (key == "graphs") {
    //------------------------------
      if (!gid) {
	cerr << "id key must be defined first in the section" << endl; continue;
      }

      Tokenize(value,v_tokens,","); 

      for (size_t i=0; i<v_tokens.size(); i++) {
	map<string,wGraph_t *>::const_iterator it = glmap_id2graph.find(v_tokens[i]);
	if( it == glmap_id2graph.end() ) {
	  cerr << "Graph ID " << v_tokens[i] << " not found,";
	  cerr << "graphs must be defined before multigraph section" << endl;
	  break;
	}
	wg  = new wGraph_t(*(it->second),*gid);
	
      }
      if (wg) {
	cerr << "graph already defined" << endl; continue;
      }
      if (inSet<string>(glset_graphFilesReadIn,path)) {
	cerr << "vector file " << path << " already read in" << endl; break;
      }

      wg = new wGraph_t();

      if (asymerrors)
	loadVectorsFromFile(path.c_str(),scanspec.c_str(),vx,vy,exl,exh,eyl,eyh);
      else
	loadVectorsFromFile(path.c_str(),scanspec.c_str(),vx,vy,xheader,yheader);

      if (strlen(xheader)) wg->xax->SetTitle(xheader);
      if (strlen(yheader)) wg->yax->SetTitle(yheader);

    //------------------------------
    } else if (key == "vectorfile2d") {
    //------------------------------
      if (!gid) {
	cerr << "id key must be defined first in the section" << endl; continue;
      }
      string path = value;
      if (wg) {
	cerr << "graph already defined" << endl; continue;
      }
      if (inSet<string>(glset_graphFilesReadIn,path)) {
	cerr << "vector file " << path << " already read in" << endl; break;
      }

      wg = new wGraph_t();

      wg->gr2d = new TGraph2D(path.c_str());

      if (wg->gr2d->IsZombie()) {
	cerr << "Unable to make Graph2D from file " << path << endl;
	exit(-1);
      }
      wg->gr2d->SetName(gid->c_str());

    //------------------------------
    } else if (key == "path") {
    //------------------------------

      if (!gid) {
	cerr << "id key must be defined first in the section" << endl; continue;
      }
      if (wg) {
	cerr << "graph already defined" << endl; continue;
      }
      wg = new wGraph_t();
      wg->gr  = getGraphFromSpec(*gid,value);
      if (!wg->gr) continue;

    //------------------------------
    } else if (key == "clone") {
    //------------------------------

      if (!gid) {
	cerr << "id key must be defined first in the section" << endl; continue;
      }
      if (wg) {
	cerr << "graph already defined" << endl; continue;
      }
      map<string,wGraph_t *>::const_iterator it = glmap_id2graph.find(value);
      if( it == glmap_id2graph.end() ) {
	cerr << "Graph ID " << value << " not found,";
	cerr << "clone must be defined after the clonee" << endl;
	break;
      }
      wg  = new wGraph_t(*(it->second),*gid);

    //------------------------------
    } else if (key == "bayesdiv") {
    //------------------------------

      Tokenize(value,v_tokens,",/"); // either comma-separated or using '/'
      if (v_tokens.size() != 2) {
	cerr << "expect comma-separated list of exactly two histo specs to divide! ";
	cerr << theline << endl;
	continue;
      }

      TH1 *tmph1 = (TH1 *)findHisto(v_tokens[0]); if (!tmph1) exit(-1);
      TH1 *tmph2 = (TH1 *)findHisto(v_tokens[1]); if (!tmph2) exit(-1);

      cout << tmph1->GetNbinsX() << " " << tmph2->GetNbinsX() << endl;

      wg = new wGraph_t();

      // equivalent to BayesDivide
      //
      if (gl_verbose) wg->gr = new TGraphAsymmErrors(tmph1,tmph2,"debug");
      else            wg->gr = new TGraphAsymmErrors(tmph1,tmph2,"");
      //if (gl_verbose) wg->gr = new TGraphAsymmErrors(tmph1,tmph2,"cl=0.683 b(1,1) mode v");
      //else            wg->gr = new TGraphAsymmErrors(tmph1,tmph2,"cl=0.683 b(1,1) mode");
      if (!wg->gr) {
	cerr << "BayesDivide didn't work! wonder why..." << endl;
	continue;
      } else if (gl_verbose) {
	cout << wg->gr->GetN() << " points in the graph" << endl;
      }

    } else if (!wg) {
      cerr<<"One of keys path,clone,vectorfile,vectorfile2d or bayesdiv must be defined before key..."<<key<<endl;
    } else {
      if     ( key == "xoffset" )      xoffset   = str2flt(value);
      else if( key == "yoffset" )      yoffset   = str2flt(value);
      else if( key == "yscale" )       yscale    = str2flt(value);
      else if( key == "title"  )       title     = TString(value);
      else if( key == "xtitle" )       wg->xax->SetTitle(value.c_str());
      else if( key == "ytitle" )       wg->yax->SetTitle(value.c_str());
      else if( key == "ztitle" )       wg->zax->SetTitle(value.c_str());
      else if( key == "xtitleoffset" ) wg->xax->SetTitleOffset(str2flt(value));
      else if( key == "ytitleoffset" ) wg->yax->SetTitleOffset(str2flt(value));
      else if( key == "ztitleoffset" ) wg->zax->SetTitleOffset(str2flt(value));
      else if( key == "xmin" )         xmin      = str2flt(value);
      else if( key == "xmax" )         xmax      = str2flt(value);
      else if( key == "ymin" )         ymin      = str2flt(value);
      else if( key == "ymax" )         ymax      = str2flt(value);
      else if( key == "zmin" )         zmin      = str2flt(value);
      else if( key == "zmax" )         zmax      = str2flt(value);
      else if( key == "linecolor" )    wg->lcolor  = str2int(value);
      else if( key == "linestyle" )    wg->lstyle  = str2int(value);
      else if( key == "linewidth" )    wg->lwidth  = str2int(value);
      else if( key == "markercolor" )  wg->mcolor  = str2int(value);
      else if( key == "markerstyle" )  wg->mstyle  = str2int(value);
      else if( key == "markersize"  )  wg->msize   = str2int(value);
      else if( key == "fillcolor" )    wg->fcolor  = str2int(value);
      else if( key == "fillstyle" )    wg->fstyle  = str2int(value);
      else if( key == "xndiv" )        wg->xax->SetNdivisions(str2int(value));
      else if( key == "yndiv" )        wg->yax->SetNdivisions(str2int(value));
      else if( key == "asymerrors" )   asymerrors  = (bool)str2int(value);
      else if( key == "leglabel" )     wg->leglabel   = value;
      else if( key == "draw" )         wg->drawopt    = value;
      else if( key == "legdraw" )      wg->legdrawopt = value;
      else if( key == "setprecision" ) cout << setprecision(str2int(value));
      else if( key == "printvecs2file") printVectorsToFile(wg); // ,value);
      else if( key == "fittf1" ) {
	TF1 *tf1 = findTF1(value);
	if( !tf1 ) {
	  cerr << "TF1 " << value << " must be defined first" << endl;
	  continue;
	}
	string funcnewname = value+(*gid);
	wg->fitfn = new TF1(*tf1);
	wg->fitfn->SetName(funcnewname.c_str());
      }
      else if ( key == "contours" ) {
	Tokenize(value,v_tokens,",");
	wg->contours = new TVectorD(v_tokens.size());
	for (size_t i=0; i<v_tokens.size(); i++)
	  wg->contours[i] = str2flt(v_tokens[i]);
      }
      else {
	cerr << "unknown key " << key << endl;
      }
#if 0
      processCommonHistoParams(key,value,*wh);
#endif
    }
  }

  //cout << title << endl;
  if (wg->gr2d) {
    wg->gr2d->SetTitle(title);
    wg->gr2d->SetLineStyle   (wg->lstyle);
    wg->gr2d->SetLineColor   (wg->lcolor);
    wg->gr2d->SetLineWidth   (wg->lwidth);
    wg->gr2d->SetMarkerColor (wg->mcolor);
    wg->gr2d->SetMarkerStyle (wg->mstyle);
    wg->gr2d->SetMarkerSize  (wg->msize);
    wg->gr2d->SetFillStyle   (wg->fstyle);
    wg->gr2d->SetFillColor   (wg->fcolor);
    if (zmax>zmin)  
      wg->zax->SetLimits(zmin,zmax);
  } else {
    if (vx.GetNoElements()) { // load utility guarantees the same size for both
      if (yscale  != 1.0) vy *= yscale;
      if (xoffset != 0.0) vx += xoffset;
      if (yoffset != 0.0) vy += yoffset;
      if (asymerrors) 
	wg->gr = new TGraphAsymmErrors(vx,vy,exl,exh,eyl,eyh);
      else
	wg->gr = new TGraph(vx,vy);
    }
    wg->gr->UseCurrentStyle();
    wg->gr->SetTitle(title);
    wg->gr->SetLineStyle   (wg->lstyle);
    wg->gr->SetLineColor   (wg->lcolor);
    wg->gr->SetLineWidth   (wg->lwidth);
    wg->gr->SetMarkerColor (wg->mcolor);
    wg->gr->SetMarkerStyle (wg->mstyle);
    wg->gr->SetMarkerSize  (wg->msize);
    wg->gr->SetFillStyle   (wg->fstyle);
    wg->gr->SetFillColor   (wg->fcolor);

    if (xmax>xmin) wg->xax->SetLimits(xmin,xmax);
    if (ymax>ymin) wg->yax->SetLimits(ymin,ymax);
  }

  glmap_id2graph.insert(pair<string,wGraph_t *>(*gid,wg));

  return (wg != NULL);
}                                                 // processGraphSection
示例#29
0
bool                              // returns true if success
processGraphSection(FILE *fp,
		    string& theline,
		    bool& new_section)
{
  vector<string> v_tokens;
  TString  title;
  string   *gid  = NULL;
  TVectorD vx,vy,vz,exl,exh,eyl,eyh;
  float xoffset=0.0,yoffset=0.0, yscale=1.0;
  float xmin=0.,xmax=0.,ymin=0.,ymax=0.,zmin=0.,zmax=0.;
  bool asymerrors = false;
  bool printvecs  = false;
  wGraph_t wg;                                    // placeholder for read-in values
  vector<std::pair<string, wGraph_t *> > v_graphs;

  char xheader[80],yheader[80];
  xheader[0]=0;
  yheader[0]=0;

  if (gl_verbose) cout << "Processing graph section" << endl;

  new_section=false;

  while (getLine(fp,theline,"graph")) {
    if (!theline.size()) continue;
    if (theline[0] == '#') continue; // comments are welcome

    if (theline[0] == '[') {
      new_section=true;
      break;
    }

    string key, value;
    if (!getKeyValue(theline,key,value)) continue;

    //--------------------
    if (key == "id") {
    //--------------------
      if (gid != NULL) {
	cerr << "no more than one id per graph section allowed " << value << endl;
	break;
      }

      gid = new string(value);

    //------------------------------
    } else if (key == "vectorfile") {
    //------------------------------
      if (!gid) {
	cerr << "id key must be defined first in the section" << endl; continue;
      }
      string path     = value;
      string scanspec = asymerrors ?  "%lf %lf %lf %lf" : "%lf %lf";

      Tokenize(value,v_tokens,",");
      if (v_tokens.size() > 1) {
	path     = v_tokens[0];
	scanspec = v_tokens[1];
      }

      if (v_graphs.size()) {
	cerr << "graph(s) already defined" << endl; continue;
      }
      if (inSet<string>(glset_graphFilesReadIn,path)) {
	cerr << "vector file " << path << " already read in" << endl; break;
      }

      wGraph_t *pwg = new wGraph_t();

      if (asymerrors)
	loadVectorsFromFile(path.c_str(),scanspec.c_str(),vx,vy,exl,exh,eyl,eyh);
      else
	loadVectorsFromFile(path.c_str(),scanspec.c_str(),vx,vy,xheader,yheader);

      if (strlen(xheader)) pwg->xax->SetTitle(xheader);
      if (strlen(yheader)) pwg->yax->SetTitle(yheader);

      v_graphs.push_back(pair<string,wGraph_t *>(*gid,pwg));

      // pend filling the graph until all parameters are read in

    //------------------------------
    } else if (key == "vectorfile2d") {
    //------------------------------
      if (!gid) {
	cerr << "id key must be defined first in the section" << endl; continue;
      }
      if (v_graphs.size()) {
	cerr << "graph(s) already defined" << endl; continue;
      }

      Tokenize(value,v_tokens,",");

      string path=v_tokens[0];
      if (inSet<string>(glset_graphFilesReadIn,path)) {
	cerr << "vector file " << path << " already read in" << endl; break;
      }

      wGraph_t *pwg = new wGraph_t();

      switch(v_tokens.size()) {
      case 1:  pwg->gr2d = new TGraph2D(path.c_str()); break;
      case 2:  pwg->gr2d = new TGraph2D(path.c_str(),v_tokens[1].c_str()); break;
      case 3:  pwg->gr2d = new TGraph2D(path.c_str(),v_tokens[1].c_str(),v_tokens[2].c_str()); break;
      default:
	cerr << "malformed vectorfile2d spec path[,format[,option]] " << value << endl;
	break;
      }

      if (pwg->gr2d->IsZombie()) {
	cerr << "Unable to make Graph2D from file " << path << endl;
	exit(-1);
      }
      pwg->gr2d->SetName(gid->c_str());

      v_graphs.push_back(pair<string,wGraph_t *>(*gid,pwg));

    //------------------------------
    } else if (key == "path") {
    //------------------------------

      if (!gid) {
	cerr << "id key must be defined first in the section" << endl; continue;
      }
      if (v_graphs.size()) {
	cerr << "graph already defined" << endl; continue;
      }
      wGraph_t *pwg = new wGraph_t();
      pwg->gr  = getGraphFromSpec(*gid,value);
      if (!pwg->gr) continue;

      v_graphs.push_back(pair<string,wGraph_t *>(*gid,pwg));

    //------------------------------
    } else if (key == "clone") {
    //------------------------------

      if (!gid) {
	cerr << "id key must be defined first in the section" << endl; continue;
      }
      if (v_graphs.size()) {
	cerr << "graph already defined" << endl; continue;
      }
      map<string,wGraph_t *>::const_iterator it = glmap_id2graph.find(value);
      if( it == glmap_id2graph.end() ) {
	cerr << "Graph ID " << value << " not found,";
	cerr << "clone must be defined after the clonee" << endl;
	break;
      }
      wGraph_t *pwg  = new wGraph_t(*(it->second),*gid);

      v_graphs.push_back(pair<string,wGraph_t *>(*gid,pwg));

    //------------------------------
    } else if( key == "fromhisto" ) { // converts TH1 to TGraph
    //------------------------------
      if( !gid ) {
	cerr << "id key must be defined first in the section" << endl; continue;
      }
      if (v_graphs.size()) {
	cerr << "graph(s) already defined" << endl; continue;
      }
      // look for multihist with this identifier
      std::map<string,unsigned>::const_iterator it=glmap_mhid2size.find(value);
      if (it!=glmap_mhid2size.end()) {
	for (size_t i=0; i<it->second; i++) {
	  string hidi=value+int2str(i);
	  TH1 *h = (TH1 *)findHisto(hidi,"");
	  assert(h);
	  wGraph_t *pwg = new wGraph_t();
	  pwg->gr = new TGraph(h);
	  v_graphs.push_back(pair<string,wGraph_t *>(*gid,pwg));
	}
      } else {
	TH1 *h = (TH1 *)findHisto(value);
	assert(h);
	wGraph_t *pwg = new wGraph_t();
	pwg->gr = new TGraph(h);
	v_graphs.push_back(pair<string,wGraph_t *>(*gid,pwg));
      }

    //------------------------------
    } else if( key == "fillfromtree" ) { // converts tree array variables into a group of graphs
    //------------------------------
      if( !gid ) {
	cerr << "id key must be defined first in the section" << endl; continue;
      }
      if (v_graphs.size()) {
	cerr << "graph(s) already defined" << endl; continue;
      }

      Tokenize(value,v_tokens,";");
      string treedrawspec=v_tokens[0];

      int ifirst=-1,ilast=-1;
      if (v_tokens.size() == 2) {
	string range=v_tokens[1];
	Tokenize(range,v_tokens,"-");
	if (v_tokens.size()==2) {
	  ifirst=str2int(v_tokens[0]);
	  ilast =str2int(v_tokens[1]);
	}
      }
      //cout << v_tokens.size() << " " << ifirst << " " << ilast << endl;
      if (ifirst>0 && 
	  ilast>=ifirst ) {
	for (int i=ifirst; i<=ilast; i++) {
	  wGraph_t *pwg = NULL;

	  // defined in spTree.C
	  void fillGraphFromTreeVar(std::string& drawspec,int index,wGraph_t *&pwg);
	  fillGraphFromTreeVar(treedrawspec,i,pwg);
	  assert(pwg);
	  string gidi= (*gid)+"_"+int2str(i-ifirst);
	  v_graphs.push_back(std::pair<string,wGraph_t *>(gidi,pwg));
	}

	glmap_mgid2size.insert(pair<string,unsigned>(*gid,v_graphs.size()));
      } else {
	wGraph_t *pwg = NULL;
	void fillGraphFromTreeVar(std::string& drawspec,int index,wGraph_t *&pwg);
	fillGraphFromTreeVar(treedrawspec,0,pwg);
	assert(pwg);
	v_graphs.push_back(std::pair<string,wGraph_t *>(*gid,pwg));
	glmap_mgid2size.insert(pair<string,unsigned>(*gid,v_graphs.size()));
      }

    //------------------------------
    } else if (key == "bayesdiv") {
    //------------------------------

      Tokenize(value,v_tokens,",/"); // either comma-separated or using '/'
      if (v_tokens.size() != 2) {
	cerr << "expect comma-separated list of exactly two histo specs to divide! ";
	cerr << theline << endl;
	continue;
      }

      TH1 *tmph1 = (TH1 *)findHisto(v_tokens[0]); if (!tmph1) exit(-1);
      TH1 *tmph2 = (TH1 *)findHisto(v_tokens[1]); if (!tmph2) exit(-1);

      cout << tmph1->GetNbinsX() << " " << tmph2->GetNbinsX() << endl;

      wGraph_t *pwg = new wGraph_t();

      if ( gl_verbose ) { 
	std::cout << "Dump of bin contents, errors" << std::endl ; 
	if ( tmph1->GetNbinsX() == tmph2->GetNbinsX() ) { 
	  for (int ib=1; ib<=tmph1->GetNbinsX(); ib++) {
	    std::cout << ib << ": " << tmph1->GetBinContent(ib) << "+/-" << tmph1->GetBinError(ib) 
		      << ", " << tmph2->GetBinContent(ib) << "+/-" << tmph2->GetBinError(ib) << std::endl ; 
	  }
	} else { 
	  cerr << "Histograms being divided do not have same number of bins!!!" << endl ; 
	}
      }

      // equivalent to BayesDivide
      //
      if (gl_verbose) pwg->gr = new TGraphAsymmErrors(tmph1,tmph2,"debug");
      else            pwg->gr = new TGraphAsymmErrors(tmph1,tmph2,"");
      //if (gl_verbose) pwg->gr = new TGraphAsymmErrors(tmph1,tmph2,"cl=0.683 b(1,1) mode v");
      //else            pwg->gr = new TGraphAsymmErrors(tmph1,tmph2,"cl=0.683 b(1,1) mode");
      if (!pwg->gr) {
	cerr << "BayesDivide didn't work! wonder why..." << endl;
	continue;
      } else if (gl_verbose) {
	cout << pwg->gr->GetN() << " points in the graph" << endl;
      }

      // Fix in case something broke

      for (int i=0; i<pwg->gr->GetN(); i++) {
          if ( pwg->gr->GetErrorYhigh(i) == 0. || pwg->gr->GetErrorYlow(i) == 0 ) { // Something bad happened
              if ( gl_verbose ) std::cout << "Problem with Bayes divide, checking..." << std::endl ;
              double pass  = tmph1->GetBinContent(i+1) ; 
              double total = tmph2->GetBinContent(i+1) ;
              if ( gl_verbose ) std::cout << pass << "/" << total << std::endl ;
              if ( pass == total ) {
                  if ( gl_verbose ) std::cout << "Everything OK" << std::endl ;
              } else { 
                  if ( gl_verbose ) std::cout << "Yep, something is broken" << std::endl ;
                  double xval, yval ;
                  pwg->gr->GetPoint(i,xval,yval) ;
                  yval = pass / total ;
                  // Use simplified efficiency assumption
                  // double u1 = tmph1->GetBinError(i+1) / tmph1->GetBinContent(i+1) ; 
                  // double u2 = tmph2->GetBinError(i+1) / tmph2->GetBinContent(i+1) ; 
                  // double unc = yval * sqrt( u1*u1 + u2*u2 ) ; 
                  double unc = sqrt( yval * (1.-yval)/tmph2->GetBinContent(i+1) ) ; 
                  double uhi = ( (yval + unc > 1.)?(1.-yval):(unc) ) ; 
                  double ulo = ( (yval - unc < 0.)?(yval):(unc) ) ;
                  pwg->gr->SetPoint(i,xval,yval) ;
                  ((TGraphAsymmErrors*)pwg->gr)->SetPointError(i,pwg->gr->GetErrorXlow(i),pwg->gr->GetErrorXhigh(i),ulo,uhi) ; 
//                   pwg->gr->SetPointEYhigh(i,uhi) ; 
//                   pwg->gr->SetPointEYlow(i,ulo) ; 
              }
          }   
          if (gl_verbose) std::cout << i << ": " << pwg->gr->GetErrorYhigh(i) << "/" << pwg->gr->GetErrorYlow(i) << std::endl ; 
      }

    } else if (!v_graphs.size()) {
      cerr<<"One of keys path,clone,vectorfile,vectorfile2d or bayesdiv must be defined before key..."<<key<<endl;
    } else {
      if     ( key == "xoffset" )      xoffset   = str2flt(value);
      else if( key == "yoffset" )      yoffset   = str2flt(value);
      else if( key == "yscale" )       yscale    = str2flt(value);
      else if( key == "title"  )       title     = TString(value);
      else if( key == "xtitle" )       wg.xax->SetTitle      (TString(value));
      else if( key == "ytitle" )       wg.yax->SetTitle      (TString(value));
      else if( key == "ztitle" )       wg.zax->SetTitle      (TString(value));
      else if( key == "xtitleoffset" ) wg.xax->SetTitleOffset(str2flt(value));
      else if( key == "ytitleoffset" ) wg.yax->SetTitleOffset(str2flt(value));
      else if( key == "ztitleoffset" ) wg.zax->SetTitleOffset(str2flt(value));
      else if( key == "xndiv" )        wg.xax->SetNdivisions (str2int(value));
      else if( key == "yndiv" )        wg.yax->SetNdivisions (str2int(value));
      else if( key == "zndiv" )        wg.zax->SetNdivisions (str2int(value));
      else if( key == "xmin" )         xmin         = str2flt(value);
      else if( key == "xmax" )         xmax         = str2flt(value);
      else if( key == "ymin" )         ymin         = str2flt(value);
      else if( key == "ymax" )         ymax         = str2flt(value);
      else if( key == "zmin" )         zmin         = str2flt(value);
      else if( key == "zmax" )         zmax         = str2flt(value);
      else if( key == "linecolor" )    wg.lcolor    = str2int(value);
      else if( key == "linestyle" )    wg.lstyle    = str2int(value);
      else if( key == "linewidth" )    wg.lwidth    = str2int(value);
      else if( key == "markercolor" )  wg.mcolor    = str2int(value);
      else if( key == "markerstyle" )  wg.mstyle    = str2int(value);
      else if( key == "markersize"  )  wg.msize     = str2int(value);
      else if( key == "fillcolor" )    wg.fcolor    = str2int(value);
      else if( key == "fillstyle" )    wg.fstyle    = str2int(value);
      else if( key == "asymerrors" )   asymerrors   = (bool)str2int(value);
      else if( key == "leglabel" )     wg.leglabel  = value;
      else if( key == "draw" )         wg.drawopt   = value;
      else if( key == "legdraw" )      wg.legdrawopt= value;
      else if( key == "setprecision" ) cout << setprecision(str2int(value));
      else if( key == "printvecs2file") printvecs = true;
      else if( key == "fittf1" ) {
	TF1 *tf1 = findTF1(value);
	if( !tf1 ) {
	  cerr << "TF1 " << value << " must be defined first" << endl;
	  continue;
	}
	string funcnewname = value+(*gid);
	wg.fitfn = new TF1(*tf1);
	wg.fitfn->SetName(funcnewname.c_str());
      }
      else if ( key == "contours" ) {
	Tokenize(value,v_tokens,",");
	wg.contours = new TVectorD(v_tokens.size());
	for (size_t i=0; i<v_tokens.size(); i++)
	  wg.contours[i] = str2flt(v_tokens[i]);
      }
      else {
	cerr << "unknown key " << key << endl;
      }
#if 0
      processCommonHistoParams(key,value,*wh);
#endif
    }
  } // getline loop

  //cout << title << endl;

  for (size_t i=0; i<v_graphs.size(); i++) {
    string gidi = v_graphs[i].first;
    wGraph_t *pwg = v_graphs[i].second;
    if (pwg->gr2d) {
      pwg->gr2d->SetTitle(title);
      pwg->gr2d->SetLineStyle   (wg.lstyle);
      pwg->gr2d->SetLineColor   (wg.lcolor);
      pwg->gr2d->SetLineWidth   (wg.lwidth);
      pwg->gr2d->SetMarkerColor (wg.mcolor);
      pwg->gr2d->SetMarkerStyle (wg.mstyle);
      pwg->gr2d->SetMarkerSize  (wg.msize);
      pwg->gr2d->SetFillStyle   (wg.fstyle);
      pwg->gr2d->SetFillColor   (wg.fcolor);
      if (zmax>zmin)  
	pwg->zax->SetLimits(zmin,zmax);
    } else {
      if (vx.GetNoElements()) { // load utility guarantees the same size for both
	if (yscale  != 1.0) vy *= yscale;
	if (xoffset != 0.0) vx += xoffset;
	if (yoffset != 0.0) vy += yoffset;
	if (asymerrors) 
	  pwg->gr = new TGraphAsymmErrors(vx,vy,exl,exh,eyl,eyh);
	else
	  pwg->gr = new TGraph(vx,vy);
      }
      pwg->gr->UseCurrentStyle();
      pwg->fitfn      =        wg.fitfn;
      pwg->contours   =        wg.contours;
      pwg->drawopt    =        wg.drawopt;
      pwg->legdrawopt =        wg.legdrawopt;
      pwg->gr->SetTitle       (title);
      pwg->xax->SetTitle      (wg.xax->GetTitle());
      pwg->yax->SetTitle      (wg.yax->GetTitle());
      pwg->zax->SetTitle      (wg.zax->GetTitle());
      pwg->xax->SetTitleOffset(wg.xax->GetTitleOffset());
      pwg->yax->SetTitleOffset(wg.yax->GetTitleOffset());
      pwg->zax->SetTitleOffset(wg.zax->GetTitleOffset());
      pwg->xax->SetNdivisions (wg.xax->GetNdivisions());
      pwg->yax->SetNdivisions (wg.yax->GetNdivisions());
      pwg->zax->SetNdivisions (wg.zax->GetNdivisions());
      pwg->gr->SetLineStyle   (wg.lstyle);
      pwg->gr->SetLineColor   (wg.lcolor);
      pwg->gr->SetLineWidth   (wg.lwidth);
      pwg->gr->SetMarkerColor (wg.mcolor);
      pwg->gr->SetMarkerStyle (wg.mstyle);
      pwg->gr->SetMarkerSize  (wg.msize);
      pwg->gr->SetFillStyle   (wg.fstyle);
      pwg->gr->SetFillColor   (wg.fcolor);

      if (xmax>xmin) pwg->xax->SetLimits(xmin,xmax);
      if (ymax>ymin) pwg->yax->SetLimits(ymin,ymax);

      glmap_id2graph.insert(pair<string,wGraph_t *>(gidi,pwg));

      if (printvecs) printVectorsToFile(pwg); // ,value);
    }
  }

  return (v_graphs.size());
}                                                 // processGraphSection