Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TQueryResult.cxx
Go to the documentation of this file.
1// @(#)root/tree:$Id$
2// Author: G Ganis Sep 2005
3
4/*************************************************************************
5 * Copyright (C) 1995-2005, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12/** \class TQueryResult
13\ingroup tree
14
15A container class for query results.
16*/
17
18#include <cstring>
19
20#include "strlcpy.h"
21#include "TBrowser.h"
22#include "TEventList.h"
23#include "TQueryResult.h"
24#include "TRegexp.h"
25#include "TROOT.h"
26#include "TMacro.h"
27#include "TMath.h"
28#include "TSelector.h"
29#include "TSystem.h"
30#include "TTimeStamp.h"
31
33
34////////////////////////////////////////////////////////////////////////////////
35/// Main constructor.
36
37TQueryResult::TQueryResult(Int_t seqnum, const char *opt, TList *inlist,
38 Long64_t entries, Long64_t first, const char *selec)
39 : fSeqNum(seqnum), fStatus(kSubmitted), fUsedCPU(0.), fOptions(opt),
40 fEntries(entries), fFirst(first),
41 fBytes(0), fParList("-"), fOutputList(0),
42 fFinalized(kFALSE), fArchived(kFALSE), fResultFile("-"),
43 fPrepTime(0.), fInitTime(0.), fProcTime(0.), fMergeTime(0.),
44 fRecvTime(-1), fTermTime(-1), fNumWrks(-1), fNumMergers(-1)
45{
46 // Name and unique title
48 SetTitle(TString::Format("session-localhost-%ld-%d",
49 (Long_t)TTimeStamp().GetSec(), gSystem->GetPid()));
50
51 // Start time
52 fStart.Set();
54
55 // Save input list
56 fInputList = 0;
57 if (inlist) {
58 fInputList = (TList *) (inlist->Clone());
60 }
61
62 // Log file
63 fLogFile = new TMacro("LogFile");
64
65 // Selector files
66 fDraw = selec ? TSelector::IsStandardDraw(selec) : kFALSE;
67 if (fDraw) {
68 // The input list should contain info about the variables and
69 // selection cuts: save them into the macro title
70 TString varsel;
71 if (fInputList) {
72 TIter nxo(fInputList);
73 TObject *o = 0;
74 while ((o = nxo())) {
75 if (!strcmp(o->GetName(),"varexp")) {
76 varsel = o->GetTitle();
77 Int_t iht = varsel.Index(">>htemp");
78 if (iht > -1)
79 varsel.Remove(iht);
80 varsel.Form("\"%s\";", varsel.Data());
81 }
82 if (!strcmp(o->GetName(),"selection"))
83 varsel += TString::Format("\"%s\"", o->GetTitle());
84 }
85 if (gDebug > 0)
86 Info("TQueryResult","selec: %s, varsel: %s", selec, varsel.Data());
87 // Log notification also in the instance
88 fLogFile->AddLine(TString::Format("TQueryResult: selec: %s, varsel: %s",
89 selec, varsel.Data()));
90 }
91 // Standard draw action: save only the name
92 fSelecImp = new TMacro(selec, varsel);
93 fSelecHdr = 0;
94 } else {
95 // Save selector file
96 fSelecHdr = new TMacro;
97 fSelecImp = new TMacro;
98 SaveSelector(selec);
99 }
100
101 // List of libraries loaded at creation
102 const char *pl = gSystem->GetLibraries();
103 fLibList = (pl && (strlen(pl) > 0)) ? pl : "-";
104}
105
106////////////////////////////////////////////////////////////////////////////////
107/// Destructor.
108
110{
116}
117
118////////////////////////////////////////////////////////////////////////////////
119/// Return an instance of TQueryResult containing only the local
120/// info fields, i.e. no outputlist, liblist, dset, selectors, etc..
121/// Used for fast retrieve of information about existing queries
122/// and their status.
123
125{
126 // Create instance
128 fFirst, 0);
129
130 // Correct fields
131 qr->fStatus = fStatus;
132 qr->fStart.Set(fStart.Convert());
133 qr->fEnd.Set(fEnd.Convert());
134 qr->fUsedCPU = fUsedCPU;
135 qr->fEntries = fEntries;
136 qr->fFirst = fFirst;
137 qr->fBytes = fBytes;
138 qr->fParList = fParList;
140 qr->fArchived = fArchived;
141 qr->fPrepTime = fPrepTime;
142 qr->fInitTime = fInitTime;
143 qr->fProcTime = fProcTime;
145 qr->fRecvTime = fRecvTime;
146 qr->fTermTime = fTermTime;
147 qr->fNumWrks = fNumWrks;
149
150 qr->fSelecHdr = 0;
151 if (GetSelecHdr()) {
152 qr->fSelecHdr = new TMacro();
155 }
156 qr->fSelecImp = 0;
157 if (GetSelecImp()) {
158 qr->fSelecImp = new TMacro();
161 }
162
163 // Name and title
164 qr->SetName(GetName());
165 qr->SetTitle(GetTitle());
166
167 return qr;
168}
169
170////////////////////////////////////////////////////////////////////////////////
171/// Save the selector header and implementation into the dedicated
172/// TMacro instances. The header is searched for in the same directory
173/// of the implementation file.
174
175void TQueryResult::SaveSelector(const char *selector)
176{
177 if (!selector)
178 return;
179
180 // Separate out aclic chars
181 TString selec = selector;
182 TString aclicMode;
183 TString arguments;
184 TString io;
185 selec = gSystem->SplitAclicMode(selec, aclicMode, arguments, io);
186
187 // Store aclic options, if any
188 if (aclicMode.Length() > 0)
189 fOptions += TString::Format("#%s", aclicMode.Data());
190
191 // If the selector is in a precompiled shared lib (e.g. in a PAR)
192 // we just save the name
193 TString selname = gSystem->BaseName(selec);
194 fSelecImp->SetName(selname);
195 Int_t idx = selname.Index(".");
196 if (idx < 0) {
197 // Notify
198 if (gDebug > 0)
199 Info("SaveSelector", "precompiled selector: just save the name");
200 fSelecImp->SetTitle(selname);
201 } else {
202 // We locate the file and save it in compressed form
203 if (idx > -1)
204 selname.Remove(idx);
205 fSelecImp->SetTitle(selname);
206
207 // Locate the implementation file
208 char *selc = gSystem->Which(TROOT::GetMacroPath(), selec, kReadPermission);
209 if (!selc) {
210 if (gDebug > 0)
211 Warning("SaveSelector",
212 "could not locate selector implementation file (%s)", selec.Data());
213 return;
214 }
215
216 // Fill the TMacro instance
217 fSelecImp->ReadFile(selc);
219
220 // Locate the included header file
221 char *p = (char *) strrchr(selc,'.');
222 if (p) {
223 strlcpy(p+1,"h",strlen(p));
224 } else {
225 if (gDebug > 0)
226 Warning("SaveSelector",
227 "bad formatted name (%s): could not build header file name", selc);
228 }
229 if (!(gSystem->AccessPathName(selc, kReadPermission))) {
230 fSelecHdr->ReadFile(selc);
232 fSelecHdr->SetTitle(selname);
233 } else {
234 if (gDebug > 0)
235 Warning("SaveSelector",
236 "could not locate selector header file (%s)", selc);
237 }
238
239 delete[] selc;
240 }
241}
242
243////////////////////////////////////////////////////////////////////////////////
244/// End of query settings.
245
247{
248 // End time
249 fEnd.Set();
250
251 // Status
252 fStatus = (status < kAborted || status > kCompleted) ? kAborted : status;
253
254 // Clone the results
255 if (outlist && fOutputList != outlist) {
256 if (fOutputList) {
259 }
260 if ((fOutputList = (TList *) (outlist->Clone()))) {
262 Info("RecordEnd", "output list cloned successfully!");
263 } else {
264 Warning("RecordEnd", "unable to clone output list!!!");
265 }
266 }
267}
268
269////////////////////////////////////////////////////////////////////////////////
270/// Set processing info.
271
273 Float_t init, Float_t proc)
274{
275 fEntries = (ent > 0) ? ent : fEntries;
276 fUsedCPU = (cpu > 0.) ? cpu : fUsedCPU;
277 fBytes = (bytes > 0.) ? bytes : fBytes;
278 fInitTime = (init > 0.) ? init : fInitTime;
279 fProcTime = (proc > 0.) ? proc : fProcTime;
280}
281
282////////////////////////////////////////////////////////////////////////////////
283/// Fill log file.
284
285void TQueryResult::AddLogLine(const char *logline)
286{
287 if (logline)
288 fLogFile->AddLine(logline);
289}
290
291////////////////////////////////////////////////////////////////////////////////
292/// Add obj to the input list
293
295{
296 if (fInputList && obj)
297 fInputList->Add(obj);
298}
299
300////////////////////////////////////////////////////////////////////////////////
301/// Set (or update) query in archived state.
302
303void TQueryResult::SetArchived(const char *archfile)
304{
305 if (IsDone()) {
307 if (archfile && (strlen(archfile) > 0))
308 fResultFile = archfile;
309 }
310}
311
312////////////////////////////////////////////////////////////////////////////////
313/// Print query content. Use opt = "F" for a full listing.
314
316{
317 // Attention: the list must match EQueryStatus
318 const char *qst[] = {
319 "aborted ", "submitted", "running ", "stopped ", "completed"
320 };
321
322 // Status label
323 Int_t st = (fStatus > 0 && fStatus <= kCompleted) ? fStatus : 0;
324
325 // Range label
326 Long64_t last = (fEntries > -1) ? fFirst+fEntries-1 : -1;
327
328 // Option
329 Bool_t full = ((strchr(opt,'F') || strchr(opt,'f'))) ? kTRUE : kFALSE;
330
331 // Query number to be printed
332 Int_t qry = fSeqNum;
333 TString qn = opt;
334 TRegexp re("N.*N");
335 Int_t i1 = qn.Index(re);
336 if (i1 != kNPOS) {
337 qn.Remove(0, i1+1);
338 qn.Remove(qn.Index("N"));
339 qry = qn.Atoi();
340 }
341
342 // Print separator if full dump
343 if (full) Printf("+++");
344
345 TString range;
346 if (!full && (last > -1))
347 range.Form("evts:%lld-%lld", fFirst, last);
348
349 // Print header
350 if (!fDraw) {
351 const char *fin = fFinalized ? "finalized" : qst[st];
352 const char *arc = fArchived ? "(A)" : "";
353 Printf("+++ #:%d ref:\"%s:%s\" sel:%s %9s%s %s",
354 qry, GetTitle(), GetName(), fSelecImp->GetTitle(), fin, arc,
355 range.Data());
356 } else {
357 Printf("+++ #:%d ref:\"%s:%s\" varsel:%s %s",
358 qry, GetTitle(), GetName(), fSelecImp->GetTitle(),
359 range.Data());
360 }
361
362 // We are done, if not full dump
363 if (!full) return;
364
365 // Time information
366 Float_t elapsed = (fProcTime > 0.) ? fProcTime
367 : (Float_t)(fEnd.Convert() - fStart.Convert());
368 Printf("+++ started: %s", fStart.AsString());
369 if (fPrepTime > 0.)
370 Printf("+++ prepare: %.3f sec", fPrepTime);
371 Printf("+++ init: %.3f sec", fInitTime);
372 Printf("+++ process: %.3f sec (CPU time: %.1f sec)", elapsed, fUsedCPU);
373 if (fNumMergers > 0) {
374 Printf("+++ merge: %.3f sec (%d mergers)", fMergeTime, fNumMergers);
375 } else {
376 Printf("+++ merge: %.3f sec ", fMergeTime);
377 }
378 if (fRecvTime > 0.)
379 Printf("+++ transfer: %.3f sec", fRecvTime);
380 if (fTermTime > 0.)
381 Printf("+++ terminate: %.3f sec", fTermTime);
382
383 // Number of events processed, rate, size
384 Double_t rate = 0.0;
385 if (fEntries > -1 && elapsed > 0)
386 rate = fEntries / (Double_t)elapsed ;
387 Float_t size = ((Float_t)fBytes) / TMath::Power(2.,20.);
388 Printf("+++ processed: %lld events (size: %.3f MBs)", fEntries, size);
389 Printf("+++ rate: %.1f evts/sec", rate);
390
391 Printf("+++ # workers: %d ", fNumWrks);
392
393 // Package information
394 if (fParList.Length() > 1)
395 Printf("+++ packages: %s", fParList.Data());
396
397 // Result information
398 TString res = fResultFile;
399 if (!fArchived) {
400 Int_t dq = res.Index("queries");
401 if (dq > -1) {
402 res.Remove(0,res.Index("queries"));
403 res.Insert(0,"<PROOF_SandBox>/");
404 }
405 if (res.BeginsWith("-")) {
406 res = (fStatus == kAborted) ? "not available" : "sent to client";
407 }
408 }
409 if (res.Length() > 1)
410 Printf("+++ results: %s", res.Data());
411
412 if (fOutputList && fOutputList->GetSize() > 0)
413 Printf("+++ outlist: %d objects", fOutputList->GetSize());
414}
415
416////////////////////////////////////////////////////////////////////////////////
417/// To support browsing of the results.
418
420{
421 if (fOutputList)
422 b->Add(fOutputList, fOutputList->Class(), "OutputList");
423}
424
425////////////////////////////////////////////////////////////////////////////////
426/// Set / change the input list.
427/// The flag 'adopt' determines whether the list is adopted (default)
428/// or cloned. If adopted, object ownership is transferred to this object.
429/// The internal fInputList will always be owner of its objects.
430
432{
433 if (!in || in != fInputList)
435
436 if (in && in != fInputList) {
437 if (!adopt) {
438 fInputList = (TList *) (in->Clone());
439 } else {
440 fInputList = new TList;
441 TIter nxi(in);
442 TObject *o = 0;
443 while ((o = nxi()))
444 fInputList->Add(o);
445 in->SetOwner(kFALSE);
446 }
448 }
449}
450
451////////////////////////////////////////////////////////////////////////////////
452/// Set / change the output list.
453/// The flag 'adopt' determines whether the list is adopted (default)
454/// or cloned. If adopted, object ownership is transferred to this object.
455/// The internal fOutputList will always be owner of its objects.
456
458{
459 if (!out) {
461 return;
462 }
463
464 if (out && out != fOutputList) {
465 TObject *o = 0;
466 if (fOutputList) {
467 TIter nxoo(fOutputList);
468 while ((o = nxoo())) {
469 if (out->FindObject(o)) fOutputList->Remove(o);
470 }
472 }
473 if (!adopt) {
474 fOutputList = (TList *) (out->Clone());
475 } else {
476 fOutputList = new TList;
477 TIter nxo(out);
478 o = 0;
479 while ((o = nxo()))
480 fOutputList->Add(o);
481 out->SetOwner(kFALSE);
482 }
484 }
485}
486
487////////////////////////////////////////////////////////////////////////////////
488/// Compare two query result instances for equality.
489/// Session name and query number are compared.
490
492{
493 if (!strcmp(qr1.GetTitle(), qr2.GetTitle()))
494 if (qr1.GetSeqNum() == qr2.GetSeqNum())
495 return kTRUE;
496 return kFALSE;
497}
498
499////////////////////////////////////////////////////////////////////////////////
500/// Return TRUE if reference ref matches.
501
503{
504 TString lref; lref.Form("%s:%s", GetTitle(), GetName());
505
506 if (lref == ref)
507 return kTRUE;
508
509 return kFALSE;
510}
511
512////////////////////////////////////////////////////////////////////////////////
513/// Return first instance of class 'classname' in the input list.
514/// Useful to access TDSet, TEventList, ...
515
516TObject *TQueryResult::GetInputObject(const char *classname) const
517{
518 TObject *o = 0;
519 if (classname && fInputList) {
520 TIter nxi(fInputList);
521 while ((o = nxi()))
522 if (!strncmp(o->ClassName(), classname, strlen(classname)))
523 return o;
524 }
525
526 // Not found
527 return o;
528}
#define SafeDelete(p)
Definition RConfig.hxx:537
#define b(i)
Definition RSha256.hxx:100
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
const Ssiz_t kNPOS
Definition RtypesCore.h:124
const Bool_t kFALSE
Definition RtypesCore.h:101
long Long_t
Definition RtypesCore.h:54
bool Bool_t
Definition RtypesCore.h:63
double Double_t
Definition RtypesCore.h:59
long long Long64_t
Definition RtypesCore.h:80
float Float_t
Definition RtypesCore.h:57
const Bool_t kTRUE
Definition RtypesCore.h:100
const char Option_t
Definition RtypesCore.h:66
#define ClassImp(name)
Definition Rtypes.h:364
Bool_t operator==(const TQueryResult &qr1, const TQueryResult &qr2)
Compare two query result instances for equality.
Int_t gDebug
Definition TROOT.cxx:592
void Printf(const char *fmt,...)
@ kReadPermission
Definition TSystem.h:47
R__EXTERN TSystem * gSystem
Definition TSystem.h:559
T1 fFirst
Definition X11Events.mm:86
Using a TBrowser one can browse all ROOT objects.
Definition TBrowser.h:37
virtual void SetOwner(Bool_t enable=kTRUE)
Set whether this collection is the owner (enable==true) of its content.
virtual TObject * Clone(const char *newname="") const
Make a clone of an collection using the Streamer facility.
virtual Int_t GetSize() const
Return the capacity of the collection, i.e.
void Set()
Set Date/Time to current time as reported by the system.
Definition TDatime.cxx:289
UInt_t Convert(Bool_t toGMT=kFALSE) const
Convert fDatime from TDatime format to the standard time_t format.
Definition TDatime.cxx:182
const char * AsString() const
Return the date & time as a string (ctime() format).
Definition TDatime.cxx:102
A doubly linked list.
Definition TList.h:38
virtual void Add(TObject *obj)
Definition TList.h:81
virtual TObject * Remove(TObject *obj)
Remove object from the list.
Definition TList.cxx:822
virtual TObject * FindObject(const char *name) const
Find an object in this list using its name.
Definition TList.cxx:578
virtual void Delete(Option_t *option="")
Remove all objects from the list AND delete all heap based objects.
Definition TList.cxx:470
Class supporting a collection of lines with C++ code.
Definition TMacro.h:31
virtual TObjString * AddLine(const char *text)
Add line with text in the list of lines of this macro.
Definition TMacro.cxx:141
virtual Int_t ReadFile(const char *filename)
Read lines in filename in this macro.
Definition TMacro.cxx:338
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
Definition TNamed.cxx:164
virtual void SetName(const char *name)
Set the name of the TNamed.
Definition TNamed.cxx:140
virtual const char * GetTitle() const
Returns title of object.
Definition TNamed.h:48
virtual const char * GetName() const
Returns name of object.
Definition TNamed.h:47
Mother of all ROOT objects.
Definition TObject.h:41
virtual const char * GetName() const
Returns name of object.
Definition TObject.cxx:429
virtual const char * ClassName() const
Returns name of class to which the object belongs.
Definition TObject.cxx:200
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition TObject.cxx:949
virtual const char * GetTitle() const
Returns title of object.
Definition TObject.cxx:473
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
Definition TObject.cxx:937
A container class for query results.
virtual void SetOutputList(TList *out, Bool_t adopt=kTRUE)
Set / change the output list.
TString fOptions
processing options + aclic mode (< opt >#< aclic_mode >)
void AddLogLine(const char *logline)
Fill log file.
TDatime fStart
time when processing started
Long64_t fFirst
first entry processed
Int_t GetSeqNum() const
TDatime fEnd
time when processing ended
TMacro * fSelecHdr
selector header file
void SetArchived(const char *archfile)
Set (or update) query in archived state.
virtual void RecordEnd(EQueryStatus status, TList *outlist=0)
End of query settings.
Bool_t Matches(const char *ref)
Return TRUE if reference ref matches.
TMacro * GetSelecImp() const
TQueryResult * CloneInfo()
Return an instance of TQueryResult containing only the local info fields, i.e.
Bool_t fArchived
whether the query has been archived
void SaveSelector(const char *selec)
Save the selector header and implementation into the dedicated TMacro instances.
TList * fInputList
input list; contains also data sets, entry list, ...
void Print(Option_t *opt="") const
Print query content. Use opt = "F" for a full listing.
virtual void SetProcessInfo(Long64_t ent, Float_t cpu=0., Long64_t siz=-1, Float_t inittime=0., Float_t proctime=0.)
Set processing info.
Float_t fProcTime
Processing time (seconds) (millisec precision)
Bool_t fDraw
true if draw action query
Int_t fNumMergers
Number of submergers.
virtual Bool_t IsDone() const
virtual void SetInputList(TList *in, Bool_t adopt=kTRUE)
Set / change the input list.
TObject * GetInputObject(const char *classname) const
Return first instance of class 'classname' in the input list.
virtual ~TQueryResult()
Destructor.
TString fParList
colon-separated list of PAR loaded at fStart
TMacro * GetSelecHdr() const
Bool_t fFinalized
whether Terminate has been run
Float_t fRecvTime
Transfer-to-client time (seconds) (millisec precision)
TList * fOutputList
output list
Float_t fTermTime
Terminate time (seconds) (millisec precision)
Float_t fPrepTime
Prepare time (seconds) (millisec precision)
void AddInput(TObject *obj)
Add obj to the input list.
EQueryStatus fStatus
query status
Float_t fUsedCPU
real CPU time used (seconds)
Int_t fSeqNum
query unique sequential number
TMacro * fSelecImp
selector implementation file
Long64_t fBytes
number of bytes processed
TString fResultFile
URL of the file where results have been archived.
TMacro * fLogFile
file with log messages from the query
Long64_t fEntries
number of entries processed
void Browse(TBrowser *b=0)
To support browsing of the results.
Float_t fMergeTime
Merging time (seconds) (millisec precision)
Int_t fNumWrks
Number of workers at start.
TString fLibList
blank-separated list of libs loaded at fStart
Float_t fInitTime
Initialization time (seconds) (millisec precision)
static const char * GetMacroPath()
Get macro search path. Static utility function.
Definition TROOT.cxx:2720
Regular expression class.
Definition TRegexp.h:31
static Bool_t IsStandardDraw(const char *selec)
Find out if this is a standard selection used for Draw actions (either TSelectorDraw,...
Basic string class.
Definition TString.h:136
Ssiz_t Length() const
Definition TString.h:410
TString & Insert(Ssiz_t pos, const char *s)
Definition TString.h:649
Int_t Atoi() const
Return integer value of string.
Definition TString.cxx:1946
const char * Data() const
Definition TString.h:369
Bool_t BeginsWith(const char *s, ECaseCompare cmp=kExact) const
Definition TString.h:615
TString & Remove(Ssiz_t pos)
Definition TString.h:673
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString.
Definition TString.cxx:2336
void Form(const char *fmt,...)
Formats a string using a printf style format descriptor.
Definition TString.cxx:2314
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
Definition TString.h:639
virtual int GetPid()
Get process id.
Definition TSystem.cxx:710
virtual TString SplitAclicMode(const char *filename, TString &mode, TString &args, TString &io) const
This method split a filename of the form:
Definition TSystem.cxx:4252
virtual Bool_t AccessPathName(const char *path, EAccessMode mode=kFileExists)
Returns FALSE if one can access a file using the specified access mode.
Definition TSystem.cxx:1296
virtual const char * BaseName(const char *pathname)
Base name of a file name. Base name of /user/root is root.
Definition TSystem.cxx:935
virtual char * Which(const char *search, const char *file, EAccessMode mode=kFileExists)
Find location of file in a search path.
Definition TSystem.cxx:1546
virtual const char * GetLibraries(const char *regexp="", const char *option="", Bool_t isRegexp=kTRUE)
Return a space separated list of loaded shared libraries.
Definition TSystem.cxx:2142
The TTimeStamp encapsulates seconds and ns since EPOCH.
Definition TTimeStamp.h:71
LongDouble_t Power(LongDouble_t x, LongDouble_t y)
Definition TMath.h:685
Definition first.py:1