test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Classes | Macros | Enumerations | Functions | Variables
fastHadd.cc File Reference
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <vector>
#include <set>
#include <string>
#include <iostream>
#include <memory>
#include "DQMServices/Core/src/ROOTFilePB.pb.h"
#include <google/protobuf/io/coded_stream.h>
#include <google/protobuf/io/gzip_stream.h>
#include <google/protobuf/io/zero_copy_stream_impl.h>
#include <TROOT.h>
#include <TFile.h>
#include <TBufferFile.h>
#include <TObject.h>
#include <TObjString.h>
#include <TH1.h>
#include <TKey.h>

Go to the source code of this file.

Classes

struct  MicroME
 

Macros

#define DEBUG(x, msg)   if (debug >= x) std::cout << "DEBUG: " << msg << std::flush
 

Enumerations

enum  ErrType { ERR_BADCFG =1, ERR_NOFILE }
 
enum  TaskType { TASK_ADD, TASK_DUMP, TASK_CONVERT, TASK_ENCODE }
 

Functions

int addFiles (const std::string &output_filename, const std::vector< std::string > &filenames)
 
int convertFile (const std::string &output_filename, const std::vector< std::string > &filenames)
 
int dumpFiles (const std::vector< std::string > &filenames)
 
int encodeFile (const std::string &output_filename, const std::vector< std::string > &filenames)
 
TObject * extractNextObject (TBufferFile &buf)
 
void fillMessage (dqmstorepb::ROOTFilePB &dqmstore_output_msg, const std::set< MicroME > &micromes)
 
static void get_info (const dqmstorepb::ROOTFilePB::Histo &h, std::string &dirname, std::string &objname, TObject **obj)
 
static bool lessThanMME (const std::string &lhs_dirname, const std::string &lhs_objname, const std::string &rhs_dirname, const std::string &rhs_objname)
 
int main (int argc, char *argv[])
 
void processDirectory (TFile *file, const std::string &curdir, std::set< std::string > &dirs, std::set< std::string > &objs, std::set< std::string > &fullnames, std::set< MicroME > &micromes)
 
static int showusage (void)
 
void writeMessage (const dqmstorepb::ROOTFilePB &dqmstore_output_msg, const std::string &output_filename)
 

Variables

int debug = 0
 

Macro Definition Documentation

#define DEBUG (   x,
  msg 
)    if (debug >= x) std::cout << "DEBUG: " << msg << std::flush
Copyright (c) 2013 "Marco Rovere"

This code is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

This code is simple: its sole purpose is to either dump or add ProtocolBuffer-gzipped files that are meant to replace ordinary ROOT files containing only hierarchies of histograms, arranged in arbitrarily complex levels of directories. The merging logic is such that plots present in all files are added, while plots present in some of the files are anyway tracked and added, if similar ones are found in other files.

The logic of the merging algorithm is trivial and fully rely on the ordered nature of the ProtocolBuffer files read in input. An internal set container of MicroME is used to host the final results. The relational ordering of the set must be guaranteed to match the one used to order the ProtocolBuffer files for optimal performance and correctness.

A dependency on protocolbuffer is needed and should be alrady included out of the box into any recent CMSSW release.

In case the protoclBuffer package is not avaialble, you need to install it as an external toolfile. Therefore, in order to be able to compile and run the code, you need to locally install protocol buffer 2.4.1 and add it as a scram tool to your preferred CMSSW development area.

The toolfile I used is:

<tool name="protocolbuf" version="2.4.1"> <client> <environment name="PROTOCOLBUF_CLIENT_BASE" default="/afs/cern.ch/work/r/rovere/protocolbuf"> <environment name="LIBDIR" value="$PROTOCOLBUF_CLIENT_BASE/lib"> <environment name="INCLUDE" value="$PROTOCOLBUF_CLIENT_BASE/include"> <environment name="PATH" value="$PROTOCOLBUF_CLIENT_BASE/bin"> <lib name="protobuf"> <use name="zlib"> </client> <runtime name="PATH" value="$PROTOCOLBUF_CLIENT_BASE/bin"> </tool>

To register it into your development area you can simply do:

scram setup protocolbuf.xml

To verify the correctness of the information, do:

scram tool info protocolbuf. You should see an output similar to the following:

