6 |
|
#include "FWCore/ServiceRegistry/interface/ActivityRegistry.h" |
7 |
|
#include "FWCore/ServiceRegistry/interface/Service.h" |
8 |
|
#include "FWCore/MessageLogger/interface/JobReport.h" |
9 |
< |
#include "MitAna/DataUtil/interface/TreeWriter.h" |
10 |
< |
#include "MitAna/DataTree/interface/Names.h" |
9 |
> |
#include "MitProd/ObjectService/interface/NamedObject.h" |
10 |
|
|
11 |
|
using namespace edm; |
12 |
|
using namespace std; |
14 |
|
|
15 |
|
//-------------------------------------------------------------------------------------------------- |
16 |
|
ObjectService::ObjectService(const ParameterSet &cfg, ActivityRegistry &ar) : |
17 |
< |
obs_(0) |
17 |
> |
obs_(0), |
18 |
> |
obsEvt_(0) |
19 |
|
{ |
20 |
|
// Constructor. |
21 |
|
|
22 |
< |
#if 0 |
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, "ObjectService::ObjectService()\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 |
66 |
< |
tws_.SetOwner(kTRUE); |
67 |
< |
tws_.Expand(treeNames_.size()); |
68 |
< |
|
69 |
< |
// init tree writers |
70 |
< |
for (unsigned int i=0; i<treeNames_.size(); ++i) { |
71 |
< |
|
72 |
< |
TreeWriter *t = new TreeWriter(treeNames_.at(i).c_str(),1); |
73 |
< |
t->SetPrefix(fileNames_.at(i).c_str()); |
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 |
< |
} |
22 |
> |
obs_.SetOwner(kTRUE); |
23 |
> |
obsEvt_.SetOwner(kTRUE); |
24 |
|
|
25 |
|
// set watchers |
26 |
|
ar.watchPreProcessEvent (this,&ObjectService::preEventProcessing); |
27 |
|
ar.watchPostProcessEvent(this,&ObjectService::postEventProcessing); |
28 |
|
ar.watchPostBeginJob (this,&ObjectService::postBeginJob); |
29 |
|
ar.watchPostEndJob (this,&ObjectService::postEndJob); |
109 |
– |
#endif |
30 |
|
} |
31 |
|
|
32 |
|
//-------------------------------------------------------------------------------------------------- |
35 |
|
// Destructor. |
36 |
|
} |
37 |
|
|
118 |
– |
#if 0 |
119 |
– |
//-------------------------------------------------------------------------------------------------- |
120 |
– |
TreeWriter* ObjectService::get(const char *name) |
121 |
– |
{ |
122 |
– |
// Get TreeWriter by name. If no name given, first one will be returned. |
123 |
– |
|
124 |
– |
if (tws_.GetEntries()<=0) |
125 |
– |
return 0; |
126 |
– |
|
127 |
– |
if (name==0) |
128 |
– |
return dynamic_cast<TreeWriter*>(tws_.At(0)); |
129 |
– |
|
130 |
– |
TObject *ret = tws_.FindObject(name); |
131 |
– |
|
132 |
– |
return dynamic_cast<TreeWriter*>(ret); |
133 |
– |
} |
134 |
– |
|
38 |
|
//-------------------------------------------------------------------------------------------------- |
39 |
|
void ObjectService::postBeginJob() |
40 |
|
{ |
44 |
|
//-------------------------------------------------------------------------------------------------- |
45 |
|
void ObjectService::postEndJob() |
46 |
|
{ |
47 |
< |
// Clear all TreeWriter objects. |
47 |
> |
// Clear all objects in the hashtables. |
48 |
|
|
49 |
< |
tws_.Clear(); |
49 |
> |
obs_.Delete(); |
50 |
> |
obsEvt_.Delete(); |
51 |
|
} |
52 |
|
|
53 |
|
//-------------------------------------------------------------------------------------------------- |
54 |
|
void ObjectService::postEventProcessing(const Event&, const EventSetup&) |
55 |
|
{ |
56 |
< |
// Loop over all TreeWriter objects before processing of an event. |
56 |
> |
// Remove objects put per event. |
57 |
|
|
58 |
< |
for (int i=0; i<tws_.GetEntries(); ++i) { |
155 |
< |
TreeWriter *tw=dynamic_cast<TreeWriter*>(tws_.At(i)); |
156 |
< |
if (tw) |
157 |
< |
tw->EndEvent(); |
158 |
< |
} |
58 |
> |
obsEvt_.Clear(); |
59 |
|
} |
60 |
|
|
61 |
|
//-------------------------------------------------------------------------------------------------- |
62 |
|
void ObjectService::preEventProcessing(const EventID&, const Timestamp&) |
63 |
|
{ |
164 |
– |
// Loop over all TreeWriter objects after processing of a events. |
165 |
– |
|
166 |
– |
for (int i=0; i<tws_.GetEntries(); ++i) { |
167 |
– |
TreeWriter *tw=dynamic_cast<TreeWriter*>(tws_.At(i)); |
168 |
– |
if (tw) |
169 |
– |
tw->BeginEvent(); |
170 |
– |
} |
64 |
|
} |
172 |
– |
#endif |