Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions core/base/inc/TROOT.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ namespace ROOT {
void EnableObjectAutoRegistration();
void DisableObjectAutoRegistration();
bool ObjectAutoRegistrationEnabled();
void SetObjectAutoRegistrationDefault(bool enabled);
} // namespace Experimental
}

Expand Down
59 changes: 43 additions & 16 deletions core/base/src/TROOT.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -295,24 +295,29 @@ namespace {
return moduleHeaderInfoBuffer;
}

/// State helper for object auto registration.
enum class AutoReg : unsigned char {
kNotInitialised = 0,
kOn,
kOff,
};

////////////////////////////////////////////////////////////////////////////////
/// \brief Test if various objects (such as TH1-derived classes) should automatically register
/// themselves (ROOT 6 mode) or not (ROOT 7 mode).
/// A default can be set in a .rootrc using e.g. "Root.ObjectAutoRegistration: 1" or setting
/// the environment variable "ROOT_OBJECT_AUTO_REGISTRATION=0".
AutoReg &ObjectAutoRegistrationEnabledImpl()
/// Set or read the default state for object auto registration. This state is used to initialise the
/// auto-registration state for each thread that starts.
AutoReg ObjectAutoRegistrationDefault(AutoReg defaultState)
{
static constexpr auto rcName = "Root.ObjectAutoRegistration"; // Update the docs if this is changed
static constexpr auto envName = "ROOT_OBJECT_AUTO_REGISTRATION"; // Update the docs if this is changed
thread_local static AutoReg tlsState = AutoReg::kNotInitialised;
static std::atomic<AutoReg> defaultFromAPI = AutoReg::kNotInitialised;

static const AutoReg defaultState = []() {
if (defaultState != AutoReg::kNotInitialised) {
defaultFromAPI = defaultState;
}
if (const auto apiDefault = defaultFromAPI.load(); apiDefault != AutoReg::kNotInitialised) {
return apiDefault;
}

static const AutoReg defaultFromEnvironment = []() {
AutoReg autoReg = AutoReg::kOn; // ROOT 6 default
std::stringstream infoMessage;

Expand Down Expand Up @@ -356,10 +361,18 @@ namespace {
return autoReg;
}();

if (tlsState == AutoReg::kNotInitialised) {
assert(defaultState != AutoReg::kNotInitialised);
tlsState = defaultState;
}
return defaultFromEnvironment;
}

////////////////////////////////////////////////////////////////////////////////
/// \brief Test if various objects (such as TH1-derived classes) should automatically register
/// themselves (ROOT 6 mode) or not (ROOT 7 mode).
/// A default can be set in a .rootrc using e.g. "Root.ObjectAutoRegistration: 1" or setting
/// the environment variable "ROOT_OBJECT_AUTO_REGISTRATION=0".
AutoReg &ObjectAutoRegistrationEnabledImpl()
{
thread_local static AutoReg tlsState = ObjectAutoRegistrationDefault(AutoReg::kNotInitialised);
assert(tlsState != AutoReg::kNotInitialised);

return tlsState;
}
Expand Down Expand Up @@ -733,10 +746,14 @@ namespace Internal {
///
/// ## Setting defaults
///
/// A default can be set in a .rootrc using e.g. `Root.ObjectAutoRegistration: 1` or setting
/// the environment variable `ROOT_OBJECT_AUTO_REGISTRATION=0`. Note that this default affects
/// all the threads that get started.
/// When a default is set using one of these methods, ROOT will notify with an Info message.
/// A default can be set (in order of precedence):
/// 1. Using \ref SetObjectAutoRegistrationDefault().
/// 2. Setting the environment variable `ROOT_OBJECT_AUTO_REGISTRATION=[01]`
/// 3. Setting `Root.ObjectAutoRegistration: [01]` in a .rootrc file.
///
/// Note that this default affects all the threads that get started, but a running thread's behaviour
/// can only be changed using Enable/DisableObjectAutoRegistration().
/// When the default state is changed using the environment or .rootrc, ROOT issues a reminder.
///
/// ## Difference to TH1::AddDirectoryStatus()
///
Expand Down Expand Up @@ -765,6 +782,16 @@ namespace Internal {
assert(state != AutoReg::kNotInitialised);
return state == AutoReg::kOn;
}

////////////////////////////////////////////////////////////////////////////////
/// Set default for object auto registration when a thread starts up.
/// Threads that are already running are *not* affected by this call, including
/// the calling thread.
/// \copydetails ROOT::Experimental::EnableObjectAutoRegistration()
void SetObjectAutoRegistrationDefault(bool enabled)
{
ObjectAutoRegistrationDefault(enabled ? AutoReg::kOn : AutoReg::kOff);
}
} // namespace Experimental
} // end of ROOT namespace

Expand Down
21 changes: 20 additions & 1 deletion core/base/test/TROOTTests.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,26 @@ TEST(TROOT, AutoRegistrationTLS)
EnableObjectAutoRegistration();
EXPECT_EQ(ObjectAutoRegistrationEnabled(), true);

for (auto thread : {&t1, &t2, &t3, &t4}) {
const bool stateBeforeJoin = ObjectAutoRegistrationEnabled();

for (auto *thread : {&t1, &t2, &t3, &t4}) {
thread->join();
}

auto testAPIDefault = [](bool expectedState){
EXPECT_EQ(ObjectAutoRegistrationEnabled(), expectedState);
};
SetObjectAutoRegistrationDefault(true);
std::thread t5{testAPIDefault, true};

EXPECT_EQ(ObjectAutoRegistrationEnabled(), stateBeforeJoin);

t5.join();

SetObjectAutoRegistrationDefault(false);
std::thread t6{testAPIDefault, false};

EXPECT_EQ(ObjectAutoRegistrationEnabled(), stateBeforeJoin);

t6.join();
}
2 changes: 1 addition & 1 deletion math/mlp/inc/TMultiLayerPerceptron.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
#include "TObject.h"
#include "TString.h"
#include "TObjArray.h"
#include "TMatrixD.h"
#include "TNeuron.h"
#include "TMatrixDfwd.h"

class TTree;
class TEventList;
Expand Down
2 changes: 2 additions & 0 deletions math/mlp/src/TMLPAnalyzer.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,8 @@ void TMLPAnalyzer::DrawNetwork(Int_t neuron, const char* signal, const char* bg)
// build event lists for signal and background
TEventList* signal_list = new TEventList("__tmpSig_MLPA");
TEventList* bg_list = new TEventList("__tmpBkg_MLPA");
signal_list->SetDirectory(gDirectory);
bg_list->SetDirectory(gDirectory);
data->Draw(">>__tmpSig_MLPA",signal,"goff");
data->Draw(">>__tmpBkg_MLPA",bg,"goff");

Expand Down
23 changes: 18 additions & 5 deletions math/mlp/src/TMultiLayerPerceptron.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ neurons, hidden layers and inputs/outputs that does not apply to TMultiLayerPerc
#include "TH2.h"
#include "TGraph.h"
#include "TLegend.h"
#include "TMatrixD.h"
#include "TMultiGraph.h"
#include "TDirectory.h"
#include "TSystem.h"
Expand Down Expand Up @@ -458,12 +459,12 @@ TMultiLayerPerceptron::TMultiLayerPerceptron(const char * layout, TTree * data,
fCurrentTree = -1;
fCurrentTreeWeight = 1;
{
TDirectory::TContext ctxt;
TDirectory::TContext ctxt{nullptr};
fTraining = new TEventList(Form("fTrainingList_%zu",(size_t)this));
}
fTrainingOwner = true;
{
TDirectory::TContext ctxt;
TDirectory::TContext ctxt{nullptr};
fTest = new TEventList(Form("fTestList_%zu",(size_t)this));
}
fTestOwner = true;
Expand All @@ -478,8 +479,12 @@ TMultiLayerPerceptron::TMultiLayerPerceptron(const char * layout, TTree * data,
fManager = nullptr;
if (data) {
BuildNetwork();
fTraining->SetDirectory(gDirectory);
fTest->SetDirectory(gDirectory);
data->Draw(Form(">>fTrainingList_%zu",(size_t)this),training,"goff");
data->Draw(Form(">>fTestList_%zu",(size_t)this),(const char *)testcut,"goff");
fTraining->SetDirectory(nullptr);
fTest->SetDirectory(nullptr);
AttachData();
}
else {
Expand Down Expand Up @@ -537,12 +542,12 @@ TMultiLayerPerceptron::TMultiLayerPerceptron(const char * layout,
fCurrentTree = -1;
fCurrentTreeWeight = 1;
{
TDirectory::TContext ctxt;
TDirectory::TContext ctxt{nullptr};
fTraining = new TEventList(Form("fTrainingList_%zu",(size_t)this));
}
fTrainingOwner = true;
{
TDirectory::TContext ctxt;
TDirectory::TContext ctxt{nullptr};
fTest = new TEventList(Form("fTestList_%zu",(size_t)this));
}
fTestOwner = true;
Expand All @@ -557,8 +562,12 @@ TMultiLayerPerceptron::TMultiLayerPerceptron(const char * layout,
fManager = nullptr;
if (data) {
BuildNetwork();
fTraining->SetDirectory(gDirectory);
fTest->SetDirectory(gDirectory);
data->Draw(Form(">>fTrainingList_%zu",(size_t)this),training,"goff");
data->Draw(Form(">>fTestList_%zu",(size_t)this),(const char *)testcut,"goff");
fTraining->SetDirectory(nullptr);
fTest->SetDirectory(nullptr);
AttachData();
}
else {
Expand Down Expand Up @@ -645,12 +654,14 @@ void TMultiLayerPerceptron::SetTrainingDataSet(const char * train)
{
if(fTraining && fTrainingOwner) delete fTraining;
{
TDirectory::TContext ctxt;
TDirectory::TContext ctxt{nullptr};
fTraining = new TEventList(Form("fTrainingList_%zu",(size_t)this));
}
fTrainingOwner = true;
if (fData) {
fTraining->SetDirectory(gDirectory);
fData->Draw(Form(">>fTrainingList_%zu",(size_t)this),train,"goff");
fTraining->SetDirectory(nullptr);
}
else {
Warning("TMultiLayerPerceptron::TMultiLayerPerceptron","Data not set. Cannot define datasets");
Expand All @@ -672,7 +683,9 @@ void TMultiLayerPerceptron::SetTestDataSet(const char * test)
}
fTestOwner = true;
if (fData) {
fTraining->SetDirectory(gDirectory);
fData->Draw(Form(">>fTestList_%zu",(size_t)this),test,"goff");
fTraining->SetDirectory(nullptr);
}
else {
Warning("TMultiLayerPerceptron::TMultiLayerPerceptron","Data not set. Cannot define datasets");
Expand Down
19 changes: 3 additions & 16 deletions roottest/root/tree/cache/variableCluster.C
Original file line number Diff line number Diff line change
Expand Up @@ -220,26 +220,13 @@ Long64_t checkBoundary(TTree *tree, Long64_t entry)
TTree::TClusterIterator clusterIter = tree->GetClusterIterator(entry);
fEntryCurrent = clusterIter();
fEntryNext = clusterIter.GetNextEntry();

// fprintf(stdout,"finds = %lld %lld\n",fEntryCurrent,fEntryNext);

if (fEntryCurrent < fEntryMin) fEntryCurrent = fEntryMin;
if (fEntryMax <= 0) fEntryMax = tree->GetEntries();
if (fEntryNext > fEntryMax) fEntryNext = fEntryMax;

// Check if owner has a TEventList set. If yes we optimize for this
// Special case reading only the baskets containing entries in the
// list.
// TEventList *elist = fOwner->GetEventList();
// Long64_t chainOffset = 0;
// if (elist) {
// if (fOwner->IsA() ==TChain::Class()) {
// TChain *chain = (TChain*)fOwner;
// Int_t t = chain->GetTreeNumber();
// chainOffset = chain->GetTreeOffset()[t];
// }
// }


Int_t flushIntervals = 0;
Long64_t minEntry = fEntryCurrent;
Long64_t prevNtot;
Expand Down
1 change: 0 additions & 1 deletion tmva/tmva/src/Classification.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
#include <TKey.h>
#include <TLeaf.h>
#include <TBranch.h>
#include <TEventList.h>
#include <TGraph.h>
#include <TMatrixF.h>
#include <TMatrixDSym.h>
Expand Down
3 changes: 0 additions & 3 deletions tmva/tmva/src/DataInputHandler.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,9 @@ Class that contains all the data information.
#include "TMVA/DataLoader.h"
#include "TMVA/MsgLogger.h"
#include "TMVA/Types.h"
#include "TEventList.h"
#include "TCut.h"
#include "TTree.h"

#include "TMVA/Configurable.h"

#include <vector>
#include <fstream>

Expand Down
9 changes: 0 additions & 9 deletions tmva/tmva/src/DataSetFactory.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -41,26 +41,17 @@ Class that contains all the data information
#include <iostream>

#include <algorithm>
#include <functional>
#include <numeric>
#include <random>

#include "TMVA/DataSetFactory.h"

#include "TEventList.h"
#include "TFile.h"
#include "TRandom3.h"
#include "TMatrixF.h"
#include "TVectorF.h"
#include "TMath.h"
#include "TTree.h"
#include "TBranch.h"

#include "TMVA/MsgLogger.h"
#include "TMVA/Configurable.h"
#include "TMVA/VariableIdentityTransform.h"
#include "TMVA/VariableDecorrTransform.h"
#include "TMVA/VariablePCATransform.h"
#include "TMVA/DataSet.h"
#include "TMVA/DataSetInfo.h"
#include "TMVA/DataInputHandler.h"
Expand Down
8 changes: 2 additions & 6 deletions tmva/tmva/src/DataSetInfo.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,8 @@ Class that contains all the data information.

*/

#include <vector>

#include "TEventList.h"
#include "TH2.h"
#include "TRandom3.h"
#include "TMatrixF.h"
#include "TVectorF.h"
#include "TROOT.h"

#include "TMVA/MsgLogger.h"
#include "TMVA/Tools.h"
Expand All @@ -50,6 +44,8 @@ Class that contains all the data information.
#include "TMVA/Types.h"
#include "TMVA/VariableInfo.h"

#include <vector>

////////////////////////////////////////////////////////////////////////////////
/// constructor

Expand Down
13 changes: 5 additions & 8 deletions tmva/tmva/src/Factory.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -71,26 +71,23 @@ evaluation phases.
#include "TMVA/ResultsClassification.h"
#include "TMVA/ResultsRegression.h"
#include "TMVA/ResultsMulticlass.h"
#include <list>
#include <bitset>
#include <set>

#include "TMVA/Types.h"

#include "TROOT.h"
#include "TFile.h"
#include "TLeaf.h"
#include "TEventList.h"
#include "TH2.h"
#include "TGraph.h"
#include "TStyle.h"
#include "TMatrixF.h"
#include "TMatrixDSym.h"
#include "TMultiGraph.h"
#include "TPrincipal.h"
#include "TMath.h"
#include "TSystem.h"
#include "TCanvas.h"
#include "TMultiGraph.h"

#include <bitset>
#include <list>
#include <set>

const Int_t MinNoTrainingEvents = 10;
// const Int_t MinNoTestEvents = 1;
Expand Down
3 changes: 0 additions & 3 deletions tmva/tmva/src/MethodTMlpANN.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ for details on this ANN.
#include "TMVA/MethodTMlpANN.h"

#include "TMVA/Config.h"
#include "TMVA/Configurable.h"
#include "TMVA/DataSet.h"
#include "TMVA/DataSetInfo.h"
#include "TMVA/IMethod.h"
Expand All @@ -58,8 +57,6 @@ for details on this ANN.
#include "TMVA/ClassifierFactory.h"
#include "TMVA/Tools.h"

#include "TLeaf.h"
#include "TEventList.h"
#include "TROOT.h"
#include "TMultiLayerPerceptron.h"
#include "ThreadLocalStorage.h"
Expand Down
Loading
Loading