Tool info as configured in location /afs/cern.ch/work/r/rovere/fastHistoMergingPB/CMSSW_7_0_X_2013-07-08-0200 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Name : protocolbuf Version : 2.4.1 ++++++++++++++++++++ SCRAM_PROJECT=no PROTOCOLBUF_CLIENT_BASE=/afs/cern.ch/work/r/rovere/protocolbuf LIB=protobuf LIBDIR=/afs/cern.ch/work/r/rovere/protocolbuf/lib INCLUDE=/afs/cern.ch/work/r/rovere/protocolbuf/include USE=zlib PATH=/afs/cern.ch/work/r/rovere/protocolbuf/bin

Definition at line 100 of file fastHadd.cc.

Referenced by MicroME::add(), addFiles(), convertFile(), dumpFiles(), encodeFile(), fillMessage(), processDirectory(), and writeMessage().

Enumeration Type Documentation

enum ErrType
Enumerator
ERR_BADCFG 
ERR_NOFILE 

Definition at line 156 of file fastHadd.cc.

156  {
157  ERR_BADCFG=1,
158  ERR_NOFILE
159 };
enum TaskType
Enumerator
TASK_ADD 
TASK_DUMP 
TASK_CONVERT 
TASK_ENCODE 

Definition at line 149 of file fastHadd.cc.

149  {
150  TASK_ADD,
151  TASK_DUMP,
152  TASK_CONVERT,
154 };

Function Documentation

int addFiles ( const std::string &  output_filename,
const std::vector< std::string > &  filenames 
)

Definition at line 391 of file fastHadd.cc.

References gather_cfg::cout, DEBUG, diffTreeTool::diff, alignCSCRings::e, HTMLExport::elem(), ERR_NOFILE, fillMessage(), groupFilesInBlocks::fin, first, dqmstorepb::ROOTFilePB_Histo::flags(), dqmstorepb::ROOTFilePB_Histo::full_pathname(), MicroME::fullname, get_info(), h, dqmstorepb::ROOTFilePB::histo(), dqmstorepb::ROOTFilePB::histo_size(), i, input, lessThanMME(), cmsHarvester::loop, NULL, getGTfromDQMFile::obj, MicroME::obj, cmsHarvester::path, AlCaHLTBitMon_QueryRunRegistry::string, and writeMessage().

Referenced by main().

