fEvents(),
fMaxSize(0),
fOpenFilesAtStart(false),
- fOutputDataTypes()
+ fOutputDataTypes(),
+ fIsRaw(kTRUE)
{
// see header file for class documentation
// or
if (!bHaveDatatype) {
HLTWarning("no data type available so far, please set data type and specification before the file name. The first available data type will be set for all files preceding it");
}
- FileDesc* pDesc=new FileDesc(argv[i], currDataType, currSpecification);
+ FileDesc* pDesc=new FileDesc(argv[i], currDataType, currSpecification, fIsRaw);
if (pDesc) {
iResult=InsertFile(pCurrEvent, pDesc);
} else {
// return 0;
// }
-AliHLTFilePublisher::FileDesc::FileDesc(const char* name, AliHLTComponentDataType dt, AliHLTUInt32_t spec)
+AliHLTFilePublisher::FileDesc::FileDesc(const char* name, AliHLTComponentDataType dt, AliHLTUInt32_t spec, Bool_t isRaw)
:
TObject(),
+ fIsRaw(isRaw),
fName(name),
fpInstance(NULL),
fDataType(dt),
{
// see header file for class documentation
int iResult=0;
- TString fullFN= fName + "?filetype=raw";
+
+ TString fullFN="";
+
+ if ( fIsRaw ) fullFN = fName + "?filetype=raw";
+ else fullFN = fName;
+
fpInstance = new TFile(fullFN);
if (fpInstance) {
if (fpInstance->IsZombie()==0) {
*/
int OpenFiles(bool keepOpen);
+ /** Get List of Events, needed in the RootFilePublisher.*/
+ TList* GetEventList() { return &fEvents;}
+
+ /** Set if root files instead of raw files should be read,
+ * needed in the RootFilePublisher.
+ * @param isRaw kTRUE if raw file, kFALSE for rootfile
+ */
+ void SetIsRawFile( Bool_t isRaw ) { fIsRaw = isRaw; }
+
protected:
/**
* Init method.
*/
virtual int ScanArgument(int argc, const char** argv);
- protected:
/**
* Get the data type which is set for the current file
*/
/** prohibit assignment operator */
AliHLTFilePublisher& operator=(const AliHLTFilePublisher&);
+ protected:
/**
* File descriptor.
*/
/** constructor not implemented */
FileDesc();
/** constructor to use */
- FileDesc(const char* name, AliHLTComponentDataType dt, AliHLTUInt32_t spec);
+ FileDesc(const char* name, AliHLTComponentDataType dt, AliHLTUInt32_t spec, Bool_t isRaw=kTRUE);
/** destructor */
~FileDesc();
/** prohibited copy operator */
FileDesc& operator=(FileDesc&);
+ /** is raw (kTRUE) or root (kFALSE) file */
+ Bool_t fIsRaw; //! transient
/** file name */
TString fName; //! transient
/** file instance */
TList fEvents; //! transient
/** the maximum buffer size i.e. size of the biggest file */
- Int_t fMaxSize; //! transient
+ Int_t fMaxSize; //! transient
/** Flag specifying if all the files should be opened during initialisation. */
bool fOpenFilesAtStart; //! transient
/** output data types */
AliHLTComponentDataTypeList fOutputDataTypes; //! transient
- ClassDef(AliHLTFilePublisher, 2)
+ /** Is raw file (kTRUE) [default] or root file (kFALSE). */
+ Bool_t fIsRaw; //! transient
+
+ ClassDef(AliHLTFilePublisher, 3)
};
#endif
**************************************************************************/
/** @file AliHLTRootFilePublisherComponent.cxx
- @author Matthias Richter
+ @author Matthias Richter, Jochen Thaeder
@date
@brief HLT file publisher component implementation. */
//#include <TMath.h>
//#include <TFile.h>
-// temporary
-#include "TH1F.h"
+#include "TList.h"
+#include "TTree.h"
+#include "TKey.h"
+#include "TFile.h"
+
/** ROOT macro for the implementation of ROOT specific class methods */
ClassImp(AliHLTRootFilePublisherComponent)
+/*
+ * ---------------------------------------------------------------------------------
+ * Constructor / Destructor
+ * ---------------------------------------------------------------------------------
+ */
+
+// #################################################################################
AliHLTRootFilePublisherComponent::AliHLTRootFilePublisherComponent()
:
- AliHLTFilePublisher()
-{
+ AliHLTFilePublisher(),
+ fpCurrentEvent(NULL),
+ fObjectName("") {
// see header file for class documentation
// or
// refer to README to build package
// or
// visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
+ // Set file to ROOT-File
+ SetIsRawFile( kFALSE );
}
-AliHLTRootFilePublisherComponent::~AliHLTRootFilePublisherComponent()
-{
+// #################################################################################
+AliHLTRootFilePublisherComponent::~AliHLTRootFilePublisherComponent() {
// see header file for class documentation
// file list and file name list are owner of their objects and
// delete all the objects
}
-const char* AliHLTRootFilePublisherComponent::GetComponentID()
-{
- // see header file for class documentation
- return "ROOTFilePublisher";
-}
-
-AliHLTComponentDataType AliHLTRootFilePublisherComponent::GetOutputDataType()
-{
- // see header file for class documentation
- AliHLTComponentDataType dt =
- {sizeof(AliHLTComponentDataType),
- kAliHLTVoidDataTypeID,
- kAliHLTVoidDataOrigin};
- return dt;
-}
+/*
+ * ---------------------------------------------------------------------------------
+ * Public functions to implement AliHLTComponent's interface.
+ * These functions are required for the registration process
+ * ---------------------------------------------------------------------------------
+ */
-void AliHLTRootFilePublisherComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
-{
+// #################################################################################
+const char* AliHLTRootFilePublisherComponent::GetComponentID() {
// see header file for class documentation
- constBase=10000;
- inputMultiplier=1.0;
+ return "ROOTFilePublisher";
}
-AliHLTComponent* AliHLTRootFilePublisherComponent::Spawn()
-{
+// #################################################################################
+AliHLTComponent* AliHLTRootFilePublisherComponent::Spawn() {
// see header file for class documentation
return new AliHLTRootFilePublisherComponent;
}
-int AliHLTRootFilePublisherComponent::ScanArgument(int argc, const char** argv)
-{
+/*
+ * ---------------------------------------------------------------------------------
+ * Protected functions to implement AliHLTComponent's interface.
+ * These functions provide initialization as well as the actual processing
+ * capabilities of the component.
+ * ---------------------------------------------------------------------------------
+ */
+
+// #################################################################################
+Int_t AliHLTRootFilePublisherComponent::ScanArgument(Int_t argc, const char** argv) {
// see header file for class documentation
- // there are no other arguments than the standard ones
- if (argc==0 && argv==NULL) {
- // this is just to get rid of the warning "unused parameter"
+ Int_t iResult = 0;
+
+ TString argument = "";
+ TString parameter = "";
+ Int_t bMissingParam = 0;
+
+ argument=argv[iResult];
+ if (argument.IsNull()) return -EINVAL;
+
+ // -objectname
+ if ( !argument.CompareTo("-objectname") ) {
+ if ( ! (bMissingParam=(++iResult>=argc)) ) {
+ parameter = argv[iResult];
+ parameter.Remove(TString::kLeading, ' '); // remove all blanks
+ fObjectName = parameter;
+ }
+ }
+ else {
+ HLTError("unknown argument %s", argument.Data());
+ iResult = -EINVAL;
+ }
+
+ if ( bMissingParam ) {
+ HLTError("missing parameter for argument %s", argument.Data());
+ iResult = -EPROTO;
}
- int iResult=-EPROTO;
- return iResult;
-}
-int AliHLTRootFilePublisherComponent::OpenFiles()
-{
- // see header file for class documentation
- int iResult=0;
return iResult;
}
-int AliHLTRootFilePublisherComponent::GetEvent( const AliHLTComponentEventData& /*evtData*/,
+ // #################################################################################
+Int_t AliHLTRootFilePublisherComponent::GetEvent( const AliHLTComponentEventData& /*evtData*/,
AliHLTComponentTriggerData& /*trigData*/,
AliHLTUInt8_t* /*outputPtr*/,
- AliHLTUInt32_t& /*size*/,
- vector<AliHLTComponentBlockData>& /*outputBlocks*/ )
-{
+ AliHLTUInt32_t& size,
+ vector<AliHLTComponentBlockData>& /*outputBlocks*/ ) {
// see header file for class documentation
- int iResult=0;
- if (GetEventCount()%2==0) {
- TH1F *hpx = new TH1F("hpx","px distribution",100,-4,4);
- hpx->FillRandom("gaus",1000);
- PushBack(hpx, "TH1F", "ROOT");
- delete hpx;
+
+ if ( !IsDataEvent() ) return 0;
+
+ Int_t iResult=0;
+ size=0;
+
+ // -- Ptr to current event
+ TObjLink *lnk = fpCurrentEvent;
+ if ( lnk == NULL) {
+ lnk = GetEventList()->FirstLink();
+ fpCurrentEvent = lnk;
+ }
+
+ if ( lnk ) {
+ EventFiles* pEventDesc = dynamic_cast<EventFiles*>( lnk->GetObject() );
+ if (pEventDesc) {
+
+ HLTDebug("publishing files for event %p", pEventDesc);
+ TList& files=*pEventDesc; // type conversion operator defined
+ TObjLink *flnk=files.FirstLink();
+
+ while (flnk && iResult>=0) {
+
+ FileDesc* pFileDesc=dynamic_cast<FileDesc*>(flnk->GetObject());
+
+ if (not fOpenFilesAtStart) pFileDesc->OpenFile();
+ TFile* pFile=NULL;
+
+ if (pFileDesc && (pFile=*pFileDesc)!=NULL) {
+
+ for ( Int_t i = 0; i < pFile->GetListOfKeys()->GetEntries(); i++ ){
+ TKey * key= dynamic_cast<TKey*>( pFile->GetListOfKeys()->At(i) );
+
+ if ( fObjectName ) {
+ if ( !( ((TString) key->GetName()).CompareTo(fObjectName) ) )
+ PushBack( key->ReadObj(), *pFileDesc, *pFileDesc );
+ }
+ else
+ PushBack( key->ReadObj(), *pFileDesc, *pFileDesc );
+ // above : type conversion operator defined for DataType and Spec
+ }
+
+ if (not fOpenFilesAtStart) pFileDesc->CloseFile();
+ } else {
+ HLTError("no file available");
+ iResult=-EFAULT;
+ }
+ flnk = flnk->Next();
+ }
+ } else {
+ HLTError("can not get event descriptor from list link");
+ iResult=-EFAULT;
+ }
} else {
- TH1F *hpy = new TH1F("hpy","py distribution",100,-10,10);
- hpy->FillRandom("gaus",10000);
- PushBack(hpy, "TH1F", "ROOT");
- delete hpy;
+ iResult=-ENOENT;
}
+ if (iResult>=0 && fpCurrentEvent) fpCurrentEvent=fpCurrentEvent->Next();
return iResult;
}
//* See cxx source for full Copyright notice *
/** @file AliHLTRootFilePublisherComponent.h
- @author Matthias Richter
+ @author Matthias Richter, Jochen Thaeder
@date
@brief component for publishing of Root objects from a root file.
@note The class is used in Offline (AliRoot) context
/**
* @class AliHLTRootFilePublisherComponent
- * \Note: This component is not what it pretends to be. So far it was just
- * used for debugging purpose. If you need a component publishing objects
- * from a root file make a feature request at <br>
- * https://savannah.cern.ch/projects/alicehlt/
- * and assign it to richterm. <br>
- * Or even better, start the development, any contributions are welcome.
+ * An HLT data source component which publishes root objects from one
+ * or a sequence of root files. Be aware, one root file can contain
+ * several root objects. Either all objects or one objectcan be selected.<br>
*
- * Component ID: \b RootFilePublisherComponent <br>
- * Library: \b libAliHLTUtil.
+ * <h2>General properties:</h2>
*
- * Mandatory arguments: <br>
+ * Component ID: \b RootFilePublisher <br>
+ * Library: \b libAliHLTUtil.so <br>
+ * Input Data Types: none <br>
+ * Output Data Types: according to arguments <br>
*
- * Optional arguments:<br>
+ * <h2>Mandatory arguments:</h2>
+ * @see AliHLTFilePublisher for mandatory defaultarguments
*
- * @see AliHLTFilePublisher for default arguments
+ * <h2>Optional arguments:</h2>
+ * @see AliHLTFilePublisher for optional default arguments
+ * <!-- NOTE: ignore the \li. <i> and </i>: it's just doxygen formatting -->
+ * \li -objectname <i> objectname </i>
+ * Name of the object in the root file to be fetched. This is set for
+ * all events/files. If not given, all objects are fetched.
+ *
+ * <h2>Configuration:</h2>
+ * <!-- NOTE: ignore the \li. <i> and </i>: it's just doxygen formatting -->
+ * Configuration by component arguments.
+ *
+ * <h2>Default CDB entries:</h2>
+ * The component loads no CDB entries.
+ *
+ * <h2>Performance:</h2>
+ * The component does not process any event data.
+ *
+ * <h2>Memory consumption:</h2>
+ * The component does not process any event data.
+ *
+ * <h2>Output size:</h2>
+ * According to the available data. The component is an AliHLTDataSource
+ * and inteded to be used in the AliHLTSystem framework only. The component
+ * implements the standard AliHLTSystem adaptive buffer allocation.
+ *
+ * The component needs at least one argument \em -datafile or \em -datafilelist.
+ * Both can occur multiple times. The \em -datatype and \em -dataspec
+ * parameters are valid for all files until the next occurrence of
+ * \em -datatype/spec.
+ * All files are published within one event, unless the \em -nexevent specifies
+ * where to break into multiple events. Be aware, one root file can contain
+ * several root objects. If \em -objectname is not used to select one, all
+ * objects are all published with the same datatype and specification.
*
* @ingroup alihlt_util_components
*/
+
class AliHLTRootFilePublisherComponent : public AliHLTFilePublisher {
public:
+
+ /*
+ * ---------------------------------------------------------------------------------
+ * Constructor / Destructor
+ * ---------------------------------------------------------------------------------
+ */
+
/** standard constructor */
AliHLTRootFilePublisherComponent();
+
/** destructor */
virtual ~AliHLTRootFilePublisherComponent();
+
+ /*
+ * ---------------------------------------------------------------------------------
+ * Public functions to implement AliHLTComponent's interface.
+ * These functions are required for the registration process
+ * ---------------------------------------------------------------------------------
+ */
+ /** interface function, see @ref AliHLTComponent for description */
const char* GetComponentID();
- AliHLTComponentDataType GetOutputDataType();
- void GetOutputDataSize( unsigned long& constBase, double& inputMultiplier );
+
+ /** interface function, see @ref AliHLTComponent for description */
AliHLTComponent* Spawn();
- /**
- * Open all files.
- * Opens all files for all events from the event list @ref fEvents and adds TFile
- * opjects to the internal list.
+ protected:
+ /*
+ * ---------------------------------------------------------------------------------
+ * Protected functions to implement AliHLTComponent's interface.
+ * These functions provide initialization as well as the actual processing
+ * capabilities of the component.
+ * ---------------------------------------------------------------------------------
*/
- int OpenFiles();
- protected:
/**
* Data processing method for the component.
* The component uses the @ref alihltcomponent-high-level-interface
* to put serialized Root object into the output stream. Despite of that it
- * implements the lox-level DumpEvent method in order to allow child classes
+ * implements the low-level DumpEvent method in order to allow child classes
* to use the low-level method.
* @param evtData event data structure
* @param trigData trigger data structure
* @param outputBlocks not used
* @return
*/
- int GetEvent( const AliHLTComponentEventData& evtData,
+ Int_t GetEvent( const AliHLTComponentEventData& evtData,
AliHLTComponentTriggerData& trigData,
AliHLTUInt8_t* outputPtr,
AliHLTUInt32_t& size,
* -EINVAL unknown argument <br>
* -EPROTO parameter for argument missing <br>
*/
- virtual int ScanArgument(int argc, const char** argv);
+ virtual Int_t ScanArgument(Int_t argc, const char** argv);
private:
+
+ /*
+ * ---------------------------------------------------------------------------------
+ * Private functions to implement AliHLTComponent's interface.
+ * These functions provide initialization as well as the actual processing
+ * capabilities of the component.
+ * ---------------------------------------------------------------------------------
+ */
+
/** copy constructor prohibited */
AliHLTRootFilePublisherComponent(const AliHLTRootFilePublisherComponent&);
+
/** assignment operator prohibited */
AliHLTRootFilePublisherComponent& operator=(const AliHLTRootFilePublisherComponent&);
+ /*
+ * ---------------------------------------------------------------------------------
+ * Members - private
+ * ---------------------------------------------------------------------------------
+ */
+
+ /** The current event */
+ TObjLink *fpCurrentEvent; //! transient
+
+ /** Name of the object which should be fetched
+ * from the root file.
+ */
+ TString fObjectName; //! objectname
+
ClassDef(AliHLTRootFilePublisherComponent, 0)
};
#endif
--- /dev/null
+
+/**
+ * @file rootfilepublisher-sample.C
+ * @brief Macro for testing ROOT-file publishing and writing
+ *
+ * This macro is a testing/example macro of how to use the RootFilePublisher
+ * (AliHLTRootFilePublisher) and RootFileWriter (AliHLTRootFileWriter).
+ * It defines only two component in the chain, the publisher, which
+ * publishes the content of the root files according to the selection.
+ * Be aware there can be several root objects in one root file.
+ *
+ * The file myRootFile.root has to be changed with the actual file.
+ * In this example, an ESD file is used, which contains a "esdTree" and
+ * a "HLTesdTree" object. Only the "HLTesdTree" object is selected. The
+ * data blocks, which will are published here, have the data type of
+ * {ROOTTOBJ,"***"} and specification of 0x00000000. They also have to
+ * been adopted to the actual content of the root file.
+ *
+ * @author thaeder@kip.uni-heidelberg.de
+ * @ingroup alihlt_tutorial
+ */
+
+/** RootFilePublisher test macro
+ * @param nEvents Number of events which should be processed
+ */
+void rootfilepublisher(Int_t nEvents=1) {
+
+ TString writerInput;
+ TString arg;
+
+ AliHLTSystem gHLT;
+ gHLT.LoadComponentLibraries("libAliHLTUtil.so");
+
+ // -- Root publisher configuration
+ // !!! myRootFile.root has to be exchanged with an existing one.
+ arg.Form("-objectname HLTesdTree -datatype 'ESD_TREE' 'TPC '-dataspec 0x00000000 -datafile myRootFile.root");
+
+ // -- The AliHLTRootFilePublisher (component Id \em 'ROOTFilePublisher' provides
+ // the given file (see AliHLTRootFilePublisher for more options) to the
+ // subsequent components in the chain.
+ AliHLTConfiguration rootPublisher("RootPublisher", "ROOTFilePublisher", NULL, arg.Data() );
+
+ // -
+ // -- Processing Components can be put in here
+ // -
+
+ // -- The AliHLTRootFileWriter (Id 'ROOTFileWriter') is a data sink. It writes
+ // all incoming data blocks to files. Several options available.
+ // AliHLTConfiguration sink1("sink1", "FileWriter", "ESDPublisher", NULL);
+ AliHLTConfiguration rootWriter("RootWriter", "ROOTFileWriter", "RootPublisher","-datafile event");
+
+ // -- Here you specify the top most configuration of the chain. The
+ // configuration depends on all the parents. The task lisy is build
+ // according to that.
+ gHLT.BuildTaskList("RootWriter");
+ gHLT.Run(nEvents);
+}