CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/Calibration/TkAlCaRecoProducers/plugins/PCLMetadataWriter.cc

Go to the documentation of this file.
00001 
00002 /*
00003  *  See header file for a description of this class.
00004  *
00005  *  $Date: 2011/03/03 09:32:46 $
00006  *  $Revision: 1.2 $
00007  *  \author G. Cerminara - CERN
00008  */
00009 
00010 #include "Calibration/TkAlCaRecoProducers/plugins/PCLMetadataWriter.h"
00011 
00012 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00013 
00014 #include "FWCore/ServiceRegistry/interface/Service.h"
00015 #include "CondCore/DBOutputService/interface/PoolDBOutputService.h"
00016 #include "FWCore/MessageLogger/interface/JobReport.h"
00017 #include "FWCore/Framework/interface/ESHandle.h"
00018 #include "FWCore/Framework/interface/EventSetup.h"
00019 #include "CondFormats/DataRecord/interface/DropBoxMetadataRcd.h"
00020 #include "CondFormats/Common/interface/DropBoxMetadata.h"
00021 
00022 
00023 using namespace std;
00024 using namespace edm;
00025 
00026 PCLMetadataWriter::PCLMetadataWriter(const edm::ParameterSet& pSet){
00027   
00028   readFromDB = pSet.getParameter<bool>("readFromDB");
00029   
00030 
00031   vector<ParameterSet> recordsToMap = pSet.getParameter<vector<ParameterSet> >("recordsToMap");
00032   for(vector<ParameterSet>::const_iterator recordPset = recordsToMap.begin();
00033       recordPset != recordsToMap.end();
00034       ++recordPset) {
00035     
00036     string record = (*recordPset).getUntrackedParameter<string>("record");
00037     map<string, string> jrInfo;
00038     if(!readFromDB) {
00039       vector<string> paramKeys = (*recordPset).getParameterNames();
00040       for(vector<string>::const_iterator key = paramKeys.begin();
00041           key != paramKeys.end();
00042           ++key) {
00043         jrInfo["Source"] = "AlcaHarvesting";
00044         jrInfo["FileClass"] = "ALCA";
00045         if(*key != "record") {
00046           jrInfo[*key] = (*recordPset).getUntrackedParameter<string>(*key);
00047         }
00048       }
00049     }
00050     recordMap[record] = jrInfo;
00051 
00052   }
00053 
00054 }
00055 
00056 PCLMetadataWriter::~PCLMetadataWriter(){}
00057 
00058 
00059 void PCLMetadataWriter::analyze(const edm::Event& event, const edm::EventSetup& eSetup) {}
00060 
00061 
00062 void PCLMetadataWriter::beginRun(const edm::Run& run, const edm::EventSetup& eSetup) {} 
00063 
00064 void PCLMetadataWriter::endRun(const edm::Run& run, const edm::EventSetup& eSetup) {
00065 
00066   const DropBoxMetadata *metadata = 0;
00067 
00068   if(readFromDB) {
00069     // Read the objects
00070     edm::ESHandle<DropBoxMetadata> mdPayload;
00071     eSetup.get<DropBoxMetadataRcd>().get(mdPayload);
00072     
00073     metadata = mdPayload.product();
00074   }
00075 
00076   // get the PoolDBOutputService
00077   Service<cond::service::PoolDBOutputService> poolDbService;
00078   if(poolDbService.isAvailable() ) {
00079     edm::Service<edm::JobReport> jr;
00080     if (jr.isAvailable()) {
00081       // the filename is unique for all records
00082       string filename = poolDbService->session().connectionString();
00083 
00084       // loop over all records
00085       for(map<string,  map<string, string> >::const_iterator recordAndMap = recordMap.begin();
00086           recordAndMap != recordMap.end();
00087           ++recordAndMap) {
00088 
00089         string record = (*recordAndMap).first;
00090         // this is the map of metadata that we write in the JR
00091         map<string, string> jrInfo = (*recordAndMap).second;
00092         if(readFromDB) {
00093           if(metadata->knowsRecord(record)) {
00094             jrInfo = metadata->getRecordParameters(record).getParameterMap();
00095           }
00096         }
00097         jrInfo["inputtag"] = poolDbService->tag(record);
00098         
00099         
00100         // actually write in the job report
00101         jr->reportAnalysisFile(filename, jrInfo);
00102       }
00103     }
00104   }
00105 }
00106 
00107 
00108 #include "FWCore/Framework/interface/MakerMacros.h"
00109 DEFINE_FWK_MODULE(PCLMetadataWriter);