392  {
393  dqmstorepb::ROOTFilePB dqmstore_outputmessage;
394  std::set<std::string> dirs;
395  std::set<std::string> objs;
396  std::set<std::string> fullnames;
397  std::set<MicroME> micromes;
398 
399  assert(filenames.size() > 0);
400  DEBUG(1, "Adding file " << filenames[0] << std::endl);
401  {
402  dqmstorepb::ROOTFilePB dqmstore_message;
403  int filedescriptor;
404  if ((filedescriptor = open(filenames[0].c_str(), O_RDONLY)) == -1) {
405  std::cout << "Fatal Error opening file "
406  << filenames[0] << std::endl;
407  return ERR_NOFILE;
408  }
409 
410  FileInputStream fin(filedescriptor);
411  GzipInputStream input(&fin);
412  CodedInputStream input_coded(&input);
413  input_coded.SetTotalBytesLimit(1024*1024*1024, -1);
414  if (!dqmstore_message.ParseFromCodedStream(&input_coded)) {
415  std::cout << "Fatal Error opening file "
416  << filenames[0] << std::endl;
417  return ERR_NOFILE;
418  }
419  for (int i = 0; i < dqmstore_message.histo_size(); i++) {
421  std::string objname;
422  TObject *obj = NULL;
423  const dqmstorepb::ROOTFilePB::Histo &h = dqmstore_message.histo(i);
424  get_info(h, path, objname, &obj);
425  MicroME * mme = new MicroME(&*(fullnames.insert(h.full_pathname()).first),
426  &*(dirs.insert(path).first),
427  &*(objs.insert(objname).first),
428  h.flags());
429  if (obj) {
430  mme->obj = obj;
431  micromes.insert(*mme);
432  DEBUG(2, "Inserting MicroME " << *mme->fullname << std::endl);
433  }
434  }
435  }
436 
437  for (int i = 1, e = filenames.size(); i != e; ++i) {
438  DEBUG(1, "Adding file " << filenames[i] << std::endl);
439  dqmstorepb::ROOTFilePB dqmstore_msg;
440  int filedescriptor;
441  if ((filedescriptor = open(filenames[i].c_str(), O_RDONLY)) == -1) {
442  std::cout << "Fatal Error opening file "
443  << filenames[i] << std::endl;
444  return ERR_NOFILE;
445  }
446  FileInputStream fin(filedescriptor);
447  GzipInputStream input(&fin);
448  CodedInputStream input_coded(&input);
449  input_coded.SetTotalBytesLimit(1024*1024*1024, -1);
450  if (!dqmstore_msg.ParseFromCodedStream(&input_coded)) {
451  std::cout << "Fatal Error opening file "
452  << filenames[0] << std::endl;
453  return ERR_NOFILE;
454  }
455 
456  std::set<MicroME>::iterator mi = micromes.begin();
457  std::set<MicroME>::iterator me = micromes.end();
458  int elem = 0;
459  for (; mi != me; ++mi) {
461  std::string objname;
463  TObject *obj = NULL;
464  if (elem < dqmstore_msg.histo_size()) {
466  const_cast<dqmstorepb::ROOTFilePB::Histo &>(dqmstore_msg.histo(elem));
467  get_info(h, path, objname, &obj);
468 
469  DEBUG(2, "Comparing " << *(*mi).dirname << "/"
470  << *(*mi).objname << " vs "
471  << h.full_pathname() << std::endl);
472  int diff = (*mi).fullname->compare(h.full_pathname());
473  if (diff == 0 && obj != NULL) {
474  mi->add(obj);
475  delete obj;
476  ++elem;
477  } else if (! lessThanMME(*(*mi).dirname, *(*mi).objname,
478  path, objname)) {
479  // loop over elem till they are no longer less than iterator.
480  bool loop = true;
481  while (loop) {
482  DEBUG(2, "Adding Missing histogram "
483  << h.full_pathname() << std::endl);
484  // That's fine since we add elements to the left of the
485  // current node, so we do not screw up the iteration
486  // process.
487  MicroME * mme = new MicroME(&*(fullnames.insert(h.full_pathname()).first),
488  &*(dirs.insert(path).first),
489  &*(objs.insert(objname).first));
490  if (obj) {
491  mme->obj = obj;
492  micromes.insert(*mme);
493  ++elem;
494  }
495  if (elem < dqmstore_msg.histo_size()) {
496  h = const_cast<dqmstorepb::ROOTFilePB::Histo &>(dqmstore_msg.histo(elem));
497  get_info(h, path, objname, &obj);
498  DEBUG(2, "Comparing " << *(*mi).dirname << "/"
499  << *(*mi).objname << " vs "
500  << h.full_pathname() << std::endl);
501  loop = ! lessThanMME(*(*mi).dirname, *(*mi).objname,
502  path, objname);
503  } else {
504  loop = false;
505  }
506  }
507  }
508  }
509  }
510 
511  // Transfer whatever else is left pending in the new file.
512  while (elem < dqmstore_msg.histo_size()) {
514  std::string objname;
515  TObject *obj = NULL;
516 
517  const dqmstorepb::ROOTFilePB::Histo &h = dqmstore_msg.histo(elem);
518  get_info(h, path, objname, &obj);
519  DEBUG(2, "Adding Missing histogram " << h.full_pathname() << std::endl);
520  MicroME * mme = new MicroME(&*(fullnames.insert(h.full_pathname()).first),
521  &*(dirs.insert(path).first),
522  &*(objs.insert(objname).first));
523  if (obj) {
524  mme->obj = obj;
525  micromes.insert(*mme);
526  ++elem;
527  }
528  }
529  }
530 
531  dqmstorepb::ROOTFilePB dqmstore_output_msg;
532  fillMessage(dqmstore_output_msg, micromes);
533  writeMessage(dqmstore_output_msg, output_filename);
534 
535  return 0;
536 }
int i
Definition: DBlmapReader.cc:9
const ::std::string & full_pathname() const
static void get_info(const dqmstorepb::ROOTFilePB::Histo &h, std::string &dirname, std::string &objname, TObject **obj)
Definition: fastHadd.cc:178
void fillMessage(dqmstorepb::ROOTFilePB &dqmstore_output_msg, const std::set< MicroME > &micromes)
Definition: fastHadd.cc:220
TObject * obj
Definition: fastHadd.cc:122
#define NULL
Definition: scimark2.h:8
int loop
CMSSW
static std::string const input
Definition: EdmProvDump.cc:44
tuple path
else: Piece not in the list, fine.
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
bool first
Definition: L1TdeRCT.cc:75
const std::string * fullname
Definition: fastHadd.cc:119
const ::dqmstorepb::ROOTFilePB_Histo & histo(int index) const
void writeMessage(const dqmstorepb::ROOTFilePB &dqmstore_output_msg, const std::string &output_filename)
Definition: fastHadd.cc:198
inline::google::protobuf::uint32 flags() const
tuple cout
Definition: gather_cfg.py:121
#define DEBUG(x, msg)
Definition: fastHadd.cc:100
static bool lessThanMME(const std::string &lhs_dirname, const std::string &lhs_objname, const std::string &rhs_dirname, const std::string &rhs_objname)
Definition: fastHadd.cc:104
int convertFile ( const std::string &  output_filename,
const std::vector< std::string > &  filenames 
)

