1 |
// $Id:$
|
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<std::vector<std::string> >("treeNames")),
|
21 |
fileNames_(cfg.getUntrackedParameter<std::vector<std::string> >("fileNames")),
|
22 |
pathNames_(cfg.getUntrackedParameter<std::vector<std::string> >("pathNames")),
|
23 |
maxSizes_(cfg.getUntrackedParameter<std::vector<unsigned> >("maxSizes")),
|
24 |
compLevels_(cfg.getUntrackedParameter<std::vector<unsigned> >("compLevels")),
|
25 |
splitLevels_(cfg.getUntrackedParameter<std::vector<unsigned> >("splitLevels")),
|
26 |
brSizes_(cfg.getUntrackedParameter<std::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 |
if(i<pathNames_.size()) t->SetBaseURL(pathNames_.at(i).c_str());
|
43 |
else if (pathNames_.size()>0) t->SetBaseURL(pathNames_.at(0).c_str());
|
44 |
if(i<maxSizes_.size()) t->SetMaxSize(maxSizes_.at(i)*1024*1024);
|
45 |
else if (maxSizes_.size()>0) t->SetMaxSize(maxSizes_.at(0)*1024*1024);
|
46 |
if(i<compLevels_.size()) t->SetCompressLevel(compLevels_.at(i));
|
47 |
else if (compLevels_.size()>0) t->SetCompressLevel(compLevels_.at(0));
|
48 |
if(i<splitLevels_.size()) t->SetDefaultSL(splitLevels_.at(i));
|
49 |
else if (splitLevels_.size()>0) t->SetDefaultSL(splitLevels_.at(0));
|
50 |
if(i<brSizes_.size()) t->SetDefaultBrSize(brSizes_.at(i));
|
51 |
else if (brSizes_.size()>0) t->SetDefaultBrSize(brSizes_.at(0));
|
52 |
|
53 |
//t->Print();
|
54 |
tws_.Add(t);
|
55 |
}
|
56 |
|
57 |
// set watchers
|
58 |
r.watchPreProcessEvent(this,&TreeService::preEventProcessing);
|
59 |
r.watchPostProcessEvent(this,&TreeService::postEventProcessing);
|
60 |
r.watchPostBeginJob(this,&TreeService::postBeginJob);
|
61 |
r.watchPostEndJob(this,&TreeService::postEndJob);
|
62 |
}
|
63 |
|
64 |
//-------------------------------------------------------------------------------------------------
|
65 |
TreeService::~TreeService()
|
66 |
{
|
67 |
}
|
68 |
|
69 |
//-------------------------------------------------------------------------------------------------
|
70 |
TreeWriter* TreeService::get(const char *name)
|
71 |
{
|
72 |
if(tws_.GetEntries()<=0) return 0;
|
73 |
|
74 |
if(name==0)
|
75 |
return dynamic_cast<TreeWriter*>(tws_.At(0));
|
76 |
|
77 |
TObject *ret = tws_.FindObject(name);
|
78 |
return dynamic_cast<TreeWriter*>(ret);
|
79 |
}
|
80 |
|
81 |
//-------------------------------------------------------------------------------------------------
|
82 |
void TreeService::postBeginJob()
|
83 |
{
|
84 |
// nothing to be done for now
|
85 |
}
|
86 |
|
87 |
//-------------------------------------------------------------------------------------------------
|
88 |
void TreeService::postEndJob()
|
89 |
{
|
90 |
tws_.Clear();
|
91 |
}
|
92 |
|
93 |
//-------------------------------------------------------------------------------------------------
|
94 |
void TreeService::postEventProcessing(const Event&, const EventSetup&)
|
95 |
{
|
96 |
for(int i=0;i<tws_.GetEntries();++i) {
|
97 |
TreeWriter *tw=dynamic_cast<TreeWriter*>(tws_.At(i));
|
98 |
if(tw)
|
99 |
tw->EndEvent();
|
100 |
}
|
101 |
}
|
102 |
|
103 |
//-------------------------------------------------------------------------------------------------
|
104 |
void TreeService::preEventProcessing(const EventID&, const Timestamp&)
|
105 |
{
|
106 |
for(int i=0;i<tws_.GetEntries();++i) {
|
107 |
TreeWriter *tw=dynamic_cast<TreeWriter*>(tws_.At(i));
|
108 |
if(tw)
|
109 |
tw->BeginEvent();
|
110 |
}
|
111 |
}
|