LCOV - code coverage report
Current view: top level - HLT/BASE/util - AliHLTRootFileWriterComponent.cxx (source / functions) Hit Total Coverage
Test: coverage.info Lines: 11 61 18.0 %
Date: 2016-06-14 17:26:59 Functions: 6 12 50.0 %

          Line data    Source code
       1             : // $Id$
       2             : 
       3             : //**************************************************************************
       4             : //* This file is property of and copyright by the                          * 
       5             : //* ALICE Experiment at CERN, All rights reserved.                         *
       6             : //*                                                                        *
       7             : //* Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no>        *
       8             : //*                  for The ALICE HLT Project.                            *
       9             : //*                                                                        *
      10             : //* Permission to use, copy, modify and distribute this software and its   *
      11             : //* documentation strictly for non-commercial purposes is hereby granted   *
      12             : //* without fee, provided that the above copyright notice appears in all   *
      13             : //* copies and that both the copyright notice and this permission notice   *
      14             : //* appear in the supporting documentation. The authors make no claims     *
      15             : //* about the suitability of this software for any purpose. It is          *
      16             : //* provided "as is" without express or implied warranty.                  *
      17             : //**************************************************************************
      18             : 
      19             : /// @file   AliHLTRootFileWriterComponent.cxx
      20             : /// @author Matthias Richter
      21             : /// @date   
      22             : /// @brief  Base class for writer components to store data in a ROOT file
      23             : ///
      24             : 
      25             : #include "AliHLTRootFileWriterComponent.h"
      26             : #include "TFile.h"
      27             : #include "TString.h"
      28             : #include "TObjectTable.h" // for root object validity
      29             : 
      30             : /** ROOT macro for the implementation of ROOT specific class methods */
      31           8 : ClassImp(AliHLTRootFileWriterComponent)
      32             : 
      33             : AliHLTRootFileWriterComponent::AliHLTRootFileWriterComponent()
      34             :   :
      35           6 :   AliHLTFileWriter(),
      36           6 :   fEventID(kAliHLTVoidEventID),
      37           6 :   fCurrentFile(NULL),
      38           6 :   fOptions(0)
      39          24 : {
      40             :   // The RootFileWriter provides a stand alone component to write incoming
      41             :   // TObject like structures into a Root file. Furthermore it provides a
      42             :   // base class for customized writers.
      43             :   // Component ID: \b ROOTFileWriter                                      <br>
      44             :   // Library: \b libAliHLTUtil.so                                               <br>
      45             :   // Input Data Types: ::kAliHLTAnyDataType                             <br>
      46             :   // Output Data Types: none                                            <br>
      47             : 
      48             :   // all blocks of one event go into the same file
      49           6 :   SetMode(kConcatenateBlocks);
      50             :   // write all events by default
      51           6 :   SetMode(kWriteAllEvents);
      52           9 : }
      53             : 
      54             : AliHLTRootFileWriterComponent::~AliHLTRootFileWriterComponent()
      55          12 : {
      56             :   // destructor
      57          18 : }
      58             : 
      59             : int AliHLTRootFileWriterComponent::InitWriter()
      60             : {
      61             :   // overloaded from AliHLTFileWriter: local initialization
      62             : 
      63             :   // choose .root as default extension
      64           0 :   if (GetExtension().IsNull()) SetExtension("root");
      65           0 :   return 0;
      66           0 : }
      67             : 
      68             : int AliHLTRootFileWriterComponent::CloseWriter()
      69             : {
      70             :   // overloaded from AliHLTFileWriter: local cleanup
      71           0 :   if (fCurrentFile!=NULL) {
      72             :     HLTDebug("close root file");
      73           0 :     TFile* pFile=fCurrentFile; fCurrentFile=NULL;
      74           0 :     pFile->Close(); delete pFile;
      75           0 :   }
      76           0 :   return 0;
      77             : }
      78             : 
      79             : int AliHLTRootFileWriterComponent::DumpEvent( const AliHLTComponentEventData& evtData,
      80             :                                               const AliHLTComponentBlockData* /*blocks*/, 
      81             :                                               AliHLTComponentTriggerData& /*trigData*/ )
      82             : {
      83             :   // overloaded from AliHLTDataSink: event processing
      84             :   int iResult=0;
      85           0 :   if (!IsDataEvent() && !CheckMode(kWriteAllEvents)) return 0;
      86             : 
      87             :   int count=0;
      88           0 :   for (const TObject* pObj=GetFirstInputObject();
      89           0 :        pObj && iResult>=0;
      90           0 :        pObj=GetNextInputObject()) {
      91           0 :     iResult=WriteObject(evtData.fEventID, pObj);
      92           0 :     if (iResult == 0) {
      93           0 :       count++;
      94             :       HLTDebug("wrote object of class %s, data type %s", pObj->ClassName(), (DataType2Text(GetDataType(pObj)).c_str())); 
      95           0 :     }
      96             :   }
      97             :   HLTDebug("wrote %d object(s) from %d input blocks to file", count, GetNumberOfInputBlocks());
      98             :   return iResult;
      99           0 : }
     100             : 
     101             : int AliHLTRootFileWriterComponent::ScanArgument(int argc, const char** argv)
     102             : {
     103             :   // configuration
     104             :   int iResult=0;
     105           0 :   if (argc<=0) return 0;
     106           0 :   TString argument=argv[0];
     107             :   int bMissingParam=0;
     108             : 
     109             :   // -overwrite
     110           0 :   if (argument.CompareTo("-overwrite")==0) {
     111           0 :     fOptions|=TObject::kOverwrite;
     112             :     iResult=1;
     113             :     
     114           0 :   } else {
     115             :     iResult=-EINVAL;
     116             :   }
     117             : 
     118           0 :   if (bMissingParam) {
     119           0 :     HLTError("missing parameter for argument %s", argument.Data());
     120             :     iResult=-EINVAL;
     121           0 :   }
     122             : 
     123             :   return iResult;
     124           0 : }
     125             : 
     126             : int AliHLTRootFileWriterComponent::WriteObject(const AliHLTEventID_t eventID, const TObject *pOb)
     127             : {
     128             :   // write an object
     129             :   int iResult=0;
     130           0 :   if (pOb) {
     131             :     HLTDebug("write object %p (%s)", pOb, pOb->GetName());
     132           0 :     if (!CheckMode(kConcatenateEvents) && eventID != fEventID &&
     133           0 :         fCurrentFile!=NULL && eventID!=kAliHLTVoidEventID) {
     134           0 :       TFile* pFile=fCurrentFile; fCurrentFile=NULL;
     135           0 :       pFile->Close(); delete pFile;
     136           0 :     }
     137           0 :     if (fCurrentFile==NULL) {
     138           0 :       fCurrentFile=OpenFile(eventID, 0);
     139           0 :       if (fCurrentFile) fEventID=eventID;
     140             :     }
     141           0 :     if (fCurrentFile) {
     142           0 :       fCurrentFile->cd();
     143           0 :       pOb->Write("", fOptions);
     144           0 :     } else {
     145             :       iResult=-EBADF;
     146             :     }
     147             :   }
     148           0 :   return iResult;
     149             : }
     150             : 
     151             : TFile* AliHLTRootFileWriterComponent::OpenFile(const AliHLTEventID_t eventID, const int blockID, const char* option)
     152             : {
     153             :   // open file for writing
     154             :   TFile* pFile=NULL;
     155           0 :   TString filename("");
     156           0 :   if ((BuildFileName(eventID, blockID, kAliHLTVoidDataType, 0, filename))>=0 && filename.IsNull()==0) {
     157           0 :     pFile=new TFile(filename, option);
     158           0 :     if (pFile) {
     159           0 :       if (pFile->IsZombie()) {
     160           0 :         delete pFile;
     161             :         pFile=NULL;
     162           0 :         HLTError("can not open ROOT file %s", filename.Data());
     163             :       }
     164             :     } else {
     165           0 :       HLTFatal("memory allocation failed");
     166             :     }
     167             :   } else {
     168           0 :     HLTError("failed to build a new file name for event %#8x", eventID);
     169             :   }
     170             :   return pFile;
     171           0 : }

Generated by: LCOV version 1.11