Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:52:09

0001 #include "CondCore/DBCommon/interface/DBWriter.h"
0002 #include "CondCore/IOVService/interface/IOV.h"
0003 #include "CondCore/MetaDataService/interface/MetaData.h"
0004 #include "FWCore/Framework/interface/IOVSyncValue.h"
0005 #include "SealKernel/Service.h"
0006 #include "POOLCore/POOLContext.h"
0007 #include "SealKernel/Context.h"
0008 #include <string>
0009 #include <iostream>
0010 
0011 #include "CalibCalorimetry/HcalAlgos/interface/HcalDbServiceHardcode.h"
0012 #include "CondFormats/HcalObjects/interface/HcalPedestals.h"
0013 #include "CondFormats/HcalObjects/interface/HcalPedestalWidths.h"
0014 #include "CondFormats/HcalObjects/interface/HcalGains.h"
0015 #include "CondFormats/HcalObjects/interface/HcalGainWidths.h"
0016 #include "DataFormats/HcalDetId/interface/HcalDetId.h"
0017 
0018 #include "Geometry/CaloTopology/interface/HcalTopology.h"
0019 
0020 bool validHcalCell (const HcalDetId& fCell) {
0021   if (fCell.iphi () <=0)  return false;
0022   int absEta = abs (fCell.ieta ());
0023   int phi = fCell.iphi ();
0024   int depth = fCell.depth ();
0025   HcalSubdetector det = fCell.subdet ();
0026   // phi ranges
0027   if ((absEta >= 40 && phi > 18) ||
0028       (absEta >= 21 && phi > 36) ||
0029       phi > 72)   return false;
0030   if (absEta <= 0)       return false;
0031   else if (absEta <= 14) return (depth == 1 || depth == 4) && det == HcalBarrel; 
0032   else if (absEta == 15) return (depth == 1 || depth == 2 || depth == 4) && det == HcalBarrel; 
0033   else if (absEta == 16) return depth >= 1 && depth <= 2 && det == HcalBarrel || depth == 3 && det == HcalEndcap; 
0034   else if (absEta == 17) return depth == 1 && det == HcalEndcap; 
0035   else if (absEta <= 26) return depth >= 1 && depth <= 2 && det == HcalEndcap; 
0036   else if (absEta <= 28) return depth >= 1 && depth <= 3 && det == HcalEndcap; 
0037   else if (absEta == 29) return depth >= 1 && depth <= 2 && (det == HcalEndcap || det == HcalForward); 
0038   else if (absEta <= 41) return depth >= 1 && depth <= 2 && det == HcalForward;
0039   else return false;
0040 }
0041 
0042 
0043 
0044 int main (int argn, char** argv){
0045   std::string contact ("sqlite_file:hcal_default_calib.db");
0046   if (argn > 1) {
0047     contact = std::string (argv [1]);
0048   }
0049   std::cout << " Using DB connection: " << contact << std::endl; 
0050   // std::string contact("oracle://cmscald/ratnikov");
0051   // std::string contact("sqlite_file:hcal_default_calib.db");
0052   pool::POOLContext::loadComponent( "SEAL/Services/MessageService" );
0053   pool::POOLContext::loadComponent( "POOL/Services/EnvironmentAuthenticationService" );
0054 
0055   cond::DBWriter w(contact);
0056   w.startTransaction();
0057 
0058   HcalPedestals* pedestals=new HcalPedestals;
0059   HcalPedestalWidths* pedestalWidths=new HcalPedestalWidths;
0060   HcalGains* gains=new HcalGains;
0061   HcalGainWidths* gainWidths=new HcalGainWidths;
0062 
0063   int counter = 0;
0064   HcalTopology topology;
0065   for (int eta = -50; eta < 50; eta++) {
0066     for (int phi = 0; phi < 100; phi++) {
0067       for (int depth = 1; depth < 5; depth++) {
0068     for (int det = 1; det < 5; det++) {
0069       HcalDetId cell ((HcalSubdetector) det, eta, phi, depth);
0070       if (topology.valid(cell)) {
0071         uint32_t cellId = cell.rawId(); 
0072         HcalDbServiceHardcode srv;
0073         pedestals->addValue (cellId, srv.pedestals (cell));
0074         pedestalWidths->addValue (cellId, srv.pedestalErrors (cell));
0075         gains->addValue (cellId, srv.gains (cell));
0076         gainWidths->addValue (cellId, srv.gainErrors (cell));
0077 
0078         counter++;
0079         std::cout << counter << "  Added channel ID " << cellId 
0080               << " eta/phi/depth/det: " << eta << '/' << phi << '/' << depth << '/' << det << std::endl;
0081       }
0082     }
0083       }
0084     }
0085   }
0086   pedestals->sort ();
0087   pedestalWidths->sort ();
0088   gains->sort ();
0089   gainWidths->sort ();
0090 
0091   std::string pedtok=w.write<HcalPedestals> (pedestals, "HcalPedestals");//pool::Ref takes the ownership of ped1
0092   std::string pedWtok=w.write<HcalPedestalWidths> (pedestalWidths, "HcalPedestalWidths");//pool::Ref takes the ownership of ped1
0093   std::string gaintok=w.write<HcalGains> (gains, "HcalGains");//pool::Ref takes the ownership of ped1
0094   std::string gainWtok=w.write<HcalGainWidths> (gainWidths, "HcalGainWidths");//pool::Ref takes the ownership of ped1
0095 
0096   cond::IOV* iov=new cond::IOV;
0097   // this is cludge until IOV parameters are defined unsigned consistently with IOVSyncValue
0098   edm::IOVSyncValue endtime = edm::IOVSyncValue (edm::EventID(0x7FFFFFFF, 0x7FFFFFFF), edm::Timestamp::endOfTime());
0099   iov->iov.insert (std::make_pair (endtime.eventID().run(), pedtok));
0100   std::string iovToken1 = w.write<cond::IOV> (iov,"IOV");
0101 
0102   iov=new cond::IOV;
0103   iov->iov.insert (std::make_pair (endtime.eventID().run(), pedWtok));
0104   std::string iovToken2 = w.write<cond::IOV> (iov,"IOV");
0105 
0106   iov=new cond::IOV;
0107   iov->iov.insert (std::make_pair (endtime.eventID().run(), gaintok));
0108   std::string iovToken3 = w.write<cond::IOV> (iov,"IOV");
0109 
0110   iov=new cond::IOV;
0111   iov->iov.insert (std::make_pair (endtime.eventID().run(), gainWtok));
0112   std::string iovToken4 = w.write<cond::IOV> (iov,"IOV");
0113 
0114   std::cout << "\n\n==============================================" << std::endl;
0115   std::cout << "Pedestals token      -> " << pedtok  << std::endl;
0116   std::cout << "Pedestal Widths token-> " << pedWtok  << std::endl;
0117   std::cout << "Gains token          -> " << gaintok  << std::endl;
0118   std::cout << "GainWidths token     -> " << gainWtok  << std::endl;
0119   std::cout << "IOV tokens           -> " << iovToken1  << std::endl
0120         << "                        " << iovToken2  << std::endl
0121         << "                        " << iovToken3  << std::endl
0122         << "                        " << iovToken4  << std::endl;
0123   
0124   w.commitTransaction();
0125 
0126   //register the iovToken to the metadata service
0127   cond::MetaData metadata_svc(contact);
0128   metadata_svc.addMapping("HcalPedestals_default_v1", iovToken1);  
0129   metadata_svc.addMapping("HcalPedestalWidths_default_v1", iovToken2);  
0130   metadata_svc.addMapping("HcalGains_default_v1", iovToken3);  
0131   metadata_svc.addMapping("HcalGainWidths_default_v1", iovToken4);  
0132 }