3 |
|
#include "MitProd/TreeService/interface/TreeService.h" |
4 |
|
#include "DataFormats/Provenance/interface/ModuleDescription.h" |
5 |
|
#include "FWCore/ParameterSet/interface/ParameterSet.h" |
6 |
– |
#include "FWCore/ServiceRegistry/interface/ActivityRegistry.h" |
7 |
– |
#include "FWCore/ServiceRegistry/interface/Service.h" |
6 |
|
#include "FWCore/MessageLogger/interface/JobReport.h" |
7 |
+ |
#include "FWCore/MessageLogger/interface/MessageLogger.h" |
8 |
|
#include "MitAna/DataUtil/interface/TreeWriter.h" |
9 |
|
#include "MitAna/DataTree/interface/Names.h" |
10 |
+ |
#include "MitCommon/OptIO/interface/OptInt.h" |
11 |
|
|
12 |
|
using namespace edm; |
13 |
|
using namespace std; |
14 |
|
using namespace mithep; |
15 |
|
|
16 |
|
//-------------------------------------------------------------------------------------------------- |
17 |
< |
TreeService::TreeService(const ParameterSet &cfg, ActivityRegistry &r) : |
18 |
< |
tws_ (0) |
17 |
> |
TreeService::TreeService(const ParameterSet &cfg) : |
18 |
> |
tws_(0), |
19 |
> |
zipMode_(1), |
20 |
> |
bZipThres_(1), |
21 |
> |
gZipThres_(1), |
22 |
> |
lzoThres_(1), |
23 |
> |
lzmaThres_(1), |
24 |
> |
optIOVerbose_(1), |
25 |
> |
fDoReset_(cfg.getUntrackedParameter<bool>("doReset",1)) |
26 |
|
{ |
27 |
+ |
// Constructor. |
28 |
+ |
|
29 |
|
if (cfg.exists("treeNames")) |
30 |
|
treeNames_=cfg.getUntrackedParameter<vector<string> >("treeNames"); |
31 |
|
else |
59 |
|
if (cfg.exists("brSizes")) |
60 |
|
brSizes_=cfg.getUntrackedParameter<vector<unsigned> >("brSizes"); |
61 |
|
else |
62 |
< |
brSizes_.push_back(32*1024); |
62 |
> |
brSizes_.push_back(16*1024); |
63 |
|
|
64 |
|
if (treeNames_.size()!=fileNames_.size()) { |
65 |
|
throw edm::Exception(edm::errors::Configuration, "TreeService::TreeService()\n") |
68 |
|
return; |
69 |
|
} |
70 |
|
|
71 |
+ |
if (OptInt::IsActivated()) { |
72 |
+ |
if (cfg.exists("zipMode")) |
73 |
+ |
zipMode_=cfg.getUntrackedParameter<unsigned>("zipMode"); |
74 |
+ |
else |
75 |
+ |
zipMode_ = 99; |
76 |
+ |
|
77 |
+ |
if (cfg.exists("bZipThres")) |
78 |
+ |
bZipThres_=cfg.getUntrackedParameter<double>("bZipThres"); |
79 |
+ |
else |
80 |
+ |
bZipThres_ = -1.0; |
81 |
+ |
|
82 |
+ |
if (cfg.exists("gZipThres")) |
83 |
+ |
gZipThres_=cfg.getUntrackedParameter<double>("gZipThres"); |
84 |
+ |
else |
85 |
+ |
gZipThres_ = 1.0; |
86 |
+ |
|
87 |
+ |
if (cfg.exists("lzoThres")) |
88 |
+ |
lzoThres_=cfg.getUntrackedParameter<double>("lzoThres"); |
89 |
+ |
else |
90 |
+ |
lzoThres_ = -1.0; |
91 |
+ |
|
92 |
+ |
if (cfg.exists("lzmaThres")) |
93 |
+ |
lzmaThres_=cfg.getUntrackedParameter<double>("lzmaThres"); |
94 |
+ |
else |
95 |
+ |
lzmaThres_ = 0.95; |
96 |
+ |
|
97 |
+ |
if (cfg.exists("optIOVerbose")) |
98 |
+ |
optIOVerbose_=cfg.getUntrackedParameter<unsigned>("optIOVerbose"); |
99 |
+ |
else |
100 |
+ |
optIOVerbose_ = 0; |
101 |
+ |
|
102 |
+ |
OptInt::SetZipMode(zipMode_); |
103 |
+ |
OptInt::SetGzipFraction(gZipThres_); |
104 |
+ |
OptInt::SetBzipFraction(bZipThres_); |
105 |
+ |
OptInt::SetLzoFraction(lzoThres_); |
106 |
+ |
OptInt::SetLzmaFraction(lzmaThres_); |
107 |
+ |
OptInt::SetVerbose(optIOVerbose_); |
108 |
+ |
|
109 |
+ |
} else { |
110 |
+ |
|
111 |
+ |
if (cfg.exists("zipMode") || cfg.exists("bZipThres") || |
112 |
+ |
cfg.exists("gZipThres") || cfg.exists("lzoThres") || |
113 |
+ |
cfg.exists("lzmaThres")) { |
114 |
+ |
edm::LogError("TreeService") << "OptIO interface not properly pre-loaded, " |
115 |
+ |
"ignoring given settings." << std::endl; |
116 |
+ |
} |
117 |
+ |
} |
118 |
+ |
|
119 |
|
// setup tw array |
120 |
|
tws_.SetOwner(kTRUE); |
121 |
|
tws_.Expand(treeNames_.size()); |
123 |
|
// init tree writers |
124 |
|
for (unsigned int i=0; i<treeNames_.size(); ++i) { |
125 |
|
|
126 |
< |
TreeWriter *t = new TreeWriter(treeNames_.at(i).c_str(),1); |
70 |
< |
|
126 |
> |
TreeWriter *t = new TreeWriter(treeNames_.at(i).c_str(),0); |
127 |
|
t->SetPrefix(fileNames_.at(i).c_str()); |
128 |
|
|
129 |
< |
if (i<pathNames_.size()) |
129 |
> |
if (i<pathNames_.size()) |
130 |
|
t->SetBaseURL(pathNames_.at(i).c_str()); |
131 |
|
else if (pathNames_.size()>0) |
132 |
|
t->SetBaseURL(pathNames_.at(0).c_str()); |
133 |
|
|
134 |
< |
if (i<maxSizes_.size()) |
134 |
> |
if (i<maxSizes_.size()) |
135 |
|
t->SetMaxSize((Long64_t)maxSizes_.at(i)*1024*1024); |
136 |
|
else if (maxSizes_.size()>0) |
137 |
|
t->SetMaxSize((Long64_t)maxSizes_.at(0)*1024*1024); |
138 |
|
|
139 |
< |
if (i<compLevels_.size()) |
139 |
> |
if (i<compLevels_.size()) |
140 |
|
t->SetCompressLevel(compLevels_.at(i)); |
141 |
|
else if (compLevels_.size()>0) |
142 |
|
t->SetCompressLevel(compLevels_.at(0)); |
143 |
|
|
144 |
< |
if (i<splitLevels_.size()) |
144 |
> |
if (i<splitLevels_.size()) |
145 |
|
t->SetDefaultSL(splitLevels_.at(i)); |
146 |
|
else if (splitLevels_.size()>0) |
147 |
|
t->SetDefaultSL(splitLevels_.at(0)); |
148 |
|
|
149 |
< |
if (i<brSizes_.size()) |
149 |
> |
if (i<brSizes_.size()) |
150 |
|
t->SetDefaultBrSize(brSizes_.at(i)); |
151 |
|
else if (brSizes_.size()>0) |
152 |
|
t->SetDefaultBrSize(brSizes_.at(0)); |
156 |
|
} |
157 |
|
|
158 |
|
// set watchers |
159 |
< |
r.watchPreProcessEvent (this,&TreeService::preEventProcessing); |
160 |
< |
r.watchPostProcessEvent(this,&TreeService::postEventProcessing); |
161 |
< |
r.watchPostBeginJob (this,&TreeService::postBeginJob); |
162 |
< |
r.watchPostEndJob (this,&TreeService::postEndJob); |
159 |
> |
// ar.watchPreProcessEvent (this,&TreeService::preEventProcessing); |
160 |
> |
// ar.watchPostProcessEvent(this,&TreeService::postEventProcessing); |
161 |
> |
// ar.watchPostBeginJob (this,&TreeService::postBeginJob); |
162 |
> |
// ar.watchPostEndJob (this,&TreeService::postEndJob); |
163 |
|
} |
164 |
|
|
165 |
|
//-------------------------------------------------------------------------------------------------- |
166 |
|
TreeService::~TreeService() |
167 |
|
{ |
168 |
+ |
// Destructor. |
169 |
|
} |
170 |
|
|
171 |
|
//-------------------------------------------------------------------------------------------------- |
172 |
< |
TreeWriter* TreeService::get(const char *name) |
172 |
> |
TreeWriter *TreeService::get(const char *name) |
173 |
|
{ |
174 |
+ |
// Get TreeWriter by name. If no name given, first one will be returned. |
175 |
+ |
|
176 |
|
if (tws_.GetEntries()<=0) |
177 |
|
return 0; |
178 |
|
|
187 |
|
//-------------------------------------------------------------------------------------------------- |
188 |
|
void TreeService::postBeginJob() |
189 |
|
{ |
190 |
< |
// nothing to be done for now |
190 |
> |
// Nothing to be done for now |
191 |
|
} |
192 |
|
|
193 |
|
//-------------------------------------------------------------------------------------------------- |
194 |
|
void TreeService::postEndJob() |
195 |
|
{ |
196 |
+ |
// Clear all TreeWriter objects. |
197 |
+ |
|
198 |
|
tws_.Clear(); |
199 |
|
} |
200 |
|
|
201 |
|
//-------------------------------------------------------------------------------------------------- |
202 |
< |
void TreeService::postEventProcessing(const Event&, const EventSetup&) |
202 |
> |
void TreeService::postEventProcessing() |
203 |
|
{ |
204 |
+ |
// Loop over all TreeWriter objects before processing of an event. |
205 |
+ |
|
206 |
|
for (int i=0; i<tws_.GetEntries(); ++i) { |
207 |
|
TreeWriter *tw=dynamic_cast<TreeWriter*>(tws_.At(i)); |
208 |
< |
if (tw) |
209 |
< |
tw->EndEvent(); |
208 |
> |
if (tw) { |
209 |
> |
if (i<tws_.GetEntries()-1) |
210 |
> |
tw->EndEvent(); |
211 |
> |
else // make sure objects are only reset at the end (if at all) |
212 |
> |
tw->EndEvent(fDoReset_); |
213 |
> |
} |
214 |
|
} |
215 |
|
} |
216 |
|
|
217 |
|
//-------------------------------------------------------------------------------------------------- |
218 |
< |
void TreeService::preEventProcessing(const EventID&, const Timestamp&) |
218 |
> |
void TreeService::preEventProcessing() |
219 |
|
{ |
220 |
+ |
// Loop over all TreeWriter objects after processing of a events. |
221 |
+ |
|
222 |
|
for (int i=0; i<tws_.GetEntries(); ++i) { |
223 |
|
TreeWriter *tw=dynamic_cast<TreeWriter*>(tws_.At(i)); |
224 |
< |
if (tw) |
225 |
< |
tw->BeginEvent(); |
224 |
> |
if (tw) { |
225 |
> |
if (i==0) // make sure objects are only reset at the beginning (if at all) |
226 |
> |
tw->BeginEvent(fDoReset_); |
227 |
> |
else |
228 |
> |
tw->BeginEvent(); |
229 |
> |
} |
230 |
|
} |
231 |
|
} |