3 /**************************************************************************
4 * This file is property of and copyright by the ALICE HLT Project *
5 * ALICE Experiment at CERN, All rights reserved. *
7 * Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no> *
8 * for The ALICE HLT Project. *
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 **************************************************************************/
19 /** @file AliHLTRootFileWriterComponent.cxx
20 @author Matthias Richter
22 @brief Base class for writer components to store data in a ROOT file
26 #include "AliHLTRootFileWriterComponent.h"
29 #include "TObjectTable.h" // for root object validity
31 /** the global object for component registration */
32 AliHLTRootFileWriterComponent gAliHLTRootFileWriterComponent;
34 /** ROOT macro for the implementation of ROOT specific class methods */
35 ClassImp(AliHLTRootFileWriterComponent)
37 AliHLTRootFileWriterComponent::AliHLTRootFileWriterComponent()
40 fEventID(kAliHLTVoidEventID),
43 // see header file for class documentation
45 // refer to README to build package
47 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
49 // all blocks of one event go into the same file
50 SetMode(kConcatenateBlocks);
53 AliHLTRootFileWriterComponent::~AliHLTRootFileWriterComponent()
55 // see header file for class documentation
58 int AliHLTRootFileWriterComponent::InitWriter()
60 // see header file for class documentation
62 // choose .root as default extension
63 if (GetExtension().IsNull()) SetExtension("root");
67 int AliHLTRootFileWriterComponent::CloseWriter()
69 // see header file for class documentation
70 if (fCurrentFile!=NULL) {
71 HLTDebug("close root file");
72 TFile* pFile=fCurrentFile; fCurrentFile=NULL;
73 pFile->Close(); delete pFile;
78 int AliHLTRootFileWriterComponent::DumpEvent( const AliHLTComponentEventData& evtData,
79 const AliHLTComponentBlockData* blocks,
80 AliHLTComponentTriggerData& trigData )
82 // see header file for class documentation
84 if (evtData.fStructSize==0 && blocks==NULL && trigData.fStructSize==0) {
85 // this is just to get rid of the warning "unused parameter"
87 const TObject* pObj=GetFirstInputObject(kAliHLTAnyDataType);
88 HLTDebug("got first object %p", pObj);
90 while (pObj && iResult>=0) {
91 iResult=WriteObject(evtData.fEventID, pObj);
94 HLTDebug("wrote object of class %s, data type %s", pObj->ClassName(), (DataType2Text(GetDataType(pObj)).c_str()));
96 pObj=GetNextInputObject();
98 HLTDebug("wrote %d object(s) from %d input blocks to file", count, GetNumberOfInputBlocks());
102 int AliHLTRootFileWriterComponent::ScanArgument(int argc, const char** argv)
104 // see header file for class documentation
105 // no other arguments known
106 if (argc==0 && argv==NULL) {
107 // this is just to get rid of the warning "unused parameter"
113 int AliHLTRootFileWriterComponent::WriteObject(const AliHLTEventID_t eventID, const TObject *pOb)
115 // see header file for class documentation
118 HLTDebug("write object %p (%s)", pOb, pOb->GetName());
119 if (!CheckMode(kConcatenateEvents) && eventID != fEventID &&
120 fCurrentFile!=NULL && eventID!=kAliHLTVoidEventID) {
121 TFile* pFile=fCurrentFile; fCurrentFile=NULL;
122 pFile->Close(); delete pFile;
124 if (fCurrentFile==NULL) {
125 fCurrentFile=OpenFile(eventID, 0);
126 if (fCurrentFile) fEventID=eventID;
138 TFile* AliHLTRootFileWriterComponent::OpenFile(const AliHLTEventID_t eventID, const int blockID, const char* option)
140 // see header file for class documentation
142 TString filename("");
143 if ((BuildFileName(eventID, blockID, kAliHLTVoidDataType, 0, filename))>=0 && filename.IsNull()==0) {
144 pFile=new TFile(filename, option);
146 if (pFile->IsZombie()) {
149 HLTError("can not open ROOT file %s", filename.Data());
152 HLTFatal("memory allocation failed");
155 HLTError("failed to build a new file name for event %#8x", eventID);