Re: checking result of SetBranchAddress

From: Alexander Mann <amann_at_uni-goettingen.de>
Date: Fri, 11 Sep 2009 17:03:13 +0200


Hi Philippe,

thanks for your efforts.

> We will update SetBranchAddress to return a status code.

That would be very useful indeed.

> However, I can not reproduce your example where the address does not
> change upon a successful call to SetBranchAddress. Could you send
> a complete running example?

The log output I included in one of my mails was produced by adding some debug lines to SCycleBaseNTuple.icc, which is part of the SFrame framework I'm using. The part of code affected is attached, for illustrational purposes.

cu,
Alexander

template< typename T >
bool SCycleBaseNTuple::ConnectVariable( const char* treeName, const char* branchName,

                                        T& variable ) throw ( SError ) {

   m_logger << VERBOSE << "ConnectVariable( treeName = \"" << treeName
            << "\", branchName = \"" << branchName << "\") called" << SLogger::endmsg;

   // Access the TTree. The function will throw an exception if unsuccessful    TTree* tree = GetTree( treeName );
   TBranch* br = 0;

   // Check if the branch actually exists:    if( ! tree->GetBranch( branchName ) ) {

      m_logger << ERROR << "Branch \"" << branchName << "\" doesn't exist in TTree \""
               << treeName << "\"" << SLogger::endmsg;
      return false;

   }
   //
   // Detect what kind of variable we're dealing with:
   //

   const char* type_name = typeid( variable ).name();    printf("--> %s before %p\n", branchName, tree->GetBranch(branchName)); // <------------ DEBUG    if( strlen( type_name ) == 1 ) {
      // For primitive types nothing fancy needs to be done
      m_logger << VERBOSE << "The supplied variable is a \"primitive\""
               << SLogger::endmsg;
      tree->SetBranchAddress( branchName, &variable, &br );

   } else {

      // The object pointers have to be initialised to zero before
      // connecting them to the branches
      m_logger << VERBOSE << "The supplied variable is an object pointer"
               << SLogger::endmsg;
      variable = 0;
      tree->SetBranchAddress( branchName, &variable, &br );

   }
   printf("--> now is %p\n", tree->GetBranch(branchName));                  //    <------------ DEBUG
   if (tree->GetBranch(branchName) == 0) { // does not work like this...
     // SetBranchAddress was not successful       (85)
     m_logger << ERROR << "SetBranchAddress has not been successful" << SLogger::endmsg;
     return false;

   }    

   this->RegisterInputBranch( br );
   m_logger << DEBUG << "Connected branch \"" << branchName << "\" in tree \""

            << treeName << "\"" << SLogger::endmsg;

   return true;

} Received on Fri Sep 11 2009 - 17:03:22 CEST

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