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

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;
v.push_back(child_ad1);
v.push_back(child_ad2);
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