Commit ed20297d authored by Stezowski Olivier's avatar Stezowski Olivier
Browse files

modification to have Log classes in one directory

git-svn-id: svn+ssh://anonsvn.in2p3.fr/agata/gammaware/trunk@1772 c3abf467-7ff2-0310-b516-c5fb849bdde0
parent b45579b4
......@@ -48,8 +48,8 @@ ROOTDS := $(subst LinkDef,Dict,$(ROOTDSTMP))
ROOTDO := $(ROOTDS:.$(SrcSuf)=.$(ObjSuf))
# Non-ROOTDICTIONNARY part, sources, includes and objects
# remove LogMessage, LogCollector and CentralLog since they are in the Core library
MODULESOURCES := $(filter-out %Dict.$(SrcSuf) LogMessage.$(SrcSuf) LogCollector.$(SrcSuf) CentralLog.$(SrcSuf),$(wildcard *.$(SrcSuf)))
MODULEINCLUDES := $(MODULESOURCES:.$(SrcSuf)=.h)
MODULEOBJECTS := $(MODULESOURCES:.$(SrcSuf)=.$(ObjSuf))
......
......@@ -100,7 +100,7 @@ install(TARGETS ${GWLIBNAME} RUNTIME DESTINATION bin
ARCHIVE DESTINATION lib
COMPONENT libraries)
#
install(FILES ${headers} DESTINATION include COMPONENT headers )
install(FILES ${headers} DESTINATION ${GW_INCLUDE_DIR} COMPONENT headers )
......
......@@ -3,7 +3,7 @@
#
project (dev)
#
MESSAGE(" + ${PROJECT_NAME}")
MESSAGE("[GW] + ${PROJECT_NAME}")
#
#
set(GWLIBNAME GWDEV)
......@@ -99,7 +99,7 @@ install(TARGETS ${GWLIBNAME} RUNTIME DESTINATION bin
ARCHIVE DESTINATION lib
COMPONENT libraries)
#
install(FILES ${headers} DESTINATION include COMPONENT headers )
install(FILES ${headers} DESTINATION ${GW_INCLUDE_DIR} COMPONENT headers )
......
......@@ -10,8 +10,8 @@ set(GWLIBNAME GWADFE)
#
# internal and external dependencies
#
set( EXTRA_INTERNAL_LIBRARIES GWCORE GWADF)
set( EXTRA_EXTERNAL_LIBRARIES Core Cint Graf MathCore Gpad Hist Tree RIO )
set( EXTRA_INTERNAL_LIBRARIES GWCORE GWADF GWPHYSICS)
set( EXTRA_EXTERNAL_LIBRARIES Core Cint Graf MathCore Gpad Hist Tree RIO Thread)
#
# headers / dictionnary / sources
#
......@@ -104,7 +104,7 @@ install(TARGETS ${GWLIBNAME} RUNTIME DESTINATION bin
ARCHIVE DESTINATION lib
COMPONENT libraries)
#
install(FILES ${headers} DESTINATION include COMPONENT headers )
install(FILES ${headers} DESTINATION ${GW_INCLUDE_DIR} COMPONENT headers )
......
......@@ -13,7 +13,7 @@
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* aLong_t with this program; if not, write to the *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
......
......@@ -134,7 +134,7 @@ public:
//! allocate a new watcher so that it creates corectly its directory under the dispatcher directory
template<typename Watcher_T> Watcher_T * Add(const Char_t *name, const Char_t *title, ADF::DFTrigger *t = 0x0)
{
//set the watcher
//set the watcher. Directories are set in Add
Watcher_T *watcher = new Watcher_T(name,title);
if ( t )
Add( watcher , t );
......@@ -144,7 +144,7 @@ public:
return watcher;
}
//!
//! change directories and Load objects if required
virtual void SetDirectory(TDirectory *mother_dir_of_watcher = gROOT, TDirectory *mother_dir_for_tag = gROOT, Bool_t load_objects = true);
//! add only Watchers to the list of tasks to avoid problems.
......
......@@ -13,7 +13,7 @@
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* aLong_t with this program; if not, write to the *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
......
......@@ -13,7 +13,7 @@
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* aLong_t with this program; if not, write to the *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
......@@ -22,6 +22,9 @@
#include "TTreeWatchers.h"
#include "TTreeFormula.h"
#include "TRegexp.h"
using namespace Gw;
TTreeBuilder::TTreeBuilder(const char *name, const char *title, TTree *tree) :
......@@ -93,13 +96,33 @@ TTreeMaster::~TTreeMaster()
{
}
UInt_t TTreeMaster::Snapshot(Option_t *opt)
{
UInt_t bytes = 0u;
// for all watchers, ask to snap spectra and conditions
TIter loopontask(GetListOfTasks());
TObject *task;
while ( ((task=loopontask())) ) {
Watcher *watcher =
dynamic_cast<Watcher *>(task);
if ( watcher ) {
// to be sure and so that it should not be necessary in watchers
bytes += watcher->Snapshot(opt);
}
}
// add additional snap which is just a Write of the tree
return bytes;
}
void TTreeMaster::Exec(Option_t * option)
{
Short_t nb_ok = 0u, nb_watcher = GetListOfTasks()->GetEntries();
TIter loopontask(GetListOfTasks());
TTask *task;
while ( ((task=(TTask*)loopontask())) ) {
TObject *task;
while ( ((task=loopontask())) ) {
Watcher *watcher =
dynamic_cast<Watcher *>(task);
......@@ -118,3 +141,393 @@ void TTreeMaster::Exec(Option_t * option)
FillTree();
}
ClassImp(TTreeWithConditions);
TTreeWithConditions::TTreeWithConditions(const char *name, const char *title, TTree *tree, Short_t do_spectra, Short_t do_tree) :
Watcher(name,title),
TTreeBuilder(name,title,tree),
fDoSpectra(do_spectra),
fDoTree(do_tree),
fClone(0x0),
fCondHandler(),
fUserGCond(),
fUserTFCond(),
fAllGCond()
{
// clone is always set since it is used for coincidences.
fClone = new TTree(Form("WC_%s_",name),Form("Clone of %s %s",name,title));
if ( fClone ) {
fClone->SetDirectory(0);
fClone->SetCircular(10000);
}
}
TTreeWithConditions::~TTreeWithConditions()
{
//
if ( fClone ) {
delete fClone; fClone = 0x0;
}
// delete all conditions
std::vector< GCondition * >::iterator
listed_item;
for ( listed_item = fAllGCond.begin() ; listed_item != fAllGCond.end() ; listed_item++ ) {
if ( (*listed_item) ) {
delete (*listed_item);
(*listed_item) = 0x0;
}
}
}
UInt_t TTreeWithConditions::Snapshot(Option_t *opt)
{
TString o = opt; Bool_t save_cond = true; UInt_t bytes = 0u; TDirectory *in_dir = gDirectory;
if ( o.Contains("!cond")) {
//
save_cond = false;
//
o.ReplaceAll("!cond","");
}
// save spectra
bytes += Watcher::Snapshot(o.Data());
if ( save_cond ) {
TRegexp rexp(Form("%s",o.Data()),true);
if ( rexp.Status() == TRegexp::kOK ) {
// check first it is not already there ?
std::vector< GCondition * >::iterator
listed_item;
for ( listed_item = fAllGCond.begin() ; listed_item != fAllGCond.end() ; listed_item++ ) {
o = (*listed_item)->GetName();
printf("hh \n");
if ( o.Contains(rexp) && fDirectory && fDirectory->GetDirectory("Conditions") ) {
printf("hhh \n");
// bytes += fDirectory->GetDirectory("Conditions")->WriteTObject((*listed_item));
fDirectory->GetDirectory("Conditions")->cd();
(*listed_item)->Export(opt,"gdir");
}
}
}
in_dir->cd();
}
return bytes;
}
std::pair< GCond1D *, TH1 * > TTreeWithConditions::MakeGCond1D(const Char_t *name_cond, const Char_t *title_cond, const Char_t *name_leaf,
const Char_t *name_hist, const Char_t *title_hist , Int_t bin, Double_t min, Double_t max, Option_t *opt)
{
TString tmp = opt; std::pair < GCond1D *, TH1 * > p; GCondHandler *handler = 0x0; GCond1D *cond = 0x0; TH1 *hist = 0x0;
p.first = 0x0;
p.second = 0x0;
// check first it is not already there ?
std::vector< GCondition * >::iterator
listed_item;
for ( listed_item = fAllGCond.begin() ; listed_item != fAllGCond.end() ; listed_item++ ) {
tmp = (*listed_item)->GetName();
if ( tmp == name_cond ) {
std::cout << "Cannot have two conditions wth the same name " << name_cond << std::cout;
return p;
}
}
// find leaf in the tree
TLeaf *leaf = fClone->GetLeaf(name_leaf);
if ( leaf == 0x0 ) {
// log to be added
return p;
}
// Associated histogram
tmp = opt;
if ( tmp.Contains("C") )
{
hist = new TH1C(name_hist,title_hist,bin,min,max);
}
else if ( tmp.Contains("S") )
{
hist = new TH1S(name_hist,title_hist,bin,min,max);
}
else if ( tmp.Contains("I") )
{
hist = new TH1I(name_hist,title_hist,bin,min,max);
}
else if ( tmp.Contains("F") )
{
hist = new TH1F(name_hist,title_hist,bin,min,max);
}
else if ( tmp.Contains("D") )
{
hist = new TH1D(name_hist,title_hist,bin,min,max);
}
else if ( tmp.Contains("P") )
{
// hist = new TProfile(name_hist,title_hist,bin,min,max);
}
cond = new GCond1D(name_cond,title_cond);
if ( cond == 0x0 || hist == 0x0) {
if ( cond ) {
delete cond;
}
if ( hist ) {
delete hist;
}
return p;
}
else {
AddToPool(hist);
cond->SetVarName(name_leaf,"X");
// Add condition to the watcher directory
if ( GetDirectory() )
GetDirectory()->Add(cond);
handler = new SimpleGCondHandler1D( cond, leaf, hist );
fCondHandler.push_back(handler);
fAllGCond.push_back(cond);
}
p.first = cond; p.second = hist; return p;
}
std::pair< GCond2D *, TH1 * > TTreeWithConditions::MakeGCond2D(const Char_t *name_cond, const Char_t *title_cond, const Char_t *name_leaf,
const Char_t *name_hist, const Char_t *title_hist , Int_t binx, Double_t xmin, Double_t xmax, Int_t biny, Double_t ymin, Double_t ymax, Option_t *opt)
{
TString tmp = opt, tmp_leaf(name_leaf); std::pair < GCond2D *, TH1 * > p; GCond2D *cond = 0x0; GCondHandler *handler = 0x0; TH1 *hist = 0x0;
//
p.first = 0x0;
p.second = 0x0;
// check first it is not already there ?
std::vector< GCondition * >::iterator
listed_item;
for ( listed_item = fAllGCond.begin() ; listed_item != fAllGCond.end() ; listed_item++ ) {
tmp = (*listed_item)->GetName();
if ( tmp == name_cond ) {
std::cout << "Cannot have two conditions wth the same name " << name_cond << std::cout;
return p;
}
}
TObjArray *name_leaves = tmp_leaf.Tokenize(":");
if ( name_leaves == 0x0 || name_leaves->GetEntries() != 2 ) {
// log to be added
printf("Cannot get leafes from %s \n",name_leaf);
return p;
}
// find leaf in the tree
TLeaf *leaf1 = fClone->GetLeaf( name_leaves->At(0)->GetName() ), *leaf2 = fClone->GetLeaf( name_leaves->At(1)->GetName() );
delete name_leaves;
if ( leaf1 == 0x0 || leaf2 == 0x0 ) {
// log to be added
printf("Cannot find leafes \n");
return p;
}
// Associated histogram
tmp = opt;
if ( tmp.Contains("C") )
{
hist = new TH2C(name_hist,title_hist,binx,xmin,xmax,biny,ymin,ymax);
}
else if ( tmp.Contains("S") )
{
hist = new TH2S(name_hist,title_hist,binx,xmin,xmax,biny,ymin,ymax);
}
else if ( tmp.Contains("I") )
{
hist = new TH2I(name_hist,title_hist,binx,xmin,xmax,biny,ymin,ymax);
}
else if ( tmp.Contains("F") )
{
hist = new TH2F(name_hist,title_hist,binx,xmin,xmax,biny,ymin,ymax);
}
else if ( tmp.Contains("D") )
{
hist = new TH2D(name_hist,title_hist,binx,xmin,xmax,biny,ymin,ymax);
}
else if ( tmp.Contains("P") )
{
// hist = new TProfile(name_hist,title_hist,bin,min,max);
}
cond = new GCond2D(name_cond,title_cond);
if ( cond == 0x0 || hist == 0x0 ) {
if ( cond ) {
delete cond;
}
if ( hist ) {
delete hist;
}
return p;
}
else {
AddToPool(hist);
cond->SetVarName(leaf1->GetName(),"X"); cond->SetVarName(leaf2->GetName(),"Y");
// Add condition to the watcher directory
if ( GetDirectory() )
GetDirectory()->Add(cond);
//
handler = new SimpleGCondHandler2D( cond, leaf1, leaf2, hist );
//
fCondHandler.push_back(handler);
fAllGCond.push_back(cond);
}
p.first = cond; p.second = hist; return p;
}
GCond1D * TTreeWithConditions::MakeGCond1D(const Char_t *name_cond, const Char_t *title_cond)
{
GCond1D *cond = 0x0;
// check first it is not already there ?
std::vector< GCondition * >::iterator
listed_item;
for ( listed_item = fAllGCond.begin() ; listed_item != fAllGCond.end() ; listed_item++ ) {
TString tmp = (*listed_item)->GetName();
if ( tmp == name_cond ) {
std::cout << "Cannot have two conditions wth the same name " << name_cond << std::cout;
return cond;
}
}
cond = new GCond1D(name_cond,title_cond);
if ( cond ) {
fUserGCond.push_back(cond); fAllGCond.push_back(cond);
}
return cond;
}
GCond2D * TTreeWithConditions::MakeGCond2D(const Char_t *name_cond, const Char_t *title_cond)
{
GCond2D *cond = 0x0;
// check first it is not already there ?
std::vector< GCondition * >::iterator
listed_item;
for ( listed_item = fAllGCond.begin() ; listed_item != fAllGCond.end() ; listed_item++ ) {
TString tmp = (*listed_item)->GetName();
if ( tmp == name_cond ) {
std::cout << "Cannot have two conditions wth the same name " << name_cond << std::cout;
return cond;
}
}
cond = new GCond2D(name_cond,title_cond);
if ( cond ) {
fUserGCond.push_back(cond); fAllGCond.push_back(cond);
}
return cond;
}
void TTreeWithConditions::SetDirectory(TDirectory *mother_dir_of_watcher, TDirectory *mother_dir_tag, Bool_t load_objects)
{
// apply modifications of the directtory first for spectra & tagged spectra
Watcher::SetDirectory(mother_dir_of_watcher,mother_dir_tag,load_objects);
//! keep current dir in which are the conditions
TDirectory *old_cond_dir = GetDirectory()->GetDirectory("Conditions"), *new_cond_dir, *curent_dir = gDirectory;
// add also conditions to the watcher diectory
new_cond_dir = GetDirectory()->GetDirectory("Conditions");
if ( new_cond_dir == 0x0 )
new_cond_dir = GetDirectory()->mkdir("Conditions");
new_cond_dir->cd();
std::vector< GCondition * >::iterator
listed_item;
for ( listed_item = fAllGCond.begin() ; listed_item != fAllGCond.end() ; listed_item++ ) {
//
GCondition *cond = (*listed_item);
//
if ( old_cond_dir )
old_cond_dir->Remove(cond);
if ( new_cond_dir )
new_cond_dir->Add(cond);
//
if ( load_objects )
cond->Import("*","gdir","+");
//
}
if ( curent_dir )
curent_dir->cd();
}
Int_t TTreeWithConditions::CheckCondByHandler()
{
Int_t nb = 0;
std::list< GCondHandler * >::iterator
listed_item;
for ( listed_item = fCondHandler.begin() ; listed_item != fCondHandler.end() ; listed_item++ ) {
(*listed_item)->Fill();
if ( (*listed_item)->Check() )
nb++;
}
/*
std::vector< TTreeFormula * >::iterator
listed_formula;
for ( listed_formula = fUserTFCond.begin() ; listed_formula != fUserTFCond.end() ; listed_formula++ ) {
if ( (*listed_formula)->EvalInstance() )
nb++;
}
*/
return nb;
}
Int_t TTreeWithConditions::CheckTreeFormula()
{
Int_t nb = 0;
std::vector< TTreeFormula * >::iterator
listed_formula;
for ( listed_formula = fUserTFCond.begin() ; listed_formula != fUserTFCond.end() ; listed_formula++ ) {
if ( (*listed_formula)->EvalInstance() )
nb++;
}
return nb;
}
/*
void TTreeWithConditions::FillSpectraByHandler()
{
std::list< GCondHandler * >::iterator
listed_item;
for ( listed_item = fCondHandler.begin() ; listed_item != fCondHandler.end() ; listed_item++ ) {
(*listed_item)->Fill();
}
}
*/
Int_t TTreeWithConditions::AddTreeFormula(const Char_t *name, const Char_t *expression)
{
/*
TTreeFormula *nf = new TTreeFormula(name,expression,fClone);
if ( nf->GetTree() ) { // test if it is a good expression ... should log
fUserTFCond.push_back(nf);
}
return fUserTFCond.size();
*/
return 0;
}
......@@ -13,7 +13,7 @@
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* aLong_t with this program; if not, write to the *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
......@@ -24,7 +24,12 @@
#define Gw_TTreeWatchers
#include "Watchers.h"
#include "GCondition.h"
#include "TTree.h"
#include "TH1.h"
#include "TH2.h"
#include "TLeaf.h"
namespace Gw
{
......@@ -74,7 +79,19 @@ protected:
public:
TTreeMaster(const char *name, const char *title);
virtual ~TTreeMaster();
//! Save all histograms belonging to this watcher. Should be overloaded in case of spectra not registered in pool
/*!
if option contains !tag, tagged spectra are not saved.
if option contains *, all spectra are saved, otherwise assume wildcard
Ex:
- * !tag
- *_E
- *_E !tag
*/
virtual UInt_t Snapshot(Option_t * = "*");
//! allocate a new watcher so that it creates corectly its directory under the dispatcher directory
template<typename Watcher_T> Watcher_T * Add(const Char_t *name, const Char_t *title)
{
......@@ -104,6 +121,196 @@ public:
ClassDef(TTreeMaster,0) // Watcher that owns the tree and call Fill
};
//! To handle a simple branch
class SimpleGCondHandler1D : public GCondHandler
{
private:
TLeaf *fData;
private:
TH1 *fHisto;
public:
SimpleGCondHandler1D(GCondition *cond, TLeaf *data, TH1 *h) : GCondHandler(cond), fData(data), fHisto(h)
{;}
virtual ~SimpleGCondHandler1D()
{;}