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>
99 #define DEBUG(x, msg) if (debug >= x) std::cout << "DEBUG: " << msg << std::flush
107 int diff = lhs_dirname.compare(rhs_dirname);
108 return (diff < 0 ?
true
109 : diff == 0 ? lhs_objname < rhs_objname :
false);
142 using google::protobuf::io::FileInputStream;
143 using google::protobuf::io::FileOutputStream;
144 using google::protobuf::io::GzipInputStream;
145 using google::protobuf::io::GzipOutputStream;
146 using google::protobuf::io::CodedInputStream;
147 using google::protobuf::io::ArrayInputStream;
153 if (buf.Length() == buf.BufferSize())
156 return reinterpret_cast<TObject *
>(buf.ReadObjectAny(0));
164 size_t dirpos = (slash == std::string::npos ? 0 :
slash);
165 size_t namepos = (slash == std::string::npos ? 0 : slash+1);
167 objname.assign(h.
full_pathname(), namepos, std::string::npos);
168 TBufferFile buf(TBufferFile::kRead, h.
size(),
181 DEBUG(1,
"Writing file" << std::endl);
183 int out_fd = ::open(output_filename.c_str(),
184 O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR);
185 FileOutputStream out_stream(out_fd);
187 options.format = GzipOutputStream::GZIP;
188 options.compression_level = 2;
189 GzipOutputStream gzip_stream(&out_stream,
191 dqmstore_output_msg.SerializeToZeroCopyStream(&gzip_stream);
193 google::protobuf::ShutdownProtobufLibrary();
198 const std::set<MicroME> & micromes) {
199 std::set<MicroME>::iterator mi = micromes.begin();
200 std::set<MicroME>::iterator me = micromes.end();
202 DEBUG(1,
"Streaming ROOT objects" << std::endl);
203 for (; mi != me; ++mi) {
205 DEBUG(2,
"Streaming ROOT object " << *(mi->fullname) <<
"\n");
207 TBufferFile buffer(TBufferFile::kWrite);
208 buffer.WriteObject(mi->obj);
219 std::set<std::string> &dirs,
220 std::set<std::string> &objs,
221 std::set<std::string> &fullnames,
222 std::set<MicroME>& micromes) {
223 DEBUG(1,
"Processing directory " << curdir <<
"\n");
224 file->cd(curdir.c_str());
226 TIter
next (gDirectory->GetListOfKeys());
227 while ((key = (TKey *)
next())) {
228 TObject *
obj = key->ReadObj();
229 if (dynamic_cast<TDirectory *>(obj)) {
231 subdir.reserve(curdir.size() + strlen(obj->GetName()) + 2);
233 if (! curdir.empty())
235 subdir += obj->GetName();
237 }
else if (dynamic_cast<TH1 *>(obj)) {
238 (
dynamic_cast<TH1*
>(
obj))->SetDirectory(0);
239 DEBUG(2, curdir <<
"/" << obj->GetName() <<
"\n");
240 MicroME mme(&*(fullnames.insert(curdir
243 &*(dirs.insert(curdir).first),
244 &*(objs.insert(obj->GetName()).
first));
246 mme.
obj =
dynamic_cast<TH1*
>(
obj);
247 micromes.insert(mme);
255 const std::vector<std::string> &
filenames) {
256 assert(filenames.size() == 1);
257 TFile
input(filenames[0].c_str());
258 DEBUG(0,
"Encoding file " << filenames[0] << std::endl);
259 std::set<std::string> dirs;
260 std::set<std::string> objs;
261 std::set<std::string> fullnames;
262 std::set<MicroME> micromes;
273 const std::vector<std::string> &
filenames) {
274 assert(filenames.size() == 1);
275 TFile
output(output_filename.c_str(),
"RECREATE");
276 DEBUG(0,
"Converting file " << filenames[0] << std::endl);
279 int filedescriptor = open(filenames[0].c_str(), O_RDONLY);
280 FileInputStream
fin(filedescriptor);
281 GzipInputStream
input(&fin);
282 CodedInputStream input_coded(&input);
283 input_coded.SetTotalBytesLimit(1024*1024*1024, -1);
284 if (!dqmstore_message.ParseFromCodedStream(&input_coded)) {
286 << filenames[0] << std::endl;
294 TBufferFile buf(TBufferFile::kRead, h.
size(),
304 size_t end = path.find(
'/', start);
305 if (end == std::string::npos)
310 if (! gDirectory->Get(part.c_str()))
311 gDirectory->mkdir(part.c_str());
312 gDirectory->cd(part.c_str());
314 if (end+1 >= path.size())
318 end = path.find(
'/', start);
319 if (end == std::string::npos)
323 DEBUG(1, obj->GetName() << std::endl);
326 google::protobuf::ShutdownProtobufLibrary();
331 assert(filenames.size() > 0);
332 for (
int i = 0,
e = filenames.size();
i !=
e; ++
i) {
333 DEBUG(0,
"Dumping file " << filenames[
i] << std::endl);
336 int filedescriptor = open(filenames[0].c_str(), O_RDONLY);
337 FileInputStream
fin(filedescriptor);
338 GzipInputStream
input(&fin);
339 CodedInputStream input_coded(&input);
340 input_coded.SetTotalBytesLimit(1024*1024*1024, -1);
341 if (!dqmstore_message.ParseFromCodedStream(&input_coded)) {
343 << filenames[0] << std::endl;
351 TBufferFile buf(TBufferFile::kRead, h.
size(),
356 DEBUG(1, obj->GetName() << std::endl);
359 google::protobuf::ShutdownProtobufLibrary();
364 const std::vector<std::string> &
filenames) {
366 std::set<std::string> dirs;
367 std::set<std::string> objs;
368 std::set<std::string> fullnames;
369 std::set<MicroME> micromes;
371 assert(filenames.size() > 1);
372 DEBUG(1,
"Adding file " << filenames[0] << std::endl);
376 if ((filedescriptor = open(filenames[0].c_str(), O_RDONLY)) == -1) {
378 << filenames[0] << std::endl;
382 FileInputStream
fin(filedescriptor);
383 GzipInputStream
input(&fin);
384 CodedInputStream input_coded(&input);
385 input_coded.SetTotalBytesLimit(1024*1024*1024, -1);
386 if (!dqmstore_message.ParseFromCodedStream(&input_coded)) {
388 << filenames[0] << std::endl;
398 &*(dirs.insert(path).first),
399 &*(objs.insert(objname).first));
402 micromes.insert(*mme);
403 DEBUG(2,
"Inserting MicroME " << *mme->
fullname << std::endl);
408 for (
int i = 1,
e = filenames.size();
i !=
e; ++
i) {
409 DEBUG(1,
"Adding file " << filenames[
i] << std::endl);
412 if ((filedescriptor = open(filenames[
i].c_str(), O_RDONLY)) == -1) {
414 << filenames[
i] << std::endl;
417 FileInputStream
fin(filedescriptor);
418 GzipInputStream
input(&fin);
419 CodedInputStream input_coded(&input);
420 input_coded.SetTotalBytesLimit(1024*1024*1024, -1);
421 if (!dqmstore_msg.ParseFromCodedStream(&input_coded)) {
423 << filenames[0] << std::endl;
427 std::set<MicroME>::iterator mi = micromes.begin();
428 std::set<MicroME>::iterator me = micromes.end();
430 for (; mi != me; ++mi) {
439 DEBUG(2,
"Comparing " << *(*mi).dirname <<
"/"
440 << *(*mi).objname <<
" vs "
443 if (diff == 0 && obj !=
NULL) {
447 }
else if (!
lessThanMME(*(*mi).dirname, *(*mi).objname,
452 DEBUG(2,
"Adding Missing histogram "
458 &*(dirs.insert(path).first),
459 &*(objs.insert(objname).first));
462 micromes.insert(*mme);
468 DEBUG(2,
"Comparing " << *(*mi).dirname <<
"/"
469 << *(*mi).objname <<
" vs "
471 loop = !
lessThanMME(*(*mi).dirname, *(*mi).objname,
491 &*(dirs.insert(path).first),
492 &*(objs.insert(objname).first));
494 mme->obj =
const_cast<TH1*
>(
obj);
495 micromes.insert(*mme);
514 <<
" [--[no-]debug] TASK OPTIONS\n\n "
515 << app_name <<
" [OPTIONS] add -o OUTPUT_FILE [DAT FILE...]\n "
516 << app_name <<
" [OPTIONS] convert -o ROOT_FILE DAT_FILE\n "
517 << app_name <<
" [OPTIONS] encode -o DAT_FILE ROOT_FILE\n "
518 << app_name <<
" [OPTIONS] dump [DAT FILE...]\n ";
529 filenames.reserve(argc);
531 for (arg = 1; arg <
argc; ++
arg) {
532 if (! strcmp(argv[arg],
"--no-debug"))
534 else if (! strcmp(argv[arg],
"--debug")
535 || ! strcmp(argv[arg],
"-d"))
542 if (! strcmp(argv[arg],
"add")) {
545 }
else if (! strcmp(argv[arg],
"dump")) {
548 }
else if (! strcmp(argv[arg],
"convert")) {
551 }
else if (! strcmp(argv[arg],
"encode")) {
555 std::cerr <<
"Unknown action: " << argv[
arg] << std::endl;
565 std::cerr <<
"add|convert|encode actions requires a -o option to be set\n";
568 if (! strcmp(argv[arg],
"-o")) {
570 output_file = argv[++
arg];
572 std::cerr <<
" -o option requires a value\n";
582 filenames.push_back(argv[arg]);
592 filenames.push_back(argv[arg]);
597 ret =
addFiles(output_file, filenames);
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
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
const ::std::string & streamed_histo() const
static std::string const input
int main(int argc, char **argv)
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()
MicroME(const std::string *full, const std::string *dir, const std::string *obj)
static int showusage(void)
static void get_info(const dqmstorepb::ROOTFilePB::Histo &h, std::string &dirname, std::string &objname, TH1 **obj)
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)