]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/exa/sampleAliHLTOUTHandlerEsdBranch.C
coveritiy
[u/mrichter/AliRoot.git] / HLT / exa / sampleAliHLTOUTHandlerEsdBranch.C
CommitLineData
acf07b19 1// $Id$
2/**
3 * @file sampleAliHLTOUTHandlerEsdBranch.C
4 * @brief Example macro to illustrate function of AliHLTOUTHandlerEsdBranch.
5 * @note Macro requires simulated raw data, please run e.g. ppbench setup.
6 *
7 * HLTOUT handlers inherit from class AliHLTOUTHandler and are utilized to
8 * process data blocks in the HLTOUT. As a specific case HLTOUT can contain
9 * data blocks/streamed objects designated for storage in custom ESD branches.
10 * AliHLTOUTHandlerEsdBranch provides an easy way to implement merging of
11 * such blocks/objects into the hltEsd.
12 *
13 * Usage: Simulate a data sample (e.g. ppbench) and run this macro in the
14 * folder for raw data reconstruction.
15 * <pre>
16 * aliroot -b -q -l sampleAliHLTOUTHandlerEsdBranch.C \
17 * | tee sampleAliHLTOUTHandlerEsdBranch.log
18 * </pre>
19 *
20 * The macro contains 3 parts:
21 * - the hltEsd layout object is adjusted in order to allow for the
22 * new branch
23 * - an object is generated, streamed and saved to file
24 * - a small HLT chain is run
25 *
26 * The HLT chain is as simple as just publishing the binary object file with
27 * the appropriate data type. The published object becomes part of the HLTOUT
28 * and the handler of the AliHLTAgentSample is called as it will announce
29 * the ability to process data blocks of this specific type from HLTOUT.
30 *
31 * @author Matthias.Richter@ift.uib.no
32 * @ingroup alihlt_tutorial
33 */
34void sampleAliHLTOUTHandlerEsdBranch()
35{
36 // require a simulated data sample, e.g. the ppbench setup
37 // we need raw data in order to run a custom HLT chain
38 TString datainput;
39 if (!gSystem->AccessPathName("raw.root")) datainput="raw.root";
40 else if (!gSystem->AccessPathName("raw0")) datainput="./";
41
42 TString grpstorage;
43 if (!gSystem->AccessPathName("GRP/GRP/Data")) grpstorage="local://$PWD";
44 else if (!gSystem->AccessPathName("../GRP/GRP/Data")) grpstorage="local://$PWD/..";
45
46 if (datainput.IsNull() || grpstorage.IsNull()) {
47 cout << "sampleAliHLTOUTHandlerEsdBranch.C: illustrate AliHLTOUTHandlerEsdBranch" << endl;
48 cout << " Usage: aliroot -b -q -l sampleAliHLTOUTHandlerEsdBranch.C" << endl;
49 cout << "" << endl;
50 cout << " Macro requieres a simulated data sample, please run e.g. ppbench setup" << endl;
51 cout << " and run in the folder with the raw data" << endl;
52 if (datainput.IsNull()) cout << "Error: no raw data input found" << endl;
53 if (grpstorage.IsNull()) cout << "Error: no GRP entry found in neither ./ nor ../" << endl;
54 return;
55 }
56
57 if (!gSystem->AccessPathName("galice.root")) {
58 cout << "AliReconstruction from raw data requires to delete the galice.root file" << endl;
59 cout << "of previous reconstruction cycles. IMPORTANT: do not delete the file in" << endl;
60 cout << "the simulation folder but run in a subfolder like e.g. recraw" << endl;
61 return;
62 }
63
64 // Basic settings
65 TString command;
66
67 TString objectFileName=gSystem->TempDirectory();
68 objectFileName+="/";objectFileName+="inputobject.dat";
69
70 // Create the input object
71 TClonesArray* inputObject=new TClonesArray("TNamed");
72 inputObject->SetName("MyPrivateBranch");
73
74 // Init OCDB
75 AliCDBManager * man = AliCDBManager::Instance();
76 man->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
77 // set specific storage for GRP entry
78 man->SetSpecificStorage("GRP/GRP/Data", grpstorage);
79
80 // Adjust hltEsd layout
81 //
82 // in order to allow custom branches for the HLT ESD a layout object is
83 // stored in OCDB. This object will be generated automatically in the future
84 // according to the online setup. It can be adapted manually to enable specific
85 // branches. In this example we add the input object (still an empty TClonesArray)
86 // to the layout and store the object.
87 const char* esdLayoutEntry="HLT/ConfigHLT/esdLayout";
88 if (gSystem->AccessPathName(esdLayoutEntry)) {
89 command="mkdir -p "; command+=esdLayoutEntry;
90 gSystem->Exec(command);
91 }
92 command="cp $ALICE_ROOT/OCDB/"; command+=esdLayoutEntry; command+="/Run* "; command+=esdLayoutEntry;
93 gSystem->Exec(command);
94 man->SetSpecificStorage(esdLayoutEntry, "local://$PWD");
95 man->SetRun(0);
96
97 AliCDBEntry* esdLayoutObject=man->Get(esdLayoutEntry);
98 AliESDEvent* esdLayout=(AliESDEvent*)esdLayoutObject->GetObject();
99 if (!esdLayout->FindListObject(inputObject->GetName())) {
100 esdLayout->AddObject(inputObject);
101 }
102 man->Put(esdLayout, esdLayoutObject->GetId(), esdLayoutObject->GetMetaData());
103 man->UnloadFromCache(esdLayoutEntry);
104
105 // now add some data to the input object, stream it and save to file
106 new ((*inputObject)[inputObject->GetEntriesFast()]) TNamed("data1","some data");
107 new ((*inputObject)[inputObject->GetEntriesFast()]) TNamed("data2","some more data");
108 AliHLTMessage* pMsg=AliHLTMessage::Stream(inputObject);
109 if (!pMsg) {
110 cerr << "failed to stream input object" << endl;
111 return;
112 }
113 ofstream objectFile(objectFileName);
114 objectFile.write(pMsg->Buffer(), pMsg->Length());
115 objectFile.close();
116 delete pMsg;
117 if (gSystem->AccessPathName(objectFileName)) {
118 cerr << "failed to write input file " << objectFileName << endl;
119 return;
120 }
121
122 //////////////////////////////////////////////////////////////////////////////////////
123 //
124 // Reconstruction settings
125 AliReconstruction rec;
126
127 rec.SetRunReconstruction("HLT ITS TPC");
128 rec.SetInput(datainput);
129 rec.SetWriteESDfriend(kFALSE);
130
131 // QA options
132 rec.SetRunQA(":") ;
133 //rec.SetQARefDefaultStorage("local://$ALICE_ROOT/QAref") ;
134
135 //////////////////////////////////////////////////////////////////////////////////////
136 //
137 // setup the HLT system
138 AliHLTSystem* pHLT=AliHLTPluginBase::GetInstance();
139
140 // define the HLT chain to be run in AliReconstruction
141 // arguments:
142 // 1) id of the configuartion, later used to refer to this configuration
143 // 2) id of the component to run
144 // 3) parents, no parents in this case
145 // 4) optional component arguments
146 TString arguments;
147 arguments.Form("-datatype ROOTTOBJ SMPL -datafile %s", objectFileName.Data());
148 AliHLTConfiguration publisher("Object-Publisher", "FilePublisher", "", arguments.Data());
149
150 // set option for the HLT module in AliReconstruction
151 // arguments
152 // - ignore-hltout : ignore the HLTOUT payload from the HLT DDLs
153 // - libraries to be used as plugins
154 // - loglevel=0x7c : Info, Important, Warning, Error, Fatal
155 // - chains=Object-Publisher : chains to be run
156 rec.SetOption("HLT",
157 "ignore-hltout "
158 "libAliHLTSample.so "
159 "loglevel=0x7c "
160 "chains=Object-Publisher "
161 );
162
163 rec.SetRunPlaneEff(kFALSE);
164
165 // switch off cleanESD
166 rec.SetCleanESD(kFALSE);
167
168 AliLog::Flush();
169 rec.Run();
170
171}