]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ANALYSIS/AliAnalysisDataContainer.cxx
fix for generating the outputs_valid file in MC generator mode
[u/mrichter/AliRoot.git] / ANALYSIS / AliAnalysisDataContainer.cxx
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
45 #include <Riostream.h>
46 #include <TMethodCall.h>
47
48 #include <TClass.h>
49 #include <TSystem.h>
50 #include <TFile.h>
51 #include <TTree.h>
52 #include <TH1.h>
53 #include <TROOT.h>
54
55 #include "AliAnalysisManager.h"
56 #include "AliAnalysisDataContainer.h"
57 #include "AliAnalysisDataSlot.h"
58 #include "AliAnalysisTask.h"
59
60 using std::endl;
61 using std::cout;
62 using std::ios;
63 using std::setiosflags;
64 using std::setprecision;
65 ClassImp(AliAnalysisDataContainer)
66
67 //______________________________________________________________________________
68 AliAnalysisDataContainer::AliAnalysisDataContainer() : TNamed(),
69                           fDataReady(kFALSE),
70                           fOwnedData(kFALSE),
71                           fFileName(),
72                           fFolderName(),
73                           fFile(NULL),
74                           fData(NULL),
75                           fType(NULL),
76                           fProducer(NULL),
77                           fConsumers(NULL)
78 {
79 // Dummy ctor.
80 }
81
82 //______________________________________________________________________________
83 AliAnalysisDataContainer::AliAnalysisDataContainer(const char *name, TClass *type)
84                          :TNamed(name,""),
85                           fDataReady(kFALSE),
86                           fOwnedData(kFALSE),
87                           fFileName(),
88                           fFolderName(),
89                           fFile(NULL),
90                           fData(NULL),
91                           fType(type),
92                           fProducer(NULL),
93                           fConsumers(NULL)
94 {
95 // Default constructor.
96    SetTitle(fType->GetName());
97 }
98
99 //______________________________________________________________________________
100 AliAnalysisDataContainer::AliAnalysisDataContainer(const AliAnalysisDataContainer &cont)
101                          :TNamed(cont),
102                           fDataReady(cont.fDataReady),
103                           fOwnedData(kFALSE),
104                           fFileName(cont.fFileName),
105                           fFolderName(cont.fFolderName),
106                           fFile(NULL),
107                           fData(cont.fData),
108                           fType(NULL),
109                           fProducer(cont.fProducer),
110                           fConsumers(NULL)
111 {
112 // Copy ctor.
113    GetType();
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    }   
119 }
120
121 //______________________________________________________________________________
122 AliAnalysisDataContainer::~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
129 //______________________________________________________________________________
130 AliAnalysisDataContainer &AliAnalysisDataContainer::operator=(const AliAnalysisDataContainer &cont)
131 {
132 // Assignment.
133    if (&cont != this) {
134       TNamed::operator=(cont);
135       fDataReady = cont.fDataReady;
136       fOwnedData = kFALSE;
137       fFileName = cont.fFileName;
138       fFolderName = cont.fFolderName;
139       fFile = NULL;
140       fData = cont.fData;
141       GetType();
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
152 //______________________________________________________________________________
153 void 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 //______________________________________________________________________________
176 Bool_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 //______________________________________________________________________________
188 void 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 //______________________________________________________________________________
207 TClass *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 //______________________________________________________________________________
217 void 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 //______________________________________________________________________________
237 Long64_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;
249    }
250
251    if (list->IsEmpty()) return 1;
252
253    TIter next(list);
254    AliAnalysisDataContainer *cont;
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++;
268    }
269    callEnv.SetParam((Long_t) collectionData);
270    callEnv.Execute(fData);
271    delete collectionData;
272
273    return count+1;
274 }
275
276 //______________________________________________________________________________
277 void 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();
284    Bool_t dep = (opt.Contains("dep"))?kTRUE:kFALSE;
285    if (!dep) {
286       printf("%sContainer: %s  type: %s POST_LOOP=%i", ind.Data(), GetName(), GetTitle(), IsPostEventLoop());
287       if (fProducer) 
288          printf("%s = Data producer: task %s",ind.Data(),fProducer->GetName());
289       else
290          printf("%s= No data producer",ind.Data());
291       printf("%s = Consumer tasks: ", ind.Data());
292       if (!fConsumers || !fConsumers->GetEntriesFast()) printf("-none-\n");
293       else printf("\n");
294    }
295    if (fFolderName.Length())
296      printf("Filename: %s  folder: %s\n", fFileName.Data(), fFolderName.Data());
297    else
298      printf("Filename: %s\n", fFileName.Data());
299    TIter next(fConsumers);
300    AliAnalysisTask *task;
301    while ((task=(AliAnalysisTask*)next())) task->PrintTask(option, indent+3);
302 }   
303
304 //______________________________________________________________________________
305 Bool_t AliAnalysisDataContainer::SetData(TObject *data, Option_t *)
306 {
307 // Set the data as READY only if it was published by the producer.
308    // If there is no producer declared, this is a top level container.
309    AliAnalysisTask *task;
310    Bool_t init = kFALSE;
311    Int_t i, nc;
312    if (!fProducer) {
313       if (data != fData) init = kTRUE;
314       fData = data;
315       fDataReady = kTRUE;
316       if (fConsumers) {
317          nc = fConsumers->GetEntriesFast();
318          for (i=0; i<nc; i++) {
319             task = (AliAnalysisTask*)fConsumers->At(i);
320             task->CheckNotify(init);
321          }
322       }      
323       return kTRUE;
324    }
325    // Check if it is the producer who published the data     
326    if (fProducer->GetPublishedData()==data) {
327       fData = data;
328       fDataReady = kTRUE;
329       if (fConsumers) {
330          nc = fConsumers->GetEntriesFast();
331          for (i=0; i<nc; i++) {
332             task = (AliAnalysisTask*)fConsumers->At(i);
333             task->CheckNotify();
334          }
335       }      
336       return kTRUE;   
337    } else {
338      // Ignore data posting from other than the producer
339 //      cout<<"Data for container "<<GetName()<<" can be published only by producer task "<<fProducer->GetName()<<endl;
340       //AliWarning(Form("Data for container %s can be published only by producer task %s", GetName(), fProducer->GetName()));   
341       return kFALSE;           
342    }              
343 }
344
345 //______________________________________________________________________________
346 void AliAnalysisDataContainer::SetFileName(const char *filename)
347 {
348 // The filename field can be actually composed by the actual file name followed
349 // by :dirname (optional):
350 // filename = file_name[:dirname]
351 // No slashes (/) allowed
352   fFileName = filename;
353   fFolderName = "";
354   Int_t index = fFileName.Index(":");
355   // Fill the folder name
356   if (index >= 0) {
357     fFolderName = fFileName(index+1, fFileName.Length()-index);
358     fFileName.Remove(index);
359   }  
360   if (!fFileName.Length())
361     Fatal("SetFileName", "Empty file name");   
362   if (fFileName.Index("/")>=0)
363     Fatal("SetFileName", "No slashes (/) allowed in the file name");   
364 }
365
366 //______________________________________________________________________________
367 void AliAnalysisDataContainer::SetProducer(AliAnalysisTask *prod, Int_t islot)
368 {
369 // Set the producer of data. The slot number is required for data type checking.
370    if (fProducer) {
371      cout<<"Data container "<<GetName()<<" already has a producer: "<<fProducer->GetName()<<endl;
372      //AliWarning(Form("Data container %s already has a producer: %s",GetName(),fProducer->GetName()));
373    } 
374    if (fDataReady) {
375      cout<<GetName()<<" container contains data - cannot change producer!"<<endl;
376      //AliError(Form("%s container contains data - cannot change producer!", GetName()));
377       return;
378    }   
379    AliAnalysisDataSlot *slot = prod->GetOutputSlot(islot);
380    if (!slot) {
381      cout<<"Producer task "<<prod->GetName()<<" does not have an output #"<<islot<<endl;
382      //AliError(Form("Producer task %s does not have an output #%i", prod->GetName(),islot));
383       return;
384    }   
385    if (!slot->GetType()->InheritsFrom(GetType())) {
386      cout<<"Data type "<<slot->GetTitle()<<"for output slot "<<islot<<" of task "<<prod->GetName()<<" does not match container type "<<GetTitle()<<endl;
387      //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()));
388       return;
389    }   
390    
391    fProducer = prod;
392    // Add all consumers as daughter tasks
393    TIter next(fConsumers);
394    AliAnalysisTask *cons;
395    while ((cons=(AliAnalysisTask*)next())) {
396       if (!prod->GetListOfTasks()->FindObject(cons)) prod->Add(cons);
397    }   
398 }   
399
400 //______________________________________________________________________________
401 AliAnalysisDataWrapper *AliAnalysisDataContainer::ExportData() const
402 {
403 // Wraps data for sending it through the net.
404    AliAnalysisDataWrapper *pack = 0;
405    if (!fData) {
406       Error("ExportData", "Container %s - No data to be wrapped !", GetName());
407       return pack;
408    } 
409    AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
410    if (mgr && mgr->GetDebugLevel() > 1) printf("   ExportData: Wrapping data %s for container %s\n", fData->GetName(),GetName());
411    pack = new AliAnalysisDataWrapper(fData);
412    pack->SetName(fName.Data());
413    return pack;
414 }
415
416 //______________________________________________________________________________
417 void AliAnalysisDataContainer::ImportData(AliAnalysisDataWrapper *pack)
418 {
419 // Unwraps data from a data wrapper.
420    if (pack) {
421       fData = pack->Data();
422       if (!fData) {
423          Error("ImportData", "No data was wrapped for container %s", GetName());
424          return;
425       }   
426       AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
427       if (mgr && mgr->GetDebugLevel() > 1) printf("   ImportData: Unwrapping data %s for container %s\n", fData->GetName(),GetName());
428       fDataReady = kTRUE;
429       // Imported wrappers do not own data anymore (AG 13-11-07)
430       pack->SetDeleteData(kFALSE);
431    }   
432 }      
433       
434 ClassImp (AliAnalysisDataWrapper)
435
436 //______________________________________________________________________________
437 AliAnalysisDataWrapper::AliAnalysisDataWrapper(TObject *data)
438                        :TNamed(),
439                         fData(data)
440 {
441 // Ctor.
442    if (data) SetName(data->GetName());
443 }
444
445 //______________________________________________________________________________
446 AliAnalysisDataWrapper::~AliAnalysisDataWrapper()
447 {
448 // Dtor.
449    if (fData && TObject::TestBit(kDeleteData)) delete fData;
450 }   
451
452 //______________________________________________________________________________
453 AliAnalysisDataWrapper &AliAnalysisDataWrapper::operator=(const AliAnalysisDataWrapper &other)
454 {
455 // Assignment.
456    if (&other != this) {
457       TNamed::operator=(other);
458       fData = other.fData;
459    }   
460    return *this;
461 }
462
463 //______________________________________________________________________________
464 Long64_t AliAnalysisDataWrapper::Merge(TCollection *list)
465 {
466 // Merge a list of containers with this one. Containers in the list must have
467 // data of the same type.
468    if (TH1::AddDirectoryStatus()) TH1::AddDirectory(kFALSE);
469    if (!fData) return 0;
470    if (!list || list->IsEmpty()) return 1;
471
472    SetDeleteData();
473
474    TMethodCall callEnv;
475    if (fData->IsA())
476       callEnv.InitWithPrototype(fData->IsA(), "Merge", "TCollection*");
477    if (!callEnv.IsValid()) {
478       cout << "No merge interface for data stored by " << GetName() << ". Merging not possible !" << endl;
479       return 1;
480    }
481
482    TIter next1(list);
483    AliAnalysisDataWrapper *cont;
484    // Make a list where to temporary store the data to be merged.
485    TList *collectionData = new TList();
486    Int_t count = 0; // object counter
487    // printf("Wrapper %s 0x%lx (data=%s) merged with:\n", GetName(), (ULong_t)this, fData->ClassName());
488    while ((cont=(AliAnalysisDataWrapper*)next1())) {
489       cont->SetDeleteData();
490       TObject *data = cont->Data();
491       if (!data) continue;
492       // printf("   - %s 0x%lx (data=%s)\n", cont->GetName(), (ULong_t)cont, data->ClassName());
493       collectionData->Add(data);
494       count++;
495    }
496    callEnv.SetParam((Long_t) collectionData);
497    callEnv.Execute(fData);
498    delete collectionData;
499
500    return count+1;
501 }
502
503 ClassImp(AliAnalysisFileDescriptor)
504
505 //______________________________________________________________________________
506 AliAnalysisFileDescriptor::AliAnalysisFileDescriptor()
507                           :TObject(), fLfn(), fGUID(), fUrl(), fPfn(), fSE(),
508                            fIsArchive(kFALSE), fImage(0), fNreplicas(0), 
509                            fStartBytes(0), fReadBytes(0), fSize(0), fOpenedAt(0), 
510                            fOpenTime(0.), fProcessingTime(0.), fThroughput(0.), fTimer()
511 {
512 // I/O constructor
513 }
514
515 //______________________________________________________________________________
516 AliAnalysisFileDescriptor::AliAnalysisFileDescriptor(const TFile *file)
517                           :TObject(), fLfn(), fGUID(), fUrl(), fPfn(), fSE(),
518                            fIsArchive(kFALSE), fImage(0), fNreplicas(0), 
519                            fStartBytes(0), fReadBytes(0), fSize(0), fOpenedAt(0), 
520                            fOpenTime(0.), fProcessingTime(0.), fThroughput(0.), fTimer()
521 {
522 // Normal constructor
523    if (file->InheritsFrom("TAlienFile")) {
524       fLfn =(const char*)gROOT->ProcessLine(Form("((TAlienFile*)%p)->GetLfn();", file));
525       fGUID =(const char*)gROOT->ProcessLine(Form("((TAlienFile*)%p)->GetGUID();", file));
526       fUrl =(const char*)gROOT->ProcessLine(Form("((TAlienFile*)%p)->GetUrl();", file));
527       fPfn =(const char*)gROOT->ProcessLine(Form("((TAlienFile*)%p)->GetPfn();", file));
528       fSE = (const char*)gROOT->ProcessLine(Form("((TAlienFile*)%p)->GetSE();", file));
529       fImage = (Int_t)gROOT->ProcessLine(Form("((TAlienFile*)%p)->GetImage();", file));
530       fNreplicas = (Int_t)gROOT->ProcessLine(Form("((TAlienFile*)%p)->GetNreplicas();", file));
531       fOpenedAt = gROOT->ProcessLine(Form("((TAlienFile*)%p)->GetOpenTime();", file));
532       gROOT->ProcessLine(Form("((AliAnalysisFileDescriptor*)%p)->SetOpenTime(((TAlienFile*)%p)->GetElapsed());", this, file));
533    } else {
534       fLfn = file->GetName();
535       fPfn = file->GetName();
536       fUrl = file->GetName();
537       fSE = "local";
538       if (!fPfn.BeginsWith("/")) fPfn.Prepend(Form("%s/",gSystem->WorkingDirectory()));
539       fOpenedAt = time(0);
540    }
541    fStartBytes = TFile::GetFileBytesRead();
542    fIsArchive = file->IsArchive();
543    fSize = file->GetSize();
544 }
545
546 //______________________________________________________________________________
547 AliAnalysisFileDescriptor::AliAnalysisFileDescriptor(const AliAnalysisFileDescriptor &other)
548                           :TObject(other), fLfn(other.fLfn), fGUID(other.fGUID),
549                            fUrl(other.fUrl), fPfn(other.fPfn), fSE(other.fSE),
550                            fIsArchive(other.fIsArchive), fImage(other.fImage),
551                            fNreplicas(other.fNreplicas), fStartBytes(other.fStartBytes), fReadBytes(other.fReadBytes),
552                            fSize(other.fSize), fOpenedAt(other.fOpenedAt), fOpenTime(other.fOpenTime),
553                            fProcessingTime(other.fProcessingTime), fThroughput(other.fThroughput), fTimer()
554 {
555 // CC
556 }
557
558 //______________________________________________________________________________
559 AliAnalysisFileDescriptor &AliAnalysisFileDescriptor::operator=(const AliAnalysisFileDescriptor &other)
560 {
561 // Assignment.
562    if (&other == this) return *this;
563    TObject::operator=(other);
564    fLfn       = other.fLfn;
565    fGUID      = other.fGUID;
566    fUrl       = other.fUrl; 
567    fPfn       = other.fPfn;
568    fSE        = other.fSE;
569    fIsArchive = other.fIsArchive;
570    fImage     = other.fImage;
571    fNreplicas = other.fNreplicas;
572    fStartBytes = other.fStartBytes;;
573    fReadBytes = other.fReadBytes;
574    fSize      = other.fSize;
575    fOpenedAt  = other.fOpenedAt;
576    fOpenTime  = other.fOpenTime;
577    fProcessingTime = other.fProcessingTime;
578    fThroughput = other.fThroughput;
579    return *this;
580 }
581
582 //______________________________________________________________________________
583 AliAnalysisFileDescriptor::~AliAnalysisFileDescriptor()
584 {
585 // Destructor
586 }
587
588 //______________________________________________________________________________
589 void AliAnalysisFileDescriptor::Done()
590 {
591 // Must be called at the end of processing, providing file->GetBytesRead() as argument.
592    fTimer.Stop();
593    const Double_t megabyte = 1048576.;
594 //   Long64_t stampnow = time(0);
595    fReadBytes = TFile::GetFileBytesRead()-fStartBytes;
596 //   fProcessingTime = stampnow-fOpenedAt;
597    fProcessingTime = fTimer.RealTime();
598    Double_t readsize = fReadBytes/megabyte;
599    fThroughput = readsize/fProcessingTime;
600 }   
601
602 //______________________________________________________________________________
603 void AliAnalysisFileDescriptor::Print(Option_t*) const
604 {
605 // Print info about the file descriptor
606    const Double_t megabyte = 1048576.;
607    printf("===== Logical file name: %s =====\n", fLfn.Data());
608    printf("      Pfn: %s\n", fPfn.Data());
609    printf("      url: %s\n", fUrl.Data());
610    printf("      access time: %lld from SE: %s  image %d/%d\n", fOpenedAt, fSE.Data(), fImage, fNreplicas);
611    printf("      open time: %g [sec]\n", fOpenTime);
612    printf("      file size: %g [MB],  read size: %g [MB]\n", fSize/megabyte, fReadBytes/megabyte);
613    printf("      processing time [sec]: %g\n", fProcessingTime);
614    printf("      average throughput: %g [MB/sec]\n", fThroughput);
615 }
616
617 //______________________________________________________________________________
618 void AliAnalysisFileDescriptor::SavePrimitive(std::ostream &out, Option_t *)
619 {
620 // Stream info to file
621    const Double_t megabyte = 1048576.;
622    out << "#################################################################" << endl;
623    out << "pfn          " << fPfn.Data() << endl;
624    out << "url          " << fUrl.Data() << endl;
625    out << "se           " << fSE.Data() << endl;
626    out << "image        " << fImage << endl;
627    out << "nreplicas    " << fNreplicas << endl;
628    out << "openstamp    " << fOpenedAt << endl;
629    std::ios_base::fmtflags original_flags = out.flags();
630    out << setiosflags(std::ios::fixed) << std::setprecision(3);
631    out << "opentime     " << fOpenTime << endl;
632    out << "runtime      " << fProcessingTime << endl;
633    out << "filesize     " << fSize/megabyte << endl;
634    out << "readsize     " << fReadBytes/megabyte << endl;
635    out << "throughput   " << fThroughput << endl;
636    out.flags(original_flags);
637 }
638