]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGLF/FORWARD/trains/OutputUtilities.C
Added ignores
[u/mrichter/AliRoot.git] / PWGLF / FORWARD / trains / OutputUtilities.C
1 /** 
2  * @defgroup pwglf_forward_trains_util Utilities for Train setups
3  *
4  * @ingroup pwglf_forward_trains
5  */
6 /**
7  * @file   OutputUtilities.C
8  * @author Christian Holm Christensen <cholm@master.hehi.nbi.dk>
9  * @date   Tue Oct 16 17:55:32 2012
10  * 
11  * @brief  Special output handling
12  * 
13  * @ingroup pwglf_forward_trains_util
14  */
15 #ifndef TREEOUTPUTHELPER_C
16 #define TREEOUTPUTHELPER_C
17 #ifndef __CINT__
18 # include <TString.h>
19 # include <TError.h>
20 # include <AliAnalysisManager.h>
21 # include <AliAnalysisDataContainer.h>
22 # include <AliVEventHandler.h>
23 #else
24 class TString;
25 #endif
26
27 // ===================================================================
28 /**
29  * Special output handling - data sets and remote storage
30  *
31  * @ingroup pwglf_forward_trains_util
32  */
33 struct OutputUtilities
34 {
35   /** 
36    * Register output data set 
37    * 
38    * @param dsname Data set name 
39    * 
40    * @return true on success
41    */
42   static Bool_t RegisterDataset(const TString& dsname)
43   {
44     // Get the manager
45     AliAnalysisManager* mgr = AliAnalysisManager::GetAnalysisManager();
46     
47     // If we are asked to make a data-set, get the output handler and
48     // common output container.
49     AliVEventHandler*         handler = mgr->GetOutputEventHandler();
50     if (!handler) return true;
51
52     // Get the container 
53     AliAnalysisDataContainer* cont    = mgr->GetCommonOutputContainer();
54     if (!cont) { 
55       Warning("OutputUtilities::RegisterDataset", 
56               "No common output container defined");
57       return false;
58     }
59
60     // Make the name 
61     TString nme(dsname);
62     if (nme.IsNull()) nme = mgr->GetName();
63     if (nme.IsNull()) { 
64       Error("OutputUtilities::RegisterDataset", "No data set name specified");
65       return false;
66     }
67
68     // Flag for data-set creation
69     cont->SetRegisterDataset(true);
70
71     handler->SetOutputFileName(nme);
72     // cont->SetFileName(nme);
73
74     TString base(handler->GetOutputFileName());
75     base.ReplaceAll(".root","");
76     Info("OutputUtilities::RegisterDataset", 
77          "Will register tree output AODs (%s%s) as dataset",
78          base.Data(), cont->GetTitle());
79
80     return true;
81   }
82   /** 
83    * Get the name of the registered data set
84    * 
85    * 
86    * @return Name of the registered data set
87    */
88   static TString RegisteredDataset()
89   {
90     TString ret;
91
92     AliAnalysisManager* mgr = AliAnalysisManager::GetAnalysisManager();
93     AliVEventHandler*   oh  = mgr->GetOutputEventHandler();
94     if (!oh) { 
95       Warning("OutputUtilities::GetOutputDataSet", 
96               "No outout event handler defined");
97       return ret;
98     }
99     AliAnalysisDataContainer* co  = mgr->GetCommonOutputContainer();
100     if (!co) { 
101       Warning("OutputUtilities::GetOutputDataSet", 
102               "No common output container defined");
103       return ret;
104     }
105     if (!co->IsRegisterDataset()) { 
106       Info("OutputUtilities::GetOutputDataSet", 
107            "Common output is not registered as dataset");
108       return ret;
109     }
110     ret = oh->GetOutputFileName();
111     // ret.ReplaceAll("TTree", "");
112     ret.ReplaceAll(".root", "");
113     // ret.Append(co->GetTitle());
114
115     return ret;
116   }
117   /** 
118    * Register special putput storage 
119    * 
120    * @param url Url (root://host/full_path)
121    * 
122    * @return true on success
123    */
124   static Bool_t RegisterStorage(const TString& url)
125   {
126     if (url.IsNull()) { 
127       Error("OutputUtilities::RegisterStorage", "No storage URI specified");
128       return false;
129     }
130
131     // Get the manager
132     AliAnalysisManager* mgr = AliAnalysisManager::GetAnalysisManager();
133     
134     // Get the container 
135     AliAnalysisDataContainer* cont    = mgr->GetCommonOutputContainer();
136     if (!cont) { 
137       Warning("OutputUtilities::RegisterStorage", 
138               "No common output container defined");
139       return false;
140     }
141
142     cont->SetSpecialOutput();
143     mgr->SetSpecialOutputLocation(url);
144
145     return true;
146   }
147 };
148 #endif
149 //
150 // EOF
151 //