Definition at line 299 of file fastHadd.cc.

References gather_cfg::cout, DEBUG, end, ERR_NOFILE, extractNextObject(), groupFilesInBlocks::fin, dqmstorepb::ROOTFilePB_Histo::full_pathname(), get_info(), h, dqmstorepb::ROOTFilePB::histo(), dqmstorepb::ROOTFilePB::histo_size(), i, input, getGTfromDQMFile::obj, convertSQLitetoXML_cfg::output, cmsHarvester::path, dqmstorepb::ROOTFilePB_Histo::size(), dqm_diff::start, dqmstorepb::ROOTFilePB_Histo::streamed_histo(), and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by main().

300  {
301  assert(filenames.size() == 1);
302  TFile output(output_filename.c_str(), "RECREATE");
303  DEBUG(0, "Converting file " << filenames[0] << std::endl);
304  dqmstorepb::ROOTFilePB dqmstore_message;
305 
306  int filedescriptor = open(filenames[0].c_str(), O_RDONLY);
307  FileInputStream fin(filedescriptor);
308  GzipInputStream input(&fin);
309  CodedInputStream input_coded(&input);
310  input_coded.SetTotalBytesLimit(1024*1024*1024, -1);
311  if (!dqmstore_message.ParseFromCodedStream(&input_coded)) {
312  std::cout << "Fatal Error opening file "
313  << filenames[0] << std::endl;
314  return ERR_NOFILE;
315  }
316 
317  for (int i = 0; i < dqmstore_message.histo_size(); i++) {
318  const dqmstorepb::ROOTFilePB::Histo& h = dqmstore_message.histo(i);
319  DEBUG(1, h.full_pathname() << std::endl);
320  DEBUG(1, h.size() << std::endl);
321  TBufferFile buf(TBufferFile::kRead, h.size(),
322  (void*)h.streamed_histo().data(),
323  kFALSE);
324  buf.Reset();
325  TObject *obj = extractNextObject(buf);
326  std::string path,objname;
327  get_info(h, path, objname, &obj);
328  gDirectory->cd("/");
329  // Find the first path component.
330  size_t start = 0;
331  size_t end = path.find('/', start);
332  if (end == std::string::npos)
333  end = path.size();
334  while (true)
335  {
336  std::string part(path, start, end-start);
337  if (! gDirectory->Get(part.c_str()))
338  gDirectory->mkdir(part.c_str());
339  gDirectory->cd(part.c_str());
340  // Stop if we reached the end, ignoring any trailing '/'.
341  if (end+1 >= path.size())
342  break;
343  // Find the next path component.
344  start = end+1;
345  end = path.find('/', start);
346  if (end == std::string::npos)
347  end = path.size();
348  }
349  obj->Write();
350  DEBUG(1, obj->GetName() << std::endl);
351  }
352  output.Close();
353  google::protobuf::ShutdownProtobufLibrary();
354  return 0;
355 }
int i
Definition: DBlmapReader.cc:9
inline::google::protobuf::uint32 size() const
tuple start
Check for commandline option errors.
Definition: dqm_diff.py:58
const ::std::string & full_pathname() const
static void get_info(const dqmstorepb::ROOTFilePB::Histo &h, std::string &dirname, std::string &objname, TObject **obj)
Definition: fastHadd.cc:178
TObject * extractNextObject(TBufferFile &buf)
Definition: fastHadd.cc:171
const ::std::string & streamed_histo() const
static std::string const input
Definition: EdmProvDump.cc:44
tuple path
else: Piece not in the list, fine.
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
#define end
Definition: vmac.h:37
const ::dqmstorepb::ROOTFilePB_Histo & histo(int index) const
part
Definition: HCALResponse.h:20
tuple cout
Definition: gather_cfg.py:121
#define DEBUG(x, msg)
Definition: fastHadd.cc:100
int dumpFiles ( const std::vector< std::string > &  filenames)

