CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ROOTSchema.cc
Go to the documentation of this file.
1 /*
2 
3 Author: Adam Hunt - Princeton University
4 Date: 2007-10-05
5 
6 This is the control layer of the root file writer. This is where all the error checking takes place.
7 The worker layer does not do any error checking. This is called by the user layer.
8 
9 */
10 
11 //
12 // constructor and destructor
13 //
14 
17 #include "RecoLuminosity/ROOTSchema/interface/HTMLGenerator.hh"
20 
21 #include "RecoLuminosity/TCPReceiver/interface/LumiStructures.hh"
22 
23 #include <iomanip>
24 
25 HCAL_HLX::ROOTSchema::ROOTSchema():RFMerger_(NULL), RFTransfer_(NULL),
26  LumiHTML_(NULL), RFWriter_(NULL),
27  previousRun_(0), firstSectionNumber_(0),
28  startTime_(0),
29  bMerge_(0), bWBM_(0), bTransfer_(0),
30  bEtSumOnly_(false),
31  fileType_("RAW"),
32  lsDir_(""),
33  mergeDir_(""),
34  dateDir_(""),
35  runDir_("")
36 {
37 
38  // Allocate memory for private members.
40  if( !RFWriter_ ){
41  //Could not allocate memory.
42  }
44  if( !RFMerger_ ){
45  //Could not allocate memory.
46  }
48  if( !RFTransfer_ ){
49  // Could not allocate memory.
50  }
51  LumiHTML_ = new HTMLGenerator;
52  if( !LumiHTML_ ){
53  // Could not allocate memory.
54  }
55 }
56 
58  // Deallocate memory for private members.
59 
60  EndRun();
61 
62  if( RFWriter_ ){
63  delete RFWriter_;
64  RFWriter_ = 0;
65  }
66 
67  if( RFMerger_ ){
68  delete RFMerger_;
69  RFMerger_ = 0;
70  }
71 
72  if( RFTransfer_ ){
73  delete RFTransfer_;
74  RFTransfer_ = 0;
75  }
76 
77  if( LumiHTML_ ){
78  delete LumiHTML_;
79  LumiHTML_ = 0;
80  }
81 }
82 
83 // *************************************** Configuration ************************************
84 
85 // ******** General ***********
86 
87 void HCAL_HLX::ROOTSchema::SetEtSumOnly(const bool bEtSumOnly){
88 
89  bEtSumOnly_ = bEtSumOnly;
90 }
91 
92 void HCAL_HLX::ROOTSchema::SetFileType( const std::string &fileType ){
93 
94  if( fileType_ != fileType ){
95  fileType_ = fileType;
96  if( (fileType_ != "RAW") && (fileType_ != "VDM") && (fileType_ != "ET") ){
97  fileType_ = "RAW"; // Default to RAW.
98  }
99 
100  if( fileType_ != "ET" && bEtSumOnly_ ){
101  bEtSumOnly_ = false;
102  }
103  if( fileType_ == "ET" && !bEtSumOnly_ ){
104  bEtSumOnly_ = true;
105  }
106 
107  RFWriter_->SetEtSumOnly( bEtSumOnly_ );
108  LumiHTML_->SetEtSumOnly( bEtSumOnly_ );
109  RFMerger_->SetEtSumOnly( bEtSumOnly_ );
110  RFTransfer_->SetEtSumOnly( bEtSumOnly_ );
111 
112  RFWriter_->SetFileType(fileType_);
113  LumiHTML_->SetFileType(fileType_);
114  RFMerger_->SetFileType(fileType_);
115  RFTransfer_->SetFileType(fileType_);
116 
117  }
118 
119 }
120 
121 // ******** LS Writer *********
122 
123 void HCAL_HLX::ROOTSchema::SetLSDir(const std::string &lsDir ){
124 
125  lsDir_ = lsDir;
126  if( lsDir_.substr( lsDir_.size() - 1) != "/" ){
127  lsDir_ += "/";
128  }
129 }
130 
131 // ******** Merger ************
132 
134 
135  bMerge_ = bMerge;
136  if( !bMerge_ ){
137  bTransfer_ = false;
138  }
139 }
140 
141 void HCAL_HLX::ROOTSchema::SetMergeDir(const std::string &mergeDir ){
142 
143  mergeDir_ = mergeDir;
144  if( mergeDir_.substr( mergeDir_.size() - 1) != "/" ){
145  mergeDir_ += "/";
146  }
147 }
148 
149 // ******** Transfer **********
150 
151 void HCAL_HLX::ROOTSchema::SetTransferFiles(const bool bTransfer){
152 
153  bTransfer_ = bTransfer;
154  if( bTransfer_ ){
155  bMerge_ = true;
156  }
157 }
158 
159 // ******** HTML **************
160 
162 
163  bWBM_ = bWBM;
164 }
165 
166 void HCAL_HLX::ROOTSchema::SetWebDir(const std::string &webDir){
167 
168  LumiHTML_->SetOutputDir( webDir );
169 }
170 
171 void HCAL_HLX::ROOTSchema::SetHistoBins(const int NBins, const double XMin, const double XMax){
172 
173  LumiHTML_->SetHistoBins( NBins, XMin, XMax );
174 }
175 
176 // *********************************** Handle Lumi section and end of run ************************
177 
179 
180  if( (previousRun_) != (lumiSection.hdr.runNumber) ){
181  EndRun();
182 
183  // Keep track of run information.
184  previousRun_ = lumiSection.hdr.runNumber;
185  firstSectionNumber_ = lumiSection.hdr.sectionNumber;
186  startTime_ = lumiSection.hdr.timestamp;
187 
188  RFWriter_->SetDate( TimeStampYYYYMMDD( startTime_ ));
189  RFMerger_->SetDate( TimeStampYYYYMMDD( startTime_ ));
190 
191  // Create directory structure for the new run.
192  std::stringstream runDirss;
193  runDirss.str(std::string(""));
194  dateDir_ = TimeStampYYYYMM( startTime_ ) + "/";
195  runDirss << std::setw(9) << std::setfill('0') << previousRun_ << "/";
196  runDir_ = runDirss.str();
197 
198  MakeDir( lsDir_ + dateDir_ + runDir_ , 0775);
199  RFWriter_->SetDir( lsDir_ + dateDir_ + runDir_ );
200 
201  RFMerger_->SetInputDir( lsDir_ + dateDir_ + runDir_ );
202  MakeDir( mergeDir_ + dateDir_ , 0775);
203  RFMerger_->SetOutputDir( mergeDir_ + dateDir_ );
204 
205  LumiHTML_->SetInputDir( lsDir_ + dateDir_ + runDir_ );
206  RFTransfer_->SetInputDir( mergeDir_ + dateDir_ );
207  }
208 
209  // Write individual lumi section files.
210  RFWriter_->OpenFile( lumiSection );
211  RFWriter_->FillTree( lumiSection );
212  RFWriter_->CloseFile();
213 
214  // Create a web page.
215  if( bWBM_ ){
216  LumiHTML_->CreateWebPage( RFWriter_->GetFileName(), 0 );
217  }
218  return true;
219 }
220 
222 
223  if( previousRun_ != 0 ){
224  if( bMerge_ ){
225  RFMerger_->Merge( previousRun_, firstSectionNumber_ );
226 
227  if( bTransfer_ ){
228  RFTransfer_->SetFileName( RFMerger_->GetOutputFileName());
229  RFTransfer_->TransferFile();
230  }
231  }
232  previousRun_ = 0;
233  }
234 }
void SetWebDir(const std::string &webDir)
Definition: ROOTSchema.cc:166
void SetHistoBins(const int NBins, const double XMin, const double XMax)
Definition: ROOTSchema.cc:171
void SetLSDir(const std::string &lsDir)
Definition: ROOTSchema.cc:123
void SetCreateWebPage(const bool bWBM)
Definition: ROOTSchema.cc:161
void SetFileType(const std::string &fileType)
Definition: ROOTSchema.cc:92
HCAL_HLX::ROOTFileMerger * RFMerger_
Definition: ROOTSchema.h:50
HCAL_HLX::ROOTFileTransfer * RFTransfer_
Definition: ROOTSchema.h:51
#define NULL
Definition: scimark2.h:8
HCAL_HLX::HTMLGenerator * LumiHTML_
Definition: ROOTSchema.h:52
void SetMergeFiles(const bool bMerge)
Definition: ROOTSchema.cc:133
HCAL_HLX::ROOTFileWriter * RFWriter_
Definition: ROOTSchema.h:53
bool ProcessSection(const HCAL_HLX::LUMI_SECTION &lumiSection)
Definition: ROOTSchema.cc:178
void SetTransferFiles(const bool bTransfer)
Definition: ROOTSchema.cc:151
void SetEtSumOnly(const bool bEtSumOnly)
Definition: ROOTSchema.cc:87
void SetMergeDir(const std::string &mergeDir)
Definition: ROOTSchema.cc:141