68 class TPacketizer::TFileStat :
public TObject {
79 Bool_t IsDone()
const {
return fIsDone;}
80 void SetDone() {fIsDone =
kTRUE;}
81 TFileNode *GetNode()
const {
return fNode;}
83 Long64_t GetNextEntry()
const {
return fNextEntry;}
84 void MoveNextEntry(
Long64_t step) {fNextEntry += step;}
88 TPacketizer::TFileStat::TFileStat(TFileNode *node,
TDSetElement *elem)
89 : fIsDone(
kFALSE), fNode(node), fElement(elem), fNextEntry(elem->GetFirst())
96 class TPacketizer::TFileNode :
public TObject {
108 TFileNode(
const char *name);
109 ~TFileNode() {
delete fFiles;
delete fActFiles; }
111 void IncMySlaveCnt() { fMySlaveCnt++; }
112 void IncSlaveCnt(
const char *slave) {
if (fNodeName != slave) fSlaveCnt++; }
113 void DecSlaveCnt(
const char *slave) {
if (fNodeName != slave) fSlaveCnt--;
R__ASSERT(fSlaveCnt >= 0); }
114 Int_t GetSlaveCnt()
const {
return fMySlaveCnt + fSlaveCnt;}
115 Int_t GetNumberOfActiveFiles()
const {
return fActFiles->
GetSize(); }
118 const char *
GetName()
const {
return fNodeName.
Data(); }
122 TFileStat *f =
new TFileStat(
this,elem);
124 if (fUnAllocFileNext == 0) fUnAllocFileNext = fFiles->
First();
129 TObject *next = fUnAllocFileNext;
133 fActFiles->
Add(next);
134 if (fActFileNext == 0) fActFileNext = fActFiles->
First();
137 fUnAllocFileNext = fFiles->
After(fUnAllocFileNext);
140 return (TFileStat *)
next;
147 if (fActFileNext != 0) {
148 fActFileNext = fActFiles->
After(fActFileNext);
149 if (fActFileNext == 0) fActFileNext = fActFiles->
First();
152 return (TFileStat *)
next;
157 if (fActFileNext == file) fActFileNext = fActFiles->
After(file);
159 if (fActFileNext == 0) fActFileNext = fActFiles->
First();
166 const TFileNode *obj =
dynamic_cast<const TFileNode*
>(other);
168 Error(
"Compare",
"input is not a TPacketizer::TFileNode object");
172 Int_t myVal = GetSlaveCnt();
173 Int_t otherVal = obj->GetSlaveCnt();
174 if (myVal < otherVal) {
176 }
else if (myVal > otherVal) {
185 std::cout <<
"OBJ: " <<
IsA()->
GetName() <<
"\t" << fNodeName
186 <<
"\tMySlaveCount " << fMySlaveCnt
187 <<
"\tSlaveCount " << fSlaveCnt << std::endl;
192 fUnAllocFileNext = fFiles->
First();
201 TPacketizer::TFileNode::TFileNode(
const char *name)
202 : fNodeName(name), fFiles(new
TList), fUnAllocFileNext(0),fActFiles(new
TList),
203 fActFileNext(0), fMySlaveCnt(0), fSlaveCnt(0)
219 TFileNode *fFileNode;
224 TSlaveStat(
TSlave *slave);
227 TFileNode *GetFileNode()
const {
return fFileNode; }
229 void SetFileNode(TFileNode *node) { fFileNode = node; }
233 TPacketizer::TSlaveStat::TSlaveStat(
TSlave *slave)
234 : fFileNode(0), fCurFile(0), fCurElem(0)
243 TPacketizer::TSlaveStat::~TSlaveStat()
257 fStatus->SetLastProcTime(0.);
265 Error(
"AddProcessed",
"status arg undefined");
281 PDB(kPacketizer,1)
Info(
"TPacketizer",
"Enter (first %lld, num %lld)", first, num);
294 Error(
"TPacketizer",
"No progress status");
300 if (maxSlaveCnt < 0) {
301 Warning(
"TPacketizer",
"PROOF_MaxSlavesPerNode must be positive");
310 Warning(
"TPacketizer",
"PROOF_MaxSlavesPerNode must be positive");
313 maxSlaveCnt = (
Long_t) mxslcnt;
318 maxSlaveCnt =
gEnv->
GetValue(
"Packetizer.MaxWorkersPerNode", slaves->GetSize());
321 if (maxSlaveCnt > 0) {
324 Info(
"TPacketizer",
"setting max number of workers per node to %ld",
fMaxSlaveCnt);
365 if (host.
Contains(
"localhost") || host ==
"127.0.0.1") {
373 node =
new TFileNode(host);
385 Info(
"TPacketizer",
"Initial number of workers: %d", nwrks);
390 Int_t validateMode = 0;
396 "processing subset of entries: validating by file? %s", byfile ?
"yes":
"no");
409 PDB(kPacketizer,2)
Info(
"TPacketizer",
"processing range: first %lld, num %lld", first, num);
429 Info(
"TPacketizer",
" --> first %lld, num %lld (cur %lld)", eFirst, eNum, cur);
433 if (cur + eNum < first) {
436 Info(
"TPacketizer",
" --> skip element cur %lld", cur);
441 if (num != -1 && (first+num <= cur)) {
444 Info(
"TPacketizer",
" --> drop element cur %lld", cur);
449 if (cur <= first || (num != -1 && (first+num <= cur+eNum))) {
454 e->
SetFirst( eFirst + (first - cur) );
457 Info(
"TPacketizer",
" --> adjust start %lld and end %lld",
458 eFirst + (first - cur), first + num - cur);
461 if (num != -1 && (first+num <= cur+eNum)) {
466 Info(
"TPacketizer",
" --> adjust end %lld", first + num - cur);
473 Info(
"TPacketizer",
" --> increment 'cur' by %lld", eNum);
488 eNum = evl ? evl->
GetN() : eNum;
494 Info(
"TPacketizer",
" --> next cur %lld", cur);
510 if (host.
Contains(
"localhost") || host ==
"127.0.0.1") {
518 node =
new TFileNode( host );
529 Info(
"TPacketizer",
"processing %lld entries in %d files on %d hosts",
539 Info(
"TPacketizer",
"no valid or non-empty file found: setting invalid");
552 Long_t packetAsAFraction = 20;
554 Info(
"Process",
"using alternate fraction of query time as a packet Size: %ld",
578 PDB(kPacketizer,1)
Info(
"TPacketizer",
"Return");
603 Error(
"AddWorkers",
"Null list of new workers!");
611 while (( sl = dynamic_cast<TSlave*>(
next()) ))
643 file = node->GetNextUnAlloc();
647 file = node->GetNextUnAlloc();
669 std::cout <<
"TPacketizer::NextUnAllocNode()" << std::endl;
675 PDB(kPacketizer,1)
Info(
"NextUnAllocNode",
"reached workers per node limit (%ld)",
700 file = node->GetNextActive();
714 Printf(
"TPacketizer::NextActiveNode : ----------------------");
721 Info(
"NextActiveNode",
"reached workers per node limit (%ld)",
fMaxSlaveCnt);
733 TFileNode *node = file->GetNode();
735 node->RemoveActive(file);
759 while ((fn = (TFileNode*) files.
Next()) != 0) {
765 while ((key = slaves.
Next()) != 0) {
770 slstat->SetFileNode(fn);
773 slstat->fCurFile = 0;
775 Warning(
"Reset",
"TSlaveStat associated to key '%s' is NULL", key->
GetName());
798 Info(
"ValidateFiles",
"socket added to monitor: %p (%s)",
803 Info(
"ValidateFiles",
804 "mon: %p, wrk: %p, sck: %p", &mon, slm, slm->
GetSocket());
815 TString msg(
"Validating files");
832 Error(
"ValidateFiles",
"TSlaveStat associated to slave '%s' is NULL", s->GetName());
839 if ( (node = slstat->GetFileNode()) != 0 ) {
842 slstat->SetFileNode(0);
855 slstat->fCurFile = file;
858 if (entries < 0 || strlen(elem->
GetTitle()) <= 0) {
860 file->GetNode()->IncSlaveCnt(slstat->GetName());
867 s->GetSocket()->Send( m );
870 Info(
"ValidateFiles",
871 "sent to worker-%s (%s) via %p GETENTRIES on %s %s %s %s",
872 s->GetOrdinal(), s->GetName(), s->GetSocket(),
883 Error(
"ValidateFiles",
884 "first (%lld) higher then number of entries (%lld) in %s",
887 slstat->fCurFile->SetDone();
891 if (elem->
GetNum() == -1) {
894 Warning(
"ValidateFiles",
"num (%lld) + first (%lld) larger then number of"
900 Info(
"ValidateFiles",
901 "found elem '%s' with %lld entries", elem->
GetFileName(), entries);
916 if (byfile && maxent > 0 && totent > 0) {
918 Long64_t nrestf = (maxent - totent) * nopenf / totent ;
919 if (nrestf <= 0 && maxent > totent) nrestf = 1;
922 Info(
"ValidateFiles",
"{%lld, %lld, %lld): needs to validate %lld more files",
923 maxent, totent, nopenf, nrestf);
925 while ((slm = (
TSlave *) si.
Next()) && nrestf--) {
931 Info(
"ValidateFiles",
"no need to validate more files");
940 Info(
"ValidateFiles",
"waiting for %d workers:", mon.
GetActive());
945 Info(
"ValidateFiles",
"found sck: %p", s);
956 Error(
"ValidateFiles",
"selection has been interrupted - STOP");
963 PDB(kPacketizer,3)
Info(
"ValidateFiles",
"select returned: %p", sock);
968 Error(
"ValidateFiles",
"worker-%s (%s) got invalid - STOP",
977 if ( sock->
Recv(reply) <= 0 ) {
981 Error(
"ValidateFiles",
"Recv failed! for worker-%s (%s)",
991 Error(
"ValidateFiles",
"kPROOF_FATAL from worker-%s (%s)",
1004 slavestat->fCurFile->GetNode()->DecSlaveCnt(slavestat->GetName());
1007 (*reply) >> entries;
1012 (*reply) >> objname;
1017 if ( entries > 0 ) {
1025 Error(
"ValidateFiles",
"first (%lld) higher then number of entries (%lld) in %s",
1029 slavestat->fCurFile->SetDone();
1034 if ( e->
GetNum() == -1 ) {
1037 Error(
"ValidateFiles",
1038 "num (%lld) + first (%lld) larger then number of keys/entries (%lld) in %s",
1069 PDB(kPacketizer,3)
Info(
"ValidateFiles",
" %lld events validated", totent);
1072 if (maxent < 0 || ((totent < maxent) && !byfile))
1093 while ( (el = dynamic_cast<TDSetElement*> (
next())) ) {
1095 el->SetTDSetOffset(offset);
1109 if ( slstat == 0 )
return 0;
1111 return slstat->GetEntriesProcessed();
1126 while ((key = nxw()) != 0) {
1128 if (slstat && slstat->GetProgressStatus() && slstat->GetEntriesProcessed() > 0) {
1130 currate += slstat->GetProgressStatus()->GetCurrentRate();
1160 if ( slstat->fCurElem != 0 ) {
1161 Double_t latency = 0., proctime = 0., proccpu = 0.;
1165 Long64_t numev = slstat->fCurElem->GetNum();
1178 numev = status->
GetEntries() - slstat->GetEntriesProcessed();
1179 progress = slstat->AddProcessed(status);
1184 totev = status->GetEntries();
1190 Error(
"GetNextPacket",
"no status came in the kPROOF_GETPACKET message");
1193 (*r) >> latency >> proctime >> proccpu;
1200 numev = totev - slstat->GetEntriesProcessed();
1201 if (numev > 0) slstat->GetProgressStatus()->IncEntries(numev);
1202 if (bytesRead > 0) slstat->GetProgressStatus()->IncBytesRead(bytesRead);
1203 if (numev > 0 || bytesRead > 0) slstat->GetProgressStatus()->SetLastUpdate();
1212 Info(
"GetNextPacket",
"worker-%s (%s): %lld %7.3lf %7.3lf %7.3lf %lld",
1214 numev, latency, proctime, proccpu, bytesRead);
1218 numev, latency, proctime, proccpu, bytesRead);
1220 slstat->fCurElem = 0;
1226 firstPacket =
kTRUE;
1236 TFileStat *file = slstat->fCurFile;
1238 if ( file != 0 && file->IsDone() ) {
1239 file->GetNode()->DecSlaveCnt(slstat->GetName());
1242 file->GetElement()->GetFileName(),
kFALSE);
1246 slstat->fCurFile = file;
1251 if (slstat->GetFileNode() != 0) {
1254 slstat->SetFileNode(0);
1268 if (!file)
return 0;
1270 slstat->fCurFile = file;
1271 file->GetNode()->IncSlaveCnt(slstat->GetName());
1274 file->GetNode()->GetName(),
1275 file->GetElement()->GetFileName(),
kTRUE);
1282 if (num < 1) num = 1;
1284 Long64_t first = file->GetNextEntry();
1287 if ( first + num >= last ) {
1295 file->MoveNextEntry(num);
1301 slstat->fCurElem->SetEntryList(base->
GetEntryList(), first, num);
1312 return slstat->fCurElem;
1323 while ((key = nxw())) {
1325 if (wrkstat && wrkstat->fCurFile) actw++;
const char * GetHost() const
virtual Int_t GetEntries() const
virtual const char * GetTitle() const
Returns title of object.
const char * GetOrdinal() const
Long64_t GetEntries(Bool_t istree=kTRUE, Bool_t openfile=kTRUE)
Returns number of entries in tree or objects in file.
void Add(THist< DIMENSION, PRECISIONA > &to, THist< DIMENSION, PRECISIONB > &from)
TSocket * GetSocket() const
void SetProtocol(const char *proto, Bool_t setDefaultPort=kFALSE)
Set protocol and, optionally, change the port accordingly.
ClassImp(TSeqCollection) Int_t TSeqCollection TIter next(this)
Return index of object in collection.
virtual Bool_t IsValid() const
Int_t GetActiveWorkers()
Return the number of workers still processing.
virtual Int_t Send(const TMessage &mess)
Send a TMessage object.
void SetTDSetOffset(Long64_t offset)
This class represents a WWW compatible URL.
virtual Int_t Recv(TMessage *&mess)
Receive a TMessage object.
virtual void SetOwner(Bool_t enable=kTRUE)
Set whether this collection is the owner (enable==true) of its content.
const char * GetProtocol() const
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
Long64_t GetBytesRead() const
void SetLastUpdate(Double_t updtTime=0)
Update time stamp either with the passed value (if > 0) or with the current time. ...
void Add(TObject *obj)
This function may not be used (but we need to provide it since it is a pure virtual in TCollection)...
virtual void Add(TSocket *sock, Int_t interest=kRead)
Add socket to the monitor's active list.
Float_t GetCurrentRate(Bool_t &all)
Get Estimation of the current rate; just summing the current rates of the active workers.
void RemoveActiveNode(TFileNode *)
Remove node from the list of actives.
TList * GetListOfActives() const
Returns a list with all active sockets.
virtual ~TPacketizer()
Destructor.
virtual TObject * FindObject(const char *name) const
Find an object in this list using its name.
void Print(Option_t *options="") const
Print a TDSetElement. When option="a" print full data.
virtual void DeActivateAll()
De-activate all activated sockets.
virtual Bool_t HandleTimer(TTimer *timer)
Send progress message to client.
Long64_t GetEntriesProcessed() const
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Double_t GetProcTime() const
const char * GetObjName() const
virtual void Sort(Bool_t order=kSortAscending)
Sort linked list.
virtual Int_t GetN() const
const char * Data() const
Double_t GetCPUTime() const
Long64_t GetTDSetOffset() const
TDSetElement * GetNextPacket(TSlave *sl, TMessage *r)
Get next packet.
virtual TObject * After(const TObject *obj) const
Returns the object after object obj.
TDSetElement * CreateNewPacket(TDSetElement *base, Long64_t first, Long64_t num)
Creates a new TDSetElement from from base packet starting from the first entry with num entries...
virtual void DeActivate(TSocket *sock)
De-activate a socket.
void IncEntries(Long64_t entries=1)
void IncBytesRead(Long64_t bytesRead)
virtual void AddAll(const TCollection *col)
TList * GetListOfElements() const
void Info(const char *location, const char *msgfmt,...)
TObject * GetValue(const char *keyname) const
Returns a pointer to the value associated with keyname as name of the key.
void Reset()
Reset the internal datastructure for packet distribution.
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
void Error(const char *location, const char *msgfmt,...)
TSocket * Select()
Return pointer to socket for which an event is waiting.
TObject * GetParameter(const char *par) const
Get specified parameter.
TProofProgressStatus * fProgressStatus
Long64_t GetFirst() const
virtual Bool_t IsSortable() const
TObject * FindObject(const char *keyname) const
Check if a (key,value) pair exists with keyname as name of the key.
virtual void Print(Option_t *option="") const
This method must be overridden when a class wants to print itself.
const char * GetName() const
Returns name of object.
void SetLastEntries(Long64_t entries)
TSocket * GetSocket() const
void RemoveUnAllocNode(TFileNode *)
Remove unallocated node.
void SendDataSetStatus(const char *msg, UInt_t n, UInt_t tot, Bool_t st)
Send or notify data set status.
void RemoveActive(TFileStat *file)
Remove file from the list of actives.
const char * GetFileName() const
R__EXTERN TSystem * gSystem
virtual Int_t GetValue(const char *name, Int_t dflt)
Returns the integer value for a resource.
virtual TObject * Remove(TObject *obj)
Remove object from the list.
const char * GetHostFQDN() const
Return fully qualified domain name of url host.
char * Form(const char *fmt,...)
TObject * GetEntryList() const
TFileNode * NextUnAllocNode()
Get next unallocated node.
A TEventList object is a list of selected events (entries) in a TTree.
TFileStat * GetNextUnAlloc(TFileNode *node=0)
Get next unallocated file.
virtual const char * GetName() const
Returns name of object.
void Reset(Detail::TBranchProxy *x)
void Warning(const char *location, const char *msgfmt,...)
Long64_t GetEntries() const
virtual void Activate(TSocket *sock)
Activate a de-activated socket.
void DeleteValues()
Remove all (key,value) pairs from the map AND delete the values when they are allocated on the heap...
ClassImp(TPacketizer) TPacketizer
Constructor.
virtual void Print(Option_t *option="") const
Default print for collections, calls Print(option, 1).
const char * GetDataSet() const
void SetHost(const char *host)
R__EXTERN TProof * gProof
Int_t AddWorkers(TList *workers)
Adds new workers. Returns the number of workers added, or -1 on failure.
virtual Int_t GetSize() const
Int_t GetActive(Long_t timeout=-1) const
Return number of sockets in the active list.
virtual const char * GetName() const
Returns name of object.
virtual const char * HostName()
Return the system's host name.
TMap implements an associative array of (key,value) pairs using a THashTable for efficient retrieval ...
void SetNum(Long64_t num)
virtual void Clear(Option_t *option="")
Remove all objects from the list.
Int_t GetProtocol() const
void ValidateFiles(TDSet *dset, TList *slaves, Long64_t maxent=-1, Bool_t byfile=kFALSE)
Check existence of file/dir/tree an get number of entries.
virtual Long64_t GetN() const
Mother of all ROOT objects.
virtual TObject * First() const
Return the first object in the list. Returns 0 when list is empty.
R__EXTERN TProofServ * gProofServ
virtual void Add(TObject *obj)
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
virtual Int_t Compare(const TObject *obj) const
Compare abstract method.
ClassImp(TSlaveInfo) Int_t TSlaveInfo const TSlaveInfo * si
Used to sort slaveinfos by ordinal.
TFileStat * GetNextActive()
Get next active file.
void SetFirst(Long64_t first)
virtual void SetTitle(const char *title="")
Change (i.e. set) the title of the TNamed.
A List of entry numbers in a TTree or TChain.
virtual TProofProgressStatus * AddProcessed(TProofProgressStatus *st)=0
const char * GetDirectory() const
Return directory where to look for object.
TFileNode * NextActiveNode()
Get next active node.
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.