Definition at line 357 of file fastHadd.cc.

References gather_cfg::cout, DEBUG, alignCSCRings::e, ERR_NOFILE, extractNextObject(), groupFilesInBlocks::fin, dqmstorepb::ROOTFilePB_Histo::flags(), dqmstorepb::ROOTFilePB_Histo::full_pathname(), h, dqmstorepb::ROOTFilePB::histo(), dqmstorepb::ROOTFilePB::histo_size(), i, input, getGTfromDQMFile::obj, dqmstorepb::ROOTFilePB_Histo::size(), and dqmstorepb::ROOTFilePB_Histo::streamed_histo().

Referenced by main().

357  {
358  assert(filenames.size() > 0);
359  for (int i = 0, e = filenames.size(); i != e; ++i) {
360  DEBUG(0, "Dumping file " << filenames[i] << std::endl);
361  dqmstorepb::ROOTFilePB dqmstore_message;
362 
363  int filedescriptor = open(filenames[0].c_str(), O_RDONLY);
364  FileInputStream fin(filedescriptor);
365  GzipInputStream input(&fin);
366  CodedInputStream input_coded(&input);
367  input_coded.SetTotalBytesLimit(1024*1024*1024, -1);
368  if (!dqmstore_message.ParseFromCodedStream(&input_coded)) {
369  std::cout << "Fatal Error opening file "
370  << filenames[0] << std::endl;
371  return ERR_NOFILE;
372  }
373 
374  for (int i = 0; i < dqmstore_message.histo_size(); i++) {
375  const dqmstorepb::ROOTFilePB::Histo& h = dqmstore_message.histo(i);
376  DEBUG(1, h.full_pathname() << std::endl);
377  DEBUG(1, h.size() << std::endl);
378  TBufferFile buf(TBufferFile::kRead, h.size(),
379  (void*)h.streamed_histo().data(),
380  kFALSE);
381  buf.Reset();
382  TObject *obj = extractNextObject(buf);
383  DEBUG(1, obj->GetName() << std::endl);
384  DEBUG(1, "Flags: " << h.flags() << std::endl);
385  }
386  }
387  google::protobuf::ShutdownProtobufLibrary();
388  return 0;
389 }
int i
Definition: DBlmapReader.cc:9
inline::google::protobuf::uint32 size() const
const ::std::string & full_pathname() const
TObject * extractNextObject(TBufferFile &buf)
Definition: fastHadd.cc:171
const ::std::string & streamed_histo() const
static std::string const input
Definition: EdmProvDump.cc:44
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
const ::dqmstorepb::ROOTFilePB_Histo & histo(int index) const
inline::google::protobuf::uint32 flags() const
tuple cout
Definition: gather_cfg.py:121
#define DEBUG(x, msg)
Definition: fastHadd.cc:100
int encodeFile ( const std::string &  output_filename,
const std::vector< std::string > &  filenames 
)

Definition at line 281 of file fastHadd.cc.

References DEBUG, fillMessage(), input, processDirectory(), and writeMessage().

Referenced by main().

282  {
283  assert(filenames.size() == 1);
284  TFile input(filenames[0].c_str());
285  DEBUG(0, "Encoding file " << filenames[0] << std::endl);
286  std::set<std::string> dirs;
287  std::set<std::string> objs;
288  std::set<std::string> fullnames;
289  std::set<MicroME> micromes;
290  dqmstorepb::ROOTFilePB dqmstore_message;
291 
292  processDirectory(&input, "", dirs, objs, fullnames, micromes);
293  fillMessage(dqmstore_message, micromes);
294  writeMessage(dqmstore_message, output_filename);
295 
296  return 0;
297 }
void processDirectory(TFile *file, const std::string &curdir, std::set< std::string > &dirs, std::set< std::string > &objs, std::set< std::string > &fullnames, std::set< MicroME > &micromes)
Definition: fastHadd.cc:241
void fillMessage(dqmstorepb::ROOTFilePB &dqmstore_output_msg, const std::set< MicroME > &micromes)
Definition: fastHadd.cc:220
static std::string const input
Definition: EdmProvDump.cc:44
void writeMessage(const dqmstorepb::ROOTFilePB &dqmstore_output_msg, const std::string &output_filename)
Definition: fastHadd.cc:198
#define DEBUG(x, msg)
Definition: fastHadd.cc:100
TObject* extractNextObject ( TBufferFile &  buf)
inline
Extract the next serialised ROOT object from @a buf. Returns null

