]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/exa/extract-ddlraw.C
Fixing comments
[u/mrichter/AliRoot.git] / HLT / exa / extract-ddlraw.C
1 // $Id$
2 /**
3  * @file extract-ddlraw.C
4  * @brief Tool to extract DDL raw data.
5  *
6  * Usage:
7  * <pre>
8  *   aliroot -b -q 'extract-ddlraw.C("raw.root", 768, 769)' | tee extract-ddlraw.log
9  * </pre>
10  *
11  * This macro is an example for the AliHLTRawReaderPublisherComponent.
12  * It extracts the DDL payload from an AliRawReader in a given equipment
13  * range. Input can be either a root file or the path to the directory
14  * containing the 'rawx' sub folders.
15  *
16  * A light-weight AliReconstruction-like setup creates the appropriate
17  * RawReader for the specified input and uses the standard AliHLTReconstructor
18  * to run a small HLT chain. The chain utilizes the AliRawReaderPublisher
19  * to extract the payload of the equipments and writes this to files.
20  *
21  * @note In this example the AliHLTRawReaderPublisherComponent does not set any data
22  * type nor specification for the published data blocks. Please remember
23  * to provide appropriate arguments via '-datatype' and '-dataspec'
24  * arguments (see AliHLTRawReaderPublisherComponent).
25  *
26  * @author Matthias.Richter@ift.uib.no
27  * @ingroup alihlt_tutorial
28  */
29 void extract_ddlraw(const char* input, int iMinDDLno, int iMaxDDLno)
30 {
31   /////////////////////////////////////////////////////////////////////////
32   /////////////////////////////////////////////////////////////////////////
33   //
34   // some defaults
35   const char* baseName="RAW.ddl";
36
37   /////////////////////////////////////////////////////////////////////////
38   /////////////////////////////////////////////////////////////////////////
39   //
40   // setup of the RawReader
41   if (!input) {
42     cerr << "invalid path" << endl;
43     cerr << "usage: aliroot -b -q 'extract-ddlraw.C(\"raw.root\", 768, 769)'" << endl;
44     return;
45   }
46
47   AliRawReader* pRawReader=AliRawReader::Create(input);
48   if (!pRawReader) {
49     cout << "can not open RawReader for file " << input << endl;
50     return;
51   }
52   if (!pRawReader->NextEvent()) {
53     cerr << "no events available" << endl;
54     return;
55   }
56
57   /////////////////////////////////////////////////////////////////////////
58   /////////////////////////////////////////////////////////////////////////
59   //
60   // setup of the HLT system
61   AliHLTSystem* pHLT=AliHLTPluginBase::GetInstance();
62   if (!pHLT) {
63     cerr << "fatal error: can not get HLT instance" << endl;
64   }
65
66   /////////////////////////////////////////////////////////////////////////
67   /////////////////////////////////////////////////////////////////////////
68   //
69   // the configuration chain
70   // we show two possible configurations:
71   //  1. having one publisher for each ddl, the configurations are created
72   //     in a loop
73   //  2. all in one publisher
74   // can be easily switched with the following
75   bool bAllInOne=false;
76
77   TString writerInput;
78   TString arg;
79
80   if (!bAllInOne) {
81     // create one publisher for each ddl
82     for (int ddlno=iMinDDLno; ddlno<=iMaxDDLno; ddlno++) {
83       TString arg, publisher;
84
85       // raw data publisher components
86       arg.Form("-minid %d -skipempty -verbose", ddlno);
87       publisher.Form("DP_%d", ddlno);
88       // see AliHLTRawReaderPublisherComponent
89       AliHLTConfiguration pubconf(publisher.Data(), "AliRawReaderPublisher", NULL , arg.Data());
90
91       if (!writerInput.IsNull()) writerInput+=" ";
92       writerInput+=publisher;
93     }
94   } else {
95     // publish all ddls by the same component, this is much more
96     // effective as it avoids repeated parsing through the data
97     arg.Form("-minid %d -maxid %d -skipempty -verbose", iMinDDLno, iMaxDDLno);
98     // see AliHLTRawReaderPublisherComponent
99     AliHLTConfiguration pubconf("publisher", "AliRawReaderPublisher", NULL , arg.Data());
100     if (!writerInput.IsNull()) writerInput+=" ";
101     writerInput+="publisher";
102   }
103
104   // the writer configuration is the same for both
105   arg.Form("-specfmt=_%%d -subdir=raw%%d -blcknofmt= -idfmt= -datafile %s", baseName);
106   // see AliHLTFileWriter
107   AliHLTConfiguration fwconf("sink1", "FileWriter"   , writerInput.Data(), arg.Data());
108
109
110   /////////////////////////////////////////////////////////////////////////
111   /////////////////////////////////////////////////////////////////////////
112   //
113   // the reconstructor setup
114   AliHLTReconstructor hltRec;
115   hltRec.SetOption("libAliHLTUtil.so loglevel=0x7c chains=sink1");
116   if (hltRec.Init()<0) {
117     cerr << "initialization of reconstructor failed" << endl;
118     return;
119   }
120
121   // this is just a dummy ESD to provide valid parameters to the
122   // reconstructor
123   AliESDEvent* pESD = new AliESDEvent;
124   pESD->CreateStdContent();
125
126   /////////////////////////////////////////////////////////////////////////
127   /////////////////////////////////////////////////////////////////////////
128   //
129   // the reconstruction loop
130   Int_t event=0;
131   UChar_t* pData=NULL;
132   pRawReader->RewindEvents();
133   while (pRawReader->NextEvent()) {
134     cout << "=======================================================" << endl;
135     cout << "event " << event << endl;
136     cout << "-------------------------------------------------------" << endl;
137     pRawReader->Reset();
138     hltRec.Reconstruct(pRawReader, NULL);
139     event++;
140   }
141
142   delete pESD;
143 }
144
145 void extract_ddlraw()
146 {
147   cerr << "===============================================================" << endl;
148   cerr << "usage: aliroot -b -q 'extract-ddlraw.C(\"raw.root\", 768, 769)'" << endl << endl;
149   cerr << "please provide input, min and max equipment id" << endl;
150   cerr << "===============================================================" << endl;
151 }