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,
208 FileOutputStream out_stream(out_fd);
210 options.format = GzipOutputStream::GZIP;
211 options.compression_level = 2;
212 GzipOutputStream gzip_stream(&out_stream,
214 dqmstore_output_msg.SerializeToZeroCopyStream(&gzip_stream);
216 google::protobuf::ShutdownProtobufLibrary();
221 const std::set<MicroME> & micromes) {
222 std::set<MicroME>::iterator mi = micromes.begin();
223 std::set<MicroME>::iterator me = micromes.end();
225 DEBUG(1,
"Streaming ROOT objects" << std::endl);
226 for (; mi != me; ++mi) {
228 DEBUG(2,
"Streaming ROOT object " << *(mi->fullname) <<
"\n");
230 TBufferFile buffer(TBufferFile::kWrite);
231 buffer.WriteObject(mi->obj);
243 std::set<std::string> &dirs,
244 std::set<std::string> &objs,
245 std::set<std::string> &fullnames,
246 std::set<MicroME>& micromes) {
247 DEBUG(1,
"Processing directory " << curdir <<
"\n");
248 file->cd(curdir.c_str());
250 TIter
next (gDirectory->GetListOfKeys());
251 while ((key = (TKey *)
next())) {
252 TObject *
obj = key->ReadObj();
253 if (dynamic_cast<TDirectory *>(obj)) {
255 subdir.reserve(curdir.size() + strlen(obj->GetName()) + 2);
257 if (! curdir.empty())
259 subdir += obj->GetName();
261 }
else if ((dynamic_cast<TH1 *>(obj)) || (dynamic_cast<TObjString *>(obj))) {
262 if (dynamic_cast<TH1 *>(obj)) {
263 dynamic_cast<TH1 *
>(
obj)->SetDirectory(0);
266 DEBUG(2, curdir <<
"/" << obj->GetName() <<
"\n");
267 MicroME mme(&*(fullnames.insert(curdir
270 &*(dirs.insert(curdir).first),
271 &*(objs.insert(obj->GetName()).
first));
274 micromes.insert(mme);
282 const std::vector<std::string> &
filenames) {
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;
300 const std::vector<std::string> &
filenames) {
301 assert(filenames.size() == 1);
302 TFile
output(output_filename.c_str(),
"RECREATE");
303 DEBUG(0,
"Converting file " << filenames[0] << std::endl);
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)) {
313 << filenames[0] << std::endl;
321 TBufferFile buf(TBufferFile::kRead, h.
size(),
331 size_t end = path.find(
'/', start);
332 if (end == std::string::npos)
337 if (! gDirectory->Get(part.c_str()))
338 gDirectory->mkdir(part.c_str());
339 gDirectory->cd(part.c_str());
341 if (end+1 >= path.size())
345 end = path.find(
'/', start);
346 if (end == std::string::npos)
350 DEBUG(1, obj->GetName() << std::endl);
353 google::protobuf::ShutdownProtobufLibrary();
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);
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)) {
370 << filenames[0] << std::endl;
378 TBufferFile buf(TBufferFile::kRead, h.
size(),
383 DEBUG(1, obj->GetName() << std::endl);
384 DEBUG(1,
"Flags: " << h.
flags() << std::endl);
387 google::protobuf::ShutdownProtobufLibrary();
392 const std::vector<std::string> &
filenames) {
394 std::set<std::string> dirs;
395 std::set<std::string> objs;
396 std::set<std::string> fullnames;
397 std::set<MicroME> micromes;
399 assert(filenames.size() > 0);
400 DEBUG(1,
"Adding file " << filenames[0] << std::endl);
404 if ((filedescriptor = open(filenames[0].c_str(), O_RDONLY)) == -1) {
406 << filenames[0] << std::endl;
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)) {
416 << filenames[0] << std::endl;
426 &*(dirs.insert(path).first),
427 &*(objs.insert(objname).first),
431 micromes.insert(*mme);
432 DEBUG(2,
"Inserting MicroME " << *mme->
fullname << std::endl);
437 for (
int i = 1,
e = filenames.size();
i !=
e; ++
i) {
438 DEBUG(1,
"Adding file " << filenames[
i] << std::endl);
441 if ((filedescriptor = open(filenames[
i].c_str(), O_RDONLY)) == -1) {
443 << filenames[
i] << std::endl;
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)) {
452 << filenames[0] << std::endl;
456 std::set<MicroME>::iterator mi = micromes.begin();
457 std::set<MicroME>::iterator me = micromes.end();
459 for (; mi != me; ++mi) {
469 DEBUG(2,
"Comparing " << *(*mi).dirname <<
"/"
470 << *(*mi).objname <<
" vs "
473 if (diff == 0 && obj !=
NULL) {
477 }
else if (!
lessThanMME(*(*mi).dirname, *(*mi).objname,
482 DEBUG(2,
"Adding Missing histogram "
488 &*(dirs.insert(path).first),
489 &*(objs.insert(objname).first));
492 micromes.insert(*mme);
498 DEBUG(2,
"Comparing " << *(*mi).dirname <<
"/"
499 << *(*mi).objname <<
" vs "
501 loop = !
lessThanMME(*(*mi).dirname, *(*mi).objname,
521 &*(dirs.insert(path).first),
522 &*(objs.insert(objname).first));
525 micromes.insert(*mme);
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 ";
559 filenames.reserve(argc);
561 for (arg = 1; arg <
argc; ++
arg) {
562 if (! strcmp(argv[arg],
"--no-debug"))
564 else if (! strcmp(argv[arg],
"--debug")
565 || ! strcmp(argv[arg],
"-d"))
572 if (! strcmp(argv[arg],
"add")) {
575 }
else if (! strcmp(argv[arg],
"dump")) {
578 }
else if (! strcmp(argv[arg],
"convert")) {
581 }
else if (! strcmp(argv[arg],
"encode")) {
585 std::cerr <<
"Unknown action: " << argv[
arg] << std::endl;
595 std::cerr <<
"add|convert|encode actions requires a -o option to be set\n";
598 if (! strcmp(argv[arg],
"-o")) {
600 output_file = argv[++
arg];
602 std::cerr <<
" -o option requires a value\n";
612 filenames.push_back(argv[arg]);
622 filenames.push_back(argv[arg]);
627 ret =
addFiles(output_file, filenames);
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)