if there are no more objects in the buffer, or a null pointer was serialised at this location.

Definition at line 171 of file fastHadd.cc.

Referenced by convertFile(), dumpFiles(), and get_info().

171  {
172  if (buf.Length() == buf.BufferSize())
173  return 0;
174  buf.InitMap();
175  return reinterpret_cast<TObject *>(buf.ReadObjectAny(0));
176 }
void fillMessage ( dqmstorepb::ROOTFilePB dqmstore_output_msg,
const std::set< MicroME > &  micromes 
)

Definition at line 220 of file fastHadd.cc.

References dqmstorepb::ROOTFilePB::add_histo(), DEBUG, h, dqmstorepb::ROOTFilePB_Histo::set_flags(), dqmstorepb::ROOTFilePB_Histo::set_full_pathname(), dqmstorepb::ROOTFilePB_Histo::set_size(), and dqmstorepb::ROOTFilePB_Histo::set_streamed_histo().

Referenced by addFiles(), and encodeFile().

221  {
222  std::set<MicroME>::iterator mi = micromes.begin();
223  std::set<MicroME>::iterator me = micromes.end();
224 
225  DEBUG(1, "Streaming ROOT objects" << std::endl);
226  for (; mi != me; ++mi) {
227  dqmstorepb::ROOTFilePB::Histo* h = dqmstore_output_msg.add_histo();
228  DEBUG(2, "Streaming ROOT object " << *(mi->fullname) << "\n");
229  h->set_full_pathname(*(mi->fullname));
230  TBufferFile buffer(TBufferFile::kWrite);
231  buffer.WriteObject(mi->obj);
232  h->set_size(buffer.Length());
233  h->set_flags(mi->flags);
234  h->set_streamed_histo((const void*)buffer.Buffer(),
235  buffer.Length());
236  delete mi->obj;
237  }
238 }
void set_flags(::google::protobuf::uint32 value)
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
void set_size(::google::protobuf::uint32 value)
void set_full_pathname(const ::std::string &value)
inline::dqmstorepb::ROOTFilePB_Histo * add_histo()
#define DEBUG(x, msg)
Definition: fastHadd.cc:100
void set_streamed_histo(const ::std::string &value)
static void get_info ( const dqmstorepb::ROOTFilePB::Histo h,
std::string &  dirname,
std::string &  objname,
TObject **  obj 
)
static

Definition at line 178 of file fastHadd.cc.

References dtNoiseDBValidation_cfg::cerr, extractNextObject(), dqmstorepb::ROOTFilePB_Histo::full_pathname(), dqmstorepb::ROOTFilePB_Histo::size(), pickleFileParser::slash, and dqmstorepb::ROOTFilePB_Histo::streamed_histo().

Referenced by addFiles(), and convertFile().

181  {
182 
183  size_t slash = h.full_pathname().rfind('/');
184  size_t dirpos = (slash == std::string::npos ? 0 : slash);
185  size_t namepos = (slash == std::string::npos ? 0 : slash+1);
186  dirname.assign(h.full_pathname(), 0, dirpos);
187  objname.assign(h.full_pathname(), namepos, std::string::npos);
188  TBufferFile buf(TBufferFile::kRead, h.size(),
189  (void*)h.streamed_histo().data(),
190  kFALSE);
191  buf.Reset();
192  *obj = extractNextObject(buf);
193  if (!*obj) {
194  std::cerr << "Error reading element: " << h.full_pathname() << std::endl;
195  }
196 }
inline::google::protobuf::uint32 size() const
const ::std::string & full_pathname() const
TObject * extractNextObject(TBufferFile &buf)
Definition: fastHadd.cc:171
const ::std::string & streamed_histo() const
static bool lessThanMME ( const std::string &  lhs_dirname,
const std::string &  lhs_objname,
const std::string &  rhs_dirname,
const std::string &  rhs_objname 
)
static

