forked from root-project/root
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TProofPlayer.cxx
4913 lines (4220 loc) · 166 KB
/
TProofPlayer.cxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// @(#)root/proofplayer:$Id$
// Author: Maarten Ballintijn 07/01/02
/*************************************************************************
* Copyright (C) 1995-2001, Rene Brun and Fons Rademakers. *
* All rights reserved. *
* *
* For the licensing terms see $ROOTSYS/LICENSE. *
* For the list of contributors see $ROOTSYS/README/CREDITS. *
*************************************************************************/
/** \class TProofPlayer
\ingroup proofkernel
Internal class steering processing in PROOF.
Instances of the TProofPlayer class are created on the worker nodes
per session and do the processing.
Instances of its subclass - TProofPlayerRemote are created per each
query on the master(s) and on the client. On the master(s),
TProofPlayerRemote coordinate processing, check the dataset, create
the packetizer and take care of merging the results of the workers.
The instance on the client collects information on the input
(dataset and selector), it invokes the Begin() method and finalizes
the query by calling Terminate().
*/
#include "TProofDraw.h"
#include "TProofPlayer.h"
#include "THashList.h"
#include "TEnv.h"
#include "TEventIter.h"
#include "TVirtualPacketizer.h"
#include "TSelector.h"
#include "TSocket.h"
#include "TProofServ.h"
#include "TProof.h"
#include "TProofOutputFile.h"
#include "TProofSuperMaster.h"
#include "TSlave.h"
#include "TClass.h"
#include "TROOT.h"
#include "TError.h"
#include "TException.h"
#include "MessageTypes.h"
#include "TMessage.h"
#include "TDSetProxy.h"
#include "TString.h"
#include "TSystem.h"
#include "TFile.h"
#include "TFileCollection.h"
#include "TFileInfo.h"
#include "TFileMerger.h"
#include "TProofDebug.h"
#include "TTimer.h"
#include "TMap.h"
#include "TPerfStats.h"
#include "TStatus.h"
#include "TEventList.h"
#include "TProofLimitsFinder.h"
#include "THashList.h"
#include "TSortedList.h"
#include "TTree.h"
#include "TEntryList.h"
#include "TDSet.h"
#include "TDrawFeedback.h"
#include "TNamed.h"
#include "TObjString.h"
#include "TQueryResult.h"
#include "TMD5.h"
#include "TMethodCall.h"
#include "TObjArray.h"
#include "TH1.h"
#include "TVirtualMonitoring.h"
#include "TParameter.h"
#include "TOutputListSelectorDataMap.h"
#include "TStopwatch.h"
// Timeout exception
#define kPEX_STOPPED 1001
#define kPEX_ABORTED 1002
// To flag an abort condition: use a local static variable to avoid
// warnings about problems with longjumps
static Bool_t gAbort = kFALSE;
class TAutoBinVal : public TNamed {
private:
Double_t fXmin, fXmax, fYmin, fYmax, fZmin, fZmax;
public:
TAutoBinVal(const char *name, Double_t xmin, Double_t xmax, Double_t ymin,
Double_t ymax, Double_t zmin, Double_t zmax) : TNamed(name,"")
{
fXmin = xmin; fXmax = xmax;
fYmin = ymin; fYmax = ymax;
fZmin = zmin; fZmax = zmax;
}
void GetAll(Double_t& xmin, Double_t& xmax, Double_t& ymin,
Double_t& ymax, Double_t& zmin, Double_t& zmax)
{
xmin = fXmin; xmax = fXmax;
ymin = fYmin; ymax = fYmax;
zmin = fZmin; zmax = fZmax;
}
};
//
// Special timer to dispatch pending events while processing
////////////////////////////////////////////////////////////////////////////////
class TDispatchTimer : public TTimer {
private:
TProofPlayer *fPlayer;
public:
TDispatchTimer(TProofPlayer *p) : TTimer(1000, kFALSE), fPlayer(p) { }
Bool_t Notify();
};
////////////////////////////////////////////////////////////////////////////////
/// Handle expiration of the timer associated with dispatching pending
/// events while processing. We must act as fast as possible here, so
/// we just set a flag submitting a request for dispatching pending events
Bool_t TDispatchTimer::Notify()
{
if (gDebug > 0) printf("TDispatchTimer::Notify: called!\n");
fPlayer->SetBit(TProofPlayer::kDispatchOneEvent);
// Needed for the next shot
Reset();
return kTRUE;
}
//
// Special timer to notify reach of max packet proc time
////////////////////////////////////////////////////////////////////////////////
class TProctimeTimer : public TTimer {
private:
TProofPlayer *fPlayer;
public:
TProctimeTimer(TProofPlayer *p, Long_t to) : TTimer(to, kFALSE), fPlayer(p) { }
Bool_t Notify();
};
////////////////////////////////////////////////////////////////////////////////
/// Handle expiration of the timer associated with dispatching pending
/// events while processing. We must act as fast as possible here, so
/// we just set a flag submitting a request for dispatching pending events
Bool_t TProctimeTimer::Notify()
{
if (gDebug > 0) printf("TProctimeTimer::Notify: called!\n");
fPlayer->SetBit(TProofPlayer::kMaxProcTimeReached);
// One shot only
return kTRUE;
}
//
// Special timer to handle stop/abort request via exception raising
////////////////////////////////////////////////////////////////////////////////
class TStopTimer : public TTimer {
private:
Bool_t fAbort;
TProofPlayer *fPlayer;
public:
TStopTimer(TProofPlayer *p, Bool_t abort, Int_t to);
Bool_t Notify();
};
////////////////////////////////////////////////////////////////////////////////
/// Constructor for the timer to stop/abort processing.
/// The 'timeout' is in seconds.
/// Make sure that 'to' make sense, i.e. not larger than 10 days;
/// the minimum value is 10 ms (0 does not seem to start the timer ...).
TStopTimer::TStopTimer(TProofPlayer *p, Bool_t abort, Int_t to)
: TTimer(((to <= 0 || to > 864000) ? 10 : to * 1000), kFALSE)
{
if (gDebug > 0)
Info ("TStopTimer","enter: %d, timeout: %d", abort, to);
fPlayer = p;
fAbort = abort;
if (gDebug > 1)
Info ("TStopTimer","timeout set to %s ms", fTime.AsString());
}
////////////////////////////////////////////////////////////////////////////////
/// Handle the signal coming from the expiration of the timer
/// associated with an abort or stop request.
/// We raise an exception which will be processed in the
/// event loop.
Bool_t TStopTimer::Notify()
{
if (gDebug > 0) printf("TStopTimer::Notify: called!\n");
if (fAbort)
Throw(kPEX_ABORTED);
else
Throw(kPEX_STOPPED);
return kTRUE;
}
//------------------------------------------------------------------------------
ClassImp(TProofPlayer);
THashList *TProofPlayer::fgDrawInputPars = 0;
////////////////////////////////////////////////////////////////////////////////
/// Default ctor.
TProofPlayer::TProofPlayer(TProof *)
: fAutoBins(0), fOutput(0), fSelector(0), fCreateSelObj(kTRUE), fSelectorClass(0),
fFeedbackTimer(0), fFeedbackPeriod(2000),
fEvIter(0), fSelStatus(0),
fTotalEvents(0), fReadBytesRun(0), fReadCallsRun(0), fProcessedRun(0),
fQueryResults(0), fQuery(0), fPreviousQuery(0), fDrawQueries(0),
fMaxDrawQueries(1), fStopTimer(0), fDispatchTimer(0),
fProcTimeTimer(0), fProcTime(0),
fOutputFile(0),
fSaveMemThreshold(-1), fSavePartialResults(kFALSE), fSaveResultsPerPacket(kFALSE)
{
fInput = new TList;
fExitStatus = kFinished;
fProgressStatus = new TProofProgressStatus();
ResetBit(TProofPlayer::kDispatchOneEvent);
ResetBit(TProofPlayer::kIsProcessing);
ResetBit(TProofPlayer::kMaxProcTimeReached);
ResetBit(TProofPlayer::kMaxProcTimeExtended);
static Bool_t initLimitsFinder = kFALSE;
if (!initLimitsFinder && gProofServ && !gProofServ->IsMaster()) {
THLimitsFinder::SetLimitsFinder(new TProofLimitsFinder);
initLimitsFinder = kTRUE;
}
}
////////////////////////////////////////////////////////////////////////////////
/// Destructor.
TProofPlayer::~TProofPlayer()
{
fInput->Clear("nodelete");
SafeDelete(fInput);
// The output list is owned by fSelector and destroyed in there
SafeDelete(fSelector);
SafeDelete(fFeedbackTimer);
SafeDelete(fEvIter);
SafeDelete(fQueryResults);
SafeDelete(fDispatchTimer);
SafeDelete(fProcTimeTimer);
SafeDelete(fProcTime);
SafeDelete(fStopTimer);
}
////////////////////////////////////////////////////////////////////////////////
/// Set processing bit according to 'on'
void TProofPlayer::SetProcessing(Bool_t on)
{
if (on)
SetBit(TProofPlayer::kIsProcessing);
else
ResetBit(TProofPlayer::kIsProcessing);
}
////////////////////////////////////////////////////////////////////////////////
/// Stop the process after this event. If timeout is positive, start
/// a timer firing after timeout seconds to hard-stop time-expensive
/// events.
void TProofPlayer::StopProcess(Bool_t abort, Int_t timeout)
{
if (gDebug > 0)
Info ("StopProcess","abort: %d, timeout: %d", abort, timeout);
if (fEvIter != 0)
fEvIter->StopProcess(abort);
Long_t to = 1;
if (abort == kTRUE) {
fExitStatus = kAborted;
} else {
fExitStatus = kStopped;
to = timeout;
}
// Start countdown, if needed
if (to > 0)
SetStopTimer(kTRUE, abort, to);
}
////////////////////////////////////////////////////////////////////////////////
/// Enable/disable the timer to dispatch pening events while processing.
void TProofPlayer::SetDispatchTimer(Bool_t on)
{
SafeDelete(fDispatchTimer);
ResetBit(TProofPlayer::kDispatchOneEvent);
if (on) {
fDispatchTimer = new TDispatchTimer(this);
fDispatchTimer->Start();
}
}
////////////////////////////////////////////////////////////////////////////////
/// Enable/disable the timer to stop/abort processing.
/// The 'timeout' is in seconds.
void TProofPlayer::SetStopTimer(Bool_t on, Bool_t abort, Int_t timeout)
{
std::lock_guard<std::mutex> lock(fStopTimerMtx);
// Clean-up the timer
SafeDelete(fStopTimer);
if (on) {
// create timer
fStopTimer = new TStopTimer(this, abort, timeout);
// Start the countdown
fStopTimer->Start();
if (gDebug > 0)
Info ("SetStopTimer", "%s timer STARTED (timeout: %d)",
(abort ? "ABORT" : "STOP"), timeout);
} else {
if (gDebug > 0)
Info ("SetStopTimer", "timer STOPPED");
}
}
////////////////////////////////////////////////////////////////////////////////
/// Add query result to the list, making sure that there are no
/// duplicates.
void TProofPlayer::AddQueryResult(TQueryResult *q)
{
if (!q) {
Warning("AddQueryResult","query undefined - do nothing");
return;
}
// Treat differently normal and draw queries
if (!(q->IsDraw())) {
if (!fQueryResults) {
fQueryResults = new TList;
fQueryResults->Add(q);
} else {
TIter nxr(fQueryResults);
TQueryResult *qr = 0;
TQueryResult *qp = 0;
while ((qr = (TQueryResult *) nxr())) {
// If same query, remove old version and break
if (*qr == *q) {
fQueryResults->Remove(qr);
delete qr;
break;
}
// Record position according to start time
if (qr->GetStartTime().Convert() <= q->GetStartTime().Convert())
qp = qr;
}
if (!qp) {
fQueryResults->AddFirst(q);
} else {
fQueryResults->AddAfter(qp, q);
}
}
} else if (IsClient()) {
// If max reached, eliminate first the oldest one
if (fDrawQueries == fMaxDrawQueries && fMaxDrawQueries > 0) {
TIter nxr(fQueryResults);
TQueryResult *qr = 0;
while ((qr = (TQueryResult *) nxr())) {
// If same query, remove old version and break
if (qr->IsDraw()) {
fDrawQueries--;
fQueryResults->Remove(qr);
delete qr;
break;
}
}
}
// Add new draw query
if (fDrawQueries >= 0 && fDrawQueries < fMaxDrawQueries) {
fDrawQueries++;
if (!fQueryResults)
fQueryResults = new TList;
fQueryResults->Add(q);
}
}
}
////////////////////////////////////////////////////////////////////////////////
/// Remove all query result instances referenced 'ref' from
/// the list of results.
void TProofPlayer::RemoveQueryResult(const char *ref)
{
if (fQueryResults) {
TIter nxq(fQueryResults);
TQueryResult *qr = 0;
while ((qr = (TQueryResult *) nxq())) {
if (qr->Matches(ref)) {
fQueryResults->Remove(qr);
delete qr;
}
}
}
}
////////////////////////////////////////////////////////////////////////////////
/// Get query result instances referenced 'ref' from
/// the list of results.
TQueryResult *TProofPlayer::GetQueryResult(const char *ref)
{
if (fQueryResults) {
if (ref && strlen(ref) > 0) {
TIter nxq(fQueryResults);
TQueryResult *qr = 0;
while ((qr = (TQueryResult *) nxq())) {
if (qr->Matches(ref))
return qr;
}
} else {
// Get last
return (TQueryResult *) fQueryResults->Last();
}
}
// Nothing found
return (TQueryResult *)0;
}
////////////////////////////////////////////////////////////////////////////////
/// Set current query and save previous value.
void TProofPlayer::SetCurrentQuery(TQueryResult *q)
{
fPreviousQuery = fQuery;
fQuery = q;
}
////////////////////////////////////////////////////////////////////////////////
/// Add object to input list.
void TProofPlayer::AddInput(TObject *inp)
{
fInput->Add(inp);
}
////////////////////////////////////////////////////////////////////////////////
/// Clear input list.
void TProofPlayer::ClearInput()
{
fInput->Clear();
}
////////////////////////////////////////////////////////////////////////////////
/// Get output object by name.
TObject *TProofPlayer::GetOutput(const char *name) const
{
if (fOutput)
return fOutput->FindObject(name);
return 0;
}
////////////////////////////////////////////////////////////////////////////////
/// Get output list.
TList *TProofPlayer::GetOutputList() const
{
TList *ol = fOutput;
if (!ol && fQuery)
ol = fQuery->GetOutputList();
return ol;
}
////////////////////////////////////////////////////////////////////////////////
/// Reinitialize fSelector using the selector files in the query result.
/// Needed when Finalize is called after a Process execution for the same
/// selector name.
Int_t TProofPlayer::ReinitSelector(TQueryResult *qr)
{
Int_t rc = 0;
// Make sure we have a query
if (!qr) {
Info("ReinitSelector", "query undefined - do nothing");
return -1;
}
// Selector name
TString selec = qr->GetSelecImp()->GetName();
if (selec.Length() <= 0) {
Info("ReinitSelector", "selector name undefined - do nothing");
return -1;
}
// Find out if this is a standard selection used for Draw actions
Bool_t stdselec = TSelector::IsStandardDraw(selec);
// Find out if this is a precompiled selector: in such a case we do not
// have the code in TMacros, so we must rely on local libraries
Bool_t compselec = (selec.Contains(".") || stdselec) ? kFALSE : kTRUE;
// If not, find out if it needs to be expanded
TString ipathold;
if (!stdselec && !compselec) {
// Check checksums for the versions of the selector files
Bool_t expandselec = kTRUE;
TString dir, ipath;
char *selc = gSystem->Which(TROOT::GetMacroPath(), selec, kReadPermission);
if (selc) {
// Check checksums
TMD5 *md5icur = 0, *md5iold = 0, *md5hcur = 0, *md5hold = 0;
// Implementation files
md5icur = TMD5::FileChecksum(selc);
md5iold = qr->GetSelecImp()->Checksum();
// Header files
TString selh(selc);
Int_t dot = selh.Last('.');
if (dot != kNPOS) selh.Remove(dot);
selh += ".h";
if (!gSystem->AccessPathName(selh, kReadPermission))
md5hcur = TMD5::FileChecksum(selh);
md5hold = qr->GetSelecHdr()->Checksum();
// If nothing has changed nothing to do
if (md5hcur && md5hold && md5icur && md5iold)
if (*md5hcur == *md5hold && *md5icur == *md5iold)
expandselec = kFALSE;
SafeDelete(md5icur);
SafeDelete(md5hcur);
SafeDelete(md5iold);
SafeDelete(md5hold);
if (selc) delete [] selc;
}
Bool_t ok = kTRUE;
// Expand selector files, if needed
if (expandselec) {
ok = kFALSE;
// Expand files in a temporary directory
TUUID u;
dir = Form("%s/%s",gSystem->TempDirectory(),u.AsString());
if (!(gSystem->MakeDirectory(dir))) {
// Export implementation file
selec = Form("%s/%s",dir.Data(),selec.Data());
qr->GetSelecImp()->SaveSource(selec);
// Export header file
TString seleh = Form("%s/%s",dir.Data(),qr->GetSelecHdr()->GetName());
qr->GetSelecHdr()->SaveSource(seleh);
// Adjust include path
ipathold = gSystem->GetIncludePath();
ipath = Form("-I%s %s", dir.Data(), gSystem->GetIncludePath());
gSystem->SetIncludePath(ipath.Data());
ok = kTRUE;
}
}
TString opt(qr->GetOptions());
Ssiz_t id = opt.Last('#');
if (id != kNPOS && id < opt.Length() - 1)
selec += opt(id + 1, opt.Length());
if (!ok) {
Info("ReinitSelector", "problems locating or exporting selector files");
return -1;
}
}
// Cleanup previous stuff
SafeDelete(fSelector);
fSelectorClass = 0;
// Init the selector now
Int_t iglevelsave = gErrorIgnoreLevel;
if (compselec)
// Silent error printout on first attempt
gErrorIgnoreLevel = kBreak;
if ((fSelector = TSelector::GetSelector(selec))) {
if (compselec)
gErrorIgnoreLevel = iglevelsave; // restore ignore level
fSelectorClass = fSelector->IsA();
fSelector->SetOption(qr->GetOptions());
} else {
if (compselec) {
gErrorIgnoreLevel = iglevelsave; // restore ignore level
// Retry by loading first the libraries listed in TQueryResult, if any
if (strlen(qr->GetLibList()) > 0) {
TString sl(qr->GetLibList());
TObjArray *oa = sl.Tokenize(" ");
if (oa) {
Bool_t retry = kFALSE;
TIter nxl(oa);
TObjString *os = 0;
while ((os = (TObjString *) nxl())) {
TString lib = gSystem->BaseName(os->GetName());
if (lib != "lib") {
lib.ReplaceAll("-l", "lib");
if (gSystem->Load(lib) == 0)
retry = kTRUE;
}
}
// Retry now, if the case
if (retry)
fSelector = TSelector::GetSelector(selec);
}
}
}
if (!fSelector) {
if (compselec)
Info("ReinitSelector", "compiled selector re-init failed:"
" automatic reload unsuccessful:"
" please load manually the correct library");
rc = -1;
}
}
if (fSelector) {
// Draw needs to reinit temp histos
fSelector->SetInputList(qr->GetInputList());
if (stdselec) {
((TProofDraw *)fSelector)->DefVar();
} else {
// variables may have been initialized in Begin()
fSelector->Begin(0);
}
}
// Restore original include path, if needed
if (ipathold.Length() > 0)
gSystem->SetIncludePath(ipathold.Data());
return rc;
}
////////////////////////////////////////////////////////////////////////////////
/// Incorporate output object (may not be used in this class).
Int_t TProofPlayer::AddOutputObject(TObject *)
{
MayNotUse("AddOutputObject");
return -1;
}
////////////////////////////////////////////////////////////////////////////////
/// Incorporate output list (may not be used in this class).
void TProofPlayer::AddOutput(TList *)
{
MayNotUse("AddOutput");
}
////////////////////////////////////////////////////////////////////////////////
/// Store output list (may not be used in this class).
void TProofPlayer::StoreOutput(TList *)
{
MayNotUse("StoreOutput");
}
////////////////////////////////////////////////////////////////////////////////
/// Store feedback list (may not be used in this class).
void TProofPlayer::StoreFeedback(TObject *, TList *)
{
MayNotUse("StoreFeedback");
}
////////////////////////////////////////////////////////////////////////////////
/// Report progress (may not be used in this class).
void TProofPlayer::Progress(Long64_t /*total*/, Long64_t /*processed*/)
{
MayNotUse("Progress");
}
////////////////////////////////////////////////////////////////////////////////
/// Report progress (may not be used in this class).
void TProofPlayer::Progress(Long64_t /*total*/, Long64_t /*processed*/,
Long64_t /*bytesread*/,
Float_t /*evtRate*/, Float_t /*mbRate*/,
Float_t /*evtrti*/, Float_t /*mbrti*/)
{
MayNotUse("Progress");
}
////////////////////////////////////////////////////////////////////////////////
/// Report progress (may not be used in this class).
void TProofPlayer::Progress(TProofProgressInfo * /*pi*/)
{
MayNotUse("Progress");
}
////////////////////////////////////////////////////////////////////////////////
/// Set feedback list (may not be used in this class).
void TProofPlayer::Feedback(TList *)
{
MayNotUse("Feedback");
}
////////////////////////////////////////////////////////////////////////////////
/// Draw feedback creation proxy. When accessed via TProof avoids
/// link dependency on libProofPlayer.
TDrawFeedback *TProofPlayer::CreateDrawFeedback(TProof *p)
{
return new TDrawFeedback(p);
}
////////////////////////////////////////////////////////////////////////////////
/// Set draw feedback option.
void TProofPlayer::SetDrawFeedbackOption(TDrawFeedback *f, Option_t *opt)
{
if (f)
f->SetOption(opt);
}
////////////////////////////////////////////////////////////////////////////////
/// Delete draw feedback object.
void TProofPlayer::DeleteDrawFeedback(TDrawFeedback *f)
{
delete f;
}
////////////////////////////////////////////////////////////////////////////////
/// Save the partial results of this query to a dedicated file under the user
/// data directory. The file name has the form
/// <session_tag>.q<query_seq_num>.root
/// The file pat and the file are created if not existing already.
/// Only objects in the outputlist not being TProofOutputFile are saved.
/// The packets list 'packets' is saved if given.
/// Trees not attached to any file are attached to the open file.
/// If 'queryend' is kTRUE evrything is written out (TTrees included).
/// The actual saving action is controlled by 'force' and by fSavePartialResults /
/// fSaveResultsPerPacket:
///
/// fSavePartialResults = kFALSE/kTRUE no-saving/saving
/// fSaveResultsPerPacket = kFALSE/kTRUE save-per-query/save-per-packet
///
/// The function CheckMemUsage sets fSavePartialResults = 1 if fSaveMemThreshold > 0 and
/// ProcInfo_t::fMemResident >= fSaveMemThreshold: from that point on partial results
/// are always saved and expensive calls to TSystem::GetProcInfo saved.
/// The switch fSaveResultsPerPacket is instead controlled by the user or admin
/// who can also force saving in all cases; parameter PROOF_SavePartialResults or
/// RC env ProofPlayer.SavePartialResults .
/// However, if 'force' is kTRUE, fSavePartialResults and fSaveResultsPerPacket
/// are ignored.
/// Return -1 in case of problems, 0 otherwise.
Int_t TProofPlayer::SavePartialResults(Bool_t queryend, Bool_t force)
{
Bool_t save = (force || (fSavePartialResults &&
(queryend || fSaveResultsPerPacket))) ? kTRUE : kFALSE;
if (!save) {
PDB(kOutput, 2)
Info("SavePartialResults", "partial result saving disabled");
return 0;
}
// Sanity check
if (!gProofServ) {
Error("SavePartialResults", "gProofServ undefined: something really wrong going on!!!");
return -1;
}
if (!fOutput) {
Error("SavePartialResults", "fOutput undefined: something really wrong going on!!!");
return -1;
}
PDB(kOutput, 1)
Info("SavePartialResults", "start saving partial results {%d,%d,%d,%d}",
queryend, force, fSavePartialResults, fSaveResultsPerPacket);
// Get list of processed packets from the iterator
PDB(kOutput, 2) Info("SavePartialResults", "fEvIter: %p", fEvIter);
TList *packets = (fEvIter) ? fEvIter->GetPackets() : 0;
PDB(kOutput, 2) Info("SavePartialResults", "list of packets: %p, sz: %d",
packets, (packets ? packets->GetSize(): -1));
// Open the file
const char *oopt = "UPDATE";
// Check if the file has already been defined
TString baseName(fOutputFilePath);
if (fOutputFilePath.IsNull()) {
baseName.Form("output-%s.q%d.root", gProofServ->GetTopSessionTag(), gProofServ->GetQuerySeqNum());
if (gProofServ->GetDataDirOpts() && strlen(gProofServ->GetDataDirOpts()) > 0) {
fOutputFilePath.Form("%s/%s?%s", gProofServ->GetDataDir(), baseName.Data(),
gProofServ->GetDataDirOpts());
} else {
fOutputFilePath.Form("%s/%s", gProofServ->GetDataDir(), baseName.Data());
}
Info("SavePartialResults", "file with (partial) output: '%s'", fOutputFilePath.Data());
oopt = "RECREATE";
}
// Open the file in write mode
if (!(fOutputFile = TFile::Open(fOutputFilePath, oopt)) ||
(fOutputFile && fOutputFile->IsZombie())) {
Error("SavePartialResults", "cannot open '%s' for writing", fOutputFilePath.Data());
SafeDelete(fOutputFile);
return -1;
}
// Save current directory
TDirectory *curdir = gDirectory;
fOutputFile->cd();
// Write first the packets list, if required
if (packets) {
TDirectory *packetsDir = fOutputFile->mkdir("packets");
if (packetsDir) packetsDir->cd();
packets->Write(0, TObject::kSingleKey | TObject::kOverwrite);
fOutputFile->cd();
}
Bool_t notempty = kFALSE;
// Write out the output list
TList torm;
TIter nxo(fOutput);
TObject *o = 0;
while ((o = nxo())) {
// Skip output file drivers
if (o->InheritsFrom(TProofOutputFile::Class())) continue;
// Skip control objets
if (!strncmp(o->GetName(), "PROOF_", 6)) continue;
// Skip data members mapping
if (o->InheritsFrom(TOutputListSelectorDataMap::Class())) continue;
// Skip missing file info
if (!strcmp(o->GetName(), "MissingFiles")) continue;
// Trees need a special treatment
if (o->InheritsFrom("TTree")) {
TTree *t = (TTree *) o;
TDirectory *d = t->GetDirectory();
// If the tree is not attached to any file ...
if (!d || (d && !d->InheritsFrom("TFile"))) {
// ... we attach it
t->SetDirectory(fOutputFile);
}
if (t->GetDirectory() == fOutputFile) {
if (queryend) {
// ... we write it out
o->Write(0, TObject::kOverwrite);
// At least something in the file
notempty = kTRUE;
// Flag for removal from the outputlist
torm.Add(o);
// Prevent double-deletion attempts
t->SetDirectory(0);
} else {
// ... or we set in automatic flush mode
t->SetAutoFlush();
}
}
} else if (queryend || fSaveResultsPerPacket) {
// Save overwriting what's already there
o->Write(0, TObject::kOverwrite);
// At least something in the file
notempty = kTRUE;
// Flag for removal from the outputlist
if (queryend) torm.Add(o);
}
}
// Restore previous directory
gDirectory = curdir;
// Close the file if required
if (notempty) {
if (!fOutput->FindObject(baseName)) {
TProofOutputFile *po = 0;
// Get directions
TNamed *nm = (TNamed *) fInput->FindObject("PROOF_DefaultOutputOption");
TString oname = (nm) ? nm->GetTitle() : fOutputFilePath.Data();
if (nm && oname.BeginsWith("ds:")) {
oname.Replace(0, 3, "");
TString qtag =
TString::Format("%s_q%d", gProofServ->GetTopSessionTag(), gProofServ->GetQuerySeqNum());
oname.ReplaceAll("<qtag>", qtag);
// Create the TProofOutputFile for dataset creation
po = new TProofOutputFile(baseName, "DRO", oname.Data());
} else {
Bool_t hasddir = kFALSE;
// Create the TProofOutputFile for automatic merging
po = new TProofOutputFile(baseName, "M");
if (oname.BeginsWith("of:")) oname.Replace(0, 3, "");
if (gProofServ->IsTopMaster()) {
if (!strcmp(TUrl(oname, kTRUE).GetProtocol(), "file")) {
TString dsrv;
TProofServ::GetLocalServer(dsrv);
TProofServ::FilterLocalroot(oname, dsrv);
oname.Insert(0, dsrv);
}
} else {
if (nm) {
// The name has been sent by the client: resolve local place holders
oname.ReplaceAll("<file>", baseName);
} else {
// We did not get any indication; the final file will be in the datadir on
// the top master and it will be resolved there
oname.Form("<datadir>/%s", baseName.Data());
hasddir = kTRUE;
}
}
po->SetOutputFileName(oname.Data());
if (hasddir)
// Reset the bit, so that <datadir> has a chance to be resolved in AddOutputObject
po->ResetBit(TProofOutputFile::kOutputFileNameSet);
po->SetName(gSystem->BaseName(oname.Data()));
}
po->AdoptFile(fOutputFile);
fOutput->Add(po);
// Flag the nature of this file
po->SetBit(TProofOutputFile::kSwapFile);
}
}
fOutputFile->Close();
SafeDelete(fOutputFile);
// If last call, cleanup the output list from objects saved to file
if (queryend && torm.GetSize() > 0) {
TIter nxrm(&torm);
while ((o = nxrm())) { fOutput->Remove(o); }
}
torm.SetOwner(kFALSE);
PDB(kOutput, 1)
Info("SavePartialResults", "partial results saved to file");
// We are done
return 0;
}
////////////////////////////////////////////////////////////////////////////////
/// Make sure that a valid selector object
/// Return -1 in case of problems, 0 otherwise
Int_t TProofPlayer::AssertSelector(const char *selector_file)
{
if (selector_file && strlen(selector_file)) {
if (fCreateSelObj) SafeDelete(fSelector);
// Get selector files from cache
TString ocwd = gSystem->WorkingDirectory();
if (gProofServ) {
gProofServ->GetCacheLock()->Lock();
gSystem->ChangeDirectory(gProofServ->GetCacheDir());
}
fSelector = TSelector::GetSelector(selector_file);
if (gProofServ) {
gSystem->ChangeDirectory(ocwd);
gProofServ->GetCacheLock()->Unlock();
}
if (!fSelector) {
Error("AssertSelector", "cannot load: %s", selector_file );
return -1;
}
fCreateSelObj = kTRUE;
Info("AssertSelector", "Processing via filename (%s)", selector_file);
} else if (!fSelector) {
Error("AssertSelector", "no TSelector object define : cannot continue!");
return -1;
} else {
Info("AssertSelector", "Processing via TSelector object");
}
// Done
return 0;