Saturday, April 19, 2008

connect to fnal from SLC4 laptop

kinit -A -f user@FNAL.GOV
ssh -2 -Y user@cmslpc.fnal.gov

Wednesday, April 09, 2008

convert std::iterator to int index

#include <vector> ;
#include <algorithm> ;

std::vector<double> a;
a.push_back(3.); a.push_back(5.); a.push_back(9.);
std::vector::iterator it = std::find(a.begin(),a.end(),9.);
int index = it - a.begin();

Thursday, April 03, 2008

funny behavior TTree with vectors

while working with CMSSW_1_7_5 I noticed one funny thing.
I am trying to store a vector of double in a tree (created within an analyzer etc.).
The relevant lines are

--------------------------------------------------
TTree *tree_;
std::vector < double > *ptr_vect ;

// assign the pointers to smth valid

tree_->Branch("mybranch","std::vector <double>",&ptr_vect); // opt. 1)

tree_->Branch("mybranch","std::vector < double >",&ptr_vect); // opt. 2)
--------------------------------------------------

The only difference is the whitespaces in the second option.
When I use opt. 1) everything is fine; when I use opt. 2) everything compiles
fine, but then it crashes when it reaches the TTree::Branch line.
I guess the problem is that root doesn't manage properly white spaces when
parsing the option classname in

TTree::Branch(const char* name, const char* classname, void*** addobj, Int_t bufsize = 32000, Int_t splitlevel = 99)

The same code in a standalone app gives the following message,
which is easier to understand than " Generating stack trace..."

$ g++ -o test.exe test.C `root-config --cflags --libs`
$ ./test.exe
Error in : The class requested (vector >double<:) for the branch "branch0" refer to an stl collection and do not have a compiled CollectionProxy. Please generate the dictionary for this class (vector>double<)

two options to force the loading of the dictionary:

// opt 1
#ifdef __MAKECINT__
#pragma link C++ class vector >double< ;
#endif

// opt 2

gROOT->ProcessLine("#include >vector<");