80 #include <sys/types.h>
89 #include <google/protobuf/io/coded_stream.h>
90 #include <google/protobuf/io/gzip_stream.h>
91 #include <google/protobuf/io/zero_copy_stream_impl.h>
94 #include <TBufferFile.h>
96 #include <TObjString.h>
100 #define DEBUG(x, msg) if (debug >= x) std::cout << "DEBUG: " << msg << std::flush
108 int diff = lhs_dirname.compare(rhs_dirname);
109 return (diff < 0 ?
true
110 : diff == 0 ? lhs_objname < rhs_objname :
false);
133 void add(TObject *obj_to_add)
const {
134 DEBUG(1,
"Merging: " <<
obj->GetName() <<
135 " << " << obj_to_add->GetName() << std::endl);
137 if (dynamic_cast<TH1 *>(
obj) &&
dynamic_cast<TH1 *
>(obj_to_add)) {
138 dynamic_cast<TH1 *
>(
obj)->Add(dynamic_cast<TH1 *>(obj_to_add));
139 }
else if (dynamic_cast<TObjString *>(
obj) &&
dynamic_cast<TObjString *
>(obj_to_add)) {
143 DEBUG(1,
"Cannot merge (different types): " <<
obj->GetName() <<
144 " << " << obj_to_add->GetName() << std::endl);
161 using google::protobuf::io::FileInputStream;
162 using google::protobuf::io::FileOutputStream;
163 using google::protobuf::io::GzipInputStream;
164 using google::protobuf::io::GzipOutputStream;
165 using google::protobuf::io::CodedInputStream;
166 using google::protobuf::io::ArrayInputStream;
172 if (buf.Length() == buf.BufferSize())
175 return reinterpret_cast<TObject *
>(buf.ReadObjectAny(0));
184 size_t dirpos = (slash == std::string::npos ? 0 :
slash);
185 size_t namepos = (slash == std::string::npos ? 0 : slash+1);
187 objname.assign(h.
full_pathname(), namepos, std::string::npos);
188 TBufferFile buf(TBufferFile::kRead, h.
size(),
201 DEBUG(1,
"Writing file" << std::endl);
203 int out_fd = ::open(output_filename.c_str(),
204 O_WRONLY | O_CREAT | O_TRUNC,
209 FileOutputStream out_stream(out_fd);
211 options.format = GzipOutputStream::GZIP;
212 options.compression_level = 2;
213 GzipOutputStream gzip_stream(&out_stream,
215 dqmstore_output_msg.SerializeToZeroCopyStream(&gzip_stream);
225 const std::set<MicroME> & micromes) {
226 std::set<MicroME>::iterator mi = micromes.begin();
227 std::set<MicroME>::iterator me = micromes.end();
229 DEBUG(1,
"Streaming ROOT objects" << std::endl);
230 for (; mi != me; ++mi) {
232 DEBUG(2,
"Streaming ROOT object " << *(mi->fullname) <<
"\n");
234 TBufferFile buffer(TBufferFile::kWrite);
235 buffer.WriteObject(mi->obj);
247 std::set<std::string> &dirs,
248 std::set<std::string> &objs,
249 std::set<std::string> &fullnames,
250 std::set<MicroME>& micromes) {
251 DEBUG(1,
"Processing directory " << curdir <<
"\n");
252 file->cd(curdir.c_str());
254 TIter
next (gDirectory->GetListOfKeys());
255 while ((key = (TKey *)
next())) {
256 TObject *
obj = key->ReadObj();
257 if (dynamic_cast<TDirectory *>(obj)) {
259 subdir.reserve(curdir.size() + strlen(obj->GetName()) + 2);
261 if (! curdir.empty())
263 subdir += obj->GetName();
265 }
else if ((dynamic_cast<TH1 *>(obj)) || (dynamic_cast<TObjString *>(obj))) {
266 if (dynamic_cast<TH1 *>(obj)) {
267 dynamic_cast<TH1 *
>(
obj)->SetDirectory(0);
270 DEBUG(2, curdir <<
"/" << obj->GetName() <<
"\n");
271 MicroME mme(&*(fullnames.insert(curdir
274 &*(dirs.insert(curdir).first),
275 &*(objs.insert(obj->GetName()).
first));
278 micromes.insert(mme);
286 const std::vector<std::string> &
filenames) {
287 assert(filenames.size() == 1);
288 TFile
input(filenames[0].c_str());
289 DEBUG(0,
"Encoding file " << filenames[0] << std::endl);
290 std::set<std::string> dirs;
291 std::set<std::string> objs;
292 std::set<std::string> fullnames;
293 std::set<MicroME> micromes;
304 const std::vector<std::string> &
filenames) {
305 assert(filenames.size() == 1);
306 TFile
output(output_filename.c_str(),
"RECREATE");
307 DEBUG(0,
"Converting file " << filenames[0] << std::endl);
310 int filedescriptor = ::open(filenames[0].c_str(), O_RDONLY);
311 FileInputStream
fin(filedescriptor);
312 GzipInputStream
input(&fin);
313 CodedInputStream input_coded(&input);
314 input_coded.SetTotalBytesLimit(1024*1024*1024, -1);
315 if (!dqmstore_message.ParseFromCodedStream(&input_coded)) {
317 << filenames[0] << std::endl;
320 ::close(filedescriptor);
326 TBufferFile buf(TBufferFile::kRead, h.
size(),
336 size_t end = path.find(
'/', start);
337 if (end == std::string::npos)
342 if (! gDirectory->Get(part.c_str()))
343 gDirectory->mkdir(part.c_str());
344 gDirectory->cd(part.c_str());
346 if (end+1 >= path.size())
350 end = path.find(
'/', start);
351 if (end == std::string::npos)
355 DEBUG(1, obj->GetName() << std::endl);
362 assert(filenames.size() > 0);
363 for (
int i = 0,
e = filenames.size();
i !=
e; ++
i) {
364 DEBUG(0,
"Dumping file " << filenames[
i] << std::endl);
367 int filedescriptor = ::open(filenames[0].c_str(), O_RDONLY);
368 FileInputStream
fin(filedescriptor);
369 GzipInputStream
input(&fin);
370 CodedInputStream input_coded(&input);
371 input_coded.SetTotalBytesLimit(1024*1024*1024, -1);
372 if (!dqmstore_message.ParseFromCodedStream(&input_coded)) {
374 << filenames[0] << std::endl;
377 ::close(filedescriptor);
383 TBufferFile buf(TBufferFile::kRead, h.
size(),
388 DEBUG(1, obj->GetName() << std::endl);
389 DEBUG(1,
"Flags: " << h.
flags() << std::endl);
397 const std::vector<std::string> &
filenames) {
399 std::set<std::string> dirs;
400 std::set<std::string> objs;
401 std::set<std::string> fullnames;
402 std::set<MicroME> micromes;
404 assert(filenames.size() > 0);
405 DEBUG(1,
"Adding file " << filenames[0] << std::endl);
409 if ((filedescriptor = ::open(filenames[0].c_str(), O_RDONLY)) == -1) {
411 << filenames[0] << std::endl;
415 FileInputStream
fin(filedescriptor);
416 GzipInputStream
input(&fin);
417 CodedInputStream input_coded(&input);
418 input_coded.SetTotalBytesLimit(1024*1024*1024, -1);
419 if (!dqmstore_message.ParseFromCodedStream(&input_coded)) {
421 << filenames[0] << std::endl;
424 ::close(filedescriptor);
433 &*(dirs.insert(path).first),
434 &*(objs.insert(objname).first),
438 micromes.insert(*mme);
439 DEBUG(2,
"Inserting MicroME " << *mme->
fullname << std::endl);
444 for (
int i = 1,
e = filenames.size();
i !=
e; ++
i) {
445 DEBUG(1,
"Adding file " << filenames[
i] << std::endl);
448 if ((filedescriptor = ::open(filenames[
i].c_str(), O_RDONLY)) == -1) {
450 << filenames[
i] << std::endl;
453 FileInputStream
fin(filedescriptor);
454 GzipInputStream
input(&fin);
455 CodedInputStream input_coded(&input);
456 input_coded.SetTotalBytesLimit(1024*1024*1024, -1);
457 if (!dqmstore_msg.ParseFromCodedStream(&input_coded)) {
459 << filenames[0] << std::endl;
462 ::close(filedescriptor);
464 std::set<MicroME>::iterator mi = micromes.begin();
465 std::set<MicroME>::iterator me = micromes.end();
467 for (; mi != me; ++mi) {
477 DEBUG(2,
"Comparing " << *(*mi).dirname <<
"/"
478 << *(*mi).objname <<
" vs "
481 if (diff == 0 && obj !=
NULL) {
485 }
else if (!
lessThanMME(*(*mi).dirname, *(*mi).objname,
490 DEBUG(2,
"Adding Missing histogram "
496 &*(dirs.insert(path).first),
497 &*(objs.insert(objname).first));
500 micromes.insert(*mme);
506 DEBUG(2,
"Comparing " << *(*mi).dirname <<
"/"
507 << *(*mi).objname <<
" vs "
509 loop = !
lessThanMME(*(*mi).dirname, *(*mi).objname,
529 &*(dirs.insert(path).first),
530 &*(objs.insert(objname).first));
533 micromes.insert(*mme);
552 <<
" [--[no-]debug] TASK OPTIONS\n\n "
553 << app_name <<
" [OPTIONS] add -o OUTPUT_FILE [DAT FILE...]\n "
554 << app_name <<
" [OPTIONS] convert -o ROOT_FILE DAT_FILE\n "
555 << app_name <<
" [OPTIONS] encode -o DAT_FILE ROOT_FILE\n "
556 << app_name <<
" [OPTIONS] dump [DAT FILE...]\n ";
567 filenames.reserve(argc);
569 for (arg = 1; arg <
argc; ++
arg) {
570 if (! strcmp(argv[arg],
"--no-debug"))
572 else if (! strcmp(argv[arg],
"--debug")
573 || ! strcmp(argv[arg],
"-d"))
580 if (! strcmp(argv[arg],
"add")) {
583 }
else if (! strcmp(argv[arg],
"dump")) {
586 }
else if (! strcmp(argv[arg],
"convert")) {
589 }
else if (! strcmp(argv[arg],
"encode")) {
593 std::cerr <<
"Unknown action: " << argv[
arg] << std::endl;
603 std::cerr <<
"add|convert|encode actions requires a -o option to be set\n";
606 if (! strcmp(argv[arg],
"-o")) {
608 output_file = argv[++
arg];
610 std::cerr <<
" -o option requires a value\n";
620 filenames.push_back(argv[arg]);
630 filenames.push_back(argv[arg]);
635 ret =
addFiles(output_file, filenames);
644 google::protobuf::ShutdownProtobufLibrary();
MicroME(const std::string *full, const std::string *dir, const std::string *obj, uint32_t flags=0)
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 > µmes)
inline::google::protobuf::uint32 size() const
tuple start
Check for commandline option errors.
const ::std::string & full_pathname() const
const std::string * objname
static void get_info(const dqmstorepb::ROOTFilePB::Histo &h, std::string &dirname, std::string &objname, TObject **obj)
TObject * extractNextObject(TBufferFile &buf)
void fillMessage(dqmstorepb::ROOTFilePB &dqmstore_output_msg, const std::set< MicroME > µmes)
bool operator<(const MicroME &rhs) const
int addFiles(const std::string &output_filename, const std::vector< std::string > &filenames)
const std::string * dirname
void add(TObject *obj_to_add) const
void set_flags(::google::protobuf::uint32 value)
const ::std::string & streamed_histo() const
static std::string const input
int main(int argc, char **argv)
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.
const std::string * fullname
int encodeFile(const std::string &output_filename, const std::vector< std::string > &filenames)
const ::dqmstorepb::ROOTFilePB_Histo & histo(int index) const
void set_size(::google::protobuf::uint32 value)
void writeMessage(const dqmstorepb::ROOTFilePB &dqmstore_output_msg, const std::string &output_filename)
void set_full_pathname(const ::std::string &value)
int convertFile(const std::string &output_filename, const std::vector< std::string > &filenames)
std::vector< boost::shared_ptr< fireworks::OptionNode > > Options
inline::dqmstorepb::ROOTFilePB_Histo * add_histo()
inline::google::protobuf::uint32 flags() const
static int showusage(void)
int dumpFiles(const std::vector< std::string > &filenames)
static bool lessThanMME(const std::string &lhs_dirname, const std::string &lhs_objname, const std::string &rhs_dirname, const std::string &rhs_objname)
void set_streamed_histo(const ::std::string &value)