Skip to content

Commit 3b6caf4

Browse files
committed
Add new test root-project#29 testing trees in sub-dirs
Address the use case reported on the forum (http://root.cern.ch/phpBB3/viewtopic.php?f=13&t=17605)
1 parent abb32d2 commit 3b6caf4

File tree

5 files changed

+221
-44
lines changed

5 files changed

+221
-44
lines changed

test/stressProof.cxx

Lines changed: 132 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
// * Test 26 : Handling output via file ......................... OK * * //
6565
// * Test 27 : Simple: selector by object ....................... OK * * //
6666
// * Test 28 : H1 dataset: selector by object ................... OK * * //
67+
// * Test 29 : Chain with TTree in subdirs ...................... OK * * //
6768
// * * All registered tests have been passed :-) * * //
6869
// * ****************************************************************** * //
6970
// * * //
@@ -133,7 +134,7 @@
133134

134135
#include "proof/getProof.C"
135136

136-
#define PT_NUMTEST 28
137+
#define PT_NUMTEST 29
137138

138139
static const char *urldef = "proof://localhost:40000";
139140
static TString gtutdir;
@@ -249,7 +250,7 @@ int main(int argc,const char *argv[])
249250
printf(" in case of error.\n");
250251
printf(" -k,-keeplog keep all logfiles, including the ones from the PROOF nodes (in one single file)\n");
251252
printf(" The paths are printed on the screen.\n");
252-
printf(" -catlog prints all the logfiles (also the ones from PROOF nodes) on stdout; useful for");
253+
printf(" -catlog prints all the logfiles (also the ones from PROOF nodes) on stdout; useful for\n");
253254
printf(" presenting a single aggregated output for automatic tests. If specified in\n");
254255
printf(" conjunction with -cleanlog it will only print the logfiles in case of errors\n");
255256
printf(" -dyn run the test in dynamicStartup mode\n");
@@ -619,7 +620,8 @@ Double_t ProofTest::gRefReal[PT_NUMTEST] = {
619620
0.259239, // #25: TTree friends, same file
620621
6.868858, // #26: Simple generation: merge-via-file
621622
6.362017, // #27: Simple random number generation by TSelector object
622-
5.519631 // #28: H1: by-object processing
623+
5.519631, // #28: H1: by-object processing
624+
7.452465 // #29: Chain with TTree in subdirs
623625
};
624626

625627
//
@@ -750,6 +752,7 @@ Int_t PT_EventRange(void *, RunTimes &);
750752
Int_t PT_POFNtuple(void *, RunTimes &);
751753
Int_t PT_POFDataset(void *, RunTimes &);
752754
Int_t PT_Friends(void *, RunTimes &);
755+
Int_t PT_TreeSubDirs(void *, RunTimes &);
753756
Int_t PT_SimpleByObj(void *, RunTimes &);
754757
Int_t PT_H1ChainByObj(void *, RunTimes &);
755758
Int_t PT_AssertTutorialDir(const char *tutdir);
@@ -1066,6 +1069,8 @@ int stressProof(const char *url, const char *tests, Int_t nwrks,
10661069
testList->Add(new ProofTest("Simple: selector by object", 27, &PT_SimpleByObj, 0, "1", "ProofSimple", kTRUE));
10671070
// H1 analysis over HTTP by TSeletor object
10681071
testList->Add(new ProofTest("H1 chain: selector by object", 28, &PT_H1ChainByObj, 0, "1", "h1analysis", kTRUE));
1072+
// Test TPacketizerFile and TTree friends in separate files
1073+
testList->Add(new ProofTest("Chain with TTree in subdirs", 29, &PT_TreeSubDirs, 0, "1", "ProofFriends,ProofAux", kTRUE));
10691074
// The selectors
10701075
if (PT_AssertTutorialDir(gTutDir) != 0) {
10711076
printf("* Some of the tutorial files are missing! Stop\n");
@@ -2107,7 +2112,7 @@ Int_t PT_CheckDataset(TQueryResult *qr, Long64_t nevt)
21072112
}
21082113

21092114
//_____________________________________________________________________________
2110-
Int_t PT_CheckFriends(TQueryResult *qr, Long64_t nevt)
2115+
Int_t PT_CheckFriends(TQueryResult *qr, Long64_t nevt, bool withfriends)
21112116
{
21122117
// Check the result of the ProofFriends analysis
21132118

@@ -2134,14 +2139,15 @@ Int_t PT_CheckFriends(TQueryResult *qr, Long64_t nevt)
21342139

21352140
TString emsg;
21362141
// Check the histogram entries and mean values
2142+
Int_t nchk = (withfriends) ? 4 : 2;
21372143
Int_t rchs = 0;
21382144
const char *hnam[4] = { "histo1", "histo2", "histo3", "histo4" };
21392145
const char *hcls[4] = { "TH2F", "TH1F", "TH1F", "TH2F" };
21402146
Float_t hent[4] = { 1., .227, .0260, .0260};
21412147
TObject *o = 0;
21422148
Double_t ent = -1;
21432149
Double_t prec = 1. / TMath::Sqrt(nevt);
2144-
for (Int_t i = 0; i < 4; i++) {
2150+
for (Int_t i = 0; i < nchk; i++) {
21452151
if (!(o = out->FindObject(hnam[i]))) {
21462152
emsg.Form("object '%s' not found", hnam[i]);
21472153
rchs = -1;
@@ -4268,7 +4274,127 @@ Int_t PT_Friends(void *sf, RunTimes &tt)
42684274

42694275
// Check the results
42704276
PutPoint();
4271-
return PT_CheckFriends(gProof->GetQueryResult(), nevt * nwrk);
4277+
return PT_CheckFriends(gProof->GetQueryResult(), nevt * nwrk, 1);
4278+
}
4279+
4280+
//_____________________________________________________________________________
4281+
Int_t PT_TreeSubDirs(void *sf, RunTimes &tt)
4282+
{
4283+
// Test processing of TTree in subdirectories
4284+
4285+
// Checking arguments
4286+
PutPoint();
4287+
if (!gProof) {
4288+
printf("\n >>> Test failure: no PROOF session found\n");
4289+
return -1;
4290+
}
4291+
4292+
// Not supported in dynamic mode
4293+
if (gDynamicStartup) {
4294+
return 1;
4295+
}
4296+
PutPoint();
4297+
4298+
// File generation: we use TPacketizerFile in here to create two files per node
4299+
TList *wrks = gProof->GetListOfSlaveInfos();
4300+
if (!wrks) {
4301+
printf("\n >>> Test failure: could not get the list of information about the workers\n");
4302+
return -1;
4303+
}
4304+
4305+
// Create the map
4306+
TString fntree;
4307+
TMap *files = new TMap;
4308+
files->SetName("PROOF_FilesToProcess");
4309+
TIter nxwi(wrks);
4310+
TSlaveInfo *wi = 0;
4311+
while ((wi = (TSlaveInfo *) nxwi())) {
4312+
fntree.Form("tree_%s.root", wi->GetOrdinal());
4313+
THashList *wrklist = (THashList *) files->GetValue(wi->GetName());
4314+
if (!wrklist) {
4315+
wrklist = new THashList;
4316+
wrklist->SetName(wi->GetName());
4317+
files->Add(new TObjString(wi->GetName()), wrklist);
4318+
}
4319+
wrklist->Add(new TObjString(fntree));
4320+
}
4321+
Int_t nwrk = wrks->GetSize();
4322+
4323+
// Generate the files
4324+
gProof->AddInput(files);
4325+
gProof->SetParameter("ProofAux_Action", "GenerateTrees:dir1/dir2/dir3");
4326+
4327+
// File generation: define the number of events per worker
4328+
Long64_t nevt = 1000;
4329+
gProof->SetParameter("ProofAux_NEvents", (Long64_t)nevt);
4330+
// Special Packetizer
4331+
gProof->SetParameter("PROOF_Packetizer", "TPacketizerFile");
4332+
// Now process
4333+
gProof->Process(gAuxSel.Data(), 1);
4334+
// Remove the packetizer specifications
4335+
gProof->DeleteParameters("PROOF_Packetizer");
4336+
4337+
// Check that we got some output
4338+
if (!gProof->GetOutputList()) {
4339+
printf("\n >>> Test failure: output list not found!\n");
4340+
return -1;
4341+
}
4342+
4343+
// Create the TChain objects
4344+
TChain *dset = new TChain("dir1/dir2/dir3/Tmain");
4345+
// Fill them with the information found in the output list
4346+
Bool_t foundMain = kFALSE;
4347+
TIter nxo(gProof->GetOutputList());
4348+
TObject *o = 0;
4349+
TObjString *os = 0;
4350+
while ((o = nxo())) {
4351+
TList *l = dynamic_cast<TList *> (o);
4352+
if (l && !strncmp(l->GetName(), "MainList-", 9)) {
4353+
foundMain = kTRUE;
4354+
TIter nxf(l);
4355+
while ((os = (TObjString *) nxf()))
4356+
dset->Add(os->GetName());
4357+
}
4358+
}
4359+
dset->SetProof();
4360+
4361+
// If we did not found the main or the friend meta info we fail
4362+
if (!foundMain) {
4363+
printf("\n >>> Test failure: 'main' meta info missing!\n");
4364+
return -1;
4365+
}
4366+
4367+
// We do not plot the ntuple (we are in batch mode)
4368+
gProof->SetParameter("PROOF_DONT_PLOT", "yes");
4369+
4370+
// We do use friends
4371+
gProof->SetParameter("PROOF_NO_FRIENDS", "yes");
4372+
4373+
// Clear the list of query results
4374+
if (gProof->GetQueryResults()) gProof->GetQueryResults()->Clear();
4375+
4376+
// Process
4377+
PutPoint();
4378+
{ SwitchProgressGuard spg;
4379+
gTimer.Start();
4380+
dset->Process(gFriendsSel.Data());
4381+
gTimer.Stop();
4382+
}
4383+
4384+
// Remove any setting
4385+
gProof->DeleteParameters("PROOF_DONT_PLOT");
4386+
gProof->GetInputList()->Remove(files);
4387+
files->SetOwner(kTRUE);
4388+
SafeDelete(files);
4389+
// Clear the files created by this run
4390+
gProof->ClearData(TProof::kUnregistered | TProof::kForceClear);
4391+
4392+
// The runtimes
4393+
PT_GetLastProofTimes(tt);
4394+
4395+
// Check the results
4396+
PutPoint();
4397+
return PT_CheckFriends(gProof->GetQueryResult(), nevt * nwrk, 0);
42724398
}
42734399

42744400
//_____________________________________________________________________________

tutorials/proof/ProofAux.C

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ ProofAux::ProofAux()
2828
fNEvents= -1;
2929
fMainList = 0;
3030
fFriendList = 0;
31+
fDir = "";
3132
}
3233

3334
//_____________________________________________________________________________
@@ -47,10 +48,18 @@ Int_t ProofAux::GetAction(TList *input)
4748
// Determine the test type
4849
TNamed *ntype = dynamic_cast<TNamed*>(input->FindObject("ProofAux_Action"));
4950
if (ntype) {
50-
if (!strcmp(ntype->GetTitle(), "GenerateTrees")) {
51-
action = 0;
52-
} else if (!strcmp(ntype->GetTitle(), "GenerateTreesSameFile")) {
51+
TString act(ntype->GetTitle());
52+
if (act == "GenerateTreesSameFile") {
5353
action = 1;
54+
} else if (act.BeginsWith("GenerateTrees")) {
55+
action = 0;
56+
// Extract directory, if any
57+
Ssiz_t icol = act.Index(":");
58+
if (icol != kNPOS) {
59+
action = 2;
60+
act.Remove(0, icol+1);
61+
if (!act.IsNull()) fDir = act;
62+
}
5463
} else {
5564
Warning("GetAction", "unknown action: '%s'", ntype->GetTitle());
5665
}
@@ -87,8 +96,10 @@ void ProofAux::SlaveBegin(TTree * /*tree*/)
8796
// Create lists
8897
fMainList = new TList;
8998
if (gProofServ) fMainList->SetName(TString::Format("MainList-%s", gProofServ->GetOrdinal()));
90-
fFriendList = new TList;
91-
if (gProofServ) fFriendList->SetName(TString::Format("FriendList-%s", gProofServ->GetOrdinal()));
99+
if (fAction < 2) {
100+
fFriendList = new TList;
101+
if (gProofServ) fFriendList->SetName(TString::Format("FriendList-%s", gProofServ->GetOrdinal()));
102+
}
92103
}
93104

94105
//_____________________________________________________________________________
@@ -173,6 +184,14 @@ Bool_t ProofAux::Process(Long64_t entry)
173184
fCurrent->GetName(), fnt.Data());
174185
return kFALSE;
175186
}
187+
} else if (fAction == 2) {
188+
TString fnt;
189+
// Generate the TTree and save it in the specified file
190+
if (GenerateTree(fCurrent->GetName(), fNEvents, fnt) != 0) {
191+
Error("Process", "problems generating tree (%lld, %s, %lld)",
192+
entry, fCurrent->GetName(), fNEvents);
193+
return kFALSE;
194+
}
176195
} else {
177196
// Unknown action
178197
Warning("Process", "do not know how to process action %d - do nothing", fAction);
@@ -239,18 +258,34 @@ Int_t ProofAux::GenerateTree(const char *fnt, Long64_t ent, TString &fn)
239258
}
240259

241260
// Create the file
242-
TDirectory* savedir = gDirectory;
261+
TDirectory *savedir = gDirectory;
243262
TFile *f = new TFile(fn, "RECREATE");
244263
if (!f || f->IsZombie()) {
245264
Error("GenerateTree", "problems opening file %s", fn.Data());
246265
return rc;
247266
}
248267
savedir->cd();
268+
269+
// Create sub-drirectory, if required
270+
TDirectory *destdir = f;
271+
if (!fDir.IsNull()) {
272+
if (f->mkdir(fDir.Data())) {
273+
Info("GenerateTree", "sub-directory '%s' successfully created", fDir.Data());
274+
f->cd(fDir.Data());
275+
destdir = gDirectory;
276+
} else {
277+
Error("GenerateTree", "creating sub-directory '%s'", fDir.Data());
278+
f->Close();
279+
delete f;
280+
return rc;
281+
}
282+
}
283+
249284
rc = 0;
250285

251286
// Create the tree
252287
TTree *T = new TTree("Tmain","Main tree for tutorial friends");
253-
T->SetDirectory(f);
288+
T->SetDirectory(destdir);
254289
Int_t Run = 1;
255290
T->Branch("Run",&Run,"Run/I");
256291
Long64_t Event = 0;
@@ -269,7 +304,7 @@ Int_t ProofAux::GenerateTree(const char *fnt, Long64_t ent, TString &fn)
269304
T->Fill();
270305
}
271306
T->Print();
272-
f->cd();
307+
destdir->cd();
273308
T->Write();
274309
T->SetDirectory(0);
275310
f->Close();

tutorials/proof/ProofAux.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#ifndef ProofAux_h
88
#define ProofAux_h
99

10+
#include <TString.h>
1011
#include <TSelector.h>
1112

1213
class TList;
@@ -23,6 +24,7 @@ public :
2324
Long64_t fNEvents;
2425
TList *fMainList;
2526
TList *fFriendList;
27+
TString fDir;
2628

2729
ProofAux();
2830
virtual ~ProofAux();

0 commit comments

Comments
 (0)