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