[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [HTCondor-users] Question about the nested ClassAd

That helps 
Many thanks 

From: jfrey@xxxxxxxxxxx
Date: Thu, 20 Mar 2014 16:37:37 -0500
To: htcondor-users@xxxxxxxxxxx
Subject: Re: [HTCondor-users] Question about the nested ClassAd

On Mar 20, 2014, at 3:20 AM, 张章 <zhang_zhang@xxxxxxxx> wrote:

Dear all:
     I have encountered some problems when using the classad library in my application. 
     I need to insert a list of classads into a parent classad, like the following:

     parent classad  
          normal attribute:
          a = 1;

          classad list: 
          b = [ [c = 1, d = 1], [c = 2, d = 2] ...]

     Which data structures and APIs should I use in this case?
     Some ideas:

     ExpressTree et = [ c = 1, d = 1] 
     ExpressList el = [ [c = 1, d = 1], [c = 2, d = 2] ...]

     Then el will be inserted into the parent classad, but I do not know which APIs I should use.

First, let me correct the syntax of your example ad, just to ensure there’s no confusion:
   a = 1;
   b = { [c = 1; d = 1], [c = 2; d = 2] };

I’m assuming you are using the C++ API. There could some minor syntax errors in the code below...

If you have a string representation of the list of nested ads, then you can use the ClassAdParser class to parse that into the appropriate ExprTree*, and insert that into the parent ad:

ClassAd parent_ad;
ClassAdParser parser;
ExprTree *list = parser.ParseExpression(“{ [c = 1; d = 1], [c = 2; d = 2] }”);
parent_ad.Insert( “b”, list );

If you are building up the child ad objects with ClassAd::InsertAttr() calls, and then want to insert them into the parent ad, you can do this:

ClassAd parent_ad;
ClassAd *child_ad1 = ...;
ClassAd *child_ad1 = ...;
std::vector<ExprTree*> v;
ExprTree *list = ExprList::MakeExprList( v );
parent_ad.Insert( “b”, list );

Once you have inserted the list of nested ads in the parent ad, modifying the list by adding or removing ads is not easy, but can be done.

I hope that helps.

Thanks and regards,
Jaime Frey
UW-Madison HTCondor Project

_______________________________________________ HTCondor-users mailing list To unsubscribe, send a message to htcondor-users-request@xxxxxxxxxxx with a subject: Unsubscribe You can also unsubscribe by visiting https://lists.cs.wisc.edu/mailman/listinfo/htcondor-users The archives can be found at: https://lists.cs.wisc.edu/archive/htcondor-users/