Definition at line 104 of file fastHadd.cc.

References diffTreeTool::diff.

Referenced by addFiles(), and MicroME::operator<().

107  {
108  int diff = lhs_dirname.compare(rhs_dirname);
109  return (diff < 0 ? true
110  : diff == 0 ? lhs_objname < rhs_objname : false);
111 };
int main ( int  argc,
char *  argv[] 
)

Definition at line 552 of file fastHadd.cc.

References addFiles(), dir2webdir::argc, dtNoiseDBValidation_cfg::cerr, convertFile(), debug, dumpFiles(), encodeFile(), cmsPerfCommons::filenames, electronStore::output_file, run_regression::ret, showusage(), AlCaHLTBitMon_QueryRunRegistry::string, TASK_ADD, TASK_CONVERT, TASK_DUMP, and TASK_ENCODE.

552  {
553  int arg;
554  int ret = 0;
556  std::vector<std::string> filenames;
557  TaskType task;
558 
559  filenames.reserve(argc);
560 
561  for (arg = 1; arg < argc; ++arg) {
562  if (! strcmp(argv[arg], "--no-debug"))
563  debug = 0;
564  else if (! strcmp(argv[arg], "--debug")
565  || ! strcmp(argv[arg], "-d"))
566  debug++;
567  else
568  break;
569  }
570 
571  if (arg < argc) {
572  if (! strcmp(argv[arg], "add")) {
573  ++arg;
574  task = TASK_ADD;
575  } else if (! strcmp(argv[arg], "dump")) {
576  ++arg;
577  task = TASK_DUMP;
578  } else if (! strcmp(argv[arg], "convert")) {
579  ++arg;
580  task = TASK_CONVERT;
581  } else if (! strcmp(argv[arg], "encode")) {
582  ++arg;
583  task = TASK_ENCODE;
584  } else {
585  std::cerr << "Unknown action: " << argv[arg] << std::endl;
586  return showusage();
587  }
588  } else {
589  std::cerr << "Not enough arguments\n";
590  return showusage();
591  }
592 
593  if (task == TASK_ADD || task == TASK_CONVERT || task == TASK_ENCODE) {
594  if (arg == argc) {
595  std::cerr << "add|convert|encode actions requires a -o option to be set\n";
596  return showusage();
597  }
598  if (! strcmp(argv[arg], "-o")) {
599  if (arg < argc-1) {
600  output_file = argv[++arg];
601  } else {
602  std::cerr << " -o option requires a value\n";
603  return showusage();
604  }
605  }
606  } else if (task == TASK_DUMP) {
607  if (arg == argc) {
608  std::cerr << "Missing input file(s)\n";
609  return showusage();
610  }
611  for (; arg < argc; ++arg) {
612  filenames.push_back(argv[arg]);
613  }
614  }
615 
616  if (task == TASK_ADD || task == TASK_CONVERT || task == TASK_ENCODE) {
617  if (++arg == argc) {
618  std::cerr << "Missing input file(s)\n";
619  return showusage();
620  }
621  for (; arg < argc; ++arg) {
622  filenames.push_back(argv[arg]);
623  }
624  }
625 
626  if (task == TASK_ADD)
627  ret = addFiles(output_file, filenames);
628  else if (task == TASK_DUMP)
629  ret = dumpFiles(filenames);
630  else if (task == TASK_CONVERT)
631  ret = convertFile(output_file, filenames);
632  else if (task == TASK_ENCODE)
633  ret = encodeFile(output_file, filenames);
634 
635  return ret;
636 }
int addFiles(const std::string &output_filename, const std::vector< std::string > &filenames)
Definition: fastHadd.cc:391
A arg
Definition: Factorize.h:36
TaskType
Definition: fastHadd.cc:149
int encodeFile(const std::string &output_filename, const std::vector< std::string > &filenames)
Definition: fastHadd.cc:281
string output_file
#define debug
Definition: HDRShower.cc:19
tuple argc
Definition: dir2webdir.py:38
int convertFile(const std::string &output_filename, const std::vector< std::string > &filenames)
Definition: fastHadd.cc:299
static int showusage(void)
Definition: fastHadd.cc:539
int dumpFiles(const std::vector< std::string > &filenames)
Definition: fastHadd.cc:357
void processDirectory ( TFile *  file,
const std::string &  curdir,
std::set< std::string > &  dirs,
std::set< std::string > &  objs,
std::set< std::string > &  fullnames,
std::set< MicroME > &  micromes 
)

