1 |
// $Id: TreeService.cc,v 1.1 2008/05/27 20:09:09 loizides Exp $
|
2 |
|
3 |
#include "MitProd/TreeService/interface/TreeService.h"
|
4 |
|
5 |
#include "DataFormats/Provenance/interface/ModuleDescription.h"
|
6 |
#include "FWCore/ParameterSet/interface/ParameterSet.h"
|
7 |
#include "FWCore/ServiceRegistry/interface/ActivityRegistry.h"
|
8 |
#include "FWCore/ServiceRegistry/interface/Service.h"
|
9 |
#include "FWCore/MessageLogger/interface/JobReport.h"
|
10 |
|
11 |
#include "MitAna/DataUtil/interface/TreeWriter.h"
|
12 |
|
13 |
using namespace edm;
|
14 |
using namespace std;
|
15 |
using namespace mithep;
|
16 |
|
17 |
//--------------------------------------------------------------------------------------------------
|
18 |
TreeService::TreeService(const ParameterSet &cfg, ActivityRegistry &r)
|
19 |
: tws_(0),
|
20 |
treeNames_ (cfg.getUntrackedParameter<vector<string> >("treeNames")),
|
21 |
fileNames_ (cfg.getUntrackedParameter<vector<string> >("fileNames")),
|
22 |
pathNames_ (cfg.getUntrackedParameter<vector<string> >("pathNames")),
|
23 |
maxSizes_ (cfg.getUntrackedParameter<vector<unsigned> >("maxSizes")),
|
24 |
compLevels_ (cfg.getUntrackedParameter<vector<unsigned> >("compLevels")),
|
25 |
splitLevels_(cfg.getUntrackedParameter<vector<unsigned> >("splitLevels")),
|
26 |
brSizes_ (cfg.getUntrackedParameter<vector<unsigned> >("brSizes"))
|
27 |
{
|
28 |
if (treeNames_.size()!=treeNames_.size()) {
|
29 |
//todo throw !!!
|
30 |
}
|
31 |
|
32 |
// setup tw array
|
33 |
tws_.SetOwner(kTRUE);
|
34 |
tws_.Expand(treeNames_.size());
|
35 |
|
36 |
// init tree writers
|
37 |
for (unsigned int i=0; i<treeNames_.size(); ++i) {
|
38 |
|
39 |
TreeWriter *t = new TreeWriter(treeNames_.at(i).c_str(),1);
|
40 |
|
41 |
t->SetPrefix(fileNames_.at(i).c_str());
|
42 |
|
43 |
if (i<pathNames_.size())
|
44 |
t->SetBaseURL(pathNames_.at(i).c_str());
|
45 |
else if (pathNames_.size()>0)
|
46 |
t->SetBaseURL(pathNames_.at(0).c_str());
|
47 |
|
48 |
if (i<maxSizes_.size())
|
49 |
t->SetMaxSize(maxSizes_.at(i)*1024*1024);
|
50 |
else if (maxSizes_.size()>0)
|
51 |
t->SetMaxSize(maxSizes_.at(0)*1024*1024);
|
52 |
|
53 |
if (i<compLevels_.size())
|
54 |
t->SetCompressLevel(compLevels_.at(i));
|
55 |
else if (compLevels_.size()>0)
|
56 |
t->SetCompressLevel(compLevels_.at(0));
|
57 |
|
58 |
if (i<splitLevels_.size())
|
59 |
t->SetDefaultSL(splitLevels_.at(i));
|
60 |
else if (splitLevels_.size()>0)
|
61 |
t->SetDefaultSL(splitLevels_.at(0));
|
62 |
|
63 |
if (i<brSizes_.size())
|
64 |
t->SetDefaultBrSize(brSizes_.at(i));
|
65 |
else if (brSizes_.size()>0)
|
66 |
t->SetDefaultBrSize(brSizes_.at(0));
|
67 |
|
68 |
//t->Print();
|
69 |
tws_.Add(t);
|
70 |
}
|
71 |
|
72 |
// set watchers
|
73 |
r.watchPreProcessEvent (this,&TreeService::preEventProcessing);
|
74 |
r.watchPostProcessEvent(this,&TreeService::postEventProcessing);
|
75 |
r.watchPostBeginJob (this,&TreeService::postBeginJob);
|
76 |
r.watchPostEndJob (this,&TreeService::postEndJob);
|
77 |
}
|
78 |
|
79 |
//--------------------------------------------------------------------------------------------------
|
80 |
TreeService::~TreeService()
|
81 |
{
|
82 |
}
|
83 |
|
84 |
//--------------------------------------------------------------------------------------------------
|
85 |
TreeWriter* TreeService::get(const char *name)
|
86 |
{
|
87 |
if (tws_.GetEntries()<=0)
|
88 |
return 0;
|
89 |
|
90 |
if (name==0)
|
91 |
return dynamic_cast<TreeWriter*>(tws_.At(0));
|
92 |
|
93 |
TObject *ret = tws_.FindObject(name);
|
94 |
|
95 |
return dynamic_cast<TreeWriter*>(ret);
|
96 |
}
|
97 |
|
98 |
//--------------------------------------------------------------------------------------------------
|
99 |
void TreeService::postBeginJob()
|
100 |
{
|
101 |
// nothing to be done for now
|
102 |
}
|
103 |
|
104 |
//--------------------------------------------------------------------------------------------------
|
105 |
void TreeService::postEndJob()
|
106 |
{
|
107 |
tws_.Clear();
|
108 |
}
|
109 |
|
110 |
//--------------------------------------------------------------------------------------------------
|
111 |
void TreeService::postEventProcessing(const Event&, const EventSetup&)
|
112 |
{
|
113 |
for (int i=0; i<tws_.GetEntries(); ++i) {
|
114 |
TreeWriter *tw=dynamic_cast<TreeWriter*>(tws_.At(i));
|
115 |
if (tw)
|
116 |
tw->EndEvent();
|
117 |
}
|
118 |
}
|
119 |
|
120 |
//--------------------------------------------------------------------------------------------------
|
121 |
void TreeService::preEventProcessing(const EventID&, const Timestamp&)
|
122 |
{
|
123 |
for (int i=0; i<tws_.GetEntries(); ++i) {
|
124 |
TreeWriter *tw=dynamic_cast<TreeWriter*>(tws_.At(i));
|
125 |
if (tw)
|
126 |
tw->BeginEvent();
|
127 |
}
|
128 |
}
|