1 |
|
// $Id$ |
2 |
|
|
3 |
|
#include "MitProd/TreeService/interface/TreeService.h" |
4 |
– |
|
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" |
8 |
|
#include "FWCore/MessageLogger/interface/JobReport.h" |
10 |
– |
|
9 |
|
#include "MitAna/DataUtil/interface/TreeWriter.h" |
10 |
+ |
#include "MitAna/DataTree/interface/Names.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), |
19 |
< |
treeNames_(cfg.getUntrackedParameter<std::vector<std::string> >("treeNames")), |
20 |
< |
fileNames_(cfg.getUntrackedParameter<std::vector<std::string> >("fileNames")), |
21 |
< |
pathNames_(cfg.getUntrackedParameter<std::vector<std::string> >("pathNames")), |
22 |
< |
maxSizes_(cfg.getUntrackedParameter<std::vector<unsigned> >("maxSizes")), |
23 |
< |
compLevels_(cfg.getUntrackedParameter<std::vector<unsigned> >("compLevels")), |
24 |
< |
splitLevels_(cfg.getUntrackedParameter<std::vector<unsigned> >("splitLevels")), |
25 |
< |
brSizes_(cfg.getUntrackedParameter<std::vector<unsigned> >("brSizes")) |
26 |
< |
{ |
27 |
< |
if(treeNames_.size()!=treeNames_.size()) { |
28 |
< |
//todo throw !!! |
16 |
> |
//-------------------------------------------------------------------------------------------------- |
17 |
> |
TreeService::TreeService(const ParameterSet &cfg, ActivityRegistry &ar) : |
18 |
> |
tws_(0), |
19 |
> |
fDoReset_(cfg.getUntrackedParameter<bool>("doReset",1)) |
20 |
> |
{ |
21 |
> |
// Constructor. |
22 |
> |
|
23 |
> |
if (cfg.exists("treeNames")) |
24 |
> |
treeNames_=cfg.getUntrackedParameter<vector<string> >("treeNames"); |
25 |
> |
else |
26 |
> |
treeNames_.push_back(Names::gkEvtTreeName); |
27 |
> |
|
28 |
> |
if (cfg.exists("fileNames")) |
29 |
> |
fileNames_=cfg.getUntrackedParameter<vector<string> >("fileNames"); |
30 |
> |
else |
31 |
> |
fileNames_.push_back("mit-test"); |
32 |
> |
|
33 |
> |
if (cfg.exists("pathNames")) |
34 |
> |
pathNames_=cfg.getUntrackedParameter<vector<string> >("pathNames"); |
35 |
> |
else |
36 |
> |
pathNames_.push_back("."); |
37 |
> |
|
38 |
> |
if (cfg.exists("maxSizes")) |
39 |
> |
maxSizes_=cfg.getUntrackedParameter<vector<unsigned> >("maxSizes"); |
40 |
> |
else |
41 |
> |
maxSizes_.push_back(1024); |
42 |
> |
|
43 |
> |
if (cfg.exists("compLevels")) |
44 |
> |
compLevels_=cfg.getUntrackedParameter<vector<unsigned> >("compLevels"); |
45 |
> |
else |
46 |
> |
compLevels_.push_back(9); |
47 |
> |
|
48 |
> |
if (cfg.exists("splitLevels")) |
49 |
> |
splitLevels_=cfg.getUntrackedParameter<vector<unsigned> >("splitLevels"); |
50 |
> |
else |
51 |
> |
splitLevels_.push_back(99); |
52 |
> |
|
53 |
> |
if (cfg.exists("brSizes")) |
54 |
> |
brSizes_=cfg.getUntrackedParameter<vector<unsigned> >("brSizes"); |
55 |
> |
else |
56 |
> |
brSizes_.push_back(32*1024); |
57 |
> |
|
58 |
> |
if (treeNames_.size()!=fileNames_.size()) { |
59 |
> |
throw edm::Exception(edm::errors::Configuration, "TreeService::TreeService()\n") |
60 |
> |
<< "Number of main trees should match number of files " << treeNames_.size() |
61 |
> |
<< " " << fileNames_.size() << "\n"; |
62 |
> |
return; |
63 |
|
} |
64 |
|
|
65 |
|
// setup tw array |
67 |
|
tws_.Expand(treeNames_.size()); |
68 |
|
|
69 |
|
// init tree writers |
70 |
< |
for(unsigned int i=0;i<treeNames_.size();++i) { |
38 |
< |
|
39 |
< |
TreeWriter *t = new TreeWriter(treeNames_.at(i).c_str(),1); |
70 |
> |
for (unsigned int i=0; i<treeNames_.size(); ++i) { |
71 |
|
|
72 |
+ |
TreeWriter *t = new TreeWriter(treeNames_.at(i).c_str(),0); |
73 |
|
t->SetPrefix(fileNames_.at(i).c_str()); |
74 |
< |
if(i<pathNames_.size()) t->SetBaseURL(pathNames_.at(i).c_str()); |
75 |
< |
else if (pathNames_.size()>0) t->SetBaseURL(pathNames_.at(0).c_str()); |
76 |
< |
if(i<maxSizes_.size()) t->SetMaxSize(maxSizes_.at(i)*1024*1024); |
77 |
< |
else if (maxSizes_.size()>0) t->SetMaxSize(maxSizes_.at(0)*1024*1024); |
78 |
< |
if(i<compLevels_.size()) t->SetCompressLevel(compLevels_.at(i)); |
79 |
< |
else if (compLevels_.size()>0) t->SetCompressLevel(compLevels_.at(0)); |
80 |
< |
if(i<splitLevels_.size()) t->SetDefaultSL(splitLevels_.at(i)); |
81 |
< |
else if (splitLevels_.size()>0) t->SetDefaultSL(splitLevels_.at(0)); |
82 |
< |
if(i<brSizes_.size()) t->SetDefaultBrSize(brSizes_.at(i)); |
83 |
< |
else if (brSizes_.size()>0) t->SetDefaultBrSize(brSizes_.at(0)); |
74 |
> |
|
75 |
> |
if (i<pathNames_.size()) |
76 |
> |
t->SetBaseURL(pathNames_.at(i).c_str()); |
77 |
> |
else if (pathNames_.size()>0) |
78 |
> |
t->SetBaseURL(pathNames_.at(0).c_str()); |
79 |
> |
|
80 |
> |
if (i<maxSizes_.size()) |
81 |
> |
t->SetMaxSize((Long64_t)maxSizes_.at(i)*1024*1024); |
82 |
> |
else if (maxSizes_.size()>0) |
83 |
> |
t->SetMaxSize((Long64_t)maxSizes_.at(0)*1024*1024); |
84 |
> |
|
85 |
> |
if (i<compLevels_.size()) |
86 |
> |
t->SetCompressLevel(compLevels_.at(i)); |
87 |
> |
else if (compLevels_.size()>0) |
88 |
> |
t->SetCompressLevel(compLevels_.at(0)); |
89 |
> |
|
90 |
> |
if (i<splitLevels_.size()) |
91 |
> |
t->SetDefaultSL(splitLevels_.at(i)); |
92 |
> |
else if (splitLevels_.size()>0) |
93 |
> |
t->SetDefaultSL(splitLevels_.at(0)); |
94 |
> |
|
95 |
> |
if (i<brSizes_.size()) |
96 |
> |
t->SetDefaultBrSize(brSizes_.at(i)); |
97 |
> |
else if (brSizes_.size()>0) |
98 |
> |
t->SetDefaultBrSize(brSizes_.at(0)); |
99 |
|
|
100 |
|
//t->Print(); |
101 |
|
tws_.Add(t); |
102 |
|
} |
103 |
|
|
104 |
|
// set watchers |
105 |
< |
r.watchPreProcessEvent(this,&TreeService::preEventProcessing); |
106 |
< |
r.watchPostProcessEvent(this,&TreeService::postEventProcessing); |
107 |
< |
r.watchPostBeginJob(this,&TreeService::postBeginJob); |
108 |
< |
r.watchPostEndJob(this,&TreeService::postEndJob); |
105 |
> |
ar.watchPreProcessEvent (this,&TreeService::preEventProcessing); |
106 |
> |
ar.watchPostProcessEvent(this,&TreeService::postEventProcessing); |
107 |
> |
ar.watchPostBeginJob (this,&TreeService::postBeginJob); |
108 |
> |
ar.watchPostEndJob (this,&TreeService::postEndJob); |
109 |
|
} |
110 |
|
|
111 |
< |
//------------------------------------------------------------------------------------------------- |
111 |
> |
//-------------------------------------------------------------------------------------------------- |
112 |
|
TreeService::~TreeService() |
113 |
|
{ |
114 |
+ |
// Destructor. |
115 |
|
} |
116 |
|
|
117 |
< |
//------------------------------------------------------------------------------------------------- |
118 |
< |
TreeWriter* TreeService::get(const char *name) |
117 |
> |
//-------------------------------------------------------------------------------------------------- |
118 |
> |
TreeWriter *TreeService::get(const char *name) |
119 |
|
{ |
120 |
< |
if(tws_.GetEntries()<=0) return 0; |
120 |
> |
// Get TreeWriter by name. If no name given, first one will be returned. |
121 |
|
|
122 |
< |
if(name==0) |
122 |
> |
if (tws_.GetEntries()<=0) |
123 |
> |
return 0; |
124 |
> |
|
125 |
> |
if (name==0) |
126 |
|
return dynamic_cast<TreeWriter*>(tws_.At(0)); |
127 |
|
|
128 |
|
TObject *ret = tws_.FindObject(name); |
129 |
+ |
|
130 |
|
return dynamic_cast<TreeWriter*>(ret); |
131 |
|
} |
132 |
|
|
133 |
< |
//------------------------------------------------------------------------------------------------- |
133 |
> |
//-------------------------------------------------------------------------------------------------- |
134 |
|
void TreeService::postBeginJob() |
135 |
|
{ |
136 |
< |
// nothing to be done for now |
136 |
> |
// Nothing to be done for now |
137 |
|
} |
138 |
|
|
139 |
< |
//------------------------------------------------------------------------------------------------- |
139 |
> |
//-------------------------------------------------------------------------------------------------- |
140 |
|
void TreeService::postEndJob() |
141 |
|
{ |
142 |
+ |
// Clear all TreeWriter objects. |
143 |
+ |
|
144 |
|
tws_.Clear(); |
145 |
|
} |
146 |
|
|
147 |
< |
//------------------------------------------------------------------------------------------------- |
147 |
> |
//-------------------------------------------------------------------------------------------------- |
148 |
|
void TreeService::postEventProcessing(const Event&, const EventSetup&) |
149 |
|
{ |
150 |
< |
for(int i=0;i<tws_.GetEntries();++i) { |
150 |
> |
// Loop over all TreeWriter objects before processing of an event. |
151 |
> |
|
152 |
> |
for (int i=0; i<tws_.GetEntries(); ++i) { |
153 |
|
TreeWriter *tw=dynamic_cast<TreeWriter*>(tws_.At(i)); |
154 |
< |
if(tw) |
155 |
< |
tw->EndEvent(); |
154 |
> |
if (tw) { |
155 |
> |
if (i<tws_.GetEntries()-1) |
156 |
> |
tw->EndEvent(); |
157 |
> |
else // make sure objects are only reset at the end (if at all) |
158 |
> |
tw->EndEvent(fDoReset_); |
159 |
> |
} |
160 |
|
} |
161 |
|
} |
162 |
|
|
163 |
< |
//------------------------------------------------------------------------------------------------- |
163 |
> |
//-------------------------------------------------------------------------------------------------- |
164 |
|
void TreeService::preEventProcessing(const EventID&, const Timestamp&) |
165 |
|
{ |
166 |
< |
for(int i=0;i<tws_.GetEntries();++i) { |
166 |
> |
// Loop over all TreeWriter objects after processing of a events. |
167 |
> |
|
168 |
> |
for (int i=0; i<tws_.GetEntries(); ++i) { |
169 |
|
TreeWriter *tw=dynamic_cast<TreeWriter*>(tws_.At(i)); |
170 |
< |
if(tw) |
171 |
< |
tw->BeginEvent(); |
170 |
> |
if (tw) { |
171 |
> |
if (i==0) // make sure objects are only reset at the beginning (if at all) |
172 |
> |
tw->BeginEvent(fDoReset_); |
173 |
> |
else |
174 |
> |
tw->BeginEvent(); |
175 |
> |
} |
176 |
|
} |
177 |
|
} |