]> git.uio.no Git - u/mrichter/AliRoot.git/blame - ANALYSIS/AliAnalysisDataContainer.cxx
Use the MCchain flag in GetChainForTestMode
[u/mrichter/AliRoot.git] / ANALYSIS / AliAnalysisDataContainer.cxx
CommitLineData
d3106602 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
15
16/* $Id$ */
17// Author: Andrei Gheata, 31/05/2006
18
19//==============================================================================
20// AliAnalysysDataContainer - Container of data of arbitrary type deriving
21// from TObject used for analysis. A container must be connected to the
22// output data slot of a single analysis task (producer) , but also as
23// input slot for possibly several other tasks (consumers). The connected
24// slots must enforce the same data type as the container (or a derived type).
25// A container becomes the owner of the contained data once this was produced.
26//
27// Containers should be defined by the analysis module using:
28//
29// AliAnalysisModule::AddContainer(const char *name, TClass *type);
30//
31// A container should be connected to a producer:
32
33// AliAnalysisModule::ConnectOutput(AliAnalysisTask *task,
34// AliAnalysisDataContainer *cont)
35// and to its consumers:
36//
37// AliAnalysisModule::ConnectInput(AliAnalysisTask *task, Int_t islot,
38// AliAnalysisDataContainer *cont)
39//
40// The container will create an implicit connection between the producer task
41// and all consumers, which will become sub-tasks of the producer.
42//
43//==============================================================================
44
c52c2132 45#include <Riostream.h>
46#include <TMethodCall.h>
11026a80 47
c52c2132 48#include <TClass.h>
9162405c 49#include <TSystem.h>
8d7d3b59 50#include <TFile.h>
c52c2132 51#include <TTree.h>
ca78991b 52#include <TH1.h>
c52c2132 53#include <TROOT.h>
d3106602 54
8d7d3b59 55#include "AliAnalysisManager.h"
d3106602 56#include "AliAnalysisDataContainer.h"
57#include "AliAnalysisDataSlot.h"
58#include "AliAnalysisTask.h"
59
c82bb898 60using std::endl;
61using std::cout;
d3106602 62ClassImp(AliAnalysisDataContainer)
63
64//______________________________________________________________________________
37a26056 65AliAnalysisDataContainer::AliAnalysisDataContainer() : TNamed(),
66 fDataReady(kFALSE),
67 fOwnedData(kFALSE),
c52c2132 68 fFileName(),
84fcd93f 69 fFolderName(),
8d7d3b59 70 fFile(NULL),
37a26056 71 fData(NULL),
72 fType(NULL),
73 fProducer(NULL),
74 fConsumers(NULL)
d3106602 75{
c52c2132 76// Dummy ctor.
d3106602 77}
37a26056 78
d3106602 79//______________________________________________________________________________
80AliAnalysisDataContainer::AliAnalysisDataContainer(const char *name, TClass *type)
37a26056 81 :TNamed(name,""),
82 fDataReady(kFALSE),
0355fc48 83 fOwnedData(kFALSE),
c52c2132 84 fFileName(),
84fcd93f 85 fFolderName(),
8d7d3b59 86 fFile(NULL),
37a26056 87 fData(NULL),
88 fType(type),
89 fProducer(NULL),
90 fConsumers(NULL)
d3106602 91{
c52c2132 92// Default constructor.
93 SetTitle(fType->GetName());
37a26056 94}
95
96//______________________________________________________________________________
97AliAnalysisDataContainer::AliAnalysisDataContainer(const AliAnalysisDataContainer &cont)
98 :TNamed(cont),
99 fDataReady(cont.fDataReady),
100 fOwnedData(kFALSE),
c52c2132 101 fFileName(cont.fFileName),
84fcd93f 102 fFolderName(cont.fFolderName),
8d7d3b59 103 fFile(NULL),
37a26056 104 fData(cont.fData),
c52c2132 105 fType(NULL),
37a26056 106 fProducer(cont.fProducer),
107 fConsumers(NULL)
108{
109// Copy ctor.
c52c2132 110 GetType();
37a26056 111 if (cont.fConsumers) {
112 fConsumers = new TObjArray(2);
113 Int_t ncons = cont.fConsumers->GetEntriesFast();
114 for (Int_t i=0; i<ncons; i++) fConsumers->Add(cont.fConsumers->At(i));
115 }
d3106602 116}
117
118//______________________________________________________________________________
119AliAnalysisDataContainer::~AliAnalysisDataContainer()
120{
121// Destructor. Deletes data ! (What happens if data is a container ???)
122 if (fData && fOwnedData) delete fData;
123 if (fConsumers) delete fConsumers;
124}
125
37a26056 126//______________________________________________________________________________
127AliAnalysisDataContainer &AliAnalysisDataContainer::operator=(const AliAnalysisDataContainer &cont)
128{
129// Assignment.
130 if (&cont != this) {
131 TNamed::operator=(cont);
132 fDataReady = cont.fDataReady;
84fcd93f 133 fOwnedData = kFALSE;
c52c2132 134 fFileName = cont.fFileName;
84fcd93f 135 fFolderName = cont.fFolderName;
8d7d3b59 136 fFile = NULL;
37a26056 137 fData = cont.fData;
c52c2132 138 GetType();
37a26056 139 fProducer = cont.fProducer;
140 if (cont.fConsumers) {
141 fConsumers = new TObjArray(2);
142 Int_t ncons = cont.fConsumers->GetEntriesFast();
143 for (Int_t i=0; i<ncons; i++) fConsumers->Add(cont.fConsumers->At(i));
144 }
145 }
146 return *this;
147}
148
c52c2132 149//______________________________________________________________________________
150void AliAnalysisDataContainer::AddConsumer(AliAnalysisTask *consumer, Int_t islot)
151{
152// Add a consumer for contained data;
153 AliAnalysisDataSlot *slot = consumer->GetInputSlot(islot);
154 if (!slot || !slot->GetType()) {
155 cout<<"Consumer task "<< consumer->GetName()<<" does not have an input/type #"<<islot<<endl;
156 //AliError(Form("Consumer task %s does not have an input #%i", consumer->GetName(),islot));
157 return;
158 }
159 if (!slot->GetType()->InheritsFrom(GetType())) {
160 cout<<"Data type "<<slot->GetTitle()<<" for input slot "<<islot<<" of task "<<consumer->GetName()<<" does not match container type "<<GetTitle()<<endl;
161 //AliError(Form("Data type %s for input slot %i of task %s does not match container type %s", slot->GetType()->GetName(),islot,consumer->GetName(),fType->GetName()));
162 return;
163 }
164
165 if (!fConsumers) fConsumers = new TObjArray(2);
166 fConsumers->Add(consumer);
167 // Add the consumer task to the list of task of the producer
168 if (fProducer && !fProducer->GetListOfTasks()->FindObject(consumer))
169 fProducer->Add(consumer);
170}
171
172//______________________________________________________________________________
173Bool_t AliAnalysisDataContainer::ClientsExecuted() const
174{
175// Check if all client tasks have executed.
176 TIter next(fConsumers);
177 AliAnalysisTask *task;
178 while ((task=(AliAnalysisTask*)next())) {
179 if (!task->HasExecuted()) return kFALSE;
180 }
181 return kTRUE;
182}
183
184//______________________________________________________________________________
185void AliAnalysisDataContainer::DeleteData()
186{
187// Delete data if not needed anymore.
188 if (!fDataReady || !ClientsExecuted()) {
189 cout<<"Data not ready or not all clients of container "<<GetName()<<" executed. Data not deleted."<<endl;
190 //AliWarning(Form("Data not ready or not all clients of container %s executed. Data not deleted.", GetName()));
191 return;
192 }
193 if (!fOwnedData) {
194 cout<<"Data not owned by container "<<GetName()<<". Not deleted."<<endl;
195 //AliWarning(Form("Data not owned by container %s. Not deleted.", GetName()));
196 return;
197 }
198 delete fData;
199 fData = 0;
200 fDataReady = kFALSE;
201}
202
203//______________________________________________________________________________
204TClass *AliAnalysisDataContainer::GetType() const
205{
206// Get class type for this slot.
207 AliAnalysisDataContainer *cont = (AliAnalysisDataContainer*)this;
208 if (!fType) cont->SetType(gROOT->GetClass(fTitle.Data()));
209 if (!fType) printf("AliAnalysisDataContainer: Unknown class: %s\n", GetTitle());
210 return fType;
211}
212
213//______________________________________________________________________________
214void AliAnalysisDataContainer::GetEntry(Long64_t ientry)
215{
216// If data is ready and derives from TTree or from TBranch, this will get the
217// requested entry in memory if not already loaded.
218 if (!fDataReady || !GetType()) return;
219 Bool_t istree = fType->InheritsFrom(TTree::Class());
220 if (istree) {
221 TTree *tree = (TTree*)fData;
222 if (tree->GetReadEntry() != ientry) tree->GetEntry(ientry);
223 return;
224 }
225 Bool_t isbranch = fType->InheritsFrom(TBranch::Class());
226 if (isbranch) {
227 TBranch *branch = (TBranch*)fData;
228 if (branch->GetReadEntry() != ientry) branch->GetEntry(ientry);
229 return;
230 }
231}
232
233//______________________________________________________________________________
234Long64_t AliAnalysisDataContainer::Merge(TCollection *list)
235{
236// Merge a list of containers with this one. Containers in the list must have
237// data of the same type.
238 if (!list || !fData) return 0;
239 printf("Merging %d containers %s\n", list->GetSize()+1, GetName());
240 TMethodCall callEnv;
241 if (fData->IsA())
242 callEnv.InitWithPrototype(fData->IsA(), "Merge", "TCollection*");
243 if (!callEnv.IsValid() && !list->IsEmpty()) {
244 cout << "No merge interface for data stored by " << GetName() << ". Merging not possible !" << endl;
245 return 1;
37153431 246 }
247
c52c2132 248 if (list->IsEmpty()) return 1;
249
250 TIter next(list);
37153431 251 AliAnalysisDataContainer *cont;
c52c2132 252 // Make a list where to temporary store the data to be merged.
253 TList *collectionData = new TList();
254 Int_t count = 0; // object counter
255 while ((cont=(AliAnalysisDataContainer*)next())) {
256 TObject *data = cont->GetData();
257 if (!data) continue;
258 if (strcmp(cont->GetName(), GetName())) {
259 cout << "Not merging containers with different names !" << endl;
260 continue;
261 }
262 printf(" ... merging object %s\n", data->GetName());
263 collectionData->Add(data);
264 count++;
37153431 265 }
c52c2132 266 callEnv.SetParam((Long_t) collectionData);
267 callEnv.Execute(fData);
268 delete collectionData;
37153431 269
270 return count+1;
c52c2132 271}
272
273//______________________________________________________________________________
274void AliAnalysisDataContainer::PrintContainer(Option_t *option, Int_t indent) const
275{
276// Print info about this container.
277 TString ind;
278 for (Int_t i=0; i<indent; i++) ind += " ";
279 TString opt(option);
280 opt.ToLower();
281 Bool_t dep = (opt.Contains("dep"))?kTRUE:kFALSE;
282 if (!dep) {
b1310ef5 283 printf("%sContainer: %s type: %s POST_LOOP=%i", ind.Data(), GetName(), GetTitle(), IsPostEventLoop());
c52c2132 284 if (fProducer)
12856ea6 285 printf("%s = Data producer: task %s",ind.Data(),fProducer->GetName());
c52c2132 286 else
12856ea6 287 printf("%s= No data producer",ind.Data());
288 printf("%s = Consumer tasks: ", ind.Data());
c52c2132 289 if (!fConsumers || !fConsumers->GetEntriesFast()) printf("-none-\n");
290 else printf("\n");
37153431 291 }
84fcd93f 292 if (fFolderName.Length())
293 printf("Filename: %s folder: %s\n", fFileName.Data(), fFolderName.Data());
294 else
295 printf("Filename: %s\n", fFileName.Data());
c52c2132 296 TIter next(fConsumers);
297 AliAnalysisTask *task;
298 while ((task=(AliAnalysisTask*)next())) task->PrintTask(option, indent+3);
299}
300
d3106602 301//______________________________________________________________________________
327eaf46 302Bool_t AliAnalysisDataContainer::SetData(TObject *data, Option_t *)
d3106602 303{
304// Set the data as READY only if it was published by the producer.
d3106602 305 // If there is no producer declared, this is a top level container.
306 AliAnalysisTask *task;
327eaf46 307 Bool_t init = kFALSE;
d3106602 308 Int_t i, nc;
309 if (!fProducer) {
327eaf46 310 if (data != fData) init = kTRUE;
d3106602 311 fData = data;
312 fDataReady = kTRUE;
313 if (fConsumers) {
314 nc = fConsumers->GetEntriesFast();
315 for (i=0; i<nc; i++) {
316 task = (AliAnalysisTask*)fConsumers->At(i);
327eaf46 317 task->CheckNotify(init);
d3106602 318 }
319 }
320 return kTRUE;
37153431 321 }
d3106602 322 // Check if it is the producer who published the data
323 if (fProducer->GetPublishedData()==data) {
324 fData = data;
325 fDataReady = kTRUE;
d3106602 326 if (fConsumers) {
327 nc = fConsumers->GetEntriesFast();
328 for (i=0; i<nc; i++) {
329 task = (AliAnalysisTask*)fConsumers->At(i);
330 task->CheckNotify();
331 }
332 }
333 return kTRUE;
334 } else {
737eef16 335 // Ignore data posting from other than the producer
336// cout<<"Data for container "<<GetName()<<" can be published only by producer task "<<fProducer->GetName()<<endl;
337 //AliWarning(Form("Data for container %s can be published only by producer task %s", GetName(), fProducer->GetName()));
338 return kFALSE;
d3106602 339 }
340}
341
d3106602 342//______________________________________________________________________________
84fcd93f 343void AliAnalysisDataContainer::SetFileName(const char *filename)
344{
345// The filename field can be actually composed by the actual file name followed
346// by :dirname (optional):
347// filename = file_name[:dirname]
348// No slashes (/) allowed
349 fFileName = filename;
350 fFolderName = "";
351 Int_t index = fFileName.Index(":");
352 // Fill the folder name
353 if (index >= 0) {
354 fFolderName = fFileName(index+1, fFileName.Length()-index);
355 fFileName.Remove(index);
356 }
357 if (!fFileName.Length())
358 Fatal("SetFileName", "Empty file name");
359 if (fFileName.Index("/")>=0)
360 Fatal("SetFileName", "No slashes (/) allowed in the file name");
361}
362
363//______________________________________________________________________________
d3106602 364void AliAnalysisDataContainer::SetProducer(AliAnalysisTask *prod, Int_t islot)
365{
366// Set the producer of data. The slot number is required for data type checking.
367 if (fProducer) {
11026a80 368 cout<<"Data container "<<GetName()<<" already has a producer: "<<fProducer->GetName()<<endl;
369 //AliWarning(Form("Data container %s already has a producer: %s",GetName(),fProducer->GetName()));
d3106602 370 }
371 if (fDataReady) {
11026a80 372 cout<<GetName()<<" container contains data - cannot change producer!"<<endl;
373 //AliError(Form("%s container contains data - cannot change producer!", GetName()));
d3106602 374 return;
375 }
376 AliAnalysisDataSlot *slot = prod->GetOutputSlot(islot);
377 if (!slot) {
11026a80 378 cout<<"Producer task "<<prod->GetName()<<" does not have an output #"<<islot<<endl;
379 //AliError(Form("Producer task %s does not have an output #%i", prod->GetName(),islot));
d3106602 380 return;
381 }
c52c2132 382 if (!slot->GetType()->InheritsFrom(GetType())) {
383 cout<<"Data type "<<slot->GetTitle()<<"for output slot "<<islot<<" of task "<<prod->GetName()<<" does not match container type "<<GetTitle()<<endl;
11026a80 384 //AliError(Form("Data type %s for output slot %i of task %s does not match container type %s", slot->GetType()->GetName(),islot,prod->GetName(),fType->GetName()));
d3106602 385 return;
386 }
387
388 fProducer = prod;
389 // Add all consumers as daughter tasks
390 TIter next(fConsumers);
391 AliAnalysisTask *cons;
392 while ((cons=(AliAnalysisTask*)next())) {
393 if (!prod->GetListOfTasks()->FindObject(cons)) prod->Add(cons);
394 }
395}
981f2614 396
397//______________________________________________________________________________
398AliAnalysisDataWrapper *AliAnalysisDataContainer::ExportData() const
399{
400// Wraps data for sending it through the net.
401 AliAnalysisDataWrapper *pack = 0;
8d7d3b59 402 if (!fData) {
403 Error("ExportData", "Container %s - No data to be wrapped !", GetName());
404 return pack;
405 }
406 AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
407 if (mgr->GetDebugLevel() > 1) printf(" ExportData: Wrapping data %s for container %s\n", fData->GetName(),GetName());
981f2614 408 pack = new AliAnalysisDataWrapper(fData);
409 pack->SetName(fName.Data());
410 return pack;
411}
412
413//______________________________________________________________________________
414void AliAnalysisDataContainer::ImportData(AliAnalysisDataWrapper *pack)
415{
416// Unwraps data from a data wrapper.
417 if (pack) {
418 fData = pack->Data();
8d7d3b59 419 if (!fData) {
420 Error("ImportData", "No data was wrapped for container %s", GetName());
421 return;
422 }
423 AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
424 if (mgr->GetDebugLevel() > 1) printf(" ImportData: Unwrapping data %s for container %s\n", fData->GetName(),GetName());
981f2614 425 fDataReady = kTRUE;
8167b1d0 426 // Imported wrappers do not own data anymore (AG 13-11-07)
427 pack->SetDeleteData(kFALSE);
981f2614 428 }
429}
d3106602 430
981f2614 431ClassImp (AliAnalysisDataWrapper)
432
8167b1d0 433//______________________________________________________________________________
434AliAnalysisDataWrapper::AliAnalysisDataWrapper(TObject *data)
435 :TNamed(),
436 fData(data)
437{
438// Ctor.
439 if (data) SetName(data->GetName());
440}
441
442//______________________________________________________________________________
443AliAnalysisDataWrapper::~AliAnalysisDataWrapper()
444{
445// Dtor.
446 if (fData && TObject::TestBit(kDeleteData)) delete fData;
447}
448
981f2614 449//______________________________________________________________________________
450AliAnalysisDataWrapper &AliAnalysisDataWrapper::operator=(const AliAnalysisDataWrapper &other)
451{
452// Assignment.
453 if (&other != this) {
454 TNamed::operator=(other);
455 fData = other.fData;
456 }
457 return *this;
458}
459
460//______________________________________________________________________________
461Long64_t AliAnalysisDataWrapper::Merge(TCollection *list)
462{
463// Merge a list of containers with this one. Containers in the list must have
464// data of the same type.
ca78991b 465 if (TH1::AddDirectoryStatus()) TH1::AddDirectory(kFALSE);
981f2614 466 if (!fData) return 0;
467 if (!list || list->IsEmpty()) return 1;
468
b3694163 469 SetDeleteData();
470
981f2614 471 TMethodCall callEnv;
981f2614 472 if (fData->IsA())
473 callEnv.InitWithPrototype(fData->IsA(), "Merge", "TCollection*");
474 if (!callEnv.IsValid()) {
475 cout << "No merge interface for data stored by " << GetName() << ". Merging not possible !" << endl;
476 return 1;
477 }
478
8eedd442 479 TIter next1(list);
981f2614 480 AliAnalysisDataWrapper *cont;
481 // Make a list where to temporary store the data to be merged.
482 TList *collectionData = new TList();
483 Int_t count = 0; // object counter
ca78991b 484 // printf("Wrapper %s 0x%lx (data=%s) merged with:\n", GetName(), (ULong_t)this, fData->ClassName());
8eedd442 485 while ((cont=(AliAnalysisDataWrapper*)next1())) {
b3694163 486 cont->SetDeleteData();
981f2614 487 TObject *data = cont->Data();
488 if (!data) continue;
ca78991b 489 // printf(" - %s 0x%lx (data=%s)\n", cont->GetName(), (ULong_t)cont, data->ClassName());
981f2614 490 collectionData->Add(data);
491 count++;
492 }
493 callEnv.SetParam((Long_t) collectionData);
494 callEnv.Execute(fData);
495 delete collectionData;
496
497 return count+1;
498}
9162405c 499
500ClassImp(AliAnalysisFileDescriptor)
501
502//______________________________________________________________________________
503AliAnalysisFileDescriptor::AliAnalysisFileDescriptor()
504 :TObject(), fLfn(), fGUID(), fUrl(), fPfn(), fSE(),
505 fIsArchive(kFALSE), fImage(0), fNreplicas(0),
506 fStartBytes(0), fReadBytes(0), fSize(0), fOpenedAt(0),
9c19e756 507 fOpenTime(0.), fProcessingTime(0.), fThroughput(0.), fTimer()
9162405c 508{
509// I/O constructor
510}
511
512//______________________________________________________________________________
513AliAnalysisFileDescriptor::AliAnalysisFileDescriptor(const TFile *file)
514 :TObject(), fLfn(), fGUID(), fUrl(), fPfn(), fSE(),
515 fIsArchive(kFALSE), fImage(0), fNreplicas(0),
516 fStartBytes(0), fReadBytes(0), fSize(0), fOpenedAt(0),
9c19e756 517 fOpenTime(0.), fProcessingTime(0.), fThroughput(0.), fTimer()
9162405c 518{
519// Normal constructor
520 if (file->InheritsFrom("TAlienFile")) {
521 fLfn =(const char*)gROOT->ProcessLine(Form("((TAlienFile*)%p)->GetLfn();", file));
522 fGUID =(const char*)gROOT->ProcessLine(Form("((TAlienFile*)%p)->GetGUID();", file));
523 fUrl =(const char*)gROOT->ProcessLine(Form("((TAlienFile*)%p)->GetUrl();", file));
524 fPfn =(const char*)gROOT->ProcessLine(Form("((TAlienFile*)%p)->GetPfn();", file));
525 fSE = (const char*)gROOT->ProcessLine(Form("((TAlienFile*)%p)->GetSE();", file));
526 fImage = (Int_t)gROOT->ProcessLine(Form("((TAlienFile*)%p)->GetImage();", file));
527 fNreplicas = (Int_t)gROOT->ProcessLine(Form("((TAlienFile*)%p)->GetNreplicas();", file));
528 fOpenedAt = gROOT->ProcessLine(Form("((TAlienFile*)%p)->GetOpenTime();", file));
529 gROOT->ProcessLine(Form("((AliAnalysisFileDescriptor*)%p)->SetOpenTime(((TAlienFile*)%p)->GetElapsed());", this, file));
530 } else {
531 fLfn = file->GetName();
532 fPfn = file->GetName();
533 fUrl = file->GetName();
534 fSE = "local";
535 if (!fPfn.BeginsWith("/")) fPfn.Prepend(Form("%s/",gSystem->WorkingDirectory()));
536 fOpenedAt = time(0);
537 }
538 fStartBytes = TFile::GetFileBytesRead();
539 fIsArchive = file->IsArchive();
540 fSize = file->GetSize();
541}
542
543//______________________________________________________________________________
544AliAnalysisFileDescriptor::AliAnalysisFileDescriptor(const AliAnalysisFileDescriptor &other)
545 :TObject(other), fLfn(other.fLfn), fGUID(other.fGUID),
546 fUrl(other.fUrl), fPfn(other.fPfn), fSE(other.fSE),
547 fIsArchive(other.fIsArchive), fImage(other.fImage),
548 fNreplicas(other.fNreplicas), fStartBytes(other.fStartBytes), fReadBytes(other.fReadBytes),
549 fSize(other.fSize), fOpenedAt(other.fOpenedAt), fOpenTime(other.fOpenTime),
9c19e756 550 fProcessingTime(other.fProcessingTime), fThroughput(other.fThroughput), fTimer()
9162405c 551{
552// CC
553}
554
555//______________________________________________________________________________
556AliAnalysisFileDescriptor &AliAnalysisFileDescriptor::operator=(const AliAnalysisFileDescriptor &other)
557{
558// Assignment.
559 if (&other == this) return *this;
560 TObject::operator=(other);
561 fLfn = other.fLfn;
562 fGUID = other.fGUID;
563 fUrl = other.fUrl;
564 fPfn = other.fPfn;
565 fSE = other.fSE;
566 fIsArchive = other.fIsArchive;
567 fImage = other.fImage;
568 fNreplicas = other.fNreplicas;
569 fStartBytes = other.fStartBytes;;
570 fReadBytes = other.fReadBytes;
571 fSize = other.fSize;
572 fOpenedAt = other.fOpenedAt;
573 fOpenTime = other.fOpenTime;
574 fProcessingTime = other.fProcessingTime;
575 fThroughput = other.fThroughput;
576 return *this;
577}
578
579//______________________________________________________________________________
580AliAnalysisFileDescriptor::~AliAnalysisFileDescriptor()
581{
582// Destructor
583}
584
585//______________________________________________________________________________
586void AliAnalysisFileDescriptor::Done()
587{
588// Must be called at the end of processing, providing file->GetBytesRead() as argument.
9c19e756 589 fTimer.Stop();
9162405c 590 const Double_t megabyte = 1048576.;
9c19e756 591// Long64_t stampnow = time(0);
9162405c 592 fReadBytes = TFile::GetFileBytesRead()-fStartBytes;
9c19e756 593// fProcessingTime = stampnow-fOpenedAt;
594 fProcessingTime = fTimer.RealTime();
9162405c 595 Double_t readsize = fReadBytes/megabyte;
596 fThroughput = readsize/fProcessingTime;
597}
598
599//______________________________________________________________________________
600void AliAnalysisFileDescriptor::Print(Option_t*) const
601{
602// Print info about the file descriptor
603 const Double_t megabyte = 1048576.;
604 printf("===== Logical file name: %s =====\n", fLfn.Data());
605 printf(" Pfn: %s\n", fPfn.Data());
606 printf(" url: %s\n", fUrl.Data());
607 printf(" access time: %lld from SE: %s image %d/%d\n", fOpenedAt, fSE.Data(), fImage, fNreplicas);
608 printf(" open time: %g [sec]\n", fOpenTime);
609 printf(" file size: %g [MB], read size: %g [MB]\n", fSize/megabyte, fReadBytes/megabyte);
610 printf(" processing time [sec]: %g\n", fProcessingTime);
611 printf(" average throughput: %g [MB/sec]\n", fThroughput);
612}
613
614//______________________________________________________________________________
615void AliAnalysisFileDescriptor::SavePrimitive(ostream &out, Option_t *)
616{
617// Stream info to file
618 const Double_t megabyte = 1048576.;
619 out << "#################################################################" << endl;
620 out << "pfn " << fPfn.Data() << endl;
621 out << "url " << fUrl.Data() << endl;
622 out << "se " << fSE.Data() << endl;
623 out << "image " << fImage << endl;
624 out << "nreplicas " << fNreplicas << endl;
625 out << "openstamp " << fOpenedAt << endl;
626 out << setiosflags(ios::fixed) << setprecision(3);
627 out << "opentime " << fOpenTime << endl;
628 out << "runtime " << fProcessingTime << endl;
629 out << "filesize " << fSize/megabyte << endl;
630 out << "readsize " << fReadBytes/megabyte << endl;
631 out << "throughput " << fThroughput << endl;
632}
633