#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <vector>
#include <set>
#include <string>
#include <iostream>
#include <memory>
#include <thread>
#include <mutex>
#include <list>
#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 <TProfile.h>
#include <TKey.h>
#include <TClass.h>
#include <sys/prctl.h>
#include <sys/wait.h>
#include <csignal>
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 |
Typedefs | |
using | MEStore = std::set< MicroME > |
Enumerations | |
enum | ErrType { ERR_BADCFG =1, ERR_NOFILE } |
enum | TaskType { TASK_ADD, TASK_DUMP, TASK_CONVERT, TASK_ENCODE } |
Functions | |
int | addFile (MEStore µmes, int fd) |
int | addFiles (const std::string &output_filename, const std::vector< std::string > &filenames, int nthreads) |
void | addFilesWithFork (int parent_fd, const int fork_id, const int fork_total, 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 MEStore µmes) |
static void | get_info (const dqmstorepb::ROOTFilePB::Histo &h, std::string &dirname, std::string &objname, TObject **obj) |
int | main (int argc, char *argv[]) |
void | processDirectory (TFile *file, const std::string &curdir, MEStore µmes) |
static int | showusage () |
void | tryRootPreload () |
void | writeMessage (const dqmstorepb::ROOTFilePB &dqmstore_output_msg, const std::string &output_filename) |
void | writeMessageFD (const dqmstorepb::ROOTFilePB &dqmstore_output_msg, int out_fd) |
Variables | |
int | debug = 0 |
#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 109 of file fastHadd.cc.
Referenced by MicroME::add(), addFile(), addFiles(), addFilesWithFork(), convertFile(), dumpFiles(), encodeFile(), fillMessage(), processDirectory(), and writeMessage().
Definition at line 156 of file fastHadd.cc.
enum ErrType |
Enumerator | |
---|---|
ERR_BADCFG | |
ERR_NOFILE |
Definition at line 165 of file fastHadd.cc.
enum TaskType |
Enumerator | |
---|---|
TASK_ADD | |
TASK_DUMP | |
TASK_CONVERT | |
TASK_ENCODE |
Definition at line 158 of file fastHadd.cc.
int addFile | ( | MEStore & | micromes, |
int | fd | ||
) |
Definition at line 399 of file fastHadd.cc.
References MicroME::add(), gather_cfg::cout, DEBUG, ERR_NOFILE, groupFilesInBlocks::fin, dqmstorepb::ROOTFilePB_Histo::flags(), get_info(), dqmstorepb::ROOTFilePB::histo(), dqmstorepb::ROOTFilePB::histo_size(), mps_fire::i, input, MicroME::obj, MicroME::objname, callgraph::path, and AlCaHLTBitMon_QueryRunRegistry::string.
Referenced by addFilesWithFork().
int addFiles | ( | const std::string & | output_filename, |
const std::vector< std::string > & | filenames, | ||
int | nthreads | ||
) |
Definition at line 536 of file fastHadd.cc.
References addFilesWithFork(), DEBUG, and tryRootPreload().
Referenced by main().
void addFilesWithFork | ( | int | parent_fd, |
const int | fork_id, | ||
const int | fork_total, | ||
const std::vector< std::string > & | filenames | ||
) |
Definition at line 469 of file fastHadd.cc.
References addFile(), class-composition::children, gather_cfg::cout, DEBUG, ERR_NOFILE, cmsRelvalreport::exit, FrontierConditions_GlobalTag_cff::file, fillMessage(), mps_fire::i, pipe::pipe(), mps_update::status, AlCaHLTBitMon_QueryRunRegistry::string, and writeMessageFD().
Referenced by addFiles().
int convertFile | ( | const std::string & | output_filename, |
const std::vector< std::string > & | filenames | ||
) |
Definition at line 306 of file fastHadd.cc.
References gather_cfg::cout, DEBUG, end, ERR_NOFILE, extractNextObject(), groupFilesInBlocks::fin, dqmstorepb::ROOTFilePB_Histo::full_pathname(), get_info(), dqmstorepb::ROOTFilePB::histo(), dqmstorepb::ROOTFilePB::histo_size(), mps_fire::i, input, MicroME::obj, MicroME::objname, convertSQLitetoXML_cfg::output, callgraph::path, dqmstorepb::ROOTFilePB_Histo::size(), dqmstorepb::ROOTFilePB_Histo::streamed_histo(), and AlCaHLTBitMon_QueryRunRegistry::string.
Referenced by main().
int dumpFiles | ( | const std::vector< std::string > & | filenames | ) |
Definition at line 364 of file fastHadd.cc.
References gather_cfg::cout, DEBUG, MillePedeFileConverter_cfg::e, ERR_NOFILE, extractNextObject(), groupFilesInBlocks::fin, dqmstorepb::ROOTFilePB_Histo::flags(), dqmstorepb::ROOTFilePB_Histo::full_pathname(), dqmstorepb::ROOTFilePB::histo(), dqmstorepb::ROOTFilePB::histo_size(), mps_fire::i, input, MicroME::obj, dqmstorepb::ROOTFilePB_Histo::size(), and dqmstorepb::ROOTFilePB_Histo::streamed_histo().
Referenced by main().
int encodeFile | ( | const std::string & | output_filename, |
const std::vector< std::string > & | filenames | ||
) |
Definition at line 291 of file fastHadd.cc.
References DEBUG, fillMessage(), input, processDirectory(), and writeMessage().
Referenced by main().
|
inline |
Extract the next serialised ROOT object from buf. Returns null if there are no more objects in the buffer, or a null pointer was serialised at this location.
Definition at line 181 of file fastHadd.cc.
Referenced by convertFile(), dumpFiles(), get_info(), DQMStore::mtEnabled(), and DQMNet::unpackQualityData().
void fillMessage | ( | dqmstorepb::ROOTFilePB & | dqmstore_output_msg, |
const MEStore & | micromes | ||
) |
Definition at line 239 of file fastHadd.cc.
References dqmstorepb::ROOTFilePB::add_histo(), edmScanValgrind::buffer, DEBUG, 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 addFilesWithFork(), and encodeFile().
|
static |
Definition at line 189 of file fastHadd.cc.
References MessageLogger_cfi::cerr, extractNextObject(), dqmstorepb::ROOTFilePB_Histo::full_pathname(), dqmstorepb::ROOTFilePB_Histo::size(), pickleFileParser::slash, and dqmstorepb::ROOTFilePB_Histo::streamed_histo().
Referenced by addFile(), convertFile(), external::HEPTopTaggerV2_fixed_R::fat_initial(), DQMStore::mtEnabled(), and tryRootPreload().
int main | ( | int | argc, |
char * | argv[] | ||
) |
Definition at line 569 of file fastHadd.cc.
References addFiles(), dir2webdir::argc, MessageLogger_cfi::cerr, convertFile(), debug, dumpFiles(), encodeFile(), cmsPerfCommons::filenames, mps_setup::jobs, showusage(), AlCaHLTBitMon_QueryRunRegistry::string, TASK_ADD, TASK_CONVERT, TASK_DUMP, and TASK_ENCODE.
void processDirectory | ( | TFile * | file, |
const std::string & | curdir, | ||
MEStore & | micromes | ||
) |
Definition at line 260 of file fastHadd.cc.
References DEBUG, crabWrapper::key, GetRecoTauVFromDQM_MC_cff::next, MicroME::obj, and AlCaHLTBitMon_QueryRunRegistry::string.
Referenced by encodeFile().
|
static |
Definition at line 556 of file fastHadd.cc.
References MessageLogger_cfi::cerr, ERR_BADCFG, and AlCaHLTBitMon_QueryRunRegistry::string.
Referenced by main().
void tryRootPreload | ( | ) |
Definition at line 444 of file fastHadd.cc.
References dqmstorepb::ROOTFilePB::add_histo(), get_info(), dqmstorepb::ROOTFilePB::histo(), AnalysisDataFormats_SUSYBSMObjects::hr, MicroME::obj, MicroME::objname, callgraph::path, dqmstorepb::ROOTFilePB_Histo::set_flags(), dqmstorepb::ROOTFilePB_Histo::set_size(), dqmstorepb::ROOTFilePB_Histo::set_streamed_histo(), and AlCaHLTBitMon_QueryRunRegistry::string.
Referenced by addFiles().
void writeMessage | ( | const dqmstorepb::ROOTFilePB & | dqmstore_output_msg, |
const std::string & | output_filename | ||
) |
Definition at line 223 of file fastHadd.cc.
References DEBUG, and writeMessageFD().
Referenced by encodeFile().
void writeMessageFD | ( | const dqmstorepb::ROOTFilePB & | dqmstore_output_msg, |
int | out_fd | ||
) |
Definition at line 209 of file fastHadd.cc.
References AlcaSiPixelAliHarvester0T_cff::options.
Referenced by addFilesWithFork(), and writeMessage().
int debug = 0 |
Definition at line 111 of file fastHadd.cc.
Referenced by main().