Re: checking result of SetBranchAddress

From: Philippe Canal <pcanal_at_fnal.gov>
Date: Fri, 11 Sep 2009 10:59:34 -0500


Hi Alexander,

 > Yes, that's correct, but unfortunately, cannot be used:

Right :( ... after cross-checking, the error message does not leave _any_ trace in the branch; i.e. the addressing setting is done either way; this was needed for backward compatibility reasons.

However what you can do in your routine is the following:

     TClass *varclass = TClass::GetClass( typeid(T) );
     if ( !varclass) {
         cerr << "ROOT Does not known about: " << typeid(T).name() << endl;
     } else if ( 0!=strcmp(varclass->GetName(), tree->GetBranch( 
branchName )->GetClassName()) {
         cerr << "The branch " << branchName << " expects " << 
tree->GetBranch( branchName )->GetClassName() << endl;
         cerr << "but we got " << varclass->GetName() << endl;
     } else {
         // All is good.
     }

This test is stricter than necessary but should work well enough. The other alternative is to wait until I update the source with the return value
or to catch the error message using a custom error message handler ...

Cheers,
Philippe.

Alexander Mann wrote:
> Hi Philippe,
>
> > I expect:
> > GetAddress() == &variable
>
> Yes, that's correct, but unfortunately, cannot be used:
>
> --> StacoMuon_nucone20 before (nil)
> --> var before is 0x91a397c
> --> now is 0x91a397c
> --> var is 0x91a397c
>
> --> StacoMuon_bestMatch before (nil)
> --> var before is 0x91a3980
> Error in <TTree::SetBranchAddress>: The pointer type give
> (vector<bool>) does not correspond to the class needed (vector<int>)
> by the branch: StacoMuon_bestMatch
> --> now is 0x91a3980
> --> var is 0x91a3980
>
> My code:
> printf("--> now is %p\n", tree->GetBranch(branchName)->GetAddress());
> printf("--> var is %p\n", &variable);
>
> cu,
> Alexander
>
>
> Philippe Canal schrieb:
>> Hi Alexander,
>>
>> With
>>
>> tree->SetBranchAddress( branchName, &variable, &br );
>>
>> I expect:
>> GetAddress() == &variable
>>
>> Cheers,
>> Philippe.
>>
>> Alexander Mann wrote:
>>> Hi Philippe,
>>>
>>> (offline question)
>>>
>>> sorry, which value that I pass do you mean?
>>>
>>> cu,
>>> Alexander
>>>
>>>
>>> Philippe Canal schrieb:
>>>> Hi Alexander,
>>>>
>>>> How does the new values compare to the one you passed?
>>>>
>>>> Cheers,
>>>> Philippe
>>>>
>>>> Alexander Mann wrote:
>>>>> Hi Philippe,
>>>>>
>>>>>> The example you sent prints the location of the branch object itself
>>>>>> and __not__ the location of the user object the branch will use to
>>>>>> fill in or read from the TTree. The location of the branch object
>>>>>> is,
>>>>>> of course, not affected by the call to SetBranchAddres.
>>>>>
>>>>> OK, that makes sense. (So SetBranchAddress does not set the
>>>>> address of the branch as one might deduce from its name :)
>>>>>
>>>>> The problem however remains, as on a failure of SetBranchAddress the
>>>>> pointer is modified, too:
>>>>>
>>>>> --> StacoMuon_nucone20 before (nil)
>>>>> --> now is 0x8e2797c
>>>>>
>>>>> --> StacoMuon_bestMatch before (nil)
>>>>> Error in <TTree::SetBranchAddress>: The pointer type give
>>>>> (vector<bool>)
>>>>> does not correspond to the class needed (vector<int>) by the branch:
>>>>> StacoMuon_bestMatch
>>>>> --> now is 0x8e27980
>>>>>
>>>>> cu,
>>>>> Alexander
>>>>>
>>>
>
Received on Fri Sep 11 2009 - 17:59:54 CEST

This archive was generated by hypermail 2.2.0 : Fri Sep 11 2009 - 23:50:02 CEST