Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-03 08:20:24

0001 #include <CDBUtils.C>
0002 
0003 std::map<std::string, std::string> md5map;
0004 
0005 void loadmd5map(const std::string &fname);
0006 bool md5check(const std::string &cdbfname, const std::string &fname);
0007 int insertpl(const std::string &fname, const std::string &ptype, int runnumber);
0008 int checkpl(const std::string &fname, const std::string &ptype, int runnumber);
0009 int insertplrunrange(const std::string &fname, const std::string &ptype, int runnumber, int endrun);
0010 int checkplrunrange(const std::string &fname, const std::string &ptype, int runnumber, int endrun);
0011 int insertplinfinity(const std::string &fname, const std::string &ptype, int runnumber);
0012 int checkplinfinity(const std::string &fname, const std::string &ptype, int runnumber);
0013 
0014 int checkpl(const std::string &fname, const std::string &ptype, int runnumber)
0015 {
0016   std::string cdbres = getCalibration(ptype,runnumber);
0017   if (cdbres.empty() || cdbres.find(fname) == std::string::npos)
0018   {
0019     cout << "could not find " << fname << " inserting it" << std::endl;
0020     insertpl(fname,ptype,runnumber);
0021   }
0022   else
0023   {
0024     if (md5check(cdbres,fname))
0025     {
0026 //      cout << fname << " checks out" << std::endl;
0027     }
0028     else
0029     {
0030       cout << fname << " will be overwritten with new md5sum" << std::endl;
0031       insertpl(fname,ptype,runnumber);
0032     }
0033       
0034     }
0035   return 0;
0036 }
0037 
0038 int checkplrunrange(const std::string &fname, const std::string &ptype, int runnumber, int endrun)
0039 {
0040   std::string cdbres = getCalibration(ptype,runnumber);
0041   if (cdbres.empty() || cdbres.find(fname) == std::string::npos)
0042   {
0043     cout << "could not find " << fname << " inserting it" << std::endl;
0044     insertplrunrange(fname,ptype,runnumber,endrun);
0045   }
0046   else
0047   {
0048     if (md5check(cdbres,fname))
0049     {
0050 //      cout << fname << " checks out" << std::endl;
0051     }
0052     else
0053     {
0054       cout << fname << " will be overwritten with new md5sum" << std::endl;
0055       insertplrunrange(fname,ptype,runnumber,endrun);
0056     }
0057       
0058     }
0059   return 0;
0060 }
0061 
0062 int checkplinfinity(const std::string &fname, const std::string &ptype, int runnumber)
0063 {
0064   std::string cdbres = getCalibration(ptype,runnumber);
0065   if (cdbres.empty() || cdbres.find(fname) == std::string::npos)
0066   {
0067     cout << "could not find " << fname << " inserting it" << std::endl;
0068     insertplinfinity(fname,ptype,runnumber);
0069   }
0070   else
0071   {
0072     if (md5check(cdbres,fname))
0073     {
0074 //      cout << fname << " checks out" << std::endl;
0075     }
0076     else
0077     {
0078       cout << fname << " will be overwritten with new md5sum" << std::endl;
0079       insertplinfinity(fname,ptype,runnumber);
0080     }
0081       
0082     }
0083   return 0;
0084 }
0085 
0086 int insertpl(const std::string &fname, const std::string &ptype, int runnumber)
0087 {
0088   insertPayload(ptype,fname,runnumber,runnumber+1);
0089 //  gSystem->Exit(0);
0090   return 0;
0091 }
0092 
0093 int insertplrunrange(const std::string &fname, const std::string &ptype, int runnumber, int endrun)
0094 {
0095   cout << "insert " << fname << ", from " << runnumber << " to "
0096        << endrun+1 << endl;
0097   insertPayload(ptype,fname,runnumber,endrun+1);
0098 //  gSystem->Exit(0);
0099   return 0;
0100 }
0101 
0102 int insertplinfinity(const std::string &fname, const std::string &ptype, int runnumber)
0103 {
0104 //  std::cout << "inserting payload " << fname << " start " << runnumber << std::endl;
0105   insertPayload(ptype,fname,runnumber);
0106 //  gSystem->Exit(0);
0107   return 0;
0108 }
0109 
0110 void loadmd5map(const std::string &fname)
0111 {
0112   ifstream infile(fname);
0113   if (infile.is_open())
0114   {
0115     std::string line;
0116     while (std::getline(infile, line))
0117     {
0118       std::istringstream istr(line);
0119       std::string md5;
0120       std::string cdbfile;
0121       istr >> md5;
0122       istr >> cdbfile;
0123       md5map[cdbfile] = md5;
0124     }
0125     infile.close();
0126     // for (auto iter : md5map)
0127     // {
0128     //        std::cout << "file: " << iter.first << ", md5: " << iter.second << std::endl;
0129     // }
0130   }
0131   else
0132   {
0133     std::cout << "could not open " << fname << std::endl;
0134     gSystem->Exit(1);
0135   }
0136 }
0137 
0138 bool md5check(const std::string &cdbfname, const std::string &fname)
0139 {
0140   std::filesystem::path fullfile(cdbfname);
0141   std::string lfn = fullfile.stem();
0142   std::filesystem::path fullfname(fname);
0143   int pos = lfn.find(fullfname.stem());
0144   pos--;
0145 //  std::cout << "lfn: " << fullfile.stem() << ", fulln: "<< fullfname.stem() << ", pos: " << pos << std::endl;
0146   lfn.erase(pos);
0147   auto iter = md5map.find(fname);
0148   if (iter != md5map.end())
0149   {
0150 //    std::cout << "file " << iter->first << " md5: " << iter->second << " cdbmd5: " << lfn << std::endl;
0151     if (iter->second == lfn)
0152     {
0153 //      std::cout << "all good" << std::endl;
0154       return true;
0155     }
0156   }
0157   return false;
0158 }