Definition at line 241 of file fastHadd.cc.

References DEBUG, first, combine::key, GetRecoTauVFromDQM_MC_cff::next, getGTfromDQMFile::obj, MicroME::obj, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by encodeFile().

246  {
247  DEBUG(1, "Processing directory " << curdir << "\n");
248  file->cd(curdir.c_str());
249  TKey *key;
250  TIter next (gDirectory->GetListOfKeys());
251  while ((key = (TKey *) next())) {
252  TObject * obj = key->ReadObj();
253  if (dynamic_cast<TDirectory *>(obj)) {
254  std::string subdir;
255  subdir.reserve(curdir.size() + strlen(obj->GetName()) + 2);
256  subdir += curdir;
257  if (! curdir.empty())
258  subdir += '/';
259  subdir += obj->GetName();
260  processDirectory(file, subdir, dirs, objs, fullnames, micromes);
261  } else if ((dynamic_cast<TH1 *>(obj)) || (dynamic_cast<TObjString *>(obj))) {
262  if (dynamic_cast<TH1 *>(obj)) {
263  dynamic_cast<TH1 *>(obj)->SetDirectory(0);
264  }
265 
266  DEBUG(2, curdir << "/" << obj->GetName() << "\n");
267  MicroME mme(&*(fullnames.insert(curdir
268  + '/'
269  + std::string(obj->GetName())).first),
270  &*(dirs.insert(curdir).first),
271  &*(objs.insert(obj->GetName()).first));
272  if (obj) {
273  mme.obj = obj;
274  micromes.insert(mme);
275  }
276  }
277  }
278 }
void processDirectory(TFile *file, const std::string &curdir, std::set< std::string > &dirs, std::set< std::string > &objs, std::set< std::string > &fullnames, std::set< MicroME > &micromes)
Definition: fastHadd.cc:241
TObject * obj
Definition: fastHadd.cc:122
bool first
Definition: L1TdeRCT.cc:75
list key
Definition: combine.py:13
#define DEBUG(x, msg)
Definition: fastHadd.cc:100
static int showusage ( void  )
static

Definition at line 539 of file fastHadd.cc.

References dtNoiseDBValidation_cfg::cerr, ERR_BADCFG, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by main().

540 {
541  static const std::string app_name("fasthadd");
542 
543  std::cerr << "Usage: " << app_name
544  << " [--[no-]debug] TASK OPTIONS\n\n "
545  << app_name << " [OPTIONS] add -o OUTPUT_FILE [DAT FILE...]\n "
546  << app_name << " [OPTIONS] convert -o ROOT_FILE DAT_FILE\n "
547  << app_name << " [OPTIONS] encode -o DAT_FILE ROOT_FILE\n "
548  << app_name << " [OPTIONS] dump [DAT FILE...]\n ";
549  return ERR_BADCFG;
550 }
void writeMessage ( const dqmstorepb::ROOTFilePB dqmstore_output_msg,
const std::string &  output_filename 
)

Definition at line 198 of file fastHadd.cc.

References DEBUG, and AlCaHLTBitMon_ParallelJobs::options.

Referenced by addFiles(), and encodeFile().

199  {
200 
201  DEBUG(1, "Writing file" << std::endl);
202 
203  int out_fd = ::open(output_filename.c_str(),
204  O_WRONLY | O_CREAT | O_TRUNC,
205  S_IRUSR | S_IWUSR |
206  S_IRGRP | S_IWGRP |
207  S_IROTH);
208  FileOutputStream out_stream(out_fd);
210  options.format = GzipOutputStream::GZIP;
211  options.compression_level = 2;
212  GzipOutputStream gzip_stream(&out_stream,
213  options);
214  dqmstore_output_msg.SerializeToZeroCopyStream(&gzip_stream);
215 
216  google::protobuf::ShutdownProtobufLibrary();
217 }
std::vector< boost::shared_ptr< fireworks::OptionNode > > Options
#define DEBUG(x, msg)
Definition: fastHadd.cc:100

Variable Documentation

int debug = 0

Definition at line 102 of file fastHadd.cc.