46 const int kIncremental = 0;
47 const int kReplaceImmediately = 1;
48 const int kReplaceWait = 2;
58 while( (key = (
TKey*)nextkey()) ) {
65 if (R__NeedInitialMerge(subdir)) {
83 while( (key = (
TKey*)nextkey()) ) {
90 R__DeleteObject(subdir,withReset);
109 if (destination==0 || source==0)
return;
113 while( (key = (
TKey*)nextkey()) ) {
117 if (!source_subdir) {
121 if (!destination_subdir) {
122 destination_subdir = destination->
mkdir(key->GetName());
124 R__MigrateKey(destination,source);
126 TKey *oldkey = destination->
GetKey(key->GetName());
131 TKey *newkey =
new TKey(destination,*key,0 );
150 ClientInfo() : fFile(0), fLocalName(), fContactsCount(0), fTimeSincePrevContact(0) {}
151 ClientInfo(
const char *filename,
UInt_t clientId) : fFile(0), fContactsCount(0), fTimeSincePrevContact(0) {
162 R__MigrateKey(fFile,file);
176 struct ParallelFileMerger :
public TObject 178 typedef std::vector<ClientInfo> ClientColl_t;
181 TBits fClientsContact;
183 ClientColl_t fClients;
187 ParallelFileMerger(
const char *filename,
Bool_t writeCache =
kFALSE) : fFilename(filename), fNClientsContact(0), fMerger(
kFALSE,
kTRUE)
196 ~ParallelFileMerger()
200 for(
unsigned int f = 0 ;
f < fClients.size(); ++
f) {
201 fprintf(stderr,
"Client %d reported %u times\n",
f,fClients[
f].fContactsCount);
203 for( ClientColl_t::iterator iter = fClients.begin();
204 iter != fClients.end();
214 return fFilename.
Hash();
232 R__DeleteObject(input,
kTRUE);
241 for(
unsigned int f = 0 ;
f < fClients.size(); ++
f) {
248 for(
unsigned int f = 0 ;
f < fClients.size(); ++
f) {
249 if (fClients[
f].fFile) {
250 R__DeleteObject(fClients[
f].fFile,
kTRUE);
254 R__DeleteObject(file,
kTRUE);
260 fNClientsContact = 0;
261 fClientsContact.
Clear();
277 if (fClients.size()==0) {
284 for(
unsigned int c = 0 ;
c < fClients.size(); ++
c) {
285 sum += fClients[
c].fTimeSincePrevContact;
286 sum2 += fClients[
c].fTimeSincePrevContact*fClients[
c].fTimeSincePrevContact;
288 Double_t avg = sum / fClients.size();
302 Float_t cut = clientThreshold * fClients.size();
303 return fClientsContact.
CountBits() > cut || fNClientsContact > 2*cut;
312 if (fClients.size() < clientId+1) {
313 fClients.push_back( ClientInfo(fFilename,clientId) );
315 fClients[clientId].Set(file);
321 void parallelMergeServer(
bool cache =
false) {
340 kStartConnection = 0,
346 printf(
"fastMergeServerHist ready to accept connections\n");
356 if (clientCount > 100) {
357 printf(
"only accept 100 clients connections\n");
362 client->
Send(clientIndex, kStartConnection);
363 client->
Send(kProtocolVersion, kProtocol);
367 printf(
"Accept %d connections\n",clientCount);
375 Error(
"fastMergeServer",
"The client did not send a message\n");
379 printf(
"Client %d: %s\n", clientCount, str);
381 printf(
"Client %d: bytes recv = %d, bytes sent = %d\n", clientCount, s->
GetBytesRecv(),
385 if (mon->
GetActive() == 0 || clientCount == 0) {
386 printf(
"No more active clients... stopping\n");
403 const Float_t clientThreshold = 0.75;
405 ParallelFileMerger *info = (ParallelFileMerger*)mergers.
FindObject(filename);
407 info =
new ParallelFileMerger(filename,cache);
411 if (R__NeedInitialMerge(
transient)) {
412 info->InitialMerge(
transient);
414 info->RegisterClient(clientId,
transient);
415 if (info->NeedMerge(clientThreshold)) {
417 Info(
"fastMergeServerHist",
"Merging input from %ld clients (%d)",info->fClients.size(),clientId);
424 printf(
"*** Unexpected message ***\n");
430 TIter next(&mergers);
431 ParallelFileMerger *info;
432 while ( (info = (ParallelFileMerger*)next()) ) {
433 if (info->NeedFinalMerge())
Merge incrementally all type of objects.
TClass * GetClass() const
virtual const char * GetName() const
Returns name of object.
std::string GetName(const std::string &scope_name)
void SetBufferOffset(Int_t offset=0)
virtual Bool_t IsValid() const
static long int sum(long int i)
virtual int GetPid()
Get process id.
virtual TList * GetListOfKeys() const
virtual void Remove(TSocket *sock)
Remove a socket from the monitor.
void Clear(Option_t *option="")
Clear the value.
Int_t GetActive(Long_t timeout=-1) const
Return number of sockets in the active list.
UInt_t Hash(const TString &s)
UInt_t GetBytesRecv() const
TFile * GetOutputFile() const
virtual Int_t Send(const TMessage &mess)
Send a TMessage object.
virtual void ReadTString(TString &s)
Read TString from TBuffer.
Double_t AsDouble() const
Bool_t TestBit(UInt_t f) const
virtual Int_t Recv(TMessage *&mess)
Receive a TMessage object.
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format...
virtual void Add(TSocket *sock, Int_t interest=kRead)
Add socket to the monitor's active list.
virtual TDirectory * mkdir(const char *name, const char *title="")
Create a sub-directory and return a pointer to the created directory.
UInt_t Hash(ECaseCompare cmp=kExact) const
Return hash value.
virtual TObject * FindObject(const char *name) const
Find an object in this list using its name.
void SumBuffer(Int_t bufsize)
Increment statistics for buffer sizes of objects in this file.
A TMemFile is like a normal TFile except that it reads and writes only from memory.
static TFile * Open(const char *name, Option_t *option="", const char *ftitle="", Int_t compress=1, Int_t netopt=0)
Create / open a file.
virtual void ReadLong64(Long64_t &l)
THashTable implements a hash table to store TObject's.
virtual void ReadInt(Int_t &i)
#define ClassDef(name, id)
virtual char * ReadString(char *s, Int_t max)
Read string from I/O buffer.
virtual Int_t WriteFile(Int_t cycle=1, TFile *f=0)
Write the encoded object supported by this key.
void Info(const char *location, const char *msgfmt,...)
virtual TList * GetList() const
Merge the input file with the content of the output file (if already exising).
Book space in a file, create I/O buffers, to fill them, (un)compress them.
virtual void Delete(Option_t *option="")
Delete an object from the file.
virtual Bool_t OutputFile(const char *url, Bool_t force)
Open merger output file.
void Error(const char *location, const char *msgfmt,...)
virtual TFile * GetFile() const
TSocket * Select()
Return pointer to socket for which an event is waiting.
virtual Bool_t AddFile(TFile *source, Bool_t own, Bool_t cpProgress)
Add the TFile to this file merger and give ownership of the TFile to this object (unless kFALSE is re...
virtual void Close(Option_t *opt="")
Close the socket.
R__EXTERN TSystem * gSystem
UInt_t GetBytesSent() const
virtual Int_t Write(const char *name=0, Int_t opt=0, Int_t bufsiz=0)
Write memory objects to this file.
This class provides file copy and merging services.
virtual TObject * Remove(TObject *obj)
Remove object from the list.
void Form(const char *fmt,...)
Formats a string using a printf style format descriptor.
void SetPrintLevel(Int_t level)
The ROOT global object gROOT contains a list of all defined classes.
Bool_t InheritsFrom(const char *cl) const
Return kTRUE if this class inherits from a class with name "classname".
virtual void SaveSelf(Bool_t=kFALSE)
TObject * FindObject(const char *name) const
Find object using its name.
virtual TKey * GetKey(const char *, Short_t=9999) const
ROOT::ResetAfterMergeFunc_t GetResetAfterMerge() const
Describe directory structure in memory.
The TTimeStamp encapsulates seconds and ns since EPOCH.
void Add(TObject *obj)
Add object to the hash table.
static TClass * GetClass(const char *name, Bool_t load=kTRUE, Bool_t silent=kFALSE)
Static method returning pointer to TClass of the specified class name.
Mother of all ROOT objects.
void Delete(Option_t *option="")
Remove all objects from the table AND delete all heap based objects.
virtual Bool_t PartialMerge(Int_t type=kAll|kIncremental)
Merge the files.
virtual TDirectory * GetDirectory(const char *namecycle, Bool_t printError=false, const char *funcname="GetDirectory")
Find a directory using apath.
UInt_t CountBits(UInt_t startBit=0) const
Return number of bits set to 1 starting at bit startBit.
Double_t Sqrt(Double_t x)
Only the objects with a MergeAfterReset member function.
void SetBitNumber(UInt_t bitnumber, Bool_t value=kTRUE)
A cache when writing files over the network.