3 /** @file AliHLTRootFileWriterComponent.cxx
4 @author Matthias Richter
6 @brief Base class for writer components to store data in a ROOT file
10 #include "AliHLTRootFileWriterComponent.h"
14 /** the global object for component registration */
15 AliHLTRootFileWriterComponent gAliHLTRootFileWriterComponent;
17 /** ROOT macro for the implementation of ROOT specific class methods */
18 ClassImp(AliHLTRootFileWriterComponent)
20 AliHLTRootFileWriterComponent::AliHLTRootFileWriterComponent()
23 fEventID(kAliHLTVoidEventID),
26 // see header file for class documentation
28 // refer to README to build package
30 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
32 // all blocks of one event go into the same file
33 SetMode(kConcatenateBlocks);
36 AliHLTRootFileWriterComponent::AliHLTRootFileWriterComponent(const AliHLTRootFileWriterComponent&)
39 fEventID(kAliHLTVoidEventID),
42 // see header file for class documentation
43 HLTFatal("copy constructor untested");
46 AliHLTRootFileWriterComponent& AliHLTRootFileWriterComponent::operator=(const AliHLTRootFileWriterComponent&)
48 // see header file for class documentation
49 HLTFatal("assignment operator untested");
53 AliHLTRootFileWriterComponent::~AliHLTRootFileWriterComponent()
55 // see header file for class documentation
58 int AliHLTRootFileWriterComponent::DumpEvent( const AliHLTComponentEventData& evtData,
59 const AliHLTComponentBlockData* blocks,
60 AliHLTComponentTriggerData& trigData )
62 // see header file for class documentation
64 if (evtData.fStructSize==0 && blocks==NULL && trigData.fStructSize==0) {
65 // this is just to get rid of the warning "unused parameter"
67 const TObject* pObj=GetFirstInputObject(kAliHLTAnyDataType);
68 HLTDebug("got first object %p", pObj);
70 while (pObj && iResult>=0) {
71 iResult=WriteObject(evtData.fEventID, pObj);
74 HLTDebug("wrote object of class %s, data type %s", pObj->ClassName(), (DataType2Text(GetDataType(pObj)).c_str()));
76 pObj=GetNextInputObject();
78 HLTDebug("wrote %d of %d object(s) to file", count, GetNumberOfInputBlocks());
82 int AliHLTRootFileWriterComponent::ScanArgument(int argc, const char** argv)
84 // see header file for class documentation
85 // no other arguments known
86 if (argc==0 && argv==NULL) {
87 // this is just to get rid of the warning "unused parameter"
93 int AliHLTRootFileWriterComponent::WriteObject(const AliHLTEventID_t eventID, const TObject *pOb)
95 // see header file for class documentation
98 HLTDebug("write object %p (%s)", pOb, pOb->GetName());
99 if (CheckMode(kConcatenateEvents) && eventID != fEventID &&
100 fCurrentFile!=NULL && eventID!=kAliHLTVoidEventID) {
101 TFile* pFile=fCurrentFile; fCurrentFile=NULL;
102 pFile->Close(); delete pFile;
104 if (fCurrentFile==NULL) {
105 fCurrentFile=OpenFile(eventID, 0);
106 if (fCurrentFile) fEventID=eventID;
118 TFile* AliHLTRootFileWriterComponent::OpenFile(const AliHLTEventID_t eventID, const int blockID, const char* option)
120 // see header file for class documentation
122 TString filename("");
123 if ((BuildFileName(eventID, blockID, kAliHLTVoidDataType, filename))>=0 && filename.IsNull()==0) {
124 pFile=new TFile(filename, option);
126 if (pFile->IsZombie()) {
129 HLTError("can not open ROOT file %s", filename.Data());
132 HLTFatal("memory allocation failed");
135 HLTError("failed to build a new file name for event %#